@0xtorch/evm 0.0.13 → 0.0.15

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