@0xtorch/core 0.0.14 → 0.0.16

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 (86) hide show
  1. package/_cjs/actions/index.js +3 -1
  2. package/_cjs/actions/index.js.map +1 -1
  3. package/_cjs/actions/schemas/crossActionBundle.js +8 -2
  4. package/_cjs/actions/schemas/crossActionBundle.js.map +1 -1
  5. package/_cjs/actions/utils.js +1318 -1
  6. package/_cjs/actions/utils.js.map +1 -1
  7. package/_cjs/index.js +3 -1
  8. package/_cjs/index.js.map +1 -1
  9. package/_esm/actions/index.js +1 -1
  10. package/_esm/actions/index.js.map +1 -1
  11. package/_esm/actions/schemas/crossActionBundle.js +8 -2
  12. package/_esm/actions/schemas/crossActionBundle.js.map +1 -1
  13. package/_esm/actions/utils.js +1389 -0
  14. package/_esm/actions/utils.js.map +1 -1
  15. package/_esm/index.js +1 -1
  16. package/_esm/index.js.map +1 -1
  17. package/_types/actions/index.d.ts +2 -2
  18. package/_types/actions/index.d.ts.map +1 -1
  19. package/_types/actions/parsers/default.d.ts +1 -1
  20. package/_types/actions/schemas/action.d.ts +950 -950
  21. package/_types/actions/schemas/borrow/borrow.d.ts +16 -16
  22. package/_types/actions/schemas/borrow/borrowWithDebt.d.ts +16 -16
  23. package/_types/actions/schemas/crossActionBundle.d.ts +1578 -45107
  24. package/_types/actions/schemas/crossActionBundle.d.ts.map +1 -1
  25. package/_types/actions/schemas/crossReplace/bridgeFrom.d.ts +16 -16
  26. package/_types/actions/schemas/crossReplace/bridgeTo.d.ts +16 -16
  27. package/_types/actions/schemas/crossReplace/crossReplace.d.ts +16 -16
  28. package/_types/actions/schemas/crossTrade/crossTrade.d.ts +16 -16
  29. package/_types/actions/schemas/default/accountAction.d.ts +18 -18
  30. package/_types/actions/schemas/default/normalAction.d.ts +18 -18
  31. package/_types/actions/schemas/deposit/addLiquidity.d.ts +16 -16
  32. package/_types/actions/schemas/deposit/deposit.d.ts +16 -16
  33. package/_types/actions/schemas/deposit/depositWithBond.d.ts +16 -16
  34. package/_types/actions/schemas/deposit/stake.d.ts +16 -16
  35. package/_types/actions/schemas/fee/fee.d.ts +16 -16
  36. package/_types/actions/schemas/fee/transactionFee.d.ts +16 -16
  37. package/_types/actions/schemas/ignore/approve.d.ts +16 -16
  38. package/_types/actions/schemas/ignore/failTx.d.ts +16 -16
  39. package/_types/actions/schemas/ignore/ignore.d.ts +8 -8
  40. package/_types/actions/schemas/ignore/move.d.ts +8 -8
  41. package/_types/actions/schemas/ignore/receiveFromCex.d.ts +16 -16
  42. package/_types/actions/schemas/ignore/revoke.d.ts +16 -16
  43. package/_types/actions/schemas/ignore/sendToCex.d.ts +16 -16
  44. package/_types/actions/schemas/ignore/spam.d.ts +16 -16
  45. package/_types/actions/schemas/income/atomicArbitrage.d.ts +16 -16
  46. package/_types/actions/schemas/income/freeMintNft.d.ts +16 -16
  47. package/_types/actions/schemas/income/income.d.ts +16 -16
  48. package/_types/actions/schemas/income/nftRoyalty.d.ts +8 -8
  49. package/_types/actions/schemas/income/swapIncome.d.ts +8 -8
  50. package/_types/actions/schemas/reduce/reduce.d.ts +8 -8
  51. package/_types/actions/schemas/repayment/repayment.d.ts +16 -16
  52. package/_types/actions/schemas/repayment/repaymentWithDebt.d.ts +16 -16
  53. package/_types/actions/schemas/replace/replace.d.ts +16 -16
  54. package/_types/actions/schemas/replace/swapNft.d.ts +16 -16
  55. package/_types/actions/schemas/replace/unwrap.d.ts +16 -16
  56. package/_types/actions/schemas/replace/wrap.d.ts +16 -16
  57. package/_types/actions/schemas/trade/buyCrypto.d.ts +16 -16
  58. package/_types/actions/schemas/trade/buyNft.d.ts +16 -16
  59. package/_types/actions/schemas/trade/mintNft.d.ts +16 -16
  60. package/_types/actions/schemas/trade/sellCrypto.d.ts +16 -16
  61. package/_types/actions/schemas/trade/sellNft.d.ts +16 -16
  62. package/_types/actions/schemas/trade/trade.d.ts +16 -16
  63. package/_types/actions/schemas/transfer/swapTransfer.d.ts +8 -8
  64. package/_types/actions/schemas/transfer/transfer.d.ts +16 -16
  65. package/_types/actions/schemas/valuedown/valuedown.d.ts +16 -16
  66. package/_types/actions/schemas/valueup/valueup.d.ts +16 -16
  67. package/_types/actions/schemas/withdraw/removeLiquidity.d.ts +16 -16
  68. package/_types/actions/schemas/withdraw/unstake.d.ts +16 -16
  69. package/_types/actions/schemas/withdraw/withdraw.d.ts +16 -16
  70. package/_types/actions/schemas/withdraw/withdrawWithBond.d.ts +16 -16
  71. package/_types/actions/types/action.d.ts +17 -1
  72. package/_types/actions/types/action.d.ts.map +1 -1
  73. package/_types/actions/types/index.d.ts +1 -1
  74. package/_types/actions/types/index.d.ts.map +1 -1
  75. package/_types/actions/utils.d.ts +3 -0
  76. package/_types/actions/utils.d.ts.map +1 -1
  77. package/_types/apps/schemas.d.ts +4 -4
  78. package/_types/index.d.ts +2 -2
  79. package/_types/index.d.ts.map +1 -1
  80. package/actions/index.ts +4 -0
  81. package/actions/schemas/crossActionBundle.ts +14 -2
  82. package/actions/types/action.ts +26 -1
  83. package/actions/types/index.ts +2 -0
  84. package/actions/utils.ts +1951 -0
  85. package/index.ts +4 -0
  86. package/package.json +1 -1
@@ -7,4 +7,1393 @@ export const isTransferNftNone = (transfer) => transfer.direction === 'none' &&
7
7
  export const isTransferFiatCurrencyIn = (transfer) => transfer.direction === 'in' && transfer.asset.type === 'FiatCurrency';
8
8
  export const isTransferFiatCurrencyOut = (transfer) => transfer.direction === 'out' && transfer.asset.type === 'FiatCurrency';
9
9
  export const isTransferFiatCurrencyNone = (transfer) => transfer.direction === 'none' && transfer.asset.type === 'FiatCurrency';
10
+ export const parseBaseNormalActionToNormalAction = (action) => {
11
+ switch (action.action) {
12
+ case 'add-liquidity': {
13
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
14
+ isTransferNftIn(transfer) ||
15
+ isTransferCryptoCurrencyOut(transfer) ||
16
+ isTransferNftOut(transfer));
17
+ if (transfers.length !== action.transfers.length) {
18
+ throw new Error('Invalid action.transfers for add-liquidity');
19
+ }
20
+ if (action.loanId === undefined) {
21
+ throw new Error('action.loandId is required for add-liquidity');
22
+ }
23
+ return {
24
+ ...action,
25
+ type: 'LoanNormalAction',
26
+ action: 'add-liquidity',
27
+ loanId: action.loanId,
28
+ transfers,
29
+ };
30
+ }
31
+ case 'approve': {
32
+ if (action.transfers.length > 0) {
33
+ throw new Error('Invalid action.transfers for approve');
34
+ }
35
+ return {
36
+ ...action,
37
+ type: 'NormalAction',
38
+ action: 'approve',
39
+ transfers: [],
40
+ };
41
+ }
42
+ case 'atomic-arbitrage': {
43
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
44
+ isTransferCryptoCurrencyOut(transfer));
45
+ if (transfers.length !== action.transfers.length) {
46
+ throw new Error('Invalid action.transfers for atomic-arbitrage');
47
+ }
48
+ return {
49
+ ...action,
50
+ type: 'NormalAction',
51
+ action: 'atomic-arbitrage',
52
+ transfers,
53
+ };
54
+ }
55
+ case 'borrow': {
56
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer));
57
+ if (transfers.length !== action.transfers.length) {
58
+ throw new Error('Invalid action.transfers for borrow');
59
+ }
60
+ if (action.loanId === undefined) {
61
+ throw new Error('action.loandId is required for borrow');
62
+ }
63
+ return {
64
+ ...action,
65
+ type: 'LoanNormalAction',
66
+ action: 'borrow',
67
+ loanId: action.loanId,
68
+ transfers,
69
+ };
70
+ }
71
+ case 'borrow-with-debt': {
72
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
73
+ isTransferNftIn(transfer) ||
74
+ isTransferCryptoCurrencyOut(transfer) ||
75
+ isTransferNftOut(transfer));
76
+ if (transfers.length !== action.transfers.length) {
77
+ throw new Error('Invalid action.transfers for borrow-with-debt');
78
+ }
79
+ if (action.loanId === undefined) {
80
+ throw new Error('action.loandId is required for borrow-with-debt');
81
+ }
82
+ return {
83
+ ...action,
84
+ type: 'LoanNormalAction',
85
+ action: 'borrow-with-debt',
86
+ loanId: action.loanId,
87
+ transfers,
88
+ };
89
+ }
90
+ case 'bridge-from': {
91
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer));
92
+ if (transfers.length !== action.transfers.length) {
93
+ throw new Error('Invalid action.transfers for bridge-from');
94
+ }
95
+ if (action.crossId === undefined) {
96
+ throw new Error('action.crossId is required for bridge-from');
97
+ }
98
+ if (action.crossType === undefined) {
99
+ throw new Error('action.crossType is required for bridge-from');
100
+ }
101
+ return {
102
+ ...action,
103
+ type: 'CrossNormalAction',
104
+ action: 'bridge-from',
105
+ crossId: action.crossId,
106
+ crossType: action.crossType,
107
+ transfers,
108
+ };
109
+ }
110
+ case 'bridge-to': {
111
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer));
112
+ if (transfers.length !== action.transfers.length) {
113
+ throw new Error('Invalid action.transfers for bridge-to');
114
+ }
115
+ if (action.crossId === undefined) {
116
+ throw new Error('action.crossId is required for bridge-to');
117
+ }
118
+ if (action.crossType === undefined) {
119
+ throw new Error('action.crossType is required for bridge-to');
120
+ }
121
+ return {
122
+ ...action,
123
+ type: 'CrossNormalAction',
124
+ action: 'bridge-to',
125
+ crossId: action.crossId,
126
+ crossType: action.crossType,
127
+ transfers,
128
+ };
129
+ }
130
+ case 'buy-crypto': {
131
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
132
+ isTransferFiatCurrencyOut(transfer));
133
+ if (transfers.length !== action.transfers.length) {
134
+ throw new Error('Invalid action.transfers for buy-crypto');
135
+ }
136
+ return {
137
+ ...action,
138
+ type: 'NormalAction',
139
+ action: 'buy-crypto',
140
+ transfers,
141
+ };
142
+ }
143
+ case 'buy-nft': {
144
+ const transfers = action.transfers.filter((transfer) => isTransferNftIn(transfer) ||
145
+ isTransferFiatCurrencyOut(transfer) ||
146
+ isTransferCryptoCurrencyOut(transfer));
147
+ if (transfers.length !== action.transfers.length) {
148
+ throw new Error('Invalid action.transfers for buy-nft');
149
+ }
150
+ return {
151
+ ...action,
152
+ type: 'NormalAction',
153
+ action: 'buy-nft',
154
+ transfers,
155
+ };
156
+ }
157
+ case 'cross-replace': {
158
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
159
+ isTransferNftIn(transfer) ||
160
+ isTransferFiatCurrencyIn(transfer) ||
161
+ isTransferCryptoCurrencyOut(transfer) ||
162
+ isTransferNftOut(transfer) ||
163
+ isTransferFiatCurrencyOut(transfer));
164
+ if (transfers.length !== action.transfers.length) {
165
+ throw new Error('Invalid action.transfers for cross-replace');
166
+ }
167
+ if (action.crossId === undefined) {
168
+ throw new Error('action.crossId is required for cross-replace');
169
+ }
170
+ if (action.crossType === undefined) {
171
+ throw new Error('action.crossType is required for cross-replace');
172
+ }
173
+ return {
174
+ ...action,
175
+ type: 'CrossNormalAction',
176
+ action: 'cross-replace',
177
+ crossId: action.crossId,
178
+ crossType: action.crossType,
179
+ transfers,
180
+ };
181
+ }
182
+ case 'cross-trade': {
183
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
184
+ isTransferNftIn(transfer) ||
185
+ isTransferFiatCurrencyIn(transfer) ||
186
+ isTransferCryptoCurrencyOut(transfer) ||
187
+ isTransferNftOut(transfer) ||
188
+ isTransferFiatCurrencyOut(transfer));
189
+ if (transfers.length !== action.transfers.length) {
190
+ throw new Error('Invalid action.transfers for cross-trade');
191
+ }
192
+ if (action.crossId === undefined) {
193
+ throw new Error('action.crossId is required for cross-trade');
194
+ }
195
+ if (action.crossType === undefined) {
196
+ throw new Error('action.crossType is required for cross-trade');
197
+ }
198
+ return {
199
+ ...action,
200
+ type: 'CrossNormalAction',
201
+ action: 'cross-trade',
202
+ crossId: action.crossId,
203
+ crossType: action.crossType,
204
+ transfers,
205
+ };
206
+ }
207
+ case 'deposit': {
208
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer));
209
+ if (transfers.length !== action.transfers.length) {
210
+ throw new Error('Invalid action.transfers for deposit');
211
+ }
212
+ if (action.loanId === undefined) {
213
+ throw new Error('action.loandId is required for deposit');
214
+ }
215
+ return {
216
+ ...action,
217
+ type: 'LoanNormalAction',
218
+ action: 'deposit',
219
+ loanId: action.loanId,
220
+ transfers,
221
+ };
222
+ }
223
+ case 'deposit-with-bond': {
224
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
225
+ isTransferNftIn(transfer) ||
226
+ isTransferCryptoCurrencyOut(transfer) ||
227
+ isTransferNftOut(transfer));
228
+ if (transfers.length !== action.transfers.length) {
229
+ throw new Error('Invalid action.transfers for deposit-with-bond');
230
+ }
231
+ if (action.loanId === undefined) {
232
+ throw new Error('action.loandId is required for deposit-with-bond');
233
+ }
234
+ return {
235
+ ...action,
236
+ type: 'LoanNormalAction',
237
+ action: 'deposit-with-bond',
238
+ loanId: action.loanId,
239
+ transfers,
240
+ };
241
+ }
242
+ case 'fail-tx': {
243
+ if (action.transfers.length > 0) {
244
+ throw new Error('Invalid action.transfers for fail-tx');
245
+ }
246
+ return {
247
+ ...action,
248
+ type: 'NormalAction',
249
+ action: 'fail-tx',
250
+ transfers: [],
251
+ };
252
+ }
253
+ case 'fee': {
254
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) ||
255
+ isTransferFiatCurrencyOut(transfer));
256
+ if (transfers.length !== action.transfers.length) {
257
+ throw new Error('Invalid action.transfers for fee');
258
+ }
259
+ return {
260
+ ...action,
261
+ type: 'NormalAction',
262
+ action: 'fee',
263
+ transfers,
264
+ };
265
+ }
266
+ case 'free-mint-nft': {
267
+ const transfers = action.transfers.filter((transfer) => isTransferNftIn(transfer));
268
+ if (transfers.length !== action.transfers.length) {
269
+ throw new Error('Invalid action.transfers for free-mint-nft');
270
+ }
271
+ return {
272
+ ...action,
273
+ type: 'NormalAction',
274
+ action: 'free-mint-nft',
275
+ transfers,
276
+ };
277
+ }
278
+ case 'income': {
279
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
280
+ isTransferNftIn(transfer) ||
281
+ isTransferFiatCurrencyIn(transfer));
282
+ if (transfers.length !== action.transfers.length) {
283
+ throw new Error('Invalid action.transfers for income');
284
+ }
285
+ return {
286
+ ...action,
287
+ type: 'NormalAction',
288
+ action: 'income',
289
+ transfers,
290
+ };
291
+ }
292
+ case 'mint-nft': {
293
+ const transfers = action.transfers.filter((transfer) => isTransferNftIn(transfer) ||
294
+ isTransferFiatCurrencyOut(transfer) ||
295
+ isTransferCryptoCurrencyOut(transfer));
296
+ if (transfers.length !== action.transfers.length) {
297
+ throw new Error('Invalid action.transfers for mint-nft');
298
+ }
299
+ return {
300
+ ...action,
301
+ type: 'NormalAction',
302
+ action: 'mint-nft',
303
+ transfers,
304
+ };
305
+ }
306
+ case 'receive-from-cex': {
307
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer));
308
+ if (transfers.length !== action.transfers.length) {
309
+ throw new Error('Invalid action.transfers for receive-from-cex');
310
+ }
311
+ return {
312
+ ...action,
313
+ type: 'NormalAction',
314
+ action: 'receive-from-cex',
315
+ transfers,
316
+ };
317
+ }
318
+ case 'remove-liquidity': {
319
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
320
+ isTransferNftIn(transfer) ||
321
+ isTransferCryptoCurrencyOut(transfer) ||
322
+ isTransferNftOut(transfer));
323
+ if (transfers.length !== action.transfers.length) {
324
+ throw new Error('Invalid action.transfers for remove-liquidity');
325
+ }
326
+ if (action.loanId === undefined) {
327
+ throw new Error('action.loandId is required for remove-liquidity');
328
+ }
329
+ return {
330
+ ...action,
331
+ type: 'LoanNormalAction',
332
+ action: 'remove-liquidity',
333
+ loanId: action.loanId,
334
+ transfers,
335
+ };
336
+ }
337
+ case 'repayment': {
338
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer));
339
+ if (transfers.length !== action.transfers.length) {
340
+ throw new Error('Invalid action.transfers for repayment');
341
+ }
342
+ if (action.loanId === undefined) {
343
+ throw new Error('action.loandId is required for repayment');
344
+ }
345
+ return {
346
+ ...action,
347
+ type: 'LoanNormalAction',
348
+ action: 'repayment',
349
+ loanId: action.loanId,
350
+ transfers,
351
+ };
352
+ }
353
+ case 'repayment-with-debt': {
354
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
355
+ isTransferNftIn(transfer) ||
356
+ isTransferCryptoCurrencyOut(transfer) ||
357
+ isTransferNftOut(transfer));
358
+ if (transfers.length !== action.transfers.length) {
359
+ throw new Error('Invalid action.transfers for repayment-with-debt');
360
+ }
361
+ if (action.loanId === undefined) {
362
+ throw new Error('action.loandId is required for repayment-with-debt');
363
+ }
364
+ return {
365
+ ...action,
366
+ type: 'LoanNormalAction',
367
+ action: 'repayment-with-debt',
368
+ loanId: action.loanId,
369
+ transfers,
370
+ };
371
+ }
372
+ case 'replace': {
373
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
374
+ isTransferNftIn(transfer) ||
375
+ isTransferCryptoCurrencyOut(transfer) ||
376
+ isTransferNftOut(transfer));
377
+ if (transfers.length !== action.transfers.length) {
378
+ throw new Error('Invalid action.transfers for replace');
379
+ }
380
+ return {
381
+ ...action,
382
+ type: 'NormalAction',
383
+ action: 'replace',
384
+ transfers,
385
+ };
386
+ }
387
+ case 'revoke': {
388
+ if (action.transfers.length > 0) {
389
+ throw new Error('Invalid action.transfers for revoke');
390
+ }
391
+ return {
392
+ ...action,
393
+ type: 'NormalAction',
394
+ action: 'revoke',
395
+ transfers: [],
396
+ };
397
+ }
398
+ case 'sell-crypto': {
399
+ const transfers = action.transfers.filter((transfer) => isTransferFiatCurrencyIn(transfer) ||
400
+ isTransferCryptoCurrencyOut(transfer));
401
+ if (transfers.length !== action.transfers.length) {
402
+ throw new Error('Invalid action.transfers for sell-crypto');
403
+ }
404
+ return {
405
+ ...action,
406
+ type: 'NormalAction',
407
+ action: 'sell-crypto',
408
+ transfers,
409
+ };
410
+ }
411
+ case 'sell-nft': {
412
+ const transfers = action.transfers.filter((transfer) => isTransferFiatCurrencyIn(transfer) ||
413
+ isTransferCryptoCurrencyIn(transfer) ||
414
+ isTransferNftOut(transfer));
415
+ if (transfers.length !== action.transfers.length) {
416
+ throw new Error('Invalid action.transfers for sell-nft');
417
+ }
418
+ return {
419
+ ...action,
420
+ type: 'NormalAction',
421
+ action: 'sell-nft',
422
+ transfers,
423
+ };
424
+ }
425
+ case 'send-to-cex': {
426
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer));
427
+ if (transfers.length !== action.transfers.length) {
428
+ throw new Error('Invalid action.transfers for send-to-cex');
429
+ }
430
+ return {
431
+ ...action,
432
+ type: 'NormalAction',
433
+ action: 'send-to-cex',
434
+ transfers,
435
+ };
436
+ }
437
+ case 'spam': {
438
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
439
+ isTransferNftIn(transfer) ||
440
+ isTransferCryptoCurrencyOut(transfer) ||
441
+ isTransferNftOut(transfer));
442
+ if (transfers.length !== action.transfers.length) {
443
+ throw new Error('Invalid action.transfers for spam');
444
+ }
445
+ return {
446
+ ...action,
447
+ type: 'NormalAction',
448
+ action: 'spam',
449
+ transfers,
450
+ };
451
+ }
452
+ case 'stake': {
453
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer));
454
+ if (transfers.length !== action.transfers.length) {
455
+ throw new Error('Invalid action.transfers for stake');
456
+ }
457
+ if (action.loanId === undefined) {
458
+ throw new Error('action.loandId is required for stake');
459
+ }
460
+ return {
461
+ ...action,
462
+ type: 'LoanNormalAction',
463
+ action: 'stake',
464
+ loanId: action.loanId,
465
+ transfers,
466
+ };
467
+ }
468
+ case 'swap-nft': {
469
+ const transfers = action.transfers.filter((transfer) => isTransferNftIn(transfer) || isTransferNftOut(transfer));
470
+ if (transfers.length !== action.transfers.length) {
471
+ throw new Error('Invalid action.transfers for swap-nft');
472
+ }
473
+ return {
474
+ ...action,
475
+ type: 'NormalAction',
476
+ action: 'swap-nft',
477
+ transfers,
478
+ };
479
+ }
480
+ case 'transaction-fee': {
481
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer));
482
+ if (transfers.length !== action.transfers.length) {
483
+ throw new Error('Invalid action.transfers for transaction-fee');
484
+ }
485
+ return {
486
+ ...action,
487
+ type: 'NormalAction',
488
+ action: 'transaction-fee',
489
+ transfers,
490
+ };
491
+ }
492
+ case 'trade': {
493
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
494
+ isTransferNftIn(transfer) ||
495
+ isTransferFiatCurrencyIn(transfer) ||
496
+ isTransferCryptoCurrencyOut(transfer) ||
497
+ isTransferNftOut(transfer) ||
498
+ isTransferFiatCurrencyOut(transfer));
499
+ if (transfers.length !== action.transfers.length) {
500
+ throw new Error('Invalid action.transfers for trade');
501
+ }
502
+ return {
503
+ ...action,
504
+ type: 'NormalAction',
505
+ action: 'trade',
506
+ transfers,
507
+ };
508
+ }
509
+ case 'transfer': {
510
+ return {
511
+ ...action,
512
+ type: 'NormalAction',
513
+ action: 'transfer',
514
+ transfers: [...action.transfers],
515
+ };
516
+ }
517
+ case 'unstake': {
518
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer));
519
+ if (transfers.length !== action.transfers.length) {
520
+ throw new Error('Invalid action.transfers for unstake');
521
+ }
522
+ if (action.loanId === undefined) {
523
+ throw new Error('action.loandId is required for unstake');
524
+ }
525
+ return {
526
+ ...action,
527
+ type: 'LoanNormalAction',
528
+ action: 'unstake',
529
+ loanId: action.loanId,
530
+ transfers,
531
+ };
532
+ }
533
+ case 'unwrap': {
534
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
535
+ isTransferCryptoCurrencyOut(transfer));
536
+ if (transfers.length !== action.transfers.length) {
537
+ throw new Error('Invalid action.transfers for unwrap');
538
+ }
539
+ return {
540
+ ...action,
541
+ type: 'NormalAction',
542
+ action: 'unwrap',
543
+ transfers,
544
+ };
545
+ }
546
+ case 'valuedown': {
547
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
548
+ isTransferNftIn(transfer) ||
549
+ isTransferFiatCurrencyIn(transfer));
550
+ if (transfers.length !== action.transfers.length) {
551
+ throw new Error('Invalid action.transfers for valuedown');
552
+ }
553
+ if (action.target === undefined) {
554
+ throw new Error('action.target is required for valuedown');
555
+ }
556
+ return {
557
+ ...action,
558
+ type: 'NormalAction',
559
+ action: 'valuedown',
560
+ target: action.target,
561
+ transfers,
562
+ };
563
+ }
564
+ case 'valueup': {
565
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) ||
566
+ isTransferNftOut(transfer) ||
567
+ isTransferFiatCurrencyOut(transfer));
568
+ if (transfers.length !== action.transfers.length) {
569
+ throw new Error('Invalid action.transfers for valueup');
570
+ }
571
+ if (action.target === undefined) {
572
+ throw new Error('action.target is required for valueup');
573
+ }
574
+ return {
575
+ ...action,
576
+ type: 'NormalAction',
577
+ action: 'valueup',
578
+ target: action.target,
579
+ transfers,
580
+ };
581
+ }
582
+ case 'withdraw': {
583
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer));
584
+ if (transfers.length !== action.transfers.length) {
585
+ throw new Error('Invalid action.transfers for withdraw');
586
+ }
587
+ if (action.loanId === undefined) {
588
+ throw new Error('action.loandId is required for withdraw');
589
+ }
590
+ return {
591
+ ...action,
592
+ type: 'LoanNormalAction',
593
+ action: 'withdraw',
594
+ loanId: action.loanId,
595
+ transfers,
596
+ };
597
+ }
598
+ case 'withdraw-with-bond': {
599
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
600
+ isTransferNftIn(transfer) ||
601
+ isTransferCryptoCurrencyOut(transfer) ||
602
+ isTransferNftOut(transfer));
603
+ if (transfers.length !== action.transfers.length) {
604
+ throw new Error('Invalid action.transfers for withdraw-with-bond');
605
+ }
606
+ if (action.loanId === undefined) {
607
+ throw new Error('action.loandId is required for withdraw-with-bond');
608
+ }
609
+ return {
610
+ ...action,
611
+ type: 'LoanNormalAction',
612
+ action: 'withdraw-with-bond',
613
+ loanId: action.loanId,
614
+ transfers,
615
+ };
616
+ }
617
+ case 'wrap': {
618
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
619
+ isTransferCryptoCurrencyOut(transfer));
620
+ if (transfers.length !== action.transfers.length) {
621
+ throw new Error('Invalid action.transfers for wrap');
622
+ }
623
+ return {
624
+ ...action,
625
+ type: 'NormalAction',
626
+ action: 'wrap',
627
+ transfers,
628
+ };
629
+ }
630
+ }
631
+ };
632
+ export const parseBaseAccountActionToAccountAction = (action) => {
633
+ switch (action.action) {
634
+ case 'add-liquidity': {
635
+ // transferCryptoCurrencyInSchema,
636
+ // transferNftInSchema,
637
+ // transferCryptoCurrencyOutSchema,
638
+ // transferNftOutSchema,
639
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
640
+ isTransferNftIn(transfer) ||
641
+ isTransferCryptoCurrencyOut(transfer) ||
642
+ isTransferNftOut(transfer));
643
+ if (transfers.length !== action.transfers.length) {
644
+ throw new Error('Invalid action.transfers for add-liquidity');
645
+ }
646
+ if (action.loanId === undefined) {
647
+ throw new Error('action.loandId is required for add-liquidity');
648
+ }
649
+ return {
650
+ ...action,
651
+ type: 'LoanAccountAction',
652
+ action: 'add-liquidity',
653
+ loanId: action.loanId,
654
+ transfers,
655
+ };
656
+ }
657
+ case 'approve': {
658
+ if (action.transfers.length > 0) {
659
+ throw new Error('Invalid action.transfers for approve');
660
+ }
661
+ return {
662
+ ...action,
663
+ type: 'NormalAccountAction',
664
+ action: 'approve',
665
+ transfers: [],
666
+ };
667
+ }
668
+ case 'atomic-arbitrage': {
669
+ // transferCryptoCurrencyInSchema,
670
+ // transferCryptoCurrencyOutSchema,
671
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
672
+ isTransferCryptoCurrencyOut(transfer));
673
+ if (transfers.length !== action.transfers.length) {
674
+ throw new Error('Invalid action.transfers for atomic-arbitrage');
675
+ }
676
+ return {
677
+ ...action,
678
+ type: 'NormalAccountAction',
679
+ action: 'atomic-arbitrage',
680
+ transfers,
681
+ };
682
+ }
683
+ case 'borrow': {
684
+ // transferCryptoCurrencyInSchema, transferNftInSchema
685
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer));
686
+ if (transfers.length !== action.transfers.length) {
687
+ throw new Error('Invalid action.transfers for borrow');
688
+ }
689
+ if (action.loanId === undefined) {
690
+ throw new Error('action.loandId is required for borrow');
691
+ }
692
+ return {
693
+ ...action,
694
+ type: 'LoanAccountAction',
695
+ action: 'borrow',
696
+ loanId: action.loanId,
697
+ transfers,
698
+ };
699
+ }
700
+ case 'borrow-with-debt': {
701
+ // transferCryptoCurrencyInSchema,
702
+ // transferNftInSchema,
703
+ // transferCryptoCurrencyOutSchema,
704
+ // transferNftOutSchema,
705
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
706
+ isTransferNftIn(transfer) ||
707
+ isTransferCryptoCurrencyOut(transfer) ||
708
+ isTransferNftOut(transfer));
709
+ if (transfers.length !== action.transfers.length) {
710
+ throw new Error('Invalid action.transfers for borrow-with-debt');
711
+ }
712
+ if (action.loanId === undefined) {
713
+ throw new Error('action.loandId is required for borrow-with-debt');
714
+ }
715
+ return {
716
+ ...action,
717
+ type: 'LoanAccountAction',
718
+ action: 'borrow-with-debt',
719
+ loanId: action.loanId,
720
+ transfers,
721
+ };
722
+ }
723
+ case 'bridge-from': {
724
+ // transferCryptoCurrencyOutSchema, transferNftOutSchema
725
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer));
726
+ if (transfers.length !== action.transfers.length) {
727
+ throw new Error('Invalid action.transfers for bridge-from');
728
+ }
729
+ if (action.crossId === undefined) {
730
+ throw new Error('action.crossId is required for bridge-from');
731
+ }
732
+ if (action.crossType === undefined) {
733
+ throw new Error('action.crossType is required for bridge-from');
734
+ }
735
+ return {
736
+ ...action,
737
+ type: 'CrossAccountAction',
738
+ action: 'bridge-from',
739
+ crossId: action.crossId,
740
+ crossType: action.crossType,
741
+ transfers,
742
+ };
743
+ }
744
+ case 'bridge-to': {
745
+ // transferCryptoCurrencyInSchema, transferNftInSchema
746
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer));
747
+ if (transfers.length !== action.transfers.length) {
748
+ throw new Error('Invalid action.transfers for bridge-to');
749
+ }
750
+ if (action.crossId === undefined) {
751
+ throw new Error('action.crossId is required for bridge-to');
752
+ }
753
+ if (action.crossType === undefined) {
754
+ throw new Error('action.crossType is required for bridge-to');
755
+ }
756
+ return {
757
+ ...action,
758
+ type: 'CrossAccountAction',
759
+ action: 'bridge-to',
760
+ crossId: action.crossId,
761
+ crossType: action.crossType,
762
+ transfers,
763
+ };
764
+ }
765
+ case 'buy-crypto': {
766
+ // transferCryptoCurrencyInSchema, transferFiatCurrencyOutSchema
767
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
768
+ isTransferFiatCurrencyOut(transfer));
769
+ if (transfers.length !== action.transfers.length) {
770
+ throw new Error('Invalid action.transfers for buy-crypto');
771
+ }
772
+ return {
773
+ ...action,
774
+ type: 'NormalAccountAction',
775
+ action: 'buy-crypto',
776
+ transfers,
777
+ };
778
+ }
779
+ case 'buy-nft': {
780
+ // transferNftInSchema,
781
+ // transferFiatCurrencyOutSchema,
782
+ // transferCryptoCurrencyOutSchema,
783
+ const transfers = action.transfers.filter((transfer) => isTransferNftIn(transfer) ||
784
+ isTransferFiatCurrencyOut(transfer) ||
785
+ isTransferCryptoCurrencyOut(transfer));
786
+ if (transfers.length !== action.transfers.length) {
787
+ throw new Error('Invalid action.transfers for buy-nft');
788
+ }
789
+ return {
790
+ ...action,
791
+ type: 'NormalAccountAction',
792
+ action: 'buy-nft',
793
+ transfers,
794
+ };
795
+ }
796
+ case 'cross-replace': {
797
+ // transferInSchema, transferOutSchema
798
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
799
+ isTransferNftIn(transfer) ||
800
+ isTransferFiatCurrencyIn(transfer) ||
801
+ isTransferCryptoCurrencyOut(transfer) ||
802
+ isTransferNftOut(transfer) ||
803
+ isTransferFiatCurrencyOut(transfer));
804
+ if (transfers.length !== action.transfers.length) {
805
+ throw new Error('Invalid action.transfers for cross-replace');
806
+ }
807
+ if (action.crossId === undefined) {
808
+ throw new Error('action.crossId is required for cross-replace');
809
+ }
810
+ if (action.crossType === undefined) {
811
+ throw new Error('action.crossType is required for cross-replace');
812
+ }
813
+ return {
814
+ ...action,
815
+ type: 'CrossAccountAction',
816
+ action: 'cross-replace',
817
+ crossId: action.crossId,
818
+ crossType: action.crossType,
819
+ transfers,
820
+ };
821
+ }
822
+ case 'cross-trade': {
823
+ // transferInSchema, transferOutSchema
824
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
825
+ isTransferNftIn(transfer) ||
826
+ isTransferFiatCurrencyIn(transfer) ||
827
+ isTransferCryptoCurrencyOut(transfer) ||
828
+ isTransferNftOut(transfer) ||
829
+ isTransferFiatCurrencyOut(transfer));
830
+ if (transfers.length !== action.transfers.length) {
831
+ throw new Error('Invalid action.transfers for cross-trade');
832
+ }
833
+ if (action.crossId === undefined) {
834
+ throw new Error('action.crossId is required for cross-trade');
835
+ }
836
+ if (action.crossType === undefined) {
837
+ throw new Error('action.crossType is required for cross-trade');
838
+ }
839
+ return {
840
+ ...action,
841
+ type: 'CrossAccountAction',
842
+ action: 'cross-trade',
843
+ crossId: action.crossId,
844
+ crossType: action.crossType,
845
+ transfers,
846
+ };
847
+ }
848
+ case 'deposit': {
849
+ // transferCryptoCurrencyOutSchema, transferNftOutSchema
850
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer));
851
+ if (transfers.length !== action.transfers.length) {
852
+ throw new Error('Invalid action.transfers for deposit');
853
+ }
854
+ if (action.loanId === undefined) {
855
+ throw new Error('action.loandId is required for deposit');
856
+ }
857
+ return {
858
+ ...action,
859
+ type: 'LoanAccountAction',
860
+ action: 'deposit',
861
+ loanId: action.loanId,
862
+ transfers,
863
+ };
864
+ }
865
+ case 'deposit-with-bond': {
866
+ // transferCryptoCurrencyInSchema,
867
+ // transferNftInSchema,
868
+ // transferCryptoCurrencyOutSchema,
869
+ // transferNftOutSchema,
870
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
871
+ isTransferNftIn(transfer) ||
872
+ isTransferCryptoCurrencyOut(transfer) ||
873
+ isTransferNftOut(transfer));
874
+ if (transfers.length !== action.transfers.length) {
875
+ throw new Error('Invalid action.transfers for deposit-with-bond');
876
+ }
877
+ if (action.loanId === undefined) {
878
+ throw new Error('action.loandId is required for deposit-with-bond');
879
+ }
880
+ return {
881
+ ...action,
882
+ type: 'LoanAccountAction',
883
+ action: 'deposit-with-bond',
884
+ loanId: action.loanId,
885
+ transfers,
886
+ };
887
+ }
888
+ case 'fail-tx': {
889
+ if (action.transfers.length > 0) {
890
+ throw new Error('Invalid action.transfers for fail-tx');
891
+ }
892
+ return {
893
+ ...action,
894
+ type: 'NormalAccountAction',
895
+ action: 'fail-tx',
896
+ transfers: [],
897
+ };
898
+ }
899
+ case 'fee': {
900
+ // transferCryptoCurrencyOutSchema, transferFiatCurrencyOutSchema
901
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) ||
902
+ isTransferFiatCurrencyOut(transfer));
903
+ if (transfers.length !== action.transfers.length) {
904
+ throw new Error('Invalid action.transfers for fee');
905
+ }
906
+ return {
907
+ ...action,
908
+ type: 'NormalAccountAction',
909
+ action: 'fee',
910
+ transfers,
911
+ };
912
+ }
913
+ case 'free-mint-nft': {
914
+ // transferNftInSchema
915
+ const transfers = action.transfers.filter((transfer) => isTransferNftIn(transfer));
916
+ if (transfers.length !== action.transfers.length) {
917
+ throw new Error('Invalid action.transfers for free-mint-nft');
918
+ }
919
+ return {
920
+ ...action,
921
+ type: 'NormalAccountAction',
922
+ action: 'free-mint-nft',
923
+ transfers,
924
+ };
925
+ }
926
+ case 'ignore': {
927
+ return {
928
+ ...action,
929
+ type: 'NormalAccountAction',
930
+ action: 'ignore',
931
+ transfers: [...action.transfers],
932
+ };
933
+ }
934
+ case 'income': {
935
+ // transferInSchema
936
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
937
+ isTransferNftIn(transfer) ||
938
+ isTransferFiatCurrencyIn(transfer));
939
+ if (transfers.length !== action.transfers.length) {
940
+ throw new Error('Invalid action.transfers for income');
941
+ }
942
+ return {
943
+ ...action,
944
+ type: 'NormalAccountAction',
945
+ action: 'income',
946
+ transfers,
947
+ };
948
+ }
949
+ case 'mint-nft': {
950
+ // transferNftInSchema,
951
+ // transferFiatCurrencyOutSchema,
952
+ // transferCryptoCurrencyOutSchema,
953
+ const transfers = action.transfers.filter((transfer) => isTransferNftIn(transfer) ||
954
+ isTransferFiatCurrencyOut(transfer) ||
955
+ isTransferCryptoCurrencyOut(transfer));
956
+ if (transfers.length !== action.transfers.length) {
957
+ throw new Error('Invalid action.transfers for mint-nft');
958
+ }
959
+ return {
960
+ ...action,
961
+ type: 'NormalAccountAction',
962
+ action: 'mint-nft',
963
+ transfers,
964
+ };
965
+ }
966
+ case 'move': {
967
+ return {
968
+ ...action,
969
+ type: 'NormalAccountAction',
970
+ action: 'move',
971
+ transfers: [...action.transfers],
972
+ };
973
+ }
974
+ case 'nft-royalty': {
975
+ // transferCryptoCurrencyInSchema, transferFiatCurrencyInSchema
976
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
977
+ isTransferFiatCurrencyIn(transfer));
978
+ if (transfers.length !== action.transfers.length) {
979
+ throw new Error('Invalid action.transfers for nft-royalty');
980
+ }
981
+ return {
982
+ ...action,
983
+ type: 'NormalAccountAction',
984
+ action: 'nft-royalty',
985
+ transfers,
986
+ };
987
+ }
988
+ case 'receive-from-cex': {
989
+ // transferCryptoCurrencyInSchema, transferNftInSchema
990
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer));
991
+ if (transfers.length !== action.transfers.length) {
992
+ throw new Error('Invalid action.transfers for receive-from-cex');
993
+ }
994
+ return {
995
+ ...action,
996
+ type: 'NormalAccountAction',
997
+ action: 'receive-from-cex',
998
+ transfers,
999
+ };
1000
+ }
1001
+ case 'reduce': {
1002
+ // transferCryptoCurrencyOutSchema, transferNftOutSchema
1003
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer));
1004
+ if (transfers.length !== action.transfers.length) {
1005
+ throw new Error('Invalid action.transfers for reduce');
1006
+ }
1007
+ return {
1008
+ ...action,
1009
+ type: 'NormalAccountAction',
1010
+ action: 'reduce',
1011
+ transfers,
1012
+ };
1013
+ }
1014
+ case 'remove-liquidity': {
1015
+ // transferCryptoCurrencyInSchema,
1016
+ // transferNftInSchema,
1017
+ // transferCryptoCurrencyOutSchema,
1018
+ // transferNftOutSchema,
1019
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
1020
+ isTransferNftIn(transfer) ||
1021
+ isTransferCryptoCurrencyOut(transfer) ||
1022
+ isTransferNftOut(transfer));
1023
+ if (transfers.length !== action.transfers.length) {
1024
+ throw new Error('Invalid action.transfers for remove-liquidity');
1025
+ }
1026
+ if (action.loanId === undefined) {
1027
+ throw new Error('action.loandId is required for remove-liquidity');
1028
+ }
1029
+ return {
1030
+ ...action,
1031
+ type: 'LoanAccountAction',
1032
+ action: 'remove-liquidity',
1033
+ loanId: action.loanId,
1034
+ transfers,
1035
+ };
1036
+ }
1037
+ case 'repayment': {
1038
+ // transferCryptoCurrencyOutSchema, transferNftOutSchema
1039
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer));
1040
+ if (transfers.length !== action.transfers.length) {
1041
+ throw new Error('Invalid action.transfers for repayment');
1042
+ }
1043
+ if (action.loanId === undefined) {
1044
+ throw new Error('action.loandId is required for repayment');
1045
+ }
1046
+ return {
1047
+ ...action,
1048
+ type: 'LoanAccountAction',
1049
+ action: 'repayment',
1050
+ loanId: action.loanId,
1051
+ transfers,
1052
+ };
1053
+ }
1054
+ case 'repayment-with-debt': {
1055
+ // transferCryptoCurrencyInSchema,
1056
+ // transferNftInSchema,
1057
+ // transferCryptoCurrencyOutSchema,
1058
+ // transferNftOutSchema,
1059
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
1060
+ isTransferNftIn(transfer) ||
1061
+ isTransferCryptoCurrencyOut(transfer) ||
1062
+ isTransferNftOut(transfer));
1063
+ if (transfers.length !== action.transfers.length) {
1064
+ throw new Error('Invalid action.transfers for repayment-with-debt');
1065
+ }
1066
+ if (action.loanId === undefined) {
1067
+ throw new Error('action.loandId is required for repayment-with-debt');
1068
+ }
1069
+ return {
1070
+ ...action,
1071
+ type: 'LoanAccountAction',
1072
+ action: 'repayment-with-debt',
1073
+ loanId: action.loanId,
1074
+ transfers,
1075
+ };
1076
+ }
1077
+ case 'replace': {
1078
+ // transferCryptoCurrencyInSchema,
1079
+ // transferNftInSchema,
1080
+ // transferCryptoCurrencyOutSchema,
1081
+ // transferNftOutSchema,
1082
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
1083
+ isTransferNftIn(transfer) ||
1084
+ isTransferCryptoCurrencyOut(transfer) ||
1085
+ isTransferNftOut(transfer));
1086
+ if (transfers.length !== action.transfers.length) {
1087
+ throw new Error('Invalid action.transfers for replace');
1088
+ }
1089
+ return {
1090
+ ...action,
1091
+ type: 'NormalAccountAction',
1092
+ action: 'replace',
1093
+ transfers,
1094
+ };
1095
+ }
1096
+ case 'revoke': {
1097
+ if (action.transfers.length > 0) {
1098
+ throw new Error('Invalid action.transfers for revoke');
1099
+ }
1100
+ return {
1101
+ ...action,
1102
+ type: 'NormalAccountAction',
1103
+ action: 'revoke',
1104
+ transfers: [],
1105
+ };
1106
+ }
1107
+ case 'sell-crypto': {
1108
+ // transferFiatCurrencyInSchema, transferCryptoCurrencyOutSchema
1109
+ const transfers = action.transfers.filter((transfer) => isTransferFiatCurrencyIn(transfer) ||
1110
+ isTransferCryptoCurrencyOut(transfer));
1111
+ if (transfers.length !== action.transfers.length) {
1112
+ throw new Error('Invalid action.transfers for sell-crypto');
1113
+ }
1114
+ return {
1115
+ ...action,
1116
+ type: 'NormalAccountAction',
1117
+ action: 'sell-crypto',
1118
+ transfers,
1119
+ };
1120
+ }
1121
+ case 'sell-nft': {
1122
+ // transferFiatCurrencyInSchema,
1123
+ // transferCryptoCurrencyInSchema,
1124
+ // transferNftOutSchema,
1125
+ const transfers = action.transfers.filter((transfer) => isTransferFiatCurrencyIn(transfer) ||
1126
+ isTransferCryptoCurrencyIn(transfer) ||
1127
+ isTransferNftOut(transfer));
1128
+ if (transfers.length !== action.transfers.length) {
1129
+ throw new Error('Invalid action.transfers for sell-nft');
1130
+ }
1131
+ return {
1132
+ ...action,
1133
+ type: 'NormalAccountAction',
1134
+ action: 'sell-nft',
1135
+ transfers,
1136
+ };
1137
+ }
1138
+ case 'send-to-cex': {
1139
+ // transferCryptoCurrencyOutSchema, transferNftOutSchema
1140
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer));
1141
+ if (transfers.length !== action.transfers.length) {
1142
+ throw new Error('Invalid action.transfers for send-to-cex');
1143
+ }
1144
+ return {
1145
+ ...action,
1146
+ type: 'NormalAccountAction',
1147
+ action: 'send-to-cex',
1148
+ transfers,
1149
+ };
1150
+ }
1151
+ case 'spam': {
1152
+ // transferCryptoCurrencyInSchema,
1153
+ // transferNftInSchema,
1154
+ // transferCryptoCurrencyOutSchema,
1155
+ // transferNftOutSchema,
1156
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
1157
+ isTransferNftIn(transfer) ||
1158
+ isTransferCryptoCurrencyOut(transfer) ||
1159
+ isTransferNftOut(transfer));
1160
+ if (transfers.length !== action.transfers.length) {
1161
+ throw new Error('Invalid action.transfers for spam');
1162
+ }
1163
+ return {
1164
+ ...action,
1165
+ type: 'NormalAccountAction',
1166
+ action: 'spam',
1167
+ transfers,
1168
+ };
1169
+ }
1170
+ case 'stake': {
1171
+ // transferCryptoCurrencyOutSchema, transferNftOutSchema
1172
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer));
1173
+ if (transfers.length !== action.transfers.length) {
1174
+ throw new Error('Invalid action.transfers for stake');
1175
+ }
1176
+ if (action.loanId === undefined) {
1177
+ throw new Error('action.loandId is required for stake');
1178
+ }
1179
+ return {
1180
+ ...action,
1181
+ type: 'LoanAccountAction',
1182
+ action: 'stake',
1183
+ loanId: action.loanId,
1184
+ transfers,
1185
+ };
1186
+ }
1187
+ case 'swap-income': {
1188
+ // transferCryptoCurrencyInSchema, transferNftInSchema
1189
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer));
1190
+ if (transfers.length !== action.transfers.length) {
1191
+ throw new Error('Invalid action.transfers for swap-income');
1192
+ }
1193
+ return {
1194
+ ...action,
1195
+ type: 'NormalAccountAction',
1196
+ action: 'swap-income',
1197
+ transfers,
1198
+ };
1199
+ }
1200
+ case 'swap-nft': {
1201
+ // transferNftInSchema, transferNftOutSchema
1202
+ const transfers = action.transfers.filter((transfer) => isTransferNftIn(transfer) || isTransferNftOut(transfer));
1203
+ if (transfers.length !== action.transfers.length) {
1204
+ throw new Error('Invalid action.transfers for swap-nft');
1205
+ }
1206
+ return {
1207
+ ...action,
1208
+ type: 'NormalAccountAction',
1209
+ action: 'swap-nft',
1210
+ transfers,
1211
+ };
1212
+ }
1213
+ case 'swap-transfer': {
1214
+ // transferCryptoCurrencyOutSchema, transferNftOutSchema
1215
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer));
1216
+ if (transfers.length !== action.transfers.length) {
1217
+ throw new Error('Invalid action.transfers for swap-transfer');
1218
+ }
1219
+ return {
1220
+ ...action,
1221
+ type: 'NormalAccountAction',
1222
+ action: 'swap-transfer',
1223
+ transfers,
1224
+ };
1225
+ }
1226
+ case 'trade': {
1227
+ // transferInSchema, transferOutSchema
1228
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
1229
+ isTransferNftIn(transfer) ||
1230
+ isTransferFiatCurrencyIn(transfer) ||
1231
+ isTransferCryptoCurrencyOut(transfer) ||
1232
+ isTransferNftOut(transfer) ||
1233
+ isTransferFiatCurrencyOut(transfer));
1234
+ if (transfers.length !== action.transfers.length) {
1235
+ throw new Error('Invalid action.transfers for trade');
1236
+ }
1237
+ return {
1238
+ ...action,
1239
+ type: 'NormalAccountAction',
1240
+ action: 'trade',
1241
+ transfers,
1242
+ };
1243
+ }
1244
+ case 'transaction-fee': {
1245
+ // transferCryptoCurrencyOutSchema
1246
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer));
1247
+ if (transfers.length !== action.transfers.length) {
1248
+ throw new Error('Invalid action.transfers for transaction-fee');
1249
+ }
1250
+ return {
1251
+ ...action,
1252
+ type: 'NormalAccountAction',
1253
+ action: 'transaction-fee',
1254
+ transfers,
1255
+ };
1256
+ }
1257
+ case 'transfer': {
1258
+ // transferOutSchema
1259
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) ||
1260
+ isTransferNftOut(transfer) ||
1261
+ isTransferFiatCurrencyOut(transfer));
1262
+ if (transfers.length !== action.transfers.length) {
1263
+ throw new Error('Invalid action.transfers for transfer');
1264
+ }
1265
+ return {
1266
+ ...action,
1267
+ type: 'NormalAccountAction',
1268
+ action: 'transfer',
1269
+ transfers,
1270
+ };
1271
+ }
1272
+ case 'unstake': {
1273
+ // transferCryptoCurrencyInSchema, transferNftInSchema
1274
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer));
1275
+ if (transfers.length !== action.transfers.length) {
1276
+ throw new Error('Invalid action.transfers for unstake');
1277
+ }
1278
+ if (action.loanId === undefined) {
1279
+ throw new Error('action.loandId is required for unstake');
1280
+ }
1281
+ return {
1282
+ ...action,
1283
+ type: 'LoanAccountAction',
1284
+ action: 'unstake',
1285
+ loanId: action.loanId,
1286
+ transfers,
1287
+ };
1288
+ }
1289
+ case 'unwrap': {
1290
+ // transferCryptoCurrencyInSchema,
1291
+ // transferCryptoCurrencyOutSchema,
1292
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
1293
+ isTransferCryptoCurrencyOut(transfer));
1294
+ if (transfers.length !== action.transfers.length) {
1295
+ throw new Error('Invalid action.transfers for unwrap');
1296
+ }
1297
+ return {
1298
+ ...action,
1299
+ type: 'NormalAccountAction',
1300
+ action: 'unwrap',
1301
+ transfers,
1302
+ };
1303
+ }
1304
+ case 'valuedown': {
1305
+ // transferInSchema
1306
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
1307
+ isTransferNftIn(transfer) ||
1308
+ isTransferFiatCurrencyIn(transfer));
1309
+ if (transfers.length !== action.transfers.length) {
1310
+ throw new Error('Invalid action.transfers for valuedown');
1311
+ }
1312
+ if (action.target === undefined) {
1313
+ throw new Error('action.target is required for valuedown');
1314
+ }
1315
+ return {
1316
+ ...action,
1317
+ type: 'NormalAccountAction',
1318
+ action: 'valuedown',
1319
+ target: action.target,
1320
+ transfers,
1321
+ };
1322
+ }
1323
+ case 'valueup': {
1324
+ // transferOutSchema
1325
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyOut(transfer) ||
1326
+ isTransferNftOut(transfer) ||
1327
+ isTransferFiatCurrencyOut(transfer));
1328
+ if (transfers.length !== action.transfers.length) {
1329
+ throw new Error('Invalid action.transfers for valueup');
1330
+ }
1331
+ if (action.target === undefined) {
1332
+ throw new Error('action.target is required for valueup');
1333
+ }
1334
+ return {
1335
+ ...action,
1336
+ type: 'NormalAccountAction',
1337
+ action: 'valueup',
1338
+ target: action.target,
1339
+ transfers,
1340
+ };
1341
+ }
1342
+ case 'withdraw': {
1343
+ // transferCryptoCurrencyInSchema, transferNftInSchema
1344
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer));
1345
+ if (transfers.length !== action.transfers.length) {
1346
+ throw new Error('Invalid action.transfers for withdraw');
1347
+ }
1348
+ if (action.loanId === undefined) {
1349
+ throw new Error('action.loandId is required for withdraw');
1350
+ }
1351
+ return {
1352
+ ...action,
1353
+ type: 'LoanAccountAction',
1354
+ action: 'withdraw',
1355
+ loanId: action.loanId,
1356
+ transfers,
1357
+ };
1358
+ }
1359
+ case 'withdraw-with-bond': {
1360
+ // transferCryptoCurrencyInSchema,
1361
+ // transferNftInSchema,
1362
+ // transferCryptoCurrencyOutSchema,
1363
+ // transferNftOutSchema,
1364
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
1365
+ isTransferNftIn(transfer) ||
1366
+ isTransferCryptoCurrencyOut(transfer) ||
1367
+ isTransferNftOut(transfer));
1368
+ if (transfers.length !== action.transfers.length) {
1369
+ throw new Error('Invalid action.transfers for withdraw-with-bond');
1370
+ }
1371
+ if (action.loanId === undefined) {
1372
+ throw new Error('action.loandId is required for withdraw-with-bond');
1373
+ }
1374
+ return {
1375
+ ...action,
1376
+ type: 'LoanAccountAction',
1377
+ action: 'withdraw-with-bond',
1378
+ loanId: action.loanId,
1379
+ transfers,
1380
+ };
1381
+ }
1382
+ case 'wrap': {
1383
+ // transferCryptoCurrencyInSchema,
1384
+ // transferCryptoCurrencyOutSchema,
1385
+ const transfers = action.transfers.filter((transfer) => isTransferCryptoCurrencyIn(transfer) ||
1386
+ isTransferCryptoCurrencyOut(transfer));
1387
+ if (transfers.length !== action.transfers.length) {
1388
+ throw new Error('Invalid action.transfers for wrap');
1389
+ }
1390
+ return {
1391
+ ...action,
1392
+ type: 'NormalAccountAction',
1393
+ action: 'wrap',
1394
+ transfers,
1395
+ };
1396
+ }
1397
+ }
1398
+ };
10
1399
  //# sourceMappingURL=utils.js.map