warthog-ts 0.1.21
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.
- package/LICENSE +21 -0
- package/README.md +300 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/src/tests/account.test.d.ts +2 -0
- package/dist/src/tests/account.test.d.ts.map +1 -0
- package/dist/src/tests/account.test.js +32 -0
- package/dist/src/tests/account.test.js.map +1 -0
- package/dist/src/tests/funds.test.d.ts +2 -0
- package/dist/src/tests/funds.test.d.ts.map +1 -0
- package/dist/src/tests/funds.test.js +161 -0
- package/dist/src/tests/funds.test.js.map +1 -0
- package/dist/src/tests/hdwallet.test.d.ts +2 -0
- package/dist/src/tests/hdwallet.test.d.ts.map +1 -0
- package/dist/src/tests/hdwallet.test.js +26 -0
- package/dist/src/tests/hdwallet.test.js.map +1 -0
- package/dist/src/tests/price.test.d.ts +2 -0
- package/dist/src/tests/price.test.d.ts.map +1 -0
- package/dist/src/tests/price.test.js +40 -0
- package/dist/src/tests/price.test.js.map +1 -0
- package/dist/src/types/Account.d.ts +44 -0
- package/dist/src/types/Account.d.ts.map +1 -0
- package/dist/src/types/Account.js +74 -0
- package/dist/src/types/Account.js.map +1 -0
- package/dist/src/types/Address.d.ts +24 -0
- package/dist/src/types/Address.d.ts.map +1 -0
- package/dist/src/types/Address.js +56 -0
- package/dist/src/types/Address.js.map +1 -0
- package/dist/src/types/Api.d.ts +90 -0
- package/dist/src/types/Api.d.ts.map +1 -0
- package/dist/src/types/Api.js +99 -0
- package/dist/src/types/Api.js.map +1 -0
- package/dist/src/types/Funds.d.ts +175 -0
- package/dist/src/types/Funds.d.ts.map +1 -0
- package/dist/src/types/Funds.js +329 -0
- package/dist/src/types/Funds.js.map +1 -0
- package/dist/src/types/HDWallet.d.ts +29 -0
- package/dist/src/types/HDWallet.d.ts.map +1 -0
- package/dist/src/types/HDWallet.js +40 -0
- package/dist/src/types/HDWallet.js.map +1 -0
- package/dist/src/types/NonceId.d.ts +26 -0
- package/dist/src/types/NonceId.d.ts.map +1 -0
- package/dist/src/types/NonceId.js +37 -0
- package/dist/src/types/NonceId.js.map +1 -0
- package/dist/src/types/Price.d.ts +93 -0
- package/dist/src/types/Price.d.ts.map +1 -0
- package/dist/src/types/Price.js +170 -0
- package/dist/src/types/Price.js.map +1 -0
- package/dist/src/types/TransactionContext.d.ts +135 -0
- package/dist/src/types/TransactionContext.d.ts.map +1 -0
- package/dist/src/types/TransactionContext.js +314 -0
- package/dist/src/types/TransactionContext.js.map +1 -0
- package/dist/src/util/frexp.d.ts +2 -0
- package/dist/src/util/frexp.d.ts.map +1 -0
- package/dist/src/util/frexp.js +68 -0
- package/dist/src/util/frexp.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Warthog Team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
# warthog-ts
|
|
2
|
+
|
|
3
|
+
A TypeScript library for the Warthog cryptocurrency.
|
|
4
|
+
|
|
5
|
+
## Get Started
|
|
6
|
+
|
|
7
|
+
This guide covers all the core types and how they work together.
|
|
8
|
+
|
|
9
|
+
### Account
|
|
10
|
+
|
|
11
|
+
Create or load accounts to sign transactions.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { Account } from 'warthog-ts';
|
|
15
|
+
|
|
16
|
+
// Generate a new random account (contains private key)
|
|
17
|
+
const account = Account.fromRandom();
|
|
18
|
+
console.log('New address:', account.getAddress().hex);
|
|
19
|
+
console.log('Private key:', account.getPrivateKeyHex());
|
|
20
|
+
|
|
21
|
+
// Load an existing account from a private key
|
|
22
|
+
const existing = Account.fromPrivateKeyHex('your-private-key-hex');
|
|
23
|
+
console.log('Loaded address:', existing.getAddress().hex);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Address
|
|
27
|
+
|
|
28
|
+
Warthog uses 20-byte addresses with SHA-256 checksums. The Address class handles validation and creation.
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { Address } from 'warthog-ts';
|
|
32
|
+
|
|
33
|
+
// Create from 48-character hex string (with checksum)
|
|
34
|
+
const addr1 = Address.fromHex('0000000000000000000000000000000000000000de47c9b2');
|
|
35
|
+
// Returns null if invalid
|
|
36
|
+
if (addr1 === null) {
|
|
37
|
+
console.error('Invalid address');
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Create from 40-character raw hex (20 bytes, no checksum)
|
|
41
|
+
const addr2 = Address.fromRaw('0000000000000000000000000000000000000000de47c9b2');
|
|
42
|
+
|
|
43
|
+
// Validate any address string
|
|
44
|
+
const isValid = Address.validate('0000000000000000000000000000000000000000de47c9b2');
|
|
45
|
+
console.log('Valid:', isValid); // true
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### ParsedFunds and TokenDecimals
|
|
49
|
+
|
|
50
|
+
Parse currency strings into structured data.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { ParsedFunds, TokenDecimals, Funds } from 'warthog-ts';
|
|
54
|
+
|
|
55
|
+
// Parse a decimal string into its components
|
|
56
|
+
const pf = ParsedFunds.parse('123.45');
|
|
57
|
+
// Result: { val: 12345n, decimalPlaces: 2 }
|
|
58
|
+
|
|
59
|
+
// Convert to a specific token decimals (e.g., WART has 8 decimals)
|
|
60
|
+
const decimals = new TokenDecimals(8); // Validates range 0-18
|
|
61
|
+
const funds = Funds.fromParsedFunds(pf!, decimals);
|
|
62
|
+
console.log('Funds:', funds?.amount); // 12345000000n
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Wart
|
|
66
|
+
|
|
67
|
+
WART is Warthog's native token with 8 decimal places. Use Wart for amounts.
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { Wart } from 'warthog-ts';
|
|
71
|
+
|
|
72
|
+
// Parse from string (e.g., "1.5" WART = 150000000 E8)
|
|
73
|
+
const wart = Wart.parse('1.5');
|
|
74
|
+
|
|
75
|
+
// Create directly from E8 (validated against MAX_U64)
|
|
76
|
+
const wart2 = Wart.fromE8(150000000n);
|
|
77
|
+
|
|
78
|
+
// Parse invalid string (e.g., too many decimals)
|
|
79
|
+
const invalid = Wart.parse('1.123456789'); // Too many decimal places
|
|
80
|
+
console.log('Invalid:', invalid); // null
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### RoundedFee
|
|
84
|
+
|
|
85
|
+
Transaction fees must be in a specific format (compact 16-bit representation). Use RoundedFee to create valid fees.
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { RoundedFee, Wart } from 'warthog-ts';
|
|
89
|
+
|
|
90
|
+
// Minimum possible fee (0.00000001 WART = 1 E8)
|
|
91
|
+
const minFee = RoundedFee.min();
|
|
92
|
+
|
|
93
|
+
// Create fee from E8 value
|
|
94
|
+
// Second parameter determines rounding: true = ceil, false = floor
|
|
95
|
+
const fee = RoundedFee.fromE8(1000n, false);
|
|
96
|
+
|
|
97
|
+
// Round a Wart amount to a valid fee
|
|
98
|
+
const wart = Wart.parse('1.00000005')!;
|
|
99
|
+
const roundedFee = RoundedFee.fromWart(wart, false);
|
|
100
|
+
|
|
101
|
+
// Convert fee back to Wart if needed
|
|
102
|
+
const asWart = fee.toWart();
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### NonceId
|
|
106
|
+
|
|
107
|
+
Every transaction needs a unique nonce (32-bit unsigned integer).
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
import { NonceId } from 'warthog-ts';
|
|
111
|
+
|
|
112
|
+
// Create from a number (validates 32-bit range)
|
|
113
|
+
const nonce = NonceId.fromNumber(12345);
|
|
114
|
+
// Returns null if out of range
|
|
115
|
+
|
|
116
|
+
// Generate a random nonce
|
|
117
|
+
const randomNonce = NonceId.random();
|
|
118
|
+
|
|
119
|
+
// Validate any number
|
|
120
|
+
const isValid = NonceId.validate(12345);
|
|
121
|
+
console.log('Valid:', isValid); // true
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Full Transaction Flow
|
|
125
|
+
|
|
126
|
+
Putting it all together - create and submit a transaction:
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
import {
|
|
130
|
+
Account,
|
|
131
|
+
Address,
|
|
132
|
+
RoundedFee,
|
|
133
|
+
Wart,
|
|
134
|
+
NonceId,
|
|
135
|
+
WarthogApi
|
|
136
|
+
} from 'warthog-ts';
|
|
137
|
+
|
|
138
|
+
// 1. Load your account
|
|
139
|
+
const account = Account.fromPrivateKeyHex('your-private-key');
|
|
140
|
+
|
|
141
|
+
// 2. Prepare the recipient address
|
|
142
|
+
const recipient = Address.fromHex('0000000000000000000000000000000000000000de47c9b2')!;
|
|
143
|
+
|
|
144
|
+
// 3. Connect to the API
|
|
145
|
+
const api = new WarthogApi('https://api.warthog.example');
|
|
146
|
+
|
|
147
|
+
// 4. Create a transaction context (fetches chain pin automatically)
|
|
148
|
+
const context = await api.createTransactionContext(
|
|
149
|
+
RoundedFee.min(), // Use minimum fee 0.00000001 WART
|
|
150
|
+
NonceId.random() // Generate random nonce
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
// 5. Build the transaction
|
|
154
|
+
const tx = context.wartTransfer(
|
|
155
|
+
account, // Signing account
|
|
156
|
+
recipient, // Recipient address
|
|
157
|
+
Wart.fromE8(100000000n)! // 1 WART in E8
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
// 6. Submit to the network
|
|
161
|
+
const result = await api.submitTransaction(tx);
|
|
162
|
+
if (result.success) {
|
|
163
|
+
console.log('Transaction hash:', result.data.txHash);
|
|
164
|
+
} else {
|
|
165
|
+
console.error('Error:', result.error);
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
### Other Transaction Types
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
// Asset Transfer
|
|
173
|
+
context.transferAsset(
|
|
174
|
+
account,
|
|
175
|
+
'asset-hash-hex', // Asset hash
|
|
176
|
+
recipient,
|
|
177
|
+
Funds.parse('1000', new TokenDecimals(4))! // Asset units
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
// Liquidity Transfer (transfer liquidity pool tokens)
|
|
181
|
+
context.transferLiquidity(
|
|
182
|
+
account,
|
|
183
|
+
'asset-hash-hex', // Asset hash
|
|
184
|
+
recipient,
|
|
185
|
+
Liquidity.fromE8(100n)! // Liquidity units
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
// Buy (spend WART to buy tokens)
|
|
189
|
+
context.buy(
|
|
190
|
+
account,
|
|
191
|
+
'asset-hash-hex',
|
|
192
|
+
Wart.fromE8(100000000n)!, // WART amount
|
|
193
|
+
price // Price object
|
|
194
|
+
);
|
|
195
|
+
|
|
196
|
+
// Sell (sell tokens for WART)
|
|
197
|
+
context.sell(
|
|
198
|
+
account,
|
|
199
|
+
'asset-hash-hex',
|
|
200
|
+
Funds.parse('1000', new TokenDecimals(4))!, // Asset amount
|
|
201
|
+
price // Price object
|
|
202
|
+
);
|
|
203
|
+
|
|
204
|
+
// Deposit Liquidity
|
|
205
|
+
context.depositLiquidity(
|
|
206
|
+
account,
|
|
207
|
+
'asset-hash-hex',
|
|
208
|
+
Funds.parse('1000', new TokenDecimals(4))!, // Asset amount
|
|
209
|
+
Wart.fromE8(100000000n)! // WART amount
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
// Withdraw Liquidity
|
|
213
|
+
context.withdrawLiquidity(
|
|
214
|
+
account,
|
|
215
|
+
'asset-hash-hex',
|
|
216
|
+
Liquidity.fromE8(100n)! // Liquidity units
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
// Cancel Transaction
|
|
220
|
+
context.cancelTransaction(account, cancelHeight, cancelNonceId);
|
|
221
|
+
|
|
222
|
+
// Create Assets
|
|
223
|
+
context.createAssets(
|
|
224
|
+
account,
|
|
225
|
+
Funds.parse('1000000', new TokenDecimals(10))!, // Total supply
|
|
226
|
+
TokenDecimals.WART, // Decimals
|
|
227
|
+
'MYTOKEN' // Asset name
|
|
228
|
+
);
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
## Platform Support
|
|
232
|
+
|
|
233
|
+
This library works in:
|
|
234
|
+
- ✅ Node.js (no additional setup)
|
|
235
|
+
- ✅ React Native (requires Buffer polyfill)
|
|
236
|
+
- ✅ Browsers (requires Buffer polyfill)
|
|
237
|
+
|
|
238
|
+
## Installation
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
npm install warthog-ts ethers
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## React Native Setup
|
|
245
|
+
|
|
246
|
+
For React Native, you need to polyfill Buffer:
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
import { Buffer } from 'buffer';
|
|
250
|
+
|
|
251
|
+
// In your app initialization
|
|
252
|
+
global.Buffer = Buffer;
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Dependencies
|
|
256
|
+
|
|
257
|
+
This library requires:
|
|
258
|
+
- `ethers` ^6.0.0 (peer dependency)
|
|
259
|
+
- `elliptic` ^6.6.1 (bundled)
|
|
260
|
+
|
|
261
|
+
## Development
|
|
262
|
+
|
|
263
|
+
To install dependencies:
|
|
264
|
+
|
|
265
|
+
```bash
|
|
266
|
+
bun install
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
To run tests:
|
|
270
|
+
|
|
271
|
+
```bash
|
|
272
|
+
bun test
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
To build:
|
|
276
|
+
|
|
277
|
+
```bash
|
|
278
|
+
bun run build
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Examples
|
|
282
|
+
|
|
283
|
+
Run examples with bun:
|
|
284
|
+
|
|
285
|
+
```bash
|
|
286
|
+
bun run examples/transactions.ts
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Available Examples
|
|
290
|
+
|
|
291
|
+
- `examples/transactions.ts` - Generate wallet and send all transaction types:
|
|
292
|
+
- WART Transfer
|
|
293
|
+
- Token Transfer
|
|
294
|
+
- Limit Swap
|
|
295
|
+
- Liquidity Deposit
|
|
296
|
+
- Liquidity Withdrawal
|
|
297
|
+
- Cancelation
|
|
298
|
+
- Asset Creation
|
|
299
|
+
|
|
300
|
+
This project was created using `bun init` in bun v1.3.9. [Bun](https://bun.com) is a fast all-in-one JavaScript runtime.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { Funds, ParsedFunds, TokenDecimals, Wart, CompactFee, RoundedFee, Liquidity, MAX_U64 } from "./src/types/Funds";
|
|
2
|
+
export { Price } from "./src/types/Price";
|
|
3
|
+
export { Account } from "./src/types/Account";
|
|
4
|
+
export { Address } from "./src/types/Address";
|
|
5
|
+
export { NonceId } from "./src/types/NonceId";
|
|
6
|
+
export { HDWallet } from "./src/types/HDWallet";
|
|
7
|
+
export { TransactionContext } from "./src/types/TransactionContext";
|
|
8
|
+
export type { ChainPin, TransactionJson } from "./src/types/TransactionContext";
|
|
9
|
+
export { WarthogApi, KNOWN_NODES } from "./src/types/Api";
|
|
10
|
+
export type { NodeUrl, ApiResult, ApiSuccess, ApiError, ChainHeadData, SubmitTransactionData } from "./src/types/Api";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACxH,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACpE,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC1D,YAAY,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { Funds, ParsedFunds, TokenDecimals, Wart, CompactFee, RoundedFee, Liquidity, MAX_U64 } from "./src/types/Funds";
|
|
2
|
+
export { Price } from "./src/types/Price";
|
|
3
|
+
export { Account } from "./src/types/Account";
|
|
4
|
+
export { Address } from "./src/types/Address";
|
|
5
|
+
export { NonceId } from "./src/types/NonceId";
|
|
6
|
+
export { HDWallet } from "./src/types/HDWallet";
|
|
7
|
+
export { TransactionContext } from "./src/types/TransactionContext";
|
|
8
|
+
export { WarthogApi, KNOWN_NODES } from "./src/types/Api";
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACxH,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.test.d.ts","sourceRoot":"","sources":["../../../src/tests/account.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { test, expect } from "bun:test";
|
|
2
|
+
import { Account } from "../types/Account";
|
|
3
|
+
import { Address } from "../types/Address";
|
|
4
|
+
test("Account.fromRandom generates valid address", () => {
|
|
5
|
+
const addr = Account.fromRandom();
|
|
6
|
+
expect(addr.privateKeyHex.length).toBe(64);
|
|
7
|
+
expect(addr.publicKeyHex.length).toBe(66);
|
|
8
|
+
expect(addr.address.hex.length).toBe(48);
|
|
9
|
+
expect(Address.validate(addr.address.hex)).toBe(true);
|
|
10
|
+
});
|
|
11
|
+
test("Account.fromPrivateKeyHex generates correct keys from known private key", () => {
|
|
12
|
+
const privateKeyHex = "966a71a98bb5d13e9116c0dffa3f1a7877e45c6f563897b96cfd5c59bf0803e0";
|
|
13
|
+
const addr = Account.fromPrivateKeyHex(privateKeyHex);
|
|
14
|
+
expect(addr.privateKeyHex).toBe(privateKeyHex);
|
|
15
|
+
expect(addr.publicKeyHex).toBe("02916a397088159baf27b3ce1271a859e3e6ea27db913a94086423e5867994e705");
|
|
16
|
+
expect(addr.address.hex).toBe("3661579d61abde5837a8686dc4d65348a2fc61b1fe5f4093");
|
|
17
|
+
});
|
|
18
|
+
test("Address.validate returns false for invalid checksum", () => {
|
|
19
|
+
const privateKeyHex = "966a71a98bb5d13e9116c0dffa3f1a7877e45c6f563897b96cfd5c59bf0803e0";
|
|
20
|
+
const addr = Account.fromPrivateKeyHex(privateKeyHex);
|
|
21
|
+
const address = addr.address.hex;
|
|
22
|
+
const invalidAddress = address.slice(0, -8) + "00000000";
|
|
23
|
+
expect(Address.validate(invalidAddress)).toBe(false);
|
|
24
|
+
});
|
|
25
|
+
test("Address.validate returns false for wrong length", () => {
|
|
26
|
+
expect(Address.validate("abc123")).toBe(false);
|
|
27
|
+
expect(Address.validate("a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9")).toBe(false);
|
|
28
|
+
});
|
|
29
|
+
test("Address.validate returns false for non-hex string", () => {
|
|
30
|
+
expect(Address.validate("g1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2")).toBe(false);
|
|
31
|
+
});
|
|
32
|
+
//# sourceMappingURL=account.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account.test.js","sourceRoot":"","sources":["../../../src/tests/account.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,IAAI,CAAC,4CAA4C,EAAE,GAAG,EAAE;IACpD,MAAM,IAAI,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAElC,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC3C,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1C,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAEzC,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1D,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,yEAAyE,EAAE,GAAG,EAAE;IACjF,MAAM,aAAa,GAAG,kEAAkE,CAAC;IACzF,MAAM,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;IAEtD,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IAC/C,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,oEAAoE,CAAC,CAAC;IACrG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,kDAAkD,CAAC,CAAC;AACtF,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,qDAAqD,EAAE,GAAG,EAAE;IAC7D,MAAM,aAAa,GAAG,kEAAkE,CAAC;IACzF,MAAM,IAAI,GAAG,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;IACtD,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;IACjC,MAAM,cAAc,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC;IAEzD,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACzD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,iDAAiD,EAAE,GAAG,EAAE;IACzD,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC/C,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,4DAA4D,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACvG,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,mDAAmD,EAAE,GAAG,EAAE;IAC3D,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,8CAA8C,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACzF,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funds.test.d.ts","sourceRoot":"","sources":["../../../src/tests/funds.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { test, expect } from "bun:test";
|
|
2
|
+
import { Funds, ParsedFunds, TokenDecimals, Wart, CompactFee } from "../types/Funds";
|
|
3
|
+
// Token Decimals tests
|
|
4
|
+
test("TokenDecimals rejects invalid decimals", () => {
|
|
5
|
+
expect(() => new TokenDecimals(-1)).toThrow();
|
|
6
|
+
expect(() => new TokenDecimals(19)).toThrow();
|
|
7
|
+
});
|
|
8
|
+
// ParsedFunds tests
|
|
9
|
+
test("ParsedFunds.parse valid input", () => {
|
|
10
|
+
const pf = ParsedFunds.parse("1.123");
|
|
11
|
+
expect(pf).not.toBeNull();
|
|
12
|
+
expect(pf.val).toBe(1123n);
|
|
13
|
+
expect(pf.decimalPlaces).toBe(3);
|
|
14
|
+
});
|
|
15
|
+
test("ParsedFunds.parse 101.123000", () => {
|
|
16
|
+
const pf = ParsedFunds.parse("101.123000");
|
|
17
|
+
expect(pf).not.toBeNull();
|
|
18
|
+
expect(pf.val).toBe(101123000n);
|
|
19
|
+
expect(pf.decimalPlaces).toBe(6);
|
|
20
|
+
});
|
|
21
|
+
test("ParsedFunds.parse 101.1230001111", () => {
|
|
22
|
+
const pf = ParsedFunds.parse("101.1230001111");
|
|
23
|
+
expect(pf).not.toBeNull();
|
|
24
|
+
expect(pf.val).toBe(1011230001111n);
|
|
25
|
+
expect(pf.decimalPlaces).toBe(10);
|
|
26
|
+
});
|
|
27
|
+
test("ParsedFunds.parse 101.00000000000000", () => {
|
|
28
|
+
const pf = ParsedFunds.parse("101.00000000000000");
|
|
29
|
+
expect(pf).not.toBeNull();
|
|
30
|
+
expect(pf.val).toBe(10100000000000000n);
|
|
31
|
+
expect(pf.decimalPlaces).toBe(14);
|
|
32
|
+
});
|
|
33
|
+
test("ParsedFunds.parse 123123101.001", () => {
|
|
34
|
+
const pf = ParsedFunds.parse("123123101.001");
|
|
35
|
+
expect(pf).not.toBeNull();
|
|
36
|
+
expect(pf.val).toBe(123123101001n);
|
|
37
|
+
expect(pf.decimalPlaces).toBe(3);
|
|
38
|
+
});
|
|
39
|
+
test("ParsedFunds.parse invalid inputs", () => {
|
|
40
|
+
expect(ParsedFunds.parse("")).toBeNull();
|
|
41
|
+
expect(ParsedFunds.parse(".")).toBeNull();
|
|
42
|
+
expect(ParsedFunds.parse("abc")).toBeNull();
|
|
43
|
+
expect(ParsedFunds.parse("1.1.1")).toBeNull();
|
|
44
|
+
expect(ParsedFunds.parse("123456789012345678901")).toBeNull();
|
|
45
|
+
expect(ParsedFunds.parse("18446744073709551616")).toBeNull();
|
|
46
|
+
});
|
|
47
|
+
// Funds tests
|
|
48
|
+
test("Funds.parse valid string input", () => {
|
|
49
|
+
const f = Funds.parse("1.123", new TokenDecimals(4));
|
|
50
|
+
expect(f).not.toBeNull();
|
|
51
|
+
expect(f.amount).toBe(11230n);
|
|
52
|
+
});
|
|
53
|
+
test("Funds.parse invalid due to decimals", () => {
|
|
54
|
+
const f = Funds.parse("1.123", new TokenDecimals(2));
|
|
55
|
+
expect(f).toBeNull();
|
|
56
|
+
});
|
|
57
|
+
test("Funds.fromParsedFunds", () => {
|
|
58
|
+
const pf = new ParsedFunds(1123n, 3);
|
|
59
|
+
const f = Funds.fromParsedFunds(pf, new TokenDecimals(4));
|
|
60
|
+
expect(f).not.toBeNull();
|
|
61
|
+
expect(f.amount).toBe(11230n);
|
|
62
|
+
});
|
|
63
|
+
test("Funds.fromParsedFunds (uint64 conversion behavior) for parsed 1.123 with 0, 4, 12, 16 decimal places", () => {
|
|
64
|
+
const s = "1.123";
|
|
65
|
+
const pf = ParsedFunds.parse(s);
|
|
66
|
+
expect(pf).not.toBeNull();
|
|
67
|
+
expect(Funds.fromParsedFunds(pf, new TokenDecimals(0))).toBeNull();
|
|
68
|
+
const f4 = Funds.fromParsedFunds(pf, new TokenDecimals(4));
|
|
69
|
+
expect(f4).not.toBeNull();
|
|
70
|
+
expect(f4.amount).toBe(11230n);
|
|
71
|
+
const f12 = Funds.fromParsedFunds(pf, new TokenDecimals(12));
|
|
72
|
+
expect(f12).not.toBeNull();
|
|
73
|
+
expect(f12.amount).toBe(1123000000000n);
|
|
74
|
+
const f16 = Funds.fromParsedFunds(pf, new TokenDecimals(16));
|
|
75
|
+
expect(f16).not.toBeNull();
|
|
76
|
+
expect(f16.amount).toBe(11230000000000000n);
|
|
77
|
+
});
|
|
78
|
+
test("Funds.fromParsedFunds for parsed 101.123000 with 0, 4, 12, 16 decimal places", () => {
|
|
79
|
+
const s = "101.123000";
|
|
80
|
+
const pf = ParsedFunds.parse(s);
|
|
81
|
+
expect(pf).not.toBeNull();
|
|
82
|
+
expect(Funds.fromParsedFunds(pf, new TokenDecimals(0))).toBeNull();
|
|
83
|
+
expect(Funds.fromParsedFunds(pf, new TokenDecimals(4))).toBeNull();
|
|
84
|
+
const f12 = Funds.fromParsedFunds(pf, new TokenDecimals(12));
|
|
85
|
+
expect(f12).not.toBeNull();
|
|
86
|
+
expect(f12.amount).toBe(101123000000000n);
|
|
87
|
+
const f16 = Funds.fromParsedFunds(pf, new TokenDecimals(16));
|
|
88
|
+
expect(f16).not.toBeNull();
|
|
89
|
+
expect(f16.amount).toBe(1011230000000000000n);
|
|
90
|
+
});
|
|
91
|
+
test("Funds.fromParsedFunds for parsed 101.1230001111 for 0, 4, 12, 16 decimal places", () => {
|
|
92
|
+
const s = "101.1230001111";
|
|
93
|
+
const pf = ParsedFunds.parse(s);
|
|
94
|
+
expect(pf).not.toBeNull();
|
|
95
|
+
expect(Funds.fromParsedFunds(pf, new TokenDecimals(0))).toBeNull();
|
|
96
|
+
expect(Funds.fromParsedFunds(pf, new TokenDecimals(4))).toBeNull();
|
|
97
|
+
const f12 = Funds.fromParsedFunds(pf, new TokenDecimals(12));
|
|
98
|
+
expect(f12).not.toBeNull();
|
|
99
|
+
expect(f12.amount).toBe(101123000111100n);
|
|
100
|
+
const f16 = Funds.fromParsedFunds(pf, new TokenDecimals(16));
|
|
101
|
+
expect(f16).not.toBeNull();
|
|
102
|
+
expect(f16.amount).toBe(1011230001111000000n);
|
|
103
|
+
});
|
|
104
|
+
test("Funds.fromParsedFunds for parsed 101.00000000000000 for 0, 4, 12, 16 decimal places", () => {
|
|
105
|
+
const s = "101.00000000000000";
|
|
106
|
+
const pf = ParsedFunds.parse(s);
|
|
107
|
+
expect(pf).not.toBeNull();
|
|
108
|
+
expect(Funds.fromParsedFunds(pf, new TokenDecimals(0))).toBeNull();
|
|
109
|
+
expect(Funds.fromParsedFunds(pf, new TokenDecimals(4))).toBeNull();
|
|
110
|
+
expect(Funds.fromParsedFunds(pf, new TokenDecimals(12))).toBeNull();
|
|
111
|
+
const f16 = Funds.fromParsedFunds(pf, new TokenDecimals(16));
|
|
112
|
+
expect(f16).not.toBeNull();
|
|
113
|
+
expect(f16.amount).toBe(1010000000000000000n);
|
|
114
|
+
});
|
|
115
|
+
test("Funds.fromParsedFunds for parsed 123123101.001 for 0, 4, 12, 16 decimal places", () => {
|
|
116
|
+
const s = "123123101.001";
|
|
117
|
+
const pf = ParsedFunds.parse(s);
|
|
118
|
+
expect(pf).not.toBeNull();
|
|
119
|
+
expect(Funds.fromParsedFunds(pf, new TokenDecimals(0))).toBeNull();
|
|
120
|
+
const f4 = Funds.fromParsedFunds(pf, new TokenDecimals(4));
|
|
121
|
+
expect(f4).not.toBeNull();
|
|
122
|
+
expect(f4.amount).toBe(1231231010010n);
|
|
123
|
+
expect(Funds.fromParsedFunds(pf, new TokenDecimals(12))).toBeNull();
|
|
124
|
+
expect(Funds.fromParsedFunds(pf, new TokenDecimals(16))).toBeNull();
|
|
125
|
+
});
|
|
126
|
+
// Wart tests
|
|
127
|
+
test("Wart.parse valid input", () => {
|
|
128
|
+
const w = Wart.parse("1.123");
|
|
129
|
+
expect(w).not.toBeNull();
|
|
130
|
+
expect(w.E8).toBe(112300000n);
|
|
131
|
+
});
|
|
132
|
+
test("Wart.parse invalid due to too many decimals", () => {
|
|
133
|
+
expect(Wart.parse("1.123456789")).toBeNull();
|
|
134
|
+
});
|
|
135
|
+
test("CompactFee.fromWart amount=0 returns smallest fee", () => {
|
|
136
|
+
const w = Wart.fromE8(0n);
|
|
137
|
+
const w1 = Wart.fromE8(1n);
|
|
138
|
+
expect(w.roundedFee(false).E8).toBe(1n);
|
|
139
|
+
});
|
|
140
|
+
test("Fee rounding", () => {
|
|
141
|
+
const check_rounding = (s) => {
|
|
142
|
+
const original = Wart.parse(s);
|
|
143
|
+
expect(original).not.toBeNull();
|
|
144
|
+
// round down
|
|
145
|
+
const roundedDown = original.roundedFee(false);
|
|
146
|
+
expect(roundedDown.E8).toBeLessThanOrEqual(original.E8);
|
|
147
|
+
expect(roundedDown.E8).toBe(roundedDown.toWart().roundedFee(false).E8);
|
|
148
|
+
// round up
|
|
149
|
+
const roundedUp = original.roundedFee(true);
|
|
150
|
+
expect(roundedUp.E8).toBeGreaterThanOrEqual(original.E8);
|
|
151
|
+
expect(roundedUp.E8).toBe(roundedUp.toWart().roundedFee(true).E8);
|
|
152
|
+
};
|
|
153
|
+
check_rounding(".00003112");
|
|
154
|
+
check_rounding(".00013112");
|
|
155
|
+
check_rounding(".00113112");
|
|
156
|
+
check_rounding(".0111283");
|
|
157
|
+
check_rounding(".32");
|
|
158
|
+
check_rounding("5.12354");
|
|
159
|
+
check_rounding("10.02031022");
|
|
160
|
+
});
|
|
161
|
+
//# sourceMappingURL=funds.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funds.test.js","sourceRoot":"","sources":["../../../src/tests/funds.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAErF,uBAAuB;AACvB,IAAI,CAAC,wCAAwC,EAAE,GAAG,EAAE;IAChD,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;IAC9C,MAAM,CAAC,GAAG,EAAE,CAAC,IAAI,aAAa,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;AAClD,CAAC,CAAC,CAAC;AAEH,oBAAoB;AACpB,IAAI,CAAC,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AAC,CAAC;IAC5B,cAAc,CAAC,UAAU,CAAC,CAAC;IAC3B,cAAc,CAAC,KAAK,CAAC,CAAC;IACtB,cAAc,CAAC,SAAS,CAAC,CAAC;IAC1B,cAAc,CAAC,aAAa,CAAC,CAAC;AAClC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hdwallet.test.d.ts","sourceRoot":"","sources":["../../../src/tests/hdwallet.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { test, expect } from "bun:test";
|
|
2
|
+
import { HDWallet } from "../types/HDWallet";
|
|
3
|
+
import { Account } from "../types/Account";
|
|
4
|
+
test("HDWallet.fromMnemonic return valid Account", () => {
|
|
5
|
+
const mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
|
|
6
|
+
const wallet = HDWallet.fromMnemonic(mnemonic);
|
|
7
|
+
expect(wallet).not.toBeNull();
|
|
8
|
+
const account = wallet.deriveAccountAtIndex(0);
|
|
9
|
+
expect(account.address.hex.length).toBe(48);
|
|
10
|
+
expect(account.privateKeyHex.length).toBe(64);
|
|
11
|
+
});
|
|
12
|
+
test("HDWallet.deriveAccountAtIndex(0) != deriveAccount(1)", () => {
|
|
13
|
+
const mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
|
|
14
|
+
const wallet = HDWallet.fromMnemonic(mnemonic);
|
|
15
|
+
const account0 = wallet.deriveAccountAtIndex(0);
|
|
16
|
+
const account1 = wallet.deriveAccountAtIndex(1);
|
|
17
|
+
expect(account0.address.hex).not.toBe(account1.address.hex);
|
|
18
|
+
});
|
|
19
|
+
test("HDWallet full path derivation matches index method", () => {
|
|
20
|
+
const mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
|
|
21
|
+
const wallet = HDWallet.fromMnemonic(mnemonic);
|
|
22
|
+
const accountFromIndex = wallet.deriveAccountAtIndex(0);
|
|
23
|
+
const accountFromPath = wallet.deriveAccountFromPath("0/0");
|
|
24
|
+
expect(accountFromIndex.address.hex).toBe(accountFromPath.address.hex);
|
|
25
|
+
});
|
|
26
|
+
//# sourceMappingURL=hdwallet.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hdwallet.test.js","sourceRoot":"","sources":["../../../src/tests/hdwallet.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAE3C,IAAI,CAAC,4CAA4C,EAAE,GAAG,EAAE;IACtD,MAAM,QAAQ,GACZ,+FAA+F,CAAC;IAClG,MAAM,MAAM,GAAG,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAE/C,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC9B,MAAM,OAAO,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAE/C,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5C,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAChD,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,sDAAsD,EAAE,GAAG,EAAE;IAChE,MAAM,QAAQ,GACZ,+FAA+F,CAAC;IAClG,MAAM,MAAM,GAAG,QAAQ,CAAC,YAAY,CAAC,QAAQ,CAAC,CAAC;IAE/C,MAAM,QAAQ,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC;I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