@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.
- package/_cjs/actions/index.js +3 -1
- package/_cjs/actions/index.js.map +1 -1
- package/_cjs/actions/schemas/crossActionBundle.js +8 -2
- package/_cjs/actions/schemas/crossActionBundle.js.map +1 -1
- package/_cjs/actions/utils.js +1318 -1
- package/_cjs/actions/utils.js.map +1 -1
- package/_cjs/index.js +3 -1
- package/_cjs/index.js.map +1 -1
- package/_esm/actions/index.js +1 -1
- package/_esm/actions/index.js.map +1 -1
- package/_esm/actions/schemas/crossActionBundle.js +8 -2
- package/_esm/actions/schemas/crossActionBundle.js.map +1 -1
- package/_esm/actions/utils.js +1389 -0
- package/_esm/actions/utils.js.map +1 -1
- package/_esm/index.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_types/actions/index.d.ts +2 -2
- package/_types/actions/index.d.ts.map +1 -1
- package/_types/actions/parsers/default.d.ts +1 -1
- package/_types/actions/schemas/action.d.ts +950 -950
- package/_types/actions/schemas/borrow/borrow.d.ts +16 -16
- package/_types/actions/schemas/borrow/borrowWithDebt.d.ts +16 -16
- package/_types/actions/schemas/crossActionBundle.d.ts +1578 -45107
- package/_types/actions/schemas/crossActionBundle.d.ts.map +1 -1
- package/_types/actions/schemas/crossReplace/bridgeFrom.d.ts +16 -16
- package/_types/actions/schemas/crossReplace/bridgeTo.d.ts +16 -16
- package/_types/actions/schemas/crossReplace/crossReplace.d.ts +16 -16
- package/_types/actions/schemas/crossTrade/crossTrade.d.ts +16 -16
- package/_types/actions/schemas/default/accountAction.d.ts +18 -18
- package/_types/actions/schemas/default/normalAction.d.ts +18 -18
- package/_types/actions/schemas/deposit/addLiquidity.d.ts +16 -16
- package/_types/actions/schemas/deposit/deposit.d.ts +16 -16
- package/_types/actions/schemas/deposit/depositWithBond.d.ts +16 -16
- package/_types/actions/schemas/deposit/stake.d.ts +16 -16
- package/_types/actions/schemas/fee/fee.d.ts +16 -16
- package/_types/actions/schemas/fee/transactionFee.d.ts +16 -16
- package/_types/actions/schemas/ignore/approve.d.ts +16 -16
- package/_types/actions/schemas/ignore/failTx.d.ts +16 -16
- package/_types/actions/schemas/ignore/ignore.d.ts +8 -8
- package/_types/actions/schemas/ignore/move.d.ts +8 -8
- package/_types/actions/schemas/ignore/receiveFromCex.d.ts +16 -16
- package/_types/actions/schemas/ignore/revoke.d.ts +16 -16
- package/_types/actions/schemas/ignore/sendToCex.d.ts +16 -16
- package/_types/actions/schemas/ignore/spam.d.ts +16 -16
- package/_types/actions/schemas/income/atomicArbitrage.d.ts +16 -16
- package/_types/actions/schemas/income/freeMintNft.d.ts +16 -16
- package/_types/actions/schemas/income/income.d.ts +16 -16
- package/_types/actions/schemas/income/nftRoyalty.d.ts +8 -8
- package/_types/actions/schemas/income/swapIncome.d.ts +8 -8
- package/_types/actions/schemas/reduce/reduce.d.ts +8 -8
- package/_types/actions/schemas/repayment/repayment.d.ts +16 -16
- package/_types/actions/schemas/repayment/repaymentWithDebt.d.ts +16 -16
- package/_types/actions/schemas/replace/replace.d.ts +16 -16
- package/_types/actions/schemas/replace/swapNft.d.ts +16 -16
- package/_types/actions/schemas/replace/unwrap.d.ts +16 -16
- package/_types/actions/schemas/replace/wrap.d.ts +16 -16
- package/_types/actions/schemas/trade/buyCrypto.d.ts +16 -16
- package/_types/actions/schemas/trade/buyNft.d.ts +16 -16
- package/_types/actions/schemas/trade/mintNft.d.ts +16 -16
- package/_types/actions/schemas/trade/sellCrypto.d.ts +16 -16
- package/_types/actions/schemas/trade/sellNft.d.ts +16 -16
- package/_types/actions/schemas/trade/trade.d.ts +16 -16
- package/_types/actions/schemas/transfer/swapTransfer.d.ts +8 -8
- package/_types/actions/schemas/transfer/transfer.d.ts +16 -16
- package/_types/actions/schemas/valuedown/valuedown.d.ts +16 -16
- package/_types/actions/schemas/valueup/valueup.d.ts +16 -16
- package/_types/actions/schemas/withdraw/removeLiquidity.d.ts +16 -16
- package/_types/actions/schemas/withdraw/unstake.d.ts +16 -16
- package/_types/actions/schemas/withdraw/withdraw.d.ts +16 -16
- package/_types/actions/schemas/withdraw/withdrawWithBond.d.ts +16 -16
- package/_types/actions/types/action.d.ts +17 -1
- package/_types/actions/types/action.d.ts.map +1 -1
- package/_types/actions/types/index.d.ts +1 -1
- package/_types/actions/types/index.d.ts.map +1 -1
- package/_types/actions/utils.d.ts +3 -0
- package/_types/actions/utils.d.ts.map +1 -1
- package/_types/apps/schemas.d.ts +4 -4
- package/_types/index.d.ts +2 -2
- package/_types/index.d.ts.map +1 -1
- package/actions/index.ts +4 -0
- package/actions/schemas/crossActionBundle.ts +14 -2
- package/actions/types/action.ts +26 -1
- package/actions/types/index.ts +2 -0
- package/actions/utils.ts +1951 -0
- package/index.ts +4 -0
- package/package.json +1 -1
package/actions/utils.ts
CHANGED
|
@@ -1,4 +1,90 @@
|
|
|
1
1
|
import type {
|
|
2
|
+
AccountActionAddLiquidity,
|
|
3
|
+
AccountActionApprove,
|
|
4
|
+
AccountActionAtomicArbitrage,
|
|
5
|
+
AccountActionBorrow,
|
|
6
|
+
AccountActionBorrowWithDebt,
|
|
7
|
+
AccountActionBridgeFrom,
|
|
8
|
+
AccountActionBridgeTo,
|
|
9
|
+
AccountActionBuyCrypto,
|
|
10
|
+
AccountActionBuyNft,
|
|
11
|
+
AccountActionCrossReplace,
|
|
12
|
+
AccountActionCrossTrade,
|
|
13
|
+
AccountActionDeposit,
|
|
14
|
+
AccountActionDepositWithBond,
|
|
15
|
+
AccountActionFailTx,
|
|
16
|
+
AccountActionFee,
|
|
17
|
+
AccountActionFreeMintNft,
|
|
18
|
+
AccountActionIgnore,
|
|
19
|
+
AccountActionIncome,
|
|
20
|
+
AccountActionMintNft,
|
|
21
|
+
AccountActionMove,
|
|
22
|
+
AccountActionNftRoyalty,
|
|
23
|
+
AccountActionReceiveFromCex,
|
|
24
|
+
AccountActionReduce,
|
|
25
|
+
AccountActionRemoveLiquidity,
|
|
26
|
+
AccountActionRepayment,
|
|
27
|
+
AccountActionRepaymentWithDebt,
|
|
28
|
+
AccountActionReplace,
|
|
29
|
+
AccountActionRevoke,
|
|
30
|
+
AccountActionSellCrypto,
|
|
31
|
+
AccountActionSellNft,
|
|
32
|
+
AccountActionSendToCex,
|
|
33
|
+
AccountActionSpam,
|
|
34
|
+
AccountActionStake,
|
|
35
|
+
AccountActionSwapIncome,
|
|
36
|
+
AccountActionSwapNft,
|
|
37
|
+
AccountActionSwapTransfer,
|
|
38
|
+
AccountActionTrade,
|
|
39
|
+
AccountActionTransactionFee,
|
|
40
|
+
AccountActionTransfer,
|
|
41
|
+
AccountActionUnstake,
|
|
42
|
+
AccountActionUnwrap,
|
|
43
|
+
AccountActionValuedown,
|
|
44
|
+
AccountActionValueup,
|
|
45
|
+
AccountActionWithdraw,
|
|
46
|
+
AccountActionWithdrawWithBond,
|
|
47
|
+
AccountActionWrap,
|
|
48
|
+
NormalActionAddLiquidity,
|
|
49
|
+
NormalActionApprove,
|
|
50
|
+
NormalActionAtomicArbitrage,
|
|
51
|
+
NormalActionBorrow,
|
|
52
|
+
NormalActionBorrowWithDebt,
|
|
53
|
+
NormalActionBridgeFrom,
|
|
54
|
+
NormalActionBridgeTo,
|
|
55
|
+
NormalActionBuyCrypto,
|
|
56
|
+
NormalActionBuyNft,
|
|
57
|
+
NormalActionCrossReplace,
|
|
58
|
+
NormalActionCrossTrade,
|
|
59
|
+
NormalActionDeposit,
|
|
60
|
+
NormalActionDepositWithBond,
|
|
61
|
+
NormalActionFailTx,
|
|
62
|
+
NormalActionFee,
|
|
63
|
+
NormalActionFreeMintNft,
|
|
64
|
+
NormalActionIncome,
|
|
65
|
+
NormalActionMintNft,
|
|
66
|
+
NormalActionReceiveFromCex,
|
|
67
|
+
NormalActionRemoveLiquidity,
|
|
68
|
+
NormalActionRepayment,
|
|
69
|
+
NormalActionRepaymentWithDebt,
|
|
70
|
+
NormalActionReplace,
|
|
71
|
+
NormalActionRevoke,
|
|
72
|
+
NormalActionSellCrypto,
|
|
73
|
+
NormalActionSellNft,
|
|
74
|
+
NormalActionSendToCex,
|
|
75
|
+
NormalActionSpam,
|
|
76
|
+
NormalActionStake,
|
|
77
|
+
NormalActionSwapNft,
|
|
78
|
+
NormalActionTrade,
|
|
79
|
+
NormalActionTransactionFee,
|
|
80
|
+
NormalActionTransfer,
|
|
81
|
+
NormalActionUnstake,
|
|
82
|
+
NormalActionUnwrap,
|
|
83
|
+
NormalActionValuedown,
|
|
84
|
+
NormalActionValueup,
|
|
85
|
+
NormalActionWithdraw,
|
|
86
|
+
NormalActionWithdrawWithBond,
|
|
87
|
+
NormalActionWrap,
|
|
2
88
|
Transfer,
|
|
3
89
|
TransferCryptoCurrencyIn,
|
|
4
90
|
TransferCryptoCurrencyNone,
|
|
@@ -10,6 +96,12 @@ import type {
|
|
|
10
96
|
TransferNftNone,
|
|
11
97
|
TransferNftOut,
|
|
12
98
|
} from './types'
|
|
99
|
+
import type {
|
|
100
|
+
AccountAction,
|
|
101
|
+
BaseAccountAction,
|
|
102
|
+
BaseNormalAction,
|
|
103
|
+
NormalAction,
|
|
104
|
+
} from './types/action'
|
|
13
105
|
|
|
14
106
|
export const isTransferCryptoCurrencyIn = (
|
|
15
107
|
transfer: Transfer,
|
|
@@ -55,3 +147,1862 @@ export const isTransferFiatCurrencyNone = (
|
|
|
55
147
|
transfer: Transfer,
|
|
56
148
|
): transfer is TransferFiatCurrencyNone =>
|
|
57
149
|
transfer.direction === 'none' && transfer.asset.type === 'FiatCurrency'
|
|
150
|
+
|
|
151
|
+
export const parseBaseNormalActionToNormalAction = (
|
|
152
|
+
action: BaseNormalAction,
|
|
153
|
+
): NormalAction => {
|
|
154
|
+
switch (action.action) {
|
|
155
|
+
case 'add-liquidity': {
|
|
156
|
+
const transfers = action.transfers.filter(
|
|
157
|
+
(
|
|
158
|
+
transfer,
|
|
159
|
+
): transfer is
|
|
160
|
+
| TransferCryptoCurrencyIn
|
|
161
|
+
| TransferNftIn
|
|
162
|
+
| TransferCryptoCurrencyOut
|
|
163
|
+
| TransferNftOut =>
|
|
164
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
165
|
+
isTransferNftIn(transfer) ||
|
|
166
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
167
|
+
isTransferNftOut(transfer),
|
|
168
|
+
)
|
|
169
|
+
if (transfers.length !== action.transfers.length) {
|
|
170
|
+
throw new Error('Invalid action.transfers for add-liquidity')
|
|
171
|
+
}
|
|
172
|
+
if (action.loanId === undefined) {
|
|
173
|
+
throw new Error('action.loandId is required for add-liquidity')
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
...action,
|
|
177
|
+
type: 'LoanNormalAction',
|
|
178
|
+
action: 'add-liquidity',
|
|
179
|
+
loanId: action.loanId,
|
|
180
|
+
transfers,
|
|
181
|
+
} satisfies NormalActionAddLiquidity
|
|
182
|
+
}
|
|
183
|
+
case 'approve': {
|
|
184
|
+
if (action.transfers.length > 0) {
|
|
185
|
+
throw new Error('Invalid action.transfers for approve')
|
|
186
|
+
}
|
|
187
|
+
return {
|
|
188
|
+
...action,
|
|
189
|
+
type: 'NormalAction',
|
|
190
|
+
action: 'approve',
|
|
191
|
+
transfers: [],
|
|
192
|
+
} satisfies NormalActionApprove
|
|
193
|
+
}
|
|
194
|
+
case 'atomic-arbitrage': {
|
|
195
|
+
const transfers = action.transfers.filter(
|
|
196
|
+
(
|
|
197
|
+
transfer,
|
|
198
|
+
): transfer is TransferCryptoCurrencyIn | TransferCryptoCurrencyOut =>
|
|
199
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
200
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
201
|
+
)
|
|
202
|
+
if (transfers.length !== action.transfers.length) {
|
|
203
|
+
throw new Error('Invalid action.transfers for atomic-arbitrage')
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
...action,
|
|
207
|
+
type: 'NormalAction',
|
|
208
|
+
action: 'atomic-arbitrage',
|
|
209
|
+
transfers,
|
|
210
|
+
} satisfies NormalActionAtomicArbitrage
|
|
211
|
+
}
|
|
212
|
+
case 'borrow': {
|
|
213
|
+
const transfers = action.transfers.filter(
|
|
214
|
+
(transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
|
|
215
|
+
isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
|
|
216
|
+
)
|
|
217
|
+
if (transfers.length !== action.transfers.length) {
|
|
218
|
+
throw new Error('Invalid action.transfers for borrow')
|
|
219
|
+
}
|
|
220
|
+
if (action.loanId === undefined) {
|
|
221
|
+
throw new Error('action.loandId is required for borrow')
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
...action,
|
|
225
|
+
type: 'LoanNormalAction',
|
|
226
|
+
action: 'borrow',
|
|
227
|
+
loanId: action.loanId,
|
|
228
|
+
transfers,
|
|
229
|
+
} satisfies NormalActionBorrow
|
|
230
|
+
}
|
|
231
|
+
case 'borrow-with-debt': {
|
|
232
|
+
const transfers = action.transfers.filter(
|
|
233
|
+
(
|
|
234
|
+
transfer,
|
|
235
|
+
): transfer is
|
|
236
|
+
| TransferCryptoCurrencyIn
|
|
237
|
+
| TransferNftIn
|
|
238
|
+
| TransferCryptoCurrencyOut
|
|
239
|
+
| TransferNftOut =>
|
|
240
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
241
|
+
isTransferNftIn(transfer) ||
|
|
242
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
243
|
+
isTransferNftOut(transfer),
|
|
244
|
+
)
|
|
245
|
+
if (transfers.length !== action.transfers.length) {
|
|
246
|
+
throw new Error('Invalid action.transfers for borrow-with-debt')
|
|
247
|
+
}
|
|
248
|
+
if (action.loanId === undefined) {
|
|
249
|
+
throw new Error('action.loandId is required for borrow-with-debt')
|
|
250
|
+
}
|
|
251
|
+
return {
|
|
252
|
+
...action,
|
|
253
|
+
type: 'LoanNormalAction',
|
|
254
|
+
action: 'borrow-with-debt',
|
|
255
|
+
loanId: action.loanId,
|
|
256
|
+
transfers,
|
|
257
|
+
} satisfies NormalActionBorrowWithDebt
|
|
258
|
+
}
|
|
259
|
+
case 'bridge-from': {
|
|
260
|
+
const transfers = action.transfers.filter(
|
|
261
|
+
(transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
|
|
262
|
+
isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
|
|
263
|
+
)
|
|
264
|
+
if (transfers.length !== action.transfers.length) {
|
|
265
|
+
throw new Error('Invalid action.transfers for bridge-from')
|
|
266
|
+
}
|
|
267
|
+
if (action.crossId === undefined) {
|
|
268
|
+
throw new Error('action.crossId is required for bridge-from')
|
|
269
|
+
}
|
|
270
|
+
if (action.crossType === undefined) {
|
|
271
|
+
throw new Error('action.crossType is required for bridge-from')
|
|
272
|
+
}
|
|
273
|
+
return {
|
|
274
|
+
...action,
|
|
275
|
+
type: 'CrossNormalAction',
|
|
276
|
+
action: 'bridge-from',
|
|
277
|
+
crossId: action.crossId,
|
|
278
|
+
crossType: action.crossType,
|
|
279
|
+
transfers,
|
|
280
|
+
} satisfies NormalActionBridgeFrom
|
|
281
|
+
}
|
|
282
|
+
case 'bridge-to': {
|
|
283
|
+
const transfers = action.transfers.filter(
|
|
284
|
+
(transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
|
|
285
|
+
isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
|
|
286
|
+
)
|
|
287
|
+
if (transfers.length !== action.transfers.length) {
|
|
288
|
+
throw new Error('Invalid action.transfers for bridge-to')
|
|
289
|
+
}
|
|
290
|
+
if (action.crossId === undefined) {
|
|
291
|
+
throw new Error('action.crossId is required for bridge-to')
|
|
292
|
+
}
|
|
293
|
+
if (action.crossType === undefined) {
|
|
294
|
+
throw new Error('action.crossType is required for bridge-to')
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
...action,
|
|
298
|
+
type: 'CrossNormalAction',
|
|
299
|
+
action: 'bridge-to',
|
|
300
|
+
crossId: action.crossId,
|
|
301
|
+
crossType: action.crossType,
|
|
302
|
+
transfers,
|
|
303
|
+
} satisfies NormalActionBridgeTo
|
|
304
|
+
}
|
|
305
|
+
case 'buy-crypto': {
|
|
306
|
+
const transfers = action.transfers.filter(
|
|
307
|
+
(
|
|
308
|
+
transfer,
|
|
309
|
+
): transfer is TransferCryptoCurrencyIn | TransferFiatCurrencyOut =>
|
|
310
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
311
|
+
isTransferFiatCurrencyOut(transfer),
|
|
312
|
+
)
|
|
313
|
+
if (transfers.length !== action.transfers.length) {
|
|
314
|
+
throw new Error('Invalid action.transfers for buy-crypto')
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
...action,
|
|
318
|
+
type: 'NormalAction',
|
|
319
|
+
action: 'buy-crypto',
|
|
320
|
+
transfers,
|
|
321
|
+
} satisfies NormalActionBuyCrypto
|
|
322
|
+
}
|
|
323
|
+
case 'buy-nft': {
|
|
324
|
+
const transfers = action.transfers.filter(
|
|
325
|
+
(
|
|
326
|
+
transfer,
|
|
327
|
+
): transfer is
|
|
328
|
+
| TransferNftIn
|
|
329
|
+
| TransferFiatCurrencyOut
|
|
330
|
+
| TransferCryptoCurrencyOut =>
|
|
331
|
+
isTransferNftIn(transfer) ||
|
|
332
|
+
isTransferFiatCurrencyOut(transfer) ||
|
|
333
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
334
|
+
)
|
|
335
|
+
if (transfers.length !== action.transfers.length) {
|
|
336
|
+
throw new Error('Invalid action.transfers for buy-nft')
|
|
337
|
+
}
|
|
338
|
+
return {
|
|
339
|
+
...action,
|
|
340
|
+
type: 'NormalAction',
|
|
341
|
+
action: 'buy-nft',
|
|
342
|
+
transfers,
|
|
343
|
+
} satisfies NormalActionBuyNft
|
|
344
|
+
}
|
|
345
|
+
case 'cross-replace': {
|
|
346
|
+
const transfers = action.transfers.filter(
|
|
347
|
+
(
|
|
348
|
+
transfer,
|
|
349
|
+
): transfer is
|
|
350
|
+
| TransferCryptoCurrencyIn
|
|
351
|
+
| TransferNftIn
|
|
352
|
+
| TransferFiatCurrencyIn
|
|
353
|
+
| TransferCryptoCurrencyOut
|
|
354
|
+
| TransferNftOut
|
|
355
|
+
| TransferFiatCurrencyOut =>
|
|
356
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
357
|
+
isTransferNftIn(transfer) ||
|
|
358
|
+
isTransferFiatCurrencyIn(transfer) ||
|
|
359
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
360
|
+
isTransferNftOut(transfer) ||
|
|
361
|
+
isTransferFiatCurrencyOut(transfer),
|
|
362
|
+
)
|
|
363
|
+
if (transfers.length !== action.transfers.length) {
|
|
364
|
+
throw new Error('Invalid action.transfers for cross-replace')
|
|
365
|
+
}
|
|
366
|
+
if (action.crossId === undefined) {
|
|
367
|
+
throw new Error('action.crossId is required for cross-replace')
|
|
368
|
+
}
|
|
369
|
+
if (action.crossType === undefined) {
|
|
370
|
+
throw new Error('action.crossType is required for cross-replace')
|
|
371
|
+
}
|
|
372
|
+
return {
|
|
373
|
+
...action,
|
|
374
|
+
type: 'CrossNormalAction',
|
|
375
|
+
action: 'cross-replace',
|
|
376
|
+
crossId: action.crossId,
|
|
377
|
+
crossType: action.crossType,
|
|
378
|
+
transfers,
|
|
379
|
+
} satisfies NormalActionCrossReplace
|
|
380
|
+
}
|
|
381
|
+
case 'cross-trade': {
|
|
382
|
+
const transfers = action.transfers.filter(
|
|
383
|
+
(
|
|
384
|
+
transfer,
|
|
385
|
+
): transfer is
|
|
386
|
+
| TransferCryptoCurrencyIn
|
|
387
|
+
| TransferNftIn
|
|
388
|
+
| TransferFiatCurrencyIn
|
|
389
|
+
| TransferCryptoCurrencyOut
|
|
390
|
+
| TransferNftOut
|
|
391
|
+
| TransferFiatCurrencyOut =>
|
|
392
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
393
|
+
isTransferNftIn(transfer) ||
|
|
394
|
+
isTransferFiatCurrencyIn(transfer) ||
|
|
395
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
396
|
+
isTransferNftOut(transfer) ||
|
|
397
|
+
isTransferFiatCurrencyOut(transfer),
|
|
398
|
+
)
|
|
399
|
+
if (transfers.length !== action.transfers.length) {
|
|
400
|
+
throw new Error('Invalid action.transfers for cross-trade')
|
|
401
|
+
}
|
|
402
|
+
if (action.crossId === undefined) {
|
|
403
|
+
throw new Error('action.crossId is required for cross-trade')
|
|
404
|
+
}
|
|
405
|
+
if (action.crossType === undefined) {
|
|
406
|
+
throw new Error('action.crossType is required for cross-trade')
|
|
407
|
+
}
|
|
408
|
+
return {
|
|
409
|
+
...action,
|
|
410
|
+
type: 'CrossNormalAction',
|
|
411
|
+
action: 'cross-trade',
|
|
412
|
+
crossId: action.crossId,
|
|
413
|
+
crossType: action.crossType,
|
|
414
|
+
transfers,
|
|
415
|
+
} satisfies NormalActionCrossTrade
|
|
416
|
+
}
|
|
417
|
+
case 'deposit': {
|
|
418
|
+
const transfers = action.transfers.filter(
|
|
419
|
+
(transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
|
|
420
|
+
isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
|
|
421
|
+
)
|
|
422
|
+
if (transfers.length !== action.transfers.length) {
|
|
423
|
+
throw new Error('Invalid action.transfers for deposit')
|
|
424
|
+
}
|
|
425
|
+
if (action.loanId === undefined) {
|
|
426
|
+
throw new Error('action.loandId is required for deposit')
|
|
427
|
+
}
|
|
428
|
+
return {
|
|
429
|
+
...action,
|
|
430
|
+
type: 'LoanNormalAction',
|
|
431
|
+
action: 'deposit',
|
|
432
|
+
loanId: action.loanId,
|
|
433
|
+
transfers,
|
|
434
|
+
} satisfies NormalActionDeposit
|
|
435
|
+
}
|
|
436
|
+
case 'deposit-with-bond': {
|
|
437
|
+
const transfers = action.transfers.filter(
|
|
438
|
+
(
|
|
439
|
+
transfer,
|
|
440
|
+
): transfer is
|
|
441
|
+
| TransferCryptoCurrencyIn
|
|
442
|
+
| TransferNftIn
|
|
443
|
+
| TransferCryptoCurrencyOut
|
|
444
|
+
| TransferNftOut =>
|
|
445
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
446
|
+
isTransferNftIn(transfer) ||
|
|
447
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
448
|
+
isTransferNftOut(transfer),
|
|
449
|
+
)
|
|
450
|
+
if (transfers.length !== action.transfers.length) {
|
|
451
|
+
throw new Error('Invalid action.transfers for deposit-with-bond')
|
|
452
|
+
}
|
|
453
|
+
if (action.loanId === undefined) {
|
|
454
|
+
throw new Error('action.loandId is required for deposit-with-bond')
|
|
455
|
+
}
|
|
456
|
+
return {
|
|
457
|
+
...action,
|
|
458
|
+
type: 'LoanNormalAction',
|
|
459
|
+
action: 'deposit-with-bond',
|
|
460
|
+
loanId: action.loanId,
|
|
461
|
+
transfers,
|
|
462
|
+
} satisfies NormalActionDepositWithBond
|
|
463
|
+
}
|
|
464
|
+
case 'fail-tx': {
|
|
465
|
+
if (action.transfers.length > 0) {
|
|
466
|
+
throw new Error('Invalid action.transfers for fail-tx')
|
|
467
|
+
}
|
|
468
|
+
return {
|
|
469
|
+
...action,
|
|
470
|
+
type: 'NormalAction',
|
|
471
|
+
action: 'fail-tx',
|
|
472
|
+
transfers: [],
|
|
473
|
+
} satisfies NormalActionFailTx
|
|
474
|
+
}
|
|
475
|
+
case 'fee': {
|
|
476
|
+
const transfers = action.transfers.filter(
|
|
477
|
+
(
|
|
478
|
+
transfer,
|
|
479
|
+
): transfer is TransferCryptoCurrencyOut | TransferFiatCurrencyOut =>
|
|
480
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
481
|
+
isTransferFiatCurrencyOut(transfer),
|
|
482
|
+
)
|
|
483
|
+
if (transfers.length !== action.transfers.length) {
|
|
484
|
+
throw new Error('Invalid action.transfers for fee')
|
|
485
|
+
}
|
|
486
|
+
return {
|
|
487
|
+
...action,
|
|
488
|
+
type: 'NormalAction',
|
|
489
|
+
action: 'fee',
|
|
490
|
+
transfers,
|
|
491
|
+
} satisfies NormalActionFee
|
|
492
|
+
}
|
|
493
|
+
case 'free-mint-nft': {
|
|
494
|
+
const transfers = action.transfers.filter(
|
|
495
|
+
(transfer): transfer is TransferNftIn => isTransferNftIn(transfer),
|
|
496
|
+
)
|
|
497
|
+
if (transfers.length !== action.transfers.length) {
|
|
498
|
+
throw new Error('Invalid action.transfers for free-mint-nft')
|
|
499
|
+
}
|
|
500
|
+
return {
|
|
501
|
+
...action,
|
|
502
|
+
type: 'NormalAction',
|
|
503
|
+
action: 'free-mint-nft',
|
|
504
|
+
transfers,
|
|
505
|
+
} satisfies NormalActionFreeMintNft
|
|
506
|
+
}
|
|
507
|
+
case 'income': {
|
|
508
|
+
const transfers = action.transfers.filter(
|
|
509
|
+
(
|
|
510
|
+
transfer,
|
|
511
|
+
): transfer is
|
|
512
|
+
| TransferCryptoCurrencyIn
|
|
513
|
+
| TransferNftIn
|
|
514
|
+
| TransferFiatCurrencyIn =>
|
|
515
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
516
|
+
isTransferNftIn(transfer) ||
|
|
517
|
+
isTransferFiatCurrencyIn(transfer),
|
|
518
|
+
)
|
|
519
|
+
if (transfers.length !== action.transfers.length) {
|
|
520
|
+
throw new Error('Invalid action.transfers for income')
|
|
521
|
+
}
|
|
522
|
+
return {
|
|
523
|
+
...action,
|
|
524
|
+
type: 'NormalAction',
|
|
525
|
+
action: 'income',
|
|
526
|
+
transfers,
|
|
527
|
+
} satisfies NormalActionIncome
|
|
528
|
+
}
|
|
529
|
+
case 'mint-nft': {
|
|
530
|
+
const transfers = action.transfers.filter(
|
|
531
|
+
(
|
|
532
|
+
transfer,
|
|
533
|
+
): transfer is
|
|
534
|
+
| TransferNftIn
|
|
535
|
+
| TransferFiatCurrencyOut
|
|
536
|
+
| TransferCryptoCurrencyOut =>
|
|
537
|
+
isTransferNftIn(transfer) ||
|
|
538
|
+
isTransferFiatCurrencyOut(transfer) ||
|
|
539
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
540
|
+
)
|
|
541
|
+
if (transfers.length !== action.transfers.length) {
|
|
542
|
+
throw new Error('Invalid action.transfers for mint-nft')
|
|
543
|
+
}
|
|
544
|
+
return {
|
|
545
|
+
...action,
|
|
546
|
+
type: 'NormalAction',
|
|
547
|
+
action: 'mint-nft',
|
|
548
|
+
transfers,
|
|
549
|
+
} satisfies NormalActionMintNft
|
|
550
|
+
}
|
|
551
|
+
case 'receive-from-cex': {
|
|
552
|
+
const transfers = action.transfers.filter(
|
|
553
|
+
(transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
|
|
554
|
+
isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
|
|
555
|
+
)
|
|
556
|
+
if (transfers.length !== action.transfers.length) {
|
|
557
|
+
throw new Error('Invalid action.transfers for receive-from-cex')
|
|
558
|
+
}
|
|
559
|
+
return {
|
|
560
|
+
...action,
|
|
561
|
+
type: 'NormalAction',
|
|
562
|
+
action: 'receive-from-cex',
|
|
563
|
+
transfers,
|
|
564
|
+
} satisfies NormalActionReceiveFromCex
|
|
565
|
+
}
|
|
566
|
+
case 'remove-liquidity': {
|
|
567
|
+
const transfers = action.transfers.filter(
|
|
568
|
+
(
|
|
569
|
+
transfer,
|
|
570
|
+
): transfer is
|
|
571
|
+
| TransferCryptoCurrencyIn
|
|
572
|
+
| TransferNftIn
|
|
573
|
+
| TransferCryptoCurrencyOut
|
|
574
|
+
| TransferNftOut =>
|
|
575
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
576
|
+
isTransferNftIn(transfer) ||
|
|
577
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
578
|
+
isTransferNftOut(transfer),
|
|
579
|
+
)
|
|
580
|
+
if (transfers.length !== action.transfers.length) {
|
|
581
|
+
throw new Error('Invalid action.transfers for remove-liquidity')
|
|
582
|
+
}
|
|
583
|
+
if (action.loanId === undefined) {
|
|
584
|
+
throw new Error('action.loandId is required for remove-liquidity')
|
|
585
|
+
}
|
|
586
|
+
return {
|
|
587
|
+
...action,
|
|
588
|
+
type: 'LoanNormalAction',
|
|
589
|
+
action: 'remove-liquidity',
|
|
590
|
+
loanId: action.loanId,
|
|
591
|
+
transfers,
|
|
592
|
+
} satisfies NormalActionRemoveLiquidity
|
|
593
|
+
}
|
|
594
|
+
case 'repayment': {
|
|
595
|
+
const transfers = action.transfers.filter(
|
|
596
|
+
(transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
|
|
597
|
+
isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
|
|
598
|
+
)
|
|
599
|
+
if (transfers.length !== action.transfers.length) {
|
|
600
|
+
throw new Error('Invalid action.transfers for repayment')
|
|
601
|
+
}
|
|
602
|
+
if (action.loanId === undefined) {
|
|
603
|
+
throw new Error('action.loandId is required for repayment')
|
|
604
|
+
}
|
|
605
|
+
return {
|
|
606
|
+
...action,
|
|
607
|
+
type: 'LoanNormalAction',
|
|
608
|
+
action: 'repayment',
|
|
609
|
+
loanId: action.loanId,
|
|
610
|
+
transfers,
|
|
611
|
+
} satisfies NormalActionRepayment
|
|
612
|
+
}
|
|
613
|
+
case 'repayment-with-debt': {
|
|
614
|
+
const transfers = action.transfers.filter(
|
|
615
|
+
(
|
|
616
|
+
transfer,
|
|
617
|
+
): transfer is
|
|
618
|
+
| TransferCryptoCurrencyIn
|
|
619
|
+
| TransferNftIn
|
|
620
|
+
| TransferCryptoCurrencyOut
|
|
621
|
+
| TransferNftOut =>
|
|
622
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
623
|
+
isTransferNftIn(transfer) ||
|
|
624
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
625
|
+
isTransferNftOut(transfer),
|
|
626
|
+
)
|
|
627
|
+
if (transfers.length !== action.transfers.length) {
|
|
628
|
+
throw new Error('Invalid action.transfers for repayment-with-debt')
|
|
629
|
+
}
|
|
630
|
+
if (action.loanId === undefined) {
|
|
631
|
+
throw new Error('action.loandId is required for repayment-with-debt')
|
|
632
|
+
}
|
|
633
|
+
return {
|
|
634
|
+
...action,
|
|
635
|
+
type: 'LoanNormalAction',
|
|
636
|
+
action: 'repayment-with-debt',
|
|
637
|
+
loanId: action.loanId,
|
|
638
|
+
transfers,
|
|
639
|
+
} satisfies NormalActionRepaymentWithDebt
|
|
640
|
+
}
|
|
641
|
+
case 'replace': {
|
|
642
|
+
const transfers = action.transfers.filter(
|
|
643
|
+
(
|
|
644
|
+
transfer,
|
|
645
|
+
): transfer is
|
|
646
|
+
| TransferCryptoCurrencyIn
|
|
647
|
+
| TransferNftIn
|
|
648
|
+
| TransferCryptoCurrencyOut
|
|
649
|
+
| TransferNftOut =>
|
|
650
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
651
|
+
isTransferNftIn(transfer) ||
|
|
652
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
653
|
+
isTransferNftOut(transfer),
|
|
654
|
+
)
|
|
655
|
+
if (transfers.length !== action.transfers.length) {
|
|
656
|
+
throw new Error('Invalid action.transfers for replace')
|
|
657
|
+
}
|
|
658
|
+
return {
|
|
659
|
+
...action,
|
|
660
|
+
type: 'NormalAction',
|
|
661
|
+
action: 'replace',
|
|
662
|
+
transfers,
|
|
663
|
+
} satisfies NormalActionReplace
|
|
664
|
+
}
|
|
665
|
+
case 'revoke': {
|
|
666
|
+
if (action.transfers.length > 0) {
|
|
667
|
+
throw new Error('Invalid action.transfers for revoke')
|
|
668
|
+
}
|
|
669
|
+
return {
|
|
670
|
+
...action,
|
|
671
|
+
type: 'NormalAction',
|
|
672
|
+
action: 'revoke',
|
|
673
|
+
transfers: [],
|
|
674
|
+
} satisfies NormalActionRevoke
|
|
675
|
+
}
|
|
676
|
+
case 'sell-crypto': {
|
|
677
|
+
const transfers = action.transfers.filter(
|
|
678
|
+
(
|
|
679
|
+
transfer,
|
|
680
|
+
): transfer is TransferFiatCurrencyIn | TransferCryptoCurrencyOut =>
|
|
681
|
+
isTransferFiatCurrencyIn(transfer) ||
|
|
682
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
683
|
+
)
|
|
684
|
+
if (transfers.length !== action.transfers.length) {
|
|
685
|
+
throw new Error('Invalid action.transfers for sell-crypto')
|
|
686
|
+
}
|
|
687
|
+
return {
|
|
688
|
+
...action,
|
|
689
|
+
type: 'NormalAction',
|
|
690
|
+
action: 'sell-crypto',
|
|
691
|
+
transfers,
|
|
692
|
+
} satisfies NormalActionSellCrypto
|
|
693
|
+
}
|
|
694
|
+
case 'sell-nft': {
|
|
695
|
+
const transfers = action.transfers.filter(
|
|
696
|
+
(
|
|
697
|
+
transfer,
|
|
698
|
+
): transfer is
|
|
699
|
+
| TransferFiatCurrencyIn
|
|
700
|
+
| TransferCryptoCurrencyIn
|
|
701
|
+
| TransferNftOut =>
|
|
702
|
+
isTransferFiatCurrencyIn(transfer) ||
|
|
703
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
704
|
+
isTransferNftOut(transfer),
|
|
705
|
+
)
|
|
706
|
+
if (transfers.length !== action.transfers.length) {
|
|
707
|
+
throw new Error('Invalid action.transfers for sell-nft')
|
|
708
|
+
}
|
|
709
|
+
return {
|
|
710
|
+
...action,
|
|
711
|
+
type: 'NormalAction',
|
|
712
|
+
action: 'sell-nft',
|
|
713
|
+
transfers,
|
|
714
|
+
} satisfies NormalActionSellNft
|
|
715
|
+
}
|
|
716
|
+
case 'send-to-cex': {
|
|
717
|
+
const transfers = action.transfers.filter(
|
|
718
|
+
(transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
|
|
719
|
+
isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
|
|
720
|
+
)
|
|
721
|
+
if (transfers.length !== action.transfers.length) {
|
|
722
|
+
throw new Error('Invalid action.transfers for send-to-cex')
|
|
723
|
+
}
|
|
724
|
+
return {
|
|
725
|
+
...action,
|
|
726
|
+
type: 'NormalAction',
|
|
727
|
+
action: 'send-to-cex',
|
|
728
|
+
transfers,
|
|
729
|
+
} satisfies NormalActionSendToCex
|
|
730
|
+
}
|
|
731
|
+
case 'spam': {
|
|
732
|
+
const transfers = action.transfers.filter(
|
|
733
|
+
(
|
|
734
|
+
transfer,
|
|
735
|
+
): transfer is
|
|
736
|
+
| TransferCryptoCurrencyIn
|
|
737
|
+
| TransferNftIn
|
|
738
|
+
| TransferCryptoCurrencyOut
|
|
739
|
+
| TransferNftOut =>
|
|
740
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
741
|
+
isTransferNftIn(transfer) ||
|
|
742
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
743
|
+
isTransferNftOut(transfer),
|
|
744
|
+
)
|
|
745
|
+
if (transfers.length !== action.transfers.length) {
|
|
746
|
+
throw new Error('Invalid action.transfers for spam')
|
|
747
|
+
}
|
|
748
|
+
return {
|
|
749
|
+
...action,
|
|
750
|
+
type: 'NormalAction',
|
|
751
|
+
action: 'spam',
|
|
752
|
+
transfers,
|
|
753
|
+
} satisfies NormalActionSpam
|
|
754
|
+
}
|
|
755
|
+
case 'stake': {
|
|
756
|
+
const transfers = action.transfers.filter(
|
|
757
|
+
(transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
|
|
758
|
+
isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
|
|
759
|
+
)
|
|
760
|
+
if (transfers.length !== action.transfers.length) {
|
|
761
|
+
throw new Error('Invalid action.transfers for stake')
|
|
762
|
+
}
|
|
763
|
+
if (action.loanId === undefined) {
|
|
764
|
+
throw new Error('action.loandId is required for stake')
|
|
765
|
+
}
|
|
766
|
+
return {
|
|
767
|
+
...action,
|
|
768
|
+
type: 'LoanNormalAction',
|
|
769
|
+
action: 'stake',
|
|
770
|
+
loanId: action.loanId,
|
|
771
|
+
transfers,
|
|
772
|
+
} satisfies NormalActionStake
|
|
773
|
+
}
|
|
774
|
+
case 'swap-nft': {
|
|
775
|
+
const transfers = action.transfers.filter(
|
|
776
|
+
(transfer): transfer is TransferNftIn | TransferNftOut =>
|
|
777
|
+
isTransferNftIn(transfer) || isTransferNftOut(transfer),
|
|
778
|
+
)
|
|
779
|
+
if (transfers.length !== action.transfers.length) {
|
|
780
|
+
throw new Error('Invalid action.transfers for swap-nft')
|
|
781
|
+
}
|
|
782
|
+
return {
|
|
783
|
+
...action,
|
|
784
|
+
type: 'NormalAction',
|
|
785
|
+
action: 'swap-nft',
|
|
786
|
+
transfers,
|
|
787
|
+
} satisfies NormalActionSwapNft
|
|
788
|
+
}
|
|
789
|
+
case 'transaction-fee': {
|
|
790
|
+
const transfers = action.transfers.filter(
|
|
791
|
+
(transfer): transfer is TransferCryptoCurrencyOut =>
|
|
792
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
793
|
+
)
|
|
794
|
+
if (transfers.length !== action.transfers.length) {
|
|
795
|
+
throw new Error('Invalid action.transfers for transaction-fee')
|
|
796
|
+
}
|
|
797
|
+
return {
|
|
798
|
+
...action,
|
|
799
|
+
type: 'NormalAction',
|
|
800
|
+
action: 'transaction-fee',
|
|
801
|
+
transfers,
|
|
802
|
+
} satisfies NormalActionTransactionFee
|
|
803
|
+
}
|
|
804
|
+
case 'trade': {
|
|
805
|
+
const transfers = action.transfers.filter(
|
|
806
|
+
(
|
|
807
|
+
transfer,
|
|
808
|
+
): transfer is
|
|
809
|
+
| TransferCryptoCurrencyIn
|
|
810
|
+
| TransferNftIn
|
|
811
|
+
| TransferFiatCurrencyIn
|
|
812
|
+
| TransferCryptoCurrencyOut
|
|
813
|
+
| TransferNftOut
|
|
814
|
+
| TransferFiatCurrencyOut =>
|
|
815
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
816
|
+
isTransferNftIn(transfer) ||
|
|
817
|
+
isTransferFiatCurrencyIn(transfer) ||
|
|
818
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
819
|
+
isTransferNftOut(transfer) ||
|
|
820
|
+
isTransferFiatCurrencyOut(transfer),
|
|
821
|
+
)
|
|
822
|
+
if (transfers.length !== action.transfers.length) {
|
|
823
|
+
throw new Error('Invalid action.transfers for trade')
|
|
824
|
+
}
|
|
825
|
+
return {
|
|
826
|
+
...action,
|
|
827
|
+
type: 'NormalAction',
|
|
828
|
+
action: 'trade',
|
|
829
|
+
transfers,
|
|
830
|
+
} satisfies NormalActionTrade
|
|
831
|
+
}
|
|
832
|
+
case 'transfer': {
|
|
833
|
+
return {
|
|
834
|
+
...action,
|
|
835
|
+
type: 'NormalAction',
|
|
836
|
+
action: 'transfer',
|
|
837
|
+
transfers: [...action.transfers],
|
|
838
|
+
} satisfies NormalActionTransfer
|
|
839
|
+
}
|
|
840
|
+
case 'unstake': {
|
|
841
|
+
const transfers = action.transfers.filter(
|
|
842
|
+
(transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
|
|
843
|
+
isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
|
|
844
|
+
)
|
|
845
|
+
if (transfers.length !== action.transfers.length) {
|
|
846
|
+
throw new Error('Invalid action.transfers for unstake')
|
|
847
|
+
}
|
|
848
|
+
if (action.loanId === undefined) {
|
|
849
|
+
throw new Error('action.loandId is required for unstake')
|
|
850
|
+
}
|
|
851
|
+
return {
|
|
852
|
+
...action,
|
|
853
|
+
type: 'LoanNormalAction',
|
|
854
|
+
action: 'unstake',
|
|
855
|
+
loanId: action.loanId,
|
|
856
|
+
transfers,
|
|
857
|
+
} satisfies NormalActionUnstake
|
|
858
|
+
}
|
|
859
|
+
case 'unwrap': {
|
|
860
|
+
const transfers = action.transfers.filter(
|
|
861
|
+
(
|
|
862
|
+
transfer,
|
|
863
|
+
): transfer is TransferCryptoCurrencyIn | TransferCryptoCurrencyOut =>
|
|
864
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
865
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
866
|
+
)
|
|
867
|
+
if (transfers.length !== action.transfers.length) {
|
|
868
|
+
throw new Error('Invalid action.transfers for unwrap')
|
|
869
|
+
}
|
|
870
|
+
return {
|
|
871
|
+
...action,
|
|
872
|
+
type: 'NormalAction',
|
|
873
|
+
action: 'unwrap',
|
|
874
|
+
transfers,
|
|
875
|
+
} satisfies NormalActionUnwrap
|
|
876
|
+
}
|
|
877
|
+
case 'valuedown': {
|
|
878
|
+
const transfers = action.transfers.filter(
|
|
879
|
+
(
|
|
880
|
+
transfer,
|
|
881
|
+
): transfer is
|
|
882
|
+
| TransferCryptoCurrencyIn
|
|
883
|
+
| TransferNftIn
|
|
884
|
+
| TransferFiatCurrencyIn =>
|
|
885
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
886
|
+
isTransferNftIn(transfer) ||
|
|
887
|
+
isTransferFiatCurrencyIn(transfer),
|
|
888
|
+
)
|
|
889
|
+
if (transfers.length !== action.transfers.length) {
|
|
890
|
+
throw new Error('Invalid action.transfers for valuedown')
|
|
891
|
+
}
|
|
892
|
+
if (action.target === undefined) {
|
|
893
|
+
throw new Error('action.target is required for valuedown')
|
|
894
|
+
}
|
|
895
|
+
return {
|
|
896
|
+
...action,
|
|
897
|
+
type: 'NormalAction',
|
|
898
|
+
action: 'valuedown',
|
|
899
|
+
target: action.target,
|
|
900
|
+
transfers,
|
|
901
|
+
} satisfies NormalActionValuedown
|
|
902
|
+
}
|
|
903
|
+
case 'valueup': {
|
|
904
|
+
const transfers = action.transfers.filter(
|
|
905
|
+
(
|
|
906
|
+
transfer,
|
|
907
|
+
): transfer is
|
|
908
|
+
| TransferCryptoCurrencyOut
|
|
909
|
+
| TransferNftOut
|
|
910
|
+
| TransferFiatCurrencyOut =>
|
|
911
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
912
|
+
isTransferNftOut(transfer) ||
|
|
913
|
+
isTransferFiatCurrencyOut(transfer),
|
|
914
|
+
)
|
|
915
|
+
if (transfers.length !== action.transfers.length) {
|
|
916
|
+
throw new Error('Invalid action.transfers for valueup')
|
|
917
|
+
}
|
|
918
|
+
if (action.target === undefined) {
|
|
919
|
+
throw new Error('action.target is required for valueup')
|
|
920
|
+
}
|
|
921
|
+
return {
|
|
922
|
+
...action,
|
|
923
|
+
type: 'NormalAction',
|
|
924
|
+
action: 'valueup',
|
|
925
|
+
target: action.target,
|
|
926
|
+
transfers,
|
|
927
|
+
} satisfies NormalActionValueup
|
|
928
|
+
}
|
|
929
|
+
case 'withdraw': {
|
|
930
|
+
const transfers = action.transfers.filter(
|
|
931
|
+
(transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
|
|
932
|
+
isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
|
|
933
|
+
)
|
|
934
|
+
if (transfers.length !== action.transfers.length) {
|
|
935
|
+
throw new Error('Invalid action.transfers for withdraw')
|
|
936
|
+
}
|
|
937
|
+
if (action.loanId === undefined) {
|
|
938
|
+
throw new Error('action.loandId is required for withdraw')
|
|
939
|
+
}
|
|
940
|
+
return {
|
|
941
|
+
...action,
|
|
942
|
+
type: 'LoanNormalAction',
|
|
943
|
+
action: 'withdraw',
|
|
944
|
+
loanId: action.loanId,
|
|
945
|
+
transfers,
|
|
946
|
+
} satisfies NormalActionWithdraw
|
|
947
|
+
}
|
|
948
|
+
case 'withdraw-with-bond': {
|
|
949
|
+
const transfers = action.transfers.filter(
|
|
950
|
+
(
|
|
951
|
+
transfer,
|
|
952
|
+
): transfer is
|
|
953
|
+
| TransferCryptoCurrencyIn
|
|
954
|
+
| TransferNftIn
|
|
955
|
+
| TransferCryptoCurrencyOut
|
|
956
|
+
| TransferNftOut =>
|
|
957
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
958
|
+
isTransferNftIn(transfer) ||
|
|
959
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
960
|
+
isTransferNftOut(transfer),
|
|
961
|
+
)
|
|
962
|
+
if (transfers.length !== action.transfers.length) {
|
|
963
|
+
throw new Error('Invalid action.transfers for withdraw-with-bond')
|
|
964
|
+
}
|
|
965
|
+
if (action.loanId === undefined) {
|
|
966
|
+
throw new Error('action.loandId is required for withdraw-with-bond')
|
|
967
|
+
}
|
|
968
|
+
return {
|
|
969
|
+
...action,
|
|
970
|
+
type: 'LoanNormalAction',
|
|
971
|
+
action: 'withdraw-with-bond',
|
|
972
|
+
loanId: action.loanId,
|
|
973
|
+
transfers,
|
|
974
|
+
} satisfies NormalActionWithdrawWithBond
|
|
975
|
+
}
|
|
976
|
+
case 'wrap': {
|
|
977
|
+
const transfers = action.transfers.filter(
|
|
978
|
+
(
|
|
979
|
+
transfer,
|
|
980
|
+
): transfer is TransferCryptoCurrencyIn | TransferCryptoCurrencyOut =>
|
|
981
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
982
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
983
|
+
)
|
|
984
|
+
if (transfers.length !== action.transfers.length) {
|
|
985
|
+
throw new Error('Invalid action.transfers for wrap')
|
|
986
|
+
}
|
|
987
|
+
return {
|
|
988
|
+
...action,
|
|
989
|
+
type: 'NormalAction',
|
|
990
|
+
action: 'wrap',
|
|
991
|
+
transfers,
|
|
992
|
+
} satisfies NormalActionWrap
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
|
|
997
|
+
export const parseBaseAccountActionToAccountAction = (
|
|
998
|
+
action: BaseAccountAction,
|
|
999
|
+
): AccountAction => {
|
|
1000
|
+
switch (action.action) {
|
|
1001
|
+
case 'add-liquidity': {
|
|
1002
|
+
// transferCryptoCurrencyInSchema,
|
|
1003
|
+
// transferNftInSchema,
|
|
1004
|
+
// transferCryptoCurrencyOutSchema,
|
|
1005
|
+
// transferNftOutSchema,
|
|
1006
|
+
const transfers = action.transfers.filter(
|
|
1007
|
+
(
|
|
1008
|
+
transfer,
|
|
1009
|
+
): transfer is
|
|
1010
|
+
| TransferCryptoCurrencyIn
|
|
1011
|
+
| TransferNftIn
|
|
1012
|
+
| TransferCryptoCurrencyOut
|
|
1013
|
+
| TransferNftOut =>
|
|
1014
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1015
|
+
isTransferNftIn(transfer) ||
|
|
1016
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1017
|
+
isTransferNftOut(transfer),
|
|
1018
|
+
)
|
|
1019
|
+
if (transfers.length !== action.transfers.length) {
|
|
1020
|
+
throw new Error('Invalid action.transfers for add-liquidity')
|
|
1021
|
+
}
|
|
1022
|
+
if (action.loanId === undefined) {
|
|
1023
|
+
throw new Error('action.loandId is required for add-liquidity')
|
|
1024
|
+
}
|
|
1025
|
+
return {
|
|
1026
|
+
...action,
|
|
1027
|
+
type: 'LoanAccountAction',
|
|
1028
|
+
action: 'add-liquidity',
|
|
1029
|
+
loanId: action.loanId,
|
|
1030
|
+
transfers,
|
|
1031
|
+
} satisfies AccountActionAddLiquidity
|
|
1032
|
+
}
|
|
1033
|
+
case 'approve': {
|
|
1034
|
+
if (action.transfers.length > 0) {
|
|
1035
|
+
throw new Error('Invalid action.transfers for approve')
|
|
1036
|
+
}
|
|
1037
|
+
return {
|
|
1038
|
+
...action,
|
|
1039
|
+
type: 'NormalAccountAction',
|
|
1040
|
+
action: 'approve',
|
|
1041
|
+
transfers: [],
|
|
1042
|
+
} satisfies AccountActionApprove
|
|
1043
|
+
}
|
|
1044
|
+
case 'atomic-arbitrage': {
|
|
1045
|
+
// transferCryptoCurrencyInSchema,
|
|
1046
|
+
// transferCryptoCurrencyOutSchema,
|
|
1047
|
+
const transfers = action.transfers.filter(
|
|
1048
|
+
(
|
|
1049
|
+
transfer,
|
|
1050
|
+
): transfer is TransferCryptoCurrencyIn | TransferCryptoCurrencyOut =>
|
|
1051
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1052
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
1053
|
+
)
|
|
1054
|
+
if (transfers.length !== action.transfers.length) {
|
|
1055
|
+
throw new Error('Invalid action.transfers for atomic-arbitrage')
|
|
1056
|
+
}
|
|
1057
|
+
return {
|
|
1058
|
+
...action,
|
|
1059
|
+
type: 'NormalAccountAction',
|
|
1060
|
+
action: 'atomic-arbitrage',
|
|
1061
|
+
transfers,
|
|
1062
|
+
} satisfies AccountActionAtomicArbitrage
|
|
1063
|
+
}
|
|
1064
|
+
case 'borrow': {
|
|
1065
|
+
// transferCryptoCurrencyInSchema, transferNftInSchema
|
|
1066
|
+
const transfers = action.transfers.filter(
|
|
1067
|
+
(transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
|
|
1068
|
+
isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
|
|
1069
|
+
)
|
|
1070
|
+
if (transfers.length !== action.transfers.length) {
|
|
1071
|
+
throw new Error('Invalid action.transfers for borrow')
|
|
1072
|
+
}
|
|
1073
|
+
if (action.loanId === undefined) {
|
|
1074
|
+
throw new Error('action.loandId is required for borrow')
|
|
1075
|
+
}
|
|
1076
|
+
return {
|
|
1077
|
+
...action,
|
|
1078
|
+
type: 'LoanAccountAction',
|
|
1079
|
+
action: 'borrow',
|
|
1080
|
+
loanId: action.loanId,
|
|
1081
|
+
transfers,
|
|
1082
|
+
} satisfies AccountActionBorrow
|
|
1083
|
+
}
|
|
1084
|
+
case 'borrow-with-debt': {
|
|
1085
|
+
// transferCryptoCurrencyInSchema,
|
|
1086
|
+
// transferNftInSchema,
|
|
1087
|
+
// transferCryptoCurrencyOutSchema,
|
|
1088
|
+
// transferNftOutSchema,
|
|
1089
|
+
const transfers = action.transfers.filter(
|
|
1090
|
+
(
|
|
1091
|
+
transfer,
|
|
1092
|
+
): transfer is
|
|
1093
|
+
| TransferCryptoCurrencyIn
|
|
1094
|
+
| TransferNftIn
|
|
1095
|
+
| TransferCryptoCurrencyOut
|
|
1096
|
+
| TransferNftOut =>
|
|
1097
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1098
|
+
isTransferNftIn(transfer) ||
|
|
1099
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1100
|
+
isTransferNftOut(transfer),
|
|
1101
|
+
)
|
|
1102
|
+
if (transfers.length !== action.transfers.length) {
|
|
1103
|
+
throw new Error('Invalid action.transfers for borrow-with-debt')
|
|
1104
|
+
}
|
|
1105
|
+
if (action.loanId === undefined) {
|
|
1106
|
+
throw new Error('action.loandId is required for borrow-with-debt')
|
|
1107
|
+
}
|
|
1108
|
+
return {
|
|
1109
|
+
...action,
|
|
1110
|
+
type: 'LoanAccountAction',
|
|
1111
|
+
action: 'borrow-with-debt',
|
|
1112
|
+
loanId: action.loanId,
|
|
1113
|
+
transfers,
|
|
1114
|
+
} satisfies AccountActionBorrowWithDebt
|
|
1115
|
+
}
|
|
1116
|
+
case 'bridge-from': {
|
|
1117
|
+
// transferCryptoCurrencyOutSchema, transferNftOutSchema
|
|
1118
|
+
const transfers = action.transfers.filter(
|
|
1119
|
+
(transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
|
|
1120
|
+
isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
|
|
1121
|
+
)
|
|
1122
|
+
if (transfers.length !== action.transfers.length) {
|
|
1123
|
+
throw new Error('Invalid action.transfers for bridge-from')
|
|
1124
|
+
}
|
|
1125
|
+
if (action.crossId === undefined) {
|
|
1126
|
+
throw new Error('action.crossId is required for bridge-from')
|
|
1127
|
+
}
|
|
1128
|
+
if (action.crossType === undefined) {
|
|
1129
|
+
throw new Error('action.crossType is required for bridge-from')
|
|
1130
|
+
}
|
|
1131
|
+
return {
|
|
1132
|
+
...action,
|
|
1133
|
+
type: 'CrossAccountAction',
|
|
1134
|
+
action: 'bridge-from',
|
|
1135
|
+
crossId: action.crossId,
|
|
1136
|
+
crossType: action.crossType,
|
|
1137
|
+
transfers,
|
|
1138
|
+
} satisfies AccountActionBridgeFrom
|
|
1139
|
+
}
|
|
1140
|
+
case 'bridge-to': {
|
|
1141
|
+
// transferCryptoCurrencyInSchema, transferNftInSchema
|
|
1142
|
+
const transfers = action.transfers.filter(
|
|
1143
|
+
(transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
|
|
1144
|
+
isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
|
|
1145
|
+
)
|
|
1146
|
+
if (transfers.length !== action.transfers.length) {
|
|
1147
|
+
throw new Error('Invalid action.transfers for bridge-to')
|
|
1148
|
+
}
|
|
1149
|
+
if (action.crossId === undefined) {
|
|
1150
|
+
throw new Error('action.crossId is required for bridge-to')
|
|
1151
|
+
}
|
|
1152
|
+
if (action.crossType === undefined) {
|
|
1153
|
+
throw new Error('action.crossType is required for bridge-to')
|
|
1154
|
+
}
|
|
1155
|
+
return {
|
|
1156
|
+
...action,
|
|
1157
|
+
type: 'CrossAccountAction',
|
|
1158
|
+
action: 'bridge-to',
|
|
1159
|
+
crossId: action.crossId,
|
|
1160
|
+
crossType: action.crossType,
|
|
1161
|
+
transfers,
|
|
1162
|
+
} satisfies AccountActionBridgeTo
|
|
1163
|
+
}
|
|
1164
|
+
case 'buy-crypto': {
|
|
1165
|
+
// transferCryptoCurrencyInSchema, transferFiatCurrencyOutSchema
|
|
1166
|
+
const transfers = action.transfers.filter(
|
|
1167
|
+
(
|
|
1168
|
+
transfer,
|
|
1169
|
+
): transfer is TransferCryptoCurrencyIn | TransferFiatCurrencyOut =>
|
|
1170
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1171
|
+
isTransferFiatCurrencyOut(transfer),
|
|
1172
|
+
)
|
|
1173
|
+
if (transfers.length !== action.transfers.length) {
|
|
1174
|
+
throw new Error('Invalid action.transfers for buy-crypto')
|
|
1175
|
+
}
|
|
1176
|
+
return {
|
|
1177
|
+
...action,
|
|
1178
|
+
type: 'NormalAccountAction',
|
|
1179
|
+
action: 'buy-crypto',
|
|
1180
|
+
transfers,
|
|
1181
|
+
} satisfies AccountActionBuyCrypto
|
|
1182
|
+
}
|
|
1183
|
+
case 'buy-nft': {
|
|
1184
|
+
// transferNftInSchema,
|
|
1185
|
+
// transferFiatCurrencyOutSchema,
|
|
1186
|
+
// transferCryptoCurrencyOutSchema,
|
|
1187
|
+
const transfers = action.transfers.filter(
|
|
1188
|
+
(
|
|
1189
|
+
transfer,
|
|
1190
|
+
): transfer is
|
|
1191
|
+
| TransferNftIn
|
|
1192
|
+
| TransferFiatCurrencyOut
|
|
1193
|
+
| TransferCryptoCurrencyOut =>
|
|
1194
|
+
isTransferNftIn(transfer) ||
|
|
1195
|
+
isTransferFiatCurrencyOut(transfer) ||
|
|
1196
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
1197
|
+
)
|
|
1198
|
+
if (transfers.length !== action.transfers.length) {
|
|
1199
|
+
throw new Error('Invalid action.transfers for buy-nft')
|
|
1200
|
+
}
|
|
1201
|
+
return {
|
|
1202
|
+
...action,
|
|
1203
|
+
type: 'NormalAccountAction',
|
|
1204
|
+
action: 'buy-nft',
|
|
1205
|
+
transfers,
|
|
1206
|
+
} satisfies AccountActionBuyNft
|
|
1207
|
+
}
|
|
1208
|
+
case 'cross-replace': {
|
|
1209
|
+
// transferInSchema, transferOutSchema
|
|
1210
|
+
const transfers = action.transfers.filter(
|
|
1211
|
+
(
|
|
1212
|
+
transfer,
|
|
1213
|
+
): transfer is
|
|
1214
|
+
| TransferCryptoCurrencyIn
|
|
1215
|
+
| TransferNftIn
|
|
1216
|
+
| TransferFiatCurrencyIn
|
|
1217
|
+
| TransferCryptoCurrencyOut
|
|
1218
|
+
| TransferNftOut
|
|
1219
|
+
| TransferFiatCurrencyOut =>
|
|
1220
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1221
|
+
isTransferNftIn(transfer) ||
|
|
1222
|
+
isTransferFiatCurrencyIn(transfer) ||
|
|
1223
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1224
|
+
isTransferNftOut(transfer) ||
|
|
1225
|
+
isTransferFiatCurrencyOut(transfer),
|
|
1226
|
+
)
|
|
1227
|
+
if (transfers.length !== action.transfers.length) {
|
|
1228
|
+
throw new Error('Invalid action.transfers for cross-replace')
|
|
1229
|
+
}
|
|
1230
|
+
if (action.crossId === undefined) {
|
|
1231
|
+
throw new Error('action.crossId is required for cross-replace')
|
|
1232
|
+
}
|
|
1233
|
+
if (action.crossType === undefined) {
|
|
1234
|
+
throw new Error('action.crossType is required for cross-replace')
|
|
1235
|
+
}
|
|
1236
|
+
return {
|
|
1237
|
+
...action,
|
|
1238
|
+
type: 'CrossAccountAction',
|
|
1239
|
+
action: 'cross-replace',
|
|
1240
|
+
crossId: action.crossId,
|
|
1241
|
+
crossType: action.crossType,
|
|
1242
|
+
transfers,
|
|
1243
|
+
} satisfies AccountActionCrossReplace
|
|
1244
|
+
}
|
|
1245
|
+
case 'cross-trade': {
|
|
1246
|
+
// transferInSchema, transferOutSchema
|
|
1247
|
+
const transfers = action.transfers.filter(
|
|
1248
|
+
(
|
|
1249
|
+
transfer,
|
|
1250
|
+
): transfer is
|
|
1251
|
+
| TransferCryptoCurrencyIn
|
|
1252
|
+
| TransferNftIn
|
|
1253
|
+
| TransferFiatCurrencyIn
|
|
1254
|
+
| TransferCryptoCurrencyOut
|
|
1255
|
+
| TransferNftOut
|
|
1256
|
+
| TransferFiatCurrencyOut =>
|
|
1257
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1258
|
+
isTransferNftIn(transfer) ||
|
|
1259
|
+
isTransferFiatCurrencyIn(transfer) ||
|
|
1260
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1261
|
+
isTransferNftOut(transfer) ||
|
|
1262
|
+
isTransferFiatCurrencyOut(transfer),
|
|
1263
|
+
)
|
|
1264
|
+
if (transfers.length !== action.transfers.length) {
|
|
1265
|
+
throw new Error('Invalid action.transfers for cross-trade')
|
|
1266
|
+
}
|
|
1267
|
+
if (action.crossId === undefined) {
|
|
1268
|
+
throw new Error('action.crossId is required for cross-trade')
|
|
1269
|
+
}
|
|
1270
|
+
if (action.crossType === undefined) {
|
|
1271
|
+
throw new Error('action.crossType is required for cross-trade')
|
|
1272
|
+
}
|
|
1273
|
+
return {
|
|
1274
|
+
...action,
|
|
1275
|
+
type: 'CrossAccountAction',
|
|
1276
|
+
action: 'cross-trade',
|
|
1277
|
+
crossId: action.crossId,
|
|
1278
|
+
crossType: action.crossType,
|
|
1279
|
+
transfers,
|
|
1280
|
+
} satisfies AccountActionCrossTrade
|
|
1281
|
+
}
|
|
1282
|
+
case 'deposit': {
|
|
1283
|
+
// transferCryptoCurrencyOutSchema, transferNftOutSchema
|
|
1284
|
+
const transfers = action.transfers.filter(
|
|
1285
|
+
(transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
|
|
1286
|
+
isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
|
|
1287
|
+
)
|
|
1288
|
+
if (transfers.length !== action.transfers.length) {
|
|
1289
|
+
throw new Error('Invalid action.transfers for deposit')
|
|
1290
|
+
}
|
|
1291
|
+
if (action.loanId === undefined) {
|
|
1292
|
+
throw new Error('action.loandId is required for deposit')
|
|
1293
|
+
}
|
|
1294
|
+
return {
|
|
1295
|
+
...action,
|
|
1296
|
+
type: 'LoanAccountAction',
|
|
1297
|
+
action: 'deposit',
|
|
1298
|
+
loanId: action.loanId,
|
|
1299
|
+
transfers,
|
|
1300
|
+
} satisfies AccountActionDeposit
|
|
1301
|
+
}
|
|
1302
|
+
case 'deposit-with-bond': {
|
|
1303
|
+
// transferCryptoCurrencyInSchema,
|
|
1304
|
+
// transferNftInSchema,
|
|
1305
|
+
// transferCryptoCurrencyOutSchema,
|
|
1306
|
+
// transferNftOutSchema,
|
|
1307
|
+
const transfers = action.transfers.filter(
|
|
1308
|
+
(
|
|
1309
|
+
transfer,
|
|
1310
|
+
): transfer is
|
|
1311
|
+
| TransferCryptoCurrencyIn
|
|
1312
|
+
| TransferNftIn
|
|
1313
|
+
| TransferCryptoCurrencyOut
|
|
1314
|
+
| TransferNftOut =>
|
|
1315
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1316
|
+
isTransferNftIn(transfer) ||
|
|
1317
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1318
|
+
isTransferNftOut(transfer),
|
|
1319
|
+
)
|
|
1320
|
+
if (transfers.length !== action.transfers.length) {
|
|
1321
|
+
throw new Error('Invalid action.transfers for deposit-with-bond')
|
|
1322
|
+
}
|
|
1323
|
+
if (action.loanId === undefined) {
|
|
1324
|
+
throw new Error('action.loandId is required for deposit-with-bond')
|
|
1325
|
+
}
|
|
1326
|
+
return {
|
|
1327
|
+
...action,
|
|
1328
|
+
type: 'LoanAccountAction',
|
|
1329
|
+
action: 'deposit-with-bond',
|
|
1330
|
+
loanId: action.loanId,
|
|
1331
|
+
transfers,
|
|
1332
|
+
} satisfies AccountActionDepositWithBond
|
|
1333
|
+
}
|
|
1334
|
+
case 'fail-tx': {
|
|
1335
|
+
if (action.transfers.length > 0) {
|
|
1336
|
+
throw new Error('Invalid action.transfers for fail-tx')
|
|
1337
|
+
}
|
|
1338
|
+
return {
|
|
1339
|
+
...action,
|
|
1340
|
+
type: 'NormalAccountAction',
|
|
1341
|
+
action: 'fail-tx',
|
|
1342
|
+
transfers: [],
|
|
1343
|
+
} satisfies AccountActionFailTx
|
|
1344
|
+
}
|
|
1345
|
+
case 'fee': {
|
|
1346
|
+
// transferCryptoCurrencyOutSchema, transferFiatCurrencyOutSchema
|
|
1347
|
+
const transfers = action.transfers.filter(
|
|
1348
|
+
(
|
|
1349
|
+
transfer,
|
|
1350
|
+
): transfer is TransferCryptoCurrencyOut | TransferFiatCurrencyOut =>
|
|
1351
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1352
|
+
isTransferFiatCurrencyOut(transfer),
|
|
1353
|
+
)
|
|
1354
|
+
if (transfers.length !== action.transfers.length) {
|
|
1355
|
+
throw new Error('Invalid action.transfers for fee')
|
|
1356
|
+
}
|
|
1357
|
+
return {
|
|
1358
|
+
...action,
|
|
1359
|
+
type: 'NormalAccountAction',
|
|
1360
|
+
action: 'fee',
|
|
1361
|
+
transfers,
|
|
1362
|
+
} satisfies AccountActionFee
|
|
1363
|
+
}
|
|
1364
|
+
case 'free-mint-nft': {
|
|
1365
|
+
// transferNftInSchema
|
|
1366
|
+
const transfers = action.transfers.filter(
|
|
1367
|
+
(transfer): transfer is TransferNftIn => isTransferNftIn(transfer),
|
|
1368
|
+
)
|
|
1369
|
+
if (transfers.length !== action.transfers.length) {
|
|
1370
|
+
throw new Error('Invalid action.transfers for free-mint-nft')
|
|
1371
|
+
}
|
|
1372
|
+
return {
|
|
1373
|
+
...action,
|
|
1374
|
+
type: 'NormalAccountAction',
|
|
1375
|
+
action: 'free-mint-nft',
|
|
1376
|
+
transfers,
|
|
1377
|
+
} satisfies AccountActionFreeMintNft
|
|
1378
|
+
}
|
|
1379
|
+
case 'ignore': {
|
|
1380
|
+
return {
|
|
1381
|
+
...action,
|
|
1382
|
+
type: 'NormalAccountAction',
|
|
1383
|
+
action: 'ignore',
|
|
1384
|
+
transfers: [...action.transfers],
|
|
1385
|
+
} satisfies AccountActionIgnore
|
|
1386
|
+
}
|
|
1387
|
+
case 'income': {
|
|
1388
|
+
// transferInSchema
|
|
1389
|
+
const transfers = action.transfers.filter(
|
|
1390
|
+
(
|
|
1391
|
+
transfer,
|
|
1392
|
+
): transfer is
|
|
1393
|
+
| TransferCryptoCurrencyIn
|
|
1394
|
+
| TransferNftIn
|
|
1395
|
+
| TransferFiatCurrencyIn =>
|
|
1396
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1397
|
+
isTransferNftIn(transfer) ||
|
|
1398
|
+
isTransferFiatCurrencyIn(transfer),
|
|
1399
|
+
)
|
|
1400
|
+
if (transfers.length !== action.transfers.length) {
|
|
1401
|
+
throw new Error('Invalid action.transfers for income')
|
|
1402
|
+
}
|
|
1403
|
+
return {
|
|
1404
|
+
...action,
|
|
1405
|
+
type: 'NormalAccountAction',
|
|
1406
|
+
action: 'income',
|
|
1407
|
+
transfers,
|
|
1408
|
+
} satisfies AccountActionIncome
|
|
1409
|
+
}
|
|
1410
|
+
case 'mint-nft': {
|
|
1411
|
+
// transferNftInSchema,
|
|
1412
|
+
// transferFiatCurrencyOutSchema,
|
|
1413
|
+
// transferCryptoCurrencyOutSchema,
|
|
1414
|
+
const transfers = action.transfers.filter(
|
|
1415
|
+
(
|
|
1416
|
+
transfer,
|
|
1417
|
+
): transfer is
|
|
1418
|
+
| TransferNftIn
|
|
1419
|
+
| TransferFiatCurrencyOut
|
|
1420
|
+
| TransferCryptoCurrencyOut =>
|
|
1421
|
+
isTransferNftIn(transfer) ||
|
|
1422
|
+
isTransferFiatCurrencyOut(transfer) ||
|
|
1423
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
1424
|
+
)
|
|
1425
|
+
if (transfers.length !== action.transfers.length) {
|
|
1426
|
+
throw new Error('Invalid action.transfers for mint-nft')
|
|
1427
|
+
}
|
|
1428
|
+
return {
|
|
1429
|
+
...action,
|
|
1430
|
+
type: 'NormalAccountAction',
|
|
1431
|
+
action: 'mint-nft',
|
|
1432
|
+
transfers,
|
|
1433
|
+
} satisfies AccountActionMintNft
|
|
1434
|
+
}
|
|
1435
|
+
case 'move': {
|
|
1436
|
+
return {
|
|
1437
|
+
...action,
|
|
1438
|
+
type: 'NormalAccountAction',
|
|
1439
|
+
action: 'move',
|
|
1440
|
+
transfers: [...action.transfers],
|
|
1441
|
+
} satisfies AccountActionMove
|
|
1442
|
+
}
|
|
1443
|
+
case 'nft-royalty': {
|
|
1444
|
+
// transferCryptoCurrencyInSchema, transferFiatCurrencyInSchema
|
|
1445
|
+
const transfers = action.transfers.filter(
|
|
1446
|
+
(
|
|
1447
|
+
transfer,
|
|
1448
|
+
): transfer is TransferCryptoCurrencyIn | TransferFiatCurrencyIn =>
|
|
1449
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1450
|
+
isTransferFiatCurrencyIn(transfer),
|
|
1451
|
+
)
|
|
1452
|
+
if (transfers.length !== action.transfers.length) {
|
|
1453
|
+
throw new Error('Invalid action.transfers for nft-royalty')
|
|
1454
|
+
}
|
|
1455
|
+
return {
|
|
1456
|
+
...action,
|
|
1457
|
+
type: 'NormalAccountAction',
|
|
1458
|
+
action: 'nft-royalty',
|
|
1459
|
+
transfers,
|
|
1460
|
+
} satisfies AccountActionNftRoyalty
|
|
1461
|
+
}
|
|
1462
|
+
case 'receive-from-cex': {
|
|
1463
|
+
// transferCryptoCurrencyInSchema, transferNftInSchema
|
|
1464
|
+
const transfers = action.transfers.filter(
|
|
1465
|
+
(transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
|
|
1466
|
+
isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
|
|
1467
|
+
)
|
|
1468
|
+
if (transfers.length !== action.transfers.length) {
|
|
1469
|
+
throw new Error('Invalid action.transfers for receive-from-cex')
|
|
1470
|
+
}
|
|
1471
|
+
return {
|
|
1472
|
+
...action,
|
|
1473
|
+
type: 'NormalAccountAction',
|
|
1474
|
+
action: 'receive-from-cex',
|
|
1475
|
+
transfers,
|
|
1476
|
+
} satisfies AccountActionReceiveFromCex
|
|
1477
|
+
}
|
|
1478
|
+
case 'reduce': {
|
|
1479
|
+
// transferCryptoCurrencyOutSchema, transferNftOutSchema
|
|
1480
|
+
const transfers = action.transfers.filter(
|
|
1481
|
+
(transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
|
|
1482
|
+
isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
|
|
1483
|
+
)
|
|
1484
|
+
if (transfers.length !== action.transfers.length) {
|
|
1485
|
+
throw new Error('Invalid action.transfers for reduce')
|
|
1486
|
+
}
|
|
1487
|
+
return {
|
|
1488
|
+
...action,
|
|
1489
|
+
type: 'NormalAccountAction',
|
|
1490
|
+
action: 'reduce',
|
|
1491
|
+
transfers,
|
|
1492
|
+
} satisfies AccountActionReduce
|
|
1493
|
+
}
|
|
1494
|
+
case 'remove-liquidity': {
|
|
1495
|
+
// transferCryptoCurrencyInSchema,
|
|
1496
|
+
// transferNftInSchema,
|
|
1497
|
+
// transferCryptoCurrencyOutSchema,
|
|
1498
|
+
// transferNftOutSchema,
|
|
1499
|
+
const transfers = action.transfers.filter(
|
|
1500
|
+
(
|
|
1501
|
+
transfer,
|
|
1502
|
+
): transfer is
|
|
1503
|
+
| TransferCryptoCurrencyIn
|
|
1504
|
+
| TransferNftIn
|
|
1505
|
+
| TransferCryptoCurrencyOut
|
|
1506
|
+
| TransferNftOut =>
|
|
1507
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1508
|
+
isTransferNftIn(transfer) ||
|
|
1509
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1510
|
+
isTransferNftOut(transfer),
|
|
1511
|
+
)
|
|
1512
|
+
if (transfers.length !== action.transfers.length) {
|
|
1513
|
+
throw new Error('Invalid action.transfers for remove-liquidity')
|
|
1514
|
+
}
|
|
1515
|
+
if (action.loanId === undefined) {
|
|
1516
|
+
throw new Error('action.loandId is required for remove-liquidity')
|
|
1517
|
+
}
|
|
1518
|
+
return {
|
|
1519
|
+
...action,
|
|
1520
|
+
type: 'LoanAccountAction',
|
|
1521
|
+
action: 'remove-liquidity',
|
|
1522
|
+
loanId: action.loanId,
|
|
1523
|
+
transfers,
|
|
1524
|
+
} satisfies AccountActionRemoveLiquidity
|
|
1525
|
+
}
|
|
1526
|
+
case 'repayment': {
|
|
1527
|
+
// transferCryptoCurrencyOutSchema, transferNftOutSchema
|
|
1528
|
+
const transfers = action.transfers.filter(
|
|
1529
|
+
(transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
|
|
1530
|
+
isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
|
|
1531
|
+
)
|
|
1532
|
+
if (transfers.length !== action.transfers.length) {
|
|
1533
|
+
throw new Error('Invalid action.transfers for repayment')
|
|
1534
|
+
}
|
|
1535
|
+
if (action.loanId === undefined) {
|
|
1536
|
+
throw new Error('action.loandId is required for repayment')
|
|
1537
|
+
}
|
|
1538
|
+
return {
|
|
1539
|
+
...action,
|
|
1540
|
+
type: 'LoanAccountAction',
|
|
1541
|
+
action: 'repayment',
|
|
1542
|
+
loanId: action.loanId,
|
|
1543
|
+
transfers,
|
|
1544
|
+
} satisfies AccountActionRepayment
|
|
1545
|
+
}
|
|
1546
|
+
case 'repayment-with-debt': {
|
|
1547
|
+
// transferCryptoCurrencyInSchema,
|
|
1548
|
+
// transferNftInSchema,
|
|
1549
|
+
// transferCryptoCurrencyOutSchema,
|
|
1550
|
+
// transferNftOutSchema,
|
|
1551
|
+
const transfers = action.transfers.filter(
|
|
1552
|
+
(
|
|
1553
|
+
transfer,
|
|
1554
|
+
): transfer is
|
|
1555
|
+
| TransferCryptoCurrencyIn
|
|
1556
|
+
| TransferNftIn
|
|
1557
|
+
| TransferCryptoCurrencyOut
|
|
1558
|
+
| TransferNftOut =>
|
|
1559
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1560
|
+
isTransferNftIn(transfer) ||
|
|
1561
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1562
|
+
isTransferNftOut(transfer),
|
|
1563
|
+
)
|
|
1564
|
+
if (transfers.length !== action.transfers.length) {
|
|
1565
|
+
throw new Error('Invalid action.transfers for repayment-with-debt')
|
|
1566
|
+
}
|
|
1567
|
+
if (action.loanId === undefined) {
|
|
1568
|
+
throw new Error('action.loandId is required for repayment-with-debt')
|
|
1569
|
+
}
|
|
1570
|
+
return {
|
|
1571
|
+
...action,
|
|
1572
|
+
type: 'LoanAccountAction',
|
|
1573
|
+
action: 'repayment-with-debt',
|
|
1574
|
+
loanId: action.loanId,
|
|
1575
|
+
transfers,
|
|
1576
|
+
} satisfies AccountActionRepaymentWithDebt
|
|
1577
|
+
}
|
|
1578
|
+
case 'replace': {
|
|
1579
|
+
// transferCryptoCurrencyInSchema,
|
|
1580
|
+
// transferNftInSchema,
|
|
1581
|
+
// transferCryptoCurrencyOutSchema,
|
|
1582
|
+
// transferNftOutSchema,
|
|
1583
|
+
const transfers = action.transfers.filter(
|
|
1584
|
+
(
|
|
1585
|
+
transfer,
|
|
1586
|
+
): transfer is
|
|
1587
|
+
| TransferCryptoCurrencyIn
|
|
1588
|
+
| TransferNftIn
|
|
1589
|
+
| TransferCryptoCurrencyOut
|
|
1590
|
+
| TransferNftOut =>
|
|
1591
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1592
|
+
isTransferNftIn(transfer) ||
|
|
1593
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1594
|
+
isTransferNftOut(transfer),
|
|
1595
|
+
)
|
|
1596
|
+
if (transfers.length !== action.transfers.length) {
|
|
1597
|
+
throw new Error('Invalid action.transfers for replace')
|
|
1598
|
+
}
|
|
1599
|
+
return {
|
|
1600
|
+
...action,
|
|
1601
|
+
type: 'NormalAccountAction',
|
|
1602
|
+
action: 'replace',
|
|
1603
|
+
transfers,
|
|
1604
|
+
} satisfies AccountActionReplace
|
|
1605
|
+
}
|
|
1606
|
+
case 'revoke': {
|
|
1607
|
+
if (action.transfers.length > 0) {
|
|
1608
|
+
throw new Error('Invalid action.transfers for revoke')
|
|
1609
|
+
}
|
|
1610
|
+
return {
|
|
1611
|
+
...action,
|
|
1612
|
+
type: 'NormalAccountAction',
|
|
1613
|
+
action: 'revoke',
|
|
1614
|
+
transfers: [],
|
|
1615
|
+
} satisfies AccountActionRevoke
|
|
1616
|
+
}
|
|
1617
|
+
case 'sell-crypto': {
|
|
1618
|
+
// transferFiatCurrencyInSchema, transferCryptoCurrencyOutSchema
|
|
1619
|
+
const transfers = action.transfers.filter(
|
|
1620
|
+
(
|
|
1621
|
+
transfer,
|
|
1622
|
+
): transfer is TransferFiatCurrencyIn | TransferCryptoCurrencyOut =>
|
|
1623
|
+
isTransferFiatCurrencyIn(transfer) ||
|
|
1624
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
1625
|
+
)
|
|
1626
|
+
if (transfers.length !== action.transfers.length) {
|
|
1627
|
+
throw new Error('Invalid action.transfers for sell-crypto')
|
|
1628
|
+
}
|
|
1629
|
+
return {
|
|
1630
|
+
...action,
|
|
1631
|
+
type: 'NormalAccountAction',
|
|
1632
|
+
action: 'sell-crypto',
|
|
1633
|
+
transfers,
|
|
1634
|
+
} satisfies AccountActionSellCrypto
|
|
1635
|
+
}
|
|
1636
|
+
case 'sell-nft': {
|
|
1637
|
+
// transferFiatCurrencyInSchema,
|
|
1638
|
+
// transferCryptoCurrencyInSchema,
|
|
1639
|
+
// transferNftOutSchema,
|
|
1640
|
+
const transfers = action.transfers.filter(
|
|
1641
|
+
(
|
|
1642
|
+
transfer,
|
|
1643
|
+
): transfer is
|
|
1644
|
+
| TransferFiatCurrencyIn
|
|
1645
|
+
| TransferCryptoCurrencyIn
|
|
1646
|
+
| TransferNftOut =>
|
|
1647
|
+
isTransferFiatCurrencyIn(transfer) ||
|
|
1648
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1649
|
+
isTransferNftOut(transfer),
|
|
1650
|
+
)
|
|
1651
|
+
if (transfers.length !== action.transfers.length) {
|
|
1652
|
+
throw new Error('Invalid action.transfers for sell-nft')
|
|
1653
|
+
}
|
|
1654
|
+
return {
|
|
1655
|
+
...action,
|
|
1656
|
+
type: 'NormalAccountAction',
|
|
1657
|
+
action: 'sell-nft',
|
|
1658
|
+
transfers,
|
|
1659
|
+
} satisfies AccountActionSellNft
|
|
1660
|
+
}
|
|
1661
|
+
case 'send-to-cex': {
|
|
1662
|
+
// transferCryptoCurrencyOutSchema, transferNftOutSchema
|
|
1663
|
+
const transfers = action.transfers.filter(
|
|
1664
|
+
(transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
|
|
1665
|
+
isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
|
|
1666
|
+
)
|
|
1667
|
+
if (transfers.length !== action.transfers.length) {
|
|
1668
|
+
throw new Error('Invalid action.transfers for send-to-cex')
|
|
1669
|
+
}
|
|
1670
|
+
return {
|
|
1671
|
+
...action,
|
|
1672
|
+
type: 'NormalAccountAction',
|
|
1673
|
+
action: 'send-to-cex',
|
|
1674
|
+
transfers,
|
|
1675
|
+
} satisfies AccountActionSendToCex
|
|
1676
|
+
}
|
|
1677
|
+
case 'spam': {
|
|
1678
|
+
// transferCryptoCurrencyInSchema,
|
|
1679
|
+
// transferNftInSchema,
|
|
1680
|
+
// transferCryptoCurrencyOutSchema,
|
|
1681
|
+
// transferNftOutSchema,
|
|
1682
|
+
const transfers = action.transfers.filter(
|
|
1683
|
+
(
|
|
1684
|
+
transfer,
|
|
1685
|
+
): transfer is
|
|
1686
|
+
| TransferCryptoCurrencyIn
|
|
1687
|
+
| TransferNftIn
|
|
1688
|
+
| TransferCryptoCurrencyOut
|
|
1689
|
+
| TransferNftOut =>
|
|
1690
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1691
|
+
isTransferNftIn(transfer) ||
|
|
1692
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1693
|
+
isTransferNftOut(transfer),
|
|
1694
|
+
)
|
|
1695
|
+
if (transfers.length !== action.transfers.length) {
|
|
1696
|
+
throw new Error('Invalid action.transfers for spam')
|
|
1697
|
+
}
|
|
1698
|
+
return {
|
|
1699
|
+
...action,
|
|
1700
|
+
type: 'NormalAccountAction',
|
|
1701
|
+
action: 'spam',
|
|
1702
|
+
transfers,
|
|
1703
|
+
} satisfies AccountActionSpam
|
|
1704
|
+
}
|
|
1705
|
+
case 'stake': {
|
|
1706
|
+
// transferCryptoCurrencyOutSchema, transferNftOutSchema
|
|
1707
|
+
const transfers = action.transfers.filter(
|
|
1708
|
+
(transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
|
|
1709
|
+
isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
|
|
1710
|
+
)
|
|
1711
|
+
if (transfers.length !== action.transfers.length) {
|
|
1712
|
+
throw new Error('Invalid action.transfers for stake')
|
|
1713
|
+
}
|
|
1714
|
+
if (action.loanId === undefined) {
|
|
1715
|
+
throw new Error('action.loandId is required for stake')
|
|
1716
|
+
}
|
|
1717
|
+
return {
|
|
1718
|
+
...action,
|
|
1719
|
+
type: 'LoanAccountAction',
|
|
1720
|
+
action: 'stake',
|
|
1721
|
+
loanId: action.loanId,
|
|
1722
|
+
transfers,
|
|
1723
|
+
} satisfies AccountActionStake
|
|
1724
|
+
}
|
|
1725
|
+
case 'swap-income': {
|
|
1726
|
+
// transferCryptoCurrencyInSchema, transferNftInSchema
|
|
1727
|
+
const transfers = action.transfers.filter(
|
|
1728
|
+
(transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
|
|
1729
|
+
isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
|
|
1730
|
+
)
|
|
1731
|
+
if (transfers.length !== action.transfers.length) {
|
|
1732
|
+
throw new Error('Invalid action.transfers for swap-income')
|
|
1733
|
+
}
|
|
1734
|
+
return {
|
|
1735
|
+
...action,
|
|
1736
|
+
type: 'NormalAccountAction',
|
|
1737
|
+
action: 'swap-income',
|
|
1738
|
+
transfers,
|
|
1739
|
+
} satisfies AccountActionSwapIncome
|
|
1740
|
+
}
|
|
1741
|
+
case 'swap-nft': {
|
|
1742
|
+
// transferNftInSchema, transferNftOutSchema
|
|
1743
|
+
const transfers = action.transfers.filter(
|
|
1744
|
+
(transfer): transfer is TransferNftIn | TransferNftOut =>
|
|
1745
|
+
isTransferNftIn(transfer) || isTransferNftOut(transfer),
|
|
1746
|
+
)
|
|
1747
|
+
if (transfers.length !== action.transfers.length) {
|
|
1748
|
+
throw new Error('Invalid action.transfers for swap-nft')
|
|
1749
|
+
}
|
|
1750
|
+
return {
|
|
1751
|
+
...action,
|
|
1752
|
+
type: 'NormalAccountAction',
|
|
1753
|
+
action: 'swap-nft',
|
|
1754
|
+
transfers,
|
|
1755
|
+
} satisfies AccountActionSwapNft
|
|
1756
|
+
}
|
|
1757
|
+
case 'swap-transfer': {
|
|
1758
|
+
// transferCryptoCurrencyOutSchema, transferNftOutSchema
|
|
1759
|
+
const transfers = action.transfers.filter(
|
|
1760
|
+
(transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
|
|
1761
|
+
isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
|
|
1762
|
+
)
|
|
1763
|
+
if (transfers.length !== action.transfers.length) {
|
|
1764
|
+
throw new Error('Invalid action.transfers for swap-transfer')
|
|
1765
|
+
}
|
|
1766
|
+
return {
|
|
1767
|
+
...action,
|
|
1768
|
+
type: 'NormalAccountAction',
|
|
1769
|
+
action: 'swap-transfer',
|
|
1770
|
+
transfers,
|
|
1771
|
+
} satisfies AccountActionSwapTransfer
|
|
1772
|
+
}
|
|
1773
|
+
case 'trade': {
|
|
1774
|
+
// transferInSchema, transferOutSchema
|
|
1775
|
+
const transfers = action.transfers.filter(
|
|
1776
|
+
(
|
|
1777
|
+
transfer,
|
|
1778
|
+
): transfer is
|
|
1779
|
+
| TransferCryptoCurrencyIn
|
|
1780
|
+
| TransferNftIn
|
|
1781
|
+
| TransferFiatCurrencyIn
|
|
1782
|
+
| TransferCryptoCurrencyOut
|
|
1783
|
+
| TransferNftOut
|
|
1784
|
+
| TransferFiatCurrencyOut =>
|
|
1785
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1786
|
+
isTransferNftIn(transfer) ||
|
|
1787
|
+
isTransferFiatCurrencyIn(transfer) ||
|
|
1788
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1789
|
+
isTransferNftOut(transfer) ||
|
|
1790
|
+
isTransferFiatCurrencyOut(transfer),
|
|
1791
|
+
)
|
|
1792
|
+
if (transfers.length !== action.transfers.length) {
|
|
1793
|
+
throw new Error('Invalid action.transfers for trade')
|
|
1794
|
+
}
|
|
1795
|
+
return {
|
|
1796
|
+
...action,
|
|
1797
|
+
type: 'NormalAccountAction',
|
|
1798
|
+
action: 'trade',
|
|
1799
|
+
transfers,
|
|
1800
|
+
} satisfies AccountActionTrade
|
|
1801
|
+
}
|
|
1802
|
+
case 'transaction-fee': {
|
|
1803
|
+
// transferCryptoCurrencyOutSchema
|
|
1804
|
+
const transfers = action.transfers.filter(
|
|
1805
|
+
(transfer): transfer is TransferCryptoCurrencyOut =>
|
|
1806
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
1807
|
+
)
|
|
1808
|
+
if (transfers.length !== action.transfers.length) {
|
|
1809
|
+
throw new Error('Invalid action.transfers for transaction-fee')
|
|
1810
|
+
}
|
|
1811
|
+
return {
|
|
1812
|
+
...action,
|
|
1813
|
+
type: 'NormalAccountAction',
|
|
1814
|
+
action: 'transaction-fee',
|
|
1815
|
+
transfers,
|
|
1816
|
+
} satisfies AccountActionTransactionFee
|
|
1817
|
+
}
|
|
1818
|
+
case 'transfer': {
|
|
1819
|
+
// transferOutSchema
|
|
1820
|
+
const transfers = action.transfers.filter(
|
|
1821
|
+
(
|
|
1822
|
+
transfer,
|
|
1823
|
+
): transfer is
|
|
1824
|
+
| TransferCryptoCurrencyOut
|
|
1825
|
+
| TransferNftOut
|
|
1826
|
+
| TransferFiatCurrencyOut =>
|
|
1827
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1828
|
+
isTransferNftOut(transfer) ||
|
|
1829
|
+
isTransferFiatCurrencyOut(transfer),
|
|
1830
|
+
)
|
|
1831
|
+
if (transfers.length !== action.transfers.length) {
|
|
1832
|
+
throw new Error('Invalid action.transfers for transfer')
|
|
1833
|
+
}
|
|
1834
|
+
return {
|
|
1835
|
+
...action,
|
|
1836
|
+
type: 'NormalAccountAction',
|
|
1837
|
+
action: 'transfer',
|
|
1838
|
+
transfers,
|
|
1839
|
+
} satisfies AccountActionTransfer
|
|
1840
|
+
}
|
|
1841
|
+
case 'unstake': {
|
|
1842
|
+
// transferCryptoCurrencyInSchema, transferNftInSchema
|
|
1843
|
+
const transfers = action.transfers.filter(
|
|
1844
|
+
(transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
|
|
1845
|
+
isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
|
|
1846
|
+
)
|
|
1847
|
+
if (transfers.length !== action.transfers.length) {
|
|
1848
|
+
throw new Error('Invalid action.transfers for unstake')
|
|
1849
|
+
}
|
|
1850
|
+
if (action.loanId === undefined) {
|
|
1851
|
+
throw new Error('action.loandId is required for unstake')
|
|
1852
|
+
}
|
|
1853
|
+
return {
|
|
1854
|
+
...action,
|
|
1855
|
+
type: 'LoanAccountAction',
|
|
1856
|
+
action: 'unstake',
|
|
1857
|
+
loanId: action.loanId,
|
|
1858
|
+
transfers,
|
|
1859
|
+
} satisfies AccountActionUnstake
|
|
1860
|
+
}
|
|
1861
|
+
case 'unwrap': {
|
|
1862
|
+
// transferCryptoCurrencyInSchema,
|
|
1863
|
+
// transferCryptoCurrencyOutSchema,
|
|
1864
|
+
const transfers = action.transfers.filter(
|
|
1865
|
+
(
|
|
1866
|
+
transfer,
|
|
1867
|
+
): transfer is TransferCryptoCurrencyIn | TransferCryptoCurrencyOut =>
|
|
1868
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1869
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
1870
|
+
)
|
|
1871
|
+
if (transfers.length !== action.transfers.length) {
|
|
1872
|
+
throw new Error('Invalid action.transfers for unwrap')
|
|
1873
|
+
}
|
|
1874
|
+
return {
|
|
1875
|
+
...action,
|
|
1876
|
+
type: 'NormalAccountAction',
|
|
1877
|
+
action: 'unwrap',
|
|
1878
|
+
transfers,
|
|
1879
|
+
} satisfies AccountActionUnwrap
|
|
1880
|
+
}
|
|
1881
|
+
case 'valuedown': {
|
|
1882
|
+
// transferInSchema
|
|
1883
|
+
const transfers = action.transfers.filter(
|
|
1884
|
+
(
|
|
1885
|
+
transfer,
|
|
1886
|
+
): transfer is
|
|
1887
|
+
| TransferCryptoCurrencyIn
|
|
1888
|
+
| TransferNftIn
|
|
1889
|
+
| TransferFiatCurrencyIn =>
|
|
1890
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1891
|
+
isTransferNftIn(transfer) ||
|
|
1892
|
+
isTransferFiatCurrencyIn(transfer),
|
|
1893
|
+
)
|
|
1894
|
+
if (transfers.length !== action.transfers.length) {
|
|
1895
|
+
throw new Error('Invalid action.transfers for valuedown')
|
|
1896
|
+
}
|
|
1897
|
+
if (action.target === undefined) {
|
|
1898
|
+
throw new Error('action.target is required for valuedown')
|
|
1899
|
+
}
|
|
1900
|
+
return {
|
|
1901
|
+
...action,
|
|
1902
|
+
type: 'NormalAccountAction',
|
|
1903
|
+
action: 'valuedown',
|
|
1904
|
+
target: action.target,
|
|
1905
|
+
transfers,
|
|
1906
|
+
} satisfies AccountActionValuedown
|
|
1907
|
+
}
|
|
1908
|
+
case 'valueup': {
|
|
1909
|
+
// transferOutSchema
|
|
1910
|
+
const transfers = action.transfers.filter(
|
|
1911
|
+
(
|
|
1912
|
+
transfer,
|
|
1913
|
+
): transfer is
|
|
1914
|
+
| TransferCryptoCurrencyOut
|
|
1915
|
+
| TransferNftOut
|
|
1916
|
+
| TransferFiatCurrencyOut =>
|
|
1917
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1918
|
+
isTransferNftOut(transfer) ||
|
|
1919
|
+
isTransferFiatCurrencyOut(transfer),
|
|
1920
|
+
)
|
|
1921
|
+
if (transfers.length !== action.transfers.length) {
|
|
1922
|
+
throw new Error('Invalid action.transfers for valueup')
|
|
1923
|
+
}
|
|
1924
|
+
if (action.target === undefined) {
|
|
1925
|
+
throw new Error('action.target is required for valueup')
|
|
1926
|
+
}
|
|
1927
|
+
return {
|
|
1928
|
+
...action,
|
|
1929
|
+
type: 'NormalAccountAction',
|
|
1930
|
+
action: 'valueup',
|
|
1931
|
+
target: action.target,
|
|
1932
|
+
transfers,
|
|
1933
|
+
} satisfies AccountActionValueup
|
|
1934
|
+
}
|
|
1935
|
+
case 'withdraw': {
|
|
1936
|
+
// transferCryptoCurrencyInSchema, transferNftInSchema
|
|
1937
|
+
const transfers = action.transfers.filter(
|
|
1938
|
+
(transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
|
|
1939
|
+
isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
|
|
1940
|
+
)
|
|
1941
|
+
if (transfers.length !== action.transfers.length) {
|
|
1942
|
+
throw new Error('Invalid action.transfers for withdraw')
|
|
1943
|
+
}
|
|
1944
|
+
if (action.loanId === undefined) {
|
|
1945
|
+
throw new Error('action.loandId is required for withdraw')
|
|
1946
|
+
}
|
|
1947
|
+
return {
|
|
1948
|
+
...action,
|
|
1949
|
+
type: 'LoanAccountAction',
|
|
1950
|
+
action: 'withdraw',
|
|
1951
|
+
loanId: action.loanId,
|
|
1952
|
+
transfers,
|
|
1953
|
+
} satisfies AccountActionWithdraw
|
|
1954
|
+
}
|
|
1955
|
+
case 'withdraw-with-bond': {
|
|
1956
|
+
// transferCryptoCurrencyInSchema,
|
|
1957
|
+
// transferNftInSchema,
|
|
1958
|
+
// transferCryptoCurrencyOutSchema,
|
|
1959
|
+
// transferNftOutSchema,
|
|
1960
|
+
const transfers = action.transfers.filter(
|
|
1961
|
+
(
|
|
1962
|
+
transfer,
|
|
1963
|
+
): transfer is
|
|
1964
|
+
| TransferCryptoCurrencyIn
|
|
1965
|
+
| TransferNftIn
|
|
1966
|
+
| TransferCryptoCurrencyOut
|
|
1967
|
+
| TransferNftOut =>
|
|
1968
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1969
|
+
isTransferNftIn(transfer) ||
|
|
1970
|
+
isTransferCryptoCurrencyOut(transfer) ||
|
|
1971
|
+
isTransferNftOut(transfer),
|
|
1972
|
+
)
|
|
1973
|
+
if (transfers.length !== action.transfers.length) {
|
|
1974
|
+
throw new Error('Invalid action.transfers for withdraw-with-bond')
|
|
1975
|
+
}
|
|
1976
|
+
if (action.loanId === undefined) {
|
|
1977
|
+
throw new Error('action.loandId is required for withdraw-with-bond')
|
|
1978
|
+
}
|
|
1979
|
+
return {
|
|
1980
|
+
...action,
|
|
1981
|
+
type: 'LoanAccountAction',
|
|
1982
|
+
action: 'withdraw-with-bond',
|
|
1983
|
+
loanId: action.loanId,
|
|
1984
|
+
transfers,
|
|
1985
|
+
} satisfies AccountActionWithdrawWithBond
|
|
1986
|
+
}
|
|
1987
|
+
case 'wrap': {
|
|
1988
|
+
// transferCryptoCurrencyInSchema,
|
|
1989
|
+
// transferCryptoCurrencyOutSchema,
|
|
1990
|
+
const transfers = action.transfers.filter(
|
|
1991
|
+
(
|
|
1992
|
+
transfer,
|
|
1993
|
+
): transfer is TransferCryptoCurrencyIn | TransferCryptoCurrencyOut =>
|
|
1994
|
+
isTransferCryptoCurrencyIn(transfer) ||
|
|
1995
|
+
isTransferCryptoCurrencyOut(transfer),
|
|
1996
|
+
)
|
|
1997
|
+
if (transfers.length !== action.transfers.length) {
|
|
1998
|
+
throw new Error('Invalid action.transfers for wrap')
|
|
1999
|
+
}
|
|
2000
|
+
return {
|
|
2001
|
+
...action,
|
|
2002
|
+
type: 'NormalAccountAction',
|
|
2003
|
+
action: 'wrap',
|
|
2004
|
+
transfers,
|
|
2005
|
+
} satisfies AccountActionWrap
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
}
|