From 579634b6f7d2d9c398ffb35ca25a462b65b9031f Mon Sep 17 00:00:00 2001 From: Gusarich Date: Tue, 12 Mar 2024 16:01:57 +0300 Subject: [PATCH] define constants for reserve modes --- examples/payouts.tact | 2 +- examples/rugpull.tact | 2 +- src/imports/stdlib.ts | 15 +++++++++------ stdlib/std/base.tact | 2 +- stdlib/std/reserve.tact | 9 ++++++++- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/examples/payouts.tact b/examples/payouts.tact index a931604d1..9b2ddf2f6 100644 --- a/examples/payouts.tact +++ b/examples/payouts.tact @@ -29,7 +29,7 @@ contract Beacon with Ownable { require(ctx.sender == self.master, "Invalid sender"); // Reserve funds - nativeReserve(ton("0.1"), 0); + nativeReserve(ton("0.1"), ReserveExact); // Send response if (self.completed) { diff --git a/examples/rugpull.tact b/examples/rugpull.tact index 005f61751..b9385622b 100644 --- a/examples/rugpull.tact +++ b/examples/rugpull.tact @@ -67,7 +67,7 @@ contract RugPull with OwnableTransferable, Stoppable { receive("withdraw") { self.requireOwner(); if (!self.rugpulled) { - nativeReserve(self.balance, 0); + nativeReserve(self.balance, ReserveExact); } send(SendParameters{value: 0, to: self.owner, mode: SendRemainingBalance }); } diff --git a/src/imports/stdlib.ts b/src/imports/stdlib.ts index 2431a8481..6c1d4b2a6 100644 --- a/src/imports/stdlib.ts +++ b/src/imports/stdlib.ts @@ -116,11 +116,12 @@ files['std/base.tact'] = 'Y2sgc3RvcmFnZSBpZiBuZWVkZWQKICAgICAgICBpZiAoc2VsZi5zdG9yYWdlUmVzZXJ2ZSA+IDApIHsgLy8gT3B0aW1pemVkIGluIGNvbXBpbGUtdGltZQogICAgICAg' + 'ICAgICBsZXQgY3R4OiBDb250ZXh0ID0gY29udGV4dCgpOwogICAgICAgICAgICBsZXQgYmFsYW5jZTogSW50ID0gbXlCYWxhbmNlKCk7CiAgICAgICAgICAgIGxldCBi' + 'YWxhbmNlQmVmb3JlTWVzc2FnZTogSW50ID0gYmFsYW5jZSAtIGN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SZXNlcnZlQWxsRXhjZXB0OiBJbnQgPSAxOwpjb25zdCBSZXNlcnZlQXRNb3N0OiBJbnQgPSAyOwpjb25zdCBSZXNlcnZlQWRkT3JpZ2luYWxCYWxhbmNlOiBJ' + + 'bnQgPSA0Owpjb25zdCBSZXNlcnZlSW52ZXJ0U2lnbjogSW50ID0gODsKY29uc3QgUmVzZXJ2ZUJvdW5jZUlmQWN0aW9uRmFpbDogSW50ID0gMTY7'; files['std/send.tact'] = 'QG5hbWUoc2VuZF9yYXdfbWVzc2FnZSkKbmF0aXZlIG5hdGl2ZVNlbmRNZXNzYWdlKGNlbGw6IENlbGwsIG1vZGU6IEludCk7Cgpjb25zdCBTZW5kUmVtYWluaW5nQmFs' + 'YW5jZTogSW50ID0gMTI4Owpjb25zdCBTZW5kUmVtYWluaW5nVmFsdWU6IEludCA9IDY0Owpjb25zdCBTZW5kSWdub3JlRXJyb3JzOiBJbnQgPSAyOwpjb25zdCBTZW5k' + diff --git a/stdlib/std/base.tact b/stdlib/std/base.tact index 781ac4118..2852bdb71 100644 --- a/stdlib/std/base.tact +++ b/stdlib/std/base.tact @@ -25,7 +25,7 @@ trait BaseTrait { let balance: Int = myBalance(); let balanceBeforeMessage: Int = balance - ctx.value; if (balanceBeforeMessage < self.storageReserve) { - nativeReserve(self.storageReserve, 0); + nativeReserve(self.storageReserve, ReserveExact); send(SendParameters{bounce: bounce, to: to, value: 0, mode: SendRemainingBalance + SendIgnoreErrors, body: body, code: code, data: data }); return; } diff --git a/stdlib/std/reserve.tact b/stdlib/std/reserve.tact index 60314aa89..6686bc05b 100644 --- a/stdlib/std/reserve.tact +++ b/stdlib/std/reserve.tact @@ -1,2 +1,9 @@ @name(raw_reserve) -native nativeReserve(amount: Int, mode: Int); \ No newline at end of file +native nativeReserve(amount: Int, mode: Int); + +const ReserveExact: Int = 0; +const ReserveAllExcept: Int = 1; +const ReserveAtMost: Int = 2; +const ReserveAddOriginalBalance: Int = 4; +const ReserveInvertSign: Int = 8; +const ReserveBounceIfActionFail: Int = 16; \ No newline at end of file