@andy-liquid-labs/lighter-ts-sdk 1.0.0
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/README.md +381 -0
- package/dist/index.d.mts +3686 -0
- package/dist/index.d.ts +3686 -0
- package/dist/index.js +6168 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +5939 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +57 -0
- package/src/api/exchange/change-account-tier.ts +38 -0
- package/src/api/exchange/fastwithdraw.ts +38 -0
- package/src/api/exchange/index.ts +7 -0
- package/src/api/exchange/notification-ack.ts +36 -0
- package/src/api/exchange/send-tx-batch.ts +53 -0
- package/src/api/exchange/send-tx.ts +105 -0
- package/src/api/exchange/tokens-create.ts +50 -0
- package/src/api/exchange/tokens-revoke.ts +38 -0
- package/src/api/index.ts +3 -0
- package/src/api/info/account-by-l1-address.ts +23 -0
- package/src/api/info/account.ts +80 -0
- package/src/api/info/announcement.ts +24 -0
- package/src/api/info/api-keys.ts +32 -0
- package/src/api/info/asset-details.ts +42 -0
- package/src/api/info/candles.ts +31 -0
- package/src/api/info/exchange-stats.ts +16 -0
- package/src/api/info/fastbridge-info.ts +15 -0
- package/src/api/info/funding-rates.ts +22 -0
- package/src/api/info/fundings.ts +29 -0
- package/src/api/info/index.ts +20 -0
- package/src/api/info/next-nonce.ts +26 -0
- package/src/api/info/order-book-details.ts +125 -0
- package/src/api/info/order-books.ts +23 -0
- package/src/api/info/recent-trades.ts +24 -0
- package/src/api/info/root-info.ts +13 -0
- package/src/api/info/root-status.ts +13 -0
- package/src/api/info/tx-from-l1-hash.ts +20 -0
- package/src/api/info/tx.ts +45 -0
- package/src/api/info/txs.ts +19 -0
- package/src/api/info/withdrawal-delay.ts +13 -0
- package/src/api/info-private/account-active-orders.ts +31 -0
- package/src/api/info-private/account-inactive-orders.ts +83 -0
- package/src/api/info-private/account-limits.ts +35 -0
- package/src/api/info-private/account-metadata.ts +43 -0
- package/src/api/info-private/deposit-history.ts +49 -0
- package/src/api/info-private/export.ts +41 -0
- package/src/api/info-private/fastwithdraw-info.ts +35 -0
- package/src/api/info-private/index.ts +18 -0
- package/src/api/info-private/l1-metadata.ts +35 -0
- package/src/api/info-private/liquidations.ts +96 -0
- package/src/api/info-private/pnl.ts +52 -0
- package/src/api/info-private/position-funding.ts +54 -0
- package/src/api/info-private/public-pools-metadata.ts +46 -0
- package/src/api/info-private/referral-points.ts +43 -0
- package/src/api/info-private/tokens.ts +44 -0
- package/src/api/info-private/trades.ts +66 -0
- package/src/api/info-private/transfer-fee-info.ts +37 -0
- package/src/api/info-private/transfer-history.ts +54 -0
- package/src/api/info-private/withdraw-history.ts +49 -0
- package/src/client/clientManager.ts +121 -0
- package/src/client/exchange-client.ts +637 -0
- package/src/client/http/client.ts +137 -0
- package/src/client/http/index.ts +6 -0
- package/src/client/http/interface.ts +89 -0
- package/src/client/index.ts +11 -0
- package/src/client/info-client.ts +383 -0
- package/src/client/info-private-client.ts +444 -0
- package/src/client/txClient.ts +597 -0
- package/src/client/ws-client.ts +457 -0
- package/src/crypto/ecgfp5.ts +722 -0
- package/src/crypto/goldilocks.ts +136 -0
- package/src/crypto/gorand.ts +777 -0
- package/src/crypto/index.ts +6 -0
- package/src/crypto/poseidon2.ts +365 -0
- package/src/crypto/scalar.ts +375 -0
- package/src/index.ts +112 -0
- package/src/signer/index.ts +5 -0
- package/src/signer/keyManager.ts +132 -0
- package/src/types/bridge.ts +24 -0
- package/src/types/constants.ts +252 -0
- package/src/types/errors.ts +168 -0
- package/src/types/index.ts +12 -0
- package/src/types/requests.ts +197 -0
- package/src/types/txInfo.ts +1277 -0
- package/src/types/txInfoPools.ts +502 -0
- package/src/types/txInfoSerializer.ts +348 -0
- package/src/types/ws.ts +407 -0
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Additional Transaction Info types for pools and grouped orders
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {GoldilocksElement} from '../crypto/goldilocks';
|
|
6
|
+
import {hashNoPad, hashNToOne, hashToQuinticExtension} from '../crypto/poseidon2';
|
|
7
|
+
import * as constants from './constants';
|
|
8
|
+
import * as errors from './errors';
|
|
9
|
+
import {OrderInfo, TxInfo} from './txInfo';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* L2 Create Grouped Orders Transaction Info
|
|
13
|
+
*/
|
|
14
|
+
export class L2CreateGroupedOrdersTxInfo implements TxInfo {
|
|
15
|
+
accountIndex: bigint;
|
|
16
|
+
apiKeyIndex: number;
|
|
17
|
+
groupingType: number;
|
|
18
|
+
orders: OrderInfo[];
|
|
19
|
+
expiredAt: bigint;
|
|
20
|
+
nonce: bigint;
|
|
21
|
+
signature?: Uint8Array;
|
|
22
|
+
signedHash?: string;
|
|
23
|
+
|
|
24
|
+
constructor(params: {
|
|
25
|
+
accountIndex: bigint;
|
|
26
|
+
apiKeyIndex: number;
|
|
27
|
+
groupingType: number;
|
|
28
|
+
orders: OrderInfo[];
|
|
29
|
+
expiredAt: bigint;
|
|
30
|
+
nonce: bigint;
|
|
31
|
+
}) {
|
|
32
|
+
this.accountIndex = params.accountIndex;
|
|
33
|
+
this.apiKeyIndex = params.apiKeyIndex;
|
|
34
|
+
this.groupingType = params.groupingType;
|
|
35
|
+
this.orders = params.orders;
|
|
36
|
+
this.expiredAt = params.expiredAt;
|
|
37
|
+
this.nonce = params.nonce;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
getTxType(): number {
|
|
41
|
+
return constants.TxType.L2CreateGroupedOrders;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
validate(): void {
|
|
45
|
+
// AccountIndex
|
|
46
|
+
if (this.accountIndex < constants.MIN_ACCOUNT_INDEX) {
|
|
47
|
+
throw errors.ErrAccountIndexTooLow;
|
|
48
|
+
}
|
|
49
|
+
if (this.accountIndex > constants.MAX_ACCOUNT_INDEX) {
|
|
50
|
+
throw errors.ErrAccountIndexTooHigh;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// ApiKeyIndex
|
|
54
|
+
if (this.apiKeyIndex < constants.MIN_API_KEY_INDEX) {
|
|
55
|
+
throw errors.ErrApiKeyIndexTooLow;
|
|
56
|
+
}
|
|
57
|
+
if (this.apiKeyIndex > constants.MAX_API_KEY_INDEX) {
|
|
58
|
+
throw errors.ErrApiKeyIndexTooHigh;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// GroupingType
|
|
62
|
+
if (
|
|
63
|
+
this.groupingType !== constants.GroupingType.None &&
|
|
64
|
+
this.groupingType !== constants.GroupingType.OneTriggersTheOther &&
|
|
65
|
+
this.groupingType !== constants.GroupingType.OneCancelsTheOther &&
|
|
66
|
+
this.groupingType !== constants.GroupingType.OneTriggersAOneCancelsTheOther
|
|
67
|
+
) {
|
|
68
|
+
throw errors.ErrGroupingTypeInvalid;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Orders
|
|
72
|
+
if (this.orders.length === 0) {
|
|
73
|
+
throw errors.ErrNoOrdersInGroup;
|
|
74
|
+
}
|
|
75
|
+
if (this.orders.length > constants.MAX_GROUPED_ORDER_COUNT) {
|
|
76
|
+
throw errors.ErrTooManyGroupedOrders;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Nonce
|
|
80
|
+
if (this.nonce < constants.MIN_NONCE) {
|
|
81
|
+
throw errors.ErrNonceTooLow;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// ExpiredAt
|
|
85
|
+
if (this.expiredAt < 0n || this.expiredAt > constants.MAX_TIMESTAMP) {
|
|
86
|
+
throw errors.ErrExpiredAtInvalid;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
hash(chainId: number): Uint8Array {
|
|
91
|
+
const elements: GoldilocksElement[] = [];
|
|
92
|
+
|
|
93
|
+
elements.push(GoldilocksElement.fromUint32(chainId));
|
|
94
|
+
elements.push(
|
|
95
|
+
GoldilocksElement.fromUint32(constants.TxType.L2CreateGroupedOrders)
|
|
96
|
+
);
|
|
97
|
+
elements.push(GoldilocksElement.fromInt64(this.nonce));
|
|
98
|
+
elements.push(GoldilocksElement.fromInt64(this.expiredAt));
|
|
99
|
+
|
|
100
|
+
elements.push(GoldilocksElement.fromInt64(this.accountIndex));
|
|
101
|
+
elements.push(GoldilocksElement.fromUint32(this.apiKeyIndex));
|
|
102
|
+
elements.push(GoldilocksElement.fromUint32(this.groupingType));
|
|
103
|
+
|
|
104
|
+
// Hash each order separately and aggregate them
|
|
105
|
+
const orderHashes: GoldilocksElement[][] = [];
|
|
106
|
+
for (const order of this.orders) {
|
|
107
|
+
const orderElements: GoldilocksElement[] = [
|
|
108
|
+
GoldilocksElement.fromUint32(order.marketIndex),
|
|
109
|
+
GoldilocksElement.fromInt64(order.clientOrderIndex),
|
|
110
|
+
GoldilocksElement.fromInt64(order.baseAmount),
|
|
111
|
+
GoldilocksElement.fromUint32(order.price),
|
|
112
|
+
GoldilocksElement.fromUint32(order.isAsk),
|
|
113
|
+
GoldilocksElement.fromUint32(order.type),
|
|
114
|
+
GoldilocksElement.fromUint32(order.timeInForce),
|
|
115
|
+
GoldilocksElement.fromUint32(order.reduceOnly),
|
|
116
|
+
GoldilocksElement.fromUint32(order.triggerPrice),
|
|
117
|
+
GoldilocksElement.fromInt64(order.orderExpiry),
|
|
118
|
+
];
|
|
119
|
+
orderHashes.push(hashNoPad(orderElements));
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Aggregate order hashes
|
|
123
|
+
const aggregatedOrderHash = hashNToOne(orderHashes);
|
|
124
|
+
|
|
125
|
+
// Add all 4 elements from the aggregated hash
|
|
126
|
+
elements.push(...aggregatedOrderHash);
|
|
127
|
+
|
|
128
|
+
return hashToQuinticExtension(elements);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* L2 Create Public Pool Transaction Info
|
|
134
|
+
*/
|
|
135
|
+
export class L2CreatePublicPoolTxInfo implements TxInfo {
|
|
136
|
+
accountIndex: bigint;
|
|
137
|
+
apiKeyIndex: number;
|
|
138
|
+
operatorFee: bigint;
|
|
139
|
+
initialTotalShares: bigint;
|
|
140
|
+
minOperatorShareRate: number;
|
|
141
|
+
expiredAt: bigint;
|
|
142
|
+
nonce: bigint;
|
|
143
|
+
signature?: Uint8Array;
|
|
144
|
+
signedHash?: string;
|
|
145
|
+
|
|
146
|
+
constructor(params: {
|
|
147
|
+
accountIndex: bigint;
|
|
148
|
+
apiKeyIndex: number;
|
|
149
|
+
operatorFee: bigint;
|
|
150
|
+
initialTotalShares: bigint;
|
|
151
|
+
minOperatorShareRate: number;
|
|
152
|
+
expiredAt: bigint;
|
|
153
|
+
nonce: bigint;
|
|
154
|
+
}) {
|
|
155
|
+
this.accountIndex = params.accountIndex;
|
|
156
|
+
this.apiKeyIndex = params.apiKeyIndex;
|
|
157
|
+
this.operatorFee = params.operatorFee;
|
|
158
|
+
this.initialTotalShares = params.initialTotalShares;
|
|
159
|
+
this.minOperatorShareRate = params.minOperatorShareRate;
|
|
160
|
+
this.expiredAt = params.expiredAt;
|
|
161
|
+
this.nonce = params.nonce;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
getTxType(): number {
|
|
165
|
+
return constants.TxType.L2CreatePublicPool;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
validate(): void {
|
|
169
|
+
// AccountIndex
|
|
170
|
+
if (this.accountIndex < constants.MIN_ACCOUNT_INDEX) {
|
|
171
|
+
throw errors.ErrAccountIndexTooLow;
|
|
172
|
+
}
|
|
173
|
+
if (this.accountIndex > constants.MAX_ACCOUNT_INDEX) {
|
|
174
|
+
throw errors.ErrAccountIndexTooHigh;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// ApiKeyIndex
|
|
178
|
+
if (this.apiKeyIndex < constants.MIN_API_KEY_INDEX) {
|
|
179
|
+
throw errors.ErrApiKeyIndexTooLow;
|
|
180
|
+
}
|
|
181
|
+
if (this.apiKeyIndex > constants.MAX_API_KEY_INDEX) {
|
|
182
|
+
throw errors.ErrApiKeyIndexTooHigh;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// InitialTotalShares
|
|
186
|
+
if (this.initialTotalShares < constants.MIN_INITIAL_TOTAL_SHARES) {
|
|
187
|
+
throw errors.ErrInitialTotalSharesTooLow;
|
|
188
|
+
}
|
|
189
|
+
if (this.initialTotalShares > constants.MAX_INITIAL_TOTAL_SHARES) {
|
|
190
|
+
throw errors.ErrInitialTotalSharesTooHigh;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// MinOperatorShareRate
|
|
194
|
+
if (this.minOperatorShareRate > constants.SHARE_TICK) {
|
|
195
|
+
throw errors.ErrMinOperatorShareRateTooHigh;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Nonce
|
|
199
|
+
if (this.nonce < constants.MIN_NONCE) {
|
|
200
|
+
throw errors.ErrNonceTooLow;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// ExpiredAt
|
|
204
|
+
if (this.expiredAt < 0n || this.expiredAt > constants.MAX_TIMESTAMP) {
|
|
205
|
+
throw errors.ErrExpiredAtInvalid;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
hash(chainId: number): Uint8Array {
|
|
210
|
+
const elements: GoldilocksElement[] = [];
|
|
211
|
+
|
|
212
|
+
elements.push(GoldilocksElement.fromUint32(chainId));
|
|
213
|
+
elements.push(
|
|
214
|
+
GoldilocksElement.fromUint32(constants.TxType.L2CreatePublicPool)
|
|
215
|
+
);
|
|
216
|
+
elements.push(GoldilocksElement.fromInt64(this.nonce));
|
|
217
|
+
elements.push(GoldilocksElement.fromInt64(this.expiredAt));
|
|
218
|
+
|
|
219
|
+
elements.push(GoldilocksElement.fromInt64(this.accountIndex));
|
|
220
|
+
elements.push(GoldilocksElement.fromUint32(this.apiKeyIndex));
|
|
221
|
+
elements.push(GoldilocksElement.fromInt64(this.operatorFee));
|
|
222
|
+
elements.push(GoldilocksElement.fromInt64(this.initialTotalShares));
|
|
223
|
+
elements.push(GoldilocksElement.fromUint32(this.minOperatorShareRate));
|
|
224
|
+
|
|
225
|
+
return hashToQuinticExtension(elements);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* L2 Update Public Pool Transaction Info
|
|
231
|
+
*/
|
|
232
|
+
export class L2UpdatePublicPoolTxInfo implements TxInfo {
|
|
233
|
+
accountIndex: bigint;
|
|
234
|
+
apiKeyIndex: number;
|
|
235
|
+
publicPoolIndex: bigint;
|
|
236
|
+
status: number;
|
|
237
|
+
operatorFee: bigint;
|
|
238
|
+
minOperatorShareRate: number;
|
|
239
|
+
expiredAt: bigint;
|
|
240
|
+
nonce: bigint;
|
|
241
|
+
signature?: Uint8Array;
|
|
242
|
+
signedHash?: string;
|
|
243
|
+
|
|
244
|
+
constructor(params: {
|
|
245
|
+
accountIndex: bigint;
|
|
246
|
+
apiKeyIndex: number;
|
|
247
|
+
publicPoolIndex: bigint;
|
|
248
|
+
status: number;
|
|
249
|
+
operatorFee: bigint;
|
|
250
|
+
minOperatorShareRate: number;
|
|
251
|
+
expiredAt: bigint;
|
|
252
|
+
nonce: bigint;
|
|
253
|
+
}) {
|
|
254
|
+
this.accountIndex = params.accountIndex;
|
|
255
|
+
this.apiKeyIndex = params.apiKeyIndex;
|
|
256
|
+
this.publicPoolIndex = params.publicPoolIndex;
|
|
257
|
+
this.status = params.status;
|
|
258
|
+
this.operatorFee = params.operatorFee;
|
|
259
|
+
this.minOperatorShareRate = params.minOperatorShareRate;
|
|
260
|
+
this.expiredAt = params.expiredAt;
|
|
261
|
+
this.nonce = params.nonce;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
getTxType(): number {
|
|
265
|
+
return constants.TxType.L2UpdatePublicPool;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
validate(): void {
|
|
269
|
+
// AccountIndex
|
|
270
|
+
if (this.accountIndex < constants.MIN_ACCOUNT_INDEX) {
|
|
271
|
+
throw errors.ErrAccountIndexTooLow;
|
|
272
|
+
}
|
|
273
|
+
if (this.accountIndex > constants.MAX_ACCOUNT_INDEX) {
|
|
274
|
+
throw errors.ErrAccountIndexTooHigh;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// ApiKeyIndex
|
|
278
|
+
if (this.apiKeyIndex < constants.MIN_API_KEY_INDEX) {
|
|
279
|
+
throw errors.ErrApiKeyIndexTooLow;
|
|
280
|
+
}
|
|
281
|
+
if (this.apiKeyIndex > constants.MAX_API_KEY_INDEX) {
|
|
282
|
+
throw errors.ErrApiKeyIndexTooHigh;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// PublicPoolIndex
|
|
286
|
+
if (this.publicPoolIndex < 0n) {
|
|
287
|
+
throw errors.ErrPublicPoolIndexTooLow;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// Nonce
|
|
291
|
+
if (this.nonce < constants.MIN_NONCE) {
|
|
292
|
+
throw errors.ErrNonceTooLow;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// ExpiredAt
|
|
296
|
+
if (this.expiredAt < 0n || this.expiredAt > constants.MAX_TIMESTAMP) {
|
|
297
|
+
throw errors.ErrExpiredAtInvalid;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
hash(chainId: number): Uint8Array {
|
|
302
|
+
const elements: GoldilocksElement[] = [];
|
|
303
|
+
|
|
304
|
+
elements.push(GoldilocksElement.fromUint32(chainId));
|
|
305
|
+
elements.push(
|
|
306
|
+
GoldilocksElement.fromUint32(constants.TxType.L2UpdatePublicPool)
|
|
307
|
+
);
|
|
308
|
+
elements.push(GoldilocksElement.fromInt64(this.nonce));
|
|
309
|
+
elements.push(GoldilocksElement.fromInt64(this.expiredAt));
|
|
310
|
+
|
|
311
|
+
elements.push(GoldilocksElement.fromInt64(this.accountIndex));
|
|
312
|
+
elements.push(GoldilocksElement.fromUint32(this.apiKeyIndex));
|
|
313
|
+
elements.push(GoldilocksElement.fromInt64(this.publicPoolIndex));
|
|
314
|
+
elements.push(GoldilocksElement.fromUint32(this.status));
|
|
315
|
+
elements.push(GoldilocksElement.fromInt64(this.operatorFee));
|
|
316
|
+
elements.push(GoldilocksElement.fromUint32(this.minOperatorShareRate));
|
|
317
|
+
|
|
318
|
+
return hashToQuinticExtension(elements);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* L2 Mint Shares Transaction Info
|
|
324
|
+
*/
|
|
325
|
+
export class L2MintSharesTxInfo implements TxInfo {
|
|
326
|
+
accountIndex: bigint;
|
|
327
|
+
apiKeyIndex: number;
|
|
328
|
+
publicPoolIndex: bigint;
|
|
329
|
+
shareAmount: bigint;
|
|
330
|
+
expiredAt: bigint;
|
|
331
|
+
nonce: bigint;
|
|
332
|
+
signature?: Uint8Array;
|
|
333
|
+
signedHash?: string;
|
|
334
|
+
|
|
335
|
+
constructor(params: {
|
|
336
|
+
accountIndex: bigint;
|
|
337
|
+
apiKeyIndex: number;
|
|
338
|
+
publicPoolIndex: bigint;
|
|
339
|
+
shareAmount: bigint;
|
|
340
|
+
expiredAt: bigint;
|
|
341
|
+
nonce: bigint;
|
|
342
|
+
}) {
|
|
343
|
+
this.accountIndex = params.accountIndex;
|
|
344
|
+
this.apiKeyIndex = params.apiKeyIndex;
|
|
345
|
+
this.publicPoolIndex = params.publicPoolIndex;
|
|
346
|
+
this.shareAmount = params.shareAmount;
|
|
347
|
+
this.expiredAt = params.expiredAt;
|
|
348
|
+
this.nonce = params.nonce;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
getTxType(): number {
|
|
352
|
+
return constants.TxType.L2MintShares;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
validate(): void {
|
|
356
|
+
// AccountIndex
|
|
357
|
+
if (this.accountIndex < constants.MIN_ACCOUNT_INDEX) {
|
|
358
|
+
throw errors.ErrAccountIndexTooLow;
|
|
359
|
+
}
|
|
360
|
+
if (this.accountIndex > constants.MAX_ACCOUNT_INDEX) {
|
|
361
|
+
throw errors.ErrAccountIndexTooHigh;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// ApiKeyIndex
|
|
365
|
+
if (this.apiKeyIndex < constants.MIN_API_KEY_INDEX) {
|
|
366
|
+
throw errors.ErrApiKeyIndexTooLow;
|
|
367
|
+
}
|
|
368
|
+
if (this.apiKeyIndex > constants.MAX_API_KEY_INDEX) {
|
|
369
|
+
throw errors.ErrApiKeyIndexTooHigh;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// PublicPoolIndex
|
|
373
|
+
if (this.publicPoolIndex < 0n) {
|
|
374
|
+
throw errors.ErrPublicPoolIndexTooLow;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
// ShareAmount
|
|
378
|
+
if (this.shareAmount < constants.MIN_POOL_SHARES_TO_MINT_OR_BURN) {
|
|
379
|
+
throw errors.ErrShareAmountTooLow;
|
|
380
|
+
}
|
|
381
|
+
if (this.shareAmount > constants.MAX_POOL_SHARES_TO_MINT_OR_BURN) {
|
|
382
|
+
throw errors.ErrShareAmountTooHigh;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
// Nonce
|
|
386
|
+
if (this.nonce < constants.MIN_NONCE) {
|
|
387
|
+
throw errors.ErrNonceTooLow;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// ExpiredAt
|
|
391
|
+
if (this.expiredAt < 0n || this.expiredAt > constants.MAX_TIMESTAMP) {
|
|
392
|
+
throw errors.ErrExpiredAtInvalid;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
hash(chainId: number): Uint8Array {
|
|
397
|
+
const elements: GoldilocksElement[] = [];
|
|
398
|
+
|
|
399
|
+
elements.push(GoldilocksElement.fromUint32(chainId));
|
|
400
|
+
elements.push(GoldilocksElement.fromUint32(constants.TxType.L2MintShares));
|
|
401
|
+
elements.push(GoldilocksElement.fromInt64(this.nonce));
|
|
402
|
+
elements.push(GoldilocksElement.fromInt64(this.expiredAt));
|
|
403
|
+
|
|
404
|
+
elements.push(GoldilocksElement.fromInt64(this.accountIndex));
|
|
405
|
+
elements.push(GoldilocksElement.fromUint32(this.apiKeyIndex));
|
|
406
|
+
elements.push(GoldilocksElement.fromInt64(this.publicPoolIndex));
|
|
407
|
+
elements.push(GoldilocksElement.fromInt64(this.shareAmount));
|
|
408
|
+
|
|
409
|
+
return hashToQuinticExtension(elements);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* L2 Burn Shares Transaction Info
|
|
415
|
+
*/
|
|
416
|
+
export class L2BurnSharesTxInfo implements TxInfo {
|
|
417
|
+
accountIndex: bigint;
|
|
418
|
+
apiKeyIndex: number;
|
|
419
|
+
publicPoolIndex: bigint;
|
|
420
|
+
shareAmount: bigint;
|
|
421
|
+
expiredAt: bigint;
|
|
422
|
+
nonce: bigint;
|
|
423
|
+
signature?: Uint8Array;
|
|
424
|
+
signedHash?: string;
|
|
425
|
+
|
|
426
|
+
constructor(params: {
|
|
427
|
+
accountIndex: bigint;
|
|
428
|
+
apiKeyIndex: number;
|
|
429
|
+
publicPoolIndex: bigint;
|
|
430
|
+
shareAmount: bigint;
|
|
431
|
+
expiredAt: bigint;
|
|
432
|
+
nonce: bigint;
|
|
433
|
+
}) {
|
|
434
|
+
this.accountIndex = params.accountIndex;
|
|
435
|
+
this.apiKeyIndex = params.apiKeyIndex;
|
|
436
|
+
this.publicPoolIndex = params.publicPoolIndex;
|
|
437
|
+
this.shareAmount = params.shareAmount;
|
|
438
|
+
this.expiredAt = params.expiredAt;
|
|
439
|
+
this.nonce = params.nonce;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
getTxType(): number {
|
|
443
|
+
return constants.TxType.L2BurnShares;
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
validate(): void {
|
|
447
|
+
// AccountIndex
|
|
448
|
+
if (this.accountIndex < constants.MIN_ACCOUNT_INDEX) {
|
|
449
|
+
throw errors.ErrAccountIndexTooLow;
|
|
450
|
+
}
|
|
451
|
+
if (this.accountIndex > constants.MAX_ACCOUNT_INDEX) {
|
|
452
|
+
throw errors.ErrAccountIndexTooHigh;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// ApiKeyIndex
|
|
456
|
+
if (this.apiKeyIndex < constants.MIN_API_KEY_INDEX) {
|
|
457
|
+
throw errors.ErrApiKeyIndexTooLow;
|
|
458
|
+
}
|
|
459
|
+
if (this.apiKeyIndex > constants.MAX_API_KEY_INDEX) {
|
|
460
|
+
throw errors.ErrApiKeyIndexTooHigh;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
// PublicPoolIndex
|
|
464
|
+
if (this.publicPoolIndex < 0n) {
|
|
465
|
+
throw errors.ErrPublicPoolIndexTooLow;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
// ShareAmount
|
|
469
|
+
if (this.shareAmount < constants.MIN_POOL_SHARES_TO_MINT_OR_BURN) {
|
|
470
|
+
throw errors.ErrShareAmountTooLow;
|
|
471
|
+
}
|
|
472
|
+
if (this.shareAmount > constants.MAX_POOL_SHARES_TO_MINT_OR_BURN) {
|
|
473
|
+
throw errors.ErrShareAmountTooHigh;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// Nonce
|
|
477
|
+
if (this.nonce < constants.MIN_NONCE) {
|
|
478
|
+
throw errors.ErrNonceTooLow;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// ExpiredAt
|
|
482
|
+
if (this.expiredAt < 0n || this.expiredAt > constants.MAX_TIMESTAMP) {
|
|
483
|
+
throw errors.ErrExpiredAtInvalid;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
hash(chainId: number): Uint8Array {
|
|
488
|
+
const elements: GoldilocksElement[] = [];
|
|
489
|
+
|
|
490
|
+
elements.push(GoldilocksElement.fromUint32(chainId));
|
|
491
|
+
elements.push(GoldilocksElement.fromUint32(constants.TxType.L2BurnShares));
|
|
492
|
+
elements.push(GoldilocksElement.fromInt64(this.nonce));
|
|
493
|
+
elements.push(GoldilocksElement.fromInt64(this.expiredAt));
|
|
494
|
+
|
|
495
|
+
elements.push(GoldilocksElement.fromInt64(this.accountIndex));
|
|
496
|
+
elements.push(GoldilocksElement.fromUint32(this.apiKeyIndex));
|
|
497
|
+
elements.push(GoldilocksElement.fromInt64(this.publicPoolIndex));
|
|
498
|
+
elements.push(GoldilocksElement.fromInt64(this.shareAmount));
|
|
499
|
+
|
|
500
|
+
return hashToQuinticExtension(elements);
|
|
501
|
+
}
|
|
502
|
+
}
|