@0xtorch/evm 0.0.12 → 0.0.14

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.
@@ -1,60 +1,9 @@
1
1
  import type {
2
+ BaseNormalAction,
2
3
  CryptoCurrencyPrice,
3
4
  NormalAction,
4
- NormalActionAddLiquidity,
5
- NormalActionApprove,
6
- NormalActionAtomicArbitrage,
7
- NormalActionBorrow,
8
- NormalActionBorrowWithDebt,
9
- NormalActionBridgeFrom,
10
- NormalActionBridgeTo,
11
- NormalActionBuyCrypto,
12
- NormalActionBuyNft,
13
- NormalActionCrossReplace,
14
- NormalActionCrossTrade,
15
- NormalActionDeposit,
16
- NormalActionDepositWithBond,
17
- NormalActionFailTx,
18
- NormalActionFee,
19
- NormalActionFreeMintNft,
20
- NormalActionIncome,
21
- NormalActionMintNft,
22
- NormalActionReceiveFromCex,
23
- NormalActionRemoveLiquidity,
24
- NormalActionRepayment,
25
- NormalActionRepaymentWithDebt,
26
- NormalActionReplace,
27
- NormalActionRevoke,
28
- NormalActionSellCrypto,
29
- NormalActionSellNft,
30
- NormalActionSendToCex,
31
- NormalActionSpam,
32
- NormalActionStake,
33
- NormalActionSwapNft,
34
- NormalActionTrade,
35
- NormalActionTransactionFee,
36
- NormalActionTransfer,
37
- NormalActionUnstake,
38
- NormalActionUnwrap,
39
- NormalActionWithdraw,
40
- NormalActionWithdrawWithBond,
41
- NormalActionWrap,
42
- Transfer,
43
- TransferCryptoCurrencyIn,
44
- TransferCryptoCurrencyOut,
45
- TransferFiatCurrencyIn,
46
- TransferFiatCurrencyOut,
47
- TransferNftIn,
48
- TransferNftOut,
49
- } from '@0xtorch/core'
50
- import {
51
- isTransferCryptoCurrencyIn,
52
- isTransferCryptoCurrencyOut,
53
- isTransferFiatCurrencyIn,
54
- isTransferFiatCurrencyOut,
55
- isTransferNftIn,
56
- isTransferNftOut,
57
5
  } from '@0xtorch/core'
6
+ import { parseBaseNormalActionToNormalAction } from '@0xtorch/core'
58
7
  import type { Chain } from '../../chains'
59
8
  import type {
60
9
  Erc1155Transfer,
@@ -254,12 +203,6 @@ type GenerateActionsByGeneratorWithTargetsParameters<
254
203
  Price extends CryptoCurrencyPrice | undefined,
255
204
  > = GenerateActionsByGeneratorParameters<Price> & Target<Price>
256
205
 
257
- type BaseAction = Omit<NormalAction, 'transfers' | 'crossId' | 'loanId'> & {
258
- readonly transfers: readonly Transfer[]
259
- readonly crossId: string | undefined
260
- readonly loanId: string | undefined
261
- }
262
-
263
206
  const generateActionByGeneratorWithTargets = <
264
207
  Price extends CryptoCurrencyPrice | undefined,
265
208
  >({
@@ -273,8 +216,7 @@ const generateActionByGeneratorWithTargets = <
273
216
  targetsLog,
274
217
  }: GenerateActionsByGeneratorWithTargetsParameters<Price>): NormalAction => {
275
218
  // generator に基づいて action 生成
276
- const action: BaseAction = {
277
- type: 'NormalAction',
219
+ const action: BaseNormalAction = {
278
220
  action: generator.action,
279
221
  evidence: 'contract',
280
222
  timestamp: Number(transaction.block.timestamp) * 1000,
@@ -317,6 +259,7 @@ const generateActionByGeneratorWithTargets = <
317
259
  }),
318
260
  )
319
261
  .join(''),
262
+ crossType: generator.crossType,
320
263
  loanId:
321
264
  generator.loanId === undefined
322
265
  ? undefined
@@ -330,837 +273,9 @@ const generateActionByGeneratorWithTargets = <
330
273
  }),
331
274
  )
332
275
  .join(''),
276
+ // TODO target を生成できるようにする
277
+ target: undefined,
333
278
  }
334
279
 
335
- switch (action.action) {
336
- case 'add-liquidity': {
337
- const transfers = action.transfers.filter(
338
- (
339
- transfer,
340
- ): transfer is
341
- | TransferCryptoCurrencyIn
342
- | TransferNftIn
343
- | TransferCryptoCurrencyOut
344
- | TransferNftOut =>
345
- isTransferCryptoCurrencyIn(transfer) ||
346
- isTransferNftIn(transfer) ||
347
- isTransferCryptoCurrencyOut(transfer) ||
348
- isTransferNftOut(transfer),
349
- )
350
- if (transfers.length !== action.transfers.length) {
351
- throw new Error('Invalid action.transfers for add-liquidity')
352
- }
353
- if (action.loanId === undefined) {
354
- throw new Error('action.loandId is required for add-liquidity')
355
- }
356
- return {
357
- ...action,
358
- type: 'LoanNormalAction',
359
- action: 'add-liquidity',
360
- loanId: action.loanId,
361
- transfers,
362
- } satisfies NormalActionAddLiquidity
363
- }
364
- case 'approve': {
365
- if (action.transfers.length > 0) {
366
- throw new Error('Invalid action.transfers for approve')
367
- }
368
- return {
369
- ...action,
370
- type: 'NormalAction',
371
- action: 'approve',
372
- transfers: [],
373
- } satisfies NormalActionApprove
374
- }
375
- case 'atomic-arbitrage': {
376
- const transfers = action.transfers.filter(
377
- (
378
- transfer,
379
- ): transfer is TransferCryptoCurrencyIn | TransferCryptoCurrencyOut =>
380
- isTransferCryptoCurrencyIn(transfer) ||
381
- isTransferCryptoCurrencyOut(transfer),
382
- )
383
- if (transfers.length !== action.transfers.length) {
384
- throw new Error('Invalid action.transfers for atomic-arbitrage')
385
- }
386
- return {
387
- ...action,
388
- type: 'NormalAction',
389
- action: 'atomic-arbitrage',
390
- transfers,
391
- } satisfies NormalActionAtomicArbitrage
392
- }
393
- case 'borrow': {
394
- const transfers = action.transfers.filter(
395
- (transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
396
- isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
397
- )
398
- if (transfers.length !== action.transfers.length) {
399
- throw new Error('Invalid action.transfers for borrow')
400
- }
401
- if (action.loanId === undefined) {
402
- throw new Error('action.loandId is required for borrow')
403
- }
404
- return {
405
- ...action,
406
- type: 'LoanNormalAction',
407
- action: 'borrow',
408
- loanId: action.loanId,
409
- transfers,
410
- } satisfies NormalActionBorrow
411
- }
412
- case 'borrow-with-debt': {
413
- const transfers = action.transfers.filter(
414
- (
415
- transfer,
416
- ): transfer is
417
- | TransferCryptoCurrencyIn
418
- | TransferNftIn
419
- | TransferCryptoCurrencyOut
420
- | TransferNftOut =>
421
- isTransferCryptoCurrencyIn(transfer) ||
422
- isTransferNftIn(transfer) ||
423
- isTransferCryptoCurrencyOut(transfer) ||
424
- isTransferNftOut(transfer),
425
- )
426
- if (transfers.length !== action.transfers.length) {
427
- throw new Error('Invalid action.transfers for borrow-with-debt')
428
- }
429
- if (action.loanId === undefined) {
430
- throw new Error('action.loandId is required for borrow-with-debt')
431
- }
432
- return {
433
- ...action,
434
- type: 'LoanNormalAction',
435
- action: 'borrow-with-debt',
436
- loanId: action.loanId,
437
- transfers,
438
- } satisfies NormalActionBorrowWithDebt
439
- }
440
- case 'bridge-from': {
441
- const transfers = action.transfers.filter(
442
- (transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
443
- isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
444
- )
445
- if (transfers.length !== action.transfers.length) {
446
- throw new Error('Invalid action.transfers for bridge-from')
447
- }
448
- if (action.crossId === undefined) {
449
- throw new Error('action.crossId is required for bridge-from')
450
- }
451
- return {
452
- ...action,
453
- type: 'CrossNormalAction',
454
- action: 'bridge-from',
455
- crossId: action.crossId,
456
- transfers,
457
- } satisfies NormalActionBridgeFrom
458
- }
459
- case 'bridge-to': {
460
- const transfers = action.transfers.filter(
461
- (transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
462
- isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
463
- )
464
- if (transfers.length !== action.transfers.length) {
465
- throw new Error('Invalid action.transfers for bridge-to')
466
- }
467
- if (action.crossId === undefined) {
468
- throw new Error('action.crossId is required for bridge-to')
469
- }
470
- return {
471
- ...action,
472
- type: 'CrossNormalAction',
473
- action: 'bridge-to',
474
- crossId: action.crossId,
475
- transfers,
476
- } satisfies NormalActionBridgeTo
477
- }
478
- case 'buy-crypto': {
479
- const transfers = action.transfers.filter(
480
- (
481
- transfer,
482
- ): transfer is TransferCryptoCurrencyIn | TransferFiatCurrencyOut =>
483
- isTransferCryptoCurrencyIn(transfer) ||
484
- isTransferFiatCurrencyOut(transfer),
485
- )
486
- if (transfers.length !== action.transfers.length) {
487
- throw new Error('Invalid action.transfers for buy-crypto')
488
- }
489
- return {
490
- ...action,
491
- type: 'NormalAction',
492
- action: 'buy-crypto',
493
- transfers,
494
- } satisfies NormalActionBuyCrypto
495
- }
496
- case 'buy-nft': {
497
- const transfers = action.transfers.filter(
498
- (
499
- transfer,
500
- ): transfer is
501
- | TransferNftIn
502
- | TransferFiatCurrencyOut
503
- | TransferCryptoCurrencyOut =>
504
- isTransferNftIn(transfer) ||
505
- isTransferFiatCurrencyOut(transfer) ||
506
- isTransferCryptoCurrencyOut(transfer),
507
- )
508
- if (transfers.length !== action.transfers.length) {
509
- throw new Error('Invalid action.transfers for buy-nft')
510
- }
511
- return {
512
- ...action,
513
- type: 'NormalAction',
514
- action: 'buy-nft',
515
- transfers,
516
- } satisfies NormalActionBuyNft
517
- }
518
- case 'cross-replace': {
519
- // transferInSchema, transferOutSchema
520
- const transfers = action.transfers.filter(
521
- (
522
- transfer,
523
- ): transfer is
524
- | TransferCryptoCurrencyIn
525
- | TransferNftIn
526
- | TransferFiatCurrencyIn
527
- | TransferCryptoCurrencyOut
528
- | TransferNftOut
529
- | TransferFiatCurrencyOut =>
530
- isTransferCryptoCurrencyIn(transfer) ||
531
- isTransferNftIn(transfer) ||
532
- isTransferFiatCurrencyIn(transfer) ||
533
- isTransferCryptoCurrencyOut(transfer) ||
534
- isTransferNftOut(transfer) ||
535
- isTransferFiatCurrencyOut(transfer),
536
- )
537
- if (transfers.length !== action.transfers.length) {
538
- throw new Error('Invalid action.transfers for cross-replace')
539
- }
540
- if (action.crossId === undefined) {
541
- throw new Error('action.crossId is required for cross-replace')
542
- }
543
- return {
544
- ...action,
545
- type: 'CrossNormalAction',
546
- action: 'cross-replace',
547
- crossId: action.crossId,
548
- transfers,
549
- } satisfies NormalActionCrossReplace
550
- }
551
- case 'deposit': {
552
- // transferCryptoCurrencyOutSchema, transferNftOutSchema
553
- const transfers = action.transfers.filter(
554
- (transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
555
- isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
556
- )
557
- if (transfers.length !== action.transfers.length) {
558
- throw new Error('Invalid action.transfers for deposit')
559
- }
560
- if (action.loanId === undefined) {
561
- throw new Error('action.loandId is required for deposit')
562
- }
563
- return {
564
- ...action,
565
- type: 'LoanNormalAction',
566
- action: 'deposit',
567
- loanId: action.loanId,
568
- transfers,
569
- } satisfies NormalActionDeposit
570
- }
571
- case 'cross-trade': {
572
- // transferInSchema, transferOutSchema
573
- const transfers = action.transfers.filter(
574
- (
575
- transfer,
576
- ): transfer is
577
- | TransferCryptoCurrencyIn
578
- | TransferNftIn
579
- | TransferFiatCurrencyIn
580
- | TransferCryptoCurrencyOut
581
- | TransferNftOut
582
- | TransferFiatCurrencyOut =>
583
- isTransferCryptoCurrencyIn(transfer) ||
584
- isTransferNftIn(transfer) ||
585
- isTransferFiatCurrencyIn(transfer) ||
586
- isTransferCryptoCurrencyOut(transfer) ||
587
- isTransferNftOut(transfer) ||
588
- isTransferFiatCurrencyOut(transfer),
589
- )
590
- if (transfers.length !== action.transfers.length) {
591
- throw new Error('Invalid action.transfers for cross-trade')
592
- }
593
- if (action.crossId === undefined) {
594
- throw new Error('action.crossId is required for cross-trade')
595
- }
596
- return {
597
- ...action,
598
- type: 'CrossNormalAction',
599
- action: 'cross-trade',
600
- crossId: action.crossId,
601
- transfers,
602
- } satisfies NormalActionCrossTrade
603
- }
604
- case 'deposit-with-bond': {
605
- // transferCryptoCurrencyInSchema,
606
- // transferNftInSchema,
607
- // transferCryptoCurrencyOutSchema,
608
- // transferNftOutSchema,
609
- const transfers = action.transfers.filter(
610
- (
611
- transfer,
612
- ): transfer is
613
- | TransferCryptoCurrencyIn
614
- | TransferNftIn
615
- | TransferCryptoCurrencyOut
616
- | TransferNftOut =>
617
- isTransferCryptoCurrencyIn(transfer) ||
618
- isTransferNftIn(transfer) ||
619
- isTransferCryptoCurrencyOut(transfer) ||
620
- isTransferNftOut(transfer),
621
- )
622
- if (transfers.length !== action.transfers.length) {
623
- throw new Error('Invalid action.transfers for deposit-with-bond')
624
- }
625
- if (action.loanId === undefined) {
626
- throw new Error('action.loandId is required for deposit-with-bond')
627
- }
628
- return {
629
- ...action,
630
- type: 'LoanNormalAction',
631
- action: 'deposit-with-bond',
632
- loanId: action.loanId,
633
- transfers,
634
- } satisfies NormalActionDepositWithBond
635
- }
636
- case 'fail-tx': {
637
- if (action.transfers.length > 0) {
638
- throw new Error('Invalid action.transfers for fail-tx')
639
- }
640
- return {
641
- ...action,
642
- type: 'NormalAction',
643
- action: 'fail-tx',
644
- transfers: [],
645
- } satisfies NormalActionFailTx
646
- }
647
- case 'fee': {
648
- // transferCryptoCurrencyOutSchema, transferFiatCurrencyOutSchema
649
- const transfers = action.transfers.filter(
650
- (
651
- transfer,
652
- ): transfer is TransferCryptoCurrencyOut | TransferFiatCurrencyOut =>
653
- isTransferCryptoCurrencyOut(transfer) ||
654
- isTransferFiatCurrencyOut(transfer),
655
- )
656
- if (transfers.length !== action.transfers.length) {
657
- throw new Error('Invalid action.transfers for fee')
658
- }
659
- return {
660
- ...action,
661
- type: 'NormalAction',
662
- action: 'fee',
663
- transfers,
664
- } satisfies NormalActionFee
665
- }
666
- case 'free-mint-nft': {
667
- // transferNftInSchema
668
- const transfers = action.transfers.filter(
669
- (transfer): transfer is TransferNftIn => isTransferNftIn(transfer),
670
- )
671
- if (transfers.length !== action.transfers.length) {
672
- throw new Error('Invalid action.transfers for free-mint-nft')
673
- }
674
- return {
675
- ...action,
676
- type: 'NormalAction',
677
- action: 'free-mint-nft',
678
- transfers,
679
- } satisfies NormalActionFreeMintNft
680
- }
681
- case 'income': {
682
- // transferInSchema
683
- const transfers = action.transfers.filter(
684
- (
685
- transfer,
686
- ): transfer is
687
- | TransferCryptoCurrencyIn
688
- | TransferNftIn
689
- | TransferFiatCurrencyIn =>
690
- isTransferCryptoCurrencyIn(transfer) ||
691
- isTransferNftIn(transfer) ||
692
- isTransferFiatCurrencyIn(transfer),
693
- )
694
- if (transfers.length !== action.transfers.length) {
695
- throw new Error('Invalid action.transfers for income')
696
- }
697
- return {
698
- ...action,
699
- type: 'NormalAction',
700
- action: 'income',
701
- transfers,
702
- } satisfies NormalActionIncome
703
- }
704
- case 'mint-nft': {
705
- // transferNftInSchema,
706
- // transferFiatCurrencyOutSchema,
707
- // transferCryptoCurrencyOutSchema,
708
- const transfers = action.transfers.filter(
709
- (
710
- transfer,
711
- ): transfer is
712
- | TransferNftIn
713
- | TransferFiatCurrencyOut
714
- | TransferCryptoCurrencyOut =>
715
- isTransferNftIn(transfer) ||
716
- isTransferFiatCurrencyOut(transfer) ||
717
- isTransferCryptoCurrencyOut(transfer),
718
- )
719
- if (transfers.length !== action.transfers.length) {
720
- throw new Error('Invalid action.transfers for mint-nft')
721
- }
722
- return {
723
- ...action,
724
- type: 'NormalAction',
725
- action: 'mint-nft',
726
- transfers,
727
- } satisfies NormalActionMintNft
728
- }
729
- case 'receive-from-cex': {
730
- // transferCryptoCurrencyInSchema, transferNftInSchema
731
- const transfers = action.transfers.filter(
732
- (transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
733
- isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
734
- )
735
- if (transfers.length !== action.transfers.length) {
736
- throw new Error('Invalid action.transfers for receive-from-cex')
737
- }
738
- return {
739
- ...action,
740
- type: 'NormalAction',
741
- action: 'receive-from-cex',
742
- transfers,
743
- } satisfies NormalActionReceiveFromCex
744
- }
745
- case 'remove-liquidity': {
746
- // transferCryptoCurrencyInSchema,
747
- // transferNftInSchema,
748
- // transferCryptoCurrencyOutSchema,
749
- // transferNftOutSchema,
750
- const transfers = action.transfers.filter(
751
- (
752
- transfer,
753
- ): transfer is
754
- | TransferCryptoCurrencyIn
755
- | TransferNftIn
756
- | TransferCryptoCurrencyOut
757
- | TransferNftOut =>
758
- isTransferCryptoCurrencyIn(transfer) ||
759
- isTransferNftIn(transfer) ||
760
- isTransferCryptoCurrencyOut(transfer) ||
761
- isTransferNftOut(transfer),
762
- )
763
- if (transfers.length !== action.transfers.length) {
764
- throw new Error('Invalid action.transfers for remove-liquidity')
765
- }
766
- if (action.loanId === undefined) {
767
- throw new Error('action.loandId is required for remove-liquidity')
768
- }
769
- return {
770
- ...action,
771
- type: 'LoanNormalAction',
772
- action: 'remove-liquidity',
773
- loanId: action.loanId,
774
- transfers,
775
- } satisfies NormalActionRemoveLiquidity
776
- }
777
- case 'repayment': {
778
- // transferCryptoCurrencyOutSchema, transferNftOutSchema
779
- const transfers = action.transfers.filter(
780
- (transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
781
- isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
782
- )
783
- if (transfers.length !== action.transfers.length) {
784
- throw new Error('Invalid action.transfers for repayment')
785
- }
786
- if (action.loanId === undefined) {
787
- throw new Error('action.loandId is required for repayment')
788
- }
789
- return {
790
- ...action,
791
- type: 'LoanNormalAction',
792
- action: 'repayment',
793
- loanId: action.loanId,
794
- transfers,
795
- } satisfies NormalActionRepayment
796
- }
797
- case 'repayment-with-debt': {
798
- // transferCryptoCurrencyInSchema,
799
- // transferNftInSchema,
800
- // transferCryptoCurrencyOutSchema,
801
- // transferNftOutSchema,
802
- const transfers = action.transfers.filter(
803
- (
804
- transfer,
805
- ): transfer is
806
- | TransferCryptoCurrencyIn
807
- | TransferNftIn
808
- | TransferCryptoCurrencyOut
809
- | TransferNftOut =>
810
- isTransferCryptoCurrencyIn(transfer) ||
811
- isTransferNftIn(transfer) ||
812
- isTransferCryptoCurrencyOut(transfer) ||
813
- isTransferNftOut(transfer),
814
- )
815
- if (transfers.length !== action.transfers.length) {
816
- throw new Error('Invalid action.transfers for repayment-with-debt')
817
- }
818
- if (action.loanId === undefined) {
819
- throw new Error('action.loandId is required for repayment-with-debt')
820
- }
821
- return {
822
- ...action,
823
- type: 'LoanNormalAction',
824
- action: 'repayment-with-debt',
825
- loanId: action.loanId,
826
- transfers,
827
- } satisfies NormalActionRepaymentWithDebt
828
- }
829
- case 'replace': {
830
- // transferCryptoCurrencyInSchema,
831
- // transferNftInSchema,
832
- // transferCryptoCurrencyOutSchema,
833
- // transferNftOutSchema,
834
- const transfers = action.transfers.filter(
835
- (
836
- transfer,
837
- ): transfer is
838
- | TransferCryptoCurrencyIn
839
- | TransferNftIn
840
- | TransferCryptoCurrencyOut
841
- | TransferNftOut =>
842
- isTransferCryptoCurrencyIn(transfer) ||
843
- isTransferNftIn(transfer) ||
844
- isTransferCryptoCurrencyOut(transfer) ||
845
- isTransferNftOut(transfer),
846
- )
847
- if (transfers.length !== action.transfers.length) {
848
- throw new Error('Invalid action.transfers for replace')
849
- }
850
- return {
851
- ...action,
852
- type: 'NormalAction',
853
- action: 'replace',
854
- transfers,
855
- } satisfies NormalActionReplace
856
- }
857
- case 'revoke': {
858
- if (action.transfers.length > 0) {
859
- throw new Error('Invalid action.transfers for revoke')
860
- }
861
- return {
862
- ...action,
863
- type: 'NormalAction',
864
- action: 'revoke',
865
- transfers: [],
866
- } satisfies NormalActionRevoke
867
- }
868
- case 'sell-crypto': {
869
- // transferFiatCurrencyInSchema, transferCryptoCurrencyOutSchema
870
- const transfers = action.transfers.filter(
871
- (
872
- transfer,
873
- ): transfer is TransferFiatCurrencyIn | TransferCryptoCurrencyOut =>
874
- isTransferFiatCurrencyIn(transfer) ||
875
- isTransferCryptoCurrencyOut(transfer),
876
- )
877
- if (transfers.length !== action.transfers.length) {
878
- throw new Error('Invalid action.transfers for sell-crypto')
879
- }
880
- return {
881
- ...action,
882
- type: 'NormalAction',
883
- action: 'sell-crypto',
884
- transfers,
885
- } satisfies NormalActionSellCrypto
886
- }
887
- case 'sell-nft': {
888
- // transferFiatCurrencyInSchema,
889
- // transferCryptoCurrencyInSchema,
890
- // transferNftOutSchema,
891
- const transfers = action.transfers.filter(
892
- (
893
- transfer,
894
- ): transfer is
895
- | TransferFiatCurrencyIn
896
- | TransferCryptoCurrencyIn
897
- | TransferNftOut =>
898
- isTransferFiatCurrencyIn(transfer) ||
899
- isTransferCryptoCurrencyIn(transfer) ||
900
- isTransferNftOut(transfer),
901
- )
902
- if (transfers.length !== action.transfers.length) {
903
- throw new Error('Invalid action.transfers for sell-nft')
904
- }
905
- return {
906
- ...action,
907
- type: 'NormalAction',
908
- action: 'sell-nft',
909
- transfers,
910
- } satisfies NormalActionSellNft
911
- }
912
- case 'send-to-cex': {
913
- // transferCryptoCurrencyOutSchema, transferNftOutSchema
914
- const transfers = action.transfers.filter(
915
- (transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
916
- isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
917
- )
918
- if (transfers.length !== action.transfers.length) {
919
- throw new Error('Invalid action.transfers for send-to-cex')
920
- }
921
- return {
922
- ...action,
923
- type: 'NormalAction',
924
- action: 'send-to-cex',
925
- transfers,
926
- } satisfies NormalActionSendToCex
927
- }
928
- case 'spam': {
929
- // transferCryptoCurrencyInSchema,
930
- // transferNftInSchema,
931
- // transferCryptoCurrencyOutSchema,
932
- // transferNftOutSchema,
933
- const transfers = action.transfers.filter(
934
- (
935
- transfer,
936
- ): transfer is
937
- | TransferCryptoCurrencyIn
938
- | TransferNftIn
939
- | TransferCryptoCurrencyOut
940
- | TransferNftOut =>
941
- isTransferCryptoCurrencyIn(transfer) ||
942
- isTransferNftIn(transfer) ||
943
- isTransferCryptoCurrencyOut(transfer) ||
944
- isTransferNftOut(transfer),
945
- )
946
- if (transfers.length !== action.transfers.length) {
947
- throw new Error('Invalid action.transfers for spam')
948
- }
949
- return {
950
- ...action,
951
- type: 'NormalAction',
952
- action: 'spam',
953
- transfers,
954
- } satisfies NormalActionSpam
955
- }
956
- case 'stake': {
957
- // transferCryptoCurrencyOutSchema, transferNftOutSchema
958
- const transfers = action.transfers.filter(
959
- (transfer): transfer is TransferCryptoCurrencyOut | TransferNftOut =>
960
- isTransferCryptoCurrencyOut(transfer) || isTransferNftOut(transfer),
961
- )
962
- if (transfers.length !== action.transfers.length) {
963
- throw new Error('Invalid action.transfers for stake')
964
- }
965
- if (action.loanId === undefined) {
966
- throw new Error('action.loandId is required for stake')
967
- }
968
- return {
969
- ...action,
970
- type: 'LoanNormalAction',
971
- action: 'stake',
972
- loanId: action.loanId,
973
- transfers,
974
- } satisfies NormalActionStake
975
- }
976
- case 'swap-nft': {
977
- // transferNftInSchema, transferNftOutSchema
978
- const transfers = action.transfers.filter(
979
- (transfer): transfer is TransferNftIn | TransferNftOut =>
980
- isTransferNftIn(transfer) || isTransferNftOut(transfer),
981
- )
982
- if (transfers.length !== action.transfers.length) {
983
- throw new Error('Invalid action.transfers for swap-nft')
984
- }
985
- return {
986
- ...action,
987
- type: 'NormalAction',
988
- action: 'swap-nft',
989
- transfers,
990
- } satisfies NormalActionSwapNft
991
- }
992
- case 'trade': {
993
- // transferInSchema, transferOutSchema
994
- const transfers = action.transfers.filter(
995
- (
996
- transfer,
997
- ): transfer is
998
- | TransferCryptoCurrencyIn
999
- | TransferNftIn
1000
- | TransferFiatCurrencyIn
1001
- | TransferCryptoCurrencyOut
1002
- | TransferNftOut
1003
- | TransferFiatCurrencyOut =>
1004
- isTransferCryptoCurrencyIn(transfer) ||
1005
- isTransferNftIn(transfer) ||
1006
- isTransferFiatCurrencyIn(transfer) ||
1007
- isTransferCryptoCurrencyOut(transfer) ||
1008
- isTransferNftOut(transfer) ||
1009
- isTransferFiatCurrencyOut(transfer),
1010
- )
1011
- if (transfers.length !== action.transfers.length) {
1012
- throw new Error('Invalid action.transfers for trade')
1013
- }
1014
- return {
1015
- ...action,
1016
- type: 'NormalAction',
1017
- action: 'trade',
1018
- transfers,
1019
- } satisfies NormalActionTrade
1020
- }
1021
- case 'transaction-fee': {
1022
- // transferCryptoCurrencyOutSchema
1023
- const transfers = action.transfers.filter(
1024
- (transfer): transfer is TransferCryptoCurrencyOut =>
1025
- isTransferCryptoCurrencyOut(transfer),
1026
- )
1027
- if (transfers.length !== action.transfers.length) {
1028
- throw new Error('Invalid action.transfers for transaction-fee')
1029
- }
1030
- return {
1031
- ...action,
1032
- type: 'NormalAction',
1033
- action: 'transaction-fee',
1034
- transfers,
1035
- } satisfies NormalActionTransactionFee
1036
- }
1037
- case 'transfer': {
1038
- return {
1039
- ...action,
1040
- type: 'NormalAction',
1041
- action: 'transfer',
1042
- transfers: [...action.transfers],
1043
- } satisfies NormalActionTransfer
1044
- }
1045
- case 'unstake': {
1046
- // transferCryptoCurrencyInSchema, transferNftInSchema
1047
- const transfers = action.transfers.filter(
1048
- (transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
1049
- isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
1050
- )
1051
- if (transfers.length !== action.transfers.length) {
1052
- throw new Error('Invalid action.transfers for unstake')
1053
- }
1054
- if (action.loanId === undefined) {
1055
- throw new Error('action.loandId is required for unstake')
1056
- }
1057
- return {
1058
- ...action,
1059
- type: 'LoanNormalAction',
1060
- action: 'unstake',
1061
- loanId: action.loanId,
1062
- transfers,
1063
- } satisfies NormalActionUnstake
1064
- }
1065
- case 'unwrap': {
1066
- // transferCryptoCurrencyInSchema,
1067
- // transferCryptoCurrencyOutSchema,
1068
- const transfers = action.transfers.filter(
1069
- (
1070
- transfer,
1071
- ): transfer is TransferCryptoCurrencyIn | TransferCryptoCurrencyOut =>
1072
- isTransferCryptoCurrencyIn(transfer) ||
1073
- isTransferCryptoCurrencyOut(transfer),
1074
- )
1075
- if (transfers.length !== action.transfers.length) {
1076
- throw new Error('Invalid action.transfers for unwrap')
1077
- }
1078
- return {
1079
- ...action,
1080
- type: 'NormalAction',
1081
- action: 'unwrap',
1082
- transfers,
1083
- } satisfies NormalActionUnwrap
1084
- }
1085
- case 'wrap': {
1086
- // transferCryptoCurrencyInSchema,
1087
- // transferCryptoCurrencyOutSchema,
1088
- const transfers = action.transfers.filter(
1089
- (
1090
- transfer,
1091
- ): transfer is TransferCryptoCurrencyIn | TransferCryptoCurrencyOut =>
1092
- isTransferCryptoCurrencyIn(transfer) ||
1093
- isTransferCryptoCurrencyOut(transfer),
1094
- )
1095
- if (transfers.length !== action.transfers.length) {
1096
- throw new Error('Invalid action.transfers for wrap')
1097
- }
1098
- return {
1099
- ...action,
1100
- type: 'NormalAction',
1101
- action: 'wrap',
1102
- transfers,
1103
- } satisfies NormalActionWrap
1104
- }
1105
- case 'valuedown': {
1106
- // TODO asset の指定を可能にする
1107
- throw new Error('Not implemented for valuedown')
1108
- }
1109
- case 'valueup': {
1110
- // TODO
1111
- throw new Error('Not implemented for valueup')
1112
- }
1113
- case 'withdraw': {
1114
- // transferCryptoCurrencyInSchema, transferNftInSchema
1115
- const transfers = action.transfers.filter(
1116
- (transfer): transfer is TransferCryptoCurrencyIn | TransferNftIn =>
1117
- isTransferCryptoCurrencyIn(transfer) || isTransferNftIn(transfer),
1118
- )
1119
- if (transfers.length !== action.transfers.length) {
1120
- throw new Error('Invalid action.transfers for withdraw')
1121
- }
1122
- if (action.loanId === undefined) {
1123
- throw new Error('action.loandId is required for withdraw')
1124
- }
1125
- return {
1126
- ...action,
1127
- type: 'LoanNormalAction',
1128
- action: 'withdraw',
1129
- loanId: action.loanId,
1130
- transfers,
1131
- } satisfies NormalActionWithdraw
1132
- }
1133
- case 'withdraw-with-bond': {
1134
- // transferCryptoCurrencyInSchema,
1135
- // transferNftInSchema,
1136
- // transferCryptoCurrencyOutSchema,
1137
- // transferNftOutSchema,
1138
- const transfers = action.transfers.filter(
1139
- (
1140
- transfer,
1141
- ): transfer is
1142
- | TransferCryptoCurrencyIn
1143
- | TransferNftIn
1144
- | TransferCryptoCurrencyOut
1145
- | TransferNftOut =>
1146
- isTransferCryptoCurrencyIn(transfer) ||
1147
- isTransferNftIn(transfer) ||
1148
- isTransferCryptoCurrencyOut(transfer) ||
1149
- isTransferNftOut(transfer),
1150
- )
1151
- if (transfers.length !== action.transfers.length) {
1152
- throw new Error('Invalid action.transfers for withdraw-with-bond')
1153
- }
1154
- if (action.loanId === undefined) {
1155
- throw new Error('action.loandId is required for withdraw-with-bond')
1156
- }
1157
- return {
1158
- ...action,
1159
- type: 'LoanNormalAction',
1160
- action: 'withdraw-with-bond',
1161
- loanId: action.loanId,
1162
- transfers,
1163
- } satisfies NormalActionWithdrawWithBond
1164
- }
1165
- }
280
+ return parseBaseNormalActionToNormalAction(action)
1166
281
  }