-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTONTokenWalletNF.hpp
143 lines (105 loc) · 3.75 KB
/
TONTokenWalletNF.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#pragma once
#include <tvm/schema/message.hpp>
#include <tvm/sequence.hpp>
#include <tvm/replay_attack_protection/timestamp.hpp>
#include <tvm/smart_switcher.hpp>
#include <tvm/dict_set.hpp>
namespace tvm { namespace schema {
using WalletGramsType = uint128;
using TokensType = uint128;
using TokenId = uint128;
struct t_file {
bytes name;
lazy<MsgAddressInt> data;
bytes jsonMeta;
uint64 time;
};
struct info_token {
bytes name;
uint8 type;
bytes tokenUri;
uint64 time;
lazy<MsgAddressInt> data;
};
static constexpr unsigned TOKEN_WALLET_TIMESTAMP_DELAY = 5;
using wallet_replay_protection_t = replay_attack_protection::timestamp<TOKEN_WALLET_TIMESTAMP_DELAY>;
struct allowance_info {
lazy<MsgAddressInt> spender;
TokenId allowedToken;
};
// ===== TON Token wallet ===== //
__interface ITONTokenWallet {
// expected offchain constructor execution
__attribute__((internal, external, dyn_chain_parse))
void constructor(bytes name, bytes symbol, uint8 decimals,
uint256 root_public_key, uint256 wallet_public_key,
lazy<MsgAddressInt> root_address, cell code) = 11;
__attribute__((external,internal, noaccept, dyn_chain_parse))
void transfer(lazy<MsgAddressInt> dest, TokenId tokenId, WalletGramsType grams) = 12;
__attribute__ ((external,internal noaccept, dyn_chain_parse))
void send_all_token_by_pubkey(uint256 pubkey, lazy<MsgAddressInt> nonce) = 13;
// Receive tokens from root
__attribute__((internal, noaccept))
void accept(TokenId tokenId) = 14;
// Receive tokens from other wallet
__attribute__((internal,noaccept))
void internalTransfer(TokenId tokenId, uint256 pubkey, lazy<MsgAddressInt> timestamp) = 15;
// getters
__attribute__((getter))
bytes getName() = 16;
__attribute__((getter))
bytes getSymbol() = 17;
__attribute__((getter))
uint8 getDecimals() = 18;
__attribute__((getter))
TokensType getBalance() = 19;
__attribute__((getter))
uint256 getWalletKey() = 20;
__attribute__((getter))
lazy<MsgAddressInt> getRootAddress() = 21;
__attribute__((getter))
allowance_info allowance() = 22;
__attribute__((getter))
TokenId getTokenByIndex(TokensType index) = 23;
__attribute__((getter))
lazy<MsgAddressInt> getApproved(TokenId tokenId) = 24;
__attribute__((getter))
lazy<MsgAddressInt> getNonce() = 25;
// allowance interface
__attribute__((external, noaccept, dyn_chain_parse))
void approve(lazy<MsgAddressInt> spender, TokenId tokenId) = 26;
__attribute__((external, noaccept, dyn_chain_parse))
void transferFrom(lazy<MsgAddressInt> dest, lazy<MsgAddressInt> to, TokenId tokenId, WalletGramsType grams) = 27;
__attribute__((internal))
void internalTransferFrom(lazy<MsgAddressInt> to, TokenId tokenId) = 28;
__attribute__((external, noaccept))
void disapprove() = 29;
};
struct DTONTokenWallet {
bytes name_;
bytes symbol_;
uint8 decimals_;
uint256 root_public_key_;
uint256 wallet_public_key_;
lazy<MsgAddressInt> root_address_;
cell code_;
lazy<MsgAddressInt> nonce_;
std::optional<allowance_info> allowance_;
dict_set<TokenId> tokens_;
};
struct ETONTokenWallet {
};
// Prepare Token Wallet StateInit structure and expected contract address (hash from StateInit)
inline
std::pair<StateInit, uint256> prepare_wallet_state_init_and_addr(DTONTokenWallet wallet_data) {
cell wallet_data_cl =
prepare_persistent_data<ITONTokenWallet, wallet_replay_protection_t, DTONTokenWallet>(
wallet_replay_protection_t::init(), wallet_data);
StateInit wallet_init {
/*split_depth*/{}, /*special*/{},
wallet_data.code_, wallet_data_cl, /*library*/{}
};
cell wallet_init_cl = build(wallet_init).make_cell();
return { wallet_init, uint256(tvm_hash(wallet_init_cl)) };
}
}} // namespace tvm::schema