@defisaver/automation-sdk 3.2.5 → 3.3.0

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 (244) 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 +33 -33
  31. package/cjs/automation/private/StrategiesAutomation.js +189 -189
  32. package/cjs/automation/private/StrategiesAutomation.test.d.ts +1 -1
  33. package/cjs/automation/private/StrategiesAutomation.test.js +671 -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 +28 -28
  53. package/cjs/constants/index.js +674 -564
  54. package/cjs/index.d.ts +23 -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 +49 -49
  60. package/cjs/services/ethereumService.test.d.ts +1 -1
  61. package/cjs/services/ethereumService.test.js +242 -242
  62. package/cjs/services/strategiesService.d.ts +2 -2
  63. package/cjs/services/strategiesService.js +946 -898
  64. package/cjs/services/strategiesService.test.d.ts +1 -1
  65. package/cjs/services/strategiesService.test.js +110 -110
  66. package/cjs/services/strategySubService.d.ts +113 -111
  67. package/cjs/services/strategySubService.js +328 -314
  68. package/cjs/services/strategySubService.test.d.ts +1 -1
  69. package/cjs/services/strategySubService.test.js +1058 -936
  70. package/cjs/services/subDataService.d.ts +282 -261
  71. package/cjs/services/subDataService.js +740 -683
  72. package/cjs/services/subDataService.test.d.ts +1 -1
  73. package/cjs/services/subDataService.test.js +1458 -1282
  74. package/cjs/services/triggerService.d.ts +268 -249
  75. package/cjs/services/triggerService.js +509 -473
  76. package/cjs/services/triggerService.test.d.ts +1 -1
  77. package/cjs/services/triggerService.test.js +1139 -1045
  78. package/cjs/services/utils.d.ts +30 -30
  79. package/cjs/services/utils.js +182 -182
  80. package/cjs/services/utils.test.d.ts +1 -1
  81. package/cjs/services/utils.test.js +376 -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 +253 -226
  101. package/cjs/types/enums.js +279 -252
  102. package/cjs/types/index.d.ts +264 -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 +33 -33
  126. package/esm/automation/private/StrategiesAutomation.js +183 -183
  127. package/esm/automation/private/StrategiesAutomation.test.d.ts +1 -1
  128. package/esm/automation/private/StrategiesAutomation.test.js +666 -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 +28 -28
  148. package/esm/constants/index.js +668 -558
  149. package/esm/index.d.ts +23 -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 +41 -41
  155. package/esm/services/ethereumService.test.d.ts +1 -1
  156. package/esm/services/ethereumService.test.js +237 -237
  157. package/esm/services/strategiesService.d.ts +2 -2
  158. package/esm/services/strategiesService.js +916 -868
  159. package/esm/services/strategiesService.test.d.ts +1 -1
  160. package/esm/services/strategiesService.test.js +108 -108
  161. package/esm/services/strategySubService.d.ts +113 -111
  162. package/esm/services/strategySubService.js +299 -285
  163. package/esm/services/strategySubService.test.d.ts +1 -1
  164. package/esm/services/strategySubService.test.js +1030 -908
  165. package/esm/services/subDataService.d.ts +282 -261
  166. package/esm/services/subDataService.js +734 -677
  167. package/esm/services/subDataService.test.d.ts +1 -1
  168. package/esm/services/subDataService.test.js +1430 -1254
  169. package/esm/services/triggerService.d.ts +268 -249
  170. package/esm/services/triggerService.js +480 -444
  171. package/esm/services/triggerService.test.d.ts +1 -1
  172. package/esm/services/triggerService.test.js +1114 -1020
  173. package/esm/services/utils.d.ts +30 -30
  174. package/esm/services/utils.js +131 -131
  175. package/esm/services/utils.test.d.ts +1 -1
  176. package/esm/services/utils.test.js +348 -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 +253 -226
  196. package/esm/types/enums.js +276 -249
  197. package/esm/types/index.d.ts +264 -248
  198. package/esm/types/index.js +1 -1
  199. package/package.json +60 -60
  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 +663 -663
  216. package/src/automation/private/StrategiesAutomation.ts +254 -254
  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 +702 -593
  227. package/src/index.ts +39 -39
  228. package/src/services/contractService.ts +77 -77
  229. package/src/services/ethereumService.test.ts +257 -257
  230. package/src/services/ethereumService.ts +69 -69
  231. package/src/services/strategiesService.test.ts +105 -105
  232. package/src/services/strategiesService.ts +1219 -1158
  233. package/src/services/strategySubService.test.ts +1250 -1122
  234. package/src/services/strategySubService.ts +685 -648
  235. package/src/services/subDataService.test.ts +1546 -1387
  236. package/src/services/subDataService.ts +1024 -934
  237. package/src/services/triggerService.test.ts +1234 -1130
  238. package/src/services/triggerService.ts +659 -602
  239. package/src/services/utils.test.ts +430 -430
  240. package/src/services/utils.ts +162 -162
  241. package/src/types/enums.ts +273 -246
  242. package/src/types/index.ts +333 -312
  243. package/tsconfig.esm.json +8 -8
  244. package/tsconfig.json +22 -22
@@ -1,1122 +1,1250 @@
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 } 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
+ 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
+ describe('leverageManagementOnPrice()', () => {
692
+ const examples: Array<[
693
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
694
+ [strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, price: number, priceState: RatioState, ratioState: RatioState, user: EthereumAddress]
695
+ ]> = [
696
+ [
697
+ [
698
+ Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
699
+ true,
700
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f07775030000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
701
+ [
702
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
703
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
704
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
705
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
706
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
707
+ '0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
708
+ ],
709
+ ],
710
+ [
711
+ Bundles.MainnetIds.COMP_V3_SW_REPAY_ON_PRICE,
712
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
713
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
714
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
715
+ 200,
716
+ 2000,
717
+ RatioState.UNDER,
718
+ RatioState.UNDER,
719
+ web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
720
+ ],
721
+ ],
722
+ [
723
+ [
724
+ Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
725
+ true,
726
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f077750300000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
727
+ [
728
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
729
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
730
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
731
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
732
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
733
+ '0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
734
+ ],
735
+ ],
736
+ [
737
+ Bundles.MainnetIds.COMP_V3_SW_BOOST_ON_PRICE,
738
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
739
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
740
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
741
+ 190,
742
+ 3000,
743
+ RatioState.OVER,
744
+ RatioState.OVER,
745
+ web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
746
+ ],
747
+ ]
748
+ ];
749
+ examples.forEach(([expected, actual]) => {
750
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
751
+ expect(compoundV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
752
+ });
753
+ });
754
+ });
755
+ describe('closeOnPrice()', () => {
756
+ const examples: Array<[
757
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
758
+ [strategyOrBundleId: number, market: EthereumAddress, collToken: EthereumAddress, baseToken: EthereumAddress, stopLossPrice: number, stopLossType: CloseToAssetType, takeProfitPrice: number, takeProfitType: CloseToAssetType, user: EthereumAddress]
759
+ ]> = [
760
+ [
761
+ [
762
+ Bundles.MainnetIds.COMP_V3_SW_CLOSE,
763
+ true,
764
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
765
+ [
766
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
767
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
768
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
769
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
770
+ '0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
771
+ ],
772
+ ],
773
+ [
774
+ Bundles.MainnetIds.COMP_V3_SW_CLOSE,
775
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
776
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
777
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
778
+ 1500,
779
+ CloseToAssetType.DEBT,
780
+ 4000,
781
+ CloseToAssetType.DEBT,
782
+ web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
783
+ ],
784
+ ],
785
+ [
786
+ [
787
+ Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
788
+ true,
789
+ ['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
790
+ [
791
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
792
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
793
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
794
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
795
+ '0x0000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f0777503',
796
+ ],
797
+ ],
798
+ [
799
+ Bundles.MainnetIds.COMP_V3_EOA_CLOSE,
800
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
801
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
802
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
803
+ 0,
804
+ CloseToAssetType.DEBT,
805
+ 5000,
806
+ CloseToAssetType.COLLATERAL,
807
+ web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
808
+ ],
809
+ ]
810
+ ];
811
+ examples.forEach(([expected, actual]) => {
812
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
813
+ expect(compoundV3Encode.closeOnPrice(...actual)).to.eql(expected);
814
+ });
815
+ });
816
+ });
817
+ });
818
+
819
+ describe('When testing strategySubService.morphoAaveV2Encode', () => {
820
+ describe('leverageManagement()', () => {
821
+ const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
822
+ [
823
+ [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],
824
+ [160, 220, 180, 190, true]
825
+ ],
826
+ [
827
+ [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],
828
+ [160, 200, 180, 190, false]
829
+ ],
830
+ ];
831
+
832
+ examples.forEach(([expected, actual]) => {
833
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
834
+ expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
835
+ });
836
+ });
837
+ });
838
+ });
839
+
840
+ describe('When testing strategySubService.exchangeEncode', () => {
841
+ describe('dca()', () => {
842
+ const examples: Array<[
843
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
844
+ [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, timestamp: number, interval: number, network: ChainId],
845
+ ]> = [
846
+ [
847
+ [
848
+ Strategies.ArbitrumIds.EXCHANGE_DCA,
849
+ false,
850
+ ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd000000000000000000000000000000000000000000000000000000000012d068'],
851
+ [
852
+ '0x000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da1', '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831',
853
+ '0x0000000000000000000000000000000000000000000000000000000000038270', '0x000000000000000000000000000000000000000000000000000000000012d068'
854
+ ],
855
+ ],
856
+ [getAssetInfo('DAI', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, '230000', 1697111705805, 1233000, ChainId.Arbitrum]
857
+ ],
858
+ [
859
+ [
860
+ Strategies.MainnetIds.EXCHANGE_DCA,
861
+ false,
862
+ ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd0000000000000000000000000000000000000000000000000000000000067458'],
863
+ [
864
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599', '0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
865
+ '0x0000000000000000000000000000000000000000000000000000000000000015', '0x0000000000000000000000000000000000000000000000000000000000067458',
866
+ ],
867
+ ],
868
+ [getAssetInfo('WBTC').address, getAssetInfo('ETH').address, '21', 1697111705805, 423000, ChainId.Ethereum]
869
+ ],
870
+ ];
871
+
872
+ examples.forEach(([expected, actual]) => {
873
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
874
+ expect(exchangeEncode.dca(...actual)).to.eql(expected);
875
+ });
876
+ });
877
+ });
878
+
879
+ describe('limitOrder()', () => {
880
+ const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string], [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType]]> = [
881
+ [
882
+ [
883
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
884
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
885
+ '2131',
886
+ '0.53123',
887
+ '1696590921159',
888
+ `${OrderType.STOP_LOSS}`
889
+ ],
890
+ [
891
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
892
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
893
+ '2131',
894
+ '0.53123',
895
+ 1696590921159,
896
+ OrderType.STOP_LOSS
897
+ ]
898
+ ],
899
+ [
900
+ [
901
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
902
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
903
+ '2131',
904
+ '0.43123',
905
+ '1646590921159',
906
+ `${OrderType.TAKE_PROFIT}`
907
+ ],
908
+ [
909
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
910
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
911
+ '2131',
912
+ '0.43123',
913
+ 1646590921159,
914
+ OrderType.TAKE_PROFIT
915
+ ]
916
+ ],
917
+ ];
918
+
919
+ examples.forEach(([expected, actual]) => {
920
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
921
+ expect(exchangeEncode.limitOrder(...actual)).to.eql(expected);
922
+ });
923
+ });
924
+ });
925
+ });
926
+
927
+ describe('When testing strategySubService.sparkEncode', () => {
928
+ describe('leverageManagement()', () => {
929
+ const examples: Array<[
930
+ string,
931
+ [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
932
+ ]> = [
933
+ [
934
+ '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
935
+ [160, 220, 180, 190, true]
936
+ ],
937
+ [
938
+ '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
939
+ [160, 200, 180, 190, false]
940
+ ],
941
+ ];
942
+
943
+ examples.forEach(([expected, actual]) => {
944
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
945
+ expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
946
+ });
947
+ });
948
+ });
949
+
950
+ describe('closeToAsset()', () => {
951
+ const examples: Array<[
952
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
953
+ [
954
+ strategyOrBundleId: number,
955
+ isBundle: boolean,
956
+ triggerData: {
957
+ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState
958
+ },
959
+ subData: {
960
+ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
961
+ },
962
+ ]
963
+ ]> = [
964
+ [
965
+ [
966
+ Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
967
+ true,
968
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
969
+ [
970
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
971
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
972
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
973
+ ],
974
+ ],
975
+ [
976
+ Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
977
+ true,
978
+ {
979
+ baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER
980
+ },
981
+ {
982
+ collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
983
+ },
984
+ ]
985
+ ],
986
+ [
987
+ [
988
+ Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
989
+ true,
990
+ ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
991
+ [
992
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
993
+ '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
994
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
995
+ ],
996
+ ],
997
+ [
998
+ Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
999
+ true,
1000
+ {
1001
+ baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER
1002
+ },
1003
+ {
1004
+ collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
1005
+ },
1006
+ ]
1007
+ ]
1008
+ ];
1009
+
1010
+ examples.forEach(([expected, actual]) => {
1011
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1012
+ expect(sparkEncode.closeToAsset(...actual)).to.eql(expected);
1013
+ });
1014
+ });
1015
+ });
1016
+ });
1017
+
1018
+ describe('When testing strategySubService.crvUSDEncode', () => {
1019
+ describe('leverageManagement()', () => {
1020
+ const examples: Array<[
1021
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1022
+ [owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress],
1023
+ ]> = [
1024
+ [
1025
+ [
1026
+ Bundles.MainnetIds.CRVUSD_REPAY,
1027
+ true,
1028
+ [
1029
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001',
1030
+ ],
1031
+ [
1032
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1033
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1034
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
1035
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1036
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1037
+ ],
1038
+ ],
1039
+ [
1040
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1041
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
1042
+ RatioState.UNDER,
1043
+ 190,
1044
+ 140,
1045
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1046
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
1047
+ ]
1048
+ ],
1049
+ [
1050
+ [
1051
+ Bundles.MainnetIds.CRVUSD_BOOST,
1052
+ true,
1053
+ [
1054
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
1055
+ ],
1056
+ [
1057
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1058
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1059
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1060
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1061
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1062
+ ],
1063
+ ],
1064
+ [
1065
+ web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
1066
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
1067
+ RatioState.OVER,
1068
+ 160,
1069
+ 200,
1070
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1071
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
1072
+ ]
1073
+ ],
1074
+ ];
1075
+
1076
+ examples.forEach(([expected, actual]) => {
1077
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1078
+ expect(crvUSDEncode.leverageManagement(...actual)).to.eql(expected);
1079
+ });
1080
+ });
1081
+ });
1082
+ describe('payback()', () => {
1083
+ const examples: Array<[
1084
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1085
+ [owner: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress, controllerAddr: EthereumAddress, minHealthRatio: number],
1086
+ ]> = [
1087
+ [
1088
+ [
1089
+ Strategies.MainnetIds.CURVEUSD_PAYBACK,
1090
+ false,
1091
+ [
1092
+ '0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000',
1093
+ ],
1094
+ [
1095
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1096
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1097
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1098
+ '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1099
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e'
1100
+ ],
1101
+ ],
1102
+ [
1103
+ web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'),
1104
+ web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
1105
+ web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
1106
+ '20000',
1107
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
1108
+ web3Utils.toChecksumAddress('0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635'),
1109
+ 20,
1110
+ ]
1111
+ ]
1112
+ ];
1113
+
1114
+ examples.forEach(([expected, actual]) => {
1115
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1116
+ expect(crvUSDEncode.payback(...actual)).to.eql(expected);
1117
+ });
1118
+ });
1119
+ });
1120
+ });
1121
+ describe('When testing strategySubService.morphoBlueEncode', () => {
1122
+ describe('leverageManagement()', () => {
1123
+ const examples: Array<[
1124
+ [StrategyOrBundleIds, boolean, TriggerData, SubData],
1125
+ [
1126
+ marketId: string,
1127
+ loanToken: EthereumAddress,
1128
+ collToken: EthereumAddress,
1129
+ oracle: EthereumAddress,
1130
+ irm: EthereumAddress,
1131
+ lltv: string,
1132
+ ratioState: RatioState,
1133
+ targetRatio: number,
1134
+ triggerRatio: number,
1135
+ user: EthereumAddress,
1136
+ isEoa: boolean,
1137
+ network: ChainId
1138
+ ],
1139
+ ]> = [
1140
+ [
1141
+ [
1142
+ Bundles.MainnetIds.MORPHO_BLUE_REPAY,
1143
+ true,
1144
+ [
1145
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001',
1146
+ ],
1147
+ [
1148
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1149
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1150
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1151
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1152
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1153
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1154
+ '0x000000000000000000000000000000000000000000000000136dcc951d8c0000',
1155
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1156
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1157
+ ],
1158
+ ],
1159
+ [
1160
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
1161
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1162
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1163
+ web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
1164
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1165
+ '945000000000000000',
1166
+ RatioState.UNDER,
1167
+ 140,
1168
+ 120,
1169
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1170
+ false,
1171
+ ChainId.Ethereum,
1172
+ ]
1173
+ ],
1174
+ [
1175
+ [
1176
+ Bundles.MainnetIds.MORPHO_BLUE_BOOST,
1177
+ true,
1178
+ [
1179
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
1180
+ ],
1181
+ [
1182
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1183
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1184
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1185
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1186
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1187
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1188
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
1189
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1190
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1191
+ ],
1192
+ ],
1193
+ [
1194
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
1195
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
1196
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
1197
+ web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
1198
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
1199
+ '945000000000000000',
1200
+ RatioState.OVER,
1201
+ 160,
1202
+ 200,
1203
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1204
+ false,
1205
+ ChainId.Ethereum,
1206
+ ]
1207
+ ],
1208
+ ];
1209
+
1210
+ examples.forEach(([expected, actual]) => {
1211
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1212
+ expect(morphoBlueEncode.leverageManagement(...actual)).to.eql(expected);
1213
+ });
1214
+ });
1215
+ });
1216
+ });
1217
+
1218
+ describe('When testing strategySubService.compoundV3L2Encode', () => {
1219
+ describe('leverageManagement()', () => {
1220
+ const examples: Array<[string, [EthereumAddress, EthereumAddress, number, number, number, number, boolean, boolean]]> = [
1221
+ [
1222
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
1223
+ [
1224
+ web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1225
+ web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1226
+ 160, 220, 180, 190,
1227
+ true,
1228
+ false,
1229
+ ],
1230
+ ],
1231
+ [
1232
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
1233
+ [
1234
+ web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1235
+ web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
1236
+ 160, 220, 180, 110,
1237
+ false,
1238
+ false,
1239
+ ],
1240
+ ],
1241
+ ];
1242
+ examples.forEach(([expected, actual]) => {
1243
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1244
+ expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
1245
+ });
1246
+ });
1247
+ });
1248
+ });
1249
+
1250
+ });