"Asm.fif" include "TonUtil.fif" include 31 -1<< constant wc_undef 0 constant wc_base -1 constant wc_master { wcid@ 2dup <> swap wc_undef <> and abort"workchain_id already set to another value" wcid! } : setworkchain { globalid@ 2dup <> swap and abort"global_id already set to another value" dup 0= abort"global_id cannot be zero" globalid! } : setglobalid constant empty_cell variable @default-subwallet-id @default-subwallet-id 0! { @default-subwallet-id @ } : default-subwallet-id { @default-subwallet-id ! } : default-subwallet-id! // b x --> b' ( serializes a Gram amount ) { -1 { 1+ 2dup 8 * ufits } until rot over 4 u, -rot 8 * u, } : Gram, // workchain-id -- wc-zero-state { ref, 0 1 u, ref, ref, 0 1 u, b> dup isShardState? not abort"invalid ShardState created" } : mkemptyShardState ' dictnew : Libs{ 'nop : }Libs { 8 config! } : config.version! 1 constant capIhr 2 constant capCreateStats 4 constant capBounceMsgBody 8 constant capReportVersion 16 constant capSplitMergeTransactions 32 constant capShortDequeue // max-validators masterchain-validators min-validators -- { swap rot 16 config! } : config.validator_num! // min-stake max-stake min-total-stake max-factor -- { 4 0 reverse 17 config! } : config.validator_stake_limits! // elected-for elections-begin-before elections-end-before stakes-frozen { 4 0 reverse 15 config! } : config.election_params! variable validator-dict dictnew 0 validator-dict 2! variable validators-weight validators-weight 0! { validator-dict @ second } : validator# { dup 0<= abort"validator weight must be non-negative" 64 ufits not abort"validator weight must fit into 64 bits" } : check-val-weight // ( val-pubkey weight -- c ) { dup check-val-weight over Blen 32 <> abort"validator public key must be 32 bytes long" } : serialize-validator // ( val-pubkey adnl weight -- c ) { dup check-val-weight over 256 ufits not abort"adnl address must fit into 256 bits" rot dup Blen 32 <> abort"validator public key must be 32 bytes long" } : serialize-adnl-validator // ( weight val-cell -- ) { swap validators-weight +! 34 config! } : config.validators! variable workchain-dict // root-hash file-hash enable-utime actual-min-split min-split max-split workchain-id -- { dup isWorkchainDescr? not abort"invalid WorkchainDescr created" s s>c 12 config! } : config.workchains! variable special-dict // special-smc-addr -- { x{} swap special-dict @ 256 udict! not abort"cannot add a new special smart contract" special-dict ! } : make_special { special-dict @ dict>s s>c 31 config! } : config.special! // ( l -- D ) Converts a list of parameter indices into a dictionary { dictnew { swap uncons -rot idict! not abort"cannot add parameter index" over null? } until nip } : param-list-to-dict { param-list-to-dict 9 config! } : config.mandatory_params! { param-list-to-dict 10 config! } : config.critical_params! // min_tot_rounds max_tot_rounds min_wins max_losses min_store_sec max_store_sec bit_price cell_price -- { 8 untuple 8 0 reverse } : cfg-prop-setup // normal-prop-params critical-prop-params -- { swap cfg-prop-setup swap cfg-prop-setup } : make-proposals-setup { make-proposals-setup 11 config! } : config.param_proposals_setup! // deposit bit_pps cell_pps { 3 0 reverse } : create-complaint-pricing { create-complaint-pricing 13 config! } : config.complaint_prices! // bit-pps cell-pps mc-bit-pps mc-cell-pps -- { udict! 0= abort"cannot create storage prices dictionary" 18 config! } : config.storage_prices! { 16 << } : sg* { 16 < } : make-gas-prices-basic // gas_price ... delete_due_limit flat_gas_limit flat_gas_rate -- c { 2dup or { } : make-msg-fwd-prices { make-msg-fwd-prices 24 config! } : config.mc_fwd_prices! { make-msg-fwd-prices 25 config! } : config.fwd_prices! // mc-cc-lifetime sh-cc-lifetime sh-val-lifetime sh-val-num mc-shuffle { 4 1 reverse } : make-catchain-params { make-catchain-params 28 config! } : config.catchain_params! // round-candidates next-cand-delay-ms consensus-timeout-ms fast-attempts attempt-duration cc-max-deps max-block-size max-collated-size new-cc-ids { 8 1 reverse } : make-vsession-params { make-vsession-params 29 config! } : config.consensus_params! // b [underload soft hard] -- b' { untriple 3 roll x{c3} s, 3 roll 32 u, rot 32 u, swap 32 u, } : param_limits, // bytes-limits gas-limits lt-limits -- c { } : make-block-limits { make-block-limits 22 config! } : config.mc_block_limits! { make-block-limits 23 config! } : config.block_limits! // mc-block-create-fee bc-block-create-fee { } : make-block-create-fees { make-block-create-fees 14 config! } : config.block_create_fees! { } : make-smc-addr-cell { make-smc-addr-cell 0 config! } : config.config_smc! { make-smc-addr-cell 1 config! } : config.elector_smc! { make-smc-addr-cell 2 config! } : config.minter_smc! { make-smc-addr-cell 3 config! } : config.collector_smc! { 7 config! } : config.to_mint! 1000000000 constant Gram 1000000 constant mGram 1000 constant uGram 1 constant nGram { Gram * } : Gram* { mGram * } : mGram* { uGram * } : uGram* 'nop : nGram* { Gram swap */r } : Gram*/ { mGram swap */r } : mGram*/ { uGram swap */r } : uGram*/ { /r } : nGram*/ // GR$.17 is equivalent to 170000000 { bl word (number) ?dup 0= abort"not a valid Gram amount" 1- { Gram swap */r } { Gram * } cond 1 'nop } ::_ GR$ { 10 << } : *Ki { 20 << } : *Mi { 30 << } : *Gi { 10 <$ type ." -> " RWCode1 // code // data empty_cell // libs 3 roll // balance 0 // split_depth 0 // ticktock 2 // mode: create register_smc Masterchain swap 6 .Addr cr } : create-wallet1 // pubkey amount { over ."W0 Key " pubkey>$ type space dup .GR ." -> " WCode3 // code // data empty_cell // libs 3 roll // balance 0 0 2 register_smc Masterchain swap 6 .Addr cr } : create-wallet0 // D x t -- D' { idict! not abort"cannot add value" } : rdict-entry { 86400 * } : days* { 365 * days* } : years* // balance -- dict { dictnew over 31 -1<< rdict-entry over 3/4 */ 91 days* rdict-entry over 1/2 */ 183 days* rdict-entry swap 1/4 */ 365 days* rdict-entry 0 548 days* rdict-entry } : make-rdict1 { dictnew over 31 -1<< rdict-entry over .9 */ 0 rdict-entry over .6775 */ 1 years* rdict-entry over .445 */ 2 years* rdict-entry swap .2225 */ 3 years* rdict-entry 0 4 years* 86400 + rdict-entry } : make-rdict2 variable 'make-rdict { 'make-rdict @ execute } : make-rdict variable rwallet-start-at rwallet-start-at 0! now 86400 / 1+ 86400 * rwallet-start-at ! // pubkey amount -- { over ."Key " pubkey>$ type ." -> " RWCode2 // code // data empty_cell // libs 3 roll // balance 0 // split_depth 0 // ticktock 2 // mode: create register_smc Masterchain swap 6 .Addr cr } : create-wallet2 variable rwallet-init-pubkey // pubkey -- addr { RWCode3 // code // data empty_cell // libs 0 // balance 0 0 0 register_smc // compute address only } : precompute-wallet3-addr variable w3-addr // pubkey amount 'rdict -- { 'make-rdict ! over precompute-wallet3-addr w3-addr ! over ."RW3 Key " pubkey>$ type space dup .GR ." -> " RWCode3 // code // data empty_cell // libs 3 roll // balance 0 // split_depth 0 // ticktock w3-addr @ // address 6 // mode: create+setaddr register_smc Masterchain swap 6 .Addr cr } : create-wallet3-internal { ' make-rdict1 create-wallet3-internal } : create-wallet3 { ' make-rdict2 create-wallet3-internal } : create-wallet3b // pubkey amount { over ."Key " pubkey>$ type space dup .GR ." -> " WCode0 // code // data empty_cell // libs 3 roll // balance 0 // split_depth 0 // ticktock 2 // mode: create register_smc Masterchain swap 6 .Addr cr } : create-wallet0a { dup tlb-type-lookup { nip } { "unknown TLB type " swap $+ abort } cond } : $>tlb { bl word $>tlb 1 'nop } ::_ tlb: {