@defisaver/automation-sdk 3.0.3 → 3.0.5

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 +45 -45
  48. package/esm/constants/index.js +395 -365
  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 +701 -698
  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 +87 -87
  62. package/esm/services/strategySubService.js +257 -252
  63. package/esm/services/strategySubService.test.d.ts +1 -1
  64. package/esm/services/strategySubService.test.js +892 -890
  65. package/esm/services/subDataService.d.ts +181 -181
  66. package/esm/services/subDataService.js +442 -442
  67. package/esm/services/subDataService.test.d.ts +1 -1
  68. package/esm/services/subDataService.test.js +1223 -1223
  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 +160 -154
  96. package/esm/types/enums.js +180 -174
  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 +409 -379
  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 +905 -901
  131. package/src/services/strategySubService.test.ts +1063 -1060
  132. package/src/services/strategySubService.ts +496 -492
  133. package/src/services/subDataService.test.ts +1324 -1324
  134. package/src/services/subDataService.ts +594 -593
  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 +174 -168
  140. package/src/types/index.ts +262 -262
  141. package/tsconfig.json +79 -79
  142. package/umd/index.js +65 -24
  143. package/webpack.umd.js +52 -52
@@ -1,1060 +1,1063 @@
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
- ],
957
- ]> = [
958
- [
959
- [
960
- Bundles.MainnetIds.MORPHO_BLUE_REPAY,
961
- true,
962
- [
963
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001',
964
- ],
965
- [
966
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
967
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
968
- '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
969
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
970
- '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
971
- '0x0000000000000000000000000000000000000000000000000000000000000001',
972
- '0x000000000000000000000000000000000000000000000000136dcc951d8c0000',
973
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
974
- ],
975
- ],
976
- [
977
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
978
- web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
979
- web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
980
- web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
981
- web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
982
- '945000000000000000',
983
- RatioState.UNDER,
984
- 140,
985
- 120,
986
- web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c')
987
- ]
988
- ],
989
- [
990
- [
991
- Bundles.MainnetIds.MORPHO_BLUE_BOOST,
992
- true,
993
- [
994
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
995
- ],
996
- [
997
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
998
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
999
- '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1000
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1001
- '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1002
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1003
- '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1004
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1005
- ],
1006
- ],
1007
- [
1008
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
1009
- web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1010
- web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1011
- web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
1012
- web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1013
- '945000000000000000',
1014
- RatioState.OVER,
1015
- 160,
1016
- 200,
1017
- web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c')
1018
- ]
1019
- ],
1020
- ];
1021
-
1022
- examples.forEach(([expected, actual]) => {
1023
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1024
- expect(morphoBlueEncode.leverageManagement(...actual)).to.eql(expected);
1025
- });
1026
- });
1027
- });
1028
- });
1029
-
1030
- describe('When testing strategySubService.compoundV3L2Encode', () => {
1031
- describe('leverageManagement()', () => {
1032
- const examples: Array<[string, [EthereumAddress, EthereumAddress, number, number, number, number, boolean]]> = [
1033
- [
1034
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
1035
- [
1036
- web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1037
- web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1038
- 160, 220, 180, 190,
1039
- true
1040
- ],
1041
- ],
1042
- [
1043
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee000000',
1044
- [
1045
- web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1046
- web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1047
- 160, 220, 180, 110,
1048
- false
1049
- ],
1050
- ],
1051
- ];
1052
- examples.forEach(([expected, actual]) => {
1053
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1054
- expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
1055
- });
1056
- });
1057
- });
1058
- });
1059
-
1060
- });
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
+ ],
976
+ ],
977
+ [
978
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
979
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
980
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
981
+ web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
982
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
983
+ '945000000000000000',
984
+ RatioState.UNDER,
985
+ 140,
986
+ 120,
987
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
988
+ false,
989
+ ]
990
+ ],
991
+ [
992
+ [
993
+ Bundles.MainnetIds.MORPHO_BLUE_BOOST,
994
+ true,
995
+ [
996
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
997
+ ],
998
+ [
999
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1000
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1001
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1002
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1003
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1004
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1005
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1006
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1007
+ ],
1008
+ ],
1009
+ [
1010
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
1011
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1012
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1013
+ web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
1014
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1015
+ '945000000000000000',
1016
+ RatioState.OVER,
1017
+ 160,
1018
+ 200,
1019
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1020
+ false,
1021
+ ]
1022
+ ],
1023
+ ];
1024
+
1025
+ examples.forEach(([expected, actual]) => {
1026
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1027
+ expect(morphoBlueEncode.leverageManagement(...actual)).to.eql(expected);
1028
+ });
1029
+ });
1030
+ });
1031
+ });
1032
+
1033
+ describe('When testing strategySubService.compoundV3L2Encode', () => {
1034
+ describe('leverageManagement()', () => {
1035
+ const examples: Array<[string, [EthereumAddress, EthereumAddress, number, number, number, number, boolean]]> = [
1036
+ [
1037
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
1038
+ [
1039
+ web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1040
+ web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1041
+ 160, 220, 180, 190,
1042
+ true
1043
+ ],
1044
+ ],
1045
+ [
1046
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee000000',
1047
+ [
1048
+ web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1049
+ web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1050
+ 160, 220, 180, 110,
1051
+ false
1052
+ ],
1053
+ ],
1054
+ ];
1055
+ examples.forEach(([expected, actual]) => {
1056
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1057
+ expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
1058
+ });
1059
+ });
1060
+ });
1061
+ });
1062
+
1063
+ });