@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/CLAUDE.md DELETED
@@ -1,364 +0,0 @@
1
- # D9 Chain
2
-
3
- This directory contains comprehensive developer documentation for the D9 blockchain, auto-generated from the Polkadot-API type descriptors.
4
-
5
- ## Overview
6
-
7
- D9 is a Substrate-based blockchain with custom pallets and ink! smart contracts designed for:
8
-
9
- - **Referral System** - Multi-level referral tracking and rewards
10
- - **Node Voting** - Validator candidate voting and delegation
11
- - **Mining Rewards** - Token burning and mining reward distribution
12
- - **Merchant System** - Green points and merchant-consumer interactions
13
- - **Multi-Signature** - Multi-sig account management
14
- - **Cross-Chain Bridge** - USDT transfers between D9 and TRON
15
- - **AMM Trading** - D9/USDT automated market maker
16
-
17
- ## Documentation Files
18
-
19
- | File | Description |
20
- |------|-------------|
21
- | [PALLETS.md](./PALLETS.md) | All pallet definitions (storage, extrinsics, events, errors, constants) |
22
- | [CONTRACTS.md](./CONTRACTS.md) | All ink! smart contract interfaces (messages, storage, events) |
23
- | [TYPES.md](./TYPES.md) | Type system documentation (enums, structs, utilities) |
24
-
25
- ## Quick Reference
26
-
27
- ### Chain Configuration
28
-
29
- | Property | Value |
30
- |----------|-------|
31
- | SS58 Prefix | 9 |
32
- | Token Symbol | D9 |
33
- | Token Decimals | 12 |
34
- | Block Time | ~3 seconds |
35
- | Consensus | Aura + GRANDPA |
36
-
37
- ### Key Pallets
38
-
39
- #### D9 Custom Pallets
40
-
41
- | Pallet | Purpose |
42
- |--------|---------|
43
- | `D9Referral` | Referral tree management |
44
- | `D9Treasury` | Treasury management |
45
- | `D9NodeVoting` | Validator voting system |
46
- | `D9NodeRewards` | Node reward distribution |
47
- | `CouncilLock` | Account locking governance |
48
- | `D9MultiSig` | Multi-signature accounts |
49
-
50
- #### Standard Pallets
51
-
52
- | Pallet | Purpose |
53
- |--------|---------|
54
- | `System` | Core runtime functionality |
55
- | `Balances` | Native token (D9) management |
56
- | `Assets` | Fungible asset management |
57
- | `Contracts` | ink! smart contracts |
58
- | `Session` | Validator session management |
59
- | `Grandpa` | Finality gadget |
60
- | `Collective` | Council governance |
61
- | `Treasury` | On-chain treasury |
62
-
63
- ### Smart Contracts
64
-
65
- | Contract | Address Key | Purpose |
66
- |----------|-------------|---------|
67
- | `usdt` | USDT Token | PSP22 USDT stablecoin |
68
- | `burnManager` | Burn Manager | Central burn management |
69
- | `burnMining` | Burn Mining | Individual burn mining pools |
70
- | `miningPool` | Mining Pool | Reward pool management |
71
- | `nodeReward` | Node Reward | Validator reward distribution |
72
- | `merchantMining` | Merchant Mining | Merchant green points system |
73
- | `marketMaker` | AMM | D9/USDT trading pool |
74
- | `crossChainTransfer` | Cross-Chain | D9 <-> TRON bridge |
75
-
76
- ## Usage with @d9-network/spec
77
-
78
- ### Installation
79
-
80
- ```bash
81
- bun add @d9-network/spec
82
- ```
83
-
84
- ### Creating a Client
85
-
86
- ```typescript
87
- import { createD9SdkClient } from '@d9-network/spec';
88
-
89
- const client = await createD9SdkClient();
90
- ```
91
-
92
- ### Querying Storage
93
-
94
- ```typescript
95
- // Get account balance
96
- const account = await client.query.Balances.Account.getValue(address);
97
- console.log('Free balance:', account.free);
98
-
99
- // Get all validators
100
- const validators = await client.query.Session.Validators.getValue();
101
- ```
102
-
103
- ### Submitting Extrinsics
104
-
105
- ```typescript
106
- import { createD9SdkClient, wallet } from '@d9-network/spec';
107
-
108
- const client = await createD9SdkClient();
109
- const signer = wallet.fromMnemonic(mnemonic);
110
-
111
- // Transfer D9 tokens
112
- const tx = client.tx.Balances.transfer_keep_alive({
113
- dest: recipientAddress,
114
- value: 1000000000000n // 1 D9
115
- });
116
-
117
- const result = await tx.signAndSubmit(signer);
118
- ```
119
-
120
- ### Contract Interactions
121
-
122
- ```typescript
123
- import { contracts } from '@d9-network/spec';
124
-
125
- // Get USDT contract descriptor
126
- const usdtDescriptor = contracts.usdt;
127
-
128
- // Create contract instance
129
- const usdtContract = client.getTypedContract(
130
- usdtDescriptor,
131
- USDT_CONTRACT_ADDRESS
132
- );
133
-
134
- // Query balance
135
- const balance = await usdtContract.query['PSP22::balance_of']({
136
- owner: userAddress
137
- });
138
-
139
- // Transfer tokens
140
- const result = await usdtContract.call.transfer({
141
- to: recipientAddress,
142
- value: 1000000n,
143
- _data: new Uint8Array()
144
- });
145
- ```
146
-
147
- ## Architecture
148
-
149
- ### Pallet Relationships
150
-
151
- ```
152
- ┌─────────────────┐ ┌─────────────────┐
153
- │ D9Referral │────▶│ D9NodeVoting │
154
- │ (Referral Tree)│ │ (Vote Delegation)│
155
- └─────────────────┘ └────────┬────────┘
156
-
157
-
158
- ┌─────────────────┐ ┌─────────────────┐
159
- │ D9NodeRewards │◀────│ Session │
160
- │ (Reward Distrib)│ │ (Validators) │
161
- └─────────────────┘ └─────────────────┘
162
-
163
-
164
- ┌─────────────────┐
165
- │ Node Reward │
166
- │ (Contract) │
167
- └─────────────────┘
168
- ```
169
-
170
- ### Contract Relationships
171
-
172
- ```
173
- ┌─────────────────┐
174
- │ Burn Manager │
175
- │ (Central Hub) │
176
- └────────┬────────┘
177
-
178
- ┌─────────────────┼─────────────────┐
179
- ▼ ▼ ▼
180
- ┌────────────┐ ┌────────────┐ ┌────────────┐
181
- │Burn Mining │ │Burn Mining │ │Burn Mining │
182
- │ Pool 1 │ │ Pool 2 │ │ Pool N │
183
- └────────────┘ └────────────┘ └────────────┘
184
- │ │ │
185
- └─────────────────┼─────────────────┘
186
-
187
- ┌─────────────────┐
188
- │ Mining Pool │
189
- │ (Reward Source) │
190
- └────────┬────────┘
191
-
192
- ┌─────────────────┼─────────────────┐
193
- ▼ ▼ ▼
194
- ┌────────────┐ ┌────────────┐ ┌────────────┐
195
- │ Node Reward│ │ Merchant │ │Market Maker│
196
- │ │ │ Mining │ │ (AMM) │
197
- └────────────┘ └────────────┘ └────────────┘
198
- │ │
199
- │ │
200
- ▼ ▼
201
- ┌─────────────────────────────────┐
202
- │ USDT Contract │
203
- │ (PSP22 Token) │
204
- └─────────────────────────────────┘
205
-
206
-
207
- ┌─────────────────────────────────┐
208
- │ Cross-Chain Transfer │
209
- │ (D9 <-> TRON Bridge) │
210
- └─────────────────────────────────┘
211
- ```
212
-
213
- ## Common Operations
214
-
215
- ### Balance Operations
216
-
217
- ```typescript
218
- // Check D9 balance
219
- const balance = await client.query.Balances.Account.getValue(address);
220
-
221
- // Transfer D9
222
- await client.tx.Balances.transfer_keep_alive({
223
- dest: recipient,
224
- value: amount
225
- }).signAndSubmit(signer);
226
-
227
- // Check USDT balance
228
- const usdtBalance = await usdtContract.query['PSP22::balance_of']({
229
- owner: address
230
- });
231
- ```
232
-
233
- ### Voting Operations
234
-
235
- ```typescript
236
- // Add voting power (by burning D9)
237
- await client.tx.D9NodeVoting.add_voting_interest({
238
- amount: burnAmount
239
- }).signAndSubmit(signer);
240
-
241
- // Delegate votes to a candidate
242
- await client.tx.D9NodeVoting.delegate_votes({
243
- delegations: [[candidateAddress, voteAmount]]
244
- }).signAndSubmit(signer);
245
-
246
- // Check voting interests
247
- const interests = await client.query.D9NodeVoting.UsersVotingInterests.getValue(address);
248
- ```
249
-
250
- ### Mining Operations
251
-
252
- ```typescript
253
- // Execute a burn
254
- await burnManagerContract.call.burn({
255
- burn_beneficiary: beneficiary,
256
- burn_contract: burnMiningAddress
257
- }, { value: burnAmount });
258
-
259
- // Withdraw rewards
260
- await burnManagerContract.call.withdraw({
261
- burn_contract: burnMiningAddress
262
- });
263
-
264
- // Get portfolio
265
- const portfolio = await burnManagerContract.query.get_portfolio({
266
- account_id: address
267
- });
268
- ```
269
-
270
- ### AMM Operations
271
-
272
- ```typescript
273
- // Get pool reserves
274
- const reserves = await ammContract.query.get_currency_reserves({});
275
- // Returns [d9_reserve, usdt_reserve]
276
-
277
- // Swap D9 for USDT
278
- await ammContract.call.get_usdt({}, { value: d9Amount });
279
-
280
- // Swap USDT for D9
281
- await ammContract.call.get_d9({ usdt: usdtAmount });
282
-
283
- // Add liquidity
284
- await ammContract.call.add_liquidity(
285
- { usdt_liquidity: usdtAmount },
286
- { value: d9Amount }
287
- );
288
- ```
289
-
290
- ## Error Handling
291
-
292
- ### Dispatch Errors
293
-
294
- ```typescript
295
- try {
296
- await tx.signAndSubmit(signer);
297
- } catch (error) {
298
- if (error.type === 'Module') {
299
- // Pallet-specific error
300
- const { index, error: errorData } = error.value;
301
- // Decode using metadata
302
- } else if (error.type === 'Token') {
303
- // Token error (insufficient balance, etc.)
304
- }
305
- }
306
- ```
307
-
308
- ### Contract Errors
309
-
310
- ```typescript
311
- const result = await contract.query.someMethod({ param: value });
312
-
313
- if (!result.success) {
314
- // SCALE decode error
315
- console.error('Decode error:', result.value);
316
- } else if (!result.value.success) {
317
- // Contract error
318
- console.error('Contract error:', result.value.value);
319
- } else {
320
- // Success
321
- console.log('Result:', result.value.value);
322
- }
323
- ```
324
-
325
- ## Events Subscription
326
-
327
- ```typescript
328
- // Subscribe to all events
329
- client.event.System.ExtrinsicSuccess.watch().subscribe(event => {
330
- console.log('Extrinsic succeeded:', event);
331
- });
332
-
333
- // Subscribe to transfers
334
- client.event.Balances.Transfer.watch().subscribe(({ from, to, amount }) => {
335
- console.log(`Transfer: ${from} -> ${to}: ${amount}`);
336
- });
337
-
338
- // Subscribe to contract events
339
- // Contract events are emitted via Contracts.ContractEmitted
340
- ```
341
-
342
- ## Type Generation
343
-
344
- The types in this documentation are generated from:
345
-
346
- - **Chain metadata**: `packages/spec/.papi/metadata/`
347
- - **Contract ABIs**: `packages/spec/assets/ABIs/`
348
- - **Descriptors**: `packages/spec/.papi/descriptors/`
349
-
350
- To regenerate types after chain or contract updates:
351
-
352
- ```bash
353
- bun --filter=@d9-network/spec run build
354
- ```
355
-
356
- This runs:
357
- 1. `papi` - Generates Polkadot-API descriptors from chain metadata
358
- 2. `tsdown` - Bundles TypeScript to CJS/ESM
359
-
360
- ## Related Resources
361
-
362
- - [D9 Wallet App](../../../app/) - Mobile wallet using these types
363
- - [D9 Ink SDK](../../ink/) - ink! contract interaction utilities
364
- - [Polkadot-API Docs](https://papi.how/) - Underlying API documentation