@defisaver/automation-sdk 3.2.2 → 3.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/.babelrc +3 -3
  2. package/.editorconfig +9 -9
  3. package/.env.dev +4 -4
  4. package/.eslintignore +6 -6
  5. package/.eslintrc.js +39 -39
  6. package/.mocharc.json +4 -4
  7. package/.nvmrc +1 -1
  8. package/README.md +46 -46
  9. package/cjs/abis/Erc20.json +223 -223
  10. package/cjs/abis/SubStorage.json +21 -21
  11. package/cjs/abis/UniMulticall.json +17 -17
  12. package/cjs/abis/index.d.ts +9 -9
  13. package/cjs/abis/index.js +30 -30
  14. package/cjs/abis/legacy_AaveV2Subscriptions.json +8 -8
  15. package/cjs/abis/legacy_AuthCheck.json +8 -8
  16. package/cjs/abis/legacy_CompoundV2Subscriptions.json +9 -9
  17. package/cjs/abis/legacy_MakerSubscriptions.json +9 -9
  18. package/cjs/automation/private/Automation.d.ts +12 -12
  19. package/cjs/automation/private/Automation.js +42 -42
  20. package/cjs/automation/private/LegacyAutomation.d.ts +25 -25
  21. package/cjs/automation/private/LegacyAutomation.js +118 -118
  22. package/cjs/automation/private/LegacyProtocol.d.ts +22 -22
  23. package/cjs/automation/private/LegacyProtocol.js +41 -41
  24. package/cjs/automation/private/LegacyProtocol.test.d.ts +1 -1
  25. package/cjs/automation/private/LegacyProtocol.test.js +25 -25
  26. package/cjs/automation/private/Protocol.d.ts +22 -22
  27. package/cjs/automation/private/Protocol.js +41 -41
  28. package/cjs/automation/private/Protocol.test.d.ts +1 -1
  29. package/cjs/automation/private/Protocol.test.js +25 -25
  30. package/cjs/automation/private/StrategiesAutomation.d.ts +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 +564 -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 +898 -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 +110 -110
  67. package/cjs/services/strategySubService.js +308 -308
  68. package/cjs/services/strategySubService.test.d.ts +1 -1
  69. package/cjs/services/strategySubService.test.js +936 -936
  70. package/cjs/services/subDataService.d.ts +254 -254
  71. package/cjs/services/subDataService.js +669 -669
  72. package/cjs/services/subDataService.test.d.ts +1 -1
  73. package/cjs/services/subDataService.test.js +1282 -1282
  74. package/cjs/services/triggerService.d.ts +234 -234
  75. package/cjs/services/triggerService.js +447 -447
  76. package/cjs/services/triggerService.test.d.ts +1 -1
  77. package/cjs/services/triggerService.test.js +926 -926
  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 +226 -226
  101. package/cjs/types/enums.js +252 -252
  102. package/cjs/types/index.d.ts +248 -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 +558 -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 +868 -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 +110 -110
  162. package/esm/services/strategySubService.js +279 -279
  163. package/esm/services/strategySubService.test.d.ts +1 -1
  164. package/esm/services/strategySubService.test.js +908 -908
  165. package/esm/services/subDataService.d.ts +254 -254
  166. package/esm/services/subDataService.js +663 -663
  167. package/esm/services/subDataService.test.d.ts +1 -1
  168. package/esm/services/subDataService.test.js +1254 -1254
  169. package/esm/services/triggerService.d.ts +234 -234
  170. package/esm/services/triggerService.js +418 -418
  171. package/esm/services/triggerService.test.d.ts +1 -1
  172. package/esm/services/triggerService.test.js +901 -901
  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 +226 -226
  196. package/esm/types/enums.js +249 -249
  197. package/esm/types/index.d.ts +248 -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 +593 -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 +1158 -1158
  233. package/src/services/strategySubService.test.ts +1122 -1122
  234. package/src/services/strategySubService.ts +634 -634
  235. package/src/services/subDataService.test.ts +1387 -1387
  236. package/src/services/subDataService.ts +914 -914
  237. package/src/services/triggerService.test.ts +1004 -1004
  238. package/src/services/triggerService.ts +573 -573
  239. package/src/services/utils.test.ts +430 -430
  240. package/src/services/utils.ts +162 -162
  241. package/src/types/enums.ts +246 -246
  242. package/src/types/index.ts +312 -312
  243. package/tsconfig.esm.json +8 -8
  244. package/tsconfig.json +22 -22
  245. package/.env +0 -4
@@ -1,908 +1,908 @@
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
- import { Bundles, ChainId, OrderType, RatioState, Strategies } from '../types/enums';
7
- import '../configuration';
8
- import { aaveV2Encode, chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV2Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, sparkEncode, crvUSDEncode, compoundV3L2Encode, morphoBlueEncode, } from './strategySubService';
9
- describe('Feature: strategySubService.ts', () => {
10
- describe('When testing strategySubService.makerEncode', () => {
11
- // @ts-ignore // TODO - this requires change in @defisaver/tokens
12
- const mcdCdpManagerAddr = otherAddresses(ChainId.Ethereum).McdCdpManager;
13
- describe('repayFromSavings()', () => {
14
- const examples = [
15
- [
16
- [
17
- Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_RARI,
18
- true,
19
- ['0x00000000000000000000000000000000000000000000000000000000000000de000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
20
- [
21
- '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
22
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
23
- ],
24
- ],
25
- [
26
- Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_RARI,
27
- 222,
28
- 140,
29
- 180,
30
- true,
31
- ChainId.Ethereum,
32
- getAssetInfo('DAI').address,
33
- mcdCdpManagerAddr,
34
- ]
35
- ]
36
- ];
37
- examples.forEach(([expected, actual]) => {
38
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
39
- expect(makerEncode.repayFromSavings(...actual)).to.eql(expected);
40
- });
41
- });
42
- });
43
- describe('closeOnPrice()', () => {
44
- const examples = [
45
- [
46
- [
47
- Strategies.MainnetIds.MAKER_CLOSE_ON_PRICE_TO_DAI,
48
- false,
49
- ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000002cc9e4c0000000000000000000000000000000000000000000000000000000000000000'],
50
- [
51
- '0x0000000000000000000000000000000000000000000000000000000000000078', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
52
- '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
53
- ],
54
- ],
55
- [
56
- 120,
57
- RatioState.OVER,
58
- '0.469643',
59
- getAssetInfo('DAI').address,
60
- getAssetInfo('WBTC').address,
61
- ChainId.Ethereum,
62
- ]
63
- ]
64
- ];
65
- examples.forEach(([expected, actual]) => {
66
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
67
- expect(makerEncode.closeOnPrice(...actual)).to.eql(expected);
68
- });
69
- });
70
- });
71
- describe('trailingStop()', () => {
72
- const examples = [
73
- [
74
- [
75
- Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_COLL,
76
- false,
77
- ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000000000000000000000000000000000055ae82600000000000000000000000000000000000000000000000000000000000000007b'],
78
- [
79
- '0x000000000000000000000000000000000000000000000000000000000000096e', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
80
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
81
- ],
82
- ],
83
- [
84
- 2414,
85
- 230,
86
- getAssetInfo('WBTC').address,
87
- getAssetInfo('WBTC').address,
88
- 123,
89
- ChainId.Ethereum,
90
- ]
91
- ]
92
- ];
93
- examples.forEach(([expected, actual]) => {
94
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
95
- expect(makerEncode.trailingStop(...actual)).to.eql(expected);
96
- });
97
- });
98
- });
99
- describe('leverageManagement()', () => {
100
- const examples = [
101
- [
102
- [
103
- 5791,
104
- new Dec('210').mul(1e16).toString(),
105
- new Dec('290').mul(1e16).toString(),
106
- new Dec('240').mul(1e16).toString(),
107
- new Dec('240').mul(1e16).toString(),
108
- true,
109
- ],
110
- [
111
- 5791, '210', '290', '240', '240', true,
112
- ]
113
- ]
114
- ];
115
- examples.forEach(([expected, actual]) => {
116
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
117
- expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
118
- });
119
- });
120
- });
121
- });
122
- describe('When testing strategySubService.liquityEncode', () => {
123
- describe('closeOnPrice()', () => {
124
- const examples = [
125
- [
126
- [
127
- Strategies.MainnetIds.LIQUITY_CLOSE_ON_PRICE_TO_COLL,
128
- false,
129
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000001c027053000000000000000000000000000000000000000000000000000000000000000000'],
130
- [
131
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
132
- ],
133
- ],
134
- [
135
- RatioState.OVER,
136
- '1203',
137
- getAssetInfo('WETH').address,
138
- getAssetInfo('WETH').address,
139
- ]
140
- ]
141
- ];
142
- examples.forEach(([expected, actual]) => {
143
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
144
- expect(liquityEncode.closeOnPrice(...actual)).to.eql(expected);
145
- });
146
- });
147
- });
148
- describe('trailingStop()', () => {
149
- const examples = [
150
- [
151
- [
152
- Strategies.MainnetIds.LIQUITY_TRAILING_STOP_LOSS_TO_COLL,
153
- false,
154
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000055ae826000000000000000000000000000000000000000000000000000000000000000c97'],
155
- [
156
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
157
- ],
158
- ],
159
- [
160
- 230,
161
- getAssetInfo('WETH').address,
162
- getAssetInfo('WETH').address,
163
- 3223,
164
- ]
165
- ]
166
- ];
167
- examples.forEach(([expected, actual]) => {
168
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
169
- expect(liquityEncode.trailingStop(...actual)).to.eql(expected);
170
- });
171
- });
172
- });
173
- describe('leverageManagement()', () => {
174
- const examples = [
175
- [
176
- [
177
- new Dec('210').mul(1e16).toString(),
178
- new Dec('290').mul(1e16).toString(),
179
- new Dec('240').mul(1e16).toString(),
180
- new Dec('240').mul(1e16).toString(),
181
- false,
182
- ],
183
- [
184
- '210', '290', '240', '240', false,
185
- ]
186
- ]
187
- ];
188
- examples.forEach(([expected, actual]) => {
189
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
190
- expect(liquityEncode.leverageManagement(...actual)).to.eql(expected);
191
- });
192
- });
193
- });
194
- describe('paybackFromChickenBondStrategySub()', () => {
195
- const examples = [
196
- [
197
- [
198
- Bundles.MainnetIds.LIQUITY_PAYBACK_USING_CHICKEN_BOND,
199
- true,
200
- ['0x0000000000000000000000002439d211133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002dcbf4840eca00000000000000000000000000000000000000000000000000000000000000000000'],
201
- [
202
- '0x000000000000000000000000000000000000000000000000000000000000007b', '0x0000000000000000000000000000000000000000000000000000000000000000',
203
- '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
204
- ],
205
- ],
206
- [
207
- web3Utils.toChecksumAddress('0x2439d211133AFaB8F2B819B1066c7E434Ad94E9e'),
208
- 330,
209
- '123',
210
- 0,
211
- RatioState.OVER
212
- ]
213
- ]
214
- ];
215
- examples.forEach(([expected, actual]) => {
216
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
217
- expect(liquityEncode.paybackFromChickenBondStrategySub(...actual)).to.eql(expected);
218
- });
219
- });
220
- });
221
- describe('dsrPayback()', () => {
222
- const examples = [
223
- [
224
- [
225
- Strategies.MainnetIds.LIQUITY_DSR_PAYBACK,
226
- false,
227
- ['0x0000000000000000000000002439d211133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000250dbeda8e4b00000000000000000000000000000000000000000000000000000000000000000001'],
228
- [
229
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x00000000000000000000000000000000000000000000000029a2241af62c0000',
230
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
231
- ],
232
- ],
233
- [web3Utils.toChecksumAddress('0x2439d211133AFaB8F2B819B1066c7E434Ad94E9e'), 267, 300]
234
- ]
235
- ];
236
- examples.forEach(([expected, actual]) => {
237
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
238
- expect(liquityEncode.dsrPayback(...actual)).to.eql(expected);
239
- });
240
- });
241
- });
242
- describe('debtInFrontRepay()', () => {
243
- const examples = [
244
- [
245
- [
246
- Strategies.MainnetIds.LIQUITY_DEBT_IN_FRONT_REPAY,
247
- false,
248
- ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a0000000000000000000000000000000000000000019d971e4fe8401e74000000'],
249
- [
250
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
251
- '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
252
- '0x0000000000000000000000000000000000000000000000000000000000000000'
253
- ],
254
- ],
255
- [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '500000000', 45]
256
- ]
257
- ];
258
- examples.forEach(([expected, actual]) => {
259
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
260
- expect(liquityEncode.debtInFrontRepay(...actual)).to.eql(expected);
261
- });
262
- });
263
- });
264
- });
265
- describe('When testing strategySubService.chickenBondsEncode', () => {
266
- describe('rebond()', () => {
267
- const examples = [
268
- [
269
- ['0x00000000000000000000000000000000000000000000000000000000000005e3'],
270
- [1507]
271
- ]
272
- ];
273
- examples.forEach(([expected, actual]) => {
274
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
275
- expect(chickenBondsEncode.rebond(...actual)).to.eql(expected);
276
- });
277
- });
278
- });
279
- });
280
- describe('When testing strategySubService.aaveV2Encode', () => {
281
- describe('leverageManagement()', () => {
282
- const examples = [
283
- [
284
- [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],
285
- [160, 220, 180, 190, true]
286
- ],
287
- [
288
- [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],
289
- [160, 200, 180, 190, false]
290
- ],
291
- ];
292
- examples.forEach(([expected, actual]) => {
293
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
294
- expect(aaveV2Encode.leverageManagement(...actual)).to.eql(expected);
295
- });
296
- });
297
- });
298
- });
299
- describe('When testing strategySubService.aaveV3Encode', () => {
300
- describe('leverageManagement()', () => {
301
- const examples = [
302
- [
303
- '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
304
- [160, 220, 180, 190, true]
305
- ],
306
- [
307
- '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
308
- [160, 200, 180, 190, false]
309
- ],
310
- ];
311
- examples.forEach(([expected, actual]) => {
312
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
313
- expect(aaveV3Encode.leverageManagement(...actual)).to.eql(expected);
314
- });
315
- });
316
- });
317
- describe('closeToAsset()', () => {
318
- const examples = [
319
- [
320
- [
321
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
322
- true,
323
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
324
- [
325
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
326
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
327
- '0x0000000000000000000000000000000000000000000000000000000000000000',
328
- ],
329
- ],
330
- [
331
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
332
- true,
333
- {
334
- baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER
335
- },
336
- {
337
- collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
338
- },
339
- ]
340
- ],
341
- [
342
- [
343
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
344
- true,
345
- ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
346
- [
347
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
348
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
349
- '0x0000000000000000000000000000000000000000000000000000000000000000',
350
- ],
351
- ],
352
- [
353
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
354
- true,
355
- {
356
- baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER
357
- },
358
- {
359
- collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
360
- },
361
- ]
362
- ]
363
- ];
364
- examples.forEach(([expected, actual]) => {
365
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
366
- expect(aaveV3Encode.closeToAsset(...actual)).to.eql(expected);
367
- });
368
- });
369
- });
370
- describe('closeToAssetWithMaximumGasPrice()', () => {
371
- const examples = [
372
- [
373
- [
374
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
375
- true,
376
- [
377
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000',
378
- '0x00000000000000000000000000000000000000000000000000000002cb417800',
379
- ],
380
- [
381
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
382
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
383
- '0x0000000000000000000000000000000000000000000000000000000000000000',
384
- ],
385
- ],
386
- [
387
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
388
- true,
389
- {
390
- baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER, maximumGasPrice: 12,
391
- },
392
- {
393
- collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
394
- },
395
- ]
396
- ],
397
- [
398
- [
399
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
400
- true,
401
- [
402
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001',
403
- '0x0000000000000000000000000000000000000000000000000000004a817c8000',
404
- ],
405
- [
406
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
407
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
408
- '0x0000000000000000000000000000000000000000000000000000000000000000',
409
- ],
410
- ],
411
- [
412
- Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
413
- true,
414
- {
415
- baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER, maximumGasPrice: 320,
416
- },
417
- {
418
- collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
419
- },
420
- ]
421
- ]
422
- ];
423
- examples.forEach(([expected, actual]) => {
424
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
425
- expect(aaveV3Encode.closeToAssetWithMaximumGasPrice(...actual)).to.eql(expected);
426
- });
427
- });
428
- });
429
- describe('leverageManagementOnPrice()', () => {
430
- const examples = [
431
- [
432
- [
433
- Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
434
- true,
435
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000007acead34980000000000000000000000000000000000000000000000000000000000000001'],
436
- [
437
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
438
- '0x000000000000000000000000000000000000000000000000000000000000000a',
439
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
440
- '0x0000000000000000000000000000000000000000000000000000000000000004',
441
- '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
442
- '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
443
- '0x0000000000000000000000000000000000000000000000000000000000000000',
444
- ],
445
- ],
446
- [
447
- Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
448
- true,
449
- {
450
- baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 5274.534678, state: RatioState.UNDER
451
- },
452
- {
453
- collAsset: getAssetInfo('WETH').address,
454
- collAssetId: 10,
455
- debtAsset: getAssetInfo('DAI').address,
456
- debtAssetId: 4,
457
- marketAddr: '0x2f39d218133afab8f2b819b1066c7e434ad94e9e',
458
- targetRatio: 200,
459
- },
460
- ]
461
- ],
462
- ];
463
- examples.forEach(([expected, actual]) => {
464
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
465
- expect(aaveV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
466
- });
467
- });
468
- });
469
- });
470
- describe('When testing strategySubService.compoundV2Encode', () => {
471
- describe('leverageManagement()', () => {
472
- const examples = [
473
- [
474
- [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],
475
- [160, 220, 180, 190, true]
476
- ],
477
- [
478
- [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],
479
- [160, 200, 180, 190, false]
480
- ],
481
- ];
482
- examples.forEach(([expected, actual]) => {
483
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
484
- expect(compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
485
- });
486
- });
487
- });
488
- });
489
- describe('When testing strategySubService.compoundV3Encode', () => {
490
- describe('leverageManagement()', () => {
491
- const examples = [
492
- [
493
- [
494
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
495
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
496
- new Dec(160).mul(1e16).toString(),
497
- new Dec(220).mul(1e16).toString(),
498
- new Dec(180).mul(1e16).toString(),
499
- new Dec(190).mul(1e16).toString(),
500
- true, false,
501
- ],
502
- [
503
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
504
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
505
- 160, 220, 180, 190,
506
- true, false,
507
- ]
508
- ],
509
- [
510
- [
511
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
512
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
513
- new Dec(160).mul(1e16).toString(),
514
- new Dec(210).mul(1e16).toString(),
515
- new Dec(180).mul(1e16).toString(),
516
- new Dec(190).mul(1e16).toString(),
517
- false, true,
518
- ],
519
- [
520
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
521
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
522
- 160, 210, 180, 190,
523
- false, true,
524
- ]
525
- ],
526
- ];
527
- examples.forEach(([expected, actual]) => {
528
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
529
- expect(compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
530
- });
531
- });
532
- });
533
- });
534
- describe('When testing strategySubService.morphoAaveV2Encode', () => {
535
- describe('leverageManagement()', () => {
536
- const examples = [
537
- [
538
- [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],
539
- [160, 220, 180, 190, true]
540
- ],
541
- [
542
- [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],
543
- [160, 200, 180, 190, false]
544
- ],
545
- ];
546
- examples.forEach(([expected, actual]) => {
547
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
548
- expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
549
- });
550
- });
551
- });
552
- });
553
- describe('When testing strategySubService.exchangeEncode', () => {
554
- describe('dca()', () => {
555
- const examples = [
556
- [
557
- [
558
- Strategies.ArbitrumIds.EXCHANGE_DCA,
559
- false,
560
- ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd000000000000000000000000000000000000000000000000000000000012d068'],
561
- [
562
- '0x000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da1', '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831',
563
- '0x0000000000000000000000000000000000000000000000000000000000038270', '0x000000000000000000000000000000000000000000000000000000000012d068'
564
- ],
565
- ],
566
- [getAssetInfo('DAI', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, '230000', 1697111705805, 1233000, ChainId.Arbitrum]
567
- ],
568
- [
569
- [
570
- Strategies.MainnetIds.EXCHANGE_DCA,
571
- false,
572
- ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd0000000000000000000000000000000000000000000000000000000000067458'],
573
- [
574
- '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599', '0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
575
- '0x0000000000000000000000000000000000000000000000000000000000000015', '0x0000000000000000000000000000000000000000000000000000000000067458',
576
- ],
577
- ],
578
- [getAssetInfo('WBTC').address, getAssetInfo('ETH').address, '21', 1697111705805, 423000, ChainId.Ethereum]
579
- ],
580
- ];
581
- examples.forEach(([expected, actual]) => {
582
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
583
- expect(exchangeEncode.dca(...actual)).to.eql(expected);
584
- });
585
- });
586
- });
587
- describe('limitOrder()', () => {
588
- const examples = [
589
- [
590
- [
591
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
592
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
593
- '2131',
594
- '0.53123',
595
- '1696590921159',
596
- `${OrderType.STOP_LOSS}`
597
- ],
598
- [
599
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
600
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
601
- '2131',
602
- '0.53123',
603
- 1696590921159,
604
- OrderType.STOP_LOSS
605
- ]
606
- ],
607
- [
608
- [
609
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
610
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
611
- '2131',
612
- '0.43123',
613
- '1646590921159',
614
- `${OrderType.TAKE_PROFIT}`
615
- ],
616
- [
617
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
618
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
619
- '2131',
620
- '0.43123',
621
- 1646590921159,
622
- OrderType.TAKE_PROFIT
623
- ]
624
- ],
625
- ];
626
- examples.forEach(([expected, actual]) => {
627
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
628
- expect(exchangeEncode.limitOrder(...actual)).to.eql(expected);
629
- });
630
- });
631
- });
632
- });
633
- describe('When testing strategySubService.sparkEncode', () => {
634
- describe('leverageManagement()', () => {
635
- const examples = [
636
- [
637
- '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
638
- [160, 220, 180, 190, true]
639
- ],
640
- [
641
- '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
642
- [160, 200, 180, 190, false]
643
- ],
644
- ];
645
- examples.forEach(([expected, actual]) => {
646
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
647
- expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
648
- });
649
- });
650
- });
651
- describe('closeToAsset()', () => {
652
- const examples = [
653
- [
654
- [
655
- Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
656
- true,
657
- ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
658
- [
659
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
660
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
661
- '0x0000000000000000000000000000000000000000000000000000000000000000',
662
- ],
663
- ],
664
- [
665
- Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
666
- true,
667
- {
668
- baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER
669
- },
670
- {
671
- collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
672
- },
673
- ]
674
- ],
675
- [
676
- [
677
- Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
678
- true,
679
- ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
680
- [
681
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
682
- '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
683
- '0x0000000000000000000000000000000000000000000000000000000000000000',
684
- ],
685
- ],
686
- [
687
- Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
688
- true,
689
- {
690
- baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER
691
- },
692
- {
693
- collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
694
- },
695
- ]
696
- ]
697
- ];
698
- examples.forEach(([expected, actual]) => {
699
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
700
- expect(sparkEncode.closeToAsset(...actual)).to.eql(expected);
701
- });
702
- });
703
- });
704
- });
705
- describe('When testing strategySubService.crvUSDEncode', () => {
706
- describe('leverageManagement()', () => {
707
- const examples = [
708
- [
709
- [
710
- Bundles.MainnetIds.CRVUSD_REPAY,
711
- true,
712
- [
713
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001',
714
- ],
715
- [
716
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
717
- '0x0000000000000000000000000000000000000000000000000000000000000001',
718
- '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
719
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
720
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
721
- ],
722
- ],
723
- [
724
- web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
725
- web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
726
- RatioState.UNDER,
727
- 190,
728
- 140,
729
- '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
730
- '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
731
- ]
732
- ],
733
- [
734
- [
735
- Bundles.MainnetIds.CRVUSD_BOOST,
736
- true,
737
- [
738
- '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
739
- ],
740
- [
741
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
742
- '0x0000000000000000000000000000000000000000000000000000000000000000',
743
- '0x00000000000000000000000000000000000000000000000016345785d8a00000',
744
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
745
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
746
- ],
747
- ],
748
- [
749
- web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
750
- web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
751
- RatioState.OVER,
752
- 160,
753
- 200,
754
- '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
755
- '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
756
- ]
757
- ],
758
- ];
759
- examples.forEach(([expected, actual]) => {
760
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
761
- expect(crvUSDEncode.leverageManagement(...actual)).to.eql(expected);
762
- });
763
- });
764
- });
765
- describe('payback()', () => {
766
- const examples = [
767
- [
768
- [
769
- Strategies.MainnetIds.CURVEUSD_PAYBACK,
770
- false,
771
- [
772
- '0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000',
773
- ],
774
- [
775
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
776
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
777
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
778
- '0x00000000000000000000000000000000000000000000043c33c1937564800000',
779
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e'
780
- ],
781
- ],
782
- [
783
- web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'),
784
- web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
785
- web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
786
- '20000',
787
- '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
788
- web3Utils.toChecksumAddress('0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635'),
789
- 20,
790
- ]
791
- ]
792
- ];
793
- examples.forEach(([expected, actual]) => {
794
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
795
- expect(crvUSDEncode.payback(...actual)).to.eql(expected);
796
- });
797
- });
798
- });
799
- });
800
- describe('When testing strategySubService.morphoBlueEncode', () => {
801
- describe('leverageManagement()', () => {
802
- const examples = [
803
- [
804
- [
805
- Bundles.MainnetIds.MORPHO_BLUE_REPAY,
806
- true,
807
- [
808
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001',
809
- ],
810
- [
811
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
812
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
813
- '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
814
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
815
- '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
816
- '0x0000000000000000000000000000000000000000000000000000000000000001',
817
- '0x000000000000000000000000000000000000000000000000136dcc951d8c0000',
818
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
819
- '0x0000000000000000000000000000000000000000000000000000000000000000',
820
- ],
821
- ],
822
- [
823
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
824
- web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
825
- web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
826
- web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
827
- web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
828
- '945000000000000000',
829
- RatioState.UNDER,
830
- 140,
831
- 120,
832
- web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
833
- false,
834
- ChainId.Ethereum,
835
- ]
836
- ],
837
- [
838
- [
839
- Bundles.MainnetIds.MORPHO_BLUE_BOOST,
840
- true,
841
- [
842
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
843
- ],
844
- [
845
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
846
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
847
- '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
848
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
849
- '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
850
- '0x0000000000000000000000000000000000000000000000000000000000000000',
851
- '0x00000000000000000000000000000000000000000000000016345785d8a00000',
852
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
853
- '0x0000000000000000000000000000000000000000000000000000000000000000',
854
- ],
855
- ],
856
- [
857
- '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
858
- web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
859
- web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
860
- web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
861
- web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
862
- '945000000000000000',
863
- RatioState.OVER,
864
- 160,
865
- 200,
866
- web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
867
- false,
868
- ChainId.Ethereum,
869
- ]
870
- ],
871
- ];
872
- examples.forEach(([expected, actual]) => {
873
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
874
- expect(morphoBlueEncode.leverageManagement(...actual)).to.eql(expected);
875
- });
876
- });
877
- });
878
- });
879
- describe('When testing strategySubService.compoundV3L2Encode', () => {
880
- describe('leverageManagement()', () => {
881
- const examples = [
882
- [
883
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
884
- [
885
- web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
886
- web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
887
- 160, 220, 180, 190,
888
- true
889
- ],
890
- ],
891
- [
892
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee000000',
893
- [
894
- web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
895
- web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
896
- 160, 220, 180, 110,
897
- false
898
- ],
899
- ],
900
- ];
901
- examples.forEach(([expected, actual]) => {
902
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
903
- expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
904
- });
905
- });
906
- });
907
- });
908
- });
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
+ import { Bundles, ChainId, OrderType, RatioState, Strategies } from '../types/enums';
7
+ import '../configuration';
8
+ import { aaveV2Encode, chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV2Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, sparkEncode, crvUSDEncode, compoundV3L2Encode, morphoBlueEncode, } from './strategySubService';
9
+ describe('Feature: strategySubService.ts', () => {
10
+ describe('When testing strategySubService.makerEncode', () => {
11
+ // @ts-ignore // TODO - this requires change in @defisaver/tokens
12
+ const mcdCdpManagerAddr = otherAddresses(ChainId.Ethereum).McdCdpManager;
13
+ describe('repayFromSavings()', () => {
14
+ const examples = [
15
+ [
16
+ [
17
+ Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_RARI,
18
+ true,
19
+ ['0x00000000000000000000000000000000000000000000000000000000000000de000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001'],
20
+ [
21
+ '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
22
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
23
+ ],
24
+ ],
25
+ [
26
+ Bundles.MainnetIds.MAKER_REPAY_FROM_SMART_SAVINGS_RARI,
27
+ 222,
28
+ 140,
29
+ 180,
30
+ true,
31
+ ChainId.Ethereum,
32
+ getAssetInfo('DAI').address,
33
+ mcdCdpManagerAddr,
34
+ ]
35
+ ]
36
+ ];
37
+ examples.forEach(([expected, actual]) => {
38
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
39
+ expect(makerEncode.repayFromSavings(...actual)).to.eql(expected);
40
+ });
41
+ });
42
+ });
43
+ describe('closeOnPrice()', () => {
44
+ const examples = [
45
+ [
46
+ [
47
+ Strategies.MainnetIds.MAKER_CLOSE_ON_PRICE_TO_DAI,
48
+ false,
49
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000002cc9e4c0000000000000000000000000000000000000000000000000000000000000000'],
50
+ [
51
+ '0x0000000000000000000000000000000000000000000000000000000000000078', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
52
+ '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
53
+ ],
54
+ ],
55
+ [
56
+ 120,
57
+ RatioState.OVER,
58
+ '0.469643',
59
+ getAssetInfo('DAI').address,
60
+ getAssetInfo('WBTC').address,
61
+ ChainId.Ethereum,
62
+ ]
63
+ ]
64
+ ];
65
+ examples.forEach(([expected, actual]) => {
66
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
67
+ expect(makerEncode.closeOnPrice(...actual)).to.eql(expected);
68
+ });
69
+ });
70
+ });
71
+ describe('trailingStop()', () => {
72
+ const examples = [
73
+ [
74
+ [
75
+ Strategies.MainnetIds.MAKER_TRAILING_STOP_LOSS_TO_COLL,
76
+ false,
77
+ ['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000000000000000000000000000000000055ae82600000000000000000000000000000000000000000000000000000000000000007b'],
78
+ [
79
+ '0x000000000000000000000000000000000000000000000000000000000000096e', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
80
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005ef30b9986345249bc32d8928b7ee64de9435e39',
81
+ ],
82
+ ],
83
+ [
84
+ 2414,
85
+ 230,
86
+ getAssetInfo('WBTC').address,
87
+ getAssetInfo('WBTC').address,
88
+ 123,
89
+ ChainId.Ethereum,
90
+ ]
91
+ ]
92
+ ];
93
+ examples.forEach(([expected, actual]) => {
94
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
95
+ expect(makerEncode.trailingStop(...actual)).to.eql(expected);
96
+ });
97
+ });
98
+ });
99
+ describe('leverageManagement()', () => {
100
+ const examples = [
101
+ [
102
+ [
103
+ 5791,
104
+ new Dec('210').mul(1e16).toString(),
105
+ new Dec('290').mul(1e16).toString(),
106
+ new Dec('240').mul(1e16).toString(),
107
+ new Dec('240').mul(1e16).toString(),
108
+ true,
109
+ ],
110
+ [
111
+ 5791, '210', '290', '240', '240', true,
112
+ ]
113
+ ]
114
+ ];
115
+ examples.forEach(([expected, actual]) => {
116
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
117
+ expect(makerEncode.leverageManagement(...actual)).to.eql(expected);
118
+ });
119
+ });
120
+ });
121
+ });
122
+ describe('When testing strategySubService.liquityEncode', () => {
123
+ describe('closeOnPrice()', () => {
124
+ const examples = [
125
+ [
126
+ [
127
+ Strategies.MainnetIds.LIQUITY_CLOSE_ON_PRICE_TO_COLL,
128
+ false,
129
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000001c027053000000000000000000000000000000000000000000000000000000000000000000'],
130
+ [
131
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
132
+ ],
133
+ ],
134
+ [
135
+ RatioState.OVER,
136
+ '1203',
137
+ getAssetInfo('WETH').address,
138
+ getAssetInfo('WETH').address,
139
+ ]
140
+ ]
141
+ ];
142
+ examples.forEach(([expected, actual]) => {
143
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
144
+ expect(liquityEncode.closeOnPrice(...actual)).to.eql(expected);
145
+ });
146
+ });
147
+ });
148
+ describe('trailingStop()', () => {
149
+ const examples = [
150
+ [
151
+ [
152
+ Strategies.MainnetIds.LIQUITY_TRAILING_STOP_LOSS_TO_COLL,
153
+ false,
154
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000000000000000000000000000000000055ae826000000000000000000000000000000000000000000000000000000000000000c97'],
155
+ [
156
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
157
+ ],
158
+ ],
159
+ [
160
+ 230,
161
+ getAssetInfo('WETH').address,
162
+ getAssetInfo('WETH').address,
163
+ 3223,
164
+ ]
165
+ ]
166
+ ];
167
+ examples.forEach(([expected, actual]) => {
168
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
169
+ expect(liquityEncode.trailingStop(...actual)).to.eql(expected);
170
+ });
171
+ });
172
+ });
173
+ describe('leverageManagement()', () => {
174
+ const examples = [
175
+ [
176
+ [
177
+ new Dec('210').mul(1e16).toString(),
178
+ new Dec('290').mul(1e16).toString(),
179
+ new Dec('240').mul(1e16).toString(),
180
+ new Dec('240').mul(1e16).toString(),
181
+ false,
182
+ ],
183
+ [
184
+ '210', '290', '240', '240', false,
185
+ ]
186
+ ]
187
+ ];
188
+ examples.forEach(([expected, actual]) => {
189
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
190
+ expect(liquityEncode.leverageManagement(...actual)).to.eql(expected);
191
+ });
192
+ });
193
+ });
194
+ describe('paybackFromChickenBondStrategySub()', () => {
195
+ const examples = [
196
+ [
197
+ [
198
+ Bundles.MainnetIds.LIQUITY_PAYBACK_USING_CHICKEN_BOND,
199
+ true,
200
+ ['0x0000000000000000000000002439d211133afab8f2b819b1066c7e434ad94e9e0000000000000000000000000000000000000000000000002dcbf4840eca00000000000000000000000000000000000000000000000000000000000000000000'],
201
+ [
202
+ '0x000000000000000000000000000000000000000000000000000000000000007b', '0x0000000000000000000000000000000000000000000000000000000000000000',
203
+ '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
204
+ ],
205
+ ],
206
+ [
207
+ web3Utils.toChecksumAddress('0x2439d211133AFaB8F2B819B1066c7E434Ad94E9e'),
208
+ 330,
209
+ '123',
210
+ 0,
211
+ RatioState.OVER
212
+ ]
213
+ ]
214
+ ];
215
+ examples.forEach(([expected, actual]) => {
216
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
217
+ expect(liquityEncode.paybackFromChickenBondStrategySub(...actual)).to.eql(expected);
218
+ });
219
+ });
220
+ });
221
+ describe('dsrPayback()', () => {
222
+ const examples = [
223
+ [
224
+ [
225
+ Strategies.MainnetIds.LIQUITY_DSR_PAYBACK,
226
+ false,
227
+ ['0x0000000000000000000000002439d211133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000250dbeda8e4b00000000000000000000000000000000000000000000000000000000000000000001'],
228
+ [
229
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x00000000000000000000000000000000000000000000000029a2241af62c0000',
230
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
231
+ ],
232
+ ],
233
+ [web3Utils.toChecksumAddress('0x2439d211133AFaB8F2B819B1066c7E434Ad94E9e'), 267, 300]
234
+ ]
235
+ ];
236
+ examples.forEach(([expected, actual]) => {
237
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
238
+ expect(liquityEncode.dsrPayback(...actual)).to.eql(expected);
239
+ });
240
+ });
241
+ });
242
+ describe('debtInFrontRepay()', () => {
243
+ const examples = [
244
+ [
245
+ [
246
+ Strategies.MainnetIds.LIQUITY_DEBT_IN_FRONT_REPAY,
247
+ false,
248
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a0000000000000000000000000000000000000000019d971e4fe8401e74000000'],
249
+ [
250
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
251
+ '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
252
+ '0x0000000000000000000000000000000000000000000000000000000000000000'
253
+ ],
254
+ ],
255
+ [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '500000000', 45]
256
+ ]
257
+ ];
258
+ examples.forEach(([expected, actual]) => {
259
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
260
+ expect(liquityEncode.debtInFrontRepay(...actual)).to.eql(expected);
261
+ });
262
+ });
263
+ });
264
+ });
265
+ describe('When testing strategySubService.chickenBondsEncode', () => {
266
+ describe('rebond()', () => {
267
+ const examples = [
268
+ [
269
+ ['0x00000000000000000000000000000000000000000000000000000000000005e3'],
270
+ [1507]
271
+ ]
272
+ ];
273
+ examples.forEach(([expected, actual]) => {
274
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
275
+ expect(chickenBondsEncode.rebond(...actual)).to.eql(expected);
276
+ });
277
+ });
278
+ });
279
+ });
280
+ describe('When testing strategySubService.aaveV2Encode', () => {
281
+ describe('leverageManagement()', () => {
282
+ const examples = [
283
+ [
284
+ [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],
285
+ [160, 220, 180, 190, true]
286
+ ],
287
+ [
288
+ [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],
289
+ [160, 200, 180, 190, false]
290
+ ],
291
+ ];
292
+ examples.forEach(([expected, actual]) => {
293
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
294
+ expect(aaveV2Encode.leverageManagement(...actual)).to.eql(expected);
295
+ });
296
+ });
297
+ });
298
+ });
299
+ describe('When testing strategySubService.aaveV3Encode', () => {
300
+ describe('leverageManagement()', () => {
301
+ const examples = [
302
+ [
303
+ '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
304
+ [160, 220, 180, 190, true]
305
+ ],
306
+ [
307
+ '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
308
+ [160, 200, 180, 190, false]
309
+ ],
310
+ ];
311
+ examples.forEach(([expected, actual]) => {
312
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
313
+ expect(aaveV3Encode.leverageManagement(...actual)).to.eql(expected);
314
+ });
315
+ });
316
+ });
317
+ describe('closeToAsset()', () => {
318
+ const examples = [
319
+ [
320
+ [
321
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
322
+ true,
323
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
324
+ [
325
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
326
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
327
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
328
+ ],
329
+ ],
330
+ [
331
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
332
+ true,
333
+ {
334
+ baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER
335
+ },
336
+ {
337
+ collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
338
+ },
339
+ ]
340
+ ],
341
+ [
342
+ [
343
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
344
+ true,
345
+ ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
346
+ [
347
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
348
+ '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
349
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
350
+ ],
351
+ ],
352
+ [
353
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
354
+ true,
355
+ {
356
+ baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER
357
+ },
358
+ {
359
+ collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
360
+ },
361
+ ]
362
+ ]
363
+ ];
364
+ examples.forEach(([expected, actual]) => {
365
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
366
+ expect(aaveV3Encode.closeToAsset(...actual)).to.eql(expected);
367
+ });
368
+ });
369
+ });
370
+ describe('closeToAssetWithMaximumGasPrice()', () => {
371
+ const examples = [
372
+ [
373
+ [
374
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
375
+ true,
376
+ [
377
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000',
378
+ '0x00000000000000000000000000000000000000000000000000000002cb417800',
379
+ ],
380
+ [
381
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
382
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
383
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
384
+ ],
385
+ ],
386
+ [
387
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
388
+ true,
389
+ {
390
+ baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER, maximumGasPrice: 12,
391
+ },
392
+ {
393
+ collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
394
+ },
395
+ ]
396
+ ],
397
+ [
398
+ [
399
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
400
+ true,
401
+ [
402
+ '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001',
403
+ '0x0000000000000000000000000000000000000000000000000000004a817c8000',
404
+ ],
405
+ [
406
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
407
+ '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
408
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
409
+ ],
410
+ ],
411
+ [
412
+ Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT,
413
+ true,
414
+ {
415
+ baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER, maximumGasPrice: 320,
416
+ },
417
+ {
418
+ collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
419
+ },
420
+ ]
421
+ ]
422
+ ];
423
+ examples.forEach(([expected, actual]) => {
424
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
425
+ expect(aaveV3Encode.closeToAssetWithMaximumGasPrice(...actual)).to.eql(expected);
426
+ });
427
+ });
428
+ });
429
+ describe('leverageManagementOnPrice()', () => {
430
+ const examples = [
431
+ [
432
+ [
433
+ Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
434
+ true,
435
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000007acead34980000000000000000000000000000000000000000000000000000000000000001'],
436
+ [
437
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
438
+ '0x000000000000000000000000000000000000000000000000000000000000000a',
439
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
440
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
441
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
442
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
443
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
444
+ ],
445
+ ],
446
+ [
447
+ Bundles.MainnetIds.AAVE_V3_OPEN_ORDER_FROM_COLLATERAL,
448
+ true,
449
+ {
450
+ baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 5274.534678, state: RatioState.UNDER
451
+ },
452
+ {
453
+ collAsset: getAssetInfo('WETH').address,
454
+ collAssetId: 10,
455
+ debtAsset: getAssetInfo('DAI').address,
456
+ debtAssetId: 4,
457
+ marketAddr: '0x2f39d218133afab8f2b819b1066c7e434ad94e9e',
458
+ targetRatio: 200,
459
+ },
460
+ ]
461
+ ],
462
+ ];
463
+ examples.forEach(([expected, actual]) => {
464
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
465
+ expect(aaveV3Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
466
+ });
467
+ });
468
+ });
469
+ });
470
+ describe('When testing strategySubService.compoundV2Encode', () => {
471
+ describe('leverageManagement()', () => {
472
+ const examples = [
473
+ [
474
+ [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],
475
+ [160, 220, 180, 190, true]
476
+ ],
477
+ [
478
+ [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],
479
+ [160, 200, 180, 190, false]
480
+ ],
481
+ ];
482
+ examples.forEach(([expected, actual]) => {
483
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
484
+ expect(compoundV2Encode.leverageManagement(...actual)).to.eql(expected);
485
+ });
486
+ });
487
+ });
488
+ });
489
+ describe('When testing strategySubService.compoundV3Encode', () => {
490
+ describe('leverageManagement()', () => {
491
+ const examples = [
492
+ [
493
+ [
494
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
495
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
496
+ new Dec(160).mul(1e16).toString(),
497
+ new Dec(220).mul(1e16).toString(),
498
+ new Dec(180).mul(1e16).toString(),
499
+ new Dec(190).mul(1e16).toString(),
500
+ true, false,
501
+ ],
502
+ [
503
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
504
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
505
+ 160, 220, 180, 190,
506
+ true, false,
507
+ ]
508
+ ],
509
+ [
510
+ [
511
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
512
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
513
+ new Dec(160).mul(1e16).toString(),
514
+ new Dec(210).mul(1e16).toString(),
515
+ new Dec(180).mul(1e16).toString(),
516
+ new Dec(190).mul(1e16).toString(),
517
+ false, true,
518
+ ],
519
+ [
520
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
521
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
522
+ 160, 210, 180, 190,
523
+ false, true,
524
+ ]
525
+ ],
526
+ ];
527
+ examples.forEach(([expected, actual]) => {
528
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
529
+ expect(compoundV3Encode.leverageManagement(...actual)).to.eql(expected);
530
+ });
531
+ });
532
+ });
533
+ });
534
+ describe('When testing strategySubService.morphoAaveV2Encode', () => {
535
+ describe('leverageManagement()', () => {
536
+ const examples = [
537
+ [
538
+ [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],
539
+ [160, 220, 180, 190, true]
540
+ ],
541
+ [
542
+ [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],
543
+ [160, 200, 180, 190, false]
544
+ ],
545
+ ];
546
+ examples.forEach(([expected, actual]) => {
547
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
548
+ expect(morphoAaveV2Encode.leverageManagement(...actual)).to.eql(expected);
549
+ });
550
+ });
551
+ });
552
+ });
553
+ describe('When testing strategySubService.exchangeEncode', () => {
554
+ describe('dca()', () => {
555
+ const examples = [
556
+ [
557
+ [
558
+ Strategies.ArbitrumIds.EXCHANGE_DCA,
559
+ false,
560
+ ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd000000000000000000000000000000000000000000000000000000000012d068'],
561
+ [
562
+ '0x000000000000000000000000da10009cbd5d07dd0cecc66161fc93d7c9000da1', '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831',
563
+ '0x0000000000000000000000000000000000000000000000000000000000038270', '0x000000000000000000000000000000000000000000000000000000000012d068'
564
+ ],
565
+ ],
566
+ [getAssetInfo('DAI', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, '230000', 1697111705805, 1233000, ChainId.Arbitrum]
567
+ ],
568
+ [
569
+ [
570
+ Strategies.MainnetIds.EXCHANGE_DCA,
571
+ false,
572
+ ['0x0000000000000000000000000000000000000000000000000000018b23bd88cd0000000000000000000000000000000000000000000000000000000000067458'],
573
+ [
574
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599', '0x000000000000000000000000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
575
+ '0x0000000000000000000000000000000000000000000000000000000000000015', '0x0000000000000000000000000000000000000000000000000000000000067458',
576
+ ],
577
+ ],
578
+ [getAssetInfo('WBTC').address, getAssetInfo('ETH').address, '21', 1697111705805, 423000, ChainId.Ethereum]
579
+ ],
580
+ ];
581
+ examples.forEach(([expected, actual]) => {
582
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
583
+ expect(exchangeEncode.dca(...actual)).to.eql(expected);
584
+ });
585
+ });
586
+ });
587
+ describe('limitOrder()', () => {
588
+ const examples = [
589
+ [
590
+ [
591
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
592
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
593
+ '2131',
594
+ '0.53123',
595
+ '1696590921159',
596
+ `${OrderType.STOP_LOSS}`
597
+ ],
598
+ [
599
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
600
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
601
+ '2131',
602
+ '0.53123',
603
+ 1696590921159,
604
+ OrderType.STOP_LOSS
605
+ ]
606
+ ],
607
+ [
608
+ [
609
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
610
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
611
+ '2131',
612
+ '0.43123',
613
+ '1646590921159',
614
+ `${OrderType.TAKE_PROFIT}`
615
+ ],
616
+ [
617
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
618
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
619
+ '2131',
620
+ '0.43123',
621
+ 1646590921159,
622
+ OrderType.TAKE_PROFIT
623
+ ]
624
+ ],
625
+ ];
626
+ examples.forEach(([expected, actual]) => {
627
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
628
+ expect(exchangeEncode.limitOrder(...actual)).to.eql(expected);
629
+ });
630
+ });
631
+ });
632
+ });
633
+ describe('When testing strategySubService.sparkEncode', () => {
634
+ describe('leverageManagement()', () => {
635
+ const examples = [
636
+ [
637
+ '0x000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
638
+ [160, 220, 180, 190, true]
639
+ ],
640
+ [
641
+ '0x000000000000000016345785d8a0000000000000000000001bc16d674ec80000000000000000000018fae27693b4000000000000000000001a5e27eef13e000000',
642
+ [160, 200, 180, 190, false]
643
+ ],
644
+ ];
645
+ examples.forEach(([expected, actual]) => {
646
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
647
+ expect(sparkEncode.leverageManagement(...actual)).to.eql(expected);
648
+ });
649
+ });
650
+ });
651
+ describe('closeToAsset()', () => {
652
+ const examples = [
653
+ [
654
+ [
655
+ Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
656
+ true,
657
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000000'],
658
+ [
659
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000015',
660
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000020',
661
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
662
+ ],
663
+ ],
664
+ [
665
+ Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
666
+ true,
667
+ {
668
+ baseTokenAddress: getAssetInfo('WETH').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 1670, ratioState: RatioState.OVER
669
+ },
670
+ {
671
+ collAsset: getAssetInfo('WETH').address, collAssetId: 21, debtAsset: getAssetInfo('DAI').address, debtAssetId: 32,
672
+ },
673
+ ]
674
+ ],
675
+ [
676
+ [
677
+ Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
678
+ true,
679
+ ['0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000000000000000000000000000000000000000084d000000000000000000000000000000000000000000000000000000000000000001'],
680
+ [
681
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000015',
682
+ '0x000000000000000000000000514910771af9ca656af840dff83e8264ecf986ca', '0x0000000000000000000000000000000000000000000000000000000000000020',
683
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
684
+ ],
685
+ ],
686
+ [
687
+ Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
688
+ true,
689
+ {
690
+ baseTokenAddress: getAssetInfo('LINK').address, quoteTokenAddress: getAssetInfo('DAI').address, price: 0.00544, ratioState: RatioState.UNDER
691
+ },
692
+ {
693
+ collAsset: getAssetInfo('DAI').address, collAssetId: 21, debtAsset: getAssetInfo('LINK').address, debtAssetId: 32,
694
+ },
695
+ ]
696
+ ]
697
+ ];
698
+ examples.forEach(([expected, actual]) => {
699
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
700
+ expect(sparkEncode.closeToAsset(...actual)).to.eql(expected);
701
+ });
702
+ });
703
+ });
704
+ });
705
+ describe('When testing strategySubService.crvUSDEncode', () => {
706
+ describe('leverageManagement()', () => {
707
+ const examples = [
708
+ [
709
+ [
710
+ Bundles.MainnetIds.CRVUSD_REPAY,
711
+ true,
712
+ [
713
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635000000000000000000000000000000000000000000000000136dcc951d8c00000000000000000000000000000000000000000000000000000000000000000001',
714
+ ],
715
+ [
716
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
717
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
718
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
719
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
720
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
721
+ ],
722
+ ],
723
+ [
724
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
725
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
726
+ RatioState.UNDER,
727
+ 190,
728
+ 140,
729
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
730
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
731
+ ]
732
+ ],
733
+ [
734
+ [
735
+ Bundles.MainnetIds.CRVUSD_BOOST,
736
+ true,
737
+ [
738
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d42196350000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
739
+ ],
740
+ [
741
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
742
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
743
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
744
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
745
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
746
+ ],
747
+ ],
748
+ [
749
+ web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
750
+ web3Utils.toChecksumAddress('0xa920de414ea4ab66b97da1bfe9e6eca7d4219635'),
751
+ RatioState.OVER,
752
+ 160,
753
+ 200,
754
+ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
755
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
756
+ ]
757
+ ],
758
+ ];
759
+ examples.forEach(([expected, actual]) => {
760
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
761
+ expect(crvUSDEncode.leverageManagement(...actual)).to.eql(expected);
762
+ });
763
+ });
764
+ });
765
+ describe('payback()', () => {
766
+ const examples = [
767
+ [
768
+ [
769
+ Strategies.MainnetIds.CURVEUSD_PAYBACK,
770
+ false,
771
+ [
772
+ '0x0000000000000000000000007a2af22ba3276108cd331c8985ef9528e10a871a000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d421963500000000000000000000000000000000000000000000000002c68af0bb140000',
773
+ ],
774
+ [
775
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
776
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
777
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
778
+ '0x00000000000000000000000000000000000000000000043c33c1937564800000',
779
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e'
780
+ ],
781
+ ],
782
+ [
783
+ web3Utils.toChecksumAddress('0x7a2af22ba3276108cd331c8985ef9528e10a871a'),
784
+ web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
785
+ web3Utils.toChecksumAddress('0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280'),
786
+ '20000',
787
+ '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E',
788
+ web3Utils.toChecksumAddress('0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635'),
789
+ 20,
790
+ ]
791
+ ]
792
+ ];
793
+ examples.forEach(([expected, actual]) => {
794
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
795
+ expect(crvUSDEncode.payback(...actual)).to.eql(expected);
796
+ });
797
+ });
798
+ });
799
+ });
800
+ describe('When testing strategySubService.morphoBlueEncode', () => {
801
+ describe('leverageManagement()', () => {
802
+ const examples = [
803
+ [
804
+ [
805
+ Bundles.MainnetIds.MORPHO_BLUE_REPAY,
806
+ true,
807
+ [
808
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001',
809
+ ],
810
+ [
811
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
812
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
813
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
814
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
815
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
816
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
817
+ '0x000000000000000000000000000000000000000000000000136dcc951d8c0000',
818
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
819
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
820
+ ],
821
+ ],
822
+ [
823
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
824
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
825
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
826
+ web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
827
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
828
+ '945000000000000000',
829
+ RatioState.UNDER,
830
+ 140,
831
+ 120,
832
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
833
+ false,
834
+ ChainId.Ethereum,
835
+ ]
836
+ ],
837
+ [
838
+ [
839
+ Bundles.MainnetIds.MORPHO_BLUE_BOOST,
840
+ true,
841
+ [
842
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec410000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001bc16d674ec800000000000000000000000000000000000000000000000000000000000000000000'
843
+ ],
844
+ [
845
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
846
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
847
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
848
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
849
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
850
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
851
+ '0x00000000000000000000000000000000000000000000000016345785d8a00000',
852
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
853
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
854
+ ],
855
+ ],
856
+ [
857
+ '0xc54d7acf14de29e0e5527cabd7a576506870346a78a11a6762e2cca66322ec41',
858
+ web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
859
+ web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
860
+ web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'),
861
+ web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
862
+ '945000000000000000',
863
+ RatioState.OVER,
864
+ 160,
865
+ 200,
866
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
867
+ false,
868
+ ChainId.Ethereum,
869
+ ]
870
+ ],
871
+ ];
872
+ examples.forEach(([expected, actual]) => {
873
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
874
+ expect(morphoBlueEncode.leverageManagement(...actual)).to.eql(expected);
875
+ });
876
+ });
877
+ });
878
+ });
879
+ describe('When testing strategySubService.compoundV3L2Encode', () => {
880
+ describe('leverageManagement()', () => {
881
+ const examples = [
882
+ [
883
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
884
+ [
885
+ web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
886
+ web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
887
+ 160, 220, 180, 190,
888
+ true
889
+ ],
890
+ ],
891
+ [
892
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee000000',
893
+ [
894
+ web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'),
895
+ web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'),
896
+ 160, 220, 180, 110,
897
+ false
898
+ ],
899
+ ],
900
+ ];
901
+ examples.forEach(([expected, actual]) => {
902
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
903
+ expect(compoundV3L2Encode.leverageManagement(...actual)).to.eql(expected);
904
+ });
905
+ });
906
+ });
907
+ });
908
+ });