Skip to content

Commit

Permalink
feat[stdlib]: define constants for reserve modes (#173)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gusarich authored Mar 25, 2024
1 parent cd34466 commit e0a3288
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion examples/payouts.tact
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion examples/rugpull.tact
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
Expand Down
15 changes: 9 additions & 6 deletions src/imports/stdlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,12 @@ files['std/base.tact'] =
'Y2sgc3RvcmFnZSBpZiBuZWVkZWQKICAgICAgICBpZiAoc2VsZi5zdG9yYWdlUmVzZXJ2ZSA+IDApIHsgLy8gT3B0aW1pemVkIGluIGNvbXBpbGUtdGltZQogICAgICAg' +
'ICAgICBsZXQgY3R4OiBDb250ZXh0ID0gY29udGV4dCgpOwogICAgICAgICAgICBsZXQgYmFsYW5jZTogSW50ID0gbXlCYWxhbmNlKCk7CiAgICAgICAgICAgIGxldCBi' +
'YWxhbmNlQmVmb3JlTWVzc2FnZTogSW50ID0gYmFsYW5jZSAtIGN0eC52YWx1ZTsKICAgICAgICAgICAgaWYgKGJhbGFuY2VCZWZvcmVNZXNzYWdlIDwgc2VsZi5zdG9y' +
'YWdlUmVzZXJ2ZSkgewogICAgICAgICAgICAgICAgbmF0aXZlUmVzZXJ2ZShzZWxmLnN0b3JhZ2V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52ZXJ0U2lnbjogSW50ID0gODsKY29uc3QgUmVzZXJ2ZUJvdW5jZUlmQWN0aW9uRmFpbDogSW50ID0gMTY7';
files['std/send.tact'] =
'QG5hbWUoc2VuZF9yYXdfbWVzc2FnZSkKbmF0aXZlIG5hdGl2ZVNlbmRNZXNzYWdlKGNlbGw6IENlbGwsIG1vZGU6IEludCk7Cgpjb25zdCBTZW5kUmVtYWluaW5nQmFs' +
'YW5jZTogSW50ID0gMTI4Owpjb25zdCBTZW5kUmVtYWluaW5nVmFsdWU6IEludCA9IDY0Owpjb25zdCBTZW5kSWdub3JlRXJyb3JzOiBJbnQgPSAyOwpjb25zdCBTZW5k' +
Expand Down
2 changes: 1 addition & 1 deletion stdlib/std/base.tact
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 8 additions & 1 deletion stdlib/std/reserve.tact
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
@name(raw_reserve)
native nativeReserve(amount: Int, mode: Int);
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;

0 comments on commit e0a3288

Please sign in to comment.