@d9-network/spec 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/dist/d9_metadata-KHMVPHO2-BILssUTo.mjs +6 -0
  2. package/dist/d9_metadata-KHMVPHO2-BILssUTo.mjs.map +1 -0
  3. package/dist/d9_metadata-KHMVPHO2-CTHNW2Z9.cjs +7 -0
  4. package/dist/d9_metadata-KHMVPHO2-CTHNW2Z9.cjs.map +1 -0
  5. package/dist/descriptors-KKD7UFMX-BQkrqfg1.mjs +16 -0
  6. package/dist/descriptors-KKD7UFMX-BQkrqfg1.mjs.map +1 -0
  7. package/dist/descriptors-KKD7UFMX-DBUb__c-.cjs +17 -0
  8. package/dist/descriptors-KKD7UFMX-DBUb__c-.cjs.map +1 -0
  9. package/dist/index.cjs +250 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.cts +8712 -0
  12. package/dist/index.d.mts +8712 -0
  13. package/dist/index.mjs +195 -0
  14. package/dist/index.mjs.map +1 -0
  15. package/dist/metadataTypes-LUDFOAMC-DTvnnJbu.cjs +7 -0
  16. package/dist/metadataTypes-LUDFOAMC-DTvnnJbu.cjs.map +1 -0
  17. package/dist/metadataTypes-LUDFOAMC-FMlTA1su.mjs +6 -0
  18. package/dist/metadataTypes-LUDFOAMC-FMlTA1su.mjs.map +1 -0
  19. package/package.json +4 -1
  20. package/.claude/settings.local.json +0 -8
  21. package/.papi/contracts/burnManager.json +0 -1300
  22. package/.papi/contracts/burnMining.json +0 -1385
  23. package/.papi/contracts/crossChainTransfer.json +0 -1693
  24. package/.papi/contracts/marketMaker.json +0 -1470
  25. package/.papi/contracts/merchantMining.json +0 -1750
  26. package/.papi/contracts/miningPool.json +0 -1019
  27. package/.papi/contracts/nodeReward.json +0 -1214
  28. package/.papi/contracts/usdt.json +0 -1036
  29. package/.papi/descriptors/.gitignore +0 -3
  30. package/.papi/descriptors/package.json +0 -24
  31. package/.papi/metadata/d9.scale +0 -0
  32. package/.papi/polkadot-api.json +0 -22
  33. package/assets/ABIs/burn-manager.json +0 -1300
  34. package/assets/ABIs/burn-mining.json +0 -1385
  35. package/assets/ABIs/cross-chain-transfer.json +0 -1693
  36. package/assets/ABIs/market-maker.json +0 -1470
  37. package/assets/ABIs/merchant-mining.json +0 -1750
  38. package/assets/ABIs/mining-pool.json +0 -1019
  39. package/assets/ABIs/node-reward.json +0 -1214
  40. package/assets/ABIs/usdt.json +0 -1036
  41. package/docs/CLAUDE.md +0 -364
  42. package/docs/CONTRACTS.md +0 -603
  43. package/docs/PALLETS.md +0 -726
  44. package/docs/TYPES.md +0 -618
  45. package/scripts/papi-add-ink.ts +0 -104
  46. package/src/client.ts +0 -68
  47. package/src/index.ts +0 -17
  48. package/src/wallet/account.ts +0 -57
  49. package/src/wallet/hex.ts +0 -30
  50. package/src/wallet/index.ts +0 -6
  51. package/src/wallet/mnemonic.ts +0 -19
  52. package/src/wallet/signer.ts +0 -9
  53. package/src/wallet/sr25519.ts +0 -42
  54. package/src/wallet/ss58.ts +0 -14
  55. package/test/client.test.ts +0 -15
  56. package/test/descriptors.test.ts +0 -32
  57. package/test/wallet.test.ts +0 -65
  58. package/tsconfig.json +0 -13
  59. package/tsdown.config.ts +0 -19
package/docs/CONTRACTS.md DELETED
@@ -1,603 +0,0 @@
1
- # D9 Chain Smart Contracts Documentation
2
-
3
- This document describes all ink! smart contracts deployed on the D9 blockchain, including their messages (methods), storage, events, and error types.
4
-
5
- ## Table of Contents
6
-
7
- 1. [Token Contracts](#token-contracts)
8
- - [USDT (PSP22 Token)](#usdt-psp22-token)
9
- 2. [Mining Contracts](#mining-contracts)
10
- - [Burn Manager](#burn-manager)
11
- - [Burn Mining](#burn-mining)
12
- - [Mining Pool](#mining-pool)
13
- - [Node Reward](#node-reward)
14
- - [Merchant Mining](#merchant-mining)
15
- 3. [DeFi Contracts](#defi-contracts)
16
- - [Market Maker (AMM)](#market-maker-amm)
17
- 4. [Bridge Contracts](#bridge-contracts)
18
- - [Cross-Chain Transfer](#cross-chain-transfer)
19
-
20
- ---
21
-
22
- ## Token Contracts
23
-
24
- ### USDT (PSP22 Token)
25
-
26
- PSP22-compliant USDT stablecoin token contract.
27
-
28
- #### Storage
29
-
30
- | Key | Type | Description |
31
- |-----|------|-------------|
32
- | `psp22.supply` | `bigint` | Total token supply |
33
- | `psp22.balances` | `Map<AccountId, bigint>` | Account balances |
34
- | `psp22.allowances` | `Map<(Owner, Spender), bigint>` | Transfer allowances |
35
-
36
- #### Messages
37
-
38
- | Name | Parameters | Returns | Mutates | Description |
39
- |------|------------|---------|---------|-------------|
40
- | `transfer` | `to: SS58String, value: bigint, _data: Binary` | `Result<(), PSP22Error>` | Yes | Transfer tokens to another account |
41
- | `transfer_from` | `from: SS58String, to: SS58String, value: bigint, _data: Binary` | `Result<(), PSP22Error>` | Yes | Transfer tokens on behalf of another account |
42
- | `PSP22::total_supply` | - | `bigint` | No | Get total token supply |
43
- | `PSP22::balance_of` | `owner: SS58String` | `bigint` | No | Get account balance |
44
- | `PSP22::allowance` | `owner: SS58String, spender: SS58String` | `bigint` | No | Get transfer allowance |
45
- | `PSP22::transfer` | `to: SS58String, value: bigint, data: Binary` | `Result<(), PSP22Error>` | Yes | PSP22 standard transfer |
46
- | `PSP22::transfer_from` | `from: SS58String, to: SS58String, value: bigint, data: Binary` | `Result<(), PSP22Error>` | Yes | PSP22 standard transfer_from |
47
- | `PSP22::approve` | `spender: SS58String, value: bigint` | `Result<(), PSP22Error>` | Yes | Approve transfer allowance |
48
- | `PSP22::increase_allowance` | `spender: SS58String, delta_value: bigint` | `Result<(), PSP22Error>` | Yes | Increase allowance |
49
- | `PSP22::decrease_allowance` | `spender: SS58String, delta_value: bigint` | `Result<(), PSP22Error>` | Yes | Decrease allowance |
50
-
51
- #### Constructor
52
-
53
- ```typescript
54
- new(initial_supply: bigint): Result<(), Error>
55
- ```
56
-
57
- #### Events
58
-
59
- | Name | Data | Description |
60
- |------|------|-------------|
61
- | `Approval` | `owner, spender, amount` | Approval was granted |
62
- | `Transfer` | `from?, to?, value` | Tokens were transferred |
63
-
64
- #### Errors
65
-
66
- | Name | Description |
67
- |------|-------------|
68
- | `Custom(string)` | Custom error message |
69
- | `InsufficientBalance` | Balance too low |
70
- | `InsufficientAllowance` | Allowance too low |
71
- | `ZeroRecipientAddress` | Zero recipient address |
72
- | `ZeroSenderAddress` | Zero sender address |
73
- | `SafeTransferCheckFailed(string)` | Safe transfer check failed |
74
-
75
- ---
76
-
77
- ## Mining Contracts
78
-
79
- ### Burn Manager
80
-
81
- Central contract that manages token burning across multiple burn mining contracts.
82
-
83
- #### Storage
84
-
85
- | Key | Type | Description |
86
- |-----|------|-------------|
87
- | `portfolios` | `Map<AccountId, Portfolio>` | User burn portfolios |
88
- | `admin` | `SS58String` | Contract admin |
89
- | `burn_contracts` | `Vec<SS58String>` | Registered burn contracts |
90
- | `total_amount_burned` | `bigint` | Total tokens burned globally |
91
-
92
- #### Portfolio Structure
93
-
94
- ```typescript
95
- {
96
- amount_burned: bigint; // Total amount burned by user
97
- balance_due: bigint; // Balance due to user
98
- balance_paid: bigint; // Balance already paid
99
- last_withdrawal?: { // Last withdrawal info
100
- time: bigint;
101
- contract: SS58String;
102
- };
103
- last_burn: { // Last burn info
104
- time: bigint;
105
- contract: SS58String;
106
- };
107
- }
108
- ```
109
-
110
- #### Messages
111
-
112
- | Name | Parameters | Returns | Mutates | Payable | Description |
113
- |------|------------|---------|---------|---------|-------------|
114
- | `burn` | `burn_beneficiary: SS58String, burn_contract: SS58String` | `Result<Portfolio, Error>` | Yes | Yes | Execute a burn via cross-contract call |
115
- | `withdraw` | `burn_contract: SS58String` | `Result<Portfolio, Error>` | Yes | No | Withdraw rewards from a burn contract |
116
- | `get_portfolio` | `account_id: SS58String` | `Portfolio?` | No | No | Get user's portfolio |
117
- | `get_ancestors` | `account_id: SS58String` | `Vec<SS58String>?` | No | No | Get referral ancestors |
118
- | `get_admin` | - | `SS58String` | No | No | Get admin address |
119
- | `get_total_burned` | - | `bigint` | No | No | Get total burned amount |
120
- | `add_burn_contract` | `burn_contract: SS58String` | `Result<(), Error>` | Yes | No | Add a burn contract |
121
- | `remove_burn_contract` | `burn_contract: SS58String` | `Result<(), Error>` | Yes | No | Remove a burn contract |
122
-
123
- #### Constructor
124
-
125
- ```typescript
126
- new(admin: SS58String, burn_contracts: Vec<SS58String>): Result<(), Error>
127
- // Payable constructor
128
- ```
129
-
130
- #### Events
131
-
132
- | Name | Data | Description |
133
- |------|------|-------------|
134
- | `WithdrawalExecuted` | `from, amount` | Withdrawal was executed |
135
- | `BurnExecuted` | `from, amount` | Burn was executed |
136
-
137
- #### Errors
138
-
139
- | Name | Description |
140
- |------|-------------|
141
- | `BurnAmountInsufficient` | Burn amount too low |
142
- | `NoAccountFound` | Account not found |
143
- | `EarlyWithdrawalAttempt` | Withdrawal attempted too early |
144
- | `ContractBalanceTooLow` | Contract has insufficient balance |
145
- | `RestrictedFunction` | Function access restricted |
146
- | `WithdrawalExceedsBalance` | Withdrawal exceeds balance |
147
- | `TransferFailed` | Transfer operation failed |
148
- | `InvalidCaller` | Invalid caller |
149
- | `InvalidBurnContract` | Invalid burn contract address |
150
- | `BurnContractAlreadyAdded` | Burn contract already registered |
151
- | `CrossContractCallFailed` | Cross-contract call failed |
152
- | `WithdrawalNotAllowed` | Withdrawal not allowed |
153
- | `NoAncestorsFound` | No referral ancestors found |
154
-
155
- ---
156
-
157
- ### Burn Mining
158
-
159
- Individual burn mining contract for token burning rewards.
160
-
161
- #### Storage
162
-
163
- | Key | Type | Description |
164
- |-----|------|-------------|
165
- | `accounts` | `Map<AccountId, BurnAccount>` | User burn accounts |
166
- | `total_amount_burned` | `bigint` | Total burned in this contract |
167
- | `main_pool` | `SS58String` | Main mining pool address |
168
- | `burn_minimum` | `bigint` | Minimum burn amount |
169
- | `day_milliseconds` | `bigint` | Milliseconds per day (for calculations) |
170
- | `admin` | `SS58String` | Contract admin |
171
-
172
- #### Account Structure
173
-
174
- ```typescript
175
- {
176
- creation_timestamp: bigint;
177
- amount_burned: bigint;
178
- balance_due: bigint;
179
- balance_paid: bigint;
180
- last_withdrawal?: bigint;
181
- last_burn: bigint;
182
- referral_boost_coefficients: [bigint, bigint];
183
- last_interaction: bigint;
184
- }
185
- ```
186
-
187
- #### Messages
188
-
189
- | Name | Parameters | Returns | Mutates | Description |
190
- |------|------------|---------|---------|-------------|
191
- | `initiate_burn` | `account_id: SS58String, burn_amount: bigint` | `Result<bigint, Error>` | Yes | Initiate a burn (called by burn manager) |
192
- | `prepare_withdrawal` | `account_id: SS58String` | `Result<[bigint, bigint], Error>` | Yes | Prepare withdrawal amounts |
193
- | `get_account` | `account_id: SS58String` | `Account?` | No | Get account details |
194
- | `get_ancestors` | `account_id: SS58String` | `Vec<SS58String>?` | No | Get referral ancestors |
195
- | `update_data` | `user: SS58String, amount_burned: bigint` | `Result<(), Error>` | Yes | Update user data |
196
- | `change_main` | `new_main: SS58String` | `Result<(), Error>` | Yes | Change main pool address |
197
- | `set_day_milliseconds` | `new_day_milliseconds: bigint` | `Result<(), Error>` | Yes | Set day duration |
198
- | `set_code` | `code_hash: Hash` | `Result<(), Error>` | Yes | Upgrade contract code |
199
-
200
- #### Constructor
201
-
202
- ```typescript
203
- new(main_pool: SS58String, burn_minimum: bigint): Result<(), Error>
204
- // Payable constructor
205
- ```
206
-
207
- ---
208
-
209
- ### Mining Pool
210
-
211
- Central mining pool contract managing rewards distribution.
212
-
213
- #### Storage
214
-
215
- | Key | Type | Description |
216
- |-----|------|-------------|
217
- | `admin` | `SS58String` | Contract admin |
218
- | `main_contract` | `SS58String` | Main contract address |
219
- | `merchant_contract` | `SS58String` | Merchant contract address |
220
- | `node_reward_contract` | `SS58String` | Node reward contract address |
221
- | `amm_contract` | `SS58String` | AMM contract address |
222
- | `merchant_volume` | `bigint` | Total merchant volume |
223
- | `last_session` | `number` | Last processed session |
224
- | `accumulative_reward_pool` | `bigint` | Accumulated rewards pool |
225
- | `volume_at_index` | `Map<number, bigint>` | Volume per session |
226
-
227
- #### Messages
228
-
229
- | Name | Parameters | Returns | Mutates | Payable | Description |
230
- |------|------------|---------|---------|---------|-------------|
231
- | `get_accumulative_reward_pool` | - | `bigint` | No | No | Get reward pool balance |
232
- | `pay_node_reward` | `account_id: SS58String, amount: bigint` | `Result<(), Error>` | Yes | No | Pay node reward |
233
- | `get_merchant_volume` | - | `bigint` | No | No | Get total merchant volume |
234
- | `get_session_volume` | `session_index: number` | `bigint` | No | No | Get session volume |
235
- | `get_total_volume` | - | `bigint` | No | No | Get total volume |
236
- | `update_pool_and_retrieve` | `session_index: number` | `Result<bigint, Error>` | Yes | No | Update pool and get amount |
237
- | `deduct_from_reward_pool` | `amount: bigint` | `Result<(), Error>` | Yes | No | Deduct from reward pool |
238
- | `process_merchant_payment` | - | `Result<(), Error>` | Yes | Yes | Process merchant payment |
239
- | `merchant_user_redeem_d9` | `user_account: SS58String, redeemable_usdt: bigint` | `Result<bigint, Error>` | No | No | Redeem D9 for user |
240
- | `change_merchant_contract` | `merchant_contract: SS58String` | `Result<(), Error>` | Yes | No | Change merchant contract |
241
- | `change_node_reward_contract` | `node_reward_contract: SS58String` | `Result<(), Error>` | Yes | No | Change node reward contract |
242
- | `change_amm_contract` | `amm_contract: SS58String` | `Result<(), Error>` | Yes | No | Change AMM contract |
243
- | `change_main_contract` | `main_contract: SS58String` | `Result<(), Error>` | Yes | No | Change main contract |
244
- | `send_to` | `to: SS58String, amount: bigint` | `Result<(), Error>` | Yes | No | Send D9 to address |
245
- | `set_code` | `code_hash: Hash` | `Result<(), Error>` | Yes | No | Upgrade contract code |
246
-
247
- #### Constructor
248
-
249
- ```typescript
250
- new(
251
- main_contract: SS58String,
252
- merchant_contract: SS58String,
253
- node_reward_contract: SS58String,
254
- amm_contract: SS58String
255
- ): Result<(), Error>
256
- ```
257
-
258
- #### Errors
259
-
260
- | Name | Description |
261
- |------|-------------|
262
- | `OnlyCallableBy(SS58String)` | Function only callable by specific address |
263
- | `FailedToGetExchangeAmount` | Failed to get exchange amount |
264
- | `FailedToTransferD9ToUser` | Failed to transfer D9 to user |
265
- | `SessionPoolNotReady` | Session pool not ready |
266
-
267
- ---
268
-
269
- ### Node Reward
270
-
271
- Contract for managing validator node rewards.
272
-
273
- #### Storage
274
-
275
- | Key | Type | Description |
276
- |-----|------|-------------|
277
- | `admin` | `SS58String` | Contract admin |
278
- | `new_admin` | `SS58String` | Pending new admin |
279
- | `mining_pool` | `SS58String` | Mining pool contract |
280
- | `rewards_pallet` | `SS58String` | Rewards pallet address |
281
- | `vote_limit` | `bigint` | Vote limit for rewards |
282
- | `session_rewards` | `Map<number, [bigint, bigint]>` | Session rewards data |
283
- | `node_reward` | `Map<SS58String, bigint>` | Pending node rewards |
284
- | `authorized_reward_receiver` | `Map<SS58String, SS58String>` | Authorized reward receivers |
285
-
286
- #### Messages
287
-
288
- | Name | Parameters | Returns | Mutates | Description |
289
- |------|------------|---------|---------|-------------|
290
- | `set_mining_pool` | `mining_pool: SS58String` | `Result<(), Error>` | Yes | Set mining pool address |
291
- | `set_rewards_pallet` | `rewards_pallet: SS58String` | `Result<(), Error>` | Yes | Set rewards pallet |
292
- | `relinquish_admin` | `new_admin: SS58String` | `Result<(), Error>` | Yes | Start admin transfer |
293
- | `accept_admin` | - | `Result<(), Error>` | Yes | Accept admin role |
294
- | `cancel_admin_relinquish` | - | `Result<(), Error>` | Yes | Cancel admin transfer |
295
- | `get_vote_limit` | - | `bigint` | No | Get vote limit |
296
- | `change_vote_limit` | `new_limit: bigint` | `Result<(), Error>` | Yes | Change vote limit |
297
- | `withdraw_reward` | `node_id: SS58String` | `Result<(), Error>` | Yes | Withdraw node reward |
298
- | `get_session_rewards_data` | `session_index: number` | `[bigint, bigint]?` | No | Get session rewards |
299
- | `get_node_reward_data` | `node_id: SS58String` | `bigint?` | No | Get node's pending reward |
300
- | `get_authorized_receiver` | `node_id: SS58String` | `SS58String` | No | Get authorized receiver |
301
- | `set_authorized_receiver` | `node_id: SS58String, receiver: SS58String` | `Result<(), Error>` | Yes | Set authorized receiver |
302
- | `remove_authorized_receiver` | `node_id: SS58String` | `Result<(), Error>` | Yes | Remove authorized receiver |
303
- | `update_rewards` | `last_session: number, sorted_nodes_and_votes: Vec<(SS58String, bigint)>` | `Result<(), Error>` | Yes | Update rewards (called by pallet) |
304
- | `set_code` | `code_hash: Hash` | `Result<(), Error>` | Yes | Upgrade contract code |
305
-
306
- #### Constructor
307
-
308
- ```typescript
309
- new(mining_pool: SS58String, rewards_pallet: SS58String): Result<(), Error>
310
- ```
311
-
312
- #### Events
313
-
314
- | Name | Data | Description |
315
- |------|------|-------------|
316
- | `NodeRewardPaid` | `node, receiver, amount` | Node reward was paid |
317
-
318
- #### Errors
319
-
320
- | Name | Description |
321
- |------|-------------|
322
- | `OnlyCallableBy(SS58String)` | Only callable by specific address |
323
- | `BeyondQualificationForNodeStatus` | Beyond qualification for node status |
324
- | `ErrorIssuingPayment` | Error issuing payment |
325
- | `ErrorGettingSessionPoolFromMiningPoolContract` | Failed to get session pool |
326
- | `NotAuthorizedToWithdraw` | Not authorized to withdraw |
327
- | `NothingToWithdraw` | Nothing to withdraw |
328
- | `ErrorGettingCurrentValidators` | Failed to get current validators |
329
-
330
- ---
331
-
332
- ### Merchant Mining
333
-
334
- Contract for merchant-consumer green points and rewards system.
335
-
336
- #### Storage
337
-
338
- | Key | Type | Description |
339
- |-----|------|-------------|
340
- | `subscription_fee` | `bigint` | Merchant subscription fee |
341
- | `usdt_contract` | `SS58String` | USDT contract address |
342
- | `amm_contract` | `SS58String` | AMM contract address |
343
- | `mining_pool` | `SS58String` | Mining pool address |
344
- | `milliseconds_day` | `bigint` | Milliseconds per day |
345
- | `admin` | `SS58String` | Contract admin |
346
- | `merchant_expiry` | `Map<SS58String, bigint>` | Merchant subscription expiry |
347
- | `accounts` | `Map<SS58String, Account>` | User accounts |
348
-
349
- #### Account Structure
350
-
351
- ```typescript
352
- {
353
- green_points: bigint;
354
- relationship_factors: [bigint, bigint];
355
- last_conversion?: bigint;
356
- redeemed_usdt: bigint;
357
- redeemed_d9: bigint;
358
- created_at: bigint;
359
- }
360
- ```
361
-
362
- #### Messages
363
-
364
- | Name | Parameters | Returns | Mutates | Payable | Description |
365
- |------|------------|---------|---------|---------|-------------|
366
- | `subscribe` | `usdt_amount: bigint` | `Result<bigint, Error>` | Yes | No | Create/extend merchant subscription |
367
- | `redeem_d9` | - | `Result<bigint, Error>` | Yes | No | Redeem D9 from green points |
368
- | `give_green_points_d9` | `consumer_id: SS58String` | `Result<{merchant, consumer}, Error>` | Yes | Yes | Give green points (D9 payment) |
369
- | `give_green_points_usdt` | `consumer_id: SS58String, usdt_payment: bigint` | `Result<{merchant, consumer}, Error>` | Yes | No | Give green points (USDT payment) |
370
- | `send_usdt_payment_to_merchant` | `merchant_id: SS58String, usdt_amount: bigint` | `Result<{merchant, consumer}, Error>` | Yes | Yes | Send USDT payment to merchant |
371
- | `send_d9_payment_to_merchant` | `merchant_id: SS58String` | `Result<{merchant, consumer}, Error>` | Yes | Yes | Send D9 payment to merchant |
372
- | `get_expiry` | `account_id: SS58String` | `bigint` | No | No | Get merchant subscription expiry |
373
- | `get_account` | `account_id: SS58String` | `Account?` | No | No | Get account details |
374
- | `change_amm_contract` | `new_amm_contract: SS58String` | `Result<(), Error>` | Yes | No | Change AMM contract |
375
- | `change_mining_pool` | `new_mining_pool: SS58String` | `Result<(), Error>` | Yes | No | Change mining pool |
376
- | `change_admin` | `new_admin: SS58String` | `Result<(), Error>` | Yes | No | Change admin |
377
- | `set_code` | `code_hash: Hash` | `Result<(), Error>` | Yes | No | Upgrade contract code |
378
-
379
- #### Constructor
380
-
381
- ```typescript
382
- new(
383
- amm_contract: SS58String,
384
- mining_pool: SS58String,
385
- usdt_contract: SS58String
386
- ): Result<(), Error>
387
- ```
388
-
389
- #### Events
390
-
391
- | Name | Data | Description |
392
- |------|------|-------------|
393
- | `SubscriptionExtended` | `account_id, usdt, expiry` | Subscription extended |
394
- | `D9Redeemed` | `account_id, redeemed_d9` | D9 was redeemed |
395
- | `GreenPointsTransaction` | `{merchant: {account_id, green_points}, consumer: {account_id, green_points}}` | Green points awarded |
396
- | `D9MerchantPaymentSent` | `merchant, consumer, amount` | D9 payment sent |
397
- | `USDTMerchantPaymentSent` | `merchant, consumer, amount` | USDT payment sent |
398
- | `GivePointsUSDT` | `consumer, merchant, amount` | USDT green points given |
399
-
400
- ---
401
-
402
- ## DeFi Contracts
403
-
404
- ### Market Maker (AMM)
405
-
406
- Automated Market Maker for D9/USDT swaps and liquidity provision.
407
-
408
- #### Storage
409
-
410
- | Key | Type | Description |
411
- |-----|------|-------------|
412
- | `usdt_contract` | `SS58String` | USDT contract address |
413
- | `fee_percent` | `number` | Trading fee percentage |
414
- | `fee_total` | `bigint` | Total fees collected |
415
- | `liquidity_tolerance_percent` | `number` | Liquidity tolerance percentage |
416
- | `total_lp_tokens` | `bigint` | Total LP tokens minted |
417
- | `admin` | `SS58String` | Contract admin |
418
- | `liquidity_providers` | `Map<SS58String, bigint>` | LP token balances |
419
-
420
- #### Messages
421
-
422
- | Name | Parameters | Returns | Mutates | Payable | Description |
423
- |------|------------|---------|---------|---------|-------------|
424
- | `get_currency_reserves` | - | `[bigint, bigint]` | No | No | Get pool reserves (D9, USDT) |
425
- | `get_liquidity_provider` | `account_id: SS58String` | `bigint?` | No | No | Get LP token balance |
426
- | `add_liquidity` | `usdt_liquidity: bigint` | `Result<(), Error>` | Yes | Yes | Add liquidity (send D9) |
427
- | `remove_liquidity` | - | `Result<(), Error>` | Yes | No | Remove all liquidity |
428
- | `get_d9` | `usdt: bigint` | `Result<bigint, Error>` | Yes | No | Swap USDT for D9 |
429
- | `get_usdt` | - | `Result<bigint, Error>` | Yes | Yes | Swap D9 for USDT |
430
- | `calculate_exchange` | `direction: [Currency, Currency], amount_0: bigint` | `Result<bigint, Error>` | No | No | Calculate exchange amount |
431
- | `estimate_exchange` | `direction: [Currency, Currency], amount_0: bigint` | `Result<[bigint, bigint], Error>` | No | No | Estimate exchange with fees |
432
- | `check_new_liquidity` | `usdt_liquidity: bigint, d9_liquidity: bigint` | `Result<(), Error>` | No | No | Check if liquidity is valid |
433
- | `calc_new_lp_tokens` | `d9_liquidity: bigint, usdt_liquidity: bigint` | `bigint` | Yes | No | Calculate LP tokens for liquidity |
434
- | `check_usdt_balance` | `account_id: SS58String, amount: bigint` | `Result<(), Error>` | No | No | Check USDT balance |
435
- | `change_admin` | `new_admin: SS58String` | `Result<(), Error>` | Yes | No | Change admin |
436
- | `set_code` | `code_hash: Hash` | `Result<(), Error>` | Yes | No | Upgrade contract code |
437
-
438
- #### Constructor
439
-
440
- ```typescript
441
- new(
442
- usdt_contract: SS58String,
443
- fee_percent: number,
444
- liquidity_tolerance_percent: number
445
- ): Result<(), Error>
446
- ```
447
-
448
- #### Currency Type
449
-
450
- ```typescript
451
- enum Currency {
452
- D9,
453
- USDT
454
- }
455
- ```
456
-
457
- #### Events
458
-
459
- | Name | Data | Description |
460
- |------|------|-------------|
461
- | `LiquidityAdded` | `account_id, usdt, d9` | Liquidity added to pool |
462
- | `LiquidityRemoved` | `account_id, usdt, d9` | Liquidity removed from pool |
463
- | `D9ToUSDTConversion` | `account_id, usdt, d9` | D9 swapped for USDT |
464
- | `USDTToD9Conversion` | `account_id, usdt, d9` | USDT swapped for D9 |
465
-
466
- #### Errors
467
-
468
- | Name | Description |
469
- |------|-------------|
470
- | `D9orUSDTProvidedLiquidityAtZero` | Liquidity amount is zero |
471
- | `ConversionAmountTooLow` | Conversion amount too low |
472
- | `CouldntTransferUSDTFromUser` | Failed to transfer USDT |
473
- | `InsufficientLiquidity(Currency)` | Pool has insufficient liquidity |
474
- | `InsufficientAllowance` | Insufficient USDT allowance |
475
- | `MarketMakerHasInsufficientFunds(Currency)` | AMM has insufficient funds |
476
- | `InsufficientLiquidityProvided` | Insufficient liquidity provided |
477
- | `USDTBalanceInsufficient` | USDT balance insufficient |
478
- | `LiquidityProviderNotFound` | LP not found |
479
- | `LiquidityAddedBeyondTolerance([bigint, bigint])` | Liquidity ratio beyond tolerance |
480
- | `InsufficientLPTokens` | Insufficient LP tokens |
481
- | `InsufficientContractLPTokens` | Contract has insufficient LP tokens |
482
- | `DivisionByZero` | Division by zero |
483
- | `MultiplicationError` | Multiplication overflow |
484
- | `USDTTooSmall` | USDT amount too small |
485
- | `USDTTooMuch` | USDT amount too large |
486
- | `LiquidityTooLow` | Liquidity too low |
487
-
488
- ---
489
-
490
- ## Bridge Contracts
491
-
492
- ### Cross-Chain Transfer
493
-
494
- Contract for cross-chain USDT transfers between D9 and TRON.
495
-
496
- #### Storage
497
-
498
- | Key | Type | Description |
499
- |-----|------|-------------|
500
- | `super_admin` | `SS58String` | Super admin address |
501
- | `new_admin` | `SS58String` | Pending new admin |
502
- | `controller` | `SS58String` | Controller address |
503
- | `usdt_contract` | `SS58String` | USDT contract address |
504
- | `transaction_admins` | `Vec<SS58String>` | Transaction admin list |
505
- | `user_transaction_nonce` | `Map<SS58String, bigint>` | User transaction nonces |
506
- | `transactions` | `Map<String, Transaction>` | Transaction records |
507
-
508
- #### Transaction Structure
509
-
510
- ```typescript
511
- {
512
- transaction_id: string;
513
- transaction_type: "Commit" | "Dispatch";
514
- from_chain: "D9" | "TRON";
515
- from_address: { Tron: FixedSizeBinary<21> } | { D9: SS58String };
516
- to_address: { Tron: FixedSizeBinary<21> } | { D9: SS58String };
517
- amount: bigint;
518
- timestamp: bigint;
519
- }
520
- ```
521
-
522
- #### Messages
523
-
524
- | Name | Parameters | Returns | Mutates | Description |
525
- |------|------------|---------|---------|-------------|
526
- | `asset_commit` | `transaction_id: string, from_address: SS58String, to_address: FixedSizeBinary<21>, amount: bigint` | `Result<string, Error>` | Yes | Commit assets for cross-chain transfer (D9 -> TRON) |
527
- | `asset_dispatch` | `from_address: FixedSizeBinary<21>, to_address: SS58String, amount: bigint` | `Result<string, Error>` | Yes | Dispatch assets from TRON (TRON -> D9) |
528
- | `get_transaction` | `tx_id: string` | `Transaction?` | No | Get transaction by ID |
529
- | `get_last_transaction` | `user_id: SS58String` | `Transaction?` | No | Get user's last transaction |
530
- | `get_current_nonce` | `user_id: SS58String` | `bigint` | No | Get user's current nonce |
531
- | `generate_tx_id` | `user_id: SS58String` | `string` | No | Generate new transaction ID |
532
- | `record_cancelled_tron_transfer` | `user_id: SS58String` | `Result<(), Error>` | Yes | Record cancelled TRON transfer |
533
- | `add_transaction_admin` | `admin: SS58String` | `Result<(), Error>` | Yes | Add transaction admin |
534
- | `remove_transaction_admin` | `admin: SS58String` | `Result<(), Error>` | Yes | Remove transaction admin |
535
- | `get_transaction_admins` | - | `Vec<SS58String>` | No | Get all transaction admins |
536
- | `is_transaction_admin` | `admin: SS58String` | `boolean` | No | Check if address is admin |
537
- | `change_controller` | `new_controller: SS58String` | `Result<(), Error>` | Yes | Change controller |
538
- | `relinquish_admin` | `new_admin: SS58String` | `Result<(), Error>` | Yes | Start admin transfer |
539
- | `claim_admin` | - | `Result<(), Error>` | Yes | Claim admin role |
540
- | `cancel_admin_transfer` | - | `Result<(), Error>` | Yes | Cancel admin transfer |
541
- | `set_code` | `code_hash: Hash` | `Result<(), Error>` | Yes | Upgrade contract code |
542
-
543
- #### Constructor
544
-
545
- ```typescript
546
- new(usdt_contract: SS58String): Result<(), Error>
547
- ```
548
-
549
- #### Events
550
-
551
- | Name | Data | Description |
552
- |------|------|-------------|
553
- | `CommitCreated` | `transaction_id, from_address, amount` | Cross-chain commit created |
554
- | `DispatchCompleted` | `tx_id, to_address, amount` | Cross-chain dispatch completed |
555
-
556
- #### Errors
557
-
558
- | Name | Description |
559
- |------|-------------|
560
- | `Restrictedto(SS58String)` | Restricted to specific address |
561
- | `AmountMustBeGreaterThanZero` | Amount must be greater than zero |
562
- | `TransactionAlreadyExists` | Transaction already exists |
563
- | `InvalidAddressLength(Chain)` | Invalid address length for chain |
564
- | `InvalidHexString` | Invalid hex string |
565
- | `DecodedHexLengthInvalid` | Decoded hex length invalid |
566
- | `TronAddressInvalidByteLength` | TRON address invalid byte length |
567
- | `InvalidTronAddress` | Invalid TRON address |
568
- | `TronDecodeError` | TRON decode error |
569
- | `UnableToSendUSDT` | Unable to send USDT |
570
- | `InsufficientAllowance` | Insufficient USDT allowance |
571
- | `UserUSDTBalanceInsufficient` | User USDT balance insufficient |
572
- | `AlreadyTransactionAdmin` | Already a transaction admin |
573
-
574
- ---
575
-
576
- ## Common Contract Features
577
-
578
- ### Upgradability
579
-
580
- All contracts support code upgrades via the `set_code` message:
581
-
582
- ```typescript
583
- set_code(code_hash: FixedSizeBinary<32>): Result<(), Error>
584
- ```
585
-
586
- This allows the contract logic to be updated while preserving storage and address.
587
-
588
- ### Error Handling
589
-
590
- All contracts use Rust's `Result` type for error handling. Common error patterns:
591
-
592
- - `CouldNotReadInput` - Failed to decode input parameters
593
- - Cross-contract call errors (trapped, reverted)
594
- - Authorization errors (restricted functions)
595
- - Balance/allowance insufficient errors
596
-
597
- ### Admin Patterns
598
-
599
- Most contracts follow a two-step admin transfer pattern:
600
-
601
- 1. Current admin calls `relinquish_admin(new_admin)`
602
- 2. New admin calls `accept_admin()` or `claim_admin()`
603
- 3. Current admin can call `cancel_admin_transfer()` before acceptance