@defisaver/automation-sdk 3.1.9 → 3.1.14-spark-dev
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.
- package/.babelrc +3 -3
- package/.editorconfig +9 -9
- package/.env.dev +4 -4
- package/.eslintignore +6 -6
- package/.eslintrc.js +39 -39
- package/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/README.md +46 -46
- package/cjs/abis/Erc20.json +223 -223
- package/cjs/abis/SubStorage.json +21 -21
- package/cjs/abis/UniMulticall.json +17 -17
- package/cjs/abis/index.d.ts +9 -9
- package/cjs/abis/index.js +30 -30
- package/cjs/abis/legacy_AaveV2Subscriptions.json +8 -8
- package/cjs/abis/legacy_AuthCheck.json +8 -8
- package/cjs/abis/legacy_CompoundV2Subscriptions.json +9 -9
- package/cjs/abis/legacy_MakerSubscriptions.json +9 -9
- package/cjs/automation/private/Automation.d.ts +12 -12
- package/cjs/automation/private/Automation.js +42 -42
- package/cjs/automation/private/LegacyAutomation.d.ts +25 -25
- package/cjs/automation/private/LegacyAutomation.js +118 -118
- package/cjs/automation/private/LegacyProtocol.d.ts +22 -22
- package/cjs/automation/private/LegacyProtocol.js +41 -41
- package/cjs/automation/private/LegacyProtocol.test.d.ts +1 -1
- package/cjs/automation/private/LegacyProtocol.test.js +25 -25
- package/cjs/automation/private/Protocol.d.ts +22 -22
- package/cjs/automation/private/Protocol.js +41 -41
- package/cjs/automation/private/Protocol.test.d.ts +1 -1
- package/cjs/automation/private/Protocol.test.js +25 -25
- package/cjs/automation/private/StrategiesAutomation.d.ts +35 -33
- package/cjs/automation/private/StrategiesAutomation.js +198 -181
- package/cjs/automation/private/StrategiesAutomation.test.d.ts +1 -1
- package/cjs/automation/private/StrategiesAutomation.test.js +696 -671
- package/cjs/automation/public/ArbitrumStrategies.d.ts +5 -5
- package/cjs/automation/public/ArbitrumStrategies.js +13 -13
- package/cjs/automation/public/BaseStrategies.d.ts +5 -5
- package/cjs/automation/public/BaseStrategies.js +13 -13
- package/cjs/automation/public/EthereumStrategies.d.ts +5 -5
- package/cjs/automation/public/EthereumStrategies.js +13 -13
- package/cjs/automation/public/OptimismStrategies.d.ts +5 -5
- package/cjs/automation/public/OptimismStrategies.js +13 -13
- package/cjs/automation/public/Strategies.test.d.ts +1 -1
- package/cjs/automation/public/Strategies.test.js +61 -61
- package/cjs/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
- package/cjs/automation/public/legacy/LegacyAaveAutomation.js +20 -20
- package/cjs/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
- package/cjs/automation/public/legacy/LegacyCompoundAutomation.js +20 -20
- package/cjs/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
- package/cjs/automation/public/legacy/LegacyMakerAutomation.js +20 -20
- package/cjs/configuration.d.ts +1 -1
- package/cjs/configuration.js +12 -12
- package/cjs/constants/index.d.ts +29 -28
- package/cjs/constants/index.js +905 -534
- package/cjs/index.d.ts +24 -23
- package/cjs/index.js +65 -65
- package/cjs/services/contractService.d.ts +12 -12
- package/cjs/services/contractService.js +54 -54
- package/cjs/services/ethereumService.d.ts +7 -7
- package/cjs/services/ethereumService.js +56 -49
- package/cjs/services/ethereumService.test.d.ts +1 -1
- package/cjs/services/ethereumService.test.js +245 -242
- package/cjs/services/strategiesService.d.ts +2 -2
- package/cjs/services/strategiesService.js +1173 -861
- package/cjs/services/strategiesService.test.d.ts +1 -1
- package/cjs/services/strategiesService.test.js +111 -110
- package/cjs/services/strategySubService.d.ts +129 -107
- package/cjs/services/strategySubService.js +414 -300
- package/cjs/services/strategySubService.test.d.ts +1 -1
- package/cjs/services/strategySubService.test.js +1812 -936
- package/cjs/services/subDataService.d.ts +527 -245
- package/cjs/services/subDataService.js +1219 -636
- package/cjs/services/subDataService.test.d.ts +1 -1
- package/cjs/services/subDataService.test.js +2427 -1282
- package/cjs/services/triggerService.d.ts +325 -226
- package/cjs/services/triggerService.js +616 -433
- package/cjs/services/triggerService.test.d.ts +1 -1
- package/cjs/services/triggerService.test.js +1317 -926
- package/cjs/services/utils.d.ts +30 -30
- package/cjs/services/utils.js +190 -182
- package/cjs/services/utils.test.d.ts +1 -1
- package/cjs/services/utils.test.js +299 -376
- package/cjs/types/contracts/generated/Erc20.d.ts +53 -53
- package/cjs/types/contracts/generated/Erc20.js +5 -5
- package/cjs/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
- package/cjs/types/contracts/generated/Legacy_AaveV2Subscriptions.js +5 -5
- package/cjs/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
- package/cjs/types/contracts/generated/Legacy_AuthCheck.js +5 -5
- package/cjs/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
- package/cjs/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +5 -5
- package/cjs/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
- package/cjs/types/contracts/generated/Legacy_MakerSubscriptions.js +5 -5
- package/cjs/types/contracts/generated/SubStorage.d.ts +114 -114
- package/cjs/types/contracts/generated/SubStorage.js +5 -5
- package/cjs/types/contracts/generated/UniMulticall.d.ts +55 -55
- package/cjs/types/contracts/generated/UniMulticall.js +5 -5
- package/cjs/types/contracts/generated/index.d.ts +7 -7
- package/cjs/types/contracts/generated/index.js +2 -2
- package/cjs/types/contracts/generated/types.d.ts +54 -54
- package/cjs/types/contracts/generated/types.js +2 -2
- package/cjs/types/enums.d.ts +302 -219
- package/cjs/types/enums.js +328 -245
- package/cjs/types/index.d.ts +306 -248
- package/cjs/types/index.js +2 -2
- package/esm/abis/Erc20.json +223 -223
- package/esm/abis/SubStorage.json +21 -21
- package/esm/abis/UniMulticall.json +17 -17
- package/esm/abis/index.d.ts +9 -9
- package/esm/abis/index.js +18 -18
- package/esm/abis/legacy_AaveV2Subscriptions.json +8 -8
- package/esm/abis/legacy_AuthCheck.json +8 -8
- package/esm/abis/legacy_CompoundV2Subscriptions.json +9 -9
- package/esm/abis/legacy_MakerSubscriptions.json +9 -9
- package/esm/automation/private/Automation.d.ts +12 -12
- package/esm/automation/private/Automation.js +39 -39
- package/esm/automation/private/LegacyAutomation.d.ts +25 -25
- package/esm/automation/private/LegacyAutomation.js +112 -112
- package/esm/automation/private/LegacyProtocol.d.ts +22 -22
- package/esm/automation/private/LegacyProtocol.js +38 -38
- package/esm/automation/private/LegacyProtocol.test.d.ts +1 -1
- package/esm/automation/private/LegacyProtocol.test.js +20 -20
- package/esm/automation/private/Protocol.d.ts +22 -22
- package/esm/automation/private/Protocol.js +38 -38
- package/esm/automation/private/Protocol.test.d.ts +1 -1
- package/esm/automation/private/Protocol.test.js +20 -20
- package/esm/automation/private/StrategiesAutomation.d.ts +35 -33
- package/esm/automation/private/StrategiesAutomation.js +192 -175
- package/esm/automation/private/StrategiesAutomation.test.d.ts +1 -1
- package/esm/automation/private/StrategiesAutomation.test.js +691 -666
- package/esm/automation/public/ArbitrumStrategies.d.ts +5 -5
- package/esm/automation/public/ArbitrumStrategies.js +7 -7
- package/esm/automation/public/BaseStrategies.d.ts +5 -5
- package/esm/automation/public/BaseStrategies.js +7 -7
- package/esm/automation/public/EthereumStrategies.d.ts +5 -5
- package/esm/automation/public/EthereumStrategies.js +7 -7
- package/esm/automation/public/OptimismStrategies.d.ts +5 -5
- package/esm/automation/public/OptimismStrategies.js +7 -7
- package/esm/automation/public/Strategies.test.d.ts +1 -1
- package/esm/automation/public/Strategies.test.js +56 -56
- package/esm/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
- package/esm/automation/public/legacy/LegacyAaveAutomation.js +14 -14
- package/esm/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
- package/esm/automation/public/legacy/LegacyCompoundAutomation.js +14 -14
- package/esm/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
- package/esm/automation/public/legacy/LegacyMakerAutomation.js +14 -14
- package/esm/configuration.d.ts +1 -1
- package/esm/configuration.js +7 -7
- package/esm/constants/index.d.ts +29 -28
- package/esm/constants/index.js +899 -528
- package/esm/index.d.ts +24 -23
- package/esm/index.js +23 -23
- package/esm/services/contractService.d.ts +12 -12
- package/esm/services/contractService.js +45 -45
- package/esm/services/ethereumService.d.ts +7 -7
- package/esm/services/ethereumService.js +48 -41
- package/esm/services/ethereumService.test.d.ts +1 -1
- package/esm/services/ethereumService.test.js +240 -237
- package/esm/services/strategiesService.d.ts +2 -2
- package/esm/services/strategiesService.js +1143 -831
- package/esm/services/strategiesService.test.d.ts +1 -1
- package/esm/services/strategiesService.test.js +109 -108
- package/esm/services/strategySubService.d.ts +129 -107
- package/esm/services/strategySubService.js +385 -271
- package/esm/services/strategySubService.test.d.ts +1 -1
- package/esm/services/strategySubService.test.js +1784 -908
- package/esm/services/subDataService.d.ts +527 -245
- package/esm/services/subDataService.js +1213 -630
- package/esm/services/subDataService.test.d.ts +1 -1
- package/esm/services/subDataService.test.js +2399 -1254
- package/esm/services/triggerService.d.ts +325 -226
- package/esm/services/triggerService.js +587 -404
- package/esm/services/triggerService.test.d.ts +1 -1
- package/esm/services/triggerService.test.js +1292 -901
- package/esm/services/utils.d.ts +30 -30
- package/esm/services/utils.js +139 -131
- package/esm/services/utils.test.d.ts +1 -1
- package/esm/services/utils.test.js +297 -348
- package/esm/types/contracts/generated/Erc20.d.ts +53 -53
- package/esm/types/contracts/generated/Erc20.js +4 -4
- package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
- package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +4 -4
- package/esm/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
- package/esm/types/contracts/generated/Legacy_AuthCheck.js +4 -4
- package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
- package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +4 -4
- package/esm/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
- package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +4 -4
- package/esm/types/contracts/generated/SubStorage.d.ts +114 -114
- package/esm/types/contracts/generated/SubStorage.js +4 -4
- package/esm/types/contracts/generated/UniMulticall.d.ts +55 -55
- package/esm/types/contracts/generated/UniMulticall.js +4 -4
- package/esm/types/contracts/generated/index.d.ts +7 -7
- package/esm/types/contracts/generated/index.js +1 -1
- package/esm/types/contracts/generated/types.d.ts +54 -54
- package/esm/types/contracts/generated/types.js +1 -1
- package/esm/types/enums.d.ts +302 -219
- package/esm/types/enums.js +325 -242
- package/esm/types/index.d.ts +306 -248
- package/esm/types/index.js +1 -1
- package/package.json +60 -61
- package/scripts/generateContractTypes.js +39 -39
- package/src/abis/Erc20.json +222 -222
- package/src/abis/SubStorage.json +21 -21
- package/src/abis/UniMulticall.json +17 -17
- package/src/abis/index.ts +28 -28
- package/src/abis/legacy_AaveV2Subscriptions.json +7 -7
- package/src/abis/legacy_AuthCheck.json +7 -7
- package/src/abis/legacy_CompoundV2Subscriptions.json +8 -8
- package/src/abis/legacy_MakerSubscriptions.json +8 -8
- package/src/automation/private/Automation.ts +44 -44
- package/src/automation/private/LegacyAutomation.ts +135 -135
- package/src/automation/private/LegacyProtocol.test.ts +23 -23
- package/src/automation/private/LegacyProtocol.ts +51 -51
- package/src/automation/private/Protocol.test.ts +23 -23
- package/src/automation/private/Protocol.ts +51 -51
- package/src/automation/private/StrategiesAutomation.test.ts +703 -663
- package/src/automation/private/StrategiesAutomation.ts +265 -242
- package/src/automation/public/ArbitrumStrategies.ts +10 -10
- package/src/automation/public/BaseStrategies.ts +10 -10
- package/src/automation/public/EthereumStrategies.ts +10 -10
- package/src/automation/public/OptimismStrategies.ts +10 -10
- package/src/automation/public/Strategies.test.ts +49 -49
- package/src/automation/public/legacy/LegacyAaveAutomation.ts +20 -20
- package/src/automation/public/legacy/LegacyCompoundAutomation.ts +20 -20
- package/src/automation/public/legacy/LegacyMakerAutomation.ts +20 -20
- package/src/configuration.ts +8 -8
- package/src/constants/index.ts +935 -563
- package/src/index.ts +41 -39
- package/src/services/contractService.ts +77 -77
- package/src/services/ethereumService.test.ts +260 -257
- package/src/services/ethereumService.ts +76 -69
- package/src/services/strategiesService.test.ts +106 -105
- package/src/services/strategiesService.ts +1473 -1111
- package/src/services/strategySubService.test.ts +2136 -1122
- package/src/services/strategySubService.ts +987 -617
- package/src/services/subDataService.test.ts +2630 -1387
- package/src/services/subDataService.ts +1631 -870
- package/src/services/triggerService.test.ts +1434 -1004
- package/src/services/triggerService.ts +819 -553
- package/src/services/utils.test.ts +371 -430
- package/src/services/utils.ts +173 -162
- package/src/types/enums.ts +322 -239
- package/src/types/index.ts +385 -312
- package/tsconfig.esm.json +8 -8
- package/tsconfig.json +22 -22
- package/umd/index.js +0 -34103
|
@@ -1,617 +1,987 @@
|
|
|
1
|
-
import Dec from 'decimal.js';
|
|
2
|
-
import { getAssetInfo } from '@defisaver/tokens';
|
|
3
|
-
|
|
4
|
-
import type { OrderType } from '../types/enums';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
Bundles,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
new Dec(
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
proxyAddress
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
proxyAddress
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
) {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
return
|
|
259
|
-
},
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
return [
|
|
397
|
-
},
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
isBundle
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
) {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
const
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import { getAssetInfo } from '@defisaver/tokens';
|
|
3
|
+
|
|
4
|
+
import type { OrderType } from '../types/enums';
|
|
5
|
+
import {
|
|
6
|
+
CloseToAssetType,
|
|
7
|
+
Bundles,
|
|
8
|
+
ChainId,
|
|
9
|
+
RatioState,
|
|
10
|
+
Strategies,
|
|
11
|
+
} from '../types/enums';
|
|
12
|
+
import type { EthereumAddress, StrategyOrBundleIds } from '../types';
|
|
13
|
+
|
|
14
|
+
import { STRATEGY_IDS } from '../constants';
|
|
15
|
+
|
|
16
|
+
import * as subDataService from './subDataService';
|
|
17
|
+
import * as triggerService from './triggerService';
|
|
18
|
+
import {
|
|
19
|
+
compareAddresses, getCloseStrategyType, requireAddress, requireAddresses,
|
|
20
|
+
} from './utils';
|
|
21
|
+
|
|
22
|
+
export const makerEncode = {
|
|
23
|
+
repayFromSavings(
|
|
24
|
+
bundleId: StrategyOrBundleIds,
|
|
25
|
+
vaultId: number,
|
|
26
|
+
triggerRepayRatio: number,
|
|
27
|
+
targetRepayRatio: number,
|
|
28
|
+
isBundle: boolean = true,
|
|
29
|
+
chainId: ChainId = ChainId.Ethereum,
|
|
30
|
+
daiAddr?: EthereumAddress,
|
|
31
|
+
mcdCdpManagerAddr?: EthereumAddress,
|
|
32
|
+
) {
|
|
33
|
+
const subData = subDataService.makerRepayFromSavingsSubData.encode(vaultId, targetRepayRatio, chainId, daiAddr, mcdCdpManagerAddr);
|
|
34
|
+
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRepayRatio, RatioState.UNDER);
|
|
35
|
+
|
|
36
|
+
return [bundleId, isBundle, triggerData, subData];
|
|
37
|
+
},
|
|
38
|
+
closeOnPrice(
|
|
39
|
+
vaultId: number,
|
|
40
|
+
ratioState: RatioState,
|
|
41
|
+
price: string,
|
|
42
|
+
closeToAssetAddr: EthereumAddress,
|
|
43
|
+
chainlinkCollAddress: EthereumAddress,
|
|
44
|
+
chainId: ChainId = ChainId.Ethereum,
|
|
45
|
+
daiAddr?: EthereumAddress,
|
|
46
|
+
mcdCdpManagerAddr?: EthereumAddress,
|
|
47
|
+
) {
|
|
48
|
+
requireAddresses([closeToAssetAddr, chainlinkCollAddress]);
|
|
49
|
+
|
|
50
|
+
const subData = subDataService.makerCloseSubData.encode(vaultId, closeToAssetAddr, chainId, daiAddr, mcdCdpManagerAddr);
|
|
51
|
+
const triggerData = triggerService.chainlinkPriceTrigger.encode(chainlinkCollAddress, price, ratioState);
|
|
52
|
+
|
|
53
|
+
const strategyOrBundleId = compareAddresses(closeToAssetAddr, getAssetInfo('DAI', chainId).address)
|
|
54
|
+
? Strategies.MainnetIds.MAKER_CLOSE_ON_PRICE_TO_DAI
|
|
55
|
+
: Strategies.MainnetIds.MAKER_CLOSE_ON_PRICE_TO_COLL;
|
|
56
|
+
|
|
57
|
+
const isBundle = false;
|
|
58
|
+
|
|
59
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
60
|
+
},
|
|
61
|
+
trailingStop(
|
|
62
|
+
vaultId: number,
|
|
63
|
+
triggerPercentage: number,
|
|
64
|
+
closeToAssetAddr: EthereumAddress,
|
|
65
|
+
chainlinkCollAddress: EthereumAddress,
|
|
66
|
+
roundId: number,
|
|
67
|
+
chainId: ChainId = ChainId.Ethereum,
|
|
68
|
+
daiAddr?: EthereumAddress,
|
|
69
|
+
mcdCdpManagerAddr?: EthereumAddress,
|
|
70
|
+
) {
|
|
71
|
+
requireAddresses([closeToAssetAddr, chainlinkCollAddress]);
|
|
72
|
+
|
|
73
|
+
const subData = subDataService.makerCloseSubData.encode(vaultId, closeToAssetAddr, chainId, daiAddr, mcdCdpManagerAddr);
|
|
74
|
+
const triggerData = triggerService.trailingStopTrigger.encode(chainlinkCollAddress, triggerPercentage, roundId);
|
|
75
|
+
|
|
76
|
+
const strategyOrBundleId = compareAddresses(closeToAssetAddr, getAssetInfo('DAI', chainId).address)
|
|
77
|
+
? Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_DAI
|
|
78
|
+
: Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_COLL;
|
|
79
|
+
|
|
80
|
+
const isBundle = false;
|
|
81
|
+
|
|
82
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
83
|
+
},
|
|
84
|
+
leverageManagement(
|
|
85
|
+
vaultId: number,
|
|
86
|
+
triggerRepayRatio: string,
|
|
87
|
+
triggerBoostRatio: string,
|
|
88
|
+
targetBoostRatio: string,
|
|
89
|
+
targetRepayRatio: string,
|
|
90
|
+
boostEnabled: boolean,
|
|
91
|
+
) {
|
|
92
|
+
return [
|
|
93
|
+
vaultId,
|
|
94
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
95
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
96
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
97
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
98
|
+
boostEnabled,
|
|
99
|
+
];
|
|
100
|
+
},
|
|
101
|
+
leverageManagementWithoutSubProxy(
|
|
102
|
+
vaultId: number,
|
|
103
|
+
triggerRatio: number,
|
|
104
|
+
targetRatio: number,
|
|
105
|
+
ratioState: RatioState,
|
|
106
|
+
isBoost: boolean,
|
|
107
|
+
daiAddr?: EthereumAddress,
|
|
108
|
+
) {
|
|
109
|
+
const bundleId = isBoost ? Bundles.MainnetIds.MAKER_BOOST : Bundles.MainnetIds.MAKER_REPAY;
|
|
110
|
+
|
|
111
|
+
const triggerData = triggerService.makerRatioTrigger.encode(vaultId, triggerRatio, ratioState);
|
|
112
|
+
|
|
113
|
+
const subData = subDataService.makerLeverageManagementWithoutSubProxy.encode(vaultId, targetRatio, daiAddr);
|
|
114
|
+
|
|
115
|
+
return [
|
|
116
|
+
bundleId,
|
|
117
|
+
true,
|
|
118
|
+
triggerData,
|
|
119
|
+
subData,
|
|
120
|
+
];
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
export const liquityEncode = {
|
|
125
|
+
closeOnPrice(
|
|
126
|
+
priceOverOrUnder: RatioState,
|
|
127
|
+
price: string,
|
|
128
|
+
closeToAssetAddr: EthereumAddress,
|
|
129
|
+
chainlinkCollAddress: EthereumAddress,
|
|
130
|
+
chainId: ChainId = ChainId.Ethereum,
|
|
131
|
+
collAddr?: EthereumAddress,
|
|
132
|
+
debtAddr?: EthereumAddress,
|
|
133
|
+
) {
|
|
134
|
+
requireAddresses([closeToAssetAddr, chainlinkCollAddress]);
|
|
135
|
+
|
|
136
|
+
const subData = subDataService.liquityCloseSubData.encode(closeToAssetAddr, chainId, collAddr, debtAddr);
|
|
137
|
+
const triggerData = triggerService.chainlinkPriceTrigger.encode(chainlinkCollAddress, price, priceOverOrUnder);
|
|
138
|
+
|
|
139
|
+
const strategyOrBundleId = Strategies.MainnetIds.LIQUITY_CLOSE_ON_PRICE_TO_COLL;
|
|
140
|
+
|
|
141
|
+
const isBundle = false;
|
|
142
|
+
|
|
143
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
144
|
+
},
|
|
145
|
+
trailingStop(
|
|
146
|
+
triggerPercentage: number,
|
|
147
|
+
closeToAssetAddr: EthereumAddress,
|
|
148
|
+
chainlinkCollAddress: EthereumAddress,
|
|
149
|
+
roundId: number,
|
|
150
|
+
chainId: ChainId = ChainId.Ethereum,
|
|
151
|
+
collAddr?: EthereumAddress,
|
|
152
|
+
debtAddr?: EthereumAddress,
|
|
153
|
+
) {
|
|
154
|
+
requireAddresses([closeToAssetAddr, chainlinkCollAddress]);
|
|
155
|
+
|
|
156
|
+
const subData = subDataService.liquityCloseSubData.encode(closeToAssetAddr, chainId, collAddr, debtAddr);
|
|
157
|
+
const triggerData = triggerService.trailingStopTrigger.encode(chainlinkCollAddress, triggerPercentage, roundId);
|
|
158
|
+
|
|
159
|
+
const strategyOrBundleId = Strategies.MainnetIds.LIQUITY_TRAILING_STOP_LOSS_TO_COLL;
|
|
160
|
+
|
|
161
|
+
const isBundle = false;
|
|
162
|
+
|
|
163
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
164
|
+
},
|
|
165
|
+
paybackFromChickenBondStrategySub(
|
|
166
|
+
proxyAddress: EthereumAddress,
|
|
167
|
+
ratio: number,
|
|
168
|
+
sourceId: string,
|
|
169
|
+
sourceType: number,
|
|
170
|
+
ratioState: RatioState = RatioState.UNDER,
|
|
171
|
+
) {
|
|
172
|
+
requireAddress(proxyAddress);
|
|
173
|
+
const subData = subDataService.liquityPaybackUsingChickenBondSubData.encode(sourceId, sourceType);
|
|
174
|
+
const triggerData = triggerService.liquityRatioTrigger.encode(proxyAddress, ratio, ratioState);
|
|
175
|
+
|
|
176
|
+
const strategyId = Bundles.MainnetIds.LIQUITY_PAYBACK_USING_CHICKEN_BOND;
|
|
177
|
+
|
|
178
|
+
const isBundle = true;
|
|
179
|
+
|
|
180
|
+
return [strategyId, isBundle, triggerData, subData];
|
|
181
|
+
},
|
|
182
|
+
leverageManagement(
|
|
183
|
+
triggerRepayRatio:string,
|
|
184
|
+
triggerBoostRatio:string,
|
|
185
|
+
targetBoostRatio:string,
|
|
186
|
+
targetRepayRatio:string,
|
|
187
|
+
boostEnabled:boolean,
|
|
188
|
+
) {
|
|
189
|
+
return [
|
|
190
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
191
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
192
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
193
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
194
|
+
boostEnabled,
|
|
195
|
+
];
|
|
196
|
+
},
|
|
197
|
+
dsrPayback(
|
|
198
|
+
proxyAddress: EthereumAddress,
|
|
199
|
+
triggerRatio: number,
|
|
200
|
+
targetRatio: number,
|
|
201
|
+
) {
|
|
202
|
+
requireAddress(proxyAddress);
|
|
203
|
+
const subData = subDataService.liquityDsrPaybackSubData.encode(targetRatio);
|
|
204
|
+
const triggerData = triggerService.liquityRatioTrigger.encode(proxyAddress, triggerRatio, RatioState.UNDER);
|
|
205
|
+
|
|
206
|
+
const strategyOrBundleId = Strategies.MainnetIds.LIQUITY_DSR_PAYBACK;
|
|
207
|
+
|
|
208
|
+
const isBundle = false;
|
|
209
|
+
|
|
210
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
211
|
+
},
|
|
212
|
+
dsrSupply(
|
|
213
|
+
proxyAddress: EthereumAddress,
|
|
214
|
+
triggerRatio: number,
|
|
215
|
+
targetRatio: number,
|
|
216
|
+
) {
|
|
217
|
+
requireAddress(proxyAddress);
|
|
218
|
+
const subData = subDataService.liquityDsrSupplySubData.encode(targetRatio);
|
|
219
|
+
const triggerData = triggerService.liquityRatioTrigger.encode(proxyAddress, triggerRatio, RatioState.UNDER);
|
|
220
|
+
|
|
221
|
+
const strategyOrBundleId = Strategies.MainnetIds.LIQUITY_DSR_SUPPLY;
|
|
222
|
+
|
|
223
|
+
const isBundle = false;
|
|
224
|
+
|
|
225
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
226
|
+
},
|
|
227
|
+
debtInFrontRepay(
|
|
228
|
+
proxyAddress: EthereumAddress,
|
|
229
|
+
debtInFrontMin: string,
|
|
230
|
+
targetRatioIncrease: number,
|
|
231
|
+
) {
|
|
232
|
+
requireAddress(proxyAddress);
|
|
233
|
+
const subData = subDataService.liquityDebtInFrontRepaySubData.encode(targetRatioIncrease);
|
|
234
|
+
const triggerData = triggerService.liquityDebtInFrontWithLimitTrigger.encode(proxyAddress, debtInFrontMin);
|
|
235
|
+
|
|
236
|
+
const strategyOrBundleId = Strategies.MainnetIds.LIQUITY_DEBT_IN_FRONT_REPAY;
|
|
237
|
+
|
|
238
|
+
const isBundle = false;
|
|
239
|
+
|
|
240
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
export const chickenBondsEncode = {
|
|
245
|
+
rebond(bondId: number) {
|
|
246
|
+
return subDataService.cBondsRebondSubData.encode(bondId);
|
|
247
|
+
},
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
export const aaveV2Encode = {
|
|
251
|
+
leverageManagement(
|
|
252
|
+
triggerRepayRatio: number,
|
|
253
|
+
triggerBoostRatio: number,
|
|
254
|
+
targetBoostRatio: number,
|
|
255
|
+
targetRepayRatio: number,
|
|
256
|
+
boostEnabled: boolean,
|
|
257
|
+
) {
|
|
258
|
+
return subDataService.aaveV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
export const aaveV3Encode = {
|
|
263
|
+
leverageManagement(
|
|
264
|
+
triggerRepayRatio: number,
|
|
265
|
+
triggerBoostRatio: number,
|
|
266
|
+
targetBoostRatio: number,
|
|
267
|
+
targetRepayRatio: number,
|
|
268
|
+
boostEnabled: boolean,
|
|
269
|
+
) {
|
|
270
|
+
let subInput = '0x';
|
|
271
|
+
|
|
272
|
+
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
273
|
+
.padStart(32, '0'));
|
|
274
|
+
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
275
|
+
.padStart(32, '0'));
|
|
276
|
+
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
277
|
+
.padStart(32, '0'));
|
|
278
|
+
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
279
|
+
.padStart(32, '0'));
|
|
280
|
+
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
281
|
+
|
|
282
|
+
return subInput;
|
|
283
|
+
},
|
|
284
|
+
closeToAsset(
|
|
285
|
+
strategyOrBundleId: number,
|
|
286
|
+
isBundle: boolean = true,
|
|
287
|
+
triggerData: {
|
|
288
|
+
baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState
|
|
289
|
+
},
|
|
290
|
+
subData: {
|
|
291
|
+
collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
|
|
292
|
+
},
|
|
293
|
+
) {
|
|
294
|
+
const {
|
|
295
|
+
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
296
|
+
} = subData;
|
|
297
|
+
const subDataEncoded = subDataService.aaveV3QuotePriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId);
|
|
298
|
+
|
|
299
|
+
const {
|
|
300
|
+
baseTokenAddress, quoteTokenAddress, price, ratioState,
|
|
301
|
+
} = triggerData;
|
|
302
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, ratioState);
|
|
303
|
+
|
|
304
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
305
|
+
},
|
|
306
|
+
closeToAssetWithMaximumGasPrice(
|
|
307
|
+
strategyOrBundleId: number,
|
|
308
|
+
isBundle: boolean = true,
|
|
309
|
+
triggerData: {
|
|
310
|
+
baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState, maximumGasPrice: number
|
|
311
|
+
},
|
|
312
|
+
subData: {
|
|
313
|
+
collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
|
|
314
|
+
},
|
|
315
|
+
) {
|
|
316
|
+
const {
|
|
317
|
+
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
318
|
+
} = subData;
|
|
319
|
+
const subDataEncoded = subDataService.aaveV3QuotePriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId);
|
|
320
|
+
|
|
321
|
+
const {
|
|
322
|
+
baseTokenAddress, quoteTokenAddress, price, maximumGasPrice, ratioState,
|
|
323
|
+
} = triggerData;
|
|
324
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceWithMaximumGasPriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, ratioState, maximumGasPrice);
|
|
325
|
+
|
|
326
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
327
|
+
},
|
|
328
|
+
leverageManagementOnPrice(
|
|
329
|
+
strategyOrBundleId: number,
|
|
330
|
+
isBundle: boolean = true,
|
|
331
|
+
triggerData: {
|
|
332
|
+
baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState.UNDER
|
|
333
|
+
},
|
|
334
|
+
subData: {
|
|
335
|
+
collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number,
|
|
336
|
+
},
|
|
337
|
+
) {
|
|
338
|
+
const {
|
|
339
|
+
collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
|
|
340
|
+
} = subData;
|
|
341
|
+
const subDataEncoded = subDataService.aaveV3LeverageManagementOnPriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio);
|
|
342
|
+
|
|
343
|
+
const {
|
|
344
|
+
baseTokenAddress, quoteTokenAddress, price, state,
|
|
345
|
+
} = triggerData;
|
|
346
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
347
|
+
|
|
348
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
349
|
+
},
|
|
350
|
+
leverageManagementWithoutSubProxy(
|
|
351
|
+
strategyOrBundleId: number,
|
|
352
|
+
market: EthereumAddress,
|
|
353
|
+
user: EthereumAddress,
|
|
354
|
+
ratioState: RatioState,
|
|
355
|
+
targetRatio: number,
|
|
356
|
+
triggerRatio: number,
|
|
357
|
+
isGeneric: boolean = false, // added later, isGeneric should be `false` for old strategies (if some are using this). For EOA should be `TRUE` !!! In the future, if we switch new SW subs to generic strategies too, then all new strategies should go with `isGeneric = true`. Old ones should stay the same
|
|
358
|
+
) {
|
|
359
|
+
const isBundle = true;
|
|
360
|
+
|
|
361
|
+
const subData = subDataService.aaveV3LeverageManagementSubDataWithoutSubProxy.encode(
|
|
362
|
+
targetRatio,
|
|
363
|
+
ratioState,
|
|
364
|
+
market,
|
|
365
|
+
user,
|
|
366
|
+
isGeneric,
|
|
367
|
+
);
|
|
368
|
+
const triggerData = triggerService.aaveV3RatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
369
|
+
|
|
370
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
371
|
+
},
|
|
372
|
+
|
|
373
|
+
leverageManagementOnPriceGeneric(
|
|
374
|
+
strategyOrBundleId: number,
|
|
375
|
+
price: number,
|
|
376
|
+
ratioState: RatioState,
|
|
377
|
+
collAsset: EthereumAddress,
|
|
378
|
+
collAssetId: number,
|
|
379
|
+
debtAsset: EthereumAddress,
|
|
380
|
+
debtAssetId: number,
|
|
381
|
+
marketAddr: EthereumAddress,
|
|
382
|
+
targetRatio: number,
|
|
383
|
+
user: EthereumAddress,
|
|
384
|
+
) {
|
|
385
|
+
const isBundle = true;
|
|
386
|
+
const subDataEncoded = subDataService.aaveV3LeverageManagementOnPriceGeneric.encode(
|
|
387
|
+
collAsset,
|
|
388
|
+
collAssetId,
|
|
389
|
+
debtAsset,
|
|
390
|
+
debtAssetId,
|
|
391
|
+
marketAddr,
|
|
392
|
+
targetRatio,
|
|
393
|
+
user,
|
|
394
|
+
);
|
|
395
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(collAsset, debtAsset, price, ratioState);
|
|
396
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
397
|
+
},
|
|
398
|
+
|
|
399
|
+
closeOnPriceGeneric(
|
|
400
|
+
strategyOrBundleId: number,
|
|
401
|
+
collAsset: EthereumAddress,
|
|
402
|
+
collAssetId: number,
|
|
403
|
+
debtAsset: EthereumAddress,
|
|
404
|
+
debtAssetId: number,
|
|
405
|
+
marketAddr: EthereumAddress,
|
|
406
|
+
user: EthereumAddress,
|
|
407
|
+
stopLossPrice: number = 0,
|
|
408
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
409
|
+
takeProfitPrice: number = 0,
|
|
410
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
411
|
+
) {
|
|
412
|
+
const isBundle = true;
|
|
413
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
414
|
+
|
|
415
|
+
const subDataEncoded = subDataService.aaveV3CloseGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user);
|
|
416
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
417
|
+
|
|
418
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
419
|
+
},
|
|
420
|
+
|
|
421
|
+
collateralSwitch(
|
|
422
|
+
strategyOrBundleId: number,
|
|
423
|
+
fromAsset: EthereumAddress,
|
|
424
|
+
fromAssetId: number,
|
|
425
|
+
toAsset: EthereumAddress,
|
|
426
|
+
toAssetId: number,
|
|
427
|
+
marketAddr: EthereumAddress,
|
|
428
|
+
amountToSwitch: string,
|
|
429
|
+
baseTokenAddress: EthereumAddress,
|
|
430
|
+
quoteTokenAddress: EthereumAddress,
|
|
431
|
+
price: number,
|
|
432
|
+
state: RatioState,
|
|
433
|
+
) {
|
|
434
|
+
const isBundle = false;
|
|
435
|
+
|
|
436
|
+
const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
|
|
437
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
438
|
+
|
|
439
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
440
|
+
},
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
export const compoundV2Encode = {
|
|
444
|
+
leverageManagement(
|
|
445
|
+
triggerRepayRatio: number,
|
|
446
|
+
triggerBoostRatio: number,
|
|
447
|
+
targetBoostRatio: number,
|
|
448
|
+
targetRepayRatio: number,
|
|
449
|
+
boostEnabled: boolean,
|
|
450
|
+
) {
|
|
451
|
+
return subDataService.compoundV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
452
|
+
},
|
|
453
|
+
};
|
|
454
|
+
|
|
455
|
+
export const compoundV3Encode = {
|
|
456
|
+
leverageManagement(
|
|
457
|
+
market: EthereumAddress,
|
|
458
|
+
baseToken: EthereumAddress,
|
|
459
|
+
triggerRepayRatio: number,
|
|
460
|
+
triggerBoostRatio: number,
|
|
461
|
+
targetBoostRatio: number,
|
|
462
|
+
targetRepayRatio: number,
|
|
463
|
+
boostEnabled: boolean,
|
|
464
|
+
isEOA: boolean,
|
|
465
|
+
) {
|
|
466
|
+
return subDataService.compoundV3LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
|
|
467
|
+
},
|
|
468
|
+
leverageManagementOnPrice(
|
|
469
|
+
strategyOrBundleId: number,
|
|
470
|
+
market: EthereumAddress,
|
|
471
|
+
collToken: EthereumAddress,
|
|
472
|
+
baseToken: EthereumAddress,
|
|
473
|
+
targetRatio: number,
|
|
474
|
+
price: number,
|
|
475
|
+
priceState: RatioState,
|
|
476
|
+
ratioState: RatioState, // REPAY for repay on price, BOOST for boost on price
|
|
477
|
+
user: EthereumAddress,
|
|
478
|
+
) {
|
|
479
|
+
const isBundle = true;
|
|
480
|
+
const subDataEncoded = subDataService.compoundV3LeverageManagementOnPriceSubData.encode(market, collToken, baseToken, targetRatio, ratioState, user);
|
|
481
|
+
const triggerDataEncoded = triggerService.compoundV3PriceTrigger.encode(market, collToken, user, price, priceState);
|
|
482
|
+
|
|
483
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
484
|
+
},
|
|
485
|
+
closeOnPrice(
|
|
486
|
+
strategyOrBundleId: number,
|
|
487
|
+
market: EthereumAddress,
|
|
488
|
+
collToken: EthereumAddress,
|
|
489
|
+
baseToken: EthereumAddress,
|
|
490
|
+
stopLossPrice: number = 0,
|
|
491
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
492
|
+
takeProfitPrice: number = 0,
|
|
493
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
494
|
+
user: EthereumAddress,
|
|
495
|
+
) {
|
|
496
|
+
const isBundle = true;
|
|
497
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
498
|
+
|
|
499
|
+
const subDataEncoded = subDataService.compoundV3CloseSubData.encode(market, collToken, baseToken, closeType, user);
|
|
500
|
+
const triggerDataEncoded = triggerService.compoundV3PriceRangeTrigger.encode(market, collToken, stopLossPrice, takeProfitPrice);
|
|
501
|
+
|
|
502
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
503
|
+
},
|
|
504
|
+
};
|
|
505
|
+
|
|
506
|
+
export const compoundV3L2Encode = {
|
|
507
|
+
leverageManagement(
|
|
508
|
+
market: EthereumAddress,
|
|
509
|
+
baseToken: EthereumAddress,
|
|
510
|
+
triggerRepayRatio: number,
|
|
511
|
+
triggerBoostRatio: number,
|
|
512
|
+
targetBoostRatio: number,
|
|
513
|
+
targetRepayRatio: number,
|
|
514
|
+
boostEnabled: boolean,
|
|
515
|
+
isEOA: boolean = false,
|
|
516
|
+
) {
|
|
517
|
+
return subDataService.compoundV3L2LeverageManagementSubData.encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA);
|
|
518
|
+
},
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
export const morphoAaveV2Encode = {
|
|
522
|
+
leverageManagement(
|
|
523
|
+
triggerRepayRatio: number,
|
|
524
|
+
triggerBoostRatio: number,
|
|
525
|
+
targetBoostRatio: number,
|
|
526
|
+
targetRepayRatio: number,
|
|
527
|
+
boostEnabled: boolean,
|
|
528
|
+
) {
|
|
529
|
+
return subDataService.morphoAaveV2LeverageManagementSubData.encode(triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled);
|
|
530
|
+
},
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
export const exchangeEncode = {
|
|
534
|
+
dca(
|
|
535
|
+
fromToken: EthereumAddress,
|
|
536
|
+
toToken: EthereumAddress,
|
|
537
|
+
amount: string,
|
|
538
|
+
timestamp: number,
|
|
539
|
+
interval: number,
|
|
540
|
+
network: ChainId,
|
|
541
|
+
) {
|
|
542
|
+
requireAddresses([fromToken, toToken]);
|
|
543
|
+
const subData = subDataService.exchangeDcaSubData.encode(fromToken, toToken, amount, interval);
|
|
544
|
+
const triggerData = triggerService.exchangeTimestampTrigger.encode(timestamp, interval);
|
|
545
|
+
|
|
546
|
+
const strategyId = STRATEGY_IDS[network].EXCHANGE_DCA;
|
|
547
|
+
|
|
548
|
+
return [strategyId, false, triggerData, subData];
|
|
549
|
+
},
|
|
550
|
+
limitOrder(
|
|
551
|
+
fromToken: EthereumAddress,
|
|
552
|
+
toToken: EthereumAddress,
|
|
553
|
+
amount: string,
|
|
554
|
+
targetPrice: string,
|
|
555
|
+
goodUntil: string | number,
|
|
556
|
+
orderType: OrderType,
|
|
557
|
+
) {
|
|
558
|
+
return subDataService.exchangeLimitOrderSubData.encode(fromToken, toToken, amount, targetPrice, goodUntil, orderType);
|
|
559
|
+
},
|
|
560
|
+
};
|
|
561
|
+
|
|
562
|
+
export const sparkEncode = {
|
|
563
|
+
leverageManagement(
|
|
564
|
+
triggerRepayRatio: number,
|
|
565
|
+
triggerBoostRatio: number,
|
|
566
|
+
targetBoostRatio: number,
|
|
567
|
+
targetRepayRatio: number,
|
|
568
|
+
boostEnabled: boolean,
|
|
569
|
+
) {
|
|
570
|
+
let subInput = '0x';
|
|
571
|
+
|
|
572
|
+
subInput = subInput.concat(new Dec(triggerRepayRatio).mul(1e16).toHex().slice(2)
|
|
573
|
+
.padStart(32, '0'));
|
|
574
|
+
subInput = subInput.concat(new Dec(triggerBoostRatio).mul(1e16).toHex().slice(2)
|
|
575
|
+
.padStart(32, '0'));
|
|
576
|
+
subInput = subInput.concat(new Dec(targetBoostRatio).mul(1e16).toHex().slice(2)
|
|
577
|
+
.padStart(32, '0'));
|
|
578
|
+
subInput = subInput.concat(new Dec(targetRepayRatio).mul(1e16).toHex().slice(2)
|
|
579
|
+
.padStart(32, '0'));
|
|
580
|
+
subInput = subInput.concat(boostEnabled ? '01' : '00');
|
|
581
|
+
|
|
582
|
+
return subInput;
|
|
583
|
+
},
|
|
584
|
+
leverageManagementOnPrice(
|
|
585
|
+
strategyOrBundleId: number,
|
|
586
|
+
isBundle: boolean = true,
|
|
587
|
+
triggerData: {
|
|
588
|
+
baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: number, ratioState: RatioState
|
|
589
|
+
},
|
|
590
|
+
subData: {
|
|
591
|
+
collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number,
|
|
592
|
+
},
|
|
593
|
+
) {
|
|
594
|
+
const {
|
|
595
|
+
collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio,
|
|
596
|
+
} = subData;
|
|
597
|
+
const subDataEncoded = subDataService.sparkLeverageManagementOnPriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio);
|
|
598
|
+
|
|
599
|
+
const {
|
|
600
|
+
baseTokenAddr, quoteTokenAddr, price, ratioState,
|
|
601
|
+
} = triggerData;
|
|
602
|
+
const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddr, quoteTokenAddr, price, ratioState);
|
|
603
|
+
|
|
604
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
605
|
+
},
|
|
606
|
+
closeOnPriceGeneric(
|
|
607
|
+
strategyOrBundleId: number,
|
|
608
|
+
collAsset: EthereumAddress,
|
|
609
|
+
collAssetId: number,
|
|
610
|
+
debtAsset: EthereumAddress,
|
|
611
|
+
debtAssetId: number,
|
|
612
|
+
marketAddr: EthereumAddress,
|
|
613
|
+
user: EthereumAddress,
|
|
614
|
+
stopLossPrice: number = 0,
|
|
615
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
616
|
+
takeProfitPrice: number = 0,
|
|
617
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
618
|
+
) {
|
|
619
|
+
const isBundle = true;
|
|
620
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
621
|
+
|
|
622
|
+
const subDataEncoded = subDataService.sparkCloseGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user);
|
|
623
|
+
const triggerDataEncoded = triggerService.sparkQuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
624
|
+
|
|
625
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
626
|
+
},
|
|
627
|
+
leverageManagementWithoutSubProxy(
|
|
628
|
+
strategyOrBundleId: number,
|
|
629
|
+
market: EthereumAddress,
|
|
630
|
+
user: EthereumAddress,
|
|
631
|
+
ratioState: RatioState,
|
|
632
|
+
targetRatio: number,
|
|
633
|
+
triggerRatio: number,
|
|
634
|
+
) {
|
|
635
|
+
const isBundle = true;
|
|
636
|
+
|
|
637
|
+
const subData = subDataService.sparkLeverageManagementSubDataWithoutSubProxy.encode(
|
|
638
|
+
targetRatio,
|
|
639
|
+
ratioState,
|
|
640
|
+
);
|
|
641
|
+
const triggerData = triggerService.sparkRatioTrigger.encode(user, market, triggerRatio, ratioState);
|
|
642
|
+
|
|
643
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
644
|
+
},
|
|
645
|
+
collateralSwitch(
|
|
646
|
+
strategyOrBundleId: number,
|
|
647
|
+
fromAsset: EthereumAddress,
|
|
648
|
+
fromAssetId: number,
|
|
649
|
+
toAsset: EthereumAddress,
|
|
650
|
+
toAssetId: number,
|
|
651
|
+
marketAddr: EthereumAddress,
|
|
652
|
+
amountToSwitch: string,
|
|
653
|
+
baseTokenAddress: EthereumAddress,
|
|
654
|
+
quoteTokenAddress: EthereumAddress,
|
|
655
|
+
price: number,
|
|
656
|
+
state: RatioState,
|
|
657
|
+
) {
|
|
658
|
+
const isBundle = false;
|
|
659
|
+
|
|
660
|
+
const subDataEncoded = subDataService.sparkCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
|
|
661
|
+
const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
662
|
+
|
|
663
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
664
|
+
},
|
|
665
|
+
|
|
666
|
+
};
|
|
667
|
+
|
|
668
|
+
export const crvUSDEncode = {
|
|
669
|
+
leverageManagement(
|
|
670
|
+
owner: EthereumAddress,
|
|
671
|
+
controllerAddr: EthereumAddress,
|
|
672
|
+
ratioState: RatioState,
|
|
673
|
+
targetRatio: number,
|
|
674
|
+
triggerRatio: number,
|
|
675
|
+
collTokenAddr: EthereumAddress,
|
|
676
|
+
crvUSDAddr: EthereumAddress,
|
|
677
|
+
) {
|
|
678
|
+
const subData = subDataService.crvUSDLeverageManagementSubData.encode(controllerAddr, ratioState, targetRatio, collTokenAddr, crvUSDAddr);
|
|
679
|
+
const triggerData = triggerService.crvUSDRatioTrigger.encode(owner, controllerAddr, triggerRatio, ratioState);
|
|
680
|
+
|
|
681
|
+
// over is boost, under is repay
|
|
682
|
+
const strategyOrBundleId = ratioState === RatioState.OVER ? Bundles.MainnetIds.CRVUSD_BOOST : Bundles.MainnetIds.CRVUSD_REPAY;
|
|
683
|
+
const isBundle = true;
|
|
684
|
+
|
|
685
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
686
|
+
},
|
|
687
|
+
payback(
|
|
688
|
+
proxyAddress: EthereumAddress,
|
|
689
|
+
addressToPullTokensFrom: EthereumAddress,
|
|
690
|
+
positionOwner: EthereumAddress,
|
|
691
|
+
paybackAmount: string,
|
|
692
|
+
crvUSDAddr: EthereumAddress,
|
|
693
|
+
controllerAddr: EthereumAddress,
|
|
694
|
+
minHealthRatio: number,
|
|
695
|
+
) {
|
|
696
|
+
const subData = subDataService.crvUSDPaybackSubData.encode(controllerAddr, addressToPullTokensFrom, positionOwner, paybackAmount, crvUSDAddr);
|
|
697
|
+
const triggerData = triggerService.crvUsdHealthRatioTrigger.encode(proxyAddress, controllerAddr, minHealthRatio);
|
|
698
|
+
|
|
699
|
+
const strategyId = Strategies.MainnetIds.CURVEUSD_PAYBACK;
|
|
700
|
+
const isBundle = false;
|
|
701
|
+
|
|
702
|
+
return [strategyId, isBundle, triggerData, subData];
|
|
703
|
+
},
|
|
704
|
+
};
|
|
705
|
+
|
|
706
|
+
export const morphoBlueEncode = {
|
|
707
|
+
leverageManagement(
|
|
708
|
+
marketId: string,
|
|
709
|
+
loanToken: EthereumAddress,
|
|
710
|
+
collToken: EthereumAddress,
|
|
711
|
+
oracle: EthereumAddress,
|
|
712
|
+
irm: EthereumAddress,
|
|
713
|
+
lltv: string,
|
|
714
|
+
ratioState: RatioState,
|
|
715
|
+
targetRatio: number,
|
|
716
|
+
triggerRatio: number,
|
|
717
|
+
user: EthereumAddress,
|
|
718
|
+
isEOA: boolean,
|
|
719
|
+
network: ChainId,
|
|
720
|
+
) {
|
|
721
|
+
const subData = subDataService.morphoBlueLeverageManagementSubData.encode(loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA);
|
|
722
|
+
|
|
723
|
+
const triggerData = triggerService.morphoBlueRatioTrigger.encode(marketId, user, triggerRatio, ratioState);
|
|
724
|
+
|
|
725
|
+
// over is boost, under is repay
|
|
726
|
+
const isBoost = ratioState === RatioState.OVER;
|
|
727
|
+
let strategyOrBundleId;
|
|
728
|
+
|
|
729
|
+
if (network === ChainId.Base) {
|
|
730
|
+
return [isBoost ? Bundles.BaseIds.MORPHO_BLUE_BOOST : Bundles.BaseIds.MORPHO_BLUE_REPAY, true, triggerData, subData];
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
const bundlesIds = network === ChainId.Arbitrum ? Bundles.ArbitrumIds : Bundles.MainnetIds;
|
|
734
|
+
|
|
735
|
+
if (isBoost) strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_BOOST : bundlesIds.MORPHO_BLUE_BOOST;
|
|
736
|
+
else strategyOrBundleId = isEOA ? bundlesIds.MORPHO_BLUE_EOA_REPAY : bundlesIds.MORPHO_BLUE_REPAY;
|
|
737
|
+
const isBundle = true;
|
|
738
|
+
|
|
739
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
740
|
+
},
|
|
741
|
+
leverageManagementOnPrice(
|
|
742
|
+
strategyOrBundleId: number,
|
|
743
|
+
isBundle: boolean = true,
|
|
744
|
+
loanToken: EthereumAddress,
|
|
745
|
+
collToken: EthereumAddress,
|
|
746
|
+
oracle: EthereumAddress,
|
|
747
|
+
irm: EthereumAddress,
|
|
748
|
+
lltv: string,
|
|
749
|
+
user: EthereumAddress,
|
|
750
|
+
targetRatio: number,
|
|
751
|
+
price: number,
|
|
752
|
+
priceState: RatioState,
|
|
753
|
+
) {
|
|
754
|
+
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user);
|
|
755
|
+
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
756
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
757
|
+
},
|
|
758
|
+
closeOnPrice(
|
|
759
|
+
strategyOrBundleId: number,
|
|
760
|
+
loanToken: EthereumAddress,
|
|
761
|
+
collToken: EthereumAddress,
|
|
762
|
+
oracle: EthereumAddress,
|
|
763
|
+
irm: EthereumAddress,
|
|
764
|
+
lltv: string,
|
|
765
|
+
user: EthereumAddress,
|
|
766
|
+
stopLossPrice: number = 0,
|
|
767
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
768
|
+
takeProfitPrice: number = 0,
|
|
769
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
770
|
+
) {
|
|
771
|
+
const isBundle = true;
|
|
772
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
773
|
+
|
|
774
|
+
const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
|
|
775
|
+
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
776
|
+
|
|
777
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
778
|
+
},
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
export const liquityV2Encode = {
|
|
782
|
+
leverageManagement(
|
|
783
|
+
market: EthereumAddress,
|
|
784
|
+
troveId: string,
|
|
785
|
+
collToken: EthereumAddress,
|
|
786
|
+
boldToken: EthereumAddress,
|
|
787
|
+
ratioState: RatioState,
|
|
788
|
+
targetRatio: number,
|
|
789
|
+
triggerRatio: number,
|
|
790
|
+
strategyOrBundleId: number,
|
|
791
|
+
) {
|
|
792
|
+
const isBundle = true;
|
|
793
|
+
const subData = subDataService.liquityV2LeverageManagementSubData.encode(market, troveId, collToken, boldToken, ratioState, targetRatio);
|
|
794
|
+
const triggerData = triggerService.liquityV2RatioTrigger.encode(market, troveId, triggerRatio, ratioState);
|
|
795
|
+
|
|
796
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
797
|
+
},
|
|
798
|
+
closeOnPrice(
|
|
799
|
+
strategyOrBundleId: number,
|
|
800
|
+
market: EthereumAddress,
|
|
801
|
+
troveId: string,
|
|
802
|
+
collToken: EthereumAddress,
|
|
803
|
+
boldToken: EthereumAddress,
|
|
804
|
+
stopLossPrice: number = 0,
|
|
805
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
806
|
+
takeProfitPrice: number = 0,
|
|
807
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
808
|
+
) {
|
|
809
|
+
const isBundle = true;
|
|
810
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
811
|
+
|
|
812
|
+
const subData = subDataService.liquityV2CloseSubData.encode(market, troveId, collToken, boldToken, closeType);
|
|
813
|
+
const triggerData = triggerService.closePriceTrigger.encode(collToken, stopLossPrice, takeProfitPrice);
|
|
814
|
+
|
|
815
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
816
|
+
},
|
|
817
|
+
leverageManagementOnPrice(
|
|
818
|
+
strategyOrBundleId: number,
|
|
819
|
+
market: EthereumAddress,
|
|
820
|
+
price: number,
|
|
821
|
+
state: RatioState,
|
|
822
|
+
troveId: string,
|
|
823
|
+
collToken: EthereumAddress,
|
|
824
|
+
boldToken: EthereumAddress,
|
|
825
|
+
targetRatio: number,
|
|
826
|
+
isRepayOnPrice: boolean,
|
|
827
|
+
) {
|
|
828
|
+
const subDataEncoded = subDataService.liquityV2LeverageManagementOnPriceSubData.encode(
|
|
829
|
+
market, troveId, collToken, boldToken, targetRatio, isRepayOnPrice,
|
|
830
|
+
);
|
|
831
|
+
|
|
832
|
+
const triggerDataEncoded = triggerService.liquityV2QuotePriceTrigger.encode(market, price, state);
|
|
833
|
+
const isBundle = true;
|
|
834
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
835
|
+
},
|
|
836
|
+
payback(
|
|
837
|
+
market: EthereumAddress,
|
|
838
|
+
troveId: string,
|
|
839
|
+
boldToken: EthereumAddress,
|
|
840
|
+
targetRatio: number,
|
|
841
|
+
ratioState: RatioState,
|
|
842
|
+
triggerRatio: number,
|
|
843
|
+
) {
|
|
844
|
+
const strategyId = Strategies.MainnetIds.LIQUITY_V2_PAYBACK;
|
|
845
|
+
const isBundle = false;
|
|
846
|
+
|
|
847
|
+
const subData = subDataService.liquityV2PaybackSubData.encode(market, troveId, boldToken, targetRatio, ratioState);
|
|
848
|
+
const triggerData = triggerService.liquityV2RatioTrigger.encode(market, troveId, triggerRatio, ratioState);
|
|
849
|
+
|
|
850
|
+
return [strategyId, isBundle, triggerData, subData];
|
|
851
|
+
},
|
|
852
|
+
};
|
|
853
|
+
|
|
854
|
+
export const fluidEncode = {
|
|
855
|
+
leverageManagement(
|
|
856
|
+
nftId: string,
|
|
857
|
+
vault: EthereumAddress,
|
|
858
|
+
ratioState: RatioState,
|
|
859
|
+
targetRatio: number,
|
|
860
|
+
triggerRatio: number,
|
|
861
|
+
strategyOrBundleId: number,
|
|
862
|
+
) {
|
|
863
|
+
const isBundle = true;
|
|
864
|
+
const subData = subDataService.fluidLeverageManagementSubData.encode(nftId, vault, ratioState, targetRatio);
|
|
865
|
+
const triggerData = triggerService.fluidRatioTrigger.encode(nftId, triggerRatio, ratioState);
|
|
866
|
+
|
|
867
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
868
|
+
},
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
export const aaveV4Encode = {
|
|
872
|
+
leverageManagement(
|
|
873
|
+
strategyOrBundleId: number,
|
|
874
|
+
owner: EthereumAddress,
|
|
875
|
+
spoke: EthereumAddress,
|
|
876
|
+
ratioState: RatioState,
|
|
877
|
+
targetRatio: number,
|
|
878
|
+
triggerRatio: number,
|
|
879
|
+
) {
|
|
880
|
+
const isBundle = true;
|
|
881
|
+
const subData = subDataService.aaveV4LeverageManagementSubData.encode(spoke, owner, ratioState, targetRatio);
|
|
882
|
+
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
883
|
+
|
|
884
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
885
|
+
},
|
|
886
|
+
leverageManagementOnPrice(
|
|
887
|
+
strategyOrBundleId: number,
|
|
888
|
+
owner: EthereumAddress,
|
|
889
|
+
spoke: EthereumAddress,
|
|
890
|
+
collAsset: EthereumAddress,
|
|
891
|
+
collAssetId: number,
|
|
892
|
+
debtAsset: EthereumAddress,
|
|
893
|
+
debtAssetId: number,
|
|
894
|
+
targetRatio: number,
|
|
895
|
+
price: string,
|
|
896
|
+
priceState: RatioState,
|
|
897
|
+
ratioState: RatioState, // UNDER for repay, OVER for boost
|
|
898
|
+
) {
|
|
899
|
+
const isBundle = true;
|
|
900
|
+
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.encode(
|
|
901
|
+
spoke,
|
|
902
|
+
owner,
|
|
903
|
+
collAsset,
|
|
904
|
+
collAssetId,
|
|
905
|
+
debtAsset,
|
|
906
|
+
debtAssetId,
|
|
907
|
+
ratioState,
|
|
908
|
+
targetRatio,
|
|
909
|
+
);
|
|
910
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(
|
|
911
|
+
spoke,
|
|
912
|
+
collAssetId,
|
|
913
|
+
debtAssetId,
|
|
914
|
+
price,
|
|
915
|
+
priceState,
|
|
916
|
+
);
|
|
917
|
+
|
|
918
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
919
|
+
},
|
|
920
|
+
closeOnPrice(
|
|
921
|
+
strategyOrBundleId: number,
|
|
922
|
+
owner: EthereumAddress,
|
|
923
|
+
spoke: EthereumAddress,
|
|
924
|
+
collAsset: EthereumAddress,
|
|
925
|
+
collAssetId: number,
|
|
926
|
+
debtAsset: EthereumAddress,
|
|
927
|
+
debtAssetId: number,
|
|
928
|
+
stopLossPrice: string = '0',
|
|
929
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
930
|
+
takeProfitPrice: string = '0',
|
|
931
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
932
|
+
) {
|
|
933
|
+
const isBundle = true;
|
|
934
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
935
|
+
|
|
936
|
+
const subData = subDataService.aaveV4CloseSubData.encode(
|
|
937
|
+
spoke,
|
|
938
|
+
owner,
|
|
939
|
+
collAsset,
|
|
940
|
+
collAssetId,
|
|
941
|
+
debtAsset,
|
|
942
|
+
debtAssetId,
|
|
943
|
+
closeType,
|
|
944
|
+
);
|
|
945
|
+
const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.encode(
|
|
946
|
+
spoke,
|
|
947
|
+
collAssetId,
|
|
948
|
+
debtAssetId,
|
|
949
|
+
stopLossPrice,
|
|
950
|
+
takeProfitPrice,
|
|
951
|
+
);
|
|
952
|
+
|
|
953
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
954
|
+
},
|
|
955
|
+
collateralSwitch(
|
|
956
|
+
strategyOrBundleId: number,
|
|
957
|
+
owner: EthereumAddress,
|
|
958
|
+
spoke: EthereumAddress,
|
|
959
|
+
fromAsset: EthereumAddress,
|
|
960
|
+
fromAssetId: number,
|
|
961
|
+
toAsset: EthereumAddress,
|
|
962
|
+
toAssetId: number,
|
|
963
|
+
amountToSwitch: string,
|
|
964
|
+
price: string,
|
|
965
|
+
ratioState: RatioState,
|
|
966
|
+
) {
|
|
967
|
+
const isBundle = false;
|
|
968
|
+
const subData = subDataService.aaveV4CollateralSwitchSubData.encode(
|
|
969
|
+
spoke,
|
|
970
|
+
owner,
|
|
971
|
+
fromAsset,
|
|
972
|
+
fromAssetId,
|
|
973
|
+
toAsset,
|
|
974
|
+
toAssetId,
|
|
975
|
+
amountToSwitch,
|
|
976
|
+
);
|
|
977
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(
|
|
978
|
+
spoke,
|
|
979
|
+
fromAssetId, // baseTokenId
|
|
980
|
+
toAssetId, // quoteTokenId
|
|
981
|
+
price,
|
|
982
|
+
ratioState,
|
|
983
|
+
);
|
|
984
|
+
|
|
985
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
986
|
+
},
|
|
987
|
+
};
|