Flex
Flex exchange system
RootTokenContract.hpp
Go to the documentation of this file.
1 #pragma once
2 
12 #include "TONTokenWallet.hpp"
13 
14 namespace tvm {
15 
16 static constexpr unsigned ROOT_TIMESTAMP_DELAY = 1800;
17 using root_replay_protection_t = replay_attack_protection::timestamp<ROOT_TIMESTAMP_DELAY>;
18 
19 // ===== Root Token Contract ===== //
24 __interface IRootTokenContract {
25 
28  [[internal, external]]
30  string name,
31  string symbol,
32  uint8 decimals,
33  uint256 root_pubkey,
34  address_opt root_owner,
35  uint128 total_supply
39  ) = 10;
40 
44  [[internal, external, answer_id]]
45  bool setWalletCode(cell wallet_code) = 11;
46 
50  [[internal, external, answer_id]]
51  address deployWallet(
52  uint256 pubkey,
53  address_opt owner,
54  uint128 tokens,
55  uint128 evers,
56  opt<cell> notify
57  ) = 12;
58 
61  [[internal, answer_id]]
63  uint256 pubkey,
64  address_opt owner,
65  uint128 evers
67  ) = 13;
68 
72  [[internal, external, answer_id]]
73  void grant(
74  address dest,
75  uint128 tokens,
76  uint128 evers,
79  opt<cell> notify
80  ) = 14;
81 
83  [[internal, external, answer_id]]
84  bool mint(uint128 tokens) = 15;
85 
87  [[internal, answer_id]]
88  uint128 requestTotalGranted() = 16;
89 
91  [[getter]]
92  string getName() = 17;
93 
95  [[getter]]
96  string getSymbol() = 18;
97 
99  [[getter]]
100  uint8 getDecimals() = 19;
101 
103  [[getter]]
104  uint256 getRootKey() = 20;
105 
107  [[getter]]
108  address_opt getRootOwner() = 21;
109 
111  [[getter]]
112  uint128 getTotalSupply() = 22;
113 
115  [[getter]]
116  uint128 getTotalGranted() = 23;
117 
119  [[getter]]
120  bool hasWalletCode() = 24;
121 
123  [[getter]]
124  cell getWalletCode() = 25;
125 
127  [[getter]]
129  uint256 pubkey,
130  address_opt owner
131  ) = 26;
132 
134  [[getter]]
135  uint256 getWalletCodeHash() = 27;
136 };
137 using IRootTokenContractPtr = handle<IRootTokenContract>;
138 
141  string name_;
142  string symbol_;
143  uint8 decimals_;
144  uint256 root_pubkey_;
145  address_opt root_owner_;
146  uint128 total_supply_;
147  uint128 total_granted_;
148  optcell wallet_code_;
149 };
150 
154 };
155 
157 template<>
159  __always_inline
160  static std::pair<StateInit, uint256> execute(DRootTokenContract root_data, cell root_code) {
161  cell root_data_cl =
162  prepare_persistent_data<IRootTokenContract, root_replay_protection_t>(
163  root_replay_protection_t::init(), root_data);
164  StateInit root_init { {}, {}, root_code, root_data_cl, {} };
165  cell root_init_cl = build(root_init).make_cell();
166  return { root_init, uint256(tvm_hash(root_init_cl)) };
167  }
168 };
169 
170 } // namespace tvm
171 
TONTokenWallet contract interfaces and data-structs.
RootTokenContract persistent data struct.
Definition: RootTokenContract.hpp:140
string symbol_
Token short symbol.
Definition: RootTokenContract.hpp:142
uint256 root_pubkey_
Root public key.
Definition: RootTokenContract.hpp:144
uint128 total_supply_
Total supply of allocated tokens (in the pool).
Definition: RootTokenContract.hpp:146
address_opt root_owner_
Root internal owner (owner contract).
Definition: RootTokenContract.hpp:145
string name_
Token name.
Definition: RootTokenContract.hpp:141
uint128 total_granted_
Total granted tokens (to the wallets).
Definition: RootTokenContract.hpp:147
uint8 decimals_
Decimals for ui purposes. ex: balance 100 with decimals 2 will be printed as 1.00.
Definition: RootTokenContract.hpp:143
optcell wallet_code_
Token wallet code.
Definition: RootTokenContract.hpp:148
RootTokenContract events interface.
Definition: RootTokenContract.hpp:153
Tip3 token root contract interface. RootTokenContract is a root contract for tip3 token.
Definition: RootTokenContract.hpp:24
uint128 requestTotalGranted()
Request total granted value to be called from other contracts.
bool hasWalletCode()
Is wallet code already initialized (by IRootTokenContract::setWalletCode())
uint256 getRootKey()
Get public key of the Root.
string getName()
Get token name.
uint8 getDecimals()
Get token decimals.
address getWalletAddress(uint256 pubkey, address_opt owner)
Calculate wallet address using (pubkey, owner) pair.
void grant(address dest, uint128 tokens, uint128 evers, opt< cell > notify)
uint128 getTotalGranted()
Get total granted tokens.
uint128 getTotalSupply()
Get total supply (allocated tokens)
void constructor(string name, string symbol, uint8 decimals, uint256 root_pubkey, address_opt root_owner, uint128 total_supply)
bool mint(uint128 tokens)
Mint tokens. Allocates new tokens (increases total_supply_).
string getSymbol()
Get token symbol.
cell getWalletCode()
Get wallet code.
uint256 getWalletCodeHash()
Get wallet code hash.
address_opt getRootOwner()
Get owner contract address of the Root (optional)
address deployEmptyWallet(uint256 pubkey, address_opt owner, uint128 evers)
address deployWallet(uint256 pubkey, address_opt owner, uint128 tokens, uint128 evers, opt< cell > notify)
bool setWalletCode(cell wallet_code)