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
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
export const MAX_U64 = 0xffffffffffffffffn;
|
|
2
|
+
/**
|
|
3
|
+
* Represents token's number of decimal place).
|
|
4
|
+
* Valid range: 0-18. WART uses 8 decimal places.
|
|
5
|
+
*/
|
|
6
|
+
export class TokenDecimals {
|
|
7
|
+
/**
|
|
8
|
+
* Create a TokenDecimals instance.
|
|
9
|
+
* @param decimals - Number of decimal places (0-18)
|
|
10
|
+
* @throws Error if decimals is out of range
|
|
11
|
+
*/
|
|
12
|
+
constructor(decimals) {
|
|
13
|
+
this.decimals = decimals;
|
|
14
|
+
if (decimals < 0 || decimals > 18) {
|
|
15
|
+
throw new Error("Invalid decimals");
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Pre-configured WART decimals (8 decimals) */
|
|
20
|
+
TokenDecimals.WART = new TokenDecimals(8);
|
|
21
|
+
/** Pre-configured Liquidity decimals (8 decimals) */
|
|
22
|
+
TokenDecimals.LIQUIDITY = new TokenDecimals(8);
|
|
23
|
+
/**
|
|
24
|
+
* Represents a parsed decimal string as a 64-bit integer with decimal place info.
|
|
25
|
+
* Used internally for parsing currency strings.
|
|
26
|
+
*/
|
|
27
|
+
export class ParsedFunds {
|
|
28
|
+
constructor(val, decimalPlaces) {
|
|
29
|
+
this.val = val;
|
|
30
|
+
this.decimalPlaces = decimalPlaces;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Parse a decimal string into a ParsedFunds.
|
|
34
|
+
* @param s - Decimal string (e.g., "123.45")
|
|
35
|
+
* @returns ParsedFunds or null if invalid
|
|
36
|
+
*/
|
|
37
|
+
static parse(s) {
|
|
38
|
+
const MAX_DIGITS = 20;
|
|
39
|
+
let str = "";
|
|
40
|
+
let digitsAfterDot = 0;
|
|
41
|
+
let dotFound = false;
|
|
42
|
+
for (const char of s) {
|
|
43
|
+
if (char >= "0" && char <= "9") {
|
|
44
|
+
if (str.length >= MAX_DIGITS) {
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
str += char;
|
|
48
|
+
if (dotFound) {
|
|
49
|
+
digitsAfterDot++;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (char === ".") {
|
|
53
|
+
if (dotFound) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
dotFound = true;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (str.length === 0) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
const val = BigInt(str);
|
|
66
|
+
if (val > MAX_U64) {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
return new ParsedFunds(val, digitsAfterDot);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Convert ParsedFunds to a value for the given number of decimal places.
|
|
74
|
+
* @param fd - Parsed funds to convert
|
|
75
|
+
* @param decimals - Target decimal places
|
|
76
|
+
* @returns Value as bigint or null if invalid
|
|
77
|
+
*/
|
|
78
|
+
function valueFrom(fd, decimals) {
|
|
79
|
+
if (fd.decimalPlaces > decimals) {
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
82
|
+
const zeros = decimals - fd.decimalPlaces;
|
|
83
|
+
let value = fd.val;
|
|
84
|
+
for (let i = 0; i < zeros; i++) {
|
|
85
|
+
if (MAX_U64 / 10n < value) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
value *= 10n;
|
|
89
|
+
}
|
|
90
|
+
return value;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Represents token amounts with specific number of decimals.
|
|
94
|
+
*/
|
|
95
|
+
export class Funds {
|
|
96
|
+
constructor(amount) {
|
|
97
|
+
this.amount = amount;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Parse a decimal string to Funds.
|
|
101
|
+
* @param string - Decimal string (e.g., "123.45")
|
|
102
|
+
* @param decimals - Token decimals
|
|
103
|
+
* @returns Funds or null if invalid
|
|
104
|
+
*/
|
|
105
|
+
static parse(string, decimals) {
|
|
106
|
+
const fd = ParsedFunds.parse(string);
|
|
107
|
+
if (fd === null)
|
|
108
|
+
return null;
|
|
109
|
+
return Funds.fromParsedFunds(fd, decimals);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Convert ParsedFunds to Funds with specific number of decimals.
|
|
113
|
+
* @param fd - Parsed funds
|
|
114
|
+
* @param decimals - Token decimals
|
|
115
|
+
* @returns Funds or null if invalid
|
|
116
|
+
*/
|
|
117
|
+
static fromParsedFunds(fd, decimals) {
|
|
118
|
+
const value = valueFrom(fd, decimals.decimals);
|
|
119
|
+
if (value === null)
|
|
120
|
+
return null;
|
|
121
|
+
return new Funds(value);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Represents Warthog's native token (WART) with 8 decimal places.
|
|
126
|
+
*/
|
|
127
|
+
export class Wart {
|
|
128
|
+
constructor(E8) {
|
|
129
|
+
this.E8 = E8;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Parse a decimal string to Wart.
|
|
133
|
+
* @param string - Decimal string (e.g., "1.5")
|
|
134
|
+
* @returns Wart or null if invalid
|
|
135
|
+
*/
|
|
136
|
+
static parse(string) {
|
|
137
|
+
const fd = ParsedFunds.parse(string);
|
|
138
|
+
if (fd === null)
|
|
139
|
+
return null;
|
|
140
|
+
return Wart.fromParsedFunds(fd);
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Convert ParsedFunds to Wart.
|
|
144
|
+
* @param fd - Parsed funds
|
|
145
|
+
* @returns Wart or null if invalid
|
|
146
|
+
*/
|
|
147
|
+
static fromParsedFunds(fd) {
|
|
148
|
+
const value = valueFrom(fd, TokenDecimals.WART.decimals);
|
|
149
|
+
if (value === null)
|
|
150
|
+
return null;
|
|
151
|
+
return new Wart(value);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Create Wart from E8 value.
|
|
155
|
+
* @param E8 - Amount in E8 (1 WART = 100,000,000 E8)
|
|
156
|
+
* @returns Wart or null if invalid (exceeds MAX_U64)
|
|
157
|
+
*/
|
|
158
|
+
static fromE8(E8) {
|
|
159
|
+
if (E8 > MAX_U64) {
|
|
160
|
+
return null;
|
|
161
|
+
}
|
|
162
|
+
return new Wart(E8);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Convert to rounded fee.
|
|
166
|
+
* @param ceil - If true, round up; otherwise round down
|
|
167
|
+
* @returns RoundedFee
|
|
168
|
+
*/
|
|
169
|
+
roundedFee(ceil) {
|
|
170
|
+
return RoundedFee.fromWart(this, ceil);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Represents liquidity pool tokens with 8 decimal places.
|
|
175
|
+
* Used for liquidity deposit/withdrawal transactions.
|
|
176
|
+
*/
|
|
177
|
+
export class Liquidity {
|
|
178
|
+
constructor(E8) {
|
|
179
|
+
this.E8 = E8;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Parse a decimal string to Liquidity.
|
|
183
|
+
* @param string - Decimal string (e.g., "1.5")
|
|
184
|
+
* @returns Liquidity or null if invalid
|
|
185
|
+
*/
|
|
186
|
+
static parse(string) {
|
|
187
|
+
const fd = ParsedFunds.parse(string);
|
|
188
|
+
if (fd === null)
|
|
189
|
+
return null;
|
|
190
|
+
return Liquidity.fromParsedFunds(fd);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Convert ParsedFunds to Liquidity.
|
|
194
|
+
* @param fd - Parsed funds
|
|
195
|
+
* @returns Liquidity or null if invalid
|
|
196
|
+
*/
|
|
197
|
+
static fromParsedFunds(fd) {
|
|
198
|
+
const value = valueFrom(fd, TokenDecimals.LIQUIDITY.decimals);
|
|
199
|
+
if (value === null)
|
|
200
|
+
return null;
|
|
201
|
+
return new Liquidity(value);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Create Liquidity from E8 value.
|
|
205
|
+
* @param E8 - Amount in E8 (1 liquidity = 100,000,000 E8)
|
|
206
|
+
* @returns Liquidity or null if invalid (exceeds MAX_U64)
|
|
207
|
+
*/
|
|
208
|
+
static fromE8(E8) {
|
|
209
|
+
if (E8 > MAX_U64) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
return new Liquidity(E8);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Transaction fee in rounded WART format.
|
|
217
|
+
*
|
|
218
|
+
* This is NOT the 16-bit compact representation itself. Instead, it is the result of:
|
|
219
|
+
* 1. Converting WART to 16-bit compact format (CompactFee)
|
|
220
|
+
* 2. Converting back to WART scale
|
|
221
|
+
*
|
|
222
|
+
* This is a lossy operation - the original WART value cannot be restored from RoundedFee.
|
|
223
|
+
* Warthog nodes require rounded values on the 64-bit WART scale in API calls, not the
|
|
224
|
+
* raw 16-bit compact representation.
|
|
225
|
+
*/
|
|
226
|
+
export class RoundedFee {
|
|
227
|
+
constructor(E8) {
|
|
228
|
+
this.E8 = E8;
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Create RoundedFee from Wart.
|
|
232
|
+
* @param wart - Wart amount
|
|
233
|
+
* @param ceil - If true, round up; otherwise round down
|
|
234
|
+
* @returns RoundedFee
|
|
235
|
+
*/
|
|
236
|
+
static fromWart(wart, ceil) {
|
|
237
|
+
const compactFee = CompactFee.fromWart(wart, ceil);
|
|
238
|
+
const roundedWart = compactFee.toWart();
|
|
239
|
+
return new RoundedFee(roundedWart.E8);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Create RoundedFee from E8 value.
|
|
243
|
+
* @param E8 - Fee in E8
|
|
244
|
+
* @param ceil - If true, round up; otherwise round down
|
|
245
|
+
* @returns RoundedFee or null if invalid
|
|
246
|
+
*/
|
|
247
|
+
static fromE8(E8, ceil) {
|
|
248
|
+
const wart = Wart.fromE8(E8);
|
|
249
|
+
if (wart === null)
|
|
250
|
+
return null;
|
|
251
|
+
return RoundedFee.fromWart(wart, ceil);
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* Get minimum possible fee (0.00000001 WART = 1 E8).
|
|
255
|
+
* @returns Minimum RoundedFee
|
|
256
|
+
*/
|
|
257
|
+
static min() {
|
|
258
|
+
return RoundedFee.fromE8(0n, false);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Convert to Wart.
|
|
262
|
+
* @returns Wart representation
|
|
263
|
+
*/
|
|
264
|
+
toWart() {
|
|
265
|
+
return Wart.fromE8(this.E8);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Warthog's internal 16-bit compact fee representation.
|
|
270
|
+
* Used for compact storage and transmission of transaction fees within the protocol.
|
|
271
|
+
* Note: This is NOT used in transaction submission API - use RoundedFee instead.
|
|
272
|
+
*/
|
|
273
|
+
export class CompactFee {
|
|
274
|
+
constructor(exponent, mantissa) {
|
|
275
|
+
this.exponent = exponent;
|
|
276
|
+
this.mantissa = mantissa;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Create CompactFee from Wart amount.
|
|
280
|
+
* @param wart - Wart amount
|
|
281
|
+
* @param ceil - If true, round up; otherwise round down
|
|
282
|
+
* @returns CompactFee
|
|
283
|
+
*/
|
|
284
|
+
static fromWart(wart, ceil) {
|
|
285
|
+
if (wart.E8 === 0n) {
|
|
286
|
+
// ignore ceil and return smallest fee which corresponds to
|
|
287
|
+
// 0.00000001 WART
|
|
288
|
+
return new CompactFee(0, 0);
|
|
289
|
+
}
|
|
290
|
+
let e = 10;
|
|
291
|
+
const threshold = 0x07ffn;
|
|
292
|
+
let e8 = wart.E8;
|
|
293
|
+
let exact = true;
|
|
294
|
+
while (e8 > threshold) {
|
|
295
|
+
e += 1;
|
|
296
|
+
if (ceil && ((e8 & 1n) !== 0n)) {
|
|
297
|
+
exact = false;
|
|
298
|
+
}
|
|
299
|
+
e8 >>= 1n;
|
|
300
|
+
}
|
|
301
|
+
if (ceil && exact === false) {
|
|
302
|
+
e8 += 1n;
|
|
303
|
+
if (e8 > threshold) {
|
|
304
|
+
e8 >>= 1n;
|
|
305
|
+
e += 1;
|
|
306
|
+
if (e > 53)
|
|
307
|
+
return new CompactFee(15, 1023);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
while (e8 < 0x0400n) {
|
|
311
|
+
e -= 1;
|
|
312
|
+
e8 <<= 1n;
|
|
313
|
+
}
|
|
314
|
+
return new CompactFee(e, Number(e8 - 0x0400n));
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Convert CompactFee to Wart.
|
|
318
|
+
* @returns Wart representation
|
|
319
|
+
*/
|
|
320
|
+
toWart() {
|
|
321
|
+
if (this.exponent < 10) {
|
|
322
|
+
return Wart.fromE8(BigInt(1024 + this.mantissa) >> BigInt(10 - this.exponent));
|
|
323
|
+
}
|
|
324
|
+
else {
|
|
325
|
+
return Wart.fromE8(BigInt(1024 + this.mantissa) << BigInt(this.exponent - 10));
|
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et for Warthog.
|
|
4
|
+
* Uses derivation path m/44'/2070'/0 for Warthog accounts.
|
|
5
|
+
*/
|
|
6
|
+
export declare class HDWallet {
|
|
7
|
+
private rootNode;
|
|
8
|
+
private constructor();
|
|
9
|
+
/**
|
|
10
|
+
* Create an HDWallet from a BIP-39 mnemonic phrase.
|
|
11
|
+
* @param mnemonic - Space-separated list of BIP-39 words (12, 15, 18, 21, or 24 words)
|
|
12
|
+
* @returns HDWallet instance
|
|
13
|
+
*/
|
|
14
|
+
static fromMnemonic(mnemonic: string): HDWallet;
|
|
15
|
+
/**
|
|
16
|
+
* Derive an account at a specific index.
|
|
17
|
+
* Uses path m/44'/2070'/0/{index}.
|
|
18
|
+
* @param index - Account index (non-negative integer)
|
|
19
|
+
* @returns Account derived at the given index
|
|
20
|
+
*/
|
|
21
|
+
deriveAccountAtIndex(index: number): Account;
|
|
22
|
+
/**
|
|
23
|
+
* Derive an account from a custom BIP-44 path.
|
|
24
|
+
* @param path - BIP-44 derivation path (e.g., "0/0", "1/5")
|
|
25
|
+
* @returns Account derived from the path
|
|
26
|
+
*/
|
|
27
|
+
deriveAccountFromPath(path: string): Account;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=HDWallet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HDWallet.d.ts","sourceRoot":"","sources":["../../../src/types/HDWallet.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;;GAGG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAAsB;IAEtC,OAAO;IAIP;;;;OAIG;WACW,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ;IAStD;;;;;OAKG;IACI,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAInD;;;;OAIG;IACI,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAKpD"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ethers } from "ethers";
|
|
2
|
+
import { Account } from "./Account";
|
|
3
|
+
/**
|
|
4
|
+
* BIP-44 hierarchical deterministic wallet for Warthog.
|
|
5
|
+
* Uses derivation path m/44'/2070'/0 for Warthog accounts.
|
|
6
|
+
*/
|
|
7
|
+
export class HDWallet {
|
|
8
|
+
constructor(rootNode) {
|
|
9
|
+
this.rootNode = rootNode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Create an HDWallet from a BIP-39 mnemonic phrase.
|
|
13
|
+
* @param mnemonic - Space-separated list of BIP-39 words (12, 15, 18, 21, or 24 words)
|
|
14
|
+
* @returns HDWallet instance
|
|
15
|
+
*/
|
|
16
|
+
static fromMnemonic(mnemonic) {
|
|
17
|
+
const rootNode = ethers.HDNodeWallet.fromPhrase(mnemonic, "", "m/44'/2070'/0");
|
|
18
|
+
return new HDWallet(rootNode);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Derive an account at a specific index.
|
|
22
|
+
* Uses path m/44'/2070'/0/{index}.
|
|
23
|
+
* @param index - Account index (non-negative integer)
|
|
24
|
+
* @returns Account derived at the given index
|
|
25
|
+
*/
|
|
26
|
+
deriveAccountAtIndex(index) {
|
|
27
|
+
return this.deriveAccountFromPath(`0/${index}`);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Derive an account from a custom BIP-44 path.
|
|
31
|
+
* @param path - BIP-44 derivation path (e.g., "0/0", "1/5")
|
|
32
|
+
* @returns Account derived from the path
|
|
33
|
+
*/
|
|
34
|
+
deriveAccountFromPath(path) {
|
|
35
|
+
const childNode = this.rootNode.derivePath(path);
|
|
36
|
+
const privateKeyHex = childNode.privateKey.slice(2);
|
|
37
|
+
return Account.fromPrivateKeyHex(privateKeyHex);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=HDWallet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HDWallet.js","sourceRoot":"","sources":["../../../src/types/HDWallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC;;;GAGG;AACH,MAAM,OAAO,QAAQ;IAGnB,YAAoB,QAA6B;QAC/C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,YAAY,CAAC,QAAgB;QACzC,MAAM,QAAQ,GAAG,MAAM,CAAC,YAAY,CAAC,UAAU,CAC7C,QAAQ,EACR,EAAE,EACF,eAAe,CAChB,CAAC;QACF,OAAO,IAAI,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAChC,CAAC;IAED;;;;;OAKG;IACI,oBAAoB,CAAC,KAAa;QACvC,OAAO,IAAI,CAAC,qBAAqB,CAAC,KAAK,KAAK,EAAE,CAAC,CAAC;IAClD,CAAC;IAED;;;;OAIG;IACI,qBAAqB,CAAC,IAAY;QACvC,MAAM,SAAS,GAAG,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACjD,MAAM,aAAa,GAAG,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACpD,OAAO,OAAO,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;IAClD,CAAC;CACF"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction nonce (32-bit unsigned integer).
|
|
3
|
+
* Every transaction requires a unique nonce to prevent replay attacks.
|
|
4
|
+
*/
|
|
5
|
+
export declare class NonceId {
|
|
6
|
+
readonly value: number;
|
|
7
|
+
private constructor();
|
|
8
|
+
/**
|
|
9
|
+
* Validate that a number is a valid 32-bit unsigned integer.
|
|
10
|
+
* @param value - Number to validate
|
|
11
|
+
* @returns true if in range [0, 0xFFFFFFFF]
|
|
12
|
+
*/
|
|
13
|
+
static validate(value: number): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Create a NonceId from a number.
|
|
16
|
+
* @param value - Nonce value (must be 32-bit unsigned integer)
|
|
17
|
+
* @returns NonceId instance if valid, null otherwise
|
|
18
|
+
*/
|
|
19
|
+
static fromNumber(value: number): NonceId | null;
|
|
20
|
+
/**
|
|
21
|
+
* Generate a random nonce.
|
|
22
|
+
* @returns NonceId with random value in valid range
|
|
23
|
+
*/
|
|
24
|
+
static random(): NonceId;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=NonceId.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NonceId.d.ts","sourceRoot":"","sources":["../../../src/types/NonceId.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,qBAAa,OAAO;aACoB,KAAK,EAAE,MAAM;IAAjD,OAAO;IAEP;;;;OAIG;WACW,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAI9C;;;;OAIG;WACW,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI;IAOvD;;;OAGG;WACW,MAAM,IAAI,OAAO;CAGlC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
const MAX_U32 = 0xFFFFFFFF; // 4294967295
|
|
2
|
+
/**
|
|
3
|
+
* Transaction nonce (32-bit unsigned integer).
|
|
4
|
+
* Every transaction requires a unique nonce to prevent replay attacks.
|
|
5
|
+
*/
|
|
6
|
+
export class NonceId {
|
|
7
|
+
constructor(value) {
|
|
8
|
+
this.value = value;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Validate that a number is a valid 32-bit unsigned integer.
|
|
12
|
+
* @param value - Number to validate
|
|
13
|
+
* @returns true if in range [0, 0xFFFFFFFF]
|
|
14
|
+
*/
|
|
15
|
+
static validate(value) {
|
|
16
|
+
return value >= 0 && value <= MAX_U32;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Create a NonceId from a number.
|
|
20
|
+
* @param value - Nonce value (must be 32-bit unsigned integer)
|
|
21
|
+
* @returns NonceId instance if valid, null otherwise
|
|
22
|
+
*/
|
|
23
|
+
static fromNumber(value) {
|
|
24
|
+
if (!NonceId.validate(value)) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
return new NonceId(value);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Generate a random nonce.
|
|
31
|
+
* @returns NonceId with random value in valid range
|
|
32
|
+
*/
|
|
33
|
+
static random() {
|
|
34
|
+
return new NonceId(Math.floor(Math.random() * MAX_U32));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=NonceId.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NonceId.js","sourceRoot":"","sources":["../../../src/types/NonceId.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG,UAAU,CAAC,CAAC,aAAa;AAEzC;;;GAGG;AACH,MAAM,OAAO,OAAO;IAChB,YAAoC,KAAa;QAAb,UAAK,GAAL,KAAK,CAAQ;IAAG,CAAC;IAErD;;;;OAIG;IACI,MAAM,CAAC,QAAQ,CAAC,KAAa;QAChC,OAAO,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,OAAO,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,UAAU,CAAC,KAAa;QAClC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3B,OAAO,IAAI,CAAC;QAChB,CAAC;QACD,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;IAC9B,CAAC;IAED;;;OAGG;IACI,MAAM,CAAC,MAAM;QAChB,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,CAAC,CAAC;IAC5D,CAAC;CACJ"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { TokenDecimals } from './Funds';
|
|
2
|
+
export { TokenDecimals };
|
|
3
|
+
/**
|
|
4
|
+
* Represents a swap price in normalized mantissa/exponent format.
|
|
5
|
+
* - Mantissa: 16 bits, must be in range [0x8000, 0xFFFF] (high bit set for normalization)
|
|
6
|
+
* - Exponent: 8 bits, stored with offset +63 internally to map to range [0, 127]
|
|
7
|
+
* The price is interpreted as a qutient of the base and quote amount *integers*, i.e. when
|
|
8
|
+
* creating or printing this price representation, one must account for the number of
|
|
9
|
+
* decimals of the involved base asset traded.
|
|
10
|
+
*
|
|
11
|
+
* Used in limit swap transactions.
|
|
12
|
+
*/
|
|
13
|
+
export declare class Price {
|
|
14
|
+
readonly mantissa: number;
|
|
15
|
+
readonly exponent: number;
|
|
16
|
+
private constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Check if a mantissa is valid (normalized, high bit set).
|
|
19
|
+
* @param m - Mantissa value to check
|
|
20
|
+
* @returns true if in range [0x8000, 0xFFFF]
|
|
21
|
+
*/
|
|
22
|
+
private static isMantissa;
|
|
23
|
+
/**
|
|
24
|
+
* Check if a internal exponent representation is valid.
|
|
25
|
+
* @param e - Exponent value to check
|
|
26
|
+
* @returns true if in range [0, 127]
|
|
27
|
+
*/
|
|
28
|
+
private static isExponent;
|
|
29
|
+
/**
|
|
30
|
+
* Get the maximum possible price.
|
|
31
|
+
* @returns Price with maximum mantissa (0xFFFF) and exponent (127)
|
|
32
|
+
*/
|
|
33
|
+
static max(): Price;
|
|
34
|
+
/**
|
|
35
|
+
* Convert stored internal exponent to base-2 exponent.
|
|
36
|
+
* @returns Base-2 exponent (exponent - 63)
|
|
37
|
+
*/
|
|
38
|
+
private exponentBase2;
|
|
39
|
+
/**
|
|
40
|
+
* Get the base-2 exponent if mantissa is not considered as
|
|
41
|
+
* a fraction but as an integer.
|
|
42
|
+
* @returns Base-2 exponent for mantissa
|
|
43
|
+
*/
|
|
44
|
+
mantissaExponent2(): number;
|
|
45
|
+
/**
|
|
46
|
+
* Convert price to raw double (without decimals adjustment).
|
|
47
|
+
* @returns Price as double (mantissa * 2^exponent2)
|
|
48
|
+
*/
|
|
49
|
+
toDoubleRaw(): number;
|
|
50
|
+
/**
|
|
51
|
+
* Convert price to double corrected for asset decimals. In Warthog, every
|
|
52
|
+
* market is with respect to WART as quote asset, which always has 8 decimals
|
|
53
|
+
* so we only need to pass the base, i.e. asset decimals.
|
|
54
|
+
* @param dec - Number decimal places of the traded asset
|
|
55
|
+
* @returns Price as double with decimal places adjustment applied
|
|
56
|
+
*/
|
|
57
|
+
toDoubleAdjusted(dec: TokenDecimals): number;
|
|
58
|
+
/**
|
|
59
|
+
* Calculate base-10 exponent for decimals adjustment.
|
|
60
|
+
* @param dec - Number of decimals of the traded asset
|
|
61
|
+
* @returns Difference between WART decimals (8) and asset decimals
|
|
62
|
+
*/
|
|
63
|
+
private base10_decimals_exponent;
|
|
64
|
+
/**
|
|
65
|
+
* Create Price from raw mantissa and exponent values.
|
|
66
|
+
* @param mantissa - 16-bit mantissa (must be normalized: 0x8000-0xFFFF)
|
|
67
|
+
* @param exponent - Raw exponent before +63 adjustment (0-127)
|
|
68
|
+
* @returns Price instance if valid, null otherwise
|
|
69
|
+
*/
|
|
70
|
+
static fromMantissaExponent(mantissa: number, exponent: number): Price | null;
|
|
71
|
+
/**
|
|
72
|
+
* Create Price from a number and given decimals of the base asset.
|
|
73
|
+
* This is the recommended factory method for users.
|
|
74
|
+
* @param d - Price as decimal number
|
|
75
|
+
* @param baseDecimals - Number of decimals of the traded asset
|
|
76
|
+
* @param ceil - If true, round up; otherwise round down
|
|
77
|
+
* @returns Price instance if valid, null otherwise
|
|
78
|
+
*/
|
|
79
|
+
static fromNumberDecimals(d: number, baseDecimals: TokenDecimals, ceil?: boolean): Price | null;
|
|
80
|
+
static fromDoubleInternal(d: number, ceil?: boolean): Price | null;
|
|
81
|
+
/**
|
|
82
|
+
* Convert price to 6-character hex string for transaction.
|
|
83
|
+
* @returns Hex string (4 chars mantissa + 2 chars exponent)
|
|
84
|
+
*/
|
|
85
|
+
toHex(): string;
|
|
86
|
+
/**
|
|
87
|
+
* Parse price from 6-character hex string.
|
|
88
|
+
* @param hex - 6-character hex string (4 chars mantissa + 2 chars exponent)
|
|
89
|
+
* @returns Price instance if valid, null otherwise
|
|
90
|
+
*/
|
|
91
|
+
static fromHex(hex: string): Price | null;
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=Price.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Price.d.ts","sourceRoot":"","sources":["../../../src/types/Price.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,CAAC;AAEzB;;;;;;;;;GASG;AACH,qBAAa,KAAK;aAEM,QAAQ,EAAE,MAAM;aAChB,QAAQ,EAAE,MAAM;IAFpC,OAAO;IAKP;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAKzB;;;;OAIG;IACH,OAAO,CAAC,MAAM,CAAC,UAAU;IAIzB;;;OAGG;WACW,GAAG,IAAI,KAAK;IAK1B;;;OAGG;IACH,OAAO,CAAC,aAAa;IAIrB;;;;OAIG;IACI,iBAAiB,IAAI,MAAM;IAIlC;;;OAGG;IACI,WAAW,IAAI,MAAM;IAK5B;;;;;;OAMG;IACI,gBAAgB,CAAC,GAAG,EAAE,aAAa,GAAG,MAAM;IAMnD;;;;OAIG;IACH,OAAO,CAAC,wBAAwB;IAIhC;;;;;OAKG;WACW,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;IAQpF;;;;;;;OAOG;WACW,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,aAAa,EAAE,IAAI,GAAE,OAAe,GAAG,KAAK,GAAG,IAAI;WAW/F,kBAAkB,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,GAAE,OAAe,GAAG,KAAK,GAAG,IAAI;IAqBhF;;;OAGG;IACI,KAAK,IAAI,MAAM;IAMtB;;;;OAIG;WACW,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,GAAG,IAAI;CAmBnD"}
|