@defisaver/sdk 0.1.21 → 0.1.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/ACTIONS.md +20 -254
  2. package/AccessLists/DyDxAccessLists.js +0 -4
  3. package/AccessLists/InstaAccessLists.js +0 -8
  4. package/AccessLists/UtilsAccessLists.js +0 -5
  5. package/DEV.md +0 -7
  6. package/index.js +15 -2
  7. package/package.json +1 -1
  8. package/src/Action.js +52 -12
  9. package/src/L2Action.js +44 -0
  10. package/src/Recipe.js +5 -4
  11. package/src/Strategy.js +63 -0
  12. package/src/abis/Action.json +157 -11
  13. package/src/abis/Recipe.json +92 -47
  14. package/src/actions/aave/AaveBorrowAction.js +11 -2
  15. package/src/actions/aave/AavePaybackAction.js +11 -2
  16. package/src/actions/aave/AaveSupplyAction.js +9 -1
  17. package/src/actions/aave/AaveWithdrawAction.js +8 -1
  18. package/src/actions/aaveV3/AaveV3ATokenPaybackAction.js +53 -0
  19. package/src/actions/aaveV3/AaveV3BorrowAction.js +54 -0
  20. package/src/actions/aaveV3/AaveV3CollateralSwitchAction.js +41 -0
  21. package/src/actions/aaveV3/AaveV3PaybackAction.js +63 -0
  22. package/src/actions/aaveV3/AaveV3SetEModeAction.js +35 -0
  23. package/src/actions/aaveV3/AaveV3SupplyAction.js +64 -0
  24. package/src/actions/aaveV3/AaveV3WithdrawAction.js +41 -0
  25. package/src/actions/aaveV3/index.js +17 -0
  26. package/src/actions/basic/GasFeeAction.js +27 -0
  27. package/src/actions/basic/PullTokenAction.js +9 -3
  28. package/src/actions/basic/SellAction.js +6 -5
  29. package/src/actions/basic/SendTokenAction.js +9 -3
  30. package/src/actions/basic/SumInputsAction.js +8 -3
  31. package/src/actions/basic/UnwrapEthAction.js +8 -3
  32. package/src/actions/basic/WrapEthAction.js +5 -1
  33. package/src/actions/basic/index.js +2 -2
  34. package/src/actions/checkers/MakerRatioCheckAction.js +29 -0
  35. package/src/actions/checkers/index.js +5 -0
  36. package/src/actions/compound/CompoundBorrowAction.js +7 -1
  37. package/src/actions/compound/CompoundClaimAction.js +6 -1
  38. package/src/actions/compound/CompoundPaybackAction.js +7 -1
  39. package/src/actions/compound/CompoundSupplyAction.js +7 -1
  40. package/src/actions/compound/CompoundWithdrawAction.js +7 -1
  41. package/src/actions/dydx/DyDxWithdrawAction.js +7 -1
  42. package/src/actions/dydx/index.js +0 -2
  43. package/src/actions/flashloan/AaveV2FlashLoanAction.js +2 -2
  44. package/src/actions/flashloan/BalancerFlashLoanAction.js +2 -2
  45. package/src/actions/flashloan/DyDxFlashLoanAction.js +1 -1
  46. package/src/actions/flashloan/MakerFlashLoanAction.js +2 -2
  47. package/src/actions/index.js +4 -0
  48. package/src/actions/insta/index.js +0 -2
  49. package/src/actions/liquity/LiquityClaimAction.js +6 -2
  50. package/src/actions/liquity/LiquityCloseAction.js +7 -2
  51. package/src/actions/maker/MakerGenerateAction.js +8 -1
  52. package/src/actions/maker/MakerGiveAction.js +7 -1
  53. package/src/actions/maker/MakerMergeAction.js +7 -1
  54. package/src/actions/maker/MakerOpenVaultAction.js +6 -1
  55. package/src/actions/maker/MakerPaybackAction.js +1 -0
  56. package/src/actions/maker/MakerRatioAction.js +20 -0
  57. package/src/actions/maker/MakerSupplyAction.js +9 -1
  58. package/src/actions/maker/MakerWithdrawAction.js +10 -2
  59. package/src/actions/maker/index.js +2 -0
  60. package/src/actions/mstable/MStableDepositAction.js +2 -2
  61. package/src/actions/mstable/MStableWithdrawAction.js +2 -2
  62. package/src/actions/reflexer/ReflexerGenerateAction.js +7 -1
  63. package/src/actions/reflexer/ReflexerOpenSafeAction.js +5 -1
  64. package/src/actions/reflexer/ReflexerPaybackAction.js +7 -1
  65. package/src/actions/reflexer/ReflexerSupplyAction.js +8 -1
  66. package/src/actions/reflexer/ReflexerWithdrawAction.js +8 -1
  67. package/src/addresses.js +179 -143
  68. package/src/config.js +74 -0
  69. package/src/triggers/ChainLinkPriceTrigger.js +12 -0
  70. package/src/triggers/CompoundRatioTrigger.js +11 -0
  71. package/src/triggers/GasPriceTrigger.js +11 -0
  72. package/src/triggers/LiquityRatioTrigger.js +16 -0
  73. package/src/triggers/MakerRatioTrigger.js +15 -0
  74. package/src/triggers/ReflexerRatioTrigger.js +11 -0
  75. package/src/triggers/TimestampTrigger.js +11 -0
  76. package/src/triggers/UniV3CurrentTickTrigger.js +12 -0
  77. package/src/triggers/index.js +19 -0
  78. package/src/types.js +33 -0
  79. package/src/utils/general.js +2 -0
  80. package/src/utils/zeroExExchange.js +2 -40
  81. package/test/accessLists/MockAccessLists.json +0 -72
  82. package/test/accessLists/Recipe.js +3 -3
  83. package/test/actions/insta/InstPullTokensAction.js +2 -2
  84. package/test/index.js +4 -1
  85. package/test/utils/zeroExExchange.js +0 -8
  86. package/src/actions/basic/BuyAction.js +0 -53
  87. package/src/actions/dydx/DyDxSupplyAction.js +0 -25
  88. package/src/actions/insta/ClaimInstMakerAction.js +0 -21
  89. package/test/actions/basic/BuyAction.js +0 -100
  90. package/test/actions/dydx/DyDxSupplyAction.js +0 -78
  91. package/test/actions/insta/ClaimInstMakerAction.js +0 -46
package/ACTIONS.md CHANGED
@@ -10,6 +10,9 @@
10
10
  <dt><a href="#AaveCollateralSwitchAction">AaveCollateralSwitchAction</a></dt>
11
11
  <dd><p>AaveCollateralSwitchAction - Aave enable/disable token usage as collateral</p>
12
12
  </dd>
13
+ <dt><a href="#AaveMigrateLendAction">AaveMigrateLendAction</a></dt>
14
+ <dd><p>AaveMigrateLendAction - Migrates Lend to Aave</p>
15
+ </dd>
13
16
  <dt><a href="#AavePaybackAction">AavePaybackAction</a></dt>
14
17
  <dd><p>AavePaybackAction - Payback borrowed tokens from Aave</p>
15
18
  </dd>
@@ -26,9 +29,6 @@
26
29
  <dt><a href="#BalancerV2WithdrawAction">BalancerV2WithdrawAction</a></dt>
27
30
  <dd><p>BalancerV2WithdrawAction - Withdraw tokens from Balancer pool</p>
28
31
  </dd>
29
- <dt><a href="#BuyAction">BuyAction</a></dt>
30
- <dd><p>Buys an exact amount of dest token on DeFi Saver exchange aggregator</p>
31
- </dd>
32
32
  <dt><a href="#ChangeProxyOwnerAction">ChangeProxyOwnerAction</a></dt>
33
33
  <dd><p>ChangeProxyOwnerAction - Changes EOA which owns the proxy that is being called</p>
34
34
  </dd>
@@ -71,23 +71,6 @@
71
71
  <dt><a href="#CompoundWithdrawAction">CompoundWithdrawAction</a></dt>
72
72
  <dd><p>CompoundWithdrawAction - Withdraw token from an Compound position</p>
73
73
  </dd>
74
- <dt><a href="#CurveClaimFeesAction">CurveClaimFeesAction</a></dt>
75
- <dd></dd>
76
- <dt><a href="#CurveDepositAction">CurveDepositAction</a></dt>
77
- <dd></dd>
78
- <dt><a href="#CurveGaugeDepositAction">CurveGaugeDepositAction</a></dt>
79
- <dd></dd>
80
- <dt><a href="#CurveGaugeWithdrawAction">CurveGaugeWithdrawAction</a></dt>
81
- <dd></dd>
82
- <dt><a href="#CurveMintCrvAction">CurveMintCrvAction</a></dt>
83
- <dd></dd>
84
- <dt><a href="#CurveSwapAction">CurveSwapAction</a></dt>
85
- <dd></dd>
86
- <dt><a href="#CurveWithdrawAction">CurveWithdrawAction</a></dt>
87
- <dd></dd>
88
- <dt><a href="#DyDxSupplyAction">DyDxSupplyAction</a></dt>
89
- <dd><p>DyDxSupplyAction - Supply token to an DyDx position</p>
90
- </dd>
91
74
  <dt><a href="#DyDxWithdrawAction">DyDxWithdrawAction</a></dt>
92
75
  <dd><p>DyDxWithdrawAction - Withdraw token from an DyDx position</p>
93
76
  </dd>
@@ -109,27 +92,9 @@
109
92
  <dt><a href="#DyDxFlashLoanPaybackAction">DyDxFlashLoanPaybackAction</a></dt>
110
93
  <dd><p>Pays back a flashloan from DyDx</p>
111
94
  </dd>
112
- <dt><a href="#MakerFlashLoanAction">MakerFlashLoanAction</a></dt>
113
- <dd><p>Gets a flashloan from Maker</p>
114
- </dd>
115
- <dt><a href="#MakerFlashLoanPaybackAction">MakerFlashLoanPaybackAction</a></dt>
116
- <dd><p>Pays back a flashloan from Maker</p>
117
- </dd>
118
- <dt><a href="#GUniDeposit">GUniDeposit</a></dt>
119
- <dd><p>Action that adds liquidity to G-UNI pool of interest (mints G-UNI LP tokens)</p>
120
- </dd>
121
- <dt><a href="#GUniWithdraw">GUniWithdraw</a></dt>
122
- <dd><p>Action that removes liquidity from a G-UNI pool and burns G-UNI LP tokens</p>
123
- </dd>
124
95
  <dt><a href="#LidoStakeAction">LidoStakeAction</a></dt>
125
96
  <dd><p>LidoStakeAction - Receives WETH, transforms it to ETH then sends it to Lido staking contract receiving stETH in return</p>
126
97
  </dd>
127
- <dt><a href="#LidoUnwrapAction">LidoUnwrapAction</a></dt>
128
- <dd><p>LidoUnwrapAction - Unwraps WStEth into StEth</p>
129
- </dd>
130
- <dt><a href="#LidoWrapAction">LidoWrapAction</a></dt>
131
- <dd><p>LidoWrapAction - Turns WETH or StEth into WStEth</p>
132
- </dd>
133
98
  <dt><a href="#LiquityBorrowAction">LiquityBorrowAction</a></dt>
134
99
  <dd><p>LiquityBorrowAction - Borrows LUSD from the trove</p>
135
100
  </dd>
@@ -293,6 +258,18 @@ AaveClaimStkAaveAction - Claims stkAave from incentives controller
293
258
  ## AaveCollateralSwitchAction
294
259
  AaveCollateralSwitchAction - Aave enable/disable token usage as collateral
295
260
 
261
+ **Kind**: global class
262
+ <a name="AaveMigrateLendAction"></a>
263
+
264
+ ## AaveClaimStkAaveAction
265
+ AaveClaimStkAaveAction - Claims stkAave from incentives controller
266
+
267
+ **Kind**: global class
268
+ <a name="AaveCollateralSwitchAction"></a>
269
+
270
+ ## AaveCollateralSwitchAction
271
+ AaveCollateralSwitchAction - Aave enable/disable token usage as collateral
272
+
296
273
  **Kind**: global class
297
274
  <a name="AavePaybackAction"></a>
298
275
 
@@ -396,22 +373,6 @@ BalancerV2WithdrawAction - Withdraw tokens from Balancer pool
396
373
  - minAmountsOut <code>Array.&lt;uint256&gt;</code>
397
374
  - userData <code>bytes</code>
398
375
 
399
- <a name="BuyAction"></a>
400
-
401
- ## BuyAction
402
- Buys an exact amount of dest token on DeFi Saver exchange aggregator
403
-
404
- **Kind**: global class
405
- <a name="new_BuyAction_new"></a>
406
-
407
- ### new BuyAction(exchangeOrder, from, to, protocolFee)
408
- **Params**
409
-
410
- - exchangeOrder <code>Array</code> - Standard DFS Exchange data
411
- - from <code>string</code> - Order sender
412
- - to <code>string</code> - Order recipient
413
- - protocolFee <code>string</code> - 0x fee (amount of ETH in Wei)
414
-
415
376
  <a name="ChangeProxyOwnerAction"></a>
416
377
 
417
378
  ## ChangeProxyOwnerAction
@@ -561,7 +522,7 @@ CompoundPaybackAction - Payback borrowed tokens from Compound
561
522
  - cTokenAddr <code>EthAddress</code>
562
523
  - amount <code>string</code> - Wei amount in underlying asset decimals (not cAsset) - ie. 18 dec for cETH, not 8
563
524
  - from <code>EthAddress</code>
564
- - onBehalf <code>EthAddress</code> - Defaults to DsProxy address if 0x0
525
+ - onBehalf <code>Array.&lt;EthAddress&gt;</code>
565
526
 
566
527
  <a name="CompoundSupplyAction"></a>
567
528
 
@@ -594,130 +555,6 @@ CompoundWithdrawAction - Withdraw token from an Compound position
594
555
  - amount <code>string</code> - Wei amount in underlying asset decimals (not cAsset) - ie. 18 dec for cETH, not 8
595
556
  - to <code>EthAddress</code>
596
557
 
597
- <a name="CurveClaimFeesAction"></a>
598
-
599
- ## CurveClaimFeesAction
600
- **Kind**: global class
601
- <a name="new_CurveClaimFeesAction_new"></a>
602
-
603
- ### new CurveClaimFeesAction(claimFor, receiver)
604
- **Params**
605
-
606
- - claimFor <code>EthAddress</code>
607
- - receiver <code>EthAddress</code>
608
-
609
- <a name="CurveDepositAction"></a>
610
-
611
- ## CurveDepositAction
612
- **Kind**: global class
613
- <a name="new_CurveDepositAction_new"></a>
614
-
615
- ### new CurveDepositAction(sender, receiver, depositTarget, lpToken, sig, minMintAmount, amounts, tokens, useUnderlying)
616
- **Params**
617
-
618
- - sender <code>EthAddress</code>
619
- - receiver <code>EthAddress</code>
620
- - depositTarget <code>EthAddress</code>
621
- - lpToken <code>EthAddress</code>
622
- - sig <code>bytes4</code>
623
- - minMintAmount <code>string</code>
624
- - amounts <code>Array.&lt;string&gt;</code>
625
- - tokens <code>Array.&lt;EthAddress&gt;</code>
626
- - useUnderlying <code>boolean</code>
627
-
628
- <a name="CurveGaugeDepositAction"></a>
629
-
630
- ## CurveGaugeDepositAction
631
- **Kind**: global class
632
- <a name="new_CurveGaugeDepositAction_new"></a>
633
-
634
- ### new CurveGaugeDepositAction(gaugeAddr, lpToken, sender, onBehalfOf, amount)
635
- **Params**
636
-
637
- - gaugeAddr <code>EthAddress</code>
638
- - lpToken <code>EthAddress</code>
639
- - sender <code>EthAddress</code>
640
- - onBehalfOf <code>EthAddress</code>
641
- - amount <code>string</code>
642
-
643
- <a name="CurveGaugeWithdrawAction"></a>
644
-
645
- ## CurveGaugeWithdrawAction
646
- **Kind**: global class
647
- <a name="new_CurveGaugeWithdrawAction_new"></a>
648
-
649
- ### new CurveGaugeWithdrawAction(gaugeAddr, lpToken, receiver, amount)
650
- **Params**
651
-
652
- - gaugeAddr <code>EthAddress</code>
653
- - lpToken <code>EthAddress</code>
654
- - receiver <code>EthAddress</code>
655
- - amount <code>string</code>
656
-
657
- <a name="CurveMintCrvAction"></a>
658
-
659
- ## CurveMintCrvAction
660
- **Kind**: global class
661
- <a name="new_CurveMintCrvAction_new"></a>
662
-
663
- ### new CurveMintCrvAction(gaugeAddrs, receiver)
664
- **Params**
665
-
666
- - gaugeAddrs <code>Array.&lt;EthAddress&gt;</code>
667
- - receiver <code>EthAddress</code>
668
-
669
- <a name="CurveSwapAction"></a>
670
-
671
- ## CurveSwapAction
672
- **Kind**: global class
673
- <a name="new_CurveSwapAction_new"></a>
674
-
675
- ### new CurveSwapAction(sender, receiver, pool, tokenA, tokenB, amount, expected)
676
- **Params**
677
-
678
- - sender <code>EthAddress</code>
679
- - receiver <code>EthAddress</code>
680
- - pool <code>EthAddress</code>
681
- - tokenA <code>EthAddress</code>
682
- - tokenB <code>EthAddress</code>
683
- - amount <code>string</code>
684
- - expected <code>string</code>
685
-
686
- <a name="CurveWithdrawAction"></a>
687
-
688
- ## CurveWithdrawAction
689
- **Kind**: global class
690
- <a name="new_CurveWithdrawAction_new"></a>
691
-
692
- ### new CurveWithdrawAction(sender, receiver, depositTarget, lpToken, sig, burnAmount, minAmounts, tokens, withdrawExact, useUnderlying)
693
- **Params**
694
-
695
- - sender <code>EthAddress</code>
696
- - receiver <code>EthAddress</code>
697
- - depositTarget <code>EthAddress</code>
698
- - lpToken <code>EthAddress</code>
699
- - sig <code>bytes4</code>
700
- - burnAmount <code>string</code>
701
- - minAmounts <code>Array.&lt;string&gt;</code>
702
- - tokens <code>Array.&lt;EthAddress&gt;</code>
703
- - withdrawExact <code>boolean</code>
704
- - useUnderlying <code>boolean</code>
705
-
706
- <a name="DyDxSupplyAction"></a>
707
-
708
- ## DyDxSupplyAction
709
- DyDxSupplyAction - Supply token to an DyDx position
710
-
711
- **Kind**: global class
712
- <a name="new_DyDxSupplyAction_new"></a>
713
-
714
- ### new DyDxSupplyAction(tokenAddr, amount, from)
715
- **Params**
716
-
717
- - tokenAddr <code>EthAddress</code>
718
- - amount <code>string</code>
719
- - from <code>EthAddress</code> - Tokens will be supplied from this address
720
-
721
558
  <a name="DyDxWithdrawAction"></a>
722
559
 
723
560
  ## DyDxWithdrawAction
@@ -825,46 +662,6 @@ Pays back a flashloan from DyDx
825
662
  - loanAmount <code>string</code>
826
663
  - tokenAddr <code>EthAddress</code>
827
664
 
828
- <a name="MakerFlashLoanAction"></a>
829
-
830
- ## MakerFlashLoanAction
831
- Gets a flashloan from Maker
832
-
833
- **Kind**: global class
834
- <a name="new_MakerFlashLoanAction_new"></a>
835
-
836
- ### new MakerFlashLoanAction(amount, flParamGetterAddr, flParamGetterData)
837
- **Params**
838
-
839
- - amount <code>string</code>
840
- - flParamGetterAddr <code>EthAddress</code>
841
- - flParamGetterData <code>bytes</code>
842
-
843
- <a name="MakerFlashLoanPaybackAction"></a>
844
-
845
- ## MakerFlashLoanPaybackAction
846
- Pays back a flashloan from Maker
847
-
848
- **Kind**: global class
849
- <a name="new_MakerFlashLoanPaybackAction_new"></a>
850
-
851
- ### new MakerFlashLoanPaybackAction(loanAmount)
852
- **Params**
853
-
854
- - loanAmount <code>string</code>
855
-
856
- <a name="GUniDeposit"></a>
857
-
858
- ## GUniDeposit
859
- Action that adds liquidity to G-UNI pool of interest (mints G-UNI LP tokens)
860
-
861
- **Kind**: global class
862
- <a name="GUniWithdraw"></a>
863
-
864
- ## GUniWithdraw
865
- Action that removes liquidity from a G-UNI pool and burns G-UNI LP tokens
866
-
867
- **Kind**: global class
868
665
  <a name="LidoStakeAction"></a>
869
666
 
870
667
  ## LidoStakeAction
@@ -880,37 +677,6 @@ LidoStakeAction - Receives WETH, transforms it to ETH then sends it to Lido stak
880
677
  - from <code>EthAddress</code> - WETH will be taken from this address
881
678
  - to <code>EthAddress</code> - stETH will be sent to this address
882
679
 
883
- <a name="LidoUnwrapAction"></a>
884
-
885
- ## LidoUnwrapAction
886
- LidoUnwrapAction - Unwraps WStEth into StEth
887
-
888
- **Kind**: global class
889
- <a name="new_LidoUnwrapAction_new"></a>
890
-
891
- ### new LidoUnwrapAction(amount, from, to)
892
- **Params**
893
-
894
- - amount <code>string</code> - amount of WStEth to pull and Unwrap
895
- - from <code>EthAddress</code> - WstEth will be taken from this address
896
- - to <code>EthAddress</code> - stETH will be sent to this address
897
-
898
- <a name="LidoWrapAction"></a>
899
-
900
- ## LidoWrapAction
901
- LidoWrapAction - Turns WETH or StEth into WStEth
902
-
903
- **Kind**: global class
904
- <a name="new_LidoWrapAction_new"></a>
905
-
906
- ### new LidoWrapAction(amount, from, to, useEth)
907
- **Params**
908
-
909
- - amount <code>string</code> - amount to pull and stake
910
- - from <code>EthAddress</code> - tokens will be taken from this address
911
- - to <code>EthAddress</code> - WStEth will be sent to this address
912
- - useEth <code>boolean</code> - true for using WETH, false for using stEth
913
-
914
680
  <a name="LiquityBorrowAction"></a>
915
681
 
916
682
  ## LiquityBorrowAction
@@ -1268,7 +1034,7 @@ MStableDepositAction
1268
1034
  **Kind**: global class
1269
1035
  <a name="new_MStableDepositAction_new"></a>
1270
1036
 
1271
- ### new MStableDepositAction(bAsset, mAsset, saveAddress, vaultAddress, from, to, amount, minOut, assetPair)
1037
+ ### new MStableDepositAction(bAsset, mAsset, saveAddress, vaultAddress, from, to, amount, minOut, stake)
1272
1038
  **Params**
1273
1039
 
1274
1040
  - bAsset
@@ -1279,7 +1045,7 @@ MStableDepositAction
1279
1045
  - to
1280
1046
  - amount
1281
1047
  - minOut
1282
- - assetPair
1048
+ - stake
1283
1049
 
1284
1050
  <a name="MStableWithdrawAction"></a>
1285
1051
 
@@ -1289,7 +1055,7 @@ MStableWithdrawAction
1289
1055
  **Kind**: global class
1290
1056
  <a name="new_MStableWithdrawAction_new"></a>
1291
1057
 
1292
- ### new MStableWithdrawAction(bAsset, mAsset, saveAddress, vaultAddress, from, to, amount, minOut, assetPair)
1058
+ ### new MStableWithdrawAction(bAsset, mAsset, saveAddress, vaultAddress, from, to, amount, minOut, stake)
1293
1059
  **Params**
1294
1060
 
1295
1061
  - bAsset
@@ -1300,7 +1066,7 @@ MStableWithdrawAction
1300
1066
  - to
1301
1067
  - amount
1302
1068
  - minOut
1303
- - assetPair
1069
+ - stake
1304
1070
 
1305
1071
  <a name="RariDepositAction"></a>
1306
1072
 
@@ -1,8 +1,4 @@
1
1
  const DyDxAccessLists = {
2
- DyDxSupply: [
3
- ['0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e', []], // SoloMargin
4
- ['0x5c55B921f590a89C1Ebe84dF170E655a82b62126', []], // DefisaverLogger
5
- ],
6
2
  DyDxWithdraw: [
7
3
  ['0x1E0447b19BB6EcFdAe1e4AE1694b0C3659614e4e', []], // SoloMargin
8
4
  ['0x5c55B921f590a89C1Ebe84dF170E655a82b62126', []], // DefisaverLogger
@@ -1,12 +1,4 @@
1
1
  const InstaAccessLists = {
2
- ClaimInstMaker: [
3
- ['0x2971AdFa57b20E5a416aE5a708A8655A9c74f723', []], // InstaIndex
4
- ['0x5ef30b9986345249bc32d8928B7ee64DE9435E39', []], // DssCdpManager
5
- ['0xAC838332afc2937FdED89c16a59b2ED8e8e2743c', []], // InstaMakerDAOMerkleDistributor
6
- ['0x6f40d4A6237C257fff2dB00FA0510DeEECd303eb', []], // InstaToken
7
- ['0x5c55B921f590a89C1Ebe84dF170E655a82b62126', []], // DefisaverLogger
8
- ],
9
-
10
2
  InstPullTokens: [
11
3
  ['0x5c55B921f590a89C1Ebe84dF170E655a82b62126', []], // DefisaverLogger
12
4
  ],
@@ -12,11 +12,6 @@ const UtilsAccessLists = {
12
12
  ['0x5c55B921f590a89C1Ebe84dF170E655a82b62126', []], // DefisaverLogger
13
13
  ],
14
14
 
15
- DFSBuy: [
16
- ['0x25dd3F51e0C3c3Ff164DDC02A8E4D65Bb9cBB12D', []], // SaverExchangeRegistry
17
- ['0x5c55B921f590a89C1Ebe84dF170E655a82b62126', []], // DefisaverLogger
18
- ],
19
-
20
15
  SendToken: [],
21
16
 
22
17
  PullToken: [],
package/DEV.md CHANGED
@@ -85,7 +85,6 @@ Source: https://uniswap.org/docs/v2/javascript-SDK/getting-pair-addresses/#types
85
85
  * [.estimateSellPrice(sellAmount, sellToken, buyToken)](#utils.module_zeroExExchange.estimateSellPrice) ⇒ <code>Promise.&lt;string&gt;</code>
86
86
  * [.estimateBuyPrice(buyAmount, buyToken, sellToken)](#utils.module_zeroExExchange.estimateBuyPrice) ⇒ <code>Promise.&lt;string&gt;</code>
87
87
  * [.createSellAction(sellAmount, sellToken, buyToken, expectedPrice, acceptedSlippagePercent, fromAccount, toAccount)](#utils.module_zeroExExchange.createSellAction) ⇒ <code>Promise.&lt;SellAction&gt;</code>
88
- * [.createBuyAction(buyAmount, buyToken, sellToken, expectedPrice, acceptedSlippagePercent, fromAccount, toAccount)](#utils.module_zeroExExchange.createBuyAction) ⇒ <code>Promise.&lt;BuyAction&gt;</code>
89
88
 
90
89
  <a name="utils.module_zeroExExchange.estimateSellPrice"></a>
91
90
 
@@ -133,12 +132,6 @@ For that purpose, the estimateSellPrice method can be used.
133
132
  - fromAccount [<code>EthAddress</code>](#EthAddress) - Withdraw funds from this addr
134
133
  - toAccount [<code>EthAddress</code>](#EthAddress) - Send funds to this addr
135
134
 
136
- <a name="utils.module_zeroExExchange.createBuyAction"></a>
137
-
138
- ### zeroExExchange.createBuyAction(buyAmount, buyToken, sellToken, expectedPrice, acceptedSlippagePercent, fromAccount, toAccount) ⇒ <code>Promise.&lt;BuyAction&gt;</code>
139
- Fetches prices and creates order ready to be passed to transaction.
140
- This should only be called when before sending tx, not to be used for just querying the price.
141
- For that purpose, the estimateBuyPrice method can be used.
142
135
 
143
136
  **Kind**: static method of [<code>zeroExExchange</code>](#utils.module_zeroExExchange)
144
137
  **Params**
package/index.js CHANGED
@@ -1,16 +1,29 @@
1
1
  const Action = require('./src/Action');
2
2
  const Recipe = require('./src/Recipe');
3
+ const Strategy = require('./src/Strategy');
3
4
  const DfsWeb3 = require('./src/DfsWeb3');
5
+ const {
6
+ configure, getNetworkData, CONFIG, NETWORKS,
7
+ } = require('./src/config');
4
8
 
5
9
  const actions = require('./src/actions/');
10
+ const triggers = require('./src/triggers/');
6
11
  const utils = require('./src/utils/');
7
12
  const { actionAddresses } = require('./src/addresses');
8
13
 
9
14
  module.exports = {
10
15
  Action,
11
16
  Recipe,
17
+ Strategy,
18
+ DfsWeb3,
19
+
12
20
  actions,
13
- actionAddresses,
21
+ triggers,
14
22
  utils,
15
- DfsWeb3,
23
+
24
+ configure,
25
+ getNetworkData,
26
+ networks: NETWORKS,
27
+ actionAddressesAllChains: actionAddresses,
28
+ actionAddresses: actionAddresses[CONFIG.chainId],
16
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/sdk",
3
- "version": "0.1.21",
3
+ "version": "0.1.24",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/Action.js CHANGED
@@ -1,5 +1,6 @@
1
1
  const AbiCoder = require('web3-eth-abi');
2
2
  const { keccak256, padLeft, toHex } = require('web3-utils');
3
+ const { CONFIG } = require('./config');
3
4
 
4
5
  const ActionAbi = require('./abis/Action.json');
5
6
 
@@ -31,24 +32,46 @@ class Action {
31
32
  * @returns {string}
32
33
  * @private
33
34
  */
34
- _getId() {
35
- return keccak256(this.name);
35
+ getId() {
36
+ return keccak256(this.name).substr(0, 10);
36
37
  }
37
38
 
38
39
  /**
39
40
  * @returns {Array<number>}
40
41
  * @private
41
42
  */
42
- _getArgumentMapping() {
43
+ _getArgumentMappingWithSlots(subSlots) {
43
44
  return this.mappableArgs.map(arg => {
44
45
  if (new RegExp(/\$\d+/).test(arg)) {
45
46
  if (Array.isArray(arg)) throw TypeError('Input can\'t be mapped to arrays (tuples/structs). Specify `mappableArgs` array in constructor.');
46
47
  return parseInt(arg.substr(1))
47
48
  }
49
+
50
+ // Handle SubSlots placeholder values in strategies
51
+ if (new RegExp(/\&\w+/).test(arg)) {
52
+ if (arg === '&proxy') return 254;
53
+ if (arg === '&eoa') return 255;
54
+ return parseInt(subSlots[arg].index);
55
+ }
56
+
48
57
  return 0;
49
58
  });
50
59
  }
51
60
 
61
+ /**
62
+ * @returns {Array<number>}
63
+ * @private
64
+ */
65
+ _getArgumentMapping() {
66
+ return this.mappableArgs.map(arg => {
67
+ if (new RegExp(/\$\d+/).test(arg)) {
68
+ if (Array.isArray(arg)) throw TypeError('Input can\'t be mapped to arrays (tuples/structs). Specify `mappableArgs` array in constructor.');
69
+ return parseInt(arg.substr(1))
70
+ }
71
+ return 0;
72
+ });
73
+ }
74
+
52
75
  /**
53
76
  * @param type {string}
54
77
  * @private
@@ -67,6 +90,7 @@ class Action {
67
90
  _replaceWithPlaceholders(arg, paramType) {
68
91
  if (Array.isArray(arg)) return arg.map((_arg, i) => this._replaceWithPlaceholders(_arg, paramType[i]));
69
92
  if (new RegExp(/\$\d+/).test(arg)) return this._getPlaceholderForType(paramType);
93
+ if (new RegExp(/\&\w+/).test(arg)) return this._getPlaceholderForType(paramType);
70
94
  return arg;
71
95
  }
72
96
 
@@ -84,13 +108,18 @@ class Action {
84
108
  * @private
85
109
  */
86
110
  _encodeForCall() {
87
- const bytesEncodedArgs = this.args.map((arg, i) => {
111
+ return this.args.map((arg, i) => {
88
112
  let paramType = this.paramTypes[i];
89
113
  let _arg = this._replaceWithPlaceholders(arg, paramType);
90
114
  let _paramType = this._formatType(paramType);
91
115
  return AbiCoder.encodeParameter(_paramType, _arg);
92
116
  });
93
- return [bytesEncodedArgs];
117
+ }
118
+
119
+ encodeForL2DsProxyCall() {
120
+ // TODO fix this mess
121
+ const executeActionDirectAbi = ActionAbi.find(({ name }) => name === 'executeActionDirect');
122
+ return AbiCoder.encodeFunctionCall(executeActionDirectAbi, this._encodeForCall());
94
123
  }
95
124
 
96
125
  /**
@@ -98,11 +127,15 @@ class Action {
98
127
  * @returns {Array<string>} `address` & `data` to be passed on to DSProxy's `execute(address _target, bytes memory _data)`
99
128
  */
100
129
  encodeForDsProxyCall() {
101
- const executeActionDirectAbi = ActionAbi.find(({ name }) => name === 'executeActionDirect');
102
- return [
103
- this.contractAddress,
104
- AbiCoder.encodeFunctionCall(executeActionDirectAbi, this._encodeForCall()),
105
- ];
130
+ if (CONFIG.chainId === 1) {
131
+ const executeActionDirectAbi = ActionAbi.find(({ name }) => name === 'executeActionDirect');
132
+ return [
133
+ this.contractAddress,
134
+ AbiCoder.encodeFunctionCall(executeActionDirectAbi, this._encodeForCall()),
135
+ ];
136
+ } else {
137
+ return [this.contractAddress, this.encodeForL2DsProxyCall()];
138
+ }
106
139
  }
107
140
 
108
141
  /**
@@ -112,12 +145,19 @@ class Action {
112
145
  encodeForRecipe() {
113
146
  return [
114
147
  this._encodeForCall()[0], // actionCallData
115
- [], // subData
116
- this._getId(), // actionIds
148
+ "0x0000000000000000000000000000000000000000000000000000000000000000", // subData
149
+ this.getId(), // actionIds
117
150
  this._getArgumentMapping(), // paramMappings
118
151
  ]
119
152
  }
120
153
 
154
+ encodeForStrategy(subSlots) {
155
+ return [
156
+ this.getId(),
157
+ this._getArgumentMappingWithSlots(subSlots), // paramMappings
158
+ ]
159
+ }
160
+
121
161
  /**
122
162
  * Assets requiring approval to be used by DsProxy
123
163
  * Approval is done from owner to DsProxy
@@ -0,0 +1,44 @@
1
+ const Action = require('./Action');
2
+ class L2Action extends Action {
3
+ /**
4
+ * Encode arguments for calling the action via DsProxy
5
+ * @returns {string}
6
+ */
7
+ encodeForL2DsProxyCall() {
8
+ return this.encodeInputs();
9
+ }
10
+
11
+ encodeInputs(){
12
+ throw new Error('Use implementation from specific L2Action');
13
+ }
14
+
15
+ addressToBytes20(address){
16
+ return address.slice(2);
17
+ }
18
+
19
+ boolToBytes1(bool){
20
+ if (bool) {
21
+ return '01';
22
+ } else {
23
+ return '00';
24
+ }
25
+ }
26
+
27
+ numberToBytes2(number){
28
+ const hexNumber = number.toString(16);
29
+ return hexNumber.padStart(4, '0');
30
+ }
31
+
32
+ numberToBytes1(number){
33
+ const hexNumber = number.toString(16);
34
+ return hexNumber.padStart(2, '0');
35
+ }
36
+
37
+ numberToBytes32(number){
38
+ let hexNumber = number.toHexString();
39
+ hexNumber = hexNumber.slice(2);
40
+
41
+ return hexNumber.padStart(64, '0');
42
+ }
43
+ }
44
+ module.exports = L2Action;
package/src/Recipe.js CHANGED
@@ -21,7 +21,8 @@ class Recipe {
21
21
 
22
22
  this.name = name;
23
23
  this.actions = actions;
24
- this.taskExecutorAddress = getAddr('TaskExecutor');
24
+
25
+ this.recipeExecutorAddress = getAddr('RecipeExecutor');
25
26
  }
26
27
 
27
28
  /**
@@ -54,9 +55,9 @@ class Recipe {
54
55
  * @returns {Array<string>} `address` & `data` to be passed on to DSProxy's `execute(address _target, bytes memory _data)`
55
56
  */
56
57
  encodeForDsProxyCall() {
57
- const executeTaskAbi = RecipeAbi.find(({name}) => name === 'executeTask');
58
+ const executeTaskAbi = RecipeAbi.find(({name}) => name === 'executeRecipe');
58
59
  return [
59
- this.taskExecutorAddress,
60
+ this.recipeExecutorAddress,
60
61
  AbiCoder.encodeFunctionCall(executeTaskAbi, this._encodeForCall()),
61
62
  ];
62
63
  }
@@ -107,7 +108,7 @@ class Recipe {
107
108
  */
108
109
  getAccessList() {
109
110
  const addressMapping = {
110
- [getAddr('TaskExecutor')]: [],
111
+ [getAddr('RecipeExecutor')]: [],
111
112
  [getAddr('DFSRegistry')]: [],
112
113
  };
113
114
  this.actions.forEach((action) => {