@defisaver/automation-sdk 3.1.9 → 3.1.14-spark-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) 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 +39 -39
  6. package/.mocharc.json +4 -4
  7. package/.nvmrc +1 -1
  8. package/README.md +46 -46
  9. package/cjs/abis/Erc20.json +223 -223
  10. package/cjs/abis/SubStorage.json +21 -21
  11. package/cjs/abis/UniMulticall.json +17 -17
  12. package/cjs/abis/index.d.ts +9 -9
  13. package/cjs/abis/index.js +30 -30
  14. package/cjs/abis/legacy_AaveV2Subscriptions.json +8 -8
  15. package/cjs/abis/legacy_AuthCheck.json +8 -8
  16. package/cjs/abis/legacy_CompoundV2Subscriptions.json +9 -9
  17. package/cjs/abis/legacy_MakerSubscriptions.json +9 -9
  18. package/cjs/automation/private/Automation.d.ts +12 -12
  19. package/cjs/automation/private/Automation.js +42 -42
  20. package/cjs/automation/private/LegacyAutomation.d.ts +25 -25
  21. package/cjs/automation/private/LegacyAutomation.js +118 -118
  22. package/cjs/automation/private/LegacyProtocol.d.ts +22 -22
  23. package/cjs/automation/private/LegacyProtocol.js +41 -41
  24. package/cjs/automation/private/LegacyProtocol.test.d.ts +1 -1
  25. package/cjs/automation/private/LegacyProtocol.test.js +25 -25
  26. package/cjs/automation/private/Protocol.d.ts +22 -22
  27. package/cjs/automation/private/Protocol.js +41 -41
  28. package/cjs/automation/private/Protocol.test.d.ts +1 -1
  29. package/cjs/automation/private/Protocol.test.js +25 -25
  30. package/cjs/automation/private/StrategiesAutomation.d.ts +35 -33
  31. package/cjs/automation/private/StrategiesAutomation.js +198 -181
  32. package/cjs/automation/private/StrategiesAutomation.test.d.ts +1 -1
  33. package/cjs/automation/private/StrategiesAutomation.test.js +696 -671
  34. package/cjs/automation/public/ArbitrumStrategies.d.ts +5 -5
  35. package/cjs/automation/public/ArbitrumStrategies.js +13 -13
  36. package/cjs/automation/public/BaseStrategies.d.ts +5 -5
  37. package/cjs/automation/public/BaseStrategies.js +13 -13
  38. package/cjs/automation/public/EthereumStrategies.d.ts +5 -5
  39. package/cjs/automation/public/EthereumStrategies.js +13 -13
  40. package/cjs/automation/public/OptimismStrategies.d.ts +5 -5
  41. package/cjs/automation/public/OptimismStrategies.js +13 -13
  42. package/cjs/automation/public/Strategies.test.d.ts +1 -1
  43. package/cjs/automation/public/Strategies.test.js +61 -61
  44. package/cjs/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
  45. package/cjs/automation/public/legacy/LegacyAaveAutomation.js +20 -20
  46. package/cjs/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
  47. package/cjs/automation/public/legacy/LegacyCompoundAutomation.js +20 -20
  48. package/cjs/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
  49. package/cjs/automation/public/legacy/LegacyMakerAutomation.js +20 -20
  50. package/cjs/configuration.d.ts +1 -1
  51. package/cjs/configuration.js +12 -12
  52. package/cjs/constants/index.d.ts +29 -28
  53. package/cjs/constants/index.js +905 -534
  54. package/cjs/index.d.ts +24 -23
  55. package/cjs/index.js +65 -65
  56. package/cjs/services/contractService.d.ts +12 -12
  57. package/cjs/services/contractService.js +54 -54
  58. package/cjs/services/ethereumService.d.ts +7 -7
  59. package/cjs/services/ethereumService.js +56 -49
  60. package/cjs/services/ethereumService.test.d.ts +1 -1
  61. package/cjs/services/ethereumService.test.js +245 -242
  62. package/cjs/services/strategiesService.d.ts +2 -2
  63. package/cjs/services/strategiesService.js +1173 -861
  64. package/cjs/services/strategiesService.test.d.ts +1 -1
  65. package/cjs/services/strategiesService.test.js +111 -110
  66. package/cjs/services/strategySubService.d.ts +129 -107
  67. package/cjs/services/strategySubService.js +414 -300
  68. package/cjs/services/strategySubService.test.d.ts +1 -1
  69. package/cjs/services/strategySubService.test.js +1812 -936
  70. package/cjs/services/subDataService.d.ts +527 -245
  71. package/cjs/services/subDataService.js +1219 -636
  72. package/cjs/services/subDataService.test.d.ts +1 -1
  73. package/cjs/services/subDataService.test.js +2427 -1282
  74. package/cjs/services/triggerService.d.ts +325 -226
  75. package/cjs/services/triggerService.js +616 -433
  76. package/cjs/services/triggerService.test.d.ts +1 -1
  77. package/cjs/services/triggerService.test.js +1317 -926
  78. package/cjs/services/utils.d.ts +30 -30
  79. package/cjs/services/utils.js +190 -182
  80. package/cjs/services/utils.test.d.ts +1 -1
  81. package/cjs/services/utils.test.js +299 -376
  82. package/cjs/types/contracts/generated/Erc20.d.ts +53 -53
  83. package/cjs/types/contracts/generated/Erc20.js +5 -5
  84. package/cjs/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
  85. package/cjs/types/contracts/generated/Legacy_AaveV2Subscriptions.js +5 -5
  86. package/cjs/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
  87. package/cjs/types/contracts/generated/Legacy_AuthCheck.js +5 -5
  88. package/cjs/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
  89. package/cjs/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +5 -5
  90. package/cjs/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
  91. package/cjs/types/contracts/generated/Legacy_MakerSubscriptions.js +5 -5
  92. package/cjs/types/contracts/generated/SubStorage.d.ts +114 -114
  93. package/cjs/types/contracts/generated/SubStorage.js +5 -5
  94. package/cjs/types/contracts/generated/UniMulticall.d.ts +55 -55
  95. package/cjs/types/contracts/generated/UniMulticall.js +5 -5
  96. package/cjs/types/contracts/generated/index.d.ts +7 -7
  97. package/cjs/types/contracts/generated/index.js +2 -2
  98. package/cjs/types/contracts/generated/types.d.ts +54 -54
  99. package/cjs/types/contracts/generated/types.js +2 -2
  100. package/cjs/types/enums.d.ts +302 -219
  101. package/cjs/types/enums.js +328 -245
  102. package/cjs/types/index.d.ts +306 -248
  103. package/cjs/types/index.js +2 -2
  104. package/esm/abis/Erc20.json +223 -223
  105. package/esm/abis/SubStorage.json +21 -21
  106. package/esm/abis/UniMulticall.json +17 -17
  107. package/esm/abis/index.d.ts +9 -9
  108. package/esm/abis/index.js +18 -18
  109. package/esm/abis/legacy_AaveV2Subscriptions.json +8 -8
  110. package/esm/abis/legacy_AuthCheck.json +8 -8
  111. package/esm/abis/legacy_CompoundV2Subscriptions.json +9 -9
  112. package/esm/abis/legacy_MakerSubscriptions.json +9 -9
  113. package/esm/automation/private/Automation.d.ts +12 -12
  114. package/esm/automation/private/Automation.js +39 -39
  115. package/esm/automation/private/LegacyAutomation.d.ts +25 -25
  116. package/esm/automation/private/LegacyAutomation.js +112 -112
  117. package/esm/automation/private/LegacyProtocol.d.ts +22 -22
  118. package/esm/automation/private/LegacyProtocol.js +38 -38
  119. package/esm/automation/private/LegacyProtocol.test.d.ts +1 -1
  120. package/esm/automation/private/LegacyProtocol.test.js +20 -20
  121. package/esm/automation/private/Protocol.d.ts +22 -22
  122. package/esm/automation/private/Protocol.js +38 -38
  123. package/esm/automation/private/Protocol.test.d.ts +1 -1
  124. package/esm/automation/private/Protocol.test.js +20 -20
  125. package/esm/automation/private/StrategiesAutomation.d.ts +35 -33
  126. package/esm/automation/private/StrategiesAutomation.js +192 -175
  127. package/esm/automation/private/StrategiesAutomation.test.d.ts +1 -1
  128. package/esm/automation/private/StrategiesAutomation.test.js +691 -666
  129. package/esm/automation/public/ArbitrumStrategies.d.ts +5 -5
  130. package/esm/automation/public/ArbitrumStrategies.js +7 -7
  131. package/esm/automation/public/BaseStrategies.d.ts +5 -5
  132. package/esm/automation/public/BaseStrategies.js +7 -7
  133. package/esm/automation/public/EthereumStrategies.d.ts +5 -5
  134. package/esm/automation/public/EthereumStrategies.js +7 -7
  135. package/esm/automation/public/OptimismStrategies.d.ts +5 -5
  136. package/esm/automation/public/OptimismStrategies.js +7 -7
  137. package/esm/automation/public/Strategies.test.d.ts +1 -1
  138. package/esm/automation/public/Strategies.test.js +56 -56
  139. package/esm/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
  140. package/esm/automation/public/legacy/LegacyAaveAutomation.js +14 -14
  141. package/esm/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
  142. package/esm/automation/public/legacy/LegacyCompoundAutomation.js +14 -14
  143. package/esm/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
  144. package/esm/automation/public/legacy/LegacyMakerAutomation.js +14 -14
  145. package/esm/configuration.d.ts +1 -1
  146. package/esm/configuration.js +7 -7
  147. package/esm/constants/index.d.ts +29 -28
  148. package/esm/constants/index.js +899 -528
  149. package/esm/index.d.ts +24 -23
  150. package/esm/index.js +23 -23
  151. package/esm/services/contractService.d.ts +12 -12
  152. package/esm/services/contractService.js +45 -45
  153. package/esm/services/ethereumService.d.ts +7 -7
  154. package/esm/services/ethereumService.js +48 -41
  155. package/esm/services/ethereumService.test.d.ts +1 -1
  156. package/esm/services/ethereumService.test.js +240 -237
  157. package/esm/services/strategiesService.d.ts +2 -2
  158. package/esm/services/strategiesService.js +1143 -831
  159. package/esm/services/strategiesService.test.d.ts +1 -1
  160. package/esm/services/strategiesService.test.js +109 -108
  161. package/esm/services/strategySubService.d.ts +129 -107
  162. package/esm/services/strategySubService.js +385 -271
  163. package/esm/services/strategySubService.test.d.ts +1 -1
  164. package/esm/services/strategySubService.test.js +1784 -908
  165. package/esm/services/subDataService.d.ts +527 -245
  166. package/esm/services/subDataService.js +1213 -630
  167. package/esm/services/subDataService.test.d.ts +1 -1
  168. package/esm/services/subDataService.test.js +2399 -1254
  169. package/esm/services/triggerService.d.ts +325 -226
  170. package/esm/services/triggerService.js +587 -404
  171. package/esm/services/triggerService.test.d.ts +1 -1
  172. package/esm/services/triggerService.test.js +1292 -901
  173. package/esm/services/utils.d.ts +30 -30
  174. package/esm/services/utils.js +139 -131
  175. package/esm/services/utils.test.d.ts +1 -1
  176. package/esm/services/utils.test.js +297 -348
  177. package/esm/types/contracts/generated/Erc20.d.ts +53 -53
  178. package/esm/types/contracts/generated/Erc20.js +4 -4
  179. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
  180. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +4 -4
  181. package/esm/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
  182. package/esm/types/contracts/generated/Legacy_AuthCheck.js +4 -4
  183. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
  184. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +4 -4
  185. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
  186. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +4 -4
  187. package/esm/types/contracts/generated/SubStorage.d.ts +114 -114
  188. package/esm/types/contracts/generated/SubStorage.js +4 -4
  189. package/esm/types/contracts/generated/UniMulticall.d.ts +55 -55
  190. package/esm/types/contracts/generated/UniMulticall.js +4 -4
  191. package/esm/types/contracts/generated/index.d.ts +7 -7
  192. package/esm/types/contracts/generated/index.js +1 -1
  193. package/esm/types/contracts/generated/types.d.ts +54 -54
  194. package/esm/types/contracts/generated/types.js +1 -1
  195. package/esm/types/enums.d.ts +302 -219
  196. package/esm/types/enums.js +325 -242
  197. package/esm/types/index.d.ts +306 -248
  198. package/esm/types/index.js +1 -1
  199. package/package.json +60 -61
  200. package/scripts/generateContractTypes.js +39 -39
  201. package/src/abis/Erc20.json +222 -222
  202. package/src/abis/SubStorage.json +21 -21
  203. package/src/abis/UniMulticall.json +17 -17
  204. package/src/abis/index.ts +28 -28
  205. package/src/abis/legacy_AaveV2Subscriptions.json +7 -7
  206. package/src/abis/legacy_AuthCheck.json +7 -7
  207. package/src/abis/legacy_CompoundV2Subscriptions.json +8 -8
  208. package/src/abis/legacy_MakerSubscriptions.json +8 -8
  209. package/src/automation/private/Automation.ts +44 -44
  210. package/src/automation/private/LegacyAutomation.ts +135 -135
  211. package/src/automation/private/LegacyProtocol.test.ts +23 -23
  212. package/src/automation/private/LegacyProtocol.ts +51 -51
  213. package/src/automation/private/Protocol.test.ts +23 -23
  214. package/src/automation/private/Protocol.ts +51 -51
  215. package/src/automation/private/StrategiesAutomation.test.ts +703 -663
  216. package/src/automation/private/StrategiesAutomation.ts +265 -242
  217. package/src/automation/public/ArbitrumStrategies.ts +10 -10
  218. package/src/automation/public/BaseStrategies.ts +10 -10
  219. package/src/automation/public/EthereumStrategies.ts +10 -10
  220. package/src/automation/public/OptimismStrategies.ts +10 -10
  221. package/src/automation/public/Strategies.test.ts +49 -49
  222. package/src/automation/public/legacy/LegacyAaveAutomation.ts +20 -20
  223. package/src/automation/public/legacy/LegacyCompoundAutomation.ts +20 -20
  224. package/src/automation/public/legacy/LegacyMakerAutomation.ts +20 -20
  225. package/src/configuration.ts +8 -8
  226. package/src/constants/index.ts +935 -563
  227. package/src/index.ts +41 -39
  228. package/src/services/contractService.ts +77 -77
  229. package/src/services/ethereumService.test.ts +260 -257
  230. package/src/services/ethereumService.ts +76 -69
  231. package/src/services/strategiesService.test.ts +106 -105
  232. package/src/services/strategiesService.ts +1473 -1111
  233. package/src/services/strategySubService.test.ts +2136 -1122
  234. package/src/services/strategySubService.ts +987 -617
  235. package/src/services/subDataService.test.ts +2630 -1387
  236. package/src/services/subDataService.ts +1631 -870
  237. package/src/services/triggerService.test.ts +1434 -1004
  238. package/src/services/triggerService.ts +819 -553
  239. package/src/services/utils.test.ts +371 -430
  240. package/src/services/utils.ts +173 -162
  241. package/src/types/enums.ts +322 -239
  242. package/src/types/index.ts +385 -312
  243. package/tsconfig.esm.json +8 -8
  244. package/tsconfig.json +22 -22
  245. package/umd/index.js +0 -34103
@@ -1,1122 +1,2136 @@
1
- import { expect } from 'chai';
2
- import Dec from 'decimal.js';
3
- import { otherAddresses } from '@defisaver/sdk';
4
- import { getAssetInfo } from '@defisaver/tokens';
5
- import * as web3Utils from 'web3-utils';
6
-
7
- import { Bundles, ChainId, OrderType, RatioState, Strategies } from '../types/enums';
8
- import type { EthereumAddress, StrategyOrBundleIds, SubData, TriggerData } from '../types';
9
-
10
- import '../configuration';
11
- import {
12
- aaveV2Encode,
13
- chickenBondsEncode,
14
- liquityEncode,
15
- makerEncode,
16
- aaveV3Encode,
17
- compoundV2Encode,
18
- compoundV3Encode,
19
- morphoAaveV2Encode,
20
- exchangeEncode,
21
- sparkEncode,
22
- crvUSDEncode, compoundV3L2Encode, morphoBlueEncode,
23
- } from './strategySubService';
24
-
25
- describe('Feature: strategySubService.ts', () => {
26
- describe('When testing strategySubService.makerEncode', () => {
27
- // @ts-ignore // TODO - this requires change in @defisaver/tokens
28
- const mcdCdpManagerAddr = otherAddresses(ChainId.Ethereum).McdCdpManager;
29
-
30
- describe('repayFromSavings()', () => {
31
- const examples: Array<[
32
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
33
- [
34
- bundleId: StrategyOrBundleIds, vaultId: number, triggerRepayRatio: number, targetRepayRatio: number,
35
- isBundle?: boolean, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress,
36
- ]
37
- ]> = [
38
- [
39
- [
40
- Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_RARI,
41
- true,
42
- ['0x00000000000000000000000000000000000000000000000000000000000000de000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
43
- [
44
- '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
45
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
46
- ],
47
- ],
48
- [
49
- Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_RARI,
50
- 222,
51
- 140,
52
- 180,
53
- true,
54
- ChainId.Ethereum,
55
- getAssetInfo('DAI').address,
56
- mcdCdpManagerAddr,
57
- ]
58
- ]
59
- ];
60
-
61
- examples.forEach(([expected, actual]) => {
62
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
63
- expect(makerEncode.repayFromSavings(...actual)).to.eql(expected);
64
- });
65
- });
66
- });
67
-
68
- describe('closeOnPrice()', () => {
69
- const examples: Array<[
70
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
71
- [
72
- vaultId: number, ratioState: RatioState, price: string, closeToAssetAddr: EthereumAddress,
73
- chainlinkCollAddress: EthereumAddress, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress,
74
- ]
75
- ]> = [
76
- [
77
- [
78
- Strategies.MainnetIds.MAKER_CLOSE_ON_PRICE_TO_DAI,
79
- false,
80
- ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000002cc9e4c0000000000000000000000000000000000000000000000000000000000000000'],
81
- [
82
- '0x0000000000000000000000000000000000000000000000000000000000000078', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
83
- '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
84
- ],
85
- ],
86
- [
87
- 120,
88
- RatioState.OVER,
89
- '0.469643',
90
- getAssetInfo('DAI').address,
91
- getAssetInfo('WBTC').address,
92
- ChainId.Ethereum,
93
- ]
94
- ]
95
- ];
96
-
97
- examples.forEach(([expected, actual]) => {
98
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
99
- expect(makerEncode.closeOnPrice(...actual)).to.eql(expected);
100
- });
101
- });
102
- });
103
-
104
- describe('trailingStop()', () => {
105
- const examples: Array<[
106
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
107
- [
108
- vaultId: number, triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress,
109
- roundId: number, chainId: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress,
110
- ]
111
- ]> = [
112
- [
113
- [
114
- Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_COLL,
115
- false,
116
- ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000000000000000000000000000000000055ae82600000000000000000000000000000000000000000000000000000000000000007b'],
117
- [
118
- '0x000000000000000000000000000000000000000000000000000000000000096e', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
119
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
120
- ],
121
- ],
122
- [
123
- 2414,
124
- 230,
125
- getAssetInfo('WBTC').address,
126
- getAssetInfo('WBTC').address,
127
- 123,
128
- ChainId.Ethereum,
129
- ]
130
- ]
131
- ];
132
-
133
- examples.forEach(([expected, actual]) => {
134
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
135
- expect(makerEncode.trailingStop(...actual)).to.eql(expected);
136
- });
137
- });
138
- });
139
-
140
- describe('leverageManagement()', () => {
141
- const examples: Array<[
142
- [
143
- vaultId: number, triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
144
- targetRepayRatio: string, boostEnabled: boolean,
145
- ],
146
- [
147
- vaultId: number, triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
148
- targetRepayRatio: string, boostEnabled: boolean,
149
- ]
150
- ]> = [
151
- [
152
- [
153
- 5791,
154
- new Dec('210').mul(1e16).toString(),
155
- new Dec('290').mul(1e16).toString(),
156
- new Dec('240').mul(1e16).toString(),
157
- new Dec('240').mul(1e16).toString(),
158
- true,
159
- ],
160
- [
161
- 5791, '210', '290', '240', '240', true,
162
- ]
163
- ]
164
- ];
165
-
166
- examples.forEach(([expected, actual]) => {
167
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
168
- expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
169
- });
170
- });
171
- });
172
- });
173
-
174
- describe('When testing strategySubService.liquityEncode', () => {
175
- describe('closeOnPrice()', () => {
176
- const examples: Array<[
177
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
178
- [
179
- priceOverOrUnder: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress,
180
- chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress,
181
- ]
182
- ]> = [
183
- [
184
- [
185
- Strategies.MainnetIds.LIQUITY_CLOSE_ON_PRICE_TO_COLL,
186
- false,
187
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000001c027053000000000000000000000000000000000000000000000000000000000000000000'],
188
- [
189
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
190
- ],
191
- ],
192
- [
193
- RatioState.OVER,
194
- '1203',
195
- getAssetInfo('WETH').address,
196
- getAssetInfo('WETH').address,
197
- ]
198
- ]
199
- ];
200
-
201
- examples.forEach(([expected, actual]) => {
202
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
203
- expect(liquityEncode.closeOnPrice(...actual)).to.eql(expected);
204
- });
205
- });
206
- });
207
-
208
- describe('trailingStop()', () => {
209
- const examples: Array<[
210
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
211
- [
212
- triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number,
213
- chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress,
214
- ]
215
- ]> = [
216
- [
217
- [
218
- Strategies.MainnetIds.LIQUITY_TRAILING_STOP_LOSS_TO_COLL,
219
- false,
220
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000055ae826000000000000000000000000000000000000000000000000000000000000000c97'],
221
- [
222
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
223
- ],
224
- ],
225
- [
226
- 230,
227
- getAssetInfo('WETH').address,
228
- getAssetInfo('WETH').address,
229
- 3223,
230
- ]
231
- ]
232
- ];
233
-
234
- examples.forEach(([expected, actual]) => {
235
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
236
- expect(liquityEncode.trailingStop(...actual)).to.eql(expected);
237
- });
238
- });
239
- });
240
-
241
- describe('leverageManagement()', () => {
242
- const examples: Array<[
243
- [
244
- triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
245
- targetRepayRatio: string, boostEnabled: boolean,
246
- ],
247
- [
248
- triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
249
- targetRepayRatio: string, boostEnabled: boolean,
250
- ]
251
- ]> = [
252
- [
253
- [
254
- new Dec('210').mul(1e16).toString(),
255
- new Dec('290').mul(1e16).toString(),
256
- new Dec('240').mul(1e16).toString(),
257
- new Dec('240').mul(1e16).toString(),
258
- false,
259
- ],
260
- [
261
- '210', '290', '240', '240', false,
262
- ]
263
- ]
264
- ];
265
-
266
- examples.forEach(([expected, actual]) => {
267
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
268
- expect(liquityEncode.leverageManagement(...actual)).to.eql(expected);
269
- });
270
- });
271
- });
272
-
273
- describe('paybackFromChickenBondStrategySub()', () => {
274
- const examples: Array<[
275
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
276
- [
277
- proxyAddress: EthereumAddress, ratio: number, sourceId: string, sourceType: number, ratioState: RatioState,
278
- ]
279
- ]> = [
280
- [
281
- [
282
- Bundles.MainnetIds.LIQUITY_PAYBACK_USING_CHICKEN_BOND,
283
- true,
284
- ['0x0000000000000000000000002439d211133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002dcbf4840eca00000000000000000000000000000000000000000000000000000000000000000000'],
285
- [
286
- '0x000000000000000000000000000000000000000000000000000000000000007b', '0x0000000000000000000000000000000000000000000000000000000000000000',
287
- '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
288
- ],
289
- ],
290
- [
291
- web3Utils.toChecksumAddress('0x2439d211133AFaB8F2B819B1066c7E434Ad94E9e'),
292
- 330,
293
- '123',
294
- 0,
295
- RatioState.OVER
296
- ]
297
- ]
298
- ];
299
-
300
- examples.forEach(([expected, actual]) => {
301
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
302
- expect(liquityEncode.paybackFromChickenBondStrategySub(...actual)).to.eql(expected);
303
- });
304
- });
305
- });
306
-
307
- describe('dsrPayback()', () => {
308
- const examples: Array<[
309
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
310
- [proxyAddress: EthereumAddress, triggerRatio: number, targetRatio: number],
311
- ]> = [
312
- [
313
- [
314
- Strategies.MainnetIds.LIQUITY_DSR_PAYBACK,
315
- false,
316
- ['0x0000000000000000000000002439d211133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000250dbeda8e4b00000000000000000000000000000000000000000000000000000000000000000001'],
317
- [
318
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x00000000000000000000000000000000000000000000000029a2241af62c0000',
319
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
320
- ],
321
- ],
322
- [web3Utils.toChecksumAddress('0x2439d211133AFaB8F2B819B1066c7E434Ad94E9e'), 267, 300]
323
- ]
324
- ];
325
-
326
- examples.forEach(([expected, actual]) => {
327
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
328
- expect(liquityEncode.dsrPayback(...actual)).to.eql(expected);
329
- });
330
- });
331
- });
332
-
333
- describe('debtInFrontRepay()', () => {
334
- const examples: Array<[
335
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
336
- [proxyAddress: EthereumAddress, debtInFrontMin: string, targetRatioIncrease: number],
337
- ]> = [
338
- [
339
- [
340
- Strategies.MainnetIds.LIQUITY_DEBT_IN_FRONT_REPAY,
341
- false,
342
- ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a0000000000000000000000000000000000000000019d971e4fe8401e74000000'],
343
- [
344
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
345
- '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
346
- '0x0000000000000000000000000000000000000000000000000000000000000000'
347
- ],
348
- ],
349
- [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '500000000', 45]
350
- ]
351
- ];
352
-
353
- examples.forEach(([expected, actual]) => {
354
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
355
- expect(liquityEncode.debtInFrontRepay(...actual)).to.eql(expected);
356
- });
357
- });
358
- });
359
- });
360
-
361
- describe('When testing strategySubService.chickenBondsEncode', () => {
362
- describe('rebond()', () => {
363
- const examples: Array<[
364
- SubData,
365
- [bondId: number],
366
- ]> = [
367
- [
368
- ['0x00000000000000000000000000000000000000000000000000000000000005e3'],
369
- [1507]
370
- ]
371
- ];
372
-
373
- examples.forEach(([expected, actual]) => {
374
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
375
- expect(chickenBondsEncode.rebond(...actual)).to.eql(expected);
376
- });
377
- });
378
- });
379
- });
380
-
381
- describe('When testing strategySubService.aaveV2Encode', () => {
382
- describe('leverageManagement()', () => {
383
- const examples: Array<[
384
- [string, string, string, string, boolean],
385
- [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
386
- ]> = [
387
- [
388
- [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
389
- [160, 220, 180, 190, true]
390
- ],
391
- [
392
- [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
393
- [160, 200, 180, 190, false]
394
- ],
395
- ];
396
-
397
- examples.forEach(([expected, actual]) => {
398
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
399
- expect(aaveV2Encode.leverageManagement(...actual)).to.eql(expected);
400
- });
401
- });
402
- });
403
- });
404
-
405
- describe('When testing strategySubService.aaveV3Encode', () => {
406
- describe('leverageManagement()', () => {
407
- const examples: Array<[
408
- string,
409
- [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
410
- ]> = [
411
- [
412
- '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
413
- [160, 220, 180, 190, true]
414
- ],
415
- [
416
- '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
417
- [160, 200, 180, 190, false]
418
- ],
419
- ];
420
-
421
- examples.forEach(([expected, actual]) => {
422
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
423
- expect(aaveV3Encode.leverageManagement(...actual)).to.eql(expected);
424
- });
425
- });
426
- });
427
-
428
- describe('closeToAsset()', () => {
429
- const examples: Array<[
430
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
431
- [
432
- strategyOrBundleId: number,
433
- isBundle: boolean,
434
- triggerData: {
435
- baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState
436
- },
437
- subData: {
438
- collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
439
- },
440
- ]
441
- ]> = [
442
- [
443
- [
444
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
445
- true,
446
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
447
- [
448
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
449
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
450
- '0x0000000000000000000000000000000000000000000000000000000000000000',
451
- ],
452
- ],
453
- [
454
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
455
- true,
456
- {
457
- baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER
458
- },
459
- {
460
- collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
461
- },
462
- ]
463
- ],
464
- [
465
- [
466
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
467
- true,
468
- ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
469
- [
470
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
471
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
472
- '0x0000000000000000000000000000000000000000000000000000000000000000',
473
- ],
474
- ],
475
- [
476
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
477
- true,
478
- {
479
- baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER
480
- },
481
- {
482
- collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
483
- },
484
- ]
485
- ]
486
- ];
487
-
488
- examples.forEach(([expected, actual]) => {
489
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
490
- expect(aaveV3Encode.closeToAsset(...actual)).to.eql(expected);
491
- });
492
- });
493
- });
494
-
495
- describe('closeToAssetWithMaximumGasPrice()', () => {
496
- const examples: Array<[
497
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
498
- [
499
- strategyOrBundleId: number,
500
- isBundle: boolean,
501
- triggerData: {
502
- baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState, maximumGasPrice: number
503
- },
504
- subData: {
505
- collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
506
- },
507
- ]
508
- ]> = [
509
- [
510
- [
511
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
512
- true,
513
- [
514
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000',
515
- '0x00000000000000000000000000000000000000000000000000000002cb417800',
516
- ],
517
- [
518
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
519
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
520
- '0x0000000000000000000000000000000000000000000000000000000000000000',
521
- ],
522
- ],
523
- [
524
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
525
- true,
526
- {
527
- baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER, maximumGasPrice: 12,
528
- },
529
- {
530
- collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
531
- },
532
- ]
533
- ],
534
- [
535
- [
536
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
537
- true,
538
- [
539
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001',
540
- '0x0000000000000000000000000000000000000000000000000000004a817c8000',
541
- ],
542
- [
543
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
544
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
545
- '0x0000000000000000000000000000000000000000000000000000000000000000',
546
- ],
547
- ],
548
- [
549
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
550
- true,
551
- {
552
- baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER, maximumGasPrice: 320,
553
- },
554
- {
555
- collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
556
- },
557
- ]
558
- ]
559
- ];
560
-
561
- examples.forEach(([expected, actual]) => {
562
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
563
- expect(aaveV3Encode.closeToAssetWithMaximumGasPrice(...actual)).to.eql(expected);
564
- });
565
- });
566
- });
567
-
568
- describe('leverageManagementOnPrice()', () => {
569
- const examples: Array<[
570
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
571
- [
572
- strategyOrBundleId: number,
573
- isBundle: boolean,
574
- triggerData: {
575
- baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState.UNDER
576
- },
577
- subData: {
578
- collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number,
579
- },
580
- ]
581
- ]> = [
582
- [
583
- [
584
- Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
585
- true,
586
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000007acead34980000000000000000000000000000000000000000000000000000000000000001'],
587
- [
588
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
589
- '0x000000000000000000000000000000000000000000000000000000000000000a',
590
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
591
- '0x0000000000000000000000000000000000000000000000000000000000000004',
592
- '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
593
- '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
594
- '0x0000000000000000000000000000000000000000000000000000000000000000',
595
- ],
596
- ],
597
- [
598
- Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
599
- true,
600
- {
601
- baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 5274.534678, state: RatioState.UNDER
602
- },
603
- {
604
- collAsset: getAssetInfo('WETH').address,
605
- collAssetId: 10,
606
- debtAsset: getAssetInfo('DAI').address,
607
- debtAssetId: 4,
608
- marketAddr: '0x2f39d218133afab8f2b819b1066c7e434ad94e9e',
609
- targetRatio: 200,
610
- },
611
- ]
612
- ],
613
- ];
614
-
615
- examples.forEach(([expected, actual]) => {
616
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
617
- expect(aaveV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
618
- });
619
- });
620
- });
621
- });
622
-
623
- describe('When testing strategySubService.compoundV2Encode', () => {
624
- describe('leverageManagement()', () => {
625
- const examples: Array<[
626
- [string, string, string, string, boolean],
627
- [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
628
- ]> = [
629
- [
630
- [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
631
- [160, 220, 180, 190, true]
632
- ],
633
- [
634
- [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
635
- [160, 200, 180, 190, false]
636
- ],
637
- ];
638
-
639
- examples.forEach(([expected, actual]) => {
640
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
641
- expect(compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
642
- });
643
- });
644
- });
645
- });
646
-
647
- describe('When testing strategySubService.compoundV3Encode', () => {
648
- describe('leverageManagement()', () => {
649
- const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string, boolean, boolean], [market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean]]> = [
650
- [
651
- [
652
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
653
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
654
- new Dec(160).mul(1e16).toString(),
655
- new Dec(220).mul(1e16).toString(),
656
- new Dec(180).mul(1e16).toString(),
657
- new Dec(190).mul(1e16).toString(),
658
- true, false,
659
- ],
660
- [
661
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
662
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
663
- 160, 220, 180, 190,
664
- true, false,
665
- ]
666
- ],
667
- [
668
- [
669
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
670
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
671
- new Dec(160).mul(1e16).toString(),
672
- new Dec(210).mul(1e16).toString(),
673
- new Dec(180).mul(1e16).toString(),
674
- new Dec(190).mul(1e16).toString(),
675
- false, true,
676
- ],
677
- [
678
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
679
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
680
- 160, 210, 180, 190,
681
- false, true,
682
- ]
683
- ],
684
- ];
685
- examples.forEach(([expected, actual]) => {
686
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
687
- expect(compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
688
- });
689
- });
690
- });
691
- });
692
-
693
- describe('When testing strategySubService.morphoAaveV2Encode', () => {
694
- describe('leverageManagement()', () => {
695
- const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
696
- [
697
- [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
698
- [160, 220, 180, 190, true]
699
- ],
700
- [
701
- [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
702
- [160, 200, 180, 190, false]
703
- ],
704
- ];
705
-
706
- examples.forEach(([expected, actual]) => {
707
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
708
- expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
709
- });
710
- });
711
- });
712
- });
713
-
714
- describe('When testing strategySubService.exchangeEncode', () => {
715
- describe('dca()', () => {
716
- const examples: Array<[
717
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
718
- [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number, network: ChainId],
719
- ]> = [
720
- [
721
- [
722
- Strategies.ArbitrumIds.EXCHANGE_DCA,
723
- false,
724
- ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd000000000000000000000000000000000000000000000000000000000012d068'],
725
- [
726
- '0x000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da1', '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831',
727
- '0x0000000000000000000000000000000000000000000000000000000000038270', '0x000000000000000000000000000000000000000000000000000000000012d068'
728
- ],
729
- ],
730
- [getAssetInfo('DAI', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, '230000', 1697111705805, 1233000, ChainId.Arbitrum]
731
- ],
732
- [
733
- [
734
- Strategies.MainnetIds.EXCHANGE_DCA,
735
- false,
736
- ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd0000000000000000000000000000000000000000000000000000000000067458'],
737
- [
738
- '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599', '0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
739
- '0x0000000000000000000000000000000000000000000000000000000000000015', '0x0000000000000000000000000000000000000000000000000000000000067458',
740
- ],
741
- ],
742
- [getAssetInfo('WBTC').address, getAssetInfo('ETH').address, '21', 1697111705805, 423000, ChainId.Ethereum]
743
- ],
744
- ];
745
-
746
- examples.forEach(([expected, actual]) => {
747
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
748
- expect(exchangeEncode.dca(...actual)).to.eql(expected);
749
- });
750
- });
751
- });
752
-
753
- describe('limitOrder()', () => {
754
- const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string], [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType]]> = [
755
- [
756
- [
757
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
758
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
759
- '2131',
760
- '0.53123',
761
- '1696590921159',
762
- `${OrderType.STOP_LOSS}`
763
- ],
764
- [
765
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
766
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
767
- '2131',
768
- '0.53123',
769
- 1696590921159,
770
- OrderType.STOP_LOSS
771
- ]
772
- ],
773
- [
774
- [
775
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
776
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
777
- '2131',
778
- '0.43123',
779
- '1646590921159',
780
- `${OrderType.TAKE_PROFIT}`
781
- ],
782
- [
783
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
784
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
785
- '2131',
786
- '0.43123',
787
- 1646590921159,
788
- OrderType.TAKE_PROFIT
789
- ]
790
- ],
791
- ];
792
-
793
- examples.forEach(([expected, actual]) => {
794
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
795
- expect(exchangeEncode.limitOrder(...actual)).to.eql(expected);
796
- });
797
- });
798
- });
799
- });
800
-
801
- describe('When testing strategySubService.sparkEncode', () => {
802
- describe('leverageManagement()', () => {
803
- const examples: Array<[
804
- string,
805
- [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
806
- ]> = [
807
- [
808
- '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
809
- [160, 220, 180, 190, true]
810
- ],
811
- [
812
- '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
813
- [160, 200, 180, 190, false]
814
- ],
815
- ];
816
-
817
- examples.forEach(([expected, actual]) => {
818
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
819
- expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
820
- });
821
- });
822
- });
823
-
824
- describe('closeToAsset()', () => {
825
- const examples: Array<[
826
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
827
- [
828
- strategyOrBundleId: number,
829
- isBundle: boolean,
830
- triggerData: {
831
- baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState
832
- },
833
- subData: {
834
- collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
835
- },
836
- ]
837
- ]> = [
838
- [
839
- [
840
- Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
841
- true,
842
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
843
- [
844
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
845
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
846
- '0x0000000000000000000000000000000000000000000000000000000000000000',
847
- ],
848
- ],
849
- [
850
- Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
851
- true,
852
- {
853
- baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER
854
- },
855
- {
856
- collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
857
- },
858
- ]
859
- ],
860
- [
861
- [
862
- Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
863
- true,
864
- ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
865
- [
866
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
867
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
868
- '0x0000000000000000000000000000000000000000000000000000000000000000',
869
- ],
870
- ],
871
- [
872
- Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
873
- true,
874
- {
875
- baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER
876
- },
877
- {
878
- collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
879
- },
880
- ]
881
- ]
882
- ];
883
-
884
- examples.forEach(([expected, actual]) => {
885
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
886
- expect(sparkEncode.closeToAsset(...actual)).to.eql(expected);
887
- });
888
- });
889
- });
890
- });
891
-
892
- describe('When testing strategySubService.crvUSDEncode', () => {
893
- describe('leverageManagement()', () => {
894
- const examples: Array<[
895
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
896
- [owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress],
897
- ]> = [
898
- [
899
- [
900
- Bundles.MainnetIds.CRVUSD_REPAY,
901
- true,
902
- [
903
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001',
904
- ],
905
- [
906
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
907
- '0x0000000000000000000000000000000000000000000000000000000000000001',
908
- '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
909
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
910
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
911
- ],
912
- ],
913
- [
914
- web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
915
- web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
916
- RatioState.UNDER,
917
- 190,
918
- 140,
919
- '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
920
- '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
921
- ]
922
- ],
923
- [
924
- [
925
- Bundles.MainnetIds.CRVUSD_BOOST,
926
- true,
927
- [
928
- '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
929
- ],
930
- [
931
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
932
- '0x0000000000000000000000000000000000000000000000000000000000000000',
933
- '0x00000000000000000000000000000000000000000000000016345785d8a00000',
934
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
935
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
936
- ],
937
- ],
938
- [
939
- web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
940
- web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
941
- RatioState.OVER,
942
- 160,
943
- 200,
944
- '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
945
- '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
946
- ]
947
- ],
948
- ];
949
-
950
- examples.forEach(([expected, actual]) => {
951
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
952
- expect(crvUSDEncode.leverageManagement(...actual)).to.eql(expected);
953
- });
954
- });
955
- });
956
- describe('payback()', () => {
957
- const examples: Array<[
958
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
959
- [owner: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress, controllerAddr: EthereumAddress, minHealthRatio: number],
960
- ]> = [
961
- [
962
- [
963
- Strategies.MainnetIds.CURVEUSD_PAYBACK,
964
- false,
965
- [
966
- '0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000',
967
- ],
968
- [
969
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
970
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
971
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
972
- '0x00000000000000000000000000000000000000000000043c33c1937564800000',
973
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e'
974
- ],
975
- ],
976
- [
977
- web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'),
978
- web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
979
- web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
980
- '20000',
981
- '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
982
- web3Utils.toChecksumAddress('0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635'),
983
- 20,
984
- ]
985
- ]
986
- ];
987
-
988
- examples.forEach(([expected, actual]) => {
989
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
990
- expect(crvUSDEncode.payback(...actual)).to.eql(expected);
991
- });
992
- });
993
- });
994
- });
995
- describe('When testing strategySubService.morphoBlueEncode', () => {
996
- describe('leverageManagement()', () => {
997
- const examples: Array<[
998
- [StrategyOrBundleIds, boolean, TriggerData, SubData],
999
- [
1000
- marketId: string,
1001
- loanToken: EthereumAddress,
1002
- collToken: EthereumAddress,
1003
- oracle: EthereumAddress,
1004
- irm: EthereumAddress,
1005
- lltv: string,
1006
- ratioState: RatioState,
1007
- targetRatio: number,
1008
- triggerRatio: number,
1009
- user: EthereumAddress,
1010
- isEoa: boolean,
1011
- network: ChainId
1012
- ],
1013
- ]> = [
1014
- [
1015
- [
1016
- Bundles.MainnetIds.MORPHO_BLUE_REPAY,
1017
- true,
1018
- [
1019
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001',
1020
- ],
1021
- [
1022
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1023
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1024
- '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1025
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1026
- '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1027
- '0x0000000000000000000000000000000000000000000000000000000000000001',
1028
- '0x000000000000000000000000000000000000000000000000136dcc951d8c0000',
1029
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1030
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1031
- ],
1032
- ],
1033
- [
1034
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
1035
- web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1036
- web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1037
- web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
1038
- web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1039
- '945000000000000000',
1040
- RatioState.UNDER,
1041
- 140,
1042
- 120,
1043
- web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1044
- false,
1045
- ChainId.Ethereum,
1046
- ]
1047
- ],
1048
- [
1049
- [
1050
- Bundles.MainnetIds.MORPHO_BLUE_BOOST,
1051
- true,
1052
- [
1053
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
1054
- ],
1055
- [
1056
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1057
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1058
- '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1059
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1060
- '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1061
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1062
- '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1063
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1064
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1065
- ],
1066
- ],
1067
- [
1068
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
1069
- web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1070
- web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1071
- web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
1072
- web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1073
- '945000000000000000',
1074
- RatioState.OVER,
1075
- 160,
1076
- 200,
1077
- web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1078
- false,
1079
- ChainId.Ethereum,
1080
- ]
1081
- ],
1082
- ];
1083
-
1084
- examples.forEach(([expected, actual]) => {
1085
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1086
- expect(morphoBlueEncode.leverageManagement(...actual)).to.eql(expected);
1087
- });
1088
- });
1089
- });
1090
- });
1091
-
1092
- describe('When testing strategySubService.compoundV3L2Encode', () => {
1093
- describe('leverageManagement()', () => {
1094
- const examples: Array<[string, [EthereumAddress, EthereumAddress, number, number, number, number, boolean]]> = [
1095
- [
1096
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
1097
- [
1098
- web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1099
- web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1100
- 160, 220, 180, 190,
1101
- true
1102
- ],
1103
- ],
1104
- [
1105
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee000000',
1106
- [
1107
- web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1108
- web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1109
- 160, 220, 180, 110,
1110
- false
1111
- ],
1112
- ],
1113
- ];
1114
- examples.forEach(([expected, actual]) => {
1115
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1116
- expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
1117
- });
1118
- });
1119
- });
1120
- });
1121
-
1122
- });
1
+ import { expect } from 'chai';
2
+ import Dec from 'decimal.js';
3
+ import { otherAddresses } from '@defisaver/sdk';
4
+ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
5
+ import * as web3Utils from 'web3-utils';
6
+
7
+ import { Bundles, ChainId, CloseToAssetType, 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
+ crvUSDEncode,
22
+ compoundV3L2Encode,
23
+ morphoBlueEncode,
24
+ sparkEncode,
25
+ aaveV4Encode,
26
+ } from './strategySubService';
27
+
28
+ describe('Feature: strategySubService.ts', () => {
29
+ describe('When testing strategySubService.makerEncode', () => {
30
+ // @ts-ignore // TODO - this requires change in @defisaver/tokens
31
+ const mcdCdpManagerAddr = otherAddresses(ChainId.Ethereum).McdCdpManager;
32
+
33
+ describe('repayFromSavings()', () => {
34
+ const examples: Array<[
35
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
36
+ [
37
+ bundleId: StrategyOrBundleIds, vaultId: number, triggerRepayRatio: number, targetRepayRatio: number,
38
+ isBundle?: boolean, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress,
39
+ ]
40
+ ]> = [
41
+ [
42
+ [
43
+ Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_RARI,
44
+ true,
45
+ ['0x00000000000000000000000000000000000000000000000000000000000000de000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
46
+ [
47
+ '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
48
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
49
+ ],
50
+ ],
51
+ [
52
+ Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_RARI,
53
+ 222,
54
+ 140,
55
+ 180,
56
+ true,
57
+ ChainId.Ethereum,
58
+ getAssetInfo('DAI').address,
59
+ mcdCdpManagerAddr,
60
+ ]
61
+ ]
62
+ ];
63
+
64
+ examples.forEach(([expected, actual]) => {
65
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
66
+ expect(makerEncode.repayFromSavings(...actual)).to.eql(expected);
67
+ });
68
+ });
69
+ });
70
+
71
+ describe('closeOnPrice()', () => {
72
+ const examples: Array<[
73
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
74
+ [
75
+ vaultId: number, ratioState: RatioState, price: string, closeToAssetAddr: EthereumAddress,
76
+ chainlinkCollAddress: EthereumAddress, chainId?: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress,
77
+ ]
78
+ ]> = [
79
+ [
80
+ [
81
+ Strategies.MainnetIds.MAKER_CLOSE_ON_PRICE_TO_DAI,
82
+ false,
83
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000002cc9e4c0000000000000000000000000000000000000000000000000000000000000000'],
84
+ [
85
+ '0x0000000000000000000000000000000000000000000000000000000000000078', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
86
+ '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
87
+ ],
88
+ ],
89
+ [
90
+ 120,
91
+ RatioState.OVER,
92
+ '0.469643',
93
+ getAssetInfo('DAI').address,
94
+ getAssetInfo('WBTC').address,
95
+ ChainId.Ethereum,
96
+ ]
97
+ ]
98
+ ];
99
+
100
+ examples.forEach(([expected, actual]) => {
101
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
102
+ expect(makerEncode.closeOnPrice(...actual)).to.eql(expected);
103
+ });
104
+ });
105
+ });
106
+
107
+ describe('trailingStop()', () => {
108
+ const examples: Array<[
109
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
110
+ [
111
+ vaultId: number, triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress,
112
+ roundId: number, chainId: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress,
113
+ ]
114
+ ]> = [
115
+ [
116
+ [
117
+ Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_COLL,
118
+ false,
119
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000000000000000000000000000000000055ae82600000000000000000000000000000000000000000000000000000000000000007b'],
120
+ [
121
+ '0x000000000000000000000000000000000000000000000000000000000000096e', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
122
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
123
+ ],
124
+ ],
125
+ [
126
+ 2414,
127
+ 230,
128
+ getAssetInfo('WBTC').address,
129
+ getAssetInfo('WBTC').address,
130
+ 123,
131
+ ChainId.Ethereum,
132
+ ]
133
+ ]
134
+ ];
135
+
136
+ examples.forEach(([expected, actual]) => {
137
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
138
+ expect(makerEncode.trailingStop(...actual)).to.eql(expected);
139
+ });
140
+ });
141
+ });
142
+
143
+ describe('leverageManagement()', () => {
144
+ const examples: Array<[
145
+ [
146
+ vaultId: number, triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
147
+ targetRepayRatio: string, boostEnabled: boolean,
148
+ ],
149
+ [
150
+ vaultId: number, triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
151
+ targetRepayRatio: string, boostEnabled: boolean,
152
+ ]
153
+ ]> = [
154
+ [
155
+ [
156
+ 5791,
157
+ new Dec('210').mul(1e16).toString(),
158
+ new Dec('290').mul(1e16).toString(),
159
+ new Dec('240').mul(1e16).toString(),
160
+ new Dec('240').mul(1e16).toString(),
161
+ true,
162
+ ],
163
+ [
164
+ 5791, '210', '290', '240', '240', true,
165
+ ]
166
+ ]
167
+ ];
168
+
169
+ examples.forEach(([expected, actual]) => {
170
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
171
+ expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
172
+ });
173
+ });
174
+ });
175
+
176
+ describe('leverageManagementWithoutSubProxy()', () => {
177
+ const examples: Array<[
178
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
179
+ [
180
+ vaultId: number, triggerRatio: number, targetRatio: number, ratioState: RatioState,
181
+ isBoost: boolean, daiAddr?: EthereumAddress,
182
+ ]
183
+ ]> = [
184
+ // Repay scenario (isBoost=false, RatioState.UNDER)
185
+ [
186
+ [
187
+ Bundles.MainnetIds.MAKER_REPAY,
188
+ true,
189
+ ['0x00000000000000000000000000000000000000000000000000000000000000de000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
190
+ [
191
+ '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
192
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
193
+ ],
194
+ ],
195
+ [
196
+ 222, // vaultId
197
+ 140, // triggerRatio
198
+ 180, // targetRatio
199
+ RatioState.UNDER, // ratioState
200
+ false, // isBoost
201
+ ]
202
+ ],
203
+ // Boost scenario (isBoost=true, RatioState.OVER)
204
+ [
205
+ [
206
+ Bundles.MainnetIds.MAKER_BOOST,
207
+ true,
208
+ ['0x000000000000000000000000000000000000000000000000000000000000014d00000000000000000000000000000000000000000000000026db992a3b1800000000000000000000000000000000000000000000000000000000000000000000'],
209
+ [
210
+ '0x000000000000000000000000000000000000000000000000000000000000014d', '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
211
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
212
+ ],
213
+ ],
214
+ [
215
+ 333, // vaultId
216
+ 280, // triggerRatio
217
+ 250, // targetRatio
218
+ RatioState.OVER, // ratioState
219
+ true, // isBoost
220
+ ]
221
+ ],
222
+ ];
223
+
224
+ examples.forEach(([expected, actual]) => {
225
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
226
+ expect(makerEncode.leverageManagementWithoutSubProxy(...actual)).to.eql(expected);
227
+ });
228
+ });
229
+ });
230
+ });
231
+
232
+ describe('When testing strategySubService.liquityEncode', () => {
233
+ describe('closeOnPrice()', () => {
234
+ const examples: Array<[
235
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
236
+ [
237
+ priceOverOrUnder: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress,
238
+ chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress,
239
+ ]
240
+ ]> = [
241
+ [
242
+ [
243
+ Strategies.MainnetIds.LIQUITY_CLOSE_ON_PRICE_TO_COLL,
244
+ false,
245
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000001c027053000000000000000000000000000000000000000000000000000000000000000000'],
246
+ [
247
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
248
+ ],
249
+ ],
250
+ [
251
+ RatioState.OVER,
252
+ '1203',
253
+ getAssetInfo('WETH').address,
254
+ getAssetInfo('WETH').address,
255
+ ]
256
+ ]
257
+ ];
258
+
259
+ examples.forEach(([expected, actual]) => {
260
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
261
+ expect(liquityEncode.closeOnPrice(...actual)).to.eql(expected);
262
+ });
263
+ });
264
+ });
265
+
266
+ describe('trailingStop()', () => {
267
+ const examples: Array<[
268
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
269
+ [
270
+ triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number,
271
+ chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress,
272
+ ]
273
+ ]> = [
274
+ [
275
+ [
276
+ Strategies.MainnetIds.LIQUITY_TRAILING_STOP_LOSS_TO_COLL,
277
+ false,
278
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000055ae826000000000000000000000000000000000000000000000000000000000000000c97'],
279
+ [
280
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
281
+ ],
282
+ ],
283
+ [
284
+ 230,
285
+ getAssetInfo('WETH').address,
286
+ getAssetInfo('WETH').address,
287
+ 3223,
288
+ ]
289
+ ]
290
+ ];
291
+
292
+ examples.forEach(([expected, actual]) => {
293
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
294
+ expect(liquityEncode.trailingStop(...actual)).to.eql(expected);
295
+ });
296
+ });
297
+ });
298
+
299
+ describe('leverageManagement()', () => {
300
+ const examples: Array<[
301
+ [
302
+ triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
303
+ targetRepayRatio: string, boostEnabled: boolean,
304
+ ],
305
+ [
306
+ triggerRepayRatio: string, triggerBoostRatio: string, targetBoostRatio: string,
307
+ targetRepayRatio: string, boostEnabled: boolean,
308
+ ]
309
+ ]> = [
310
+ [
311
+ [
312
+ new Dec('210').mul(1e16).toString(),
313
+ new Dec('290').mul(1e16).toString(),
314
+ new Dec('240').mul(1e16).toString(),
315
+ new Dec('240').mul(1e16).toString(),
316
+ false,
317
+ ],
318
+ [
319
+ '210', '290', '240', '240', false,
320
+ ]
321
+ ]
322
+ ];
323
+
324
+ examples.forEach(([expected, actual]) => {
325
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
326
+ expect(liquityEncode.leverageManagement(...actual)).to.eql(expected);
327
+ });
328
+ });
329
+ });
330
+
331
+ describe('paybackFromChickenBondStrategySub()', () => {
332
+ const examples: Array<[
333
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
334
+ [
335
+ proxyAddress: EthereumAddress, ratio: number, sourceId: string, sourceType: number, ratioState: RatioState,
336
+ ]
337
+ ]> = [
338
+ [
339
+ [
340
+ Bundles.MainnetIds.LIQUITY_PAYBACK_USING_CHICKEN_BOND,
341
+ true,
342
+ ['0x0000000000000000000000002439d211133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002dcbf4840eca00000000000000000000000000000000000000000000000000000000000000000000'],
343
+ [
344
+ '0x000000000000000000000000000000000000000000000000000000000000007b', '0x0000000000000000000000000000000000000000000000000000000000000000',
345
+ '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
346
+ ],
347
+ ],
348
+ [
349
+ web3Utils.toChecksumAddress('0x2439d211133AFaB8F2B819B1066c7E434Ad94E9e'),
350
+ 330,
351
+ '123',
352
+ 0,
353
+ RatioState.OVER
354
+ ]
355
+ ]
356
+ ];
357
+
358
+ examples.forEach(([expected, actual]) => {
359
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
360
+ expect(liquityEncode.paybackFromChickenBondStrategySub(...actual)).to.eql(expected);
361
+ });
362
+ });
363
+ });
364
+
365
+ describe('dsrPayback()', () => {
366
+ const examples: Array<[
367
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
368
+ [proxyAddress: EthereumAddress, triggerRatio: number, targetRatio: number],
369
+ ]> = [
370
+ [
371
+ [
372
+ Strategies.MainnetIds.LIQUITY_DSR_PAYBACK,
373
+ false,
374
+ ['0x0000000000000000000000002439d211133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000250dbeda8e4b00000000000000000000000000000000000000000000000000000000000000000001'],
375
+ [
376
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x00000000000000000000000000000000000000000000000029a2241af62c0000',
377
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
378
+ ],
379
+ ],
380
+ [web3Utils.toChecksumAddress('0x2439d211133AFaB8F2B819B1066c7E434Ad94E9e'), 267, 300]
381
+ ]
382
+ ];
383
+
384
+ examples.forEach(([expected, actual]) => {
385
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
386
+ expect(liquityEncode.dsrPayback(...actual)).to.eql(expected);
387
+ });
388
+ });
389
+ });
390
+
391
+ describe('debtInFrontRepay()', () => {
392
+ const examples: Array<[
393
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
394
+ [proxyAddress: EthereumAddress, debtInFrontMin: string, targetRatioIncrease: number],
395
+ ]> = [
396
+ [
397
+ [
398
+ Strategies.MainnetIds.LIQUITY_DEBT_IN_FRONT_REPAY,
399
+ false,
400
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a0000000000000000000000000000000000000000019d971e4fe8401e74000000'],
401
+ [
402
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
403
+ '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
404
+ '0x0000000000000000000000000000000000000000000000000000000000000000'
405
+ ],
406
+ ],
407
+ [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '500000000', 45]
408
+ ]
409
+ ];
410
+
411
+ examples.forEach(([expected, actual]) => {
412
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
413
+ expect(liquityEncode.debtInFrontRepay(...actual)).to.eql(expected);
414
+ });
415
+ });
416
+ });
417
+ });
418
+
419
+ describe('When testing strategySubService.chickenBondsEncode', () => {
420
+ describe('rebond()', () => {
421
+ const examples: Array<[
422
+ SubData,
423
+ [bondId: number],
424
+ ]> = [
425
+ [
426
+ ['0x00000000000000000000000000000000000000000000000000000000000005e3'],
427
+ [1507]
428
+ ]
429
+ ];
430
+
431
+ examples.forEach(([expected, actual]) => {
432
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
433
+ expect(chickenBondsEncode.rebond(...actual)).to.eql(expected);
434
+ });
435
+ });
436
+ });
437
+ });
438
+
439
+ describe('When testing strategySubService.aaveV2Encode', () => {
440
+ describe('leverageManagement()', () => {
441
+ const examples: Array<[
442
+ [string, string, string, string, boolean],
443
+ [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
444
+ ]> = [
445
+ [
446
+ [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],
447
+ [160, 220, 180, 190, true]
448
+ ],
449
+ [
450
+ [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],
451
+ [160, 200, 180, 190, false]
452
+ ],
453
+ ];
454
+
455
+ examples.forEach(([expected, actual]) => {
456
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
457
+ expect(aaveV2Encode.leverageManagement(...actual)).to.eql(expected);
458
+ });
459
+ });
460
+ });
461
+ });
462
+
463
+ describe('When testing strategySubService.aaveV3Encode', () => {
464
+ describe('leverageManagement()', () => {
465
+ const examples: Array<[
466
+ string,
467
+ [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
468
+ ]> = [
469
+ [
470
+ '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
471
+ [160, 220, 180, 190, true]
472
+ ],
473
+ [
474
+ '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
475
+ [160, 200, 180, 190, false]
476
+ ],
477
+ ];
478
+
479
+ examples.forEach(([expected, actual]) => {
480
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
481
+ expect(aaveV3Encode.leverageManagement(...actual)).to.eql(expected);
482
+ });
483
+ });
484
+ });
485
+
486
+ describe('closeToAsset()', () => {
487
+ const examples: Array<[
488
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
489
+ [
490
+ strategyOrBundleId: number,
491
+ isBundle: boolean,
492
+ triggerData: {
493
+ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState
494
+ },
495
+ subData: {
496
+ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
497
+ },
498
+ ]
499
+ ]> = [
500
+ [
501
+ [
502
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
503
+ true,
504
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
505
+ [
506
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
507
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
508
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
509
+ ],
510
+ ],
511
+ [
512
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
513
+ true,
514
+ {
515
+ baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER
516
+ },
517
+ {
518
+ collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
519
+ },
520
+ ]
521
+ ],
522
+ [
523
+ [
524
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
525
+ true,
526
+ ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
527
+ [
528
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
529
+ '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
530
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
531
+ ],
532
+ ],
533
+ [
534
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
535
+ true,
536
+ {
537
+ baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER
538
+ },
539
+ {
540
+ collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
541
+ },
542
+ ]
543
+ ]
544
+ ];
545
+
546
+ examples.forEach(([expected, actual]) => {
547
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
548
+ expect(aaveV3Encode.closeToAsset(...actual)).to.eql(expected);
549
+ });
550
+ });
551
+ });
552
+
553
+ describe('closeToAssetWithMaximumGasPrice()', () => {
554
+ const examples: Array<[
555
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
556
+ [
557
+ strategyOrBundleId: number,
558
+ isBundle: boolean,
559
+ triggerData: {
560
+ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState, maximumGasPrice: number
561
+ },
562
+ subData: {
563
+ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
564
+ },
565
+ ]
566
+ ]> = [
567
+ [
568
+ [
569
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
570
+ true,
571
+ [
572
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000',
573
+ '0x00000000000000000000000000000000000000000000000000000002cb417800',
574
+ ],
575
+ [
576
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
577
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
578
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
579
+ ],
580
+ ],
581
+ [
582
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
583
+ true,
584
+ {
585
+ baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER, maximumGasPrice: 12,
586
+ },
587
+ {
588
+ collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
589
+ },
590
+ ]
591
+ ],
592
+ [
593
+ [
594
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
595
+ true,
596
+ [
597
+ '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001',
598
+ '0x0000000000000000000000000000000000000000000000000000004a817c8000',
599
+ ],
600
+ [
601
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
602
+ '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
603
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
604
+ ],
605
+ ],
606
+ [
607
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
608
+ true,
609
+ {
610
+ baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER, maximumGasPrice: 320,
611
+ },
612
+ {
613
+ collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
614
+ },
615
+ ]
616
+ ]
617
+ ];
618
+
619
+ examples.forEach(([expected, actual]) => {
620
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
621
+ expect(aaveV3Encode.closeToAssetWithMaximumGasPrice(...actual)).to.eql(expected);
622
+ });
623
+ });
624
+ });
625
+
626
+ describe('leverageManagementOnPrice()', () => {
627
+ const examples: Array<[
628
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
629
+ [
630
+ strategyOrBundleId: number,
631
+ isBundle: boolean,
632
+ triggerData: {
633
+ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState.UNDER
634
+ },
635
+ subData: {
636
+ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number,
637
+ },
638
+ ]
639
+ ]> = [
640
+ [
641
+ [
642
+ Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
643
+ true,
644
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000007acead34980000000000000000000000000000000000000000000000000000000000000001'],
645
+ [
646
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
647
+ '0x000000000000000000000000000000000000000000000000000000000000000a',
648
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
649
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
650
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
651
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
652
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
653
+ ],
654
+ ],
655
+ [
656
+ Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
657
+ true,
658
+ {
659
+ baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 5274.534678, state: RatioState.UNDER
660
+ },
661
+ {
662
+ collAsset: getAssetInfo('WETH').address,
663
+ collAssetId: 10,
664
+ debtAsset: getAssetInfo('DAI').address,
665
+ debtAssetId: 4,
666
+ marketAddr: '0x2f39d218133afab8f2b819b1066c7e434ad94e9e',
667
+ targetRatio: 200,
668
+ },
669
+ ]
670
+ ],
671
+ ];
672
+
673
+ examples.forEach(([expected, actual]) => {
674
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
675
+ expect(aaveV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
676
+ });
677
+ });
678
+ });
679
+
680
+ describe('leverageManagementOnPriceGeneric()', () => {
681
+ const examples: Array<[
682
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
683
+ [
684
+ strategyOrBundleId: number,
685
+ price: number,
686
+ ratioState: RatioState,
687
+ collAsset: EthereumAddress,
688
+ collAssetId: number,
689
+ debtAsset: EthereumAddress,
690
+ debtAssetId: number,
691
+ marketAddr: EthereumAddress,
692
+ targetRatio: number,
693
+ user: EthereumAddress
694
+ ]
695
+ ]> = [
696
+ [
697
+ [
698
+ Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
699
+ true,
700
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000001'],
701
+ [
702
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
703
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
704
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
705
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
706
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
707
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
708
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
709
+ ],
710
+ ],
711
+ [
712
+ Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
713
+ 1670,
714
+ RatioState.UNDER,
715
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
716
+ 0,
717
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
718
+ 1,
719
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
720
+ 200,
721
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
722
+ ]
723
+ ],
724
+ [
725
+ [
726
+ Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
727
+ true,
728
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000002faf0800000000000000000000000000000000000000000000000000000000000000000'],
729
+ [
730
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
731
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
732
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
733
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
734
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
735
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
736
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
737
+ ],
738
+ ],
739
+ [
740
+ Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
741
+ 0.5,
742
+ RatioState.OVER,
743
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
744
+ 2,
745
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
746
+ 1,
747
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
748
+ 200,
749
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
750
+ ]
751
+ ],
752
+ ];
753
+
754
+ examples.forEach(([expected, actual]) => {
755
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
756
+ expect(aaveV3Encode.leverageManagementOnPriceGeneric(...actual)).to.eql(expected);
757
+ });
758
+ });
759
+ });
760
+
761
+ describe('closeOnPriceGeneric()', () => {
762
+ const examples: Array<[
763
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
764
+ [
765
+ strategyOrBundleId: number,
766
+ collAsset: EthereumAddress,
767
+ collAssetId: number,
768
+ debtAsset: EthereumAddress,
769
+ debtAssetId: number,
770
+ marketAddr: EthereumAddress,
771
+ user: EthereumAddress,
772
+ stopLossPrice: number,
773
+ stopLossType: CloseToAssetType,
774
+ takeProfitPrice: number,
775
+ takeProfitType: CloseToAssetType
776
+ ]
777
+ ]> = [
778
+ // Stop loss only (to debt)
779
+ [
780
+ [
781
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
782
+ true,
783
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
784
+ [
785
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
786
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
787
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
788
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
789
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
790
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
791
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
792
+ ],
793
+ ],
794
+ [
795
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
796
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
797
+ 0,
798
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
799
+ 1,
800
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
801
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
802
+ 1500, // stopLossPrice
803
+ CloseToAssetType.DEBT, // stopLossType
804
+ 0, // takeProfitPrice
805
+ CloseToAssetType.COLLATERAL, // takeProfitType (not used since price is 0)
806
+ ]
807
+ ],
808
+ // Take profit only (to collateral)
809
+ [
810
+ [
811
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
812
+ true,
813
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
814
+ [
815
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
816
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
817
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
818
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
819
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
820
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
821
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
822
+ ],
823
+ ],
824
+ [
825
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
826
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
827
+ 0,
828
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
829
+ 1,
830
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
831
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
832
+ 0, // stopLossPrice
833
+ CloseToAssetType.DEBT, // stopLossType (not used since price is 0)
834
+ 5000, // takeProfitPrice
835
+ CloseToAssetType.COLLATERAL, // takeProfitType
836
+ ]
837
+ ],
838
+ // Both stop loss and take profit with useOnBehalf
839
+ [
840
+ [
841
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
842
+ true,
843
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
844
+ [
845
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
846
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
847
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
848
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
849
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
850
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
851
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
852
+ ],
853
+ ],
854
+ [
855
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
856
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
857
+ 2,
858
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
859
+ 1,
860
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
861
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
862
+ 1500, // stopLossPrice
863
+ CloseToAssetType.COLLATERAL, // stopLossType
864
+ 4000, // takeProfitPrice
865
+ CloseToAssetType.COLLATERAL, // takeProfitType
866
+ ]
867
+ ],
868
+ // Stop loss only (to collateral) - CloseStrategyType.STOP_LOSS_IN_COLLATERAL
869
+ [
870
+ [
871
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
872
+ true,
873
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
874
+ [
875
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
876
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
877
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
878
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
879
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
880
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
881
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
882
+ ],
883
+ ],
884
+ [
885
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
886
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
887
+ 0,
888
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
889
+ 1,
890
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
891
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
892
+ 1500, // stopLossPrice
893
+ CloseToAssetType.COLLATERAL, // stopLossType
894
+ 0, // takeProfitPrice
895
+ CloseToAssetType.DEBT, // takeProfitType (not used since price is 0)
896
+ ]
897
+ ],
898
+ // Take profit only (to debt) - CloseStrategyType.TAKE_PROFIT_IN_DEBT
899
+ [
900
+ [
901
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
902
+ true,
903
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
904
+ [
905
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
906
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
907
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
908
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
909
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
910
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
911
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
912
+ ],
913
+ ],
914
+ [
915
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
916
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
917
+ 0,
918
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
919
+ 1,
920
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
921
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
922
+ 0, // stopLossPrice
923
+ CloseToAssetType.COLLATERAL, // stopLossType (not used since price is 0)
924
+ 5000, // takeProfitPrice
925
+ CloseToAssetType.DEBT, // takeProfitType
926
+ ]
927
+ ],
928
+ // Take profit in collateral and stop loss in debt - CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
929
+ [
930
+ [
931
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
932
+ true,
933
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
934
+ [
935
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
936
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
937
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
938
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
939
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
940
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
941
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
942
+ ],
943
+ ],
944
+ [
945
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
946
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
947
+ 2,
948
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
949
+ 1,
950
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
951
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
952
+ 1500, // stopLossPrice
953
+ CloseToAssetType.DEBT, // stopLossType
954
+ 4000, // takeProfitPrice
955
+ CloseToAssetType.COLLATERAL, // takeProfitType
956
+ ]
957
+ ],
958
+ // Both stop loss and take profit in debt - CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
959
+ [
960
+ [
961
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
962
+ true,
963
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
964
+ [
965
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
966
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
967
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
968
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
969
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
970
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
971
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
972
+ ],
973
+ ],
974
+ [
975
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
976
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
977
+ 0,
978
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
979
+ 1,
980
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
981
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
982
+ 1500, // stopLossPrice
983
+ CloseToAssetType.DEBT, // stopLossType
984
+ 4000, // takeProfitPrice
985
+ CloseToAssetType.DEBT, // takeProfitType
986
+ ]
987
+ ],
988
+ // Take profit in debt and stop loss in collateral - CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
989
+ [
990
+ [
991
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
992
+ true,
993
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
994
+ [
995
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
996
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
997
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
998
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
999
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1000
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
1001
+ '0x0000000000000000000000009876543210987654321098765432109876543210',
1002
+ ],
1003
+ ],
1004
+ [
1005
+ Bundles.MainnetIds.AAVE_V3_EOA_CLOSE,
1006
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1007
+ 0,
1008
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1009
+ 1,
1010
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
1011
+ web3Utils.toChecksumAddress('0x9876543210987654321098765432109876543210'),
1012
+ 1500, // stopLossPrice
1013
+ CloseToAssetType.COLLATERAL, // stopLossType
1014
+ 4000, // takeProfitPrice
1015
+ CloseToAssetType.DEBT, // takeProfitType
1016
+ ]
1017
+ ],
1018
+ ];
1019
+
1020
+ examples.forEach(([expected, actual]) => {
1021
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1022
+ expect(aaveV3Encode.closeOnPriceGeneric(...actual)).to.eql(expected);
1023
+ });
1024
+ });
1025
+ });
1026
+
1027
+ describe('collateralSwitch()', () => {
1028
+ const examples: Array<[
1029
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1030
+ [
1031
+ strategyOrBundleId: number,
1032
+ fromAsset: EthereumAddress,
1033
+ fromAssetId: number,
1034
+ toAsset: EthereumAddress,
1035
+ toAssetId: number,
1036
+ marketAddr: EthereumAddress,
1037
+ amountToSwitch: string,
1038
+ baseTokenAddress: EthereumAddress,
1039
+ quoteTokenAddress: EthereumAddress,
1040
+ price: number,
1041
+ state: RatioState,
1042
+ ]
1043
+ ]> = [
1044
+ // WETH -> USDC, price 100000, state UNDER
1045
+ [
1046
+ [
1047
+ Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
1048
+ false,
1049
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
1050
+ [
1051
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1052
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1053
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1054
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1055
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1056
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
1057
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1058
+ ],
1059
+ ],
1060
+ [
1061
+ Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
1062
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1063
+ 0,
1064
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1065
+ 1,
1066
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1067
+ '10000000000000000000', // 10 WETH
1068
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1069
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1070
+ 100000,
1071
+ RatioState.UNDER,
1072
+ ]
1073
+ ],
1074
+ // USDC -> WETH, price 0.00001, state OVER
1075
+ [
1076
+ [
1077
+ Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
1078
+ false,
1079
+ ['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000000'],
1080
+ [
1081
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1082
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1083
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1084
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1085
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1086
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
1087
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1088
+ ],
1089
+ ],
1090
+ [
1091
+ Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
1092
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1093
+ 1,
1094
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1095
+ 0,
1096
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1097
+ MAXUINT, // MaxUint256
1098
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1099
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1100
+ 0.00001,
1101
+ RatioState.OVER,
1102
+ ]
1103
+ ],
1104
+ // WETH -> WBTC, price 1, state UNDER
1105
+ [
1106
+ [
1107
+ Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
1108
+ false,
1109
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000001'],
1110
+ [
1111
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1112
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1113
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1114
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1115
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1116
+ '0x0000000000000000000000000000000000000000000000004563918244f40000',
1117
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1118
+ ],
1119
+ ],
1120
+ [
1121
+ Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
1122
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1123
+ 0,
1124
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1125
+ 2,
1126
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1127
+ '5000000000000000000', // 5 WETH
1128
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1129
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1130
+ 1,
1131
+ RatioState.UNDER,
1132
+ ]
1133
+ ],
1134
+ ];
1135
+
1136
+ examples.forEach(([expected, actual]) => {
1137
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1138
+ expect(aaveV3Encode.collateralSwitch(...actual)).to.eql(expected);
1139
+ });
1140
+ });
1141
+ });
1142
+ });
1143
+
1144
+ describe('When testing strategySubService.compoundV2Encode', () => {
1145
+ describe('leverageManagement()', () => {
1146
+ const examples: Array<[
1147
+ [string, string, string, string, boolean],
1148
+ [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
1149
+ ]> = [
1150
+ [
1151
+ [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],
1152
+ [160, 220, 180, 190, true]
1153
+ ],
1154
+ [
1155
+ [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],
1156
+ [160, 200, 180, 190, false]
1157
+ ],
1158
+ ];
1159
+
1160
+ examples.forEach(([expected, actual]) => {
1161
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1162
+ expect(compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
1163
+ });
1164
+ });
1165
+ });
1166
+ });
1167
+
1168
+ describe('When testing strategySubService.compoundV3Encode', () => {
1169
+ describe('leverageManagement()', () => {
1170
+ 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]]> = [
1171
+ [
1172
+ [
1173
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
1174
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1175
+ new Dec(160).mul(1e16).toString(),
1176
+ new Dec(220).mul(1e16).toString(),
1177
+ new Dec(180).mul(1e16).toString(),
1178
+ new Dec(190).mul(1e16).toString(),
1179
+ true, false,
1180
+ ],
1181
+ [
1182
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
1183
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1184
+ 160, 220, 180, 190,
1185
+ true, false,
1186
+ ]
1187
+ ],
1188
+ [
1189
+ [
1190
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
1191
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1192
+ new Dec(160).mul(1e16).toString(),
1193
+ new Dec(210).mul(1e16).toString(),
1194
+ new Dec(180).mul(1e16).toString(),
1195
+ new Dec(190).mul(1e16).toString(),
1196
+ false, true,
1197
+ ],
1198
+ [
1199
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
1200
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1201
+ 160, 210, 180, 190,
1202
+ false, true,
1203
+ ]
1204
+ ],
1205
+ ];
1206
+ examples.forEach(([expected, actual]) => {
1207
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1208
+ expect(compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
1209
+ });
1210
+ });
1211
+ });
1212
+ describe('leverageManagementOnPrice()', () => {
1213
+ const examples: Array<[
1214
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1215
+ [strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, price: number, priceState: RatioState, ratioState: RatioState, user: EthereumAddress]
1216
+ ]> = [
1217
+ [
1218
+ [
1219
+ Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
1220
+ true,
1221
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f07775030000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
1222
+ [
1223
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1224
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1225
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1226
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1227
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1228
+ '0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
1229
+ ],
1230
+ ],
1231
+ [
1232
+ Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
1233
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1234
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1235
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1236
+ 200,
1237
+ 2000,
1238
+ RatioState.UNDER,
1239
+ RatioState.UNDER,
1240
+ web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
1241
+ ],
1242
+ ],
1243
+ [
1244
+ [
1245
+ Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
1246
+ true,
1247
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f077750300000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
1248
+ [
1249
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1250
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1251
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1252
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
1253
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1254
+ '0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
1255
+ ],
1256
+ ],
1257
+ [
1258
+ Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
1259
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1260
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1261
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1262
+ 190,
1263
+ 3000,
1264
+ RatioState.OVER,
1265
+ RatioState.OVER,
1266
+ web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
1267
+ ],
1268
+ ]
1269
+ ];
1270
+ examples.forEach(([expected, actual]) => {
1271
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1272
+ expect(compoundV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
1273
+ });
1274
+ });
1275
+ });
1276
+ describe('closeOnPrice()', () => {
1277
+ const examples: Array<[
1278
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1279
+ [strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, stopLossPrice: number, stopLossType: CloseToAssetType, takeProfitPrice: number, takeProfitType: CloseToAssetType, user: EthereumAddress]
1280
+ ]> = [
1281
+ [
1282
+ [
1283
+ Bundles.MainnetIds.COMP_V3_SW_CLOSE,
1284
+ true,
1285
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1286
+ [
1287
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1288
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1289
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1290
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1291
+ '0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
1292
+ ],
1293
+ ],
1294
+ [
1295
+ Bundles.MainnetIds.COMP_V3_SW_CLOSE,
1296
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1297
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1298
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1299
+ 1500,
1300
+ CloseToAssetType.DEBT,
1301
+ 4000,
1302
+ CloseToAssetType.DEBT,
1303
+ web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
1304
+ ],
1305
+ ],
1306
+ [
1307
+ [
1308
+ Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
1309
+ true,
1310
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
1311
+ [
1312
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1313
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1314
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1315
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1316
+ '0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
1317
+ ],
1318
+ ],
1319
+ [
1320
+ Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
1321
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1322
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1323
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1324
+ 0,
1325
+ CloseToAssetType.DEBT,
1326
+ 5000,
1327
+ CloseToAssetType.COLLATERAL,
1328
+ web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
1329
+ ],
1330
+ ]
1331
+ ];
1332
+ examples.forEach(([expected, actual]) => {
1333
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1334
+ expect(compoundV3Encode.closeOnPrice(...actual)).to.eql(expected);
1335
+ });
1336
+ });
1337
+ });
1338
+ });
1339
+
1340
+ describe('When testing strategySubService.morphoAaveV2Encode', () => {
1341
+ describe('leverageManagement()', () => {
1342
+ const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
1343
+ [
1344
+ [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],
1345
+ [160, 220, 180, 190, true]
1346
+ ],
1347
+ [
1348
+ [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],
1349
+ [160, 200, 180, 190, false]
1350
+ ],
1351
+ ];
1352
+
1353
+ examples.forEach(([expected, actual]) => {
1354
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1355
+ expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
1356
+ });
1357
+ });
1358
+ });
1359
+ });
1360
+
1361
+ describe('When testing strategySubService.exchangeEncode', () => {
1362
+ describe('dca()', () => {
1363
+ const examples: Array<[
1364
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1365
+ [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number, network: ChainId],
1366
+ ]> = [
1367
+ [
1368
+ [
1369
+ Strategies.ArbitrumIds.EXCHANGE_DCA,
1370
+ false,
1371
+ ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd000000000000000000000000000000000000000000000000000000000012d068'],
1372
+ [
1373
+ '0x000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da1', '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831',
1374
+ '0x0000000000000000000000000000000000000000000000000000000000038270', '0x000000000000000000000000000000000000000000000000000000000012d068'
1375
+ ],
1376
+ ],
1377
+ [getAssetInfo('DAI', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, '230000', 1697111705805, 1233000, ChainId.Arbitrum]
1378
+ ],
1379
+ [
1380
+ [
1381
+ Strategies.MainnetIds.EXCHANGE_DCA,
1382
+ false,
1383
+ ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd0000000000000000000000000000000000000000000000000000000000067458'],
1384
+ [
1385
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599', '0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
1386
+ '0x0000000000000000000000000000000000000000000000000000000000000015', '0x0000000000000000000000000000000000000000000000000000000000067458',
1387
+ ],
1388
+ ],
1389
+ [getAssetInfo('WBTC').address, getAssetInfo('ETH').address, '21', 1697111705805, 423000, ChainId.Ethereum]
1390
+ ],
1391
+ ];
1392
+
1393
+ examples.forEach(([expected, actual]) => {
1394
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1395
+ expect(exchangeEncode.dca(...actual)).to.eql(expected);
1396
+ });
1397
+ });
1398
+ });
1399
+
1400
+ describe('limitOrder()', () => {
1401
+ const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string], [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType]]> = [
1402
+ [
1403
+ [
1404
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1405
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1406
+ '2131',
1407
+ '0.53123',
1408
+ '1696590921159',
1409
+ `${OrderType.STOP_LOSS}`
1410
+ ],
1411
+ [
1412
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1413
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1414
+ '2131',
1415
+ '0.53123',
1416
+ 1696590921159,
1417
+ OrderType.STOP_LOSS
1418
+ ]
1419
+ ],
1420
+ [
1421
+ [
1422
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
1423
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
1424
+ '2131',
1425
+ '0.43123',
1426
+ '1646590921159',
1427
+ `${OrderType.TAKE_PROFIT}`
1428
+ ],
1429
+ [
1430
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
1431
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
1432
+ '2131',
1433
+ '0.43123',
1434
+ 1646590921159,
1435
+ OrderType.TAKE_PROFIT
1436
+ ]
1437
+ ],
1438
+ ];
1439
+
1440
+ examples.forEach(([expected, actual]) => {
1441
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1442
+ expect(exchangeEncode.limitOrder(...actual)).to.eql(expected);
1443
+ });
1444
+ });
1445
+ });
1446
+ });
1447
+
1448
+ describe('When testing strategySubService.crvUSDEncode', () => {
1449
+ describe('leverageManagement()', () => {
1450
+ const examples: Array<[
1451
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1452
+ [owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress],
1453
+ ]> = [
1454
+ [
1455
+ [
1456
+ Bundles.MainnetIds.CRVUSD_REPAY,
1457
+ true,
1458
+ [
1459
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001',
1460
+ ],
1461
+ [
1462
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1463
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1464
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
1465
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1466
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1467
+ ],
1468
+ ],
1469
+ [
1470
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1471
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
1472
+ RatioState.UNDER,
1473
+ 190,
1474
+ 140,
1475
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1476
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
1477
+ ]
1478
+ ],
1479
+ [
1480
+ [
1481
+ Bundles.MainnetIds.CRVUSD_BOOST,
1482
+ true,
1483
+ [
1484
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
1485
+ ],
1486
+ [
1487
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1488
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1489
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1490
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1491
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1492
+ ],
1493
+ ],
1494
+ [
1495
+ web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
1496
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
1497
+ RatioState.OVER,
1498
+ 160,
1499
+ 200,
1500
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1501
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
1502
+ ]
1503
+ ],
1504
+ ];
1505
+
1506
+ examples.forEach(([expected, actual]) => {
1507
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1508
+ expect(crvUSDEncode.leverageManagement(...actual)).to.eql(expected);
1509
+ });
1510
+ });
1511
+ });
1512
+ describe('payback()', () => {
1513
+ const examples: Array<[
1514
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1515
+ [owner: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress, controllerAddr: EthereumAddress, minHealthRatio: number],
1516
+ ]> = [
1517
+ [
1518
+ [
1519
+ Strategies.MainnetIds.CURVEUSD_PAYBACK,
1520
+ false,
1521
+ [
1522
+ '0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000',
1523
+ ],
1524
+ [
1525
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1526
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1527
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1528
+ '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1529
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e'
1530
+ ],
1531
+ ],
1532
+ [
1533
+ web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'),
1534
+ web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
1535
+ web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
1536
+ '20000',
1537
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
1538
+ web3Utils.toChecksumAddress('0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635'),
1539
+ 20,
1540
+ ]
1541
+ ]
1542
+ ];
1543
+
1544
+ examples.forEach(([expected, actual]) => {
1545
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1546
+ expect(crvUSDEncode.payback(...actual)).to.eql(expected);
1547
+ });
1548
+ });
1549
+ });
1550
+ });
1551
+
1552
+ describe('When testing strategySubService.morphoBlueEncode', () => {
1553
+ describe('leverageManagement()', () => {
1554
+ const examples: Array<[
1555
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1556
+ [
1557
+ marketId: string,
1558
+ loanToken: EthereumAddress,
1559
+ collToken: EthereumAddress,
1560
+ oracle: EthereumAddress,
1561
+ irm: EthereumAddress,
1562
+ lltv: string,
1563
+ ratioState: RatioState,
1564
+ targetRatio: number,
1565
+ triggerRatio: number,
1566
+ user: EthereumAddress,
1567
+ isEoa: boolean,
1568
+ network: ChainId
1569
+ ],
1570
+ ]> = [
1571
+ [
1572
+ [
1573
+ Bundles.MainnetIds.MORPHO_BLUE_REPAY,
1574
+ true,
1575
+ [
1576
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001',
1577
+ ],
1578
+ [
1579
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1580
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1581
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1582
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1583
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1584
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1585
+ '0x000000000000000000000000000000000000000000000000136dcc951d8c0000',
1586
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1587
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1588
+ ],
1589
+ ],
1590
+ [
1591
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
1592
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1593
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1594
+ web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
1595
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1596
+ '945000000000000000',
1597
+ RatioState.UNDER,
1598
+ 140,
1599
+ 120,
1600
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1601
+ false,
1602
+ ChainId.Ethereum,
1603
+ ]
1604
+ ],
1605
+ [
1606
+ [
1607
+ Bundles.MainnetIds.MORPHO_BLUE_BOOST,
1608
+ true,
1609
+ [
1610
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
1611
+ ],
1612
+ [
1613
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1614
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1615
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1616
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1617
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1618
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1619
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1620
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1621
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1622
+ ],
1623
+ ],
1624
+ [
1625
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
1626
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1627
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1628
+ web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
1629
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1630
+ '945000000000000000',
1631
+ RatioState.OVER,
1632
+ 160,
1633
+ 200,
1634
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1635
+ false,
1636
+ ChainId.Ethereum,
1637
+ ]
1638
+ ],
1639
+ ];
1640
+
1641
+ examples.forEach(([expected, actual]) => {
1642
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1643
+ expect(morphoBlueEncode.leverageManagement(...actual)).to.eql(expected);
1644
+ });
1645
+ });
1646
+ });
1647
+
1648
+ describe('closeOnPrice()', () => {
1649
+ const examples: Array<[
1650
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1651
+ [
1652
+ strategyOrBundleId: number,
1653
+ loanToken: EthereumAddress,
1654
+ collToken: EthereumAddress,
1655
+ oracle: EthereumAddress,
1656
+ irm: EthereumAddress,
1657
+ lltv: string,
1658
+ user: EthereumAddress,
1659
+ stopLossPrice: number,
1660
+ stopLossType: CloseToAssetType,
1661
+ takeProfitPrice: number,
1662
+ takeProfitType: CloseToAssetType,
1663
+ ]
1664
+ ]> = [
1665
+ [
1666
+ [
1667
+ Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
1668
+ true,
1669
+ ['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
1670
+ [
1671
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1672
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1673
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1674
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1675
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1676
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1677
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1678
+ ],
1679
+ ],
1680
+ [
1681
+ Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
1682
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1683
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1684
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1685
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1686
+ '945000000000000000',
1687
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1688
+ 1500,
1689
+ CloseToAssetType.DEBT,
1690
+ 4000,
1691
+ CloseToAssetType.COLLATERAL
1692
+ ]
1693
+ ],
1694
+ ];
1695
+
1696
+ examples.forEach(([expected, actual]) => {
1697
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1698
+ expect(morphoBlueEncode.closeOnPrice(...actual)).to.eql(expected);
1699
+ });
1700
+ });
1701
+ });
1702
+ });
1703
+
1704
+ describe('When testing strategySubService.compoundV3L2Encode', () => {
1705
+ describe('leverageManagement()', () => {
1706
+ const examples: Array<[string, [EthereumAddress, EthereumAddress, number, number, number, number, boolean, boolean]]> = [
1707
+ [
1708
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
1709
+ [
1710
+ web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1711
+ web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1712
+ 160, 220, 180, 190,
1713
+ true,
1714
+ false,
1715
+ ],
1716
+ ],
1717
+ [
1718
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
1719
+ [
1720
+ web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1721
+ web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1722
+ 160, 220, 180, 110,
1723
+ false,
1724
+ false,
1725
+ ],
1726
+ ],
1727
+ ];
1728
+ examples.forEach(([expected, actual]) => {
1729
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1730
+ expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
1731
+ });
1732
+ });
1733
+ });
1734
+ });
1735
+
1736
+ describe('When testing strategySubService.sparkEncode', () => {
1737
+ describe('leverageManagement()', () => {
1738
+ const examples: Array<[string, [number, number, number, number, boolean]]> = [
1739
+ [
1740
+ '0x0000000000000000136dcc951d8c00000000000000000000214e8348c4f0000000000000000000001d24b2dfac52000000000000000000001a5e27eef13e000001',
1741
+ [140,240,210,190,true]
1742
+ ],
1743
+ [
1744
+ '0x0000000000000000130337bdce49000000000000000000001988fe4052b800000000000000000000281b57b028e1000000000000000000002223acf76376000000',
1745
+ [137, 184, 289, 246, false]
1746
+ ]
1747
+ ];
1748
+
1749
+ examples.forEach(([expected, actual]) => {
1750
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1751
+ expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
1752
+ });
1753
+ });
1754
+ });
1755
+
1756
+ describe('leverageManagementOnPrice()', () => {
1757
+ const examples: Array<[[StrategyOrBundleIds, boolean, TriggerData, SubData],
1758
+ [
1759
+ strategyOrBundleId: number,
1760
+ isBundle: boolean,
1761
+ triggerData: { baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: number, ratioState: RatioState },
1762
+ subData: { collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number }
1763
+ ]]> = [
1764
+ [
1765
+ [
1766
+ Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
1767
+ true,
1768
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
1769
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1770
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1771
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1772
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1773
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1774
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1775
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1776
+ ],
1777
+ ],
1778
+ [
1779
+ 59,
1780
+ true,
1781
+ {
1782
+ baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1783
+ quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1784
+ price: 2500,
1785
+ ratioState: RatioState.UNDER,
1786
+ },
1787
+ {
1788
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1789
+ collAssetId: 0,
1790
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1791
+ debtAssetId: 1,
1792
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1793
+ targetRatio: 200,
1794
+ },
1795
+ ]
1796
+ ],
1797
+ [
1798
+ [
1799
+ Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
1800
+ true,
1801
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000417bce6c8000000000000000000000000000000000000000000000000000000000000000000'],
1802
+ [
1803
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1804
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1805
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1806
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1807
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1808
+ '0x00000000000000000000000000000000000000000000000022b1c8c1227a0000',
1809
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1810
+ ]
1811
+ ],
1812
+ [
1813
+ 60,
1814
+ true,
1815
+ {
1816
+ baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1817
+ quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1818
+ price: 45000,
1819
+ ratioState: RatioState.OVER,
1820
+ },
1821
+ {
1822
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1823
+ collAssetId: 2,
1824
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1825
+ debtAssetId: 4,
1826
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1827
+ targetRatio: 250,
1828
+ },
1829
+ ]
1830
+ ]
1831
+ ];
1832
+
1833
+ examples.forEach(([expected, actual]) => {
1834
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1835
+ expect(sparkEncode.leverageManagementOnPrice(...actual)).to.eql(expected);
1836
+ });
1837
+ });
1838
+ });
1839
+
1840
+ describe('closeOnPrice()', () => {
1841
+ const examples: Array<[
1842
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1843
+ [
1844
+ strategyOrBundleId: number,
1845
+ collAsset: EthereumAddress,
1846
+ collAssetId: number,
1847
+ debtAsset: EthereumAddress,
1848
+ debtAssetId: number,
1849
+ marketAddr: EthereumAddress,
1850
+ user: EthereumAddress,
1851
+ stopLossPrice: number,
1852
+ stopLossType: CloseToAssetType,
1853
+ takeProfitPrice: number,
1854
+ takeProfitType: CloseToAssetType,
1855
+ ]
1856
+ ] > =
1857
+ [
1858
+ [
1859
+ [
1860
+ Bundles.MainnetIds.SPARK_CLOSE,
1861
+ true,
1862
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000003a35294400000000000000000000000000000000000000000000000000000000574fbde6000'],
1863
+ [
1864
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1865
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1866
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1867
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1868
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1869
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1870
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1871
+ ]
1872
+ ],
1873
+ [
1874
+ 57,
1875
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1876
+ 2,
1877
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1878
+ 4,
1879
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1880
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1881
+ 40000,
1882
+ CloseToAssetType.DEBT,
1883
+ 60000,
1884
+ CloseToAssetType.COLLATERAL,
1885
+ ]
1886
+ ],
1887
+ ]
1888
+
1889
+ examples.forEach(([expected, actual]) => {
1890
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1891
+ expect(sparkEncode.closeOnPriceGeneric(...actual)).to.eql(expected);
1892
+ });
1893
+ });
1894
+ });
1895
+
1896
+ describe('collateralSwitch()', () => {
1897
+ const examples: Array<[
1898
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1899
+ [
1900
+ strategyOrBundleId: number,
1901
+ fromAsset: EthereumAddress,
1902
+ fromAssetId: number,
1903
+ toAsset: EthereumAddress,
1904
+ toAssetId: number,
1905
+ marketAddr: EthereumAddress,
1906
+ amountToSwitch: string,
1907
+ baseTokenAddress: EthereumAddress,
1908
+ quoteTokenAddress: EthereumAddress,
1909
+ price: number,
1910
+ state: RatioState,
1911
+ ]
1912
+ ]> = [
1913
+ // WETH -> cbBTC, price 0.025 WETH/cbBTC, state UNDER
1914
+ [
1915
+ [
1916
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1917
+ false,
1918
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf00000000000000000000000000000000000000000000000000000000002625a00000000000000000000000000000000000000000000000000000000000000001'],
1919
+ [
1920
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1921
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1922
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1923
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1924
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1925
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
1926
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1927
+ ],
1928
+ ],
1929
+ [
1930
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1931
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1932
+ 0,
1933
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1934
+ 7,
1935
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1936
+ '10000000000000000000', // 10 WETH
1937
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1938
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1939
+ 0.025,
1940
+ RatioState.UNDER,
1941
+ ]
1942
+ ],
1943
+ // cbBTC -> WETH, price 25 cbBTC/WETH, state UNDER
1944
+ [
1945
+ [
1946
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1947
+ false,
1948
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000009502f9000000000000000000000000000000000000000000000000000000000000000001'],
1949
+ [
1950
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1951
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1952
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1953
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1954
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1955
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1956
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1957
+ ],
1958
+ ],
1959
+ [
1960
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1961
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1962
+ 7,
1963
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1964
+ 0,
1965
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1966
+ '100000000', // 1 cbBTC (8 decimals)
1967
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1968
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1969
+ 25,
1970
+ RatioState.UNDER,
1971
+ ]
1972
+ ],
1973
+ // cbBTC -> WETH, price 40 cbBTC/WETH, state OVER
1974
+ [
1975
+ [
1976
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1977
+ false,
1978
+ ['0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000ee6b28000000000000000000000000000000000000000000000000000000000000000000'],
1979
+ [
1980
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
1981
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1982
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1983
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1984
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
1985
+ '0x0000000000000000000000000000000000000000000000000000000005f5e100',
1986
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1987
+ ],
1988
+ ],
1989
+ [
1990
+ Strategies.MainnetIds.SPARK_COLLATERAL_SWITCH,
1991
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1992
+ 7,
1993
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1994
+ 0,
1995
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
1996
+ '100000000', // 1 cbBTC (8 decimals)
1997
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
1998
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1999
+ 40,
2000
+ RatioState.OVER,
2001
+ ]
2002
+ ],
2003
+ ];
2004
+
2005
+ examples.forEach(([expected, actual]) => {
2006
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2007
+ expect(sparkEncode.collateralSwitch(...actual)).to.eql(expected);
2008
+ });
2009
+ });
2010
+ });
2011
+ });
2012
+
2013
+ describe('When testing strategySubService.aaveV4Encode', () => {
2014
+ describe('leverageManagement()', () => {
2015
+ const examples: Array<[
2016
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
2017
+ [
2018
+ strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number
2019
+ ]
2020
+ ]> = [
2021
+ [
2022
+ [1,true,["0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x0000000000000000000000000000000000000000000000000000000000000001","0x00000000000000000000000000000000000000000000000014d1120d7b160000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
2023
+ [
2024
+ 1,
2025
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2026
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2027
+ RatioState.UNDER,
2028
+ 150,
2029
+ 120,
2030
+ ]
2031
+ ]
2032
+ ];
2033
+
2034
+ examples.forEach(([expected, actual]) => {
2035
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2036
+ expect(aaveV4Encode.leverageManagement(...actual)).to.eql(expected);
2037
+ });
2038
+ });
2039
+ });
2040
+
2041
+ describe('leverageManagementOnPrice()', () => {
2042
+ const examples: Array<[
2043
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
2044
+ [
2045
+ strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price: string, priceState: RatioState, ratioState: RatioState
2046
+ ]
2047
+ ]> = [
2048
+ [
2049
+ [2,true,["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x000000000000000000000000000000000000000000000000000000000000000a","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x0000000000000000000000000000000000000000000000000000000000000014","0x0000000000000000000000000000000000000000000000000000000000000000","0x00000000000000000000000000000000000000000000000016345785d8a00000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
2050
+ [
2051
+ 2,
2052
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2053
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2054
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2055
+ 10,
2056
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2057
+ 20,
2058
+ 160,
2059
+ '1500',
2060
+ RatioState.OVER, // priceState - goes to trigger
2061
+ RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
2062
+ ]
2063
+ ]
2064
+ ];
2065
+
2066
+ examples.forEach(([expected, actual]) => {
2067
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2068
+ expect(aaveV4Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
2069
+ });
2070
+ });
2071
+ });
2072
+
2073
+ describe('closeOnPrice()', () => {
2074
+ const examples: Array<[
2075
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
2076
+ [
2077
+ strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice: string, stopLossType: CloseToAssetType, takeProfitPrice: string, takeProfitType: CloseToAssetType
2078
+ ]
2079
+ ]> = [
2080
+ [
2081
+ [3,true,["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae000000000000000000000000000000000000000000000000000000000000000000000"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x000000000000000000000000000000000000000000000000000000000000000a","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x0000000000000000000000000000000000000000000000000000000000000014","0x0000000000000000000000000000000000000000000000000000000000000003","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
2082
+ [
2083
+ 3,
2084
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2085
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2086
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2087
+ 10,
2088
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2089
+ 20,
2090
+ '1400',
2091
+ CloseToAssetType.DEBT,
2092
+ '0',
2093
+ CloseToAssetType.COLLATERAL
2094
+ ]
2095
+ ]
2096
+ ];
2097
+
2098
+ examples.forEach(([expected, actual]) => {
2099
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2100
+ expect(aaveV4Encode.closeOnPrice(...actual)).to.eql(expected);
2101
+ });
2102
+ });
2103
+ });
2104
+
2105
+ describe('collateralSwitch()', () => {
2106
+ const examples: Array<[
2107
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
2108
+ [
2109
+ strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: string, ratioState: RatioState
2110
+ ]
2111
+ ]> = [
2112
+ [
2113
+ [4,false,["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000001"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x000000000000000000000000000000000000000000000000000000000000000a","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x0000000000000000000000000000000000000000000000000000000000000014","0x0000000000000000000000000000000000000000000000000de0b6b3a7640000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
2114
+ [
2115
+ 4,
2116
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2117
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2118
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2119
+ 10,
2120
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2121
+ 20,
2122
+ '1000000000000000000',
2123
+ '1500',
2124
+ RatioState.UNDER,
2125
+ ]
2126
+ ]
2127
+ ];
2128
+
2129
+ examples.forEach(([expected, actual]) => {
2130
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2131
+ expect(aaveV4Encode.collateralSwitch(...actual)).to.eql(expected);
2132
+ });
2133
+ });
2134
+ });
2135
+ });
2136
+ });