@defisaver/automation-sdk 3.0.7 → 3.0.8-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.
Files changed (143) hide show
  1. package/.babelrc +3 -3
  2. package/.editorconfig +9 -9
  3. package/.env.dev +4 -4
  4. package/.eslintignore +6 -6
  5. package/.eslintrc.js +41 -41
  6. package/.tests.sh +2 -2
  7. package/README.md +41 -41
  8. package/esm/abis/Erc20.json +223 -223
  9. package/esm/abis/SubStorage.json +17 -17
  10. package/esm/abis/UniMulticall.json +14 -14
  11. package/esm/abis/index.d.ts +9 -9
  12. package/esm/abis/index.js +30 -30
  13. package/esm/abis/legacy_AaveV2Subscriptions.json +8 -8
  14. package/esm/abis/legacy_AuthCheck.json +8 -8
  15. package/esm/abis/legacy_CompoundV2Subscriptions.json +9 -9
  16. package/esm/abis/legacy_MakerSubscriptions.json +9 -9
  17. package/esm/automation/private/Automation.d.ts +12 -12
  18. package/esm/automation/private/Automation.js +42 -42
  19. package/esm/automation/private/LegacyAutomation.d.ts +25 -25
  20. package/esm/automation/private/LegacyAutomation.js +118 -118
  21. package/esm/automation/private/LegacyProtocol.d.ts +22 -22
  22. package/esm/automation/private/LegacyProtocol.js +41 -41
  23. package/esm/automation/private/LegacyProtocol.test.d.ts +1 -1
  24. package/esm/automation/private/LegacyProtocol.test.js +25 -25
  25. package/esm/automation/private/Protocol.d.ts +22 -22
  26. package/esm/automation/private/Protocol.js +41 -41
  27. package/esm/automation/private/Protocol.test.d.ts +1 -1
  28. package/esm/automation/private/Protocol.test.js +25 -25
  29. package/esm/automation/private/StrategiesAutomation.d.ts +33 -33
  30. package/esm/automation/private/StrategiesAutomation.js +181 -181
  31. package/esm/automation/private/StrategiesAutomation.test.d.ts +1 -1
  32. package/esm/automation/private/StrategiesAutomation.test.js +671 -671
  33. package/esm/automation/public/ArbitrumStrategies.d.ts +5 -5
  34. package/esm/automation/public/ArbitrumStrategies.js +13 -13
  35. package/esm/automation/public/EthereumStrategies.d.ts +5 -5
  36. package/esm/automation/public/EthereumStrategies.js +13 -13
  37. package/esm/automation/public/OptimismStrategies.d.ts +5 -5
  38. package/esm/automation/public/OptimismStrategies.js +13 -13
  39. package/esm/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
  40. package/esm/automation/public/legacy/LegacyAaveAutomation.js +20 -20
  41. package/esm/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
  42. package/esm/automation/public/legacy/LegacyCompoundAutomation.js +20 -20
  43. package/esm/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
  44. package/esm/automation/public/legacy/LegacyMakerAutomation.js +20 -20
  45. package/esm/configuration.d.ts +1 -1
  46. package/esm/configuration.js +12 -12
  47. package/esm/constants/index.d.ts +24 -45
  48. package/esm/constants/index.js +426 -395
  49. package/esm/index.d.ts +22 -22
  50. package/esm/index.js +63 -63
  51. package/esm/services/contractService.d.ts +12 -12
  52. package/esm/services/contractService.js +54 -54
  53. package/esm/services/ethereumService.d.ts +7 -7
  54. package/esm/services/ethereumService.js +49 -49
  55. package/esm/services/ethereumService.test.d.ts +1 -1
  56. package/esm/services/ethereumService.test.js +242 -242
  57. package/esm/services/strategiesService.d.ts +2 -2
  58. package/esm/services/strategiesService.js +700 -700
  59. package/esm/services/strategiesService.test.d.ts +1 -1
  60. package/esm/services/strategiesService.test.js +110 -110
  61. package/esm/services/strategySubService.d.ts +100 -87
  62. package/esm/services/strategySubService.js +264 -257
  63. package/esm/services/strategySubService.test.d.ts +1 -1
  64. package/esm/services/strategySubService.test.js +934 -894
  65. package/esm/services/subDataService.d.ts +192 -181
  66. package/esm/services/subDataService.js +475 -443
  67. package/esm/services/subDataService.test.d.ts +1 -1
  68. package/esm/services/subDataService.test.js +1282 -1225
  69. package/esm/services/triggerService.d.ts +191 -191
  70. package/esm/services/triggerService.js +367 -367
  71. package/esm/services/triggerService.test.d.ts +1 -1
  72. package/esm/services/triggerService.test.js +926 -926
  73. package/esm/services/utils.d.ts +25 -25
  74. package/esm/services/utils.js +131 -131
  75. package/esm/services/utils.test.d.ts +1 -1
  76. package/esm/services/utils.test.js +376 -376
  77. package/esm/types/contracts/generated/Erc20.d.ts +53 -53
  78. package/esm/types/contracts/generated/Erc20.js +5 -5
  79. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
  80. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +5 -5
  81. package/esm/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
  82. package/esm/types/contracts/generated/Legacy_AuthCheck.js +5 -5
  83. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
  84. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +5 -5
  85. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
  86. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +5 -5
  87. package/esm/types/contracts/generated/SubStorage.d.ts +114 -114
  88. package/esm/types/contracts/generated/SubStorage.js +5 -5
  89. package/esm/types/contracts/generated/UniMulticall.d.ts +55 -55
  90. package/esm/types/contracts/generated/UniMulticall.js +5 -5
  91. package/esm/types/contracts/generated/index.d.ts +7 -7
  92. package/esm/types/contracts/generated/index.js +2 -2
  93. package/esm/types/contracts/generated/types.d.ts +54 -54
  94. package/esm/types/contracts/generated/types.js +2 -2
  95. package/esm/types/enums.d.ts +168 -160
  96. package/esm/types/enums.js +188 -180
  97. package/esm/types/index.d.ts +217 -217
  98. package/esm/types/index.js +2 -2
  99. package/package.json +71 -71
  100. package/scripts/generateContractTypes.js +39 -39
  101. package/src/abis/Erc20.json +222 -222
  102. package/src/abis/SubStorage.json +17 -17
  103. package/src/abis/UniMulticall.json +14 -14
  104. package/src/abis/index.ts +28 -28
  105. package/src/abis/legacy_AaveV2Subscriptions.json +7 -7
  106. package/src/abis/legacy_AuthCheck.json +7 -7
  107. package/src/abis/legacy_CompoundV2Subscriptions.json +8 -8
  108. package/src/abis/legacy_MakerSubscriptions.json +8 -8
  109. package/src/automation/private/Automation.ts +44 -44
  110. package/src/automation/private/LegacyAutomation.ts +135 -135
  111. package/src/automation/private/LegacyProtocol.test.ts +23 -23
  112. package/src/automation/private/LegacyProtocol.ts +51 -51
  113. package/src/automation/private/Protocol.test.ts +23 -23
  114. package/src/automation/private/Protocol.ts +51 -51
  115. package/src/automation/private/StrategiesAutomation.test.ts +663 -663
  116. package/src/automation/private/StrategiesAutomation.ts +242 -242
  117. package/src/automation/public/ArbitrumStrategies.ts +10 -10
  118. package/src/automation/public/EthereumStrategies.ts +10 -10
  119. package/src/automation/public/OptimismStrategies.ts +10 -10
  120. package/src/automation/public/legacy/LegacyAaveAutomation.ts +20 -20
  121. package/src/automation/public/legacy/LegacyCompoundAutomation.ts +20 -20
  122. package/src/automation/public/legacy/LegacyMakerAutomation.ts +20 -20
  123. package/src/configuration.ts +8 -8
  124. package/src/constants/index.ts +441 -409
  125. package/src/index.ts +38 -38
  126. package/src/services/contractService.ts +77 -77
  127. package/src/services/ethereumService.test.ts +257 -257
  128. package/src/services/ethereumService.ts +69 -69
  129. package/src/services/strategiesService.test.ts +105 -105
  130. package/src/services/strategiesService.ts +904 -904
  131. package/src/services/strategySubService.test.ts +1119 -1065
  132. package/src/services/strategySubService.ts +518 -496
  133. package/src/services/subDataService.test.ts +1387 -1326
  134. package/src/services/subDataService.ts +645 -595
  135. package/src/services/triggerService.test.ts +1004 -1004
  136. package/src/services/triggerService.ts +449 -449
  137. package/src/services/utils.test.ts +430 -430
  138. package/src/services/utils.ts +103 -103
  139. package/src/types/enums.ts +182 -174
  140. package/src/types/index.ts +262 -262
  141. package/tsconfig.json +79 -79
  142. package/umd/index.js +108 -16
  143. package/webpack.umd.js +52 -52
@@ -1,1065 +1,1119 @@
1
- import { expect } from 'chai';
2
- import Dec from 'decimal.js';
3
- import { otherAddresses } from '@defisaver/sdk';
4
- import { getAssetInfo } from '@defisaver/tokens';
5
- import * as web3Utils from 'web3-utils';
6
-
7
- import { Bundles, ChainId, OrderType, RatioState, Strategies } from '../types/enums';
8
- import type { EthereumAddress, StrategyOrBundleIds, SubData, TriggerData } from '../types';
9
-
10
- import '../configuration';
11
- import {
12
- aaveV2Encode,
13
- chickenBondsEncode,
14
- liquityEncode,
15
- makerEncode,
16
- aaveV3Encode,
17
- compoundV2Encode,
18
- compoundV3Encode,
19
- morphoAaveV2Encode,
20
- exchangeEncode,
21
- sparkEncode,
22
- crvUSDEncode, compoundV3L2Encode, morphoBlueEncode,
23
- } from './strategySubService';
24
-
25
- describe('Feature: strategySubService.ts', () => {
26
- describe('When testing strategySubService.makerEncode', () => {
27
- // @ts-ignore // TODO - this requires change in @defisaver/tokens
28
- const mcdCdpManagerAddr = otherAddresses(ChainId.Ethereum).McdCdpManager;
29
-
30
- describe('repayFromSavings()', () => {
31
- const examples: Array<[
32
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
33
- [
34
- bundleId: StrategyOrBundleIds, vaultId: number, triggerRepayRatio: number, targetRepayRatio: number,
35
- isBundle?: boolean, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress,
36
- ]
37
- ]> = [
38
- [
39
- [
40
- Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_RARI,
41
- true,
42
- ['0x00000000000000000000000000000000000000000000000000000000000000de000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
43
- [
44
- '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
45
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
46
- ],
47
- ],
48
- [
49
- Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_RARI,
50
- 222,
51
- 140,
52
- 180,
53
- true,
54
- ChainId.Ethereum,
55
- getAssetInfo('DAI').address,
56
- mcdCdpManagerAddr,
57
- ]
58
- ]
59
- ];
60
-
61
- examples.forEach(([expected, actual]) => {
62
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
63
- expect(makerEncode.repayFromSavings(...actual)).to.eql(expected);
64
- });
65
- });
66
- });
67
-
68
- describe('closeOnPrice()', () => {
69
- const examples: Array<[
70
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
71
- [
72
- vaultId: number, ratioState: RatioState, price: string, closeToAssetAddr: EthereumAddress,
73
- chainlinkCollAddress: EthereumAddress, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress,
74
- ]
75
- ]> = [
76
- [
77
- [
78
- Strategies.MainnetIds.MAKER_CLOSE_ON_PRICE_TO_DAI,
79
- false,
80
- ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000002cc9e4c0000000000000000000000000000000000000000000000000000000000000000'],
81
- [
82
- '0x0000000000000000000000000000000000000000000000000000000000000078', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
83
- '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
84
- ],
85
- ],
86
- [
87
- 120,
88
- RatioState.OVER,
89
- '0.469643',
90
- getAssetInfo('DAI').address,
91
- getAssetInfo('WBTC').address,
92
- ChainId.Ethereum,
93
- ]
94
- ]
95
- ];
96
-
97
- examples.forEach(([expected, actual]) => {
98
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
99
- expect(makerEncode.closeOnPrice(...actual)).to.eql(expected);
100
- });
101
- });
102
- });
103
-
104
- describe('trailingStop()', () => {
105
- const examples: Array<[
106
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
107
- [
108
- vaultId: number, triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress,
109
- roundId: number, chainId: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress,
110
- ]
111
- ]> = [
112
- [
113
- [
114
- Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_COLL,
115
- false,
116
- ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000000000000000000000000000000000055ae82600000000000000000000000000000000000000000000000000000000000000007b'],
117
- [
118
- '0x000000000000000000000000000000000000000000000000000000000000096e', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
119
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
120
- ],
121
- ],
122
- [
123
- 2414,
124
- 230,
125
- getAssetInfo('WBTC').address,
126
- getAssetInfo('WBTC').address,
127
- 123,
128
- ChainId.Ethereum,
129
- ]
130
- ]
131
- ];
132
-
133
- examples.forEach(([expected, actual]) => {
134
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
135
- expect(makerEncode.trailingStop(...actual)).to.eql(expected);
136
- });
137
- });
138
- });
139
-
140
- describe('leverageManagement()', () => {
141
- const examples: Array<[
142
- [
143
- vaultId: number, triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
144
- targetRepayRatio: string, boostEnabled: boolean,
145
- ],
146
- [
147
- vaultId: number, triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
148
- targetRepayRatio: string, boostEnabled: boolean,
149
- ]
150
- ]> = [
151
- [
152
- [
153
- 5791,
154
- new Dec('210').mul(1e16).toString(),
155
- new Dec('290').mul(1e16).toString(),
156
- new Dec('240').mul(1e16).toString(),
157
- new Dec('240').mul(1e16).toString(),
158
- true,
159
- ],
160
- [
161
- 5791, '210', '290', '240', '240', true,
162
- ]
163
- ]
164
- ];
165
-
166
- examples.forEach(([expected, actual]) => {
167
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
168
- expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
169
- });
170
- });
171
- });
172
- });
173
-
174
- describe('When testing strategySubService.liquityEncode', () => {
175
- describe('closeOnPrice()', () => {
176
- const examples: Array<[
177
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
178
- [
179
- priceOverOrUnder: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress,
180
- chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress,
181
- ]
182
- ]> = [
183
- [
184
- [
185
- Strategies.MainnetIds.LIQUITY_CLOSE_ON_PRICE_TO_COLL,
186
- false,
187
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000001c027053000000000000000000000000000000000000000000000000000000000000000000'],
188
- [
189
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
190
- ],
191
- ],
192
- [
193
- RatioState.OVER,
194
- '1203',
195
- getAssetInfo('WETH').address,
196
- getAssetInfo('WETH').address,
197
- ]
198
- ]
199
- ];
200
-
201
- examples.forEach(([expected, actual]) => {
202
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
203
- expect(liquityEncode.closeOnPrice(...actual)).to.eql(expected);
204
- });
205
- });
206
- });
207
-
208
- describe('trailingStop()', () => {
209
- const examples: Array<[
210
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
211
- [
212
- triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number,
213
- chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress,
214
- ]
215
- ]> = [
216
- [
217
- [
218
- Strategies.MainnetIds.LIQUITY_TRAILING_STOP_LOSS_TO_COLL,
219
- false,
220
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000055ae826000000000000000000000000000000000000000000000000000000000000000c97'],
221
- [
222
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
223
- ],
224
- ],
225
- [
226
- 230,
227
- getAssetInfo('WETH').address,
228
- getAssetInfo('WETH').address,
229
- 3223,
230
- ]
231
- ]
232
- ];
233
-
234
- examples.forEach(([expected, actual]) => {
235
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
236
- expect(liquityEncode.trailingStop(...actual)).to.eql(expected);
237
- });
238
- });
239
- });
240
-
241
- describe('leverageManagement()', () => {
242
- const examples: Array<[
243
- [
244
- triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
245
- targetRepayRatio: string, boostEnabled: boolean,
246
- ],
247
- [
248
- triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
249
- targetRepayRatio: string, boostEnabled: boolean,
250
- ]
251
- ]> = [
252
- [
253
- [
254
- new Dec('210').mul(1e16).toString(),
255
- new Dec('290').mul(1e16).toString(),
256
- new Dec('240').mul(1e16).toString(),
257
- new Dec('240').mul(1e16).toString(),
258
- false,
259
- ],
260
- [
261
- '210', '290', '240', '240', false,
262
- ]
263
- ]
264
- ];
265
-
266
- examples.forEach(([expected, actual]) => {
267
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
268
- expect(liquityEncode.leverageManagement(...actual)).to.eql(expected);
269
- });
270
- });
271
- });
272
-
273
- describe('paybackFromChickenBondStrategySub()', () => {
274
- const examples: Array<[
275
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
276
- [
277
- proxyAddress: EthereumAddress, ratio: number, sourceId: string, sourceType: number, ratioState: RatioState,
278
- ]
279
- ]> = [
280
- [
281
- [
282
- Bundles.MainnetIds.LIQUITY_PAYBACK_USING_CHICKEN_BOND,
283
- true,
284
- ['0x0000000000000000000000002439d211133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002dcbf4840eca00000000000000000000000000000000000000000000000000000000000000000000'],
285
- [
286
- '0x000000000000000000000000000000000000000000000000000000000000007b', '0x0000000000000000000000000000000000000000000000000000000000000000',
287
- '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
288
- ],
289
- ],
290
- [
291
- web3Utils.toChecksumAddress('0x2439d211133AFaB8F2B819B1066c7E434Ad94E9e'),
292
- 330,
293
- '123',
294
- 0,
295
- RatioState.OVER
296
- ]
297
- ]
298
- ];
299
-
300
- examples.forEach(([expected, actual]) => {
301
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
302
- expect(liquityEncode.paybackFromChickenBondStrategySub(...actual)).to.eql(expected);
303
- });
304
- });
305
- });
306
-
307
- describe('dsrPayback()', () => {
308
- const examples: Array<[
309
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
310
- [proxyAddress: EthereumAddress, triggerRatio: number, targetRatio: number],
311
- ]> = [
312
- [
313
- [
314
- Strategies.MainnetIds.LIQUITY_DSR_PAYBACK,
315
- false,
316
- ['0x0000000000000000000000002439d211133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000250dbeda8e4b00000000000000000000000000000000000000000000000000000000000000000001'],
317
- [
318
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x00000000000000000000000000000000000000000000000029a2241af62c0000',
319
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
320
- ],
321
- ],
322
- [web3Utils.toChecksumAddress('0x2439d211133AFaB8F2B819B1066c7E434Ad94E9e'), 267, 300]
323
- ]
324
- ];
325
-
326
- examples.forEach(([expected, actual]) => {
327
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
328
- expect(liquityEncode.dsrPayback(...actual)).to.eql(expected);
329
- });
330
- });
331
- });
332
-
333
- describe('debtInFrontRepay()', () => {
334
- const examples: Array<[
335
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
336
- [proxyAddress: EthereumAddress, debtInFrontMin: string, targetRatioIncrease: number],
337
- ]> = [
338
- [
339
- [
340
- Strategies.MainnetIds.LIQUITY_DEBT_IN_FRONT_REPAY,
341
- false,
342
- ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a0000000000000000000000000000000000000000019d971e4fe8401e74000000'],
343
- [
344
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
345
- '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
346
- '0x0000000000000000000000000000000000000000000000000000000000000000'
347
- ],
348
- ],
349
- [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '500000000', 45]
350
- ]
351
- ];
352
-
353
- examples.forEach(([expected, actual]) => {
354
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
355
- expect(liquityEncode.debtInFrontRepay(...actual)).to.eql(expected);
356
- });
357
- });
358
- });
359
- });
360
-
361
- describe('When testing strategySubService.chickenBondsEncode', () => {
362
- describe('rebond()', () => {
363
- const examples: Array<[
364
- SubData,
365
- [bondId: number],
366
- ]> = [
367
- [
368
- ['0x00000000000000000000000000000000000000000000000000000000000005e3'],
369
- [1507]
370
- ]
371
- ];
372
-
373
- examples.forEach(([expected, actual]) => {
374
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
375
- expect(chickenBondsEncode.rebond(...actual)).to.eql(expected);
376
- });
377
- });
378
- });
379
- });
380
-
381
- describe('When testing strategySubService.aaveV2Encode', () => {
382
- describe('leverageManagement()', () => {
383
- const examples: Array<[
384
- [string, string, string, string, boolean],
385
- [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
386
- ]> = [
387
- [
388
- [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
389
- [160, 220, 180, 190, true]
390
- ],
391
- [
392
- [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
393
- [160, 200, 180, 190, false]
394
- ],
395
- ];
396
-
397
- examples.forEach(([expected, actual]) => {
398
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
399
- expect(aaveV2Encode.leverageManagement(...actual)).to.eql(expected);
400
- });
401
- });
402
- });
403
- });
404
-
405
- describe('When testing strategySubService.aaveV3Encode', () => {
406
- describe('leverageManagement()', () => {
407
- const examples: Array<[
408
- string,
409
- [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
410
- ]> = [
411
- [
412
- '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
413
- [160, 220, 180, 190, true]
414
- ],
415
- [
416
- '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
417
- [160, 200, 180, 190, false]
418
- ],
419
- ];
420
-
421
- examples.forEach(([expected, actual]) => {
422
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
423
- expect(aaveV3Encode.leverageManagement(...actual)).to.eql(expected);
424
- });
425
- });
426
- });
427
-
428
- describe('closeToAsset()', () => {
429
- const examples: Array<[
430
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
431
- [
432
- strategyOrBundleId: number,
433
- isBundle: boolean,
434
- triggerData: {
435
- baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState
436
- },
437
- subData: {
438
- collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
439
- },
440
- ]
441
- ]> = [
442
- [
443
- [
444
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
445
- true,
446
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
447
- [
448
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
449
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
450
- '0x0000000000000000000000000000000000000000000000000000000000000000',
451
- ],
452
- ],
453
- [
454
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
455
- true,
456
- {
457
- baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER
458
- },
459
- {
460
- collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
461
- },
462
- ]
463
- ],
464
- [
465
- [
466
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
467
- true,
468
- ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
469
- [
470
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
471
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
472
- '0x0000000000000000000000000000000000000000000000000000000000000000',
473
- ],
474
- ],
475
- [
476
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
477
- true,
478
- {
479
- baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER
480
- },
481
- {
482
- collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
483
- },
484
- ]
485
- ]
486
- ];
487
-
488
- examples.forEach(([expected, actual]) => {
489
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
490
- expect(aaveV3Encode.closeToAsset(...actual)).to.eql(expected);
491
- });
492
- });
493
- });
494
-
495
- describe('closeToAssetWithMaximumGasPrice()', () => {
496
- const examples: Array<[
497
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
498
- [
499
- strategyOrBundleId: number,
500
- isBundle: boolean,
501
- triggerData: {
502
- baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState, maximumGasPrice: number
503
- },
504
- subData: {
505
- collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
506
- },
507
- ]
508
- ]> = [
509
- [
510
- [
511
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
512
- true,
513
- [
514
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000',
515
- '0x00000000000000000000000000000000000000000000000000000002cb417800',
516
- ],
517
- [
518
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
519
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
520
- '0x0000000000000000000000000000000000000000000000000000000000000000',
521
- ],
522
- ],
523
- [
524
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
525
- true,
526
- {
527
- baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER, maximumGasPrice: 12,
528
- },
529
- {
530
- collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
531
- },
532
- ]
533
- ],
534
- [
535
- [
536
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
537
- true,
538
- [
539
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001',
540
- '0x0000000000000000000000000000000000000000000000000000004a817c8000',
541
- ],
542
- [
543
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
544
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
545
- '0x0000000000000000000000000000000000000000000000000000000000000000',
546
- ],
547
- ],
548
- [
549
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
550
- true,
551
- {
552
- baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER, maximumGasPrice: 320,
553
- },
554
- {
555
- collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
556
- },
557
- ]
558
- ]
559
- ];
560
-
561
- examples.forEach(([expected, actual]) => {
562
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
563
- expect(aaveV3Encode.closeToAssetWithMaximumGasPrice(...actual)).to.eql(expected);
564
- });
565
- });
566
- });
567
- });
568
-
569
- describe('When testing strategySubService.compoundV2Encode', () => {
570
- describe('leverageManagement()', () => {
571
- const examples: Array<[
572
- [string, string, string, string, boolean],
573
- [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
574
- ]> = [
575
- [
576
- [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
577
- [160, 220, 180, 190, true]
578
- ],
579
- [
580
- [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
581
- [160, 200, 180, 190, false]
582
- ],
583
- ];
584
-
585
- examples.forEach(([expected, actual]) => {
586
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
587
- expect(compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
588
- });
589
- });
590
- });
591
- });
592
-
593
- describe('When testing strategySubService.compoundV3Encode', () => {
594
- describe('leverageManagement()', () => {
595
- const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string, boolean, boolean], [market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean]]> = [
596
- [
597
- [
598
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
599
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
600
- new Dec(160).mul(1e16).toString(),
601
- new Dec(220).mul(1e16).toString(),
602
- new Dec(180).mul(1e16).toString(),
603
- new Dec(190).mul(1e16).toString(),
604
- true, false,
605
- ],
606
- [
607
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
608
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
609
- 160, 220, 180, 190,
610
- true, false,
611
- ]
612
- ],
613
- [
614
- [
615
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
616
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
617
- new Dec(160).mul(1e16).toString(),
618
- new Dec(210).mul(1e16).toString(),
619
- new Dec(180).mul(1e16).toString(),
620
- new Dec(190).mul(1e16).toString(),
621
- false, true,
622
- ],
623
- [
624
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
625
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
626
- 160, 210, 180, 190,
627
- false, true,
628
- ]
629
- ],
630
- ];
631
- examples.forEach(([expected, actual]) => {
632
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
633
- expect(compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
634
- });
635
- });
636
- });
637
- });
638
-
639
- describe('When testing strategySubService.morphoAaveV2Encode', () => {
640
- describe('leverageManagement()', () => {
641
- const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
642
- [
643
- [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
644
- [160, 220, 180, 190, true]
645
- ],
646
- [
647
- [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
648
- [160, 200, 180, 190, false]
649
- ],
650
- ];
651
-
652
- examples.forEach(([expected, actual]) => {
653
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
654
- expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
655
- });
656
- });
657
- });
658
- });
659
-
660
- describe('When testing strategySubService.exchangeEncode', () => {
661
- describe('dca()', () => {
662
- const examples: Array<[
663
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
664
- [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number, network: ChainId],
665
- ]> = [
666
- [
667
- [
668
- Strategies.ArbitrumIds.EXCHANGE_DCA,
669
- false,
670
- ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd000000000000000000000000000000000000000000000000000000000012d068'],
671
- [
672
- '0x000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da1', '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831',
673
- '0x0000000000000000000000000000000000000000000000000000000000038270', '0x000000000000000000000000000000000000000000000000000000000012d068'
674
- ],
675
- ],
676
- [getAssetInfo('DAI', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, '230000', 1697111705805, 1233000, ChainId.Arbitrum]
677
- ],
678
- [
679
- [
680
- Strategies.MainnetIds.EXCHANGE_DCA,
681
- false,
682
- ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd0000000000000000000000000000000000000000000000000000000000067458'],
683
- [
684
- '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599', '0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
685
- '0x0000000000000000000000000000000000000000000000000000000000000015', '0x0000000000000000000000000000000000000000000000000000000000067458',
686
- ],
687
- ],
688
- [getAssetInfo('WBTC').address, getAssetInfo('ETH').address, '21', 1697111705805, 423000, ChainId.Ethereum]
689
- ],
690
- ];
691
-
692
- examples.forEach(([expected, actual]) => {
693
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
694
- expect(exchangeEncode.dca(...actual)).to.eql(expected);
695
- });
696
- });
697
- });
698
-
699
- describe('limitOrder()', () => {
700
- const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string], [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType]]> = [
701
- [
702
- [
703
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
704
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
705
- '2131',
706
- '0.53123',
707
- '1696590921159',
708
- `${OrderType.STOP_LOSS}`
709
- ],
710
- [
711
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
712
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
713
- '2131',
714
- '0.53123',
715
- 1696590921159,
716
- OrderType.STOP_LOSS
717
- ]
718
- ],
719
- [
720
- [
721
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
722
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
723
- '2131',
724
- '0.43123',
725
- '1646590921159',
726
- `${OrderType.TAKE_PROFIT}`
727
- ],
728
- [
729
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
730
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
731
- '2131',
732
- '0.43123',
733
- 1646590921159,
734
- OrderType.TAKE_PROFIT
735
- ]
736
- ],
737
- ];
738
-
739
- examples.forEach(([expected, actual]) => {
740
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
741
- expect(exchangeEncode.limitOrder(...actual)).to.eql(expected);
742
- });
743
- });
744
- });
745
- });
746
-
747
- describe('When testing strategySubService.sparkEncode', () => {
748
- describe('leverageManagement()', () => {
749
- const examples: Array<[
750
- string,
751
- [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
752
- ]> = [
753
- [
754
- '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
755
- [160, 220, 180, 190, true]
756
- ],
757
- [
758
- '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
759
- [160, 200, 180, 190, false]
760
- ],
761
- ];
762
-
763
- examples.forEach(([expected, actual]) => {
764
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
765
- expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
766
- });
767
- });
768
- });
769
-
770
- describe('closeToAsset()', () => {
771
- const examples: Array<[
772
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
773
- [
774
- strategyOrBundleId: number,
775
- isBundle: boolean,
776
- triggerData: {
777
- baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState
778
- },
779
- subData: {
780
- collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
781
- },
782
- ]
783
- ]> = [
784
- [
785
- [
786
- Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
787
- true,
788
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
789
- [
790
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
791
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
792
- '0x0000000000000000000000000000000000000000000000000000000000000000',
793
- ],
794
- ],
795
- [
796
- Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
797
- true,
798
- {
799
- baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER
800
- },
801
- {
802
- collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
803
- },
804
- ]
805
- ],
806
- [
807
- [
808
- Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
809
- true,
810
- ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
811
- [
812
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
813
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
814
- '0x0000000000000000000000000000000000000000000000000000000000000000',
815
- ],
816
- ],
817
- [
818
- Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
819
- true,
820
- {
821
- baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER
822
- },
823
- {
824
- collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
825
- },
826
- ]
827
- ]
828
- ];
829
-
830
- examples.forEach(([expected, actual]) => {
831
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
832
- expect(sparkEncode.closeToAsset(...actual)).to.eql(expected);
833
- });
834
- });
835
- });
836
- });
837
-
838
- describe('When testing strategySubService.crvUSDEncode', () => {
839
- describe('leverageManagement()', () => {
840
- const examples: Array<[
841
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
842
- [owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress],
843
- ]> = [
844
- [
845
- [
846
- Bundles.MainnetIds.CRVUSD_REPAY,
847
- true,
848
- [
849
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001',
850
- ],
851
- [
852
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
853
- '0x0000000000000000000000000000000000000000000000000000000000000001',
854
- '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
855
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
856
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
857
- ],
858
- ],
859
- [
860
- web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
861
- web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
862
- RatioState.UNDER,
863
- 190,
864
- 140,
865
- '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
866
- '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
867
- ]
868
- ],
869
- [
870
- [
871
- Bundles.MainnetIds.CRVUSD_BOOST,
872
- true,
873
- [
874
- '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
875
- ],
876
- [
877
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
878
- '0x0000000000000000000000000000000000000000000000000000000000000000',
879
- '0x00000000000000000000000000000000000000000000000016345785d8a00000',
880
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
881
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
882
- ],
883
- ],
884
- [
885
- web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
886
- web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
887
- RatioState.OVER,
888
- 160,
889
- 200,
890
- '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
891
- '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
892
- ]
893
- ],
894
- ];
895
-
896
- examples.forEach(([expected, actual]) => {
897
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
898
- expect(crvUSDEncode.leverageManagement(...actual)).to.eql(expected);
899
- });
900
- });
901
- });
902
- describe('payback()', () => {
903
- const examples: Array<[
904
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
905
- [owner: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress, controllerAddr: EthereumAddress, minHealthRatio: number],
906
- ]> = [
907
- [
908
- [
909
- Strategies.MainnetIds.CURVEUSD_PAYBACK,
910
- false,
911
- [
912
- '0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000',
913
- ],
914
- [
915
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
916
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
917
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
918
- '0x00000000000000000000000000000000000000000000043c33c1937564800000',
919
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e'
920
- ],
921
- ],
922
- [
923
- web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'),
924
- web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
925
- web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
926
- '20000',
927
- '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
928
- web3Utils.toChecksumAddress('0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635'),
929
- 20,
930
- ]
931
- ]
932
- ];
933
-
934
- examples.forEach(([expected, actual]) => {
935
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
936
- expect(crvUSDEncode.payback(...actual)).to.eql(expected);
937
- });
938
- });
939
- });
940
- });
941
- describe('When testing strategySubService.morphoBlueEncode', () => {
942
- describe('leverageManagement()', () => {
943
- const examples: Array<[
944
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
945
- [
946
- marketId: string,
947
- loanToken: EthereumAddress,
948
- collToken: EthereumAddress,
949
- oracle: EthereumAddress,
950
- irm: EthereumAddress,
951
- lltv: string,
952
- ratioState: RatioState,
953
- targetRatio: number,
954
- triggerRatio: number,
955
- user: EthereumAddress,
956
- isEoa: boolean,
957
- ],
958
- ]> = [
959
- [
960
- [
961
- Bundles.MainnetIds.MORPHO_BLUE_REPAY,
962
- true,
963
- [
964
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001',
965
- ],
966
- [
967
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
968
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
969
- '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
970
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
971
- '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
972
- '0x0000000000000000000000000000000000000000000000000000000000000001',
973
- '0x000000000000000000000000000000000000000000000000136dcc951d8c0000',
974
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
975
- '0x0000000000000000000000000000000000000000000000000000000000000000',
976
- ],
977
- ],
978
- [
979
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
980
- web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
981
- web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
982
- web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
983
- web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
984
- '945000000000000000',
985
- RatioState.UNDER,
986
- 140,
987
- 120,
988
- web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
989
- false,
990
- ]
991
- ],
992
- [
993
- [
994
- Bundles.MainnetIds.MORPHO_BLUE_BOOST,
995
- true,
996
- [
997
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
998
- ],
999
- [
1000
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1001
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1002
- '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1003
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1004
- '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1005
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1006
- '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1007
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1008
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1009
- ],
1010
- ],
1011
- [
1012
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
1013
- web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1014
- web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1015
- web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
1016
- web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1017
- '945000000000000000',
1018
- RatioState.OVER,
1019
- 160,
1020
- 200,
1021
- web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1022
- false,
1023
- ]
1024
- ],
1025
- ];
1026
-
1027
- examples.forEach(([expected, actual]) => {
1028
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1029
- expect(morphoBlueEncode.leverageManagement(...actual)).to.eql(expected);
1030
- });
1031
- });
1032
- });
1033
- });
1034
-
1035
- describe('When testing strategySubService.compoundV3L2Encode', () => {
1036
- describe('leverageManagement()', () => {
1037
- const examples: Array<[string, [EthereumAddress, EthereumAddress, number, number, number, number, boolean]]> = [
1038
- [
1039
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
1040
- [
1041
- web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1042
- web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1043
- 160, 220, 180, 190,
1044
- true
1045
- ],
1046
- ],
1047
- [
1048
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee000000',
1049
- [
1050
- web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1051
- web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1052
- 160, 220, 180, 110,
1053
- false
1054
- ],
1055
- ],
1056
- ];
1057
- examples.forEach(([expected, actual]) => {
1058
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1059
- expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
1060
- });
1061
- });
1062
- });
1063
- });
1064
-
1065
- });
1
+ import { expect } from 'chai';
2
+ import Dec from 'decimal.js';
3
+ import { otherAddresses } from '@defisaver/sdk';
4
+ import { getAssetInfo } from '@defisaver/tokens';
5
+ import * as web3Utils from 'web3-utils';
6
+
7
+ import { Bundles, ChainId, OrderType, RatioState, Strategies } from '../types/enums';
8
+ import type { EthereumAddress, StrategyOrBundleIds, SubData, TriggerData } from '../types';
9
+
10
+ import '../configuration';
11
+ import {
12
+ aaveV2Encode,
13
+ chickenBondsEncode,
14
+ liquityEncode,
15
+ makerEncode,
16
+ aaveV3Encode,
17
+ compoundV2Encode,
18
+ compoundV3Encode,
19
+ morphoAaveV2Encode,
20
+ exchangeEncode,
21
+ sparkEncode,
22
+ crvUSDEncode, compoundV3L2Encode, morphoBlueEncode,
23
+ } from './strategySubService';
24
+
25
+ describe('Feature: strategySubService.ts', () => {
26
+ describe('When testing strategySubService.makerEncode', () => {
27
+ // @ts-ignore // TODO - this requires change in @defisaver/tokens
28
+ const mcdCdpManagerAddr = otherAddresses(ChainId.Ethereum).McdCdpManager;
29
+
30
+ describe('repayFromSavings()', () => {
31
+ const examples: Array<[
32
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
33
+ [
34
+ bundleId: StrategyOrBundleIds, vaultId: number, triggerRepayRatio: number, targetRepayRatio: number,
35
+ isBundle?: boolean, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress,
36
+ ]
37
+ ]> = [
38
+ [
39
+ [
40
+ Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_RARI,
41
+ true,
42
+ ['0x00000000000000000000000000000000000000000000000000000000000000de000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
43
+ [
44
+ '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
45
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
46
+ ],
47
+ ],
48
+ [
49
+ Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_RARI,
50
+ 222,
51
+ 140,
52
+ 180,
53
+ true,
54
+ ChainId.Ethereum,
55
+ getAssetInfo('DAI').address,
56
+ mcdCdpManagerAddr,
57
+ ]
58
+ ]
59
+ ];
60
+
61
+ examples.forEach(([expected, actual]) => {
62
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
63
+ expect(makerEncode.repayFromSavings(...actual)).to.eql(expected);
64
+ });
65
+ });
66
+ });
67
+
68
+ describe('closeOnPrice()', () => {
69
+ const examples: Array<[
70
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
71
+ [
72
+ vaultId: number, ratioState: RatioState, price: string, closeToAssetAddr: EthereumAddress,
73
+ chainlinkCollAddress: EthereumAddress, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress,
74
+ ]
75
+ ]> = [
76
+ [
77
+ [
78
+ Strategies.MainnetIds.MAKER_CLOSE_ON_PRICE_TO_DAI,
79
+ false,
80
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000002cc9e4c0000000000000000000000000000000000000000000000000000000000000000'],
81
+ [
82
+ '0x0000000000000000000000000000000000000000000000000000000000000078', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
83
+ '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
84
+ ],
85
+ ],
86
+ [
87
+ 120,
88
+ RatioState.OVER,
89
+ '0.469643',
90
+ getAssetInfo('DAI').address,
91
+ getAssetInfo('WBTC').address,
92
+ ChainId.Ethereum,
93
+ ]
94
+ ]
95
+ ];
96
+
97
+ examples.forEach(([expected, actual]) => {
98
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
99
+ expect(makerEncode.closeOnPrice(...actual)).to.eql(expected);
100
+ });
101
+ });
102
+ });
103
+
104
+ describe('trailingStop()', () => {
105
+ const examples: Array<[
106
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
107
+ [
108
+ vaultId: number, triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress,
109
+ roundId: number, chainId: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress,
110
+ ]
111
+ ]> = [
112
+ [
113
+ [
114
+ Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_COLL,
115
+ false,
116
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000000000000000000000000000000000055ae82600000000000000000000000000000000000000000000000000000000000000007b'],
117
+ [
118
+ '0x000000000000000000000000000000000000000000000000000000000000096e', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
119
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
120
+ ],
121
+ ],
122
+ [
123
+ 2414,
124
+ 230,
125
+ getAssetInfo('WBTC').address,
126
+ getAssetInfo('WBTC').address,
127
+ 123,
128
+ ChainId.Ethereum,
129
+ ]
130
+ ]
131
+ ];
132
+
133
+ examples.forEach(([expected, actual]) => {
134
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
135
+ expect(makerEncode.trailingStop(...actual)).to.eql(expected);
136
+ });
137
+ });
138
+ });
139
+
140
+ describe('leverageManagement()', () => {
141
+ const examples: Array<[
142
+ [
143
+ vaultId: number, triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
144
+ targetRepayRatio: string, boostEnabled: boolean,
145
+ ],
146
+ [
147
+ vaultId: number, triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
148
+ targetRepayRatio: string, boostEnabled: boolean,
149
+ ]
150
+ ]> = [
151
+ [
152
+ [
153
+ 5791,
154
+ new Dec('210').mul(1e16).toString(),
155
+ new Dec('290').mul(1e16).toString(),
156
+ new Dec('240').mul(1e16).toString(),
157
+ new Dec('240').mul(1e16).toString(),
158
+ true,
159
+ ],
160
+ [
161
+ 5791, '210', '290', '240', '240', true,
162
+ ]
163
+ ]
164
+ ];
165
+
166
+ examples.forEach(([expected, actual]) => {
167
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
168
+ expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
169
+ });
170
+ });
171
+ });
172
+ });
173
+
174
+ describe('When testing strategySubService.liquityEncode', () => {
175
+ describe('closeOnPrice()', () => {
176
+ const examples: Array<[
177
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
178
+ [
179
+ priceOverOrUnder: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress,
180
+ chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress,
181
+ ]
182
+ ]> = [
183
+ [
184
+ [
185
+ Strategies.MainnetIds.LIQUITY_CLOSE_ON_PRICE_TO_COLL,
186
+ false,
187
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000001c027053000000000000000000000000000000000000000000000000000000000000000000'],
188
+ [
189
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
190
+ ],
191
+ ],
192
+ [
193
+ RatioState.OVER,
194
+ '1203',
195
+ getAssetInfo('WETH').address,
196
+ getAssetInfo('WETH').address,
197
+ ]
198
+ ]
199
+ ];
200
+
201
+ examples.forEach(([expected, actual]) => {
202
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
203
+ expect(liquityEncode.closeOnPrice(...actual)).to.eql(expected);
204
+ });
205
+ });
206
+ });
207
+
208
+ describe('trailingStop()', () => {
209
+ const examples: Array<[
210
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
211
+ [
212
+ triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number,
213
+ chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress,
214
+ ]
215
+ ]> = [
216
+ [
217
+ [
218
+ Strategies.MainnetIds.LIQUITY_TRAILING_STOP_LOSS_TO_COLL,
219
+ false,
220
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000055ae826000000000000000000000000000000000000000000000000000000000000000c97'],
221
+ [
222
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
223
+ ],
224
+ ],
225
+ [
226
+ 230,
227
+ getAssetInfo('WETH').address,
228
+ getAssetInfo('WETH').address,
229
+ 3223,
230
+ ]
231
+ ]
232
+ ];
233
+
234
+ examples.forEach(([expected, actual]) => {
235
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
236
+ expect(liquityEncode.trailingStop(...actual)).to.eql(expected);
237
+ });
238
+ });
239
+ });
240
+
241
+ describe('leverageManagement()', () => {
242
+ const examples: Array<[
243
+ [
244
+ triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
245
+ targetRepayRatio: string, boostEnabled: boolean,
246
+ ],
247
+ [
248
+ triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
249
+ targetRepayRatio: string, boostEnabled: boolean,
250
+ ]
251
+ ]> = [
252
+ [
253
+ [
254
+ new Dec('210').mul(1e16).toString(),
255
+ new Dec('290').mul(1e16).toString(),
256
+ new Dec('240').mul(1e16).toString(),
257
+ new Dec('240').mul(1e16).toString(),
258
+ false,
259
+ ],
260
+ [
261
+ '210', '290', '240', '240', false,
262
+ ]
263
+ ]
264
+ ];
265
+
266
+ examples.forEach(([expected, actual]) => {
267
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
268
+ expect(liquityEncode.leverageManagement(...actual)).to.eql(expected);
269
+ });
270
+ });
271
+ });
272
+
273
+ describe('paybackFromChickenBondStrategySub()', () => {
274
+ const examples: Array<[
275
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
276
+ [
277
+ proxyAddress: EthereumAddress, ratio: number, sourceId: string, sourceType: number, ratioState: RatioState,
278
+ ]
279
+ ]> = [
280
+ [
281
+ [
282
+ Bundles.MainnetIds.LIQUITY_PAYBACK_USING_CHICKEN_BOND,
283
+ true,
284
+ ['0x0000000000000000000000002439d211133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002dcbf4840eca00000000000000000000000000000000000000000000000000000000000000000000'],
285
+ [
286
+ '0x000000000000000000000000000000000000000000000000000000000000007b', '0x0000000000000000000000000000000000000000000000000000000000000000',
287
+ '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
288
+ ],
289
+ ],
290
+ [
291
+ web3Utils.toChecksumAddress('0x2439d211133AFaB8F2B819B1066c7E434Ad94E9e'),
292
+ 330,
293
+ '123',
294
+ 0,
295
+ RatioState.OVER
296
+ ]
297
+ ]
298
+ ];
299
+
300
+ examples.forEach(([expected, actual]) => {
301
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
302
+ expect(liquityEncode.paybackFromChickenBondStrategySub(...actual)).to.eql(expected);
303
+ });
304
+ });
305
+ });
306
+
307
+ describe('dsrPayback()', () => {
308
+ const examples: Array<[
309
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
310
+ [proxyAddress: EthereumAddress, triggerRatio: number, targetRatio: number],
311
+ ]> = [
312
+ [
313
+ [
314
+ Strategies.MainnetIds.LIQUITY_DSR_PAYBACK,
315
+ false,
316
+ ['0x0000000000000000000000002439d211133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000250dbeda8e4b00000000000000000000000000000000000000000000000000000000000000000001'],
317
+ [
318
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x00000000000000000000000000000000000000000000000029a2241af62c0000',
319
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
320
+ ],
321
+ ],
322
+ [web3Utils.toChecksumAddress('0x2439d211133AFaB8F2B819B1066c7E434Ad94E9e'), 267, 300]
323
+ ]
324
+ ];
325
+
326
+ examples.forEach(([expected, actual]) => {
327
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
328
+ expect(liquityEncode.dsrPayback(...actual)).to.eql(expected);
329
+ });
330
+ });
331
+ });
332
+
333
+ describe('debtInFrontRepay()', () => {
334
+ const examples: Array<[
335
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
336
+ [proxyAddress: EthereumAddress, debtInFrontMin: string, targetRatioIncrease: number],
337
+ ]> = [
338
+ [
339
+ [
340
+ Strategies.MainnetIds.LIQUITY_DEBT_IN_FRONT_REPAY,
341
+ false,
342
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a0000000000000000000000000000000000000000019d971e4fe8401e74000000'],
343
+ [
344
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
345
+ '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
346
+ '0x0000000000000000000000000000000000000000000000000000000000000000'
347
+ ],
348
+ ],
349
+ [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '500000000', 45]
350
+ ]
351
+ ];
352
+
353
+ examples.forEach(([expected, actual]) => {
354
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
355
+ expect(liquityEncode.debtInFrontRepay(...actual)).to.eql(expected);
356
+ });
357
+ });
358
+ });
359
+ });
360
+
361
+ describe('When testing strategySubService.chickenBondsEncode', () => {
362
+ describe('rebond()', () => {
363
+ const examples: Array<[
364
+ SubData,
365
+ [bondId: number],
366
+ ]> = [
367
+ [
368
+ ['0x00000000000000000000000000000000000000000000000000000000000005e3'],
369
+ [1507]
370
+ ]
371
+ ];
372
+
373
+ examples.forEach(([expected, actual]) => {
374
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
375
+ expect(chickenBondsEncode.rebond(...actual)).to.eql(expected);
376
+ });
377
+ });
378
+ });
379
+ });
380
+
381
+ describe('When testing strategySubService.aaveV2Encode', () => {
382
+ describe('leverageManagement()', () => {
383
+ const examples: Array<[
384
+ [string, string, string, string, boolean],
385
+ [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
386
+ ]> = [
387
+ [
388
+ [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
389
+ [160, 220, 180, 190, true]
390
+ ],
391
+ [
392
+ [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
393
+ [160, 200, 180, 190, false]
394
+ ],
395
+ ];
396
+
397
+ examples.forEach(([expected, actual]) => {
398
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
399
+ expect(aaveV2Encode.leverageManagement(...actual)).to.eql(expected);
400
+ });
401
+ });
402
+ });
403
+ });
404
+
405
+ describe('When testing strategySubService.aaveV3Encode', () => {
406
+ describe('leverageManagement()', () => {
407
+ const examples: Array<[
408
+ string,
409
+ [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
410
+ ]> = [
411
+ [
412
+ '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
413
+ [160, 220, 180, 190, true]
414
+ ],
415
+ [
416
+ '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
417
+ [160, 200, 180, 190, false]
418
+ ],
419
+ ];
420
+
421
+ examples.forEach(([expected, actual]) => {
422
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
423
+ expect(aaveV3Encode.leverageManagement(...actual)).to.eql(expected);
424
+ });
425
+ });
426
+ });
427
+
428
+ describe('closeToAsset()', () => {
429
+ const examples: Array<[
430
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
431
+ [
432
+ strategyOrBundleId: number,
433
+ isBundle: boolean,
434
+ triggerData: {
435
+ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState
436
+ },
437
+ subData: {
438
+ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
439
+ },
440
+ ]
441
+ ]> = [
442
+ [
443
+ [
444
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
445
+ true,
446
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
447
+ [
448
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
449
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
450
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
451
+ ],
452
+ ],
453
+ [
454
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
455
+ true,
456
+ {
457
+ baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER
458
+ },
459
+ {
460
+ collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
461
+ },
462
+ ]
463
+ ],
464
+ [
465
+ [
466
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
467
+ true,
468
+ ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
469
+ [
470
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
471
+ '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
472
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
473
+ ],
474
+ ],
475
+ [
476
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
477
+ true,
478
+ {
479
+ baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER
480
+ },
481
+ {
482
+ collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
483
+ },
484
+ ]
485
+ ]
486
+ ];
487
+
488
+ examples.forEach(([expected, actual]) => {
489
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
490
+ expect(aaveV3Encode.closeToAsset(...actual)).to.eql(expected);
491
+ });
492
+ });
493
+ });
494
+
495
+ describe('closeToAssetWithMaximumGasPrice()', () => {
496
+ const examples: Array<[
497
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
498
+ [
499
+ strategyOrBundleId: number,
500
+ isBundle: boolean,
501
+ triggerData: {
502
+ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState, maximumGasPrice: number
503
+ },
504
+ subData: {
505
+ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
506
+ },
507
+ ]
508
+ ]> = [
509
+ [
510
+ [
511
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
512
+ true,
513
+ [
514
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000',
515
+ '0x00000000000000000000000000000000000000000000000000000002cb417800',
516
+ ],
517
+ [
518
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
519
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
520
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
521
+ ],
522
+ ],
523
+ [
524
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
525
+ true,
526
+ {
527
+ baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER, maximumGasPrice: 12,
528
+ },
529
+ {
530
+ collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
531
+ },
532
+ ]
533
+ ],
534
+ [
535
+ [
536
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
537
+ true,
538
+ [
539
+ '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001',
540
+ '0x0000000000000000000000000000000000000000000000000000004a817c8000',
541
+ ],
542
+ [
543
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
544
+ '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
545
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
546
+ ],
547
+ ],
548
+ [
549
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
550
+ true,
551
+ {
552
+ baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER, maximumGasPrice: 320,
553
+ },
554
+ {
555
+ collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
556
+ },
557
+ ]
558
+ ]
559
+ ];
560
+
561
+ examples.forEach(([expected, actual]) => {
562
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
563
+ expect(aaveV3Encode.closeToAssetWithMaximumGasPrice(...actual)).to.eql(expected);
564
+ });
565
+ });
566
+ });
567
+
568
+ describe('openOrder()', () => {
569
+ const examples: Array<[
570
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
571
+ [
572
+ strategyOrBundleId: number,
573
+ isBundle: boolean,
574
+ triggerData: {
575
+ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState.UNDER
576
+ },
577
+ subData: {
578
+ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number,
579
+ },
580
+ ]
581
+ ]> = [
582
+ [
583
+ [
584
+ Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
585
+ true,
586
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000007acead34980000000000000000000000000000000000000000000000000000000000000001'],
587
+ [
588
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
589
+ '0x000000000000000000000000000000000000000000000000000000000000000a',
590
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
591
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
592
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
593
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
594
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
595
+ ],
596
+ ],
597
+ [
598
+ Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
599
+ true,
600
+ {
601
+ baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 5274.534678, state: RatioState.UNDER
602
+ },
603
+ {
604
+ collAsset: getAssetInfo('WETH').address,
605
+ collAssetId: 10,
606
+ debtAsset: getAssetInfo('DAI').address,
607
+ debtAssetId: 4,
608
+ marketAddr: '0x2f39d218133afab8f2b819b1066c7e434ad94e9e',
609
+ targetRatio: 200,
610
+ },
611
+ ]
612
+ ],
613
+ ];
614
+
615
+ examples.forEach(([expected, actual]) => {
616
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
617
+ expect(aaveV3Encode.openOrder(...actual)).to.eql(expected);
618
+ });
619
+ });
620
+ });
621
+ });
622
+
623
+ describe('When testing strategySubService.compoundV2Encode', () => {
624
+ describe('leverageManagement()', () => {
625
+ const examples: Array<[
626
+ [string, string, string, string, boolean],
627
+ [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
628
+ ]> = [
629
+ [
630
+ [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
631
+ [160, 220, 180, 190, true]
632
+ ],
633
+ [
634
+ [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
635
+ [160, 200, 180, 190, false]
636
+ ],
637
+ ];
638
+
639
+ examples.forEach(([expected, actual]) => {
640
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
641
+ expect(compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
642
+ });
643
+ });
644
+ });
645
+ });
646
+
647
+ describe('When testing strategySubService.compoundV3Encode', () => {
648
+ describe('leverageManagement()', () => {
649
+ const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string, boolean, boolean], [market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean]]> = [
650
+ [
651
+ [
652
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
653
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
654
+ new Dec(160).mul(1e16).toString(),
655
+ new Dec(220).mul(1e16).toString(),
656
+ new Dec(180).mul(1e16).toString(),
657
+ new Dec(190).mul(1e16).toString(),
658
+ true, false,
659
+ ],
660
+ [
661
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
662
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
663
+ 160, 220, 180, 190,
664
+ true, false,
665
+ ]
666
+ ],
667
+ [
668
+ [
669
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
670
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
671
+ new Dec(160).mul(1e16).toString(),
672
+ new Dec(210).mul(1e16).toString(),
673
+ new Dec(180).mul(1e16).toString(),
674
+ new Dec(190).mul(1e16).toString(),
675
+ false, true,
676
+ ],
677
+ [
678
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
679
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
680
+ 160, 210, 180, 190,
681
+ false, true,
682
+ ]
683
+ ],
684
+ ];
685
+ examples.forEach(([expected, actual]) => {
686
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
687
+ expect(compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
688
+ });
689
+ });
690
+ });
691
+ });
692
+
693
+ describe('When testing strategySubService.morphoAaveV2Encode', () => {
694
+ describe('leverageManagement()', () => {
695
+ const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
696
+ [
697
+ [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
698
+ [160, 220, 180, 190, true]
699
+ ],
700
+ [
701
+ [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
702
+ [160, 200, 180, 190, false]
703
+ ],
704
+ ];
705
+
706
+ examples.forEach(([expected, actual]) => {
707
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
708
+ expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
709
+ });
710
+ });
711
+ });
712
+ });
713
+
714
+ describe('When testing strategySubService.exchangeEncode', () => {
715
+ describe('dca()', () => {
716
+ const examples: Array<[
717
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
718
+ [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number, network: ChainId],
719
+ ]> = [
720
+ [
721
+ [
722
+ Strategies.ArbitrumIds.EXCHANGE_DCA,
723
+ false,
724
+ ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd000000000000000000000000000000000000000000000000000000000012d068'],
725
+ [
726
+ '0x000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da1', '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831',
727
+ '0x0000000000000000000000000000000000000000000000000000000000038270', '0x000000000000000000000000000000000000000000000000000000000012d068'
728
+ ],
729
+ ],
730
+ [getAssetInfo('DAI', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, '230000', 1697111705805, 1233000, ChainId.Arbitrum]
731
+ ],
732
+ [
733
+ [
734
+ Strategies.MainnetIds.EXCHANGE_DCA,
735
+ false,
736
+ ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd0000000000000000000000000000000000000000000000000000000000067458'],
737
+ [
738
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599', '0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
739
+ '0x0000000000000000000000000000000000000000000000000000000000000015', '0x0000000000000000000000000000000000000000000000000000000000067458',
740
+ ],
741
+ ],
742
+ [getAssetInfo('WBTC').address, getAssetInfo('ETH').address, '21', 1697111705805, 423000, ChainId.Ethereum]
743
+ ],
744
+ ];
745
+
746
+ examples.forEach(([expected, actual]) => {
747
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
748
+ expect(exchangeEncode.dca(...actual)).to.eql(expected);
749
+ });
750
+ });
751
+ });
752
+
753
+ describe('limitOrder()', () => {
754
+ const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string], [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType]]> = [
755
+ [
756
+ [
757
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
758
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
759
+ '2131',
760
+ '0.53123',
761
+ '1696590921159',
762
+ `${OrderType.STOP_LOSS}`
763
+ ],
764
+ [
765
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
766
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
767
+ '2131',
768
+ '0.53123',
769
+ 1696590921159,
770
+ OrderType.STOP_LOSS
771
+ ]
772
+ ],
773
+ [
774
+ [
775
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
776
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
777
+ '2131',
778
+ '0.43123',
779
+ '1646590921159',
780
+ `${OrderType.TAKE_PROFIT}`
781
+ ],
782
+ [
783
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
784
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
785
+ '2131',
786
+ '0.43123',
787
+ 1646590921159,
788
+ OrderType.TAKE_PROFIT
789
+ ]
790
+ ],
791
+ ];
792
+
793
+ examples.forEach(([expected, actual]) => {
794
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
795
+ expect(exchangeEncode.limitOrder(...actual)).to.eql(expected);
796
+ });
797
+ });
798
+ });
799
+ });
800
+
801
+ describe('When testing strategySubService.sparkEncode', () => {
802
+ describe('leverageManagement()', () => {
803
+ const examples: Array<[
804
+ string,
805
+ [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
806
+ ]> = [
807
+ [
808
+ '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
809
+ [160, 220, 180, 190, true]
810
+ ],
811
+ [
812
+ '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
813
+ [160, 200, 180, 190, false]
814
+ ],
815
+ ];
816
+
817
+ examples.forEach(([expected, actual]) => {
818
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
819
+ expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
820
+ });
821
+ });
822
+ });
823
+
824
+ describe('closeToAsset()', () => {
825
+ const examples: Array<[
826
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
827
+ [
828
+ strategyOrBundleId: number,
829
+ isBundle: boolean,
830
+ triggerData: {
831
+ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState
832
+ },
833
+ subData: {
834
+ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
835
+ },
836
+ ]
837
+ ]> = [
838
+ [
839
+ [
840
+ Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
841
+ true,
842
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
843
+ [
844
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
845
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
846
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
847
+ ],
848
+ ],
849
+ [
850
+ Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
851
+ true,
852
+ {
853
+ baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER
854
+ },
855
+ {
856
+ collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
857
+ },
858
+ ]
859
+ ],
860
+ [
861
+ [
862
+ Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
863
+ true,
864
+ ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
865
+ [
866
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
867
+ '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
868
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
869
+ ],
870
+ ],
871
+ [
872
+ Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
873
+ true,
874
+ {
875
+ baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER
876
+ },
877
+ {
878
+ collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
879
+ },
880
+ ]
881
+ ]
882
+ ];
883
+
884
+ examples.forEach(([expected, actual]) => {
885
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
886
+ expect(sparkEncode.closeToAsset(...actual)).to.eql(expected);
887
+ });
888
+ });
889
+ });
890
+ });
891
+
892
+ describe('When testing strategySubService.crvUSDEncode', () => {
893
+ describe('leverageManagement()', () => {
894
+ const examples: Array<[
895
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
896
+ [owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress],
897
+ ]> = [
898
+ [
899
+ [
900
+ Bundles.MainnetIds.CRVUSD_REPAY,
901
+ true,
902
+ [
903
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001',
904
+ ],
905
+ [
906
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
907
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
908
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
909
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
910
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
911
+ ],
912
+ ],
913
+ [
914
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
915
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
916
+ RatioState.UNDER,
917
+ 190,
918
+ 140,
919
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
920
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
921
+ ]
922
+ ],
923
+ [
924
+ [
925
+ Bundles.MainnetIds.CRVUSD_BOOST,
926
+ true,
927
+ [
928
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
929
+ ],
930
+ [
931
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
932
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
933
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
934
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
935
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
936
+ ],
937
+ ],
938
+ [
939
+ web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
940
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
941
+ RatioState.OVER,
942
+ 160,
943
+ 200,
944
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
945
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
946
+ ]
947
+ ],
948
+ ];
949
+
950
+ examples.forEach(([expected, actual]) => {
951
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
952
+ expect(crvUSDEncode.leverageManagement(...actual)).to.eql(expected);
953
+ });
954
+ });
955
+ });
956
+ describe('payback()', () => {
957
+ const examples: Array<[
958
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
959
+ [owner: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress, controllerAddr: EthereumAddress, minHealthRatio: number],
960
+ ]> = [
961
+ [
962
+ [
963
+ Strategies.MainnetIds.CURVEUSD_PAYBACK,
964
+ false,
965
+ [
966
+ '0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000',
967
+ ],
968
+ [
969
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
970
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
971
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
972
+ '0x00000000000000000000000000000000000000000000043c33c1937564800000',
973
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e'
974
+ ],
975
+ ],
976
+ [
977
+ web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'),
978
+ web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
979
+ web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
980
+ '20000',
981
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
982
+ web3Utils.toChecksumAddress('0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635'),
983
+ 20,
984
+ ]
985
+ ]
986
+ ];
987
+
988
+ examples.forEach(([expected, actual]) => {
989
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
990
+ expect(crvUSDEncode.payback(...actual)).to.eql(expected);
991
+ });
992
+ });
993
+ });
994
+ });
995
+ describe('When testing strategySubService.morphoBlueEncode', () => {
996
+ describe('leverageManagement()', () => {
997
+ const examples: Array<[
998
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
999
+ [
1000
+ marketId: string,
1001
+ loanToken: EthereumAddress,
1002
+ collToken: EthereumAddress,
1003
+ oracle: EthereumAddress,
1004
+ irm: EthereumAddress,
1005
+ lltv: string,
1006
+ ratioState: RatioState,
1007
+ targetRatio: number,
1008
+ triggerRatio: number,
1009
+ user: EthereumAddress,
1010
+ isEoa: boolean,
1011
+ ],
1012
+ ]> = [
1013
+ [
1014
+ [
1015
+ Bundles.MainnetIds.MORPHO_BLUE_REPAY,
1016
+ true,
1017
+ [
1018
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001',
1019
+ ],
1020
+ [
1021
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1022
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1023
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1024
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1025
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1026
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1027
+ '0x000000000000000000000000000000000000000000000000136dcc951d8c0000',
1028
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1029
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1030
+ ],
1031
+ ],
1032
+ [
1033
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
1034
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1035
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1036
+ web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
1037
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1038
+ '945000000000000000',
1039
+ RatioState.UNDER,
1040
+ 140,
1041
+ 120,
1042
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1043
+ false,
1044
+ ]
1045
+ ],
1046
+ [
1047
+ [
1048
+ Bundles.MainnetIds.MORPHO_BLUE_BOOST,
1049
+ true,
1050
+ [
1051
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
1052
+ ],
1053
+ [
1054
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1055
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1056
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1057
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1058
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1059
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1060
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1061
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1062
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1063
+ ],
1064
+ ],
1065
+ [
1066
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
1067
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1068
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1069
+ web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
1070
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1071
+ '945000000000000000',
1072
+ RatioState.OVER,
1073
+ 160,
1074
+ 200,
1075
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1076
+ false,
1077
+ ]
1078
+ ],
1079
+ ];
1080
+
1081
+ examples.forEach(([expected, actual]) => {
1082
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1083
+ expect(morphoBlueEncode.leverageManagement(...actual)).to.eql(expected);
1084
+ });
1085
+ });
1086
+ });
1087
+ });
1088
+
1089
+ describe('When testing strategySubService.compoundV3L2Encode', () => {
1090
+ describe('leverageManagement()', () => {
1091
+ const examples: Array<[string, [EthereumAddress, EthereumAddress, number, number, number, number, boolean]]> = [
1092
+ [
1093
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
1094
+ [
1095
+ web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1096
+ web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1097
+ 160, 220, 180, 190,
1098
+ true
1099
+ ],
1100
+ ],
1101
+ [
1102
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee000000',
1103
+ [
1104
+ web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1105
+ web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1106
+ 160, 220, 180, 110,
1107
+ false
1108
+ ],
1109
+ ],
1110
+ ];
1111
+ examples.forEach(([expected, actual]) => {
1112
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1113
+ expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
1114
+ });
1115
+ });
1116
+ });
1117
+ });
1118
+
1119
+ });