Browse Source

Displaying the event logs

master
Lev 2 years ago
parent
commit
af42869997
  1. 2
      sources/constants.tact
  2. 1
      sources/jetton.tact
  3. 6
      sources/jetton_trait.tact
  4. BIN
      sources/output/jetton_TONB.code.boc
  5. 12
      sources/output/jetton_TONB.code.fc
  6. 49
      sources/output/jetton_TONB.code.fif
  7. 74
      sources/output/jetton_TONB.code.rev.fif
  8. 2
      sources/output/jetton_TONB.md
  9. 2
      sources/output/jetton_TONB.pkg
  10. 4
      sources/output/jetton_TONB.ts
  11. 18
      sources/staking.tact
  12. 36
      sources/tests/__snapshots__/jetton.spec.ts.snap
  13. 37
      sources/tests/jetton.spec.ts
  14. 93
      sources/utils/helpers.ts

2
sources/constants.tact

@ -1,6 +1,6 @@
const gas_consumption: Int = ton("0.01"); const gas_consumption: Int = ton("0.01");
const withdraw_gas_consumption: Int = ton("0.1"); const withdraw_gas_consumption: Int = ton("0.15");
const deposit_gas_consumption: Int = ton("0.01"); // Gas consumption during processing const deposit_gas_consumption: Int = ton("0.01"); // Gas consumption during processing
const linker_credit: Int = ton("0.02"); // TON to send to the linker for the fees const linker_credit: Int = ton("0.02"); // TON to send to the linker for the fees
const wallet_credit: Int = ton("0.065"); // TON to send to the wallet for the fees const wallet_credit: Int = ton("0.065"); // TON to send to the wallet for the fees

1
sources/jetton.tact

@ -29,6 +29,7 @@ contract TONB with TONBTrait {
staking_pool: Address?; staking_pool: Address?;
in_the_pool: Int = 0; in_the_pool: Int = 0;
withdrawal_requests: WithdrawalRequests; withdrawal_requests: WithdrawalRequests;
requested_withdrawal: Int = 0;
init(owner: Address, content: Cell?, staking_pool: Address?) { init(owner: Address, content: Cell?, staking_pool: Address?) {
self.totalSupply = 0; self.totalSupply = 0;

6
sources/jetton_trait.tact

@ -23,6 +23,7 @@ trait TONBTrait with Ownable, StakingTrait {
staking_pool: Address?; staking_pool: Address?;
in_the_pool: Int = 0; in_the_pool: Int = 0;
withdrawal_requests: WithdrawalRequests; withdrawal_requests: WithdrawalRequests;
requested_withdrawal: Int = 0;
// //
@ -72,14 +73,15 @@ trait TONBTrait with Ownable, StakingTrait {
mode: SendRemainingValue, mode: SendRemainingValue,
body: body body: body
}); });
self.requestWithdrawal(msg.owner, diff); let ctx: Context = context();
self.requestWithdrawal(ctx.sender, diff);
return; return;
} }
// Withdraw // Withdraw
send(SendParameters{ send(SendParameters{
to: msg.owner, to: msg.owner,
value: msg.amount, value: msg.amount - withdraw_gas_consumption,
bounce: false bounce: false
}); });
} }

BIN
sources/output/jetton_TONB.code.boc

Binary file not shown.

12
sources/output/jetton_TONB.code.fc

@ -561,7 +561,7 @@ _ $__gen_get_owner() method_id(83229) {
var ($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests)) = $self; var ($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests)) = $self;
var ($msg'amount) = $msg; var ($msg'amount) = $msg;
var ($ctx'bounced, $ctx'sender, $ctx'value, $ctx'raw) = __tact_context_get(); var ($ctx'bounced, $ctx'sender, $ctx'value, $ctx'raw) = __tact_context_get();
throw_unless(6384, ($ctx'value >= 100000000)); throw_unless(6384, ($ctx'value >= 150000000));
($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests))~$__gen_TONB_burn($ctx'sender, $msg'amount, $ctx'sender); ($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests))~$__gen_TONB_burn($ctx'sender, $msg'amount, $ctx'sender);
return (($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests)), ()); return (($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests)), ());
} }
@ -586,17 +586,18 @@ _ $__gen_get_owner() method_id(83229) {
var ($msg'queryId, $msg'amount, $msg'owner, $msg'responseAddress) = $msg; var ($msg'queryId, $msg'amount, $msg'owner, $msg'responseAddress) = $msg;
($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests))~$__gen_TONB_requireWallet($msg'owner); ($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests))~$__gen_TONB_requireWallet($msg'owner);
$self'totalSupply = ($self'totalSupply - $msg'amount); $self'totalSupply = ($self'totalSupply - $msg'amount);
int $available = ((__tact_my_balance() - 500000000) - 100000000); int $available = ((__tact_my_balance() - 500000000) - 150000000);
if (($available < $msg'amount)) { if (($available < $msg'amount)) {
int $diff = ($msg'amount - $available); int $diff = ($msg'amount - $available);
$send((false, $msg'owner, (__tact_my_balance() - 500000000), 0, null(), null(), null())); $send((false, $msg'owner, (__tact_my_balance() - 500000000), 0, null(), null(), null()));
cell $body = __gen_writecell_TokenTransferInternal((0, $diff, my_address(), my_address(), 0, $emptySlice(), null(), null())); cell $body = __gen_writecell_TokenTransferInternal((0, $diff, my_address(), my_address(), 0, $emptySlice(), null(), null()));
slice $walletAddress = $__gen_TONB_get_wallet_address(($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests)), $msg'owner); slice $walletAddress = $__gen_TONB_get_wallet_address(($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests)), $msg'owner);
$send((false, $walletAddress, 0, 64, $body, null(), null())); $send((false, $walletAddress, 0, 64, $body, null(), null()));
($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests))~$__gen_TONB_requestWithdrawal($msg'owner, $diff); var ($ctx'bounced, $ctx'sender, $ctx'value, $ctx'raw) = __tact_context_get();
($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests))~$__gen_TONB_requestWithdrawal($ctx'sender, $diff);
return (($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests)), ()); return (($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests)), ());
} }
$send((false, $msg'owner, $msg'amount, 0, null(), null(), null())); $send((false, $msg'owner, ($msg'amount - 150000000), 0, null(), null(), null()));
return (($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests)), ()); return (($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests)), ());
} }
@ -631,7 +632,8 @@ _ $__gen_get_owner() method_id(83229) {
var ($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests)) = $self; var ($self'totalSupply, $self'owner, $self'content, $self'mintable, $self'first_linker, $self'last_linker, $self'n_linkers, $self'staking_pool, $self'in_the_pool, ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests)) = $self;
int $i = 0; int $i = 0;
while (($i < $self'withdrawal_requests'n_requests)) { while (($i < $self'withdrawal_requests'n_requests)) {
$send((true, __tact_not_null(__tact_dict_get_int_slice($self'withdrawal_requests'addresses, 257, $i)), __tact_not_null(__tact_dict_get_int_int($self'withdrawal_requests'amounts, 257, $i, 257)), 0, null(), null(), null())); slice $addr = __tact_not_null(__tact_dict_get_int_slice($self'withdrawal_requests'addresses, 257, $i));
$send((false, $addr, 80000000, 0, __gen_writecell_TokenBurn((0, __tact_not_null(__tact_dict_get_int_int($self'withdrawal_requests'amounts, 257, $i, 257)), $addr, my_address())), null(), null()));
$i = ($i + 1); $i = ($i + 1);
} }
($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests) = (null(), null(), 0); ($self'withdrawal_requests'addresses, $self'withdrawal_requests'amounts, $self'withdrawal_requests'n_requests) = (null(), null(), 0);

49
sources/output/jetton_TONB.code.fif

@ -986,7 +986,7 @@ PROGRAM{
DROP DROP
6384 PUSHINT 6384 PUSHINT
s3 POP s3 POP
100000000 PUSHINT 150000000 PUSHINT
GEQ GEQ
s1 s2 XCHG s1 s2 XCHG
THROWANYIFNOT THROWANYIFNOT
@ -1015,7 +1015,7 @@ PROGRAM{
__tact_my_balance INLINECALLDICT __tact_my_balance INLINECALLDICT
500000000 PUSHINT 500000000 PUSHINT
SUB SUB
100000000 PUSHINT 150000000 PUSHINT
SUB SUB
s0 s13 PUSH2 s0 s13 PUSH2
LESS LESS
@ -1042,21 +1042,28 @@ PROGRAM{
PUSHNULL PUSHNULL
PUSHNULL PUSHNULL
__gen_writecell_TokenTransferInternal INLINECALLDICT __gen_writecell_TokenTransferInternal INLINECALLDICT
s13 s11 s10 PUSH3 s13 s11 s(-2) PU2XC
s12 s11 s10 PUSH3 s12 s11 s(-2) PU2XC
s12 s11 s10 PUSH3 s12 s11 s(-2) PU2XC
s12 s11 PUSH2 s12 s11 s(-2) PU2XC
s12 s11 s(-2) PU2XC
s12 s(-1) PUXC
23 s() PUSH 23 s() PUSH
26 s() PUSH SWAP
s0 26 s() XCHG
$__gen_TONB_get_wallet_address INLINECALLDICT $__gen_TONB_get_wallet_address INLINECALLDICT
FALSE FALSE
s0 s2 XCHG s0 s2 XCHG
0 PUSHINT 0 PUSHINT
64 PUSHINT 64 PUSHINT
ROT ROT
s0 17 s() XCHG
PUSHNULL PUSHNULL
PUSHNULL PUSHNULL
$send INLINECALLDICT $send INLINECALLDICT
__tact_context_get INLINECALLDICT
s2 s3 XCHG
3 BLKDROP
s12 s13 XCHG s12 s13 XCHG
s10 s12 XCHG s10 s12 XCHG
s9 s11 XCHG s9 s11 XCHG
@ -1066,13 +1073,16 @@ PROGRAM{
s5 s7 XCHG s5 s7 XCHG
s4 s6 XCHG s4 s6 XCHG
s3 s5 XCHG s3 s5 XCHG
s4 s3 s0 XCHG3 s4 s0 s3 XCHG3
s1 s2 XCHG s0 s2 XCHG
$__gen_TONB_requestWithdrawal INLINECALLDICT $__gen_TONB_requestWithdrawal INLINECALLDICT
}>ELSE<{ }>ELSE<{
DROP DROP
FALSE FALSE
s0 s14 s13 XCHG3 s0 s13 XCHG
150000000 PUSHINT
SUB
s13 s14 s0 XCHG3
0 PUSHINT 0 PUSHINT
PUSHNULL PUSHNULL
PUSHNULL PUSHNULL
@ -1170,19 +1180,24 @@ PROGRAM{
s0 s1 PUSH2 s0 s1 PUSH2
LESS LESS
}>DO<{ }>DO<{
TRUE
s4 PUSH
257 PUSHINT
s3 PUSH s3 PUSH
257 PUSHINT
s2 PUSH
__tact_dict_get_int_slice INLINECALLDICT __tact_dict_get_int_slice INLINECALLDICT
__tact_not_null INLINECALLDICT __tact_not_null INLINECALLDICT
FALSE
80000000 PUSHINT
0 PUSHINT
DUP
257 PUSHINT 257 PUSHINT
s5 s(-1) s(-1) PUXCPU s8 s(-1) s(-1) PUXCPU
s5 s(-1) PUXC s8 s(-1) PUXC
__tact_dict_get_int_int INLINECALLDICT __tact_dict_get_int_int INLINECALLDICT
__tact_not_null INLINECALLDICT __tact_not_null INLINECALLDICT
0 PUSHINT MYADDR
PUSHNULL s6 s(-1) PUXC
__gen_writecell_TokenBurn INLINECALLDICT
s3 s4 XCHG
PUSHNULL PUSHNULL
PUSHNULL PUSHNULL
$send INLINECALLDICT $send INLINECALLDICT

74
sources/output/jetton_TONB.code.rev.fif

@ -1187,7 +1187,7 @@ SETCP0
s0 POP s0 POP
6384 PUSHINT 6384 PUSHINT
s3 POP s3 POP
100000000 PUSHINT 150000000 PUSHINT
GEQ GEQ
s1 s2 XCHG s1 s2 XCHG
THROWANYIFNOT THROWANYIFNOT
@ -2125,14 +2125,17 @@ SETCP0
0 INDEX 0 INDEX
500000000 PUSHINT 500000000 PUSHINT
SUB SUB
100000000 PUSHINT 150000000 PUSHINT
SUB SUB
s0 s13 PUSH2 s0 s13 PUSH2
LESS LESS
<{ <{
s0 POP s0 POP
0 PUSHINT 0 PUSHINT
s0 s14 s13 XCHG3 s0 s13 XCHG
150000000 PUSHINT
SUB
s13 s14 s0 XCHG3
0 PUSHINT 0 PUSHINT
PUSHNULL PUSHNULL
PUSHNULL PUSHNULL
@ -2489,12 +2492,15 @@ SETCP0
}> CALLREF }> CALLREF
ENDC ENDC
}> CALLREF }> CALLREF
13 11 10 PUSH3 13 11 -2 PU2XC
12 11 10 PUSH3 12 11 -2 PU2XC
12 11 10 PUSH3 12 11 -2 PU2XC
s12 s11 PUSH2 12 11 -2 PU2XC
12 11 -2 PU2XC
s12 s-1 PUXC
s23 PUSH s23 PUSH
s26 PUSH s0 s1 XCHG
s0 s26 XCHG
<{ <{
<{ <{
2 GETGLOBVAR 2 GETGLOBVAR
@ -2540,6 +2546,7 @@ SETCP0
0 PUSHINT 0 PUSHINT
64 PUSHINT 64 PUSHINT
ROT ROT
s0 s17 XCHG
PUSHNULL PUSHNULL
PUSHNULL PUSHNULL
<{ <{
@ -2668,6 +2675,10 @@ SETCP0
s0 s1 XCHG s0 s1 XCHG
SENDRAWMSG SENDRAWMSG
}> CALLREF }> CALLREF
1 GETGLOBVAR
4 UNTUPLE
s2 s3 XCHG
3 BLKDROP
s12 s13 XCHG s12 s13 XCHG
s10 s12 XCHG s10 s12 XCHG
s9 s11 XCHG s9 s11 XCHG
@ -2677,8 +2688,8 @@ SETCP0
s5 s7 XCHG s5 s7 XCHG
s4 s6 XCHG s4 s6 XCHG
s3 s5 XCHG s3 s5 XCHG
s4 s3 s0 XCHG3 s4 s0 s3 XCHG3
s1 s2 XCHG s0 s2 XCHG
<{ <{
s1 s4 XCHG s1 s4 XCHG
257 PUSHINT 257 PUSHINT
@ -4128,10 +4139,9 @@ SETCP0
LESS LESS
}> PUSHCONT }> PUSHCONT
<{ <{
-1 PUSHINT
s4 PUSH
257 PUSHINT
s3 PUSH s3 PUSH
257 PUSHINT
s2 PUSH
ROTREV ROTREV
DICTIGET DICTIGET
NULLSWAPIFNOT NULLSWAPIFNOT
@ -4143,9 +4153,13 @@ SETCP0
s0 PUSH s0 PUSH
ISNULL ISNULL
128 THROWIF 128 THROWIF
0 PUSHINT
80000000 PUSHINT
0 PUSHINT
s0 PUSH
257 PUSHINT 257 PUSHINT
5 -1 -1 PUXCPU 8 -1 -1 PUXCPU
s5 s-1 PUXC s8 s-1 PUXC
s1 s3 s3 XCHG3 s1 s3 s3 XCHG3
DICTIGET DICTIGET
NULLSWAPIFNOT NULLSWAPIFNOT
@ -4162,8 +4176,36 @@ SETCP0
s0 PUSH s0 PUSH
ISNULL ISNULL
128 THROWIF 128 THROWIF
MYADDR
s6 s-1 PUXC
<{
NEWC
4 1 BLKSWAP
1499400124 PUSHINT
s0 s5 XCHG2
32 STU
s1 s3 XCHG
64 STU
s0 s1 XCHG
STGRAMS
s0 s1 XCHG
STSLICER
s0 s1 XCHG
s0 PUSH
ISNULL
<{
s0 POP
0 PUSHINT 0 PUSHINT
PUSHNULL s0 s1 XCHG
2 STU
}> PUSHCONT
<{
STSLICER
}> PUSHCONT
IFELSE
ENDC
}> CALLREF
s3 s4 XCHG
PUSHNULL PUSHNULL
PUSHNULL PUSHNULL
<{ <{

2
sources/output/jetton_TONB.md

@ -1,6 +1,6 @@
# TACT Compilation Report # TACT Compilation Report
Contract: TONB Contract: TONB
BOC Size: 3785 bytes BOC Size: 3825 bytes
# Types # Types
Total Types: 30 Total Types: 30

2
sources/output/jetton_TONB.pkg

File diff suppressed because one or more lines are too long

4
sources/output/jetton_TONB.ts

File diff suppressed because one or more lines are too long

18
sources/staking.tact

@ -38,6 +38,7 @@ trait StakingTrait {
withdrawal_requests: WithdrawalRequests; withdrawal_requests: WithdrawalRequests;
owner: Address; owner: Address;
in_the_pool: Int = 0; in_the_pool: Int = 0;
requested_withdrawal: Int = 0;
fun sendStake() { fun sendStake() {
if(self.staking_pool == null) { if(self.staking_pool == null) {
@ -62,12 +63,25 @@ trait StakingTrait {
receive("Withdraw completed") { receive("Withdraw completed") {
let i: Int = 0; let i: Int = 0;
while(i < self.withdrawal_requests.n_requests) { while(i < self.withdrawal_requests.n_requests) {
let addr: Address = self.withdrawal_requests.addresses.get(i)!!;
send(SendParameters{ send(SendParameters{
to: self.withdrawal_requests.addresses.get(i)!!, to: addr,
value: self.withdrawal_requests.amounts.get(i)!! value: ton("0.08"),
bounce: false,
body: TokenBurn{
amount: self.withdrawal_requests.amounts.get(i)!!,
queryId: 0,
responseAddress: myAddress(),
owner: addr
}.toCell()
}); });
i = i + 1; i = i + 1;
} }
let ctx: Context = context();
let val: Int = ctx.value;
self.in_the_pool = self.in_the_pool - val;
self.requested_withdrawal = self.requested_withdrawal - val;
let profit: Int = self.in_the_pool - self.requested_withdrawal;
// todo: send profit to the foundation (owner) // todo: send profit to the foundation (owner)
self.withdrawal_requests = WithdrawalRequests{ self.withdrawal_requests = WithdrawalRequests{
addresses: emptyMap(), addresses: emptyMap(),

36
sources/tests/__snapshots__/jetton.spec.ts.snap

@ -8,14 +8,14 @@ exports[`jetton should deploy and deposit the wallet with the correct sum of mon
{ {
"message": { "message": {
"body": { "body": {
"cell": "x{21EEB60743B9ACA00}", "cell": "x{21EEB6075174876E800}",
"type": "cell", "type": "cell",
}, },
"bounce": true, "bounce": true,
"from": "kQAI-3FJVc_ywSuY4vq0bYrzR7S4Och4y7bTU_i5yLOB3A6P", "from": "kQAI-3FJVc_ywSuY4vq0bYrzR7S4Och4y7bTU_i5yLOB3A6P",
"to": "kQDN21ZUuydn_R7jdQECoGikDdJkC5lERbPzQ8-F4wkV3B1S", "to": "kQDqdXWdE6QCwdIav5vKbWisgRNKQ1foZIJEUAP4WR9CNPfy",
"type": "internal", "type": "internal",
"value": 1200000000n, "value": 100200000000n,
}, },
"type": "received", "type": "received",
}, },
@ -31,8 +31,8 @@ exports[`jetton should deploy and deposit the wallet with the correct sum of mon
"type": "cell", "type": "cell",
}, },
"bounce": false, "bounce": false,
"from": "kQDN21ZUuydn_R7jdQECoGikDdJkC5lERbPzQ8-F4wkV3B1S", "from": "kQDqdXWdE6QCwdIav5vKbWisgRNKQ1foZIJEUAP4WR9CNPfy",
"to": "kQCD0xDqEk8PMauelTY9tsV1vLLY_ZKxdKkX65ZI2UWtHyp0", "to": "kQCFWdZkHt68RZzf5yLYgur4jRtW4Ns8l6N2S1t8g0MDPRv7",
"type": "internal", "type": "internal",
"value": 11365000n, "value": 11365000n,
}, },
@ -43,15 +43,15 @@ exports[`jetton should deploy and deposit the wallet with the correct sum of mon
"messages": [ "messages": [
{ {
"body": { "body": {
"cell": "x{178D4519000000000000000043B9ACA008019BB6ACA9764ECFFA3DC6EA020540D1481BA4C81732888B67E6879F0BC6122BB900023EDC525573FCB04AE638BEAD1B62BCD1ED2E0E721E32EDB4D4FE2E722CE07702_} "cell": "x{178D451900000000000000005174876E800801D4EAEB3A27480583A4357F3794DAD15902269486AFD0C90488A007F0B23E846900023EDC525573FCB04AE638BEAD1B62BCD1ED2E0E721E32EDB4D4FE2E722CE07702_}
x{800000000000000000000000000000000000000000000000000000000000000020041E9887509278798D5CF4A9B1EDB62BADE596C7EC958BA548BF5CB246CA2D68FC_}", x{800000000000000000000000000000000000000000000000000000000000000020042ACEB320F6F5E22CE6FF3916C41757C468DAB706D9E4BD1BB25ADBE41A1819EC_}",
"type": "cell", "type": "cell",
}, },
"bounce": false, "bounce": false,
"from": "kQDN21ZUuydn_R7jdQECoGikDdJkC5lERbPzQ8-F4wkV3B1S", "from": "kQDqdXWdE6QCwdIav5vKbWisgRNKQ1foZIJEUAP4WR9CNPfy",
"to": "kQCW8uN7SGXO3Ev7zU3ufBOBwpfqwb6QByAZqYWUs_cmSweE", "to": "kQDx8Kg9QTHxou3cHUjl5yisUuHcdW3SO_r2k2KOX9WImtuB",
"type": "internal", "type": "internal",
"value": 41723000n, "value": 41715000n,
}, },
], ],
"type": "sent", "type": "sent",
@ -69,7 +69,7 @@ exports[`jetton should work correctly with the staking 1`] = `
}, },
"bounce": true, "bounce": true,
"from": "kQAI-3FJVc_ywSuY4vq0bYrzR7S4Och4y7bTU_i5yLOB3A6P", "from": "kQAI-3FJVc_ywSuY4vq0bYrzR7S4Och4y7bTU_i5yLOB3A6P",
"to": "kQABS2GwT2RO_ayCOq1syTehl_0YJs6awEj1KGZidNqtt7wR", "to": "kQC4vZPVA2qqBA7kJfq6yPGv9VBb7MJOvNfJlDxWkagnBO9K",
"type": "internal", "type": "internal",
"value": 100200000000n, "value": 100200000000n,
}, },
@ -87,8 +87,8 @@ exports[`jetton should work correctly with the staking 1`] = `
"type": "cell", "type": "cell",
}, },
"bounce": false, "bounce": false,
"from": "kQABS2GwT2RO_ayCOq1syTehl_0YJs6awEj1KGZidNqtt7wR", "from": "kQC4vZPVA2qqBA7kJfq6yPGv9VBb7MJOvNfJlDxWkagnBO9K",
"to": "kQDXemLuELhIqpFvUfQjvfbkWV9Xd8h4_e2ejxaVkSDM6zJM", "to": "kQDTmzk2GN2cZRr-uIAU5a489Ziwu2Y4dAhQJQizU27oGL-G",
"type": "internal", "type": "internal",
"value": 11365000n, "value": 11365000n,
}, },
@ -99,13 +99,13 @@ exports[`jetton should work correctly with the staking 1`] = `
"messages": [ "messages": [
{ {
"body": { "body": {
"cell": "x{178D451900000000000000005174876E8008000296C3609EC89DFB5904755AD9926F432FFA304D9D358091EA50CCC4E9B55B6F00023EDC525573FCB04AE638BEAD1B62BCD1ED2E0E721E32EDB4D4FE2E722CE07702_} "cell": "x{178D451900000000000000005174876E800801717B27AA06D554081DC84BF57591E35FEAA0B7D9849D79AF932878AD23504E0900023EDC525573FCB04AE638BEAD1B62BCD1ED2E0E721E32EDB4D4FE2E722CE07702_}
x{80000000000000000000000000000000000000000000000000000000000000002006BBD3177085C245548B7A8FA11DEFB722CAFABBBE43C7EF6CF478B4AC8906675C_}", x{800000000000000000000000000000000000000000000000000000000000000020069CD9C9B0C6ECE328D7F5C400A72D71E7ACC585DB31C3A0428128459A9B7740C4_}",
"type": "cell", "type": "cell",
}, },
"bounce": false, "bounce": false,
"from": "kQABS2GwT2RO_ayCOq1syTehl_0YJs6awEj1KGZidNqtt7wR", "from": "kQC4vZPVA2qqBA7kJfq6yPGv9VBb7MJOvNfJlDxWkagnBO9K",
"to": "kQB-9Tm-Ms2IjYzp3kNadOgg6-b1SOP8HvOzjvGbmSmaHo12", "to": "kQC1V2Z4YfN7Y2o-d8DsuDYH2YKYJ2fJpLzmN_yMFf-Efy9L",
"type": "internal", "type": "internal",
"value": 41715000n, "value": 41715000n,
}, },
@ -120,7 +120,7 @@ exports[`jetton should work correctly with the staking 1`] = `
"type": "cell", "type": "cell",
}, },
"bounce": true, "bounce": true,
"from": "kQABS2GwT2RO_ayCOq1syTehl_0YJs6awEj1KGZidNqtt7wR", "from": "kQC4vZPVA2qqBA7kJfq6yPGv9VBb7MJOvNfJlDxWkagnBO9K",
"to": "kQB6IAwD4Haze61PlYJmyim_0AB0bs-PNhn8XOUwnkMnEcnp", "to": "kQB6IAwD4Haze61PlYJmyim_0AB0bs-PNhn8XOUwnkMnEcnp",
"type": "internal", "type": "internal",
"value": 99491421000n, "value": 99491421000n,

37
sources/tests/jetton.spec.ts

@ -5,6 +5,7 @@ import { default_content } from '../utils/config';
import { TONBWallet } from '../output/jetton_TONBWallet'; import { TONBWallet } from '../output/jetton_TONBWallet';
import { beginCell } from 'ton-core'; import { beginCell } from 'ton-core';
import { PseudoStaking } from '../output/jetton_PseudoStaking'; import { PseudoStaking } from '../output/jetton_PseudoStaking';
import { logEvents } from "../utils/helpers";
@ -18,7 +19,7 @@ describe('jetton', () => {
let tracker = system.track(contract.address); let tracker = system.track(contract.address);
// Mint // Mint
await contract.send(owner, { value: toNano('1.2') }, { $$type: 'Deposit', amount: toNano('1') }); await contract.send(owner, { value: toNano('100.2') }, { $$type: 'Deposit', amount: toNano('100') });
let log = await system.run(); let log = await system.run();
let events = tracker.events(); let events = tracker.events();
expect(events).toMatchSnapshot(); expect(events).toMatchSnapshot();
@ -26,7 +27,7 @@ describe('jetton', () => {
let addr = Address.parse((events[4] as any).messages[0].to); let addr = Address.parse((events[4] as any).messages[0].to);
let wallet_contract = system.contract(addr); let wallet_contract = system.contract(addr);
let wdata = ((await wallet_contract.get(97026, [])) as any).stack.items; let wdata = ((await wallet_contract.get(97026, [])) as any).stack.items;
expect(wdata[0].value).toEqual(1000000000n); expect(wdata[0].value).toEqual(100000000000n);
let linker_contract = system.contract(Address.parse((events[3] as any).messages[0].to)); let linker_contract = system.contract(Address.parse((events[3] as any).messages[0].to));
let linker_owner = ((await linker_contract.get('owner', [])) as any).stack.items[0]; let linker_owner = ((await linker_contract.get('owner', [])) as any).stack.items[0];
@ -36,10 +37,10 @@ describe('jetton', () => {
expect((await contract.getOwner()).toString()).toEqual(owner.address.toString()); expect((await contract.getOwner()).toString()).toEqual(owner.address.toString());
// Withdraw // Withdraw
await contract.send(owner, { value: toNano('0.15') }, { $$type: 'Withdraw', amount: toNano('0.3') }); await contract.send(owner, { value: toNano('0.15') }, { $$type: 'Withdraw', amount: toNano('20') });
log = await system.run(); log = await system.run();
events = tracker.events(); events = tracker.events();
expect((events[5] as any).messages[0].value).toBeGreaterThan(toNano('0.29')); expect((events[5] as any).messages[0].value).toBeGreaterThan(toNano('19'));
}); });
@ -55,7 +56,7 @@ describe('jetton', () => {
let tracker = system.track(contract.address); let tracker = system.track(contract.address);
// Mint - The contract should stake the money // Mint - The contract should stake the money
await contract.send(owner, { value: toNano('100.2') }, { $$type: 'Deposit', amount: toNano('100') }); await contract.send(owner, { value: toNano('100.2') }, { $$type: 'Deposit', amount: toNano('100') });
let log = await system.run(); await system.run();
let events = tracker.events(); let events = tracker.events();
// console.log(events) // console.log(events)
expect(events).toMatchSnapshot(); expect(events).toMatchSnapshot();
@ -63,10 +64,30 @@ describe('jetton', () => {
// Try to withdraw // Try to withdraw
await contract.send(owner, { value: toNano('0.15') }, { $$type: 'Withdraw', amount: toNano('50') }); await contract.send(owner, { value: toNano('0.15') }, { $$type: 'Withdraw', amount: toNano('50') });
await system.run(); let log = await system.run();
events = tracker.events(); events = tracker.events();
// console.log(events); // console.log(log)
expect((events[events.length - 1] as any).messages[0].value).toBeGreaterThan(49000000000n); // console.log((events[7] as any).messages[0])
let addressBook_rev = {'wallet': (events[6] as any).messages[0].to,
'staking': (events[7] as any).messages[0].to, 'tonb': (events[0] as any).message.to, 'owner': (events[0] as any).message.from};
// reverse keys and values
let addressBook = Object.fromEntries(Object.entries(addressBook_rev).map(([key, value]) => [value, key]));
// console.log("wallet:", (events[6] as any).messages[0].to)
// console.log("staking:", (events[7] as any).messages[0].to)
logEvents(events, addressBook);
let found_transaction = false;
for (let i = 0; i < events.length; i++) {
if (events[i].type == 'sent') {
if ((events[i] as any).messages[0].to == addressBook_rev['owner']) {
if ((events[i] as any).messages[0].value>49000000000n) {
found_transaction = true;
}
}
}
}
expect(found_transaction).toBeTruthy();
// expect((events[events.length - 1] as any).messages[0].value).toBeGreaterThan(49000000000n);
}); });
it('should correctly work with transfers', async () => { it('should correctly work with transfers', async () => {

93
sources/utils/helpers.ts

@ -1,7 +1,10 @@
import { Sha256 } from "@aws-crypto/sha256-js"; import { Sha256 } from "@aws-crypto/sha256-js";
import { beginCell, Cell, Address } from "ton"; import { beginCell, Cell, Address } from "ton";
import { Dictionary } from "ton-core"; import { BitString, Dictionary } from "ton-core";
import Prando from "prando"; import Prando from "prando";
import { TrackedMessage } from "ton-emulator/dist/events/message";
import { TrackedBody } from "ton-emulator/dist/events/message";
import { types } from '../output/types.json';
const ONCHAIN_CONTENT_PREFIX = 0x00; const ONCHAIN_CONTENT_PREFIX = 0x00;
@ -75,3 +78,91 @@ export function randomAddress(seed: string, workchain?: number) {
} }
return new Address(workchain ?? 0, hash); return new Address(workchain ?? 0, hash);
} }
export function fmtMessage(message: TrackedMessage, addressBook: any) {
let from = (message as any).from;
let to = message.to;
let value_bi: BigInt = (message as any).value;
let value = 0;
if (value_bi) {
// convert to number
value = Number(value_bi) / TON();
}
let body_t: TrackedBody | undefined | null = (message as any).body;
if (body_t === undefined) {
body_t = null;
}
let body = "<boc>";
if (body_t?.type == 'cell') {
// let c = Cell.fromBoc(Buffer.from(body_t.cell, 'base64'))[0];
// body_t.cell is like x{<boc>} ...
// we need to get everything up to } and after {
let boc = body_t.cell.slice(2, body_t.cell.indexOf('}')).slice(0, 120);
let c = new Cell({bits: new BitString(Buffer.from(boc, 'base64'), 0, boc.length * 8)});
// let c = new Cell({bits: BitString(boc)});
let op = c.beginParse().loadUint(32);
let msg_type = 'unknown';
for (let t of types) {
if (t.header == op) {
msg_type = t.name;
break;
}
}
body = msg_type;
}
if (body.length % 2 == 1) {
body += ' ';
}
while (body.length < 30) {
body = ' ' + body + ' ';
}
if (addressBook[from]) {
from = addressBook[from];
// add spaces so that length is 11
while (from.length < 11) {
from += ' ';
}
} else {
// slice first 4 symbols, ..., and last 4 symbols
from = from.slice(0, 4) + '...' + from.slice(-4);
}
if (to && addressBook[to]) {
to = addressBook[to];
// add spaces so that length is 11
while (to?.length as number < 11) {
to += ' ';
}
} else {
// slice first 4 symbols, ..., and last 4 symbols
to = to?.slice(0, 4) + '...' + to?.slice(-4);
}
return `${from} --> ${to} ${value.toFixed(3)} ${body}`;
}
export function fmtEvent(ev: any, addressBook: any) {
if (ev.type == 'received') {
return fmtMessage(ev.message, addressBook);
}
if (ev.type == 'sent-bounced') {
return `Bounced ${fmtMessage(ev.message, addressBook)}`;
}
if (ev.type == 'sent') {
let res = '';
for (let m of ev.messages) {
res += fmtMessage(m, addressBook) + '\n';
}
return res.trim();
}
if (ev.type == 'failed') {
return `Failed ${ev.errorCode}`;
}
return '';
}
export function logEvents(events: any[], addressBook: any) {
let res = '';
for (let ev of events) {
res += fmtEvent(ev, addressBook) + '\n';
}
console.log(res)
}

Loading…
Cancel
Save