@defisaver/sdk 0.1.22 → 0.2.0

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 (81) 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 +4 -0
  7. package/package.json +1 -1
  8. package/src/Action.js +36 -6
  9. package/src/Recipe.js +5 -4
  10. package/src/Strategy.js +63 -0
  11. package/src/abis/Action.json +157 -11
  12. package/src/abis/Recipe.json +92 -47
  13. package/src/actions/aave/AaveBorrowAction.js +11 -2
  14. package/src/actions/aave/AavePaybackAction.js +11 -2
  15. package/src/actions/aave/AaveSupplyAction.js +9 -1
  16. package/src/actions/aave/AaveWithdrawAction.js +8 -1
  17. package/src/actions/basic/GasFeeAction.js +27 -0
  18. package/src/actions/basic/PullTokenAction.js +9 -3
  19. package/src/actions/basic/SellAction.js +6 -5
  20. package/src/actions/basic/SendTokenAction.js +9 -3
  21. package/src/actions/basic/SendTokenAndUnwrapAction.js +36 -0
  22. package/src/actions/basic/SumInputsAction.js +8 -3
  23. package/src/actions/basic/UnwrapEthAction.js +8 -3
  24. package/src/actions/basic/UpdateSubAction.js +19 -0
  25. package/src/actions/basic/WrapEthAction.js +5 -1
  26. package/src/actions/basic/index.js +6 -2
  27. package/src/actions/checkers/MakerRatioCheckAction.js +29 -0
  28. package/src/actions/checkers/index.js +5 -0
  29. package/src/actions/compound/CompoundBorrowAction.js +7 -1
  30. package/src/actions/compound/CompoundClaimAction.js +6 -1
  31. package/src/actions/compound/CompoundPaybackAction.js +7 -1
  32. package/src/actions/compound/CompoundSupplyAction.js +7 -1
  33. package/src/actions/compound/CompoundWithdrawAction.js +7 -1
  34. package/src/actions/dydx/DyDxWithdrawAction.js +7 -1
  35. package/src/actions/dydx/index.js +0 -2
  36. package/src/actions/flashloan/AaveV2FlashLoanAction.js +2 -2
  37. package/src/actions/flashloan/BalancerFlashLoanAction.js +2 -2
  38. package/src/actions/flashloan/DyDxFlashLoanAction.js +1 -1
  39. package/src/actions/flashloan/MakerFlashLoanAction.js +2 -2
  40. package/src/actions/index.js +2 -0
  41. package/src/actions/insta/index.js +0 -2
  42. package/src/actions/liquity/LiquityClaimAction.js +6 -2
  43. package/src/actions/liquity/LiquityCloseAction.js +7 -2
  44. package/src/actions/maker/MakerGenerateAction.js +8 -1
  45. package/src/actions/maker/MakerGiveAction.js +7 -1
  46. package/src/actions/maker/MakerMergeAction.js +7 -1
  47. package/src/actions/maker/MakerOpenVaultAction.js +6 -1
  48. package/src/actions/maker/MakerPaybackAction.js +1 -0
  49. package/src/actions/maker/MakerRatioAction.js +20 -0
  50. package/src/actions/maker/MakerSupplyAction.js +9 -1
  51. package/src/actions/maker/MakerWithdrawAction.js +10 -2
  52. package/src/actions/maker/index.js +2 -0
  53. package/src/actions/mstable/MStableDepositAction.js +2 -2
  54. package/src/actions/mstable/MStableWithdrawAction.js +2 -2
  55. package/src/actions/reflexer/ReflexerGenerateAction.js +7 -1
  56. package/src/actions/reflexer/ReflexerOpenSafeAction.js +5 -1
  57. package/src/actions/reflexer/ReflexerPaybackAction.js +7 -1
  58. package/src/actions/reflexer/ReflexerSupplyAction.js +8 -1
  59. package/src/actions/reflexer/ReflexerWithdrawAction.js +8 -1
  60. package/src/addresses.js +91 -91
  61. package/src/triggers/ChainLinkPriceTrigger.js +12 -0
  62. package/src/triggers/CompoundRatioTrigger.js +11 -0
  63. package/src/triggers/GasPriceTrigger.js +11 -0
  64. package/src/triggers/LiquityRatioTrigger.js +15 -0
  65. package/src/triggers/MakerRatioTrigger.js +15 -0
  66. package/src/triggers/ReflexerRatioTrigger.js +10 -0
  67. package/src/triggers/TimestampTrigger.js +11 -0
  68. package/src/triggers/UniV3CurrentTickTrigger.js +12 -0
  69. package/src/triggers/index.js +19 -0
  70. package/src/utils/general.js +2 -0
  71. package/src/utils/zeroExExchange.js +2 -40
  72. package/test/accessLists/MockAccessLists.json +0 -72
  73. package/test/accessLists/Recipe.js +3 -3
  74. package/test/actions/insta/InstPullTokensAction.js +2 -2
  75. package/test/utils/zeroExExchange.js +0 -8
  76. package/src/actions/basic/BuyAction.js +0 -53
  77. package/src/actions/dydx/DyDxSupplyAction.js +0 -25
  78. package/src/actions/insta/ClaimInstMakerAction.js +0 -21
  79. package/test/actions/basic/BuyAction.js +0 -100
  80. package/test/actions/dydx/DyDxSupplyAction.js +0 -78
  81. 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,15 +1,19 @@
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');
4
5
 
5
6
  const actions = require('./src/actions/');
7
+ const triggers = require('./src/triggers/');
6
8
  const utils = require('./src/utils/');
7
9
  const { actionAddresses } = require('./src/addresses');
8
10
 
9
11
  module.exports = {
10
12
  Action,
11
13
  Recipe,
14
+ Strategy,
12
15
  actions,
16
+ triggers,
13
17
  actionAddresses,
14
18
  utils,
15
19
  DfsWeb3,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/sdk",
3
- "version": "0.1.22",
3
+ "version": "0.2.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/src/Action.js CHANGED
@@ -31,24 +31,46 @@ class Action {
31
31
  * @returns {string}
32
32
  * @private
33
33
  */
34
- _getId() {
35
- return keccak256(this.name);
34
+ getId() {
35
+ return keccak256(this.name).substr(0, 10);
36
36
  }
37
37
 
38
38
  /**
39
39
  * @returns {Array<number>}
40
40
  * @private
41
41
  */
42
- _getArgumentMapping() {
42
+ _getArgumentMappingWithSlots(subSlots) {
43
43
  return this.mappableArgs.map(arg => {
44
44
  if (new RegExp(/\$\d+/).test(arg)) {
45
45
  if (Array.isArray(arg)) throw TypeError('Input can\'t be mapped to arrays (tuples/structs). Specify `mappableArgs` array in constructor.');
46
46
  return parseInt(arg.substr(1))
47
47
  }
48
+
49
+ // Handle SubSlots placeholder values in strategies
50
+ if (new RegExp(/\&\w+/).test(arg)) {
51
+ if (arg === '&proxy') return 254;
52
+ if (arg === '&eoa') return 255;
53
+ return parseInt(subSlots[arg].index);
54
+ }
55
+
48
56
  return 0;
49
57
  });
50
58
  }
51
59
 
60
+ /**
61
+ * @returns {Array<number>}
62
+ * @private
63
+ */
64
+ _getArgumentMapping() {
65
+ return this.mappableArgs.map(arg => {
66
+ if (new RegExp(/\$\d+/).test(arg)) {
67
+ if (Array.isArray(arg)) throw TypeError('Input can\'t be mapped to arrays (tuples/structs). Specify `mappableArgs` array in constructor.');
68
+ return parseInt(arg.substr(1))
69
+ }
70
+ return 0;
71
+ });
72
+ }
73
+
52
74
  /**
53
75
  * @param type {string}
54
76
  * @private
@@ -67,6 +89,7 @@ class Action {
67
89
  _replaceWithPlaceholders(arg, paramType) {
68
90
  if (Array.isArray(arg)) return arg.map((_arg, i) => this._replaceWithPlaceholders(_arg, paramType[i]));
69
91
  if (new RegExp(/\$\d+/).test(arg)) return this._getPlaceholderForType(paramType);
92
+ if (new RegExp(/\&\w+/).test(arg)) return this._getPlaceholderForType(paramType);
70
93
  return arg;
71
94
  }
72
95
 
@@ -90,7 +113,7 @@ class Action {
90
113
  let _paramType = this._formatType(paramType);
91
114
  return AbiCoder.encodeParameter(_paramType, _arg);
92
115
  });
93
- return [bytesEncodedArgs];
116
+ return bytesEncodedArgs;
94
117
  }
95
118
 
96
119
  /**
@@ -112,12 +135,19 @@ class Action {
112
135
  encodeForRecipe() {
113
136
  return [
114
137
  this._encodeForCall()[0], // actionCallData
115
- [], // subData
116
- this._getId(), // actionIds
138
+ "0x0000000000000000000000000000000000000000000000000000000000000000", // subData
139
+ this.getId(), // actionIds
117
140
  this._getArgumentMapping(), // paramMappings
118
141
  ]
119
142
  }
120
143
 
144
+ encodeForStrategy(subSlots) {
145
+ return [
146
+ this.getId(),
147
+ this._getArgumentMappingWithSlots(subSlots), // paramMappings
148
+ ]
149
+ }
150
+
121
151
  /**
122
152
  * Assets requiring approval to be used by DsProxy
123
153
  * Approval is done from owner to DsProxy
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) => {
@@ -0,0 +1,63 @@
1
+ const Action = require('./Action');
2
+
3
+ // TODO: Code is a prototype should be cleaned up before use in prod.
4
+
5
+ class Strategy {
6
+
7
+ constructor(name) {
8
+ this.name = name;
9
+ this.subSlots = {};
10
+ this.actions = [];
11
+ this.triggers = [];
12
+ this.numSubSlots = 0;
13
+ }
14
+
15
+ addSubSlot(name, type) {
16
+ this.subSlots[name] = { type, index: this.numSubSlots + 128 };
17
+ this.numSubSlots++;
18
+ }
19
+
20
+ addTrigger(newTrigger) {
21
+ this.triggers.push(newTrigger);
22
+ }
23
+
24
+ addAction(newAction) {
25
+ this.actions.push(newAction);
26
+ }
27
+
28
+ print() {
29
+ console.log(`Name: ${this.name }`);
30
+ console.log(`Slots: ${this.subSlots }`);
31
+ console.log(`Action: ${this.actions[0]}`);
32
+ }
33
+
34
+ getSubSlots() {
35
+ return this.subSlots;
36
+ }
37
+
38
+ // TODO: Probably should be tied into Recipe obj. not directly with actions
39
+ encodeForDsProxyCall() {
40
+ const triggerIds = this.triggers.map((trigger) => trigger.getId());
41
+
42
+ const paramMappings = [];
43
+ const actionIds = [];
44
+
45
+ this.actions.forEach(action => {
46
+ const actionEncoded = action.encodeForStrategy(this.subSlots);
47
+
48
+ actionIds.push(actionEncoded[0]);
49
+ paramMappings.push(actionEncoded[1]);
50
+ });
51
+
52
+ return [
53
+ this.name,
54
+ triggerIds,
55
+ actionIds,
56
+ paramMappings
57
+ ];
58
+ }
59
+
60
+ }
61
+
62
+ module.exports = Strategy;
63
+