@defisaver/sdk 0.2.7 → 0.2.10

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 (138) hide show
  1. package/ACTIONS.md +21 -379
  2. package/DEV.md +298 -0
  3. package/index.js +11 -2
  4. package/package.json +2 -2
  5. package/src/Action.js +20 -8
  6. package/src/ActionWithL2.js +36 -0
  7. package/src/actions/aave/AaveBorrowAction.js +11 -2
  8. package/src/actions/aave/AaveClaimStkAaveAction.js +5 -5
  9. package/src/actions/aave/AaveCollateralSwitchAction.js +5 -4
  10. package/src/actions/aave/AavePaybackAction.js +11 -2
  11. package/src/actions/aave/AaveSupplyAction.js +6 -6
  12. package/src/actions/aave/AaveWithdrawAction.js +8 -1
  13. package/src/actions/aaveV3/AaveV3ATokenPaybackAction.js +58 -0
  14. package/src/actions/aaveV3/AaveV3BorrowAction.js +59 -0
  15. package/src/actions/aaveV3/AaveV3ClaimRewardsAction.js +45 -0
  16. package/src/actions/aaveV3/AaveV3CollateralSwitchAction.js +45 -0
  17. package/src/actions/aaveV3/AaveV3PaybackAction.js +68 -0
  18. package/src/actions/aaveV3/AaveV3SetEModeAction.js +40 -0
  19. package/src/actions/aaveV3/AaveV3SupplyAction.js +69 -0
  20. package/src/actions/aaveV3/AaveV3SwapBorrowRateModeAction.js +43 -0
  21. package/src/actions/aaveV3/AaveV3WithdrawAction.js +46 -0
  22. package/src/actions/aaveV3/index.js +21 -0
  23. package/src/actions/balancer/BalancerV2ClaimAction.js +12 -10
  24. package/src/actions/balancer/BalancerV2SupplyAction.js +16 -14
  25. package/src/actions/balancer/BalancerV2WithdrawAction.js +17 -15
  26. package/src/actions/basic/AutomationV2Unsub.js +3 -3
  27. package/src/actions/basic/ChangeProxyOwnerAction.js +4 -2
  28. package/src/actions/basic/GasFeeAction.js +6 -6
  29. package/src/actions/basic/PullTokenAction.js +9 -3
  30. package/src/actions/basic/SellAction.js +17 -10
  31. package/src/actions/basic/SendTokenAction.js +9 -4
  32. package/src/actions/basic/SubInputsAction.js +8 -3
  33. package/src/actions/basic/SumInputsAction.js +8 -3
  34. package/src/actions/basic/TokenBalanceAction.js +3 -3
  35. package/src/actions/basic/UnwrapEthAction.js +18 -5
  36. package/src/actions/basic/WrapEthAction.js +15 -5
  37. package/src/actions/basic/index.js +0 -6
  38. package/src/actions/checkers/MakerRatioCheckAction.js +5 -5
  39. package/src/actions/compound/CompoundBorrowAction.js +7 -1
  40. package/src/actions/compound/CompoundClaimAction.js +3 -3
  41. package/src/actions/compound/CompoundCollateralSwitchAction.js +4 -2
  42. package/src/actions/compound/CompoundGetDebtAction.js +3 -3
  43. package/src/actions/compound/CompoundPaybackAction.js +7 -1
  44. package/src/actions/compound/CompoundSupplyAction.js +4 -4
  45. package/src/actions/compound/CompoundWithdrawAction.js +7 -1
  46. package/src/actions/curve/CurveClaimFeesAction.js +4 -4
  47. package/src/actions/curve/CurveDepositAction.js +7 -7
  48. package/src/actions/curve/CurveGaugeDepositAction.js +6 -6
  49. package/src/actions/curve/CurveGaugeWithdrawAction.js +4 -4
  50. package/src/actions/curve/CurveMintCrvAction.js +3 -3
  51. package/src/actions/curve/CurveStethPoolDepositAction.js +9 -9
  52. package/src/actions/curve/CurveStethPoolWithdrawAction.js +9 -11
  53. package/src/actions/curve/CurveSwapAction.js +15 -15
  54. package/src/actions/curve/CurveWithdrawAction.js +7 -7
  55. package/src/actions/dydx/DyDxWithdrawAction.js +7 -1
  56. package/src/actions/flashloan/AaveV2FlashLoanAction.js +2 -2
  57. package/src/actions/flashloan/AaveV3FlashLoanAction.js +26 -0
  58. package/src/actions/flashloan/AaveV3FlashLoanPaybackAction.js +17 -0
  59. package/src/actions/flashloan/BalancerFlashLoanAction.js +2 -2
  60. package/src/actions/flashloan/DyDxFlashLoanAction.js +1 -5
  61. package/src/actions/flashloan/MakerFlashLoanAction.js +2 -2
  62. package/src/actions/flashloan/index.js +4 -0
  63. package/src/actions/guni/GUniDeposit.js +9 -9
  64. package/src/actions/guni/GUniWithdraw.js +5 -5
  65. package/src/actions/index.js +2 -2
  66. package/src/actions/insta/InstPullTokensAction.js +4 -4
  67. package/src/actions/lido/LidoStakeAction.js +7 -2
  68. package/src/actions/lido/LidoUnwrapAction.js +7 -2
  69. package/src/actions/lido/LidoWrapAction.js +7 -7
  70. package/src/actions/liquity/LiquityBorrowAction.js +5 -5
  71. package/src/actions/liquity/LiquityClaimAction.js +3 -3
  72. package/src/actions/liquity/LiquityCloseAction.js +4 -4
  73. package/src/actions/liquity/LiquityEthGainToTroveAction.js +3 -3
  74. package/src/actions/liquity/LiquityOpenAction.js +8 -8
  75. package/src/actions/liquity/LiquityPaybackAction.js +5 -5
  76. package/src/actions/liquity/LiquityRedeemAction.js +7 -7
  77. package/src/actions/liquity/LiquitySPDepositAction.js +7 -7
  78. package/src/actions/liquity/LiquitySPWithdrawAction.js +6 -6
  79. package/src/actions/liquity/LiquityStakeAction.js +7 -7
  80. package/src/actions/liquity/LiquitySupplyAction.js +5 -5
  81. package/src/actions/liquity/LiquityUnstakeAction.js +6 -6
  82. package/src/actions/liquity/LiquityWithdrawAction.js +4 -4
  83. package/src/actions/maker/MakerClaimAction.js +4 -4
  84. package/src/actions/maker/MakerGenerateAction.js +8 -1
  85. package/src/actions/maker/MakerGiveAction.js +4 -4
  86. package/src/actions/maker/MakerMergeAction.js +7 -1
  87. package/src/actions/maker/MakerOpenVaultAction.js +6 -1
  88. package/src/actions/maker/MakerPaybackAction.js +9 -2
  89. package/src/actions/maker/MakerRatioAction.js +5 -1
  90. package/src/actions/maker/MakerSupplyAction.js +9 -1
  91. package/src/actions/maker/MakerWithdrawAction.js +9 -1
  92. package/src/actions/mstable/MStableClaimAction.js +4 -4
  93. package/src/actions/mstable/MStableDepositAction.js +16 -16
  94. package/src/actions/mstable/MStableWithdrawAction.js +15 -15
  95. package/src/actions/rari/RariDepositAction.js +5 -5
  96. package/src/actions/rari/RariWithdrawAction.js +6 -6
  97. package/src/actions/reflexer/ReflexerGenerateAction.js +7 -1
  98. package/src/actions/reflexer/ReflexerNativeUniV2SaviourDepositAction.js +5 -5
  99. package/src/actions/reflexer/ReflexerNativeUniV2SaviourGetReservesAction.js +8 -3
  100. package/src/actions/reflexer/ReflexerNativeUniV2SaviourWithdrawAction.js +9 -4
  101. package/src/actions/reflexer/ReflexerOpenSafeAction.js +5 -1
  102. package/src/actions/reflexer/ReflexerPaybackAction.js +7 -1
  103. package/src/actions/reflexer/ReflexerSupplyAction.js +8 -1
  104. package/src/actions/reflexer/ReflexerWithdrawAction.js +8 -1
  105. package/src/actions/uniswap/UniswapSupplyAction.js +22 -20
  106. package/src/actions/uniswap/UniswapWithdrawAction.js +18 -16
  107. package/src/actions/uniswapV3/UniswapV3CollectAction.js +9 -7
  108. package/src/actions/uniswapV3/UniswapV3CreatePoolAction.js +22 -20
  109. package/src/actions/uniswapV3/UniswapV3MintAction.js +21 -19
  110. package/src/actions/uniswapV3/UniswapV3SupplyAction.js +19 -17
  111. package/src/actions/uniswapV3/UniswapV3WithdrawAction.js +14 -12
  112. package/src/actions/yearn/YearnSupplyAction.js +6 -6
  113. package/src/actions/yearn/YearnWithdrawAction.js +6 -6
  114. package/src/addresses.js +217 -152
  115. package/src/config.js +83 -0
  116. package/src/triggers/ChainLinkPriceTrigger.js +2 -2
  117. package/src/triggers/CompoundRatioTrigger.js +1 -1
  118. package/src/triggers/GasPriceTrigger.js +1 -1
  119. package/src/triggers/LiquityRatioTrigger.js +2 -2
  120. package/src/triggers/MakerRatioTrigger.js +5 -1
  121. package/src/triggers/ReflexerRatioTrigger.js +1 -1
  122. package/src/triggers/TimestampTrigger.js +1 -1
  123. package/src/triggers/UniV3CurrentTickTrigger.js +1 -1
  124. package/src/types.js +33 -0
  125. package/test/Action.js +1 -2
  126. package/test/accessLists/access-lists.js +2 -1
  127. package/test/actions/maker/MakerPaybackAction.js +2 -2
  128. package/test/index.js +4 -1
  129. package/src/actions/basic/SendTokenAndUnwrapAction.js +0 -30
  130. package/src/actions/basic/ToggleSubAction.js +0 -19
  131. package/src/actions/basic/UpdateSubAction.js +0 -19
  132. package/src/actions/convex/ConvexClaimAction.js +0 -60
  133. package/src/actions/convex/ConvexDepositAction.js +0 -67
  134. package/src/actions/convex/ConvexWithdrawAction.js +0 -65
  135. package/src/actions/convex/index.js +0 -9
  136. package/src/utils/convex-utils.js +0 -20
  137. package/src/utils/convexPoolInfo.json +0 -1039
  138. package/test/Strategy.js +0 -44
package/DEV.md CHANGED
@@ -0,0 +1,298 @@
1
+ ## Modules
2
+
3
+ <dl>
4
+ <dt><a href="#utils.module_uniswapLP">uniswapLP</a></dt>
5
+ <dd></dd>
6
+ <dt><a href="#utils.module_uniV3">uniV3</a></dt>
7
+ <dd></dd>
8
+ <dt><a href="#utils.module_zeroExExchange">zeroExExchange</a></dt>
9
+ <dd></dd>
10
+ </dl>
11
+
12
+ ## Classes
13
+
14
+ <dl>
15
+ <dt><a href="#Action">Action</a></dt>
16
+ <dd><p>Single action that can be executed directly, or combined into a set (ie. supply a vault)</p>
17
+ </dd>
18
+ <dt><a href="#Recipe">Recipe</a></dt>
19
+ <dd><p>Set of Actions to be performed sequentially in a single transaction</p>
20
+ </dd>
21
+ </dl>
22
+
23
+ ## Typedefs
24
+
25
+ <dl>
26
+ <dt><a href="#EthAddress">EthAddress</a> : <code>string</code></dt>
27
+ <dd><p>Ethereum address</p>
28
+ </dd>
29
+ <dt><a href="#VaultId">VaultId</a> : <code>string</code> | <code>number</code></dt>
30
+ <dd><p>Maker vault ID</p>
31
+ </dd>
32
+ <dt><a href="#AccessListItem">AccessListItem</a> : <code>Object</code></dt>
33
+ <dd><p>Access list item</p>
34
+ </dd>
35
+ <dt><a href="#AccessList">AccessList</a> : <code><a href="#AccessListItem">Array.&lt;AccessListItem&gt;</a></code></dt>
36
+ <dd></dd>
37
+ </dl>
38
+
39
+ <a name="utils.module_uniswapLP"></a>
40
+
41
+ ## uniswapLP
42
+
43
+ * [uniswapLP](#utils.module_uniswapLP)
44
+ * [.getPoolAddressByAddresses(tokenA, tokenB)](#utils.module_uniswapLP.getPoolAddressByAddresses) ⇒ [<code>EthAddress</code>](#EthAddress)
45
+ * [.getPoolAddressBySymbols(symbolA, symbolB)](#utils.module_uniswapLP.getPoolAddressBySymbols) ⇒ [<code>EthAddress</code>](#EthAddress)
46
+
47
+ <a name="utils.module_uniswapLP.getPoolAddressByAddresses"></a>
48
+
49
+ ### uniswapLP.getPoolAddressByAddresses(tokenA, tokenB) ⇒ [<code>EthAddress</code>](#EthAddress)
50
+ Computes deterministic LP address.
51
+ Source: https://uniswap.org/docs/v2/javascript-SDK/getting-pair-addresses/#typescript
52
+
53
+ **Kind**: static method of [<code>uniswapLP</code>](#utils.module_uniswapLP)
54
+ **Params**
55
+
56
+ - tokenA [<code>EthAddress</code>](#EthAddress) - Use WETH for ETH
57
+ - tokenB [<code>EthAddress</code>](#EthAddress) - Use WETH for ETH
58
+
59
+ <a name="utils.module_uniswapLP.getPoolAddressBySymbols"></a>
60
+
61
+ ### uniswapLP.getPoolAddressBySymbols(symbolA, symbolB) ⇒ [<code>EthAddress</code>](#EthAddress)
62
+ **Kind**: static method of [<code>uniswapLP</code>](#utils.module_uniswapLP)
63
+ **Params**
64
+
65
+ - symbolA <code>string</code>
66
+ - symbolB <code>string</code>
67
+
68
+ <a name="utils.module_uniV3"></a>
69
+
70
+ ## uniV3
71
+ <a name="utils.module_uniV3.getAssetAddrByTokenId"></a>
72
+
73
+ ### uniV3.getAssetAddrByTokenId(web3, tokenId) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
74
+ **Kind**: static method of [<code>uniV3</code>](#utils.module_uniV3)
75
+ **Params**
76
+
77
+ - web3 <code>Object</code> - Web3 instance
78
+ - tokenId <code>string</code>
79
+
80
+ <a name="utils.module_zeroExExchange"></a>
81
+
82
+ ## zeroExExchange
83
+
84
+ * [zeroExExchange](#utils.module_zeroExExchange)
85
+ * [.estimateSellPrice(sellAmount, sellToken, buyToken)](#utils.module_zeroExExchange.estimateSellPrice) ⇒ <code>Promise.&lt;string&gt;</code>
86
+ * [.estimateBuyPrice(buyAmount, buyToken, sellToken)](#utils.module_zeroExExchange.estimateBuyPrice) ⇒ <code>Promise.&lt;string&gt;</code>
87
+ * [.createSellAction(sellAmount, sellToken, buyToken, expectedPrice, acceptedSlippagePercent, fromAccount, toAccount)](#utils.module_zeroExExchange.createSellAction) ⇒ <code>Promise.&lt;SellAction&gt;</code>
88
+
89
+ <a name="utils.module_zeroExExchange.estimateSellPrice"></a>
90
+
91
+ ### zeroExExchange.estimateSellPrice(sellAmount, sellToken, buyToken) ⇒ <code>Promise.&lt;string&gt;</code>
92
+ Gets price estimate for selling a specific amount.
93
+ Example: getBestExchangePrice('1', 'ETH', 'DAI') - swapping 1 ETH for some DAI
94
+
95
+ **Kind**: static method of [<code>zeroExExchange</code>](#utils.module_zeroExExchange)
96
+ **Returns**: <code>Promise.&lt;string&gt;</code> - price of sellToken in buyToken
97
+ **Params**
98
+
99
+ - sellAmount <code>String</code> - amount of sellToken (not in wei)
100
+ - sellToken <code>String</code> - Symbol for asset being sold
101
+ - buyToken <code>String</code> - Symbol for asset being bought
102
+
103
+ <a name="utils.module_zeroExExchange.estimateBuyPrice"></a>
104
+
105
+ ### zeroExExchange.estimateBuyPrice(buyAmount, buyToken, sellToken) ⇒ <code>Promise.&lt;string&gt;</code>
106
+ Gets price estimate for buying a specific amount.
107
+ Example: estimateBuyPrice('1000', 'DAI', 'ETH') - swapping 1000 DAI for some ETH
108
+
109
+ **Kind**: static method of [<code>zeroExExchange</code>](#utils.module_zeroExExchange)
110
+ **Returns**: <code>Promise.&lt;string&gt;</code> - price of sellToken in buyToken
111
+ **Params**
112
+
113
+ - buyAmount <code>String</code> - amount of buyToken (not in wei)
114
+ - buyToken <code>String</code> - Symbol for asset being bought
115
+ - sellToken <code>String</code> - Symbol for asset being sold
116
+
117
+ <a name="utils.module_zeroExExchange.createSellAction"></a>
118
+
119
+ ### zeroExExchange.createSellAction(sellAmount, sellToken, buyToken, expectedPrice, acceptedSlippagePercent, fromAccount, toAccount) ⇒ <code>Promise.&lt;SellAction&gt;</code>
120
+ Fetches prices and creates order ready to be passed to transaction.
121
+ This should only be called when before sending tx, not to be used for just querying the price.
122
+ For that purpose, the estimateSellPrice method can be used.
123
+
124
+ **Kind**: static method of [<code>zeroExExchange</code>](#utils.module_zeroExExchange)
125
+ **Params**
126
+
127
+ - sellAmount <code>string</code> - Amount of asset being sold ('1.5')
128
+ - sellToken <code>string</code> - Symbol for asset being sold ('ETH')
129
+ - buyToken <code>string</code> - Symbol for asset being bought ('DAI')
130
+ - expectedPrice <code>string</code> - Price received from estimatePrice (so minPrice can be calculated based on what user saw)
131
+ - acceptedSlippagePercent <code>string</code> | <code>Number</code> - Slippage percentage tolerated [0-100]
132
+ - fromAccount [<code>EthAddress</code>](#EthAddress) - Withdraw funds from this addr
133
+ - toAccount [<code>EthAddress</code>](#EthAddress) - Send funds to this addr
134
+
135
+
136
+ **Kind**: static method of [<code>zeroExExchange</code>](#utils.module_zeroExExchange)
137
+ **Params**
138
+
139
+ - buyAmount <code>string</code> - Amount of asset being bought ('1500.123')
140
+ - buyToken <code>string</code> - Symbol for asset being bought ('DAI')
141
+ - sellToken <code>string</code> - Symbol for asset being sold ('ETH')
142
+ - expectedPrice <code>string</code> - Price received from estimatePrice (so minPrice can be calculated based on what user saw)
143
+ - acceptedSlippagePercent <code>string</code> | <code>Number</code> - Slippage percentage tolerated [0-100]
144
+ - fromAccount [<code>EthAddress</code>](#EthAddress) - Withdraw funds from this addr
145
+ - toAccount [<code>EthAddress</code>](#EthAddress) - Send funds to this addr
146
+
147
+ <a name="Action"></a>
148
+
149
+ ## Action
150
+ Single action that can be executed directly, or combined into a set (ie. supply a vault)
151
+
152
+ **Kind**: global class
153
+
154
+ * [Action](#Action)
155
+ * [new Action(name, contractAddress, paramTypes, args)](#new_Action_new)
156
+ * [.encodeForDsProxyCall()](#Action+encodeForDsProxyCall) ⇒ <code>Array.&lt;string&gt;</code>
157
+ * [.encodeForRecipe()](#Action+encodeForRecipe) ⇒ <code>Array.&lt;string&gt;</code>
158
+ * [.getAssetsToApprove()](#Action+getAssetsToApprove) ⇒ <code>Promise.&lt;Array.&lt;{owner: string, asset: string}&gt;&gt;</code>
159
+ * [.getEthValue()](#Action+getEthValue) ⇒ <code>Promise.&lt;string&gt;</code>
160
+ * [.getAccessList()](#Action+getAccessList) ⇒ [<code>AccessList</code>](#AccessList)
161
+
162
+ <a name="new_Action_new"></a>
163
+
164
+ ### new Action(name, contractAddress, paramTypes, args)
165
+ **Params**
166
+
167
+ - name <code>string</code>
168
+ - contractAddress <code>string</code>
169
+ - paramTypes <code>Array.&lt;string&gt;</code>
170
+ - args <code>Array.&lt;\*&gt;</code>
171
+
172
+ <a name="Action+encodeForDsProxyCall"></a>
173
+
174
+ ### action.encodeForDsProxyCall() ⇒ <code>Array.&lt;string&gt;</code>
175
+ Encode arguments for calling the action via DsProxy
176
+
177
+ **Kind**: instance method of [<code>Action</code>](#Action)
178
+ **Returns**: <code>Array.&lt;string&gt;</code> - `address` & `data` to be passed on to DSProxy's `execute(address _target, bytes memory _data)`
179
+ <a name="Action+encodeForRecipe"></a>
180
+
181
+ ### action.encodeForRecipe() ⇒ <code>Array.&lt;string&gt;</code>
182
+ Encodes action for Recipe call
183
+
184
+ **Kind**: instance method of [<code>Action</code>](#Action)
185
+ <a name="Action+getAssetsToApprove"></a>
186
+
187
+ ### action.getAssetsToApprove() ⇒ <code>Promise.&lt;Array.&lt;{owner: string, asset: string}&gt;&gt;</code>
188
+ Assets requiring approval to be used by DsProxy
189
+ Approval is done from owner to DsProxy
190
+
191
+ **Kind**: instance method of [<code>Action</code>](#Action)
192
+ <a name="Action+getEthValue"></a>
193
+
194
+ ### action.getEthValue() ⇒ <code>Promise.&lt;string&gt;</code>
195
+ ETH value to be sent with transaction
196
+
197
+ **Kind**: instance method of [<code>Action</code>](#Action)
198
+ **Returns**: <code>Promise.&lt;string&gt;</code> - ETH value in wei
199
+ <a name="Action+getAccessList"></a>
200
+
201
+ ### action.getAccessList() ⇒ [<code>AccessList</code>](#AccessList)
202
+ Access list for single action
203
+
204
+ **Kind**: instance method of [<code>Action</code>](#Action)
205
+ <a name="Recipe"></a>
206
+
207
+ ## Recipe
208
+ Set of Actions to be performed sequentially in a single transaction
209
+
210
+ **Kind**: global class
211
+
212
+ * [Recipe](#Recipe)
213
+ * [new Recipe(name, actions)](#new_Recipe_new)
214
+ * [.addAction(action)](#Recipe+addAction) ⇒ [<code>Recipe</code>](#Recipe)
215
+ * [.encodeForDsProxyCall()](#Recipe+encodeForDsProxyCall) ⇒ <code>Array.&lt;string&gt;</code>
216
+ * [._validateParamMappings()](#Recipe+_validateParamMappings)
217
+ * [.getAssetsToApprove()](#Recipe+getAssetsToApprove) ⇒ <code>Promise.&lt;Array.&lt;{owner: string, asset: string}&gt;&gt;</code>
218
+ * [.getEthValue()](#Recipe+getEthValue) ⇒ <code>Promise.&lt;string&gt;</code>
219
+ * [.getAccessList()](#Recipe+getAccessList) ⇒ [<code>AccessList</code>](#AccessList)
220
+
221
+ <a name="new_Recipe_new"></a>
222
+
223
+ ### new Recipe(name, actions)
224
+ **Params**
225
+
226
+ - name <code>string</code>
227
+ - actions [<code>Array.&lt;Action&gt;</code>](#Action)
228
+
229
+ <a name="Recipe+addAction"></a>
230
+
231
+ ### recipe.addAction(action) ⇒ [<code>Recipe</code>](#Recipe)
232
+ **Kind**: instance method of [<code>Recipe</code>](#Recipe)
233
+ **Params**
234
+
235
+ - action [<code>Action</code>](#Action)
236
+
237
+ <a name="Recipe+encodeForDsProxyCall"></a>
238
+
239
+ ### recipe.encodeForDsProxyCall() ⇒ <code>Array.&lt;string&gt;</code>
240
+ Encode arguments for calling the action set via DsProxy
241
+
242
+ **Kind**: instance method of [<code>Recipe</code>](#Recipe)
243
+ **Returns**: <code>Array.&lt;string&gt;</code> - `address` & `data` to be passed on to DSProxy's `execute(address _target, bytes memory _data)`
244
+ <a name="Recipe+_validateParamMappings"></a>
245
+
246
+ ### recipe.\_validateParamMappings()
247
+ Logs parameter mapping in verbose format for validation. Used for testing in development.
248
+
249
+ **Kind**: instance method of [<code>Recipe</code>](#Recipe)
250
+ <a name="Recipe+getAssetsToApprove"></a>
251
+
252
+ ### recipe.getAssetsToApprove() ⇒ <code>Promise.&lt;Array.&lt;{owner: string, asset: string}&gt;&gt;</code>
253
+ Assets requiring approval to be used by DsProxy
254
+ Approval is done from owner to DsProxy
255
+
256
+ **Kind**: instance method of [<code>Recipe</code>](#Recipe)
257
+ <a name="Recipe+getEthValue"></a>
258
+
259
+ ### recipe.getEthValue() ⇒ <code>Promise.&lt;string&gt;</code>
260
+ ETH value to be sent with transaction
261
+
262
+ **Kind**: instance method of [<code>Recipe</code>](#Recipe)
263
+ **Returns**: <code>Promise.&lt;string&gt;</code> - ETH value in wei
264
+ <a name="Recipe+getAccessList"></a>
265
+
266
+ ### recipe.getAccessList() ⇒ [<code>AccessList</code>](#AccessList)
267
+ Generates an access list for the recipe
268
+
269
+ **Kind**: instance method of [<code>Recipe</code>](#Recipe)
270
+ <a name="EthAddress"></a>
271
+
272
+ ## EthAddress : <code>string</code>
273
+ Ethereum address
274
+
275
+ **Kind**: global typedef
276
+ <a name="VaultId"></a>
277
+
278
+ ## VaultId : <code>string</code> \| <code>number</code>
279
+ Maker vault ID
280
+
281
+ **Kind**: global typedef
282
+ <a name="AccessListItem"></a>
283
+
284
+ ## AccessListItem : <code>Object</code>
285
+ Access list item
286
+
287
+ **Kind**: global typedef
288
+ **Properties**
289
+
290
+ | Name | Type |
291
+ | --- | --- |
292
+ | address | <code>string</code> |
293
+ | storageKeys | <code>Array.&lt;string&gt;</code> |
294
+
295
+ <a name="AccessList"></a>
296
+
297
+ ## AccessList : [<code>Array.&lt;AccessListItem&gt;</code>](#AccessListItem)
298
+ **Kind**: global typedef
package/index.js CHANGED
@@ -2,6 +2,9 @@ const Action = require('./src/Action');
2
2
  const Recipe = require('./src/Recipe');
3
3
  const Strategy = require('./src/Strategy');
4
4
  const DfsWeb3 = require('./src/DfsWeb3');
5
+ const {
6
+ configure, getNetworkData, CONFIG, NETWORKS,
7
+ } = require('./src/config');
5
8
 
6
9
  const actions = require('./src/actions/');
7
10
  const triggers = require('./src/triggers/');
@@ -12,9 +15,15 @@ module.exports = {
12
15
  Action,
13
16
  Recipe,
14
17
  Strategy,
18
+ DfsWeb3,
19
+
15
20
  actions,
16
21
  triggers,
17
- actionAddresses,
18
22
  utils,
19
- DfsWeb3,
23
+
24
+ configure,
25
+ getNetworkData,
26
+ networks: NETWORKS,
27
+ actionAddressesAllChains: actionAddresses,
28
+ actionAddresses: () => actionAddresses[CONFIG.chainId],
20
29
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/sdk",
3
- "version": "0.2.7",
3
+ "version": "0.2.10",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "repository": "https://github.com/DecenterApps/defisaver-sdk",
14
14
  "license": "ISC",
15
15
  "dependencies": {
16
- "@defisaver/tokens": "^1.4.12",
16
+ "@defisaver/tokens": "^1.4.7",
17
17
  "@ethersproject/address": "^5.0.10",
18
18
  "@ethersproject/solidity": "^5.0.9",
19
19
  "axios": "^0.21.1",
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
 
@@ -107,9 +108,16 @@ class Action {
107
108
  * @private
108
109
  */
109
110
  _encodeForCall() {
110
- let _arg = this._replaceWithPlaceholders(this.args, this.paramTypes);
111
- let _paramType = this._formatType(this.paramTypes);
112
- return [AbiCoder.encodeParameter(_paramType, _arg)];
111
+ return this.args.map((arg, i) => {
112
+ let paramType = this.paramTypes[i];
113
+ let _arg = this._replaceWithPlaceholders(arg, paramType);
114
+ let _paramType = this._formatType(paramType);
115
+ return AbiCoder.encodeParameter(_paramType, _arg);
116
+ });
117
+ }
118
+
119
+ encodeForL2DsProxyCall() {
120
+ throw new Error('Not L2'); // TODO improve this
113
121
  }
114
122
 
115
123
  /**
@@ -117,11 +125,15 @@ class Action {
117
125
  * @returns {Array<string>} `address` & `data` to be passed on to DSProxy's `execute(address _target, bytes memory _data)`
118
126
  */
119
127
  encodeForDsProxyCall() {
120
- const executeActionDirectAbi = ActionAbi.find(({ name }) => name === 'executeActionDirect');
121
- return [
122
- this.contractAddress,
123
- AbiCoder.encodeFunctionCall(executeActionDirectAbi, this._encodeForCall()),
124
- ];
128
+ if (CONFIG.chainId === 1) {
129
+ const executeActionDirectAbi = ActionAbi.find(({ name }) => name === 'executeActionDirect');
130
+ return [
131
+ this.contractAddress,
132
+ AbiCoder.encodeFunctionCall(executeActionDirectAbi, this._encodeForCall()),
133
+ ];
134
+ } else {
135
+ return [this.contractAddress, this.encodeForL2DsProxyCall()];
136
+ }
125
137
  }
126
138
 
127
139
  /**
@@ -0,0 +1,36 @@
1
+ const Action = require('./Action');
2
+ const Dec = require('decimal.js');
3
+
4
+ class ActionWithL2 extends Action {
5
+ /**
6
+ * Encode arguments for calling the action via DsProxy
7
+ * @returns {string}
8
+ */
9
+ encodeForL2DsProxyCall() { return this.encodeInputs(); }
10
+
11
+ encodeInputs() { throw new Error('Use implementation from specific ActionWithL2'); }
12
+
13
+ addressToBytes20(address) { return address.slice(2); }
14
+
15
+ boolToBytes1(bool) { return bool ? '01' : '00' }
16
+
17
+ async getEthValue() { return '0'; }
18
+
19
+ numberToBytes2(number){
20
+ const hexNumber = number.toString(16);
21
+ return hexNumber.padStart(4, '0');
22
+ }
23
+
24
+ numberToBytes1(number){
25
+ const hexNumber = number.toString(16);
26
+ return hexNumber.padStart(2, '0');
27
+ }
28
+
29
+ numberToBytes32(number){
30
+ let hexNumber = new Dec(number).toHex();
31
+ hexNumber = hexNumber.slice(2);
32
+
33
+ return hexNumber.padStart(64, '0');
34
+ }
35
+ }
36
+ module.exports = ActionWithL2;
@@ -19,9 +19,18 @@ class AaveBorrowAction extends Action {
19
19
  super(
20
20
  'AaveBorrow',
21
21
  getAddr('AaveBorrow'),
22
- ['address', 'address', 'uint256', 'uint256', 'address', 'address'],
23
- [market, tokenAddr, amount, rateMode, to, onBehalf],
22
+ [['address', 'address', 'uint256', 'uint256', 'address', 'address']],
23
+ [[market, tokenAddr, amount, rateMode, to, onBehalf]],
24
24
  );
25
+
26
+ this.mappableArgs = [
27
+ this.args[0][0],
28
+ this.args[0][1],
29
+ this.args[0][2],
30
+ this.args[0][3],
31
+ this.args[0][4],
32
+ this.args[0][5],
33
+ ];
25
34
  }
26
35
  }
27
36
 
@@ -11,13 +11,13 @@ class AaveClaimStkAaveAction extends Action {
11
11
  super(
12
12
  'AaveClaimStkAave',
13
13
  getAddr('AaveClaimStkAave'),
14
- ['address[]', 'uint256', 'address'],
15
- [...arguments],
14
+ [['address[]', 'uint256', 'address']],
15
+ [[...arguments]],
16
16
  );
17
17
  this.mappableArgs = [
18
- this.args[1],
19
- this.args[2],
20
- ];
18
+ this.args[0][1],
19
+ this.args[0][2],
20
+ ];
21
21
  }
22
22
  }
23
23
 
@@ -1,6 +1,6 @@
1
1
  const Action = require("../../Action");
2
2
  const {requireAddress} = require("../../utils/general.js");
3
- const {getAddr} = require('../../addresses.js');
3
+ const { getAddr } = require('../../addresses.js');
4
4
 
5
5
  /**
6
6
  * AaveCollateralSwitchAction - Aave enable/disable token usage as collateral
@@ -10,10 +10,11 @@ class AaveCollateralSwitchAction extends Action {
10
10
  super(
11
11
  'AaveCollateralSwitch',
12
12
  getAddr('AaveCollateralSwitch'),
13
- ['address', 'address[]', 'bool[]'],
14
- [...arguments],
13
+ [['address', 'address[]', 'bool[]']],
14
+ [[...arguments]],
15
15
  );
16
- this.mappableArgs = [];
16
+ this.mappableArgs = [
17
+ ];
17
18
  }
18
19
  }
19
20
 
@@ -17,9 +17,18 @@ class AavePaybackAction extends Action {
17
17
  constructor(market, tokenAddr, amount, rateMode, from, onBehalf = getAddr('Empty')) {
18
18
  super('AavePayback',
19
19
  getAddr('AavePayback'),
20
- ['address', 'address', 'uint256', 'uint256', 'address', 'address'],
21
- [market, tokenAddr, amount, rateMode, from, onBehalf],
20
+ [['address', 'address', 'uint256', 'uint256', 'address', 'address']],
21
+ [[market, tokenAddr, amount, rateMode, from, onBehalf]],
22
22
  );
23
+
24
+ this.mappableArgs = [
25
+ this.args[0][0],
26
+ this.args[0][1],
27
+ this.args[0][2],
28
+ this.args[0][3],
29
+ this.args[0][4],
30
+ this.args[0][5],
31
+ ];
23
32
  }
24
33
 
25
34
  async getAssetsToApprove() {
@@ -15,14 +15,14 @@ class AaveSupplyAction extends Action {
15
15
  * @param enableAsColl {boolean} If we need to enable asset as collateral
16
16
  */
17
17
  constructor(market, tokenAddr, amount, from, onBehalf = getAddr('Empty'), enableAsColl) {
18
- super('AaveSupply', getAddr('AaveSupply'), ['address','address','uint256','address','address','bool'], [market, tokenAddr, amount, from, onBehalf, enableAsColl]);
18
+ super('AaveSupply', getAddr('AaveSupply'), [['address','address','uint256','address','address','bool']], [[market, tokenAddr, amount, from, onBehalf, enableAsColl]]);
19
19
 
20
20
  this.mappableArgs = [
21
- this.args[0],
22
- this.args[1],
23
- this.args[2],
24
- this.args[3],
25
- this.args[4],
21
+ this.args[0][0],
22
+ this.args[0][1],
23
+ this.args[0][2],
24
+ this.args[0][3],
25
+ this.args[0][4],
26
26
  ];
27
27
  }
28
28
 
@@ -14,7 +14,14 @@ class AaveWithdrawAction extends Action {
14
14
  */
15
15
  constructor(market, tokenAddr, amount, to) {
16
16
  requireAddress(to);
17
- super('AaveWithdraw', getAddr('AaveWithdraw'), ['address','address','uint256','address'], [...arguments]);
17
+ super('AaveWithdraw', getAddr('AaveWithdraw'), [['address','address','uint256','address']], [[...arguments]]);
18
+
19
+ this.mappableArgs = [
20
+ this.args[0][0],
21
+ this.args[0][1],
22
+ this.args[0][2],
23
+ this.args[0][3],
24
+ ];
18
25
  }
19
26
  }
20
27
 
@@ -0,0 +1,58 @@
1
+ const ActionWithL2 = require("../../ActionWithL2");
2
+ const { getAssetInfoByAddress } = require("@defisaver/tokens");
3
+ const { getAddr } = require('../../addresses.js');
4
+
5
+ /**
6
+ * AaveV3ATokenPaybackAction - Repay Aave V3 debt using aTokens
7
+ */
8
+ class AaveV3ATokenPaybackAction extends ActionWithL2 {
9
+ /**
10
+ * @param useDefaultMarket {boolean} If this is true it defaults to the hardcoded market in contract
11
+ * @param market {EthAddress} Address provider for specific market
12
+ * @param amount {string} Amount of tokens to be payed back (uint.max for full debt)
13
+ * @param from {EthAddress} Where are we pulling the payback aTokens from
14
+ * @param rateMode {number} Type of borrow debt [Stable: 1, Variable: 2]
15
+ * @param aTokenAddr {EthAddress} address of the aToken to be pulled
16
+ * @param assetId {number} The id of the underlying asset to be repaid
17
+ */
18
+ constructor(useDefaultMarket, market, amount, from, rateMode, aTokenAddr, assetId) {
19
+ super('AaveV3ATokenPayback', getAddr('AaveV3ATokenPayback'),
20
+ [['uint256','address','uint8','uint16', 'bool', 'address']],
21
+ [[amount, from, rateMode, assetId, useDefaultMarket, market]]
22
+ );
23
+
24
+ this.mappableArgs = [
25
+ this.args[0][0],
26
+ this.args[0][1],
27
+ this.args[0][5],
28
+ ];
29
+ this.addressForApproval = aTokenAddr;
30
+ }
31
+
32
+ async getAssetsToApprove() {
33
+ const asset = getAssetInfoByAddress(this.addressForApproval);
34
+ if (asset.symbol !== 'ETH') return [{asset: this.addressForApproval, owner: this.args[0][2]}];
35
+ return [];
36
+ }
37
+ encodeInputs() {
38
+ // executeActionDirectL2
39
+ let encodedInput = "0x2895f3aa";
40
+ // amount
41
+ encodedInput = encodedInput.concat(this.numberToBytes32(this.args[0][0]));
42
+ // from
43
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][1]));
44
+ // rateMode
45
+ encodedInput = encodedInput.concat(this.numberToBytes1(this.args[0][2]));
46
+ // assetId
47
+ encodedInput = encodedInput.concat(this.numberToBytes2(this.args[0][3]));
48
+ // useDefaultMarket
49
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][4]))
50
+ if (!this.args[0][4]){
51
+ // market
52
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][5]));
53
+ }
54
+ return encodedInput;
55
+ }
56
+ }
57
+
58
+ module.exports = AaveV3ATokenPaybackAction;
@@ -0,0 +1,59 @@
1
+ const ActionWithL2 = require("../../ActionWithL2");
2
+ const { getAddr } = require('../../addresses.js');
3
+
4
+ /**
5
+ * AaveV3BorrowAction - Borrow a token from AaveV3
6
+ */
7
+ class AaveV3BorrowAction extends ActionWithL2 {
8
+ /**
9
+ * @param useDefaultMarket {boolean} If this is true it defaults to the hardcoded market in contract
10
+ * @param market {EthAddress} Address provider for specific market
11
+ * @param amount {string} Amount of tokens to be borrowed
12
+ * @param to {EthAddress} The address we are sending the borrowed tokens to
13
+ * @param rateMode {number} Type of borrow debt [Stable: 1, Variable: 2]
14
+ * @param assetId {number} The id of the token to be borrowed
15
+ * @param useOnBehalf {boolean} use on behalf or default to proxy
16
+ * @param [onBehalf] {EthAddress} On whose behalf we borrow the tokens, defaults to proxy
17
+ */
18
+ constructor(useDefaultMarket, market, amount, to, rateMode, assetId, useOnBehalf , onBehalf = getAddr('Empty')) {
19
+ super('AaveV3Borrow', getAddr('AaveV3Borrow'),
20
+ [['uint256','address','uint8','uint16','bool','bool','address','address']],
21
+ [[amount, to, rateMode, assetId, useDefaultMarket, useOnBehalf, market, onBehalf]]
22
+ );
23
+
24
+ this.mappableArgs = [
25
+ this.args[0][0],
26
+ this.args[0][1],
27
+ this.args[0][6],
28
+ this.args[0][7],
29
+ ];
30
+ }
31
+
32
+ encodeInputs() {
33
+ // executeActionDirectL2
34
+ let encodedInput = "0x2895f3aa";
35
+ // amount
36
+ encodedInput = encodedInput.concat(this.numberToBytes32(this.args[0][0]));
37
+ // to
38
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][1]));
39
+ // rateMode
40
+ encodedInput = encodedInput.concat(this.numberToBytes1(this.args[0][2]));
41
+ // assetId
42
+ encodedInput = encodedInput.concat(this.numberToBytes2(this.args[0][3]));
43
+ // useDefaultMarket
44
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][4]))
45
+ // useOnBehalf
46
+ encodedInput = encodedInput.concat(this.boolToBytes1(this.args[0][5]));
47
+ if (!this.args[0][4]) {
48
+ // market
49
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][6]));
50
+ }
51
+ if (this.args[0][5]) {
52
+ // onBehalf
53
+ encodedInput = encodedInput.concat(this.addressToBytes20(this.args[0][7]));
54
+ }
55
+ return encodedInput;
56
+ }
57
+ }
58
+
59
+ module.exports = AaveV3BorrowAction;