16 #include <tvm/schema/message.hpp>
17 #include <tvm/sequence.hpp>
18 #include <tvm/small_dict_map.hpp>
20 #include <tvm/replay_attack_protection/timestamp.hpp>
21 #include <tvm/smart_switcher.hpp>
22 #include <tvm/contract_handle.hpp>
24 #include "FlexLendPayloadArgs.hpp"
25 #include "Tip3Config.hpp"
26 #include "Tip3Creds.hpp"
27 #include "bind_info.hpp"
28 #include "immutable_ids.hpp"
38 #if defined(TIP3_ENABLE_EXTERNAL) && !defined(TIP3_ONLY_FLEX_EXTERNAL)
39 #define TIP3_EXTERNAL [[external]]
44 #if defined(TIP3_ENABLE_EXTERNAL) || defined(TIP3_ONLY_FLEX_EXTERNAL)
45 #define FLEX_EXTERNAL [[external]]
50 static constexpr
unsigned TOKEN_WALLET_TIMESTAMP_DELAY = 1800;
51 using wallet_replay_protection_t = replay_attack_protection::timestamp<TOKEN_WALLET_TIMESTAMP_DELAY>;
105 [[
internal, answer_id]]
109 uint32 lend_finish_time,
116 [[
internal, answer_id]]
120 uint128 evers_balance,
122 opt<Tip3Creds> sender,
128 using ITONTokenWalletNotifyPtr = handle<ITONTokenWalletNotify>;
137 [[
internal, answer_id]]
139 address_opt answer_addr,
145 uint128 return_ownership,
146 opt<cell> notify_payload
153 [[
internal, answer_id]]
155 address_opt answer_addr,
165 uint128 return_ownership,
166 opt<cell> notify_payload
170 [[
internal, answer_id]]
179 opt<cell> notify_payload
188 uint256 sender_pubkey,
189 address_opt sender_owner,
193 #ifdef TIP3_ENABLE_DESTROY
203 #ifdef TIP3_ENABLE_BURN
208 [[
internal, answer_id]]
212 address_opt out_owner,
222 [[
internal, answer_id]]
226 address_opt out_owner,
234 #ifdef TIP3_ENABLE_LEND_OWNERSHIP
239 [[
internal, answer_id]]
241 address_opt answer_addr,
245 uint128 lend_balance,
246 uint32 lend_finish_time,
248 cell unsalted_price_code,
250 FlexLendPayloadArgs args
261 opt<uint256> order_id
266 void returnOwnership(
276 opt<bind_info> binding,
283 [[
internal, answer_id]]
291 #ifdef TIP3_ENABLE_EXTERNAL
294 uint128 getBalance() = 22;
297 using ITONTokenWalletPtr = handle<ITONTokenWallet>;
309 #ifdef TIP3_ENABLE_LEND_OWNERSHIP
310 opt<uint256> lend_pubkey_;
312 opt<bind_info> binding_;
360 string name,
string symbol, uint8 decimals,
361 uint256 root_pubkey, address root_address,
362 uint256 wallet_pubkey, address_opt wallet_owner,
363 uint256 code_hash, uint16 code_depth, int8 workchain_id
366 name, symbol, decimals,
367 uint128(0), root_pubkey, root_address,
368 wallet_pubkey, wallet_owner,
369 #ifdef TIP3_ENABLE_LEND_OWNERSHIP
372 code_hash, code_depth,
381 string name,
string symbol, uint8 decimals,
382 uint256 root_pubkey, address root_address, uint256 wallet_pubkey, address_opt wallet_owner,
383 uint256 code_hash, uint16 code_depth, int8 workchain_id
386 prepare_wallet_data(name, symbol, decimals, root_pubkey, root_address, wallet_pubkey, wallet_owner,
387 code_hash, code_depth, workchain_id);
388 auto init_hdr = persistent_data_header<ITONTokenWallet, wallet_replay_protection_t>::init();
389 cell data_cl = prepare_persistent_data<ITONTokenWallet, wallet_replay_protection_t>(init_hdr, wallet_data);
390 return tvm_state_init_hash(code_hash, uint256(tvm_hash(data_cl)), code_depth, uint16(data_cl.cdepth()));
397 string name,
string symbol, uint8 decimals,
398 uint256 root_pubkey, address root_address, uint256 wallet_pubkey, address_opt wallet_owner,
399 uint256 code_hash, uint16 code_depth, int8 workchain_id
402 name, symbol, decimals,
403 uint128(0), root_pubkey, root_address, wallet_pubkey, wallet_owner,
404 code_hash, code_depth, workchain_id
406 auto init_hdr = persistent_data_header<ITONTokenWallet, wallet_replay_protection_t>::init();
407 cell data_cl = prepare_persistent_data<ITONTokenWallet, wallet_replay_protection_t>(init_hdr, wallet_data);
408 return tvm_state_init_hash(code_hash, uint256(tvm_hash(data_cl)), code_depth, uint16(data_cl.cdepth()));
415 Tip3Config tip3cfg, uint256 wallet_pubkey, address_opt wallet_owner,
416 uint256 code_hash, uint16 code_depth, int8 workchain_id
419 tip3cfg.name, tip3cfg.symbol, tip3cfg.decimals,
420 uint128(0), tip3cfg.root_pubkey, tip3cfg.root_address, wallet_pubkey, wallet_owner,
421 {}, {}, {}, code_hash, code_depth, workchain_id
423 auto init_hdr = persistent_data_header<ITONTokenWallet, wallet_replay_protection_t>::init();
424 cell data_cl = prepare_persistent_data<ITONTokenWallet, wallet_replay_protection_t>(init_hdr, wallet_data);
425 return tvm_state_init_hash(code_hash, uint256(tvm_hash(data_cl)), code_depth, uint16(data_cl.cdepth()));
432 auto init_hdr = persistent_data_header<ITONTokenWallet, wallet_replay_protection_t>::init();
433 cell wallet_data_cl =
434 prepare_persistent_data<ITONTokenWallet, wallet_replay_protection_t>(init_hdr, wallet_data);
435 StateInit wallet_init {
437 code, wallet_data_cl, {}
439 cell wallet_init_cl = build(wallet_init).make_cell();
440 return { wallet_init, uint256(tvm_hash(wallet_init_cl)) };
447 string name,
string symbol, uint8 decimals,
448 uint256 root_pubkey, address root_address,
449 uint256 wallet_pubkey, address_opt wallet_owner,
450 uint256 code_hash, uint16 code_depth,
451 int8 workchain_id, cell code
454 name, symbol, decimals,
455 uint128(0), root_pubkey, root_address, wallet_pubkey, wallet_owner,
456 code_hash, code_depth, workchain_id
458 cell wallet_data_cl =
459 prepare_persistent_data<ITONTokenWallet, wallet_replay_protection_t, DTONTokenWalletExternal>(
460 wallet_replay_protection_t::init(), wallet_data);
461 StateInit wallet_init {
463 code, wallet_data_cl, {}
465 cell wallet_init_cl = build(wallet_init).make_cell();
466 return { wallet_init, uint256(tvm_hash(wallet_init_cl)) };
473 string name,
string symbol, uint8 decimals,
474 uint256 root_pubkey, address root_address,
475 uint256 wallet_pubkey, address_opt wallet_owner,
476 uint256 code_hash, uint16 code_depth,
477 int8 workchain_id, cell code
480 name, symbol, decimals,
481 uint128(0), root_pubkey, root_address, wallet_pubkey, wallet_owner,
482 {}, {}, {}, code_hash, code_depth, workchain_id
484 cell wallet_data_cl =
485 prepare_persistent_data<ITONTokenWallet, wallet_replay_protection_t, DTONTokenWalletInternal>(
486 wallet_replay_protection_t::init(), wallet_data
488 StateInit wallet_init {
490 code, wallet_data_cl, {}
492 cell wallet_init_cl = build(wallet_init).make_cell();
493 return { wallet_init, uint256(tvm_hash(wallet_init_cl)) };
small_dict_map< lend_owner_key, lend_owner > lend_owners_map
Lend owners (contracts) map.
Definition: TONTokenWallet.hpp:65
__always_inline uint256 calc_wallet_init_hash(string name, string symbol, uint8 decimals, uint256 root_pubkey, address root_address, uint256 wallet_pubkey, address_opt wallet_owner, uint256 code_hash, uint16 code_depth, int8 workchain_id)
Definition: TONTokenWallet.hpp:380
std::pair< StateInit, uint256 > prepare_external_wallet_state_init_and_addr(string name, string symbol, uint8 decimals, uint256 root_pubkey, address root_address, uint256 wallet_pubkey, address_opt wallet_owner, uint256 code_hash, uint16 code_depth, int8 workchain_id, cell code)
Definition: TONTokenWallet.hpp:446
__always_inline uint256 calc_int_wallet_init_hash(Tip3Config tip3cfg, uint256 wallet_pubkey, address_opt wallet_owner, uint256 code_hash, uint16 code_depth, int8 workchain_id)
Definition: TONTokenWallet.hpp:414
std::pair< StateInit, uint256 > prepare_internal_wallet_state_init_and_addr(string name, string symbol, uint8 decimals, uint256 root_pubkey, address root_address, uint256 wallet_pubkey, address_opt wallet_owner, uint256 code_hash, uint16 code_depth, int8 workchain_id, cell code)
Definition: TONTokenWallet.hpp:472
dict_array< lend_owner_array_record > lend_owners_array
Lend ownership array.
Definition: TONTokenWallet.hpp:74
std::pair< StateInit, uint256 > prepare_wallet_state_init_and_addr(DTONTokenWallet wallet_data, cell code)
Definition: TONTokenWallet.hpp:431
DTONTokenWallet prepare_wallet_data(string name, string symbol, uint8 decimals, uint256 root_pubkey, address root_address, uint256 wallet_pubkey, address_opt wallet_owner, uint256 code_hash, uint16 code_depth, int8 workchain_id)
Prepare TONTokenWallet persistent data struct.
Definition: TONTokenWallet.hpp:359
__always_inline uint256 calc_ext_wallet_init_hash(string name, string symbol, uint8 decimals, uint256 root_pubkey, address root_address, uint256 wallet_pubkey, address_opt wallet_owner, uint256 code_hash, uint16 code_depth, int8 workchain_id)
Definition: TONTokenWallet.hpp:396
Definition: TONTokenWallet.hpp:320
address_opt owner_address_
Owner contract address for internal ownership.
Definition: TONTokenWallet.hpp:328
string symbol_
Token short symbol.
Definition: TONTokenWallet.hpp:322
uint256 root_pubkey_
Public key of the related RootTokenContract.
Definition: TONTokenWallet.hpp:325
string name_
Token name.
Definition: TONTokenWallet.hpp:321
uint128 balance_
Token balance of the wallet.
Definition: TONTokenWallet.hpp:324
uint16 code_depth_
Tip3 wallet code depth to verify other wallets.
Definition: TONTokenWallet.hpp:330
uint256 code_hash_
Tip3 wallet code hash to verify other wallets.
Definition: TONTokenWallet.hpp:329
int8 workchain_id_
Workchain id.
Definition: TONTokenWallet.hpp:331
uint256 wallet_pubkey_
Public key of wallet owner.
Definition: TONTokenWallet.hpp:327
uint8 decimals_
Decimals for ui purposes. ex: balance 100 with decimals 2 will be printed as 1.00.
Definition: TONTokenWallet.hpp:323
address root_address_
Address of the related RootTokenContract.
Definition: TONTokenWallet.hpp:326
Definition: TONTokenWallet.hpp:334
address_opt owner_address_
Owner contract address for internal ownership.
Definition: TONTokenWallet.hpp:342
string symbol_
Token short symbol.
Definition: TONTokenWallet.hpp:336
uint256 root_pubkey_
Public key of the related RootTokenContract.
Definition: TONTokenWallet.hpp:339
opt< uint256 > lend_pubkey_
Lend ownership pubkey.
Definition: TONTokenWallet.hpp:343
string name_
Token name.
Definition: TONTokenWallet.hpp:335
opt< bind_info > binding_
Definition: TONTokenWallet.hpp:345
uint128 balance_
Token balance of the wallet.
Definition: TONTokenWallet.hpp:338
uint16 code_depth_
Tip3 wallet code depth to verify other wallets.
Definition: TONTokenWallet.hpp:348
uint256 code_hash_
Tip3 wallet code hash to verify other wallets.
Definition: TONTokenWallet.hpp:347
lend_owners_map lend_owners_
Lend ownership map (service owner => lend_owner).
Definition: TONTokenWallet.hpp:344
int8 workchain_id_
Workchain id.
Definition: TONTokenWallet.hpp:349
uint256 wallet_pubkey_
Public key of wallet owner.
Definition: TONTokenWallet.hpp:341
uint8 decimals_
Decimals for ui purposes. ex: balance 100 with decimals 2 will be printed as 1.00.
Definition: TONTokenWallet.hpp:337
address root_address_
Address of the related RootTokenContract.
Definition: TONTokenWallet.hpp:340
TONTokenWallet persistent data struct.
Definition: TONTokenWallet.hpp:300
address_opt owner_address_
Owner contract address for internal ownership.
Definition: TONTokenWallet.hpp:308
string symbol_
Token short symbol.
Definition: TONTokenWallet.hpp:302
uint256 root_pubkey_
Public key of the related RootTokenContract.
Definition: TONTokenWallet.hpp:305
string name_
Token name.
Definition: TONTokenWallet.hpp:301
uint128 balance_
Token balance of the wallet.
Definition: TONTokenWallet.hpp:304
uint16 code_depth_
Tip3 wallet code depth to verify other wallets.
Definition: TONTokenWallet.hpp:316
uint256 code_hash_
Tip3 wallet code hash to verify other wallets.
Definition: TONTokenWallet.hpp:315
int8 workchain_id_
Workchain id.
Definition: TONTokenWallet.hpp:317
uint256 wallet_pubkey_
Public key of wallet owner.
Definition: TONTokenWallet.hpp:307
uint8 decimals_
Decimals for ui purposes. ex: balance 100 with decimals 2 will be printed as 1.00.
Definition: TONTokenWallet.hpp:303
address root_address_
Address of the related RootTokenContract.
Definition: TONTokenWallet.hpp:306
TONTokenWallet events interface.
Definition: TONTokenWallet.hpp:354
TON Token wallet notification callback interface.
Definition: TONTokenWallet.hpp:101
bool onTip3Transfer(uint128 balance, uint128 new_tokens, uint128 evers_balance, Tip3Config tip3cfg, opt< Tip3Creds > sender, Tip3Creds receiver, cell payload, address answer_addr)
Notification from tip3 wallet to its owner contract about received tokens transfer.
bool onTip3LendOwnership(uint128 balance, uint32 lend_finish_time, Tip3Creds creds, cell payload, address answer_addr)
TON Token wallet contract interface.
Definition: TONTokenWallet.hpp:133
TIP3_EXTERNAL void transfer(address_opt answer_addr, address to, uint128 tokens, uint128 evers, uint128 return_ownership, opt< cell > notify_payload)
Transfer tokens to another tip3 wallet contract.
details_info details()
Request info about contract state details (from another contract).
void acceptMint(uint128 _value, address answer_addr, uint128 keep_evers, opt< cell > notify_payload)=0x4384F298
Receive tokens from root (RootTokenContract).
uint128 balance()
Request wallet token balance using internal message (contract-to-contract).
void acceptTransfer(uint128 _value, address answer_addr, uint128 keep_evers, uint256 sender_pubkey, address_opt sender_owner, opt< cell > payload)=0x67A0B95F
Receive tokens from another tip3 wallet.
details_info getDetails()
Get info about contract state details.
TIP3_EXTERNAL void transferToRecipient(address_opt answer_addr, Tip3Creds to, uint128 tokens, uint128 evers, uint128 keep_evers, bool deploy, uint128 return_ownership, opt< cell > notify_payload)
TONTokenWallet details info (for getter).
Definition: TONTokenWallet.hpp:77
uint8 decimals
Decimals for ui purposes. ex: balance 100 with decimals 2 will be printed as 1.00.
Definition: TONTokenWallet.hpp:80
uint16 code_depth
Tip3 wallet code depth to verify other wallets.
Definition: TONTokenWallet.hpp:92
lend_owners_array lend_owners
All lend ownership records of the contract.
Definition: TONTokenWallet.hpp:87
address_opt owner_address
Owner contract address for internal ownership, will be 0:0..0 otherwise.
Definition: TONTokenWallet.hpp:85
uint256 wallet_pubkey
Public key of wallet owner (User id for FlexWallet).
Definition: TONTokenWallet.hpp:84
uint256 root_pubkey
Public key of the related RootTokenContract.
Definition: TONTokenWallet.hpp:82
address root_address
Address of the related RootTokenContract.
Definition: TONTokenWallet.hpp:83
string name
Token name.
Definition: TONTokenWallet.hpp:78
opt< bind_info > binding
Flex binding info.
Definition: TONTokenWallet.hpp:90
string symbol
Token short symbol.
Definition: TONTokenWallet.hpp:79
uint128 lend_balance
Definition: TONTokenWallet.hpp:88
opt< uint256 > lend_pubkey
Lend ownership pubkey.
Definition: TONTokenWallet.hpp:86
uint256 code_hash
Tip3 wallet code hash to verify other wallets.
Definition: TONTokenWallet.hpp:91
uint128 balance
Token balance of the wallet.
Definition: TONTokenWallet.hpp:81
int8 workchain_id
Workchain id.
Definition: TONTokenWallet.hpp:93
Lend ownership array record (for usage in getter).
Definition: TONTokenWallet.hpp:68
uint32 lend_finish_time
Lend ownership finish time.
Definition: TONTokenWallet.hpp:71
lend_owner_key lend_key
Lend ownership key (destination address + user id).
Definition: TONTokenWallet.hpp:69
uint128 lend_balance
Lend ownership balance.
Definition: TONTokenWallet.hpp:70
Complex key for lend owners mapping.
Definition: TONTokenWallet.hpp:54
addr_std_fixed dest
Destination contract address.
Definition: TONTokenWallet.hpp:55
Lend ownership record (for usage in address->lend_owner_record map).
Definition: TONTokenWallet.hpp:59
uint32 lend_finish_time
Lend ownership finish time.
Definition: TONTokenWallet.hpp:61
uint128 lend_balance
Lend ownership balance.
Definition: TONTokenWallet.hpp:60
uint256 user_pubkey
Lend pubkey of the user ordered to lend ownership to the address.
Definition: TONTokenWallet.hpp:62