Skip to content

Commit

Permalink
Merge pull request #7 from Ton-Dynasty/fix/gas-and-typo
Browse files Browse the repository at this point in the history
Fix/gas and typo
  • Loading branch information
alan890104 authored May 1, 2024
2 parents 8b55db9 + 31b892f commit 9527cc4
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 30 deletions.
12 changes: 6 additions & 6 deletions contracts/jetton_master_chef.tact
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract JettonMasterChef with Deployable, MasterChef {
startTime: Int as uint64 = 0;
metaData: Cell;
totalLpSupply: Int = 0; // Caculated total LP supply(In each pool)
reduntantReward: Int = 0; // The redundant reward for the owner
redundantReward: Int = 0; // The redundant reward for the owner
lastWithdrawTime: Int = 0; // The last withdraw time

// For Reward Jetton
Expand Down Expand Up @@ -94,7 +94,7 @@ contract JettonMasterChef with Deployable, MasterChef {

// Send the redundant jetton back to the owner
if(self.totalLpSupply == 0) {
self.reduntantReward = self.reduntantReward + (now() - self.lastWithdrawTime) * self.rewardPerSecond;
self.redundantReward = self.redundantReward + (now() - self.lastWithdrawTime) * self.rewardPerSecond;
}

// Deposit the LP tokens for the user
Expand Down Expand Up @@ -135,12 +135,12 @@ contract JettonMasterChef with Deployable, MasterChef {
require(ctx.value > ton("0.05"), "Not enough TON to redeem");
if(self.totalLpSupply == 0) {
let time: Int = min(now(), self.deadline);
self.reduntantReward = self.reduntantReward + (time - self.lastWithdrawTime) * self.rewardPerSecond;
self.redundantReward = self.redundantReward + (time - self.lastWithdrawTime) * self.rewardPerSecond;
self.lastWithdrawTime = now();
}
if(self.reduntantReward > 0) {
self.sendJetton(self.mcRewardJettonWallet, 0, self.reduntantReward, self.owner, self.owner, SendRemainingValue);
self.reduntantReward = 0;
if(self.redundantReward > 0) {
self.sendJetton(self.mcRewardJettonWallet, 0, self.redundantReward, self.owner, self.owner, SendRemainingValue);
self.redundantReward = 0;
}
}

Expand Down
12 changes: 8 additions & 4 deletions contracts/kitchen.tact
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ contract Kitchen with Deployable {

// Deploy MasterChef for jetton
receive(msg: BuildJettonMasterChef) {
let ctx: Context = context();
let sendTon: Int = ctx.value - KITCHEN_FEE;
let initCode: StateInit = self.calculateJettonMasterChef(msg.owner,msg.seed);
send(SendParameters{
to: contractAddress(initCode),
value: 0,
mode: SendRemainingValue,
value: sendTon,
mode: 0,
body: SetUpJettonMC{
owner: msg.owner,
thunderMintWallet: self.owner,
Expand All @@ -37,11 +39,13 @@ contract Kitchen with Deployable {

// Deploy MasterChef for TON
receive(msg: BuildTonMasterChef) {
let ctx: Context = context();
let sendTon: Int = ctx.value - KITCHEN_FEE;
let initCode: StateInit = self.calculateTonMasterChef(msg.owner,msg.seed);
send(SendParameters{
to: contractAddress(initCode),
value: 0,
mode: SendRemainingValue,
value: sendTon,
mode: 0,
body: SetUpTonMC{
owner: msg.owner,
thunderMintWallet: self.owner,
Expand Down
5 changes: 3 additions & 2 deletions contracts/messages.tact
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ struct MasterChefData {
}

struct RedeemData {
reduntantReward: Int as coins; // Redundant reward,
redundantReward: Int as coins; // Redundant reward,
totalLpSupply: Int as coins;
lastWithdrawTime: Int;
}
Expand All @@ -205,7 +205,8 @@ const ACC_PRECISION: Int = pow(10, 20); // Precision for the accumulated rewar
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
const gasConsumption: Int = ton("0.0059");
const GAS_CONSUMPTION: Int = ton("0.0059");
const KITCHEN_FEE: Int = ton("0.03"); // Fee for the Kitchen

// ERROR CODES
const ERROR_POOL_NOT_FOUND: Int = 1002;
Expand Down
8 changes: 4 additions & 4 deletions contracts/mini_chef.tact
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract MiniChef with Deployable {
userInfo.rewardDebt = userInfo.rewardDebt + msg.rewardDebt;
self.userInfo.set(msg.lpTokenAddress, userInfo);
let ctx: Context = context();
let sendBackTon: Int = ctx.value - gasConsumption - MIN_GAS_FEE;
let sendBackTon: Int = ctx.value - GAS_CONSUMPTION - MIN_GAS_FEE;
// Send remain Ton to owner
send(SendParameters{
to: self.owner,
Expand All @@ -50,7 +50,7 @@ contract MiniChef with Deployable {

self.userInfo.set(msg.lpTokenAddress, userInfo);
let ctx: Context = context();
let sendBackTon: Int = ctx.value - gasConsumption;
let sendBackTon: Int = ctx.value - GAS_CONSUMPTION;
send(SendParameters{
to: self.masterChef,
value: sendBackTon,
Expand All @@ -77,7 +77,7 @@ contract MiniChef with Deployable {
userInfo.rewardDebt = accumulatedReward;
self.userInfo.set(msg.lpTokenAddress, userInfo);
let ctx: Context = context();
let sendBackTon: Int = ctx.value - gasConsumption;
let sendBackTon: Int = ctx.value - GAS_CONSUMPTION;
// Send pending reward ammount to MasterChef, and then MasterChef will send it to the user
send(SendParameters{
to: self.masterChef,
Expand All @@ -103,7 +103,7 @@ contract MiniChef with Deployable {
let _pendingReward: Int = accumulatedReward - userInfo.rewardDebt;

let ctx: Context = context();
let sendBackTon: Int = ctx.value - gasConsumption;
let sendBackTon: Int = ctx.value - GAS_CONSUMPTION;
if (_pendingReward <= 0) {
userInfo.amount = userInfo.amount - msg.withdrawAmount;
userInfo.rewardDebt = userInfo.rewardDebt - msg.withdrawAmount * msg.accRewardPerShare / ACC_PRECISION;
Expand Down
6 changes: 3 additions & 3 deletions contracts/packages/mock/JettonWallet.tact
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ trait JettonWallet {
balance: Int;
owner: Address;
jetton_master: Address;
virtual const gasConsumption: Int = ton("0.05");
virtual const GAS_CONSUMPTION: Int = ton("0.05");
virtual const minTonsForStorage: Int = ton("0.05");

//********************************************//
Expand Down Expand Up @@ -132,7 +132,7 @@ trait JettonWallet {
virtual inline fun _internal_transfer_estimate_remain_value(ctx: Context, msg: JettonInternalTransfer): Int {
let tonBalanceBeforeMsg: Int = myBalance() - ctx.value;
let storage_fee: Int = self.minTonsForStorage - min(tonBalanceBeforeMsg, self.minTonsForStorage);
let remain: Int = ctx.value - (storage_fee + self.gasConsumption);
let remain: Int = ctx.value - (storage_fee + self.GAS_CONSUMPTION);
if (msg.forward_ton_amount > 0) {
remain = remain - (ctx.readForwardFee() + msg.forward_ton_amount);
}
Expand Down Expand Up @@ -206,7 +206,7 @@ trait JettonWallet {
if (msg.forward_ton_amount > 0) {
fwd_count = 2;
}
require(ctx.value > fwd_count * ctx.readForwardFee() + 2 * self.gasConsumption + self.minTonsForStorage, "Not enough funds to transfer");
require(ctx.value > fwd_count * ctx.readForwardFee() + 2 * self.GAS_CONSUMPTION + self.minTonsForStorage, "Not enough funds to transfer");
}

// @dev _transfer_jetton will transfer jettons to the jetton wallet of the destination address (owner of jetton wallet)
Expand Down
4 changes: 2 additions & 2 deletions contracts/packages/utils/Estimatable.tact
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
trait Estimatable {
virtual const gasConsumption: Int = ton("0.05");
virtual const GAS_CONSUMPTION: Int = ton("0.05");
virtual const minTonsForStorage: Int = ton("0.05");

virtual fun estimate_rest_value(ctx: Context): Int {
let restValue: Int = ctx.value;
let tonBalanceBeforeMsg: Int = myBalance() - restValue;
let storageFee: Int = self.minTonsForStorage - min(tonBalanceBeforeMsg, self.minTonsForStorage);
return restValue - (storageFee + self.gasConsumption);
return restValue - (storageFee + self.GAS_CONSUMPTION);
}
}
12 changes: 6 additions & 6 deletions contracts/ton_master_chef.tact
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract TonMasterChef with Deployable, MasterChef {
startTime: Int as uint64 = 0;
metaData: Cell;
totalLpSupply: Int = 0; // Caculated total LP supply(In each pool)
reduntantReward: Int = 0; // The redundant reward for the owner
redundantReward: Int = 0; // The redundant reward for the owner
lastWithdrawTime: Int = 0; // The last withdraw time

// For Reward TON
Expand Down Expand Up @@ -94,7 +94,7 @@ contract TonMasterChef with Deployable, MasterChef {

// Send the redundant ton back to the owner
if(self.totalLpSupply == 0) {
self.reduntantReward = self.reduntantReward + (now() - self.lastWithdrawTime) * self.rewardPerSecond;
self.redundantReward = self.redundantReward + (now() - self.lastWithdrawTime) * self.rewardPerSecond;
}

// Deposit the LP tokens for the user
Expand Down Expand Up @@ -135,12 +135,12 @@ contract TonMasterChef with Deployable, MasterChef {
require(ctx.value > ton("0.05"), "Not enough TON to redeem");
if(self.totalLpSupply == 0) {
let time: Int = min(now(), self.deadline);
self.reduntantReward = self.reduntantReward + (time - self.lastWithdrawTime) * self.rewardPerSecond;
self.redundantReward = self.redundantReward + (time - self.lastWithdrawTime) * self.rewardPerSecond;
self.lastWithdrawTime = now();
}
if(self.reduntantReward > 0) {
self.sendTon(self.owner, self.reduntantReward, SendRemainingValue);
self.reduntantReward = 0;
if(self.redundantReward > 0) {
self.sendTon(self.owner, self.redundantReward, SendRemainingValue);
self.redundantReward = 0;
}
}

Expand Down
6 changes: 3 additions & 3 deletions contracts/trait_master_chef.tact
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait MasterChef {
metaData: Cell; // The meta data of the contract, such as the name, image url, description, etc.
startTime: Int = 0; // The time when the reward distribution starts (initialize in basic setup)
totalLpSupply: Int = 0; // Caculated total LP supply(In each pool)
reduntantReward: Int = 0; // The redundant reward for the owner
redundantReward: Int = 0; // The redundant reward for the owner
lastWithdrawTime: Int = 0; // The last withdraw time

// For Reward jetton
Expand Down Expand Up @@ -224,7 +224,7 @@ trait MasterChef {
pool.lpSupply = pool.lpSupply + msg.amount;
self.totalLpSupply = self.totalLpSupply + msg.amount;
self.pools.set(ctx.sender, pool);
let sendBackTon: Int = ctx.value - gasConsumption;
let sendBackTon: Int = ctx.value - GAS_CONSUMPTION;
// Get the MiniChef init code for the user
let initCode: StateInit = self._calculateMiniChefInit(msg.sender);
send(SendParameters{
Expand Down Expand Up @@ -345,7 +345,7 @@ trait MasterChef {
// get RedeemData
get fun getRedeemData(): RedeemData {
return RedeemData{
reduntantReward: self.reduntantReward,
redundantReward: self.redundantReward,
totalLpSupply: self.totalLpSupply,
lastWithdrawTime: self.lastWithdrawTime
};
Expand Down

0 comments on commit 9527cc4

Please sign in to comment.