Skip to content

Commit

Permalink
fix: add min gas fee to restrict refund action
Browse files Browse the repository at this point in the history
  • Loading branch information
alan890104 committed Apr 19, 2024
1 parent 77eae59 commit 3ff6f55
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
7 changes: 5 additions & 2 deletions contracts/jetton_master_chef.tact
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,17 @@ contract JettonMasterChef with Deployable, MasterChef {
throw(ERROR_WRONG_AUTH);
}
// Calculate the reward jetton for ThunderMint team
self.feeForDevs = self.totalReward * FEE_PERCENT_FOR_DEV / 1000; // 0.3% fee
let feeForDevs: Int = self.totalReward * FEE_PERCENT_FOR_DEV / 1000; // 0.3% fee

// Have to transfer reward jetton and fee to the contract
let expectedAmount: Int = self.totalReward + self.feeForDevs;
let expectedAmount: Int = self.totalReward + feeForDevs;
if(msg.amount < expectedAmount || now() > self.deadline) {
self.sendJetton(self.mcRewardJettonWallet, 0 ,msg.amount, msg.sender, msg.sender, SendRemainingValue);
return;
}

// Set the fee for devs
self.feeForDevs = feeForDevs;
self.isInitialized = true;

// Send Jetton Fee to ThunderMint
Expand Down
3 changes: 2 additions & 1 deletion contracts/messages.tact
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,10 @@ struct MasterChefData {

// Constants
const THUNDER_FEE: Int = ton("0.01"); // User have to pay the fee to ThunderMint
const ACC_PRECISION: Int = pow(10,12); // Precision for the accumulated reward per share
const ACC_PRECISION: Int = pow(10, 12); // Precision for the accumulated reward per share
const ZERO_ADDRESS: Address = address("0QAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACkT");
const FEE_PERCENT_FOR_DEV: Int = 3; // 0.3% of the reward will be given to the ThunderMint
const MIN_GAS_FEE: Int = ton("0.05"); // Minimum gas fee for calling send ton

// ERROR CODES
const ERROR_POOL_NOT_FOUND: Int = 1002;
Expand Down
19 changes: 11 additions & 8 deletions contracts/ton_master_chef.tact
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,23 @@ contract TonMasterChef with Deployable, MasterChef {
});
return;
}
let sendedTon: Int = ctx.value;
let remainTon: Int = ctx.value - MIN_GAS_FEE;
let feeForDevs: Int = msg.totalReward * FEE_PERCENT_FOR_DEV / 1000;
self.feeForDevs = feeForDevs;
let expectedTon: Int = msg.totalReward + feeForDevs;
if (sendedTon < expectedTon) {
self.sendTon(msg.owner, sendedTon - ctx.readForwardFee(), 0);
if (remainTon < expectedTon) {
self.sendTon(msg.owner, remainTon, 0);
return;
}
// Update storage when ton is sufficient
self.isInitialized = true;
self.sendTon(self.thunderMintWallet, self.feeForDevs - ctx.readForwardFee(), 0);

self.feeForDevs = feeForDevs;
if (self.feeForDevs > MIN_GAS_FEE) {
self.sendTon(self.thunderMintWallet, self.feeForDevs - MIN_GAS_FEE, 0);
}

// Sending the remaining TON to the owner
if(sendedTon > expectedTon) {
self.sendTon(self.owner, sendedTon - expectedTon , 0);
if(remainTon > expectedTon) {
self.sendTon(self.owner, remainTon - expectedTon, 0);
}
}

Expand Down
2 changes: 1 addition & 1 deletion deployments/deployment.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"USDT": "EQBqSpvo4S87mX9tjHaG4zhYZeORhVhMapBJpnMZ64jhrEQK",
"AirdropFactory": "EQCKrD4mAxJ40TDCuylk2B2bTpCJVslwdE4MEWaMHa6f1x_1",
"Kitchen": "EQAF1rmr89SEddR6KQ-7baHDsEg__17xYsMfRO05vUDP_DTN",
"Kitchen": "EQDFwPAq7wFQK77xN_Kn0nP1euMobfVlM1ZcxpccW_Inw1CD",
"MasterChef": "kQBQ80fBfaLY1SgIskc0qTANEO1-aLhvdKcZAL68WWaKlSTO",
"MerkleDistributor": {
"seed": "38435217033760998392163658086743783990464893960025036024613934316511459962221",
Expand Down
8 changes: 4 additions & 4 deletions scripts/buildTonMasterChef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,22 @@ export async function run(provider: NetworkProvider) {
const kitchen = provider.open(Kitchen.fromAddress(Address.parse(deployment.Kitchen)));
const seed = BigInt(`0x${beginCell().storeUint(Date.now(), 64).endCell().hash().toString('hex')}`);
const masterchefAddress = await kitchen.getGetJettonMasterChefAddress(provider.sender().address!!, seed);
const totalReward = 1n * 10n ** 10n;
const totalReward = toNano("0.01")
let sentAmount = (totalReward * 1003n) / 1000n;
const deadline = BigInt(Math.floor(Date.now() / 1000) + 60 * 60);

const startTime = BigInt(Math.floor(Date.now() / 1000)) + 10n;
await kitchen.send(
provider.sender(),
{
value: sentAmount + toNano('1'),
value: sentAmount + toNano('0.1'),
},
{
$$type: 'BuildTonMasterChef',
owner: provider.sender().address!!,
seed: seed,
metaData: beginCell().storeStringTail('httpppp').endCell(),
deadline: deadline,
startTime: BigInt(Math.floor(Date.now() / 1000)) + 10n,
startTime: startTime,
totalReward: totalReward,
},
);
Expand Down

0 comments on commit 3ff6f55

Please sign in to comment.