Skip to content

Commit

Permalink
Reverted escrow
Browse files Browse the repository at this point in the history
  • Loading branch information
Shvandre committed Feb 28, 2025
1 parent 02e25ed commit 1908f06
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 31 deletions.
13 changes: 8 additions & 5 deletions src/test/benchmarks/contracts/escrow.tact
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ contract Escrow {

receive(msg: UpdateJettonWalletCode) {
throwUnless(400, !self.isFunded && self.assetAddress != null);
throwUnless(403, self.sellerAddress == sender());
throwUnless(403, self.sellerAddress == context().sender);

self.jettonWalletCode = msg.newJettonWalletCode;
}
Expand All @@ -125,8 +125,7 @@ contract Escrow {
let ctx: Context = context();

throwUnless(403, self.guarantorAddress == ctx.sender);
let percent: Int = max(self.guarantorRoyaltyPercent, self.GUARANTOR_PERCENT_MAX);
let royaltyAmount: Int = muldivc(percent, self.dealAmount, self.GUARANTOR_PERCENT_CONST);
let royaltyAmount: Int = self.calculateRoyaltyAmount();

if (self.assetAddress == null) {
throwUnless(404, ctx.value > (2 * self.TON_TRANSFER_GAS));
Expand Down Expand Up @@ -194,9 +193,13 @@ contract Escrow {
get fun calculateRoyaltyAmount(): Int {
// using integer math to avoid floating point issues
// see https://tact-by-example.org/04-decimal-point
let percent: Int = max(self.guarantorRoyaltyPercent, self.GUARANTOR_PERCENT_MAX);
let percent: Int = self.guarantorRoyaltyPercent;

return muldivc(percent, self.dealAmount, self.GUARANTOR_PERCENT_CONST);
if (percent >= self.GUARANTOR_PERCENT_MAX) {
percent = self.GUARANTOR_PERCENT_MAX;
}

return (self.dealAmount * percent) / self.GUARANTOR_PERCENT_CONST;
}

get fun walletAddress(): Address {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract JettonMinter(
receive(msg: ProvideWalletAddress) {
// we use message fwdFee for estimation of forward_payload costs
let ctx = context();
let fwdFee = muldivc(fwdFee(ctx.raw), 3, 2);
let fwdFee = ctx.readForwardFee();
throwUnless(75, ctx.value > fwdFee + ProvideAddressGasConsumption);

let includedAddress: Address? = msg.includeAddress ? msg.ownerAddress : null;
Expand Down
16 changes: 4 additions & 12 deletions src/test/benchmarks/contracts/jetton_wallet.tact
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ contract JettonWallet(
let fwdCount = 1 + msg.forwardTonAmount & 1;
throwUnless(709, ctx.value >
msg.forwardTonAmount +
fwdCount * muldivc(fwdFee(ctx.raw), 3, 2) +
fwdCount * ctx.readForwardFee() +
(2 * self.gasConsumption + self.minTonsForStorage)
);

Expand Down Expand Up @@ -56,7 +56,7 @@ contract JettonWallet(
msgValue -= (storageFee + self.gasConsumption);

if (msg.forwardTonAmount > 0) {
let fwdFee: Int = muldivc(fwdFee(ctx.raw), 3, 2);
let fwdFee: Int = ctx.readForwardFee();
msgValue -= msg.forwardTonAmount + fwdFee;
message(MessageParameters{
to: self.owner,
Expand Down Expand Up @@ -91,7 +91,7 @@ contract JettonWallet(
throwUnless(706, self.balance >= 0);

let ctx = context();
let fwd_fee: Int = muldivc(fwdFee(ctx.raw), 3, 2);
let fwd_fee: Int = ctx.readForwardFee();
throwUnless(707, ctx.value > (fwd_fee + 2 * self.gasConsumption));

message(MessageParameters{
Expand Down Expand Up @@ -124,12 +124,4 @@ contract JettonWallet(
code: myCode()
};
}
}

inline fun fwdFee(ctxRaw: Slice): Int {
ctxRaw.loadAddress();
ctxRaw.loadCoins();
ctxRaw.skipBits(1);
ctxRaw.loadCoins();
return ctxRaw.loadCoins();
}
}
10 changes: 0 additions & 10 deletions src/test/benchmarks/escrow/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,6 @@
"approveTon": "7131",
"cancelTon": "4957"
}
},
{
"label": "1.5.3 with optimized calculations",
"pr": "https://github.com/tact-lang/tact/pull/2058",
"gas": {
"fundingTon": "4988",
"changeCode": "5112",
"approveTon": "9167",
"cancelTon": "7116"
}
}
]
}
6 changes: 3 additions & 3 deletions src/test/benchmarks/jetton/results.json
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@
"label": "1.5.3 with reworked JettonWallet",
"pr": "https://github.com/tact-lang/tact/pull/2059",
"gas": {
"transfer": "15884",
"burn": "12701",
"discovery": "7024"
"transfer": "15778",
"burn": "12541",
"discovery": "6230"
}
}
]
Expand Down

0 comments on commit 1908f06

Please sign in to comment.