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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. package/.babelrc +3 -3
  2. package/.editorconfig +9 -9
  3. package/.env.dev +4 -4
  4. package/.eslintignore +6 -6
  5. package/.eslintrc.js +39 -39
  6. package/.mocharc.json +4 -4
  7. package/.nvmrc +1 -1
  8. package/README.md +46 -46
  9. package/cjs/abis/Erc20.json +223 -223
  10. package/cjs/abis/SubStorage.json +21 -21
  11. package/cjs/abis/UniMulticall.json +17 -17
  12. package/cjs/abis/index.d.ts +9 -9
  13. package/cjs/abis/index.js +30 -30
  14. package/cjs/abis/legacy_AaveV2Subscriptions.json +8 -8
  15. package/cjs/abis/legacy_AuthCheck.json +8 -8
  16. package/cjs/abis/legacy_CompoundV2Subscriptions.json +9 -9
  17. package/cjs/abis/legacy_MakerSubscriptions.json +9 -9
  18. package/cjs/automation/private/Automation.d.ts +12 -12
  19. package/cjs/automation/private/Automation.js +42 -42
  20. package/cjs/automation/private/LegacyAutomation.d.ts +25 -25
  21. package/cjs/automation/private/LegacyAutomation.js +118 -118
  22. package/cjs/automation/private/LegacyProtocol.d.ts +22 -22
  23. package/cjs/automation/private/LegacyProtocol.js +41 -41
  24. package/cjs/automation/private/LegacyProtocol.test.d.ts +1 -1
  25. package/cjs/automation/private/LegacyProtocol.test.js +25 -25
  26. package/cjs/automation/private/Protocol.d.ts +22 -22
  27. package/cjs/automation/private/Protocol.js +41 -41
  28. package/cjs/automation/private/Protocol.test.d.ts +1 -1
  29. package/cjs/automation/private/Protocol.test.js +25 -25
  30. package/cjs/automation/private/StrategiesAutomation.d.ts +35 -33
  31. package/cjs/automation/private/StrategiesAutomation.js +198 -181
  32. package/cjs/automation/private/StrategiesAutomation.test.d.ts +1 -1
  33. package/cjs/automation/private/StrategiesAutomation.test.js +696 -671
  34. package/cjs/automation/public/ArbitrumStrategies.d.ts +5 -5
  35. package/cjs/automation/public/ArbitrumStrategies.js +13 -13
  36. package/cjs/automation/public/BaseStrategies.d.ts +5 -5
  37. package/cjs/automation/public/BaseStrategies.js +13 -13
  38. package/cjs/automation/public/EthereumStrategies.d.ts +5 -5
  39. package/cjs/automation/public/EthereumStrategies.js +13 -13
  40. package/cjs/automation/public/OptimismStrategies.d.ts +5 -5
  41. package/cjs/automation/public/OptimismStrategies.js +13 -13
  42. package/cjs/automation/public/Strategies.test.d.ts +1 -1
  43. package/cjs/automation/public/Strategies.test.js +61 -61
  44. package/cjs/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
  45. package/cjs/automation/public/legacy/LegacyAaveAutomation.js +20 -20
  46. package/cjs/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
  47. package/cjs/automation/public/legacy/LegacyCompoundAutomation.js +20 -20
  48. package/cjs/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
  49. package/cjs/automation/public/legacy/LegacyMakerAutomation.js +20 -20
  50. package/cjs/configuration.d.ts +1 -1
  51. package/cjs/configuration.js +12 -12
  52. package/cjs/constants/index.d.ts +29 -28
  53. package/cjs/constants/index.js +905 -534
  54. package/cjs/index.d.ts +24 -23
  55. package/cjs/index.js +65 -65
  56. package/cjs/services/contractService.d.ts +12 -12
  57. package/cjs/services/contractService.js +54 -54
  58. package/cjs/services/ethereumService.d.ts +7 -7
  59. package/cjs/services/ethereumService.js +56 -49
  60. package/cjs/services/ethereumService.test.d.ts +1 -1
  61. package/cjs/services/ethereumService.test.js +245 -242
  62. package/cjs/services/strategiesService.d.ts +2 -2
  63. package/cjs/services/strategiesService.js +1173 -861
  64. package/cjs/services/strategiesService.test.d.ts +1 -1
  65. package/cjs/services/strategiesService.test.js +111 -110
  66. package/cjs/services/strategySubService.d.ts +129 -107
  67. package/cjs/services/strategySubService.js +414 -300
  68. package/cjs/services/strategySubService.test.d.ts +1 -1
  69. package/cjs/services/strategySubService.test.js +1812 -936
  70. package/cjs/services/subDataService.d.ts +527 -245
  71. package/cjs/services/subDataService.js +1219 -636
  72. package/cjs/services/subDataService.test.d.ts +1 -1
  73. package/cjs/services/subDataService.test.js +2427 -1282
  74. package/cjs/services/triggerService.d.ts +325 -226
  75. package/cjs/services/triggerService.js +616 -433
  76. package/cjs/services/triggerService.test.d.ts +1 -1
  77. package/cjs/services/triggerService.test.js +1317 -926
  78. package/cjs/services/utils.d.ts +30 -30
  79. package/cjs/services/utils.js +190 -182
  80. package/cjs/services/utils.test.d.ts +1 -1
  81. package/cjs/services/utils.test.js +299 -376
  82. package/cjs/types/contracts/generated/Erc20.d.ts +53 -53
  83. package/cjs/types/contracts/generated/Erc20.js +5 -5
  84. package/cjs/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
  85. package/cjs/types/contracts/generated/Legacy_AaveV2Subscriptions.js +5 -5
  86. package/cjs/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
  87. package/cjs/types/contracts/generated/Legacy_AuthCheck.js +5 -5
  88. package/cjs/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
  89. package/cjs/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +5 -5
  90. package/cjs/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
  91. package/cjs/types/contracts/generated/Legacy_MakerSubscriptions.js +5 -5
  92. package/cjs/types/contracts/generated/SubStorage.d.ts +114 -114
  93. package/cjs/types/contracts/generated/SubStorage.js +5 -5
  94. package/cjs/types/contracts/generated/UniMulticall.d.ts +55 -55
  95. package/cjs/types/contracts/generated/UniMulticall.js +5 -5
  96. package/cjs/types/contracts/generated/index.d.ts +7 -7
  97. package/cjs/types/contracts/generated/index.js +2 -2
  98. package/cjs/types/contracts/generated/types.d.ts +54 -54
  99. package/cjs/types/contracts/generated/types.js +2 -2
  100. package/cjs/types/enums.d.ts +302 -219
  101. package/cjs/types/enums.js +328 -245
  102. package/cjs/types/index.d.ts +306 -248
  103. package/cjs/types/index.js +2 -2
  104. package/esm/abis/Erc20.json +223 -223
  105. package/esm/abis/SubStorage.json +21 -21
  106. package/esm/abis/UniMulticall.json +17 -17
  107. package/esm/abis/index.d.ts +9 -9
  108. package/esm/abis/index.js +18 -18
  109. package/esm/abis/legacy_AaveV2Subscriptions.json +8 -8
  110. package/esm/abis/legacy_AuthCheck.json +8 -8
  111. package/esm/abis/legacy_CompoundV2Subscriptions.json +9 -9
  112. package/esm/abis/legacy_MakerSubscriptions.json +9 -9
  113. package/esm/automation/private/Automation.d.ts +12 -12
  114. package/esm/automation/private/Automation.js +39 -39
  115. package/esm/automation/private/LegacyAutomation.d.ts +25 -25
  116. package/esm/automation/private/LegacyAutomation.js +112 -112
  117. package/esm/automation/private/LegacyProtocol.d.ts +22 -22
  118. package/esm/automation/private/LegacyProtocol.js +38 -38
  119. package/esm/automation/private/LegacyProtocol.test.d.ts +1 -1
  120. package/esm/automation/private/LegacyProtocol.test.js +20 -20
  121. package/esm/automation/private/Protocol.d.ts +22 -22
  122. package/esm/automation/private/Protocol.js +38 -38
  123. package/esm/automation/private/Protocol.test.d.ts +1 -1
  124. package/esm/automation/private/Protocol.test.js +20 -20
  125. package/esm/automation/private/StrategiesAutomation.d.ts +35 -33
  126. package/esm/automation/private/StrategiesAutomation.js +192 -175
  127. package/esm/automation/private/StrategiesAutomation.test.d.ts +1 -1
  128. package/esm/automation/private/StrategiesAutomation.test.js +691 -666
  129. package/esm/automation/public/ArbitrumStrategies.d.ts +5 -5
  130. package/esm/automation/public/ArbitrumStrategies.js +7 -7
  131. package/esm/automation/public/BaseStrategies.d.ts +5 -5
  132. package/esm/automation/public/BaseStrategies.js +7 -7
  133. package/esm/automation/public/EthereumStrategies.d.ts +5 -5
  134. package/esm/automation/public/EthereumStrategies.js +7 -7
  135. package/esm/automation/public/OptimismStrategies.d.ts +5 -5
  136. package/esm/automation/public/OptimismStrategies.js +7 -7
  137. package/esm/automation/public/Strategies.test.d.ts +1 -1
  138. package/esm/automation/public/Strategies.test.js +56 -56
  139. package/esm/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
  140. package/esm/automation/public/legacy/LegacyAaveAutomation.js +14 -14
  141. package/esm/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
  142. package/esm/automation/public/legacy/LegacyCompoundAutomation.js +14 -14
  143. package/esm/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
  144. package/esm/automation/public/legacy/LegacyMakerAutomation.js +14 -14
  145. package/esm/configuration.d.ts +1 -1
  146. package/esm/configuration.js +7 -7
  147. package/esm/constants/index.d.ts +29 -28
  148. package/esm/constants/index.js +899 -528
  149. package/esm/index.d.ts +24 -23
  150. package/esm/index.js +23 -23
  151. package/esm/services/contractService.d.ts +12 -12
  152. package/esm/services/contractService.js +45 -45
  153. package/esm/services/ethereumService.d.ts +7 -7
  154. package/esm/services/ethereumService.js +48 -41
  155. package/esm/services/ethereumService.test.d.ts +1 -1
  156. package/esm/services/ethereumService.test.js +240 -237
  157. package/esm/services/strategiesService.d.ts +2 -2
  158. package/esm/services/strategiesService.js +1143 -831
  159. package/esm/services/strategiesService.test.d.ts +1 -1
  160. package/esm/services/strategiesService.test.js +109 -108
  161. package/esm/services/strategySubService.d.ts +129 -107
  162. package/esm/services/strategySubService.js +385 -271
  163. package/esm/services/strategySubService.test.d.ts +1 -1
  164. package/esm/services/strategySubService.test.js +1784 -908
  165. package/esm/services/subDataService.d.ts +527 -245
  166. package/esm/services/subDataService.js +1213 -630
  167. package/esm/services/subDataService.test.d.ts +1 -1
  168. package/esm/services/subDataService.test.js +2399 -1254
  169. package/esm/services/triggerService.d.ts +325 -226
  170. package/esm/services/triggerService.js +587 -404
  171. package/esm/services/triggerService.test.d.ts +1 -1
  172. package/esm/services/triggerService.test.js +1292 -901
  173. package/esm/services/utils.d.ts +30 -30
  174. package/esm/services/utils.js +139 -131
  175. package/esm/services/utils.test.d.ts +1 -1
  176. package/esm/services/utils.test.js +297 -348
  177. package/esm/types/contracts/generated/Erc20.d.ts +53 -53
  178. package/esm/types/contracts/generated/Erc20.js +4 -4
  179. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
  180. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +4 -4
  181. package/esm/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
  182. package/esm/types/contracts/generated/Legacy_AuthCheck.js +4 -4
  183. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
  184. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +4 -4
  185. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
  186. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +4 -4
  187. package/esm/types/contracts/generated/SubStorage.d.ts +114 -114
  188. package/esm/types/contracts/generated/SubStorage.js +4 -4
  189. package/esm/types/contracts/generated/UniMulticall.d.ts +55 -55
  190. package/esm/types/contracts/generated/UniMulticall.js +4 -4
  191. package/esm/types/contracts/generated/index.d.ts +7 -7
  192. package/esm/types/contracts/generated/index.js +1 -1
  193. package/esm/types/contracts/generated/types.d.ts +54 -54
  194. package/esm/types/contracts/generated/types.js +1 -1
  195. package/esm/types/enums.d.ts +302 -219
  196. package/esm/types/enums.js +325 -242
  197. package/esm/types/index.d.ts +306 -248
  198. package/esm/types/index.js +1 -1
  199. package/package.json +60 -61
  200. package/scripts/generateContractTypes.js +39 -39
  201. package/src/abis/Erc20.json +222 -222
  202. package/src/abis/SubStorage.json +21 -21
  203. package/src/abis/UniMulticall.json +17 -17
  204. package/src/abis/index.ts +28 -28
  205. package/src/abis/legacy_AaveV2Subscriptions.json +7 -7
  206. package/src/abis/legacy_AuthCheck.json +7 -7
  207. package/src/abis/legacy_CompoundV2Subscriptions.json +8 -8
  208. package/src/abis/legacy_MakerSubscriptions.json +8 -8
  209. package/src/automation/private/Automation.ts +44 -44
  210. package/src/automation/private/LegacyAutomation.ts +135 -135
  211. package/src/automation/private/LegacyProtocol.test.ts +23 -23
  212. package/src/automation/private/LegacyProtocol.ts +51 -51
  213. package/src/automation/private/Protocol.test.ts +23 -23
  214. package/src/automation/private/Protocol.ts +51 -51
  215. package/src/automation/private/StrategiesAutomation.test.ts +703 -663
  216. package/src/automation/private/StrategiesAutomation.ts +265 -242
  217. package/src/automation/public/ArbitrumStrategies.ts +10 -10
  218. package/src/automation/public/BaseStrategies.ts +10 -10
  219. package/src/automation/public/EthereumStrategies.ts +10 -10
  220. package/src/automation/public/OptimismStrategies.ts +10 -10
  221. package/src/automation/public/Strategies.test.ts +49 -49
  222. package/src/automation/public/legacy/LegacyAaveAutomation.ts +20 -20
  223. package/src/automation/public/legacy/LegacyCompoundAutomation.ts +20 -20
  224. package/src/automation/public/legacy/LegacyMakerAutomation.ts +20 -20
  225. package/src/configuration.ts +8 -8
  226. package/src/constants/index.ts +935 -563
  227. package/src/index.ts +41 -39
  228. package/src/services/contractService.ts +77 -77
  229. package/src/services/ethereumService.test.ts +260 -257
  230. package/src/services/ethereumService.ts +76 -69
  231. package/src/services/strategiesService.test.ts +106 -105
  232. package/src/services/strategiesService.ts +1473 -1111
  233. package/src/services/strategySubService.test.ts +2136 -1122
  234. package/src/services/strategySubService.ts +987 -617
  235. package/src/services/subDataService.test.ts +2630 -1387
  236. package/src/services/subDataService.ts +1631 -870
  237. package/src/services/triggerService.test.ts +1434 -1004
  238. package/src/services/triggerService.ts +819 -553
  239. package/src/services/utils.test.ts +371 -430
  240. package/src/services/utils.ts +173 -162
  241. package/src/types/enums.ts +322 -239
  242. package/src/types/index.ts +385 -312
  243. package/tsconfig.esm.json +8 -8
  244. package/tsconfig.json +22 -22
  245. package/umd/index.js +0 -34103
@@ -1,1254 +1,2399 @@
1
- import Dec from 'decimal.js';
2
- import { expect } from 'chai';
3
- import { getAssetInfo } from '@defisaver/tokens';
4
- import * as web3Utils from 'web3-utils';
5
- import { ChainId, OrderType, RatioState } from '../types/enums';
6
- import '../configuration';
7
- import { aaveV2LeverageManagementSubData, aaveV3LeverageManagementSubData, aaveV3QuotePriceSubData, cBondsRebondSubData, compoundV2LeverageManagementSubData, compoundV3LeverageManagementSubData, exchangeDcaSubData, exchangeLimitOrderSubData, liquityCloseSubData, liquityDebtInFrontRepaySubData, liquityDsrPaybackSubData, liquityDsrSupplySubData, liquityLeverageManagementSubData, liquityPaybackUsingChickenBondSubData, liquityRepayFromSavingsSubData, makerCloseSubData, makerLeverageManagementSubData, makerRepayFromSavingsSubData, morphoAaveV2LeverageManagementSubData, sparkLeverageManagementSubData, sparkQuotePriceSubData, crvUSDLeverageManagementSubData, compoundV3L2LeverageManagementSubData, morphoBlueLeverageManagementSubData, crvUSDPaybackSubData, aaveV3LeverageManagementOnPriceSubData, } from './subDataService';
8
- describe('Feature: subDataService.ts', () => {
9
- describe('When testing subDataService.makerRepayFromSavingsSubData', () => {
10
- describe('encode()', () => {
11
- const examples = [
12
- [
13
- [
14
- '0x000000000000000000000000000000000000000000000000000000000000007b', '0x00000000000000000000000000000000000000000000000010a741a462780000',
15
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
16
- ],
17
- [123, 120, ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e')]
18
- ],
19
- ];
20
- examples.forEach(([expected, actual]) => {
21
- it(`Given ${actual} should return expected value: ${expected}`, () => {
22
- expect(makerRepayFromSavingsSubData.encode(...actual)).to.eql(expected);
23
- });
24
- });
25
- });
26
- describe('decode()', () => {
27
- const examples = [
28
- [
29
- {
30
- vaultId: 123,
31
- daiAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
32
- mcdManagerAddr: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
33
- targetRatio: 120,
34
- },
35
- [
36
- '0x000000000000000000000000000000000000000000000000000000000000007b', '0x00000000000000000000000000000000000000000000000010a741a462780000',
37
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
38
- ],
39
- ],
40
- ];
41
- examples.forEach(([expected, actual]) => {
42
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
43
- expect(makerRepayFromSavingsSubData.decode(actual)).to.eql(expected);
44
- });
45
- });
46
- });
47
- });
48
- describe('When testing subDataService.liquityRepayFromSavingsSubData', () => {
49
- describe('decode()', () => {
50
- const examples = [
51
- [
52
- { targetRatio: 120 },
53
- [
54
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x00000000000000000000000000000000000000000000000010a741a462780000',
55
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
56
- ],
57
- ],
58
- ];
59
- examples.forEach(([expected, actual]) => {
60
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
61
- expect(liquityRepayFromSavingsSubData.decode(actual)).to.eql(expected);
62
- });
63
- });
64
- });
65
- });
66
- describe('When testing subDataService.makerCloseSubData', () => {
67
- describe('encode()', () => {
68
- const examples = [
69
- [
70
- [
71
- '0x0000000000000000000000000000000000000000000000000000000000000141', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
72
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
73
- ],
74
- [321, web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e')]
75
- ],
76
- [
77
- [
78
- '0x00000000000000000000000000000000000000000000000000000000000001a4', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
79
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002439d218133afab8f2b819b1066c7e434ad94e9e',
80
- ],
81
- [420, web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2439d218133AFaB8F2B819B1066c7E434Ad94E9e')]
82
- ],
83
- ];
84
- examples.forEach(([expected, actual]) => {
85
- it(`Given ${actual} should return expected value: ${expected}`, () => {
86
- expect(makerCloseSubData.encode(...actual)).to.eql(expected);
87
- });
88
- });
89
- });
90
- describe('decode()', () => {
91
- const examples = [
92
- [
93
- {
94
- vaultId: 321,
95
- closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
96
- },
97
- [
98
- '0x0000000000000000000000000000000000000000000000000000000000000141', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
99
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
100
- ],
101
- ],
102
- [
103
- {
104
- vaultId: 420,
105
- closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
106
- },
107
- [
108
- '0x00000000000000000000000000000000000000000000000000000000000001a4', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
109
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002439d218133afab8f2b819b1066c7e434ad94e9e',
110
- ],
111
- ],
112
- ];
113
- examples.forEach(([expected, actual]) => {
114
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
115
- expect(makerCloseSubData.decode(actual)).to.eql(expected);
116
- });
117
- });
118
- });
119
- });
120
- describe('When testing subDataService.makerLeverageManagementSubData', () => {
121
- describe('decode()', () => {
122
- const examples = [
123
- [
124
- { vaultId: 321, targetRatio: 200 },
125
- [
126
- '0x0000000000000000000000000000000000000000000000000000000000000141', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
127
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
128
- ],
129
- ],
130
- ];
131
- examples.forEach(([expected, actual]) => {
132
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
133
- expect(makerLeverageManagementSubData.decode(actual)).to.eql(expected);
134
- });
135
- });
136
- });
137
- });
138
- describe('When testing subDataService.liquityLeverageManagementSubData', () => {
139
- describe('decode()', () => {
140
- const examples = [
141
- [
142
- { targetRatio: 200 },
143
- [
144
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
145
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
146
- ],
147
- ],
148
- ];
149
- examples.forEach(([expected, actual]) => {
150
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
151
- expect(liquityLeverageManagementSubData.decode(actual)).to.eql(expected);
152
- });
153
- });
154
- });
155
- });
156
- describe('When testing subDataService.liquityCloseSubData', () => {
157
- describe('encode()', () => {
158
- const examples = [
159
- [
160
- [
161
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
162
- ],
163
- [web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address)]
164
- ],
165
- [
166
- [
167
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
168
- ],
169
- [web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address), ChainId.Ethereum]
170
- ],
171
- ];
172
- examples.forEach(([expected, actual]) => {
173
- it(`Given ${actual} should return expected value: ${expected}`, () => {
174
- expect(liquityCloseSubData.encode(...actual)).to.eql(expected);
175
- });
176
- });
177
- });
178
- describe('decode()', () => {
179
- const examples = [
180
- [
181
- {
182
- closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
183
- debtAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
184
- },
185
- [
186
- '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
187
- ],
188
- ],
189
- [
190
- {
191
- closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
192
- debtAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
193
- },
194
- [
195
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
196
- ],
197
- ],
198
- ];
199
- examples.forEach(([expected, actual]) => {
200
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
201
- expect(liquityCloseSubData.decode(actual)).to.eql(expected);
202
- });
203
- });
204
- });
205
- });
206
- describe('When testing subDataService.aaveV2LeverageManagementSubData', () => {
207
- describe('encode()', () => {
208
- const examples = [
209
- [
210
- [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],
211
- [160, 220, 180, 190, true]
212
- ],
213
- [
214
- [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],
215
- [160, 200, 180, 190, false]
216
- ],
217
- ];
218
- examples.forEach(([expected, actual]) => {
219
- it(`Given ${actual} should return expected value: ${expected}`, () => {
220
- expect(aaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
221
- });
222
- });
223
- });
224
- describe('decode()', () => {
225
- const examples = [
226
- [
227
- { targetRatio: 200 },
228
- ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
229
- ],
230
- [
231
- { targetRatio: 123 },
232
- ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
233
- ],
234
- ];
235
- examples.forEach(([expected, actual]) => {
236
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
237
- expect(aaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
238
- });
239
- });
240
- });
241
- });
242
- describe('When testing subDataService.aaveV3LeverageManagementSubData', () => {
243
- describe('decode()', () => {
244
- const examples = [
245
- [
246
- { targetRatio: 200 },
247
- ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
248
- ],
249
- [
250
- { targetRatio: 123 },
251
- ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
252
- ],
253
- ];
254
- examples.forEach(([expected, actual]) => {
255
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
256
- expect(aaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
257
- });
258
- });
259
- });
260
- });
261
- describe('When testing subDataService.aaveV3QuotePriceSubData', () => {
262
- describe('encode()', () => {
263
- const examples = [
264
- [
265
- [
266
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
267
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
268
- '0x0000000000000000000000000000000000000000000000000000000000000000',
269
- ],
270
- [
271
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
272
- 2,
273
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
274
- 4,
275
- ]
276
- ],
277
- [
278
- [
279
- '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
280
- '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
281
- '0x0000000000000000000000000000000000000000000000000000000000000000',
282
- ],
283
- [
284
- web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
285
- 6,
286
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
287
- 2,
288
- ]
289
- ],
290
- ];
291
- examples.forEach(([expected, actual]) => {
292
- it(`Given ${actual} should return expected value: ${expected}`, () => {
293
- expect(aaveV3QuotePriceSubData.encode(...actual)).to.eql(expected);
294
- });
295
- });
296
- });
297
- describe('decode()', () => {
298
- const examples = [
299
- [
300
- {
301
- collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
302
- collAssetId: 2,
303
- debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
304
- debtAssetId: 4,
305
- },
306
- [
307
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
308
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
309
- '0x0000000000000000000000000000000000000000000000000000000000000000',
310
- ],
311
- ],
312
- [
313
- {
314
- collAsset: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
315
- collAssetId: 6,
316
- debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
317
- debtAssetId: 2,
318
- },
319
- [
320
- '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
321
- '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
322
- '0x0000000000000000000000000000000000000000000000000000000000000000',
323
- ],
324
- ],
325
- ];
326
- examples.forEach(([expected, actual]) => {
327
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
328
- expect(aaveV3QuotePriceSubData.decode(actual)).to.eql(expected);
329
- });
330
- });
331
- });
332
- });
333
- describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
334
- describe('encode()', () => {
335
- const examples = [
336
- [
337
- [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],
338
- [160, 220, 180, 190, true]
339
- ],
340
- [
341
- [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],
342
- [160, 200, 180, 190, false]
343
- ],
344
- ];
345
- examples.forEach(([expected, actual]) => {
346
- it(`Given ${actual} should return expected value: ${expected}`, () => {
347
- expect(compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
348
- });
349
- });
350
- });
351
- describe('decode()', () => {
352
- const examples = [
353
- [
354
- { targetRatio: 200 },
355
- ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
356
- ],
357
- [
358
- { targetRatio: 123 },
359
- ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
360
- ],
361
- ];
362
- examples.forEach(([expected, actual]) => {
363
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
364
- expect(compoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
365
- });
366
- });
367
- });
368
- });
369
- describe('When testing subDataService.compoundV3LeverageManagementSubData', () => {
370
- describe('encode()', () => {
371
- const examples = [
372
- [
373
- [
374
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
375
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
376
- new Dec(160).mul(1e16).toString(),
377
- new Dec(220).mul(1e16).toString(),
378
- new Dec(180).mul(1e16).toString(),
379
- new Dec(190).mul(1e16).toString(),
380
- true, false,
381
- ],
382
- [
383
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
384
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
385
- 160, 220, 180, 190,
386
- true, false,
387
- ]
388
- ],
389
- [
390
- [
391
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
392
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
393
- new Dec(160).mul(1e16).toString(),
394
- new Dec(210).mul(1e16).toString(),
395
- new Dec(180).mul(1e16).toString(),
396
- new Dec(190).mul(1e16).toString(),
397
- false, true,
398
- ],
399
- [
400
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
401
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
402
- 160, 210, 180, 190,
403
- false, true,
404
- ]
405
- ],
406
- ];
407
- examples.forEach(([expected, actual]) => {
408
- it(`Given ${actual} should return expected value: ${expected}`, () => {
409
- expect(compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
410
- });
411
- });
412
- });
413
- describe('decode()', () => {
414
- const examples = [
415
- [
416
- { targetRatio: 123 },
417
- [
418
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
419
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
420
- ],
421
- ],
422
- [
423
- { targetRatio: 200 },
424
- [
425
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
426
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
427
- ],
428
- ],
429
- ];
430
- examples.forEach(([expected, actual]) => {
431
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
432
- expect(compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
433
- });
434
- });
435
- });
436
- });
437
- describe('When testing subDataService.morphoAaveV2LeverageManagementSubData', () => {
438
- describe('encode()', () => {
439
- const examples = [
440
- [
441
- [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],
442
- [160, 220, 180, 190, true]
443
- ],
444
- [
445
- [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],
446
- [160, 200, 180, 190, false]
447
- ],
448
- ];
449
- examples.forEach(([expected, actual]) => {
450
- it(`Given ${actual} should return expected value: ${expected}`, () => {
451
- expect(morphoAaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
452
- });
453
- });
454
- });
455
- describe('decode()', () => {
456
- const examples = [
457
- [
458
- { targetRatio: 200 },
459
- ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
460
- ],
461
- [
462
- { targetRatio: 123 },
463
- ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
464
- ],
465
- ];
466
- examples.forEach(([expected, actual]) => {
467
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
468
- expect(morphoAaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
469
- });
470
- });
471
- });
472
- });
473
- describe('When testing subDataService.cBondsRebondSubData', () => {
474
- describe('encode()', () => {
475
- const examples = [
476
- [
477
- ['0x00000000000000000000000000000000000000000000000000000000000000c8'],
478
- [200]
479
- ],
480
- [
481
- ['0x000000000000000000000000000000000000000000000000000000000000a119'],
482
- [41241]
483
- ],
484
- ];
485
- examples.forEach(([expected, actual]) => {
486
- it(`Given ${actual} should return expected value: ${expected}`, () => {
487
- expect(cBondsRebondSubData.encode(...actual)).to.eql(expected);
488
- });
489
- });
490
- });
491
- describe('decode()', () => {
492
- const examples = [
493
- [
494
- { bondId: '200' },
495
- ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x00000000000000000000000000000000000000000000000000000000000000c8'],
496
- ],
497
- [
498
- { bondId: '41241' },
499
- ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000000000000000000000000000000000000000a119'],
500
- ],
501
- ];
502
- examples.forEach(([expected, actual]) => {
503
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
504
- expect(cBondsRebondSubData.decode(actual)).to.eql(expected);
505
- });
506
- });
507
- });
508
- });
509
- describe('When testing subDataService.liquityPaybackUsingChickenBondSubData', () => {
510
- describe('encode()', () => {
511
- const examples = [
512
- [
513
- [
514
- '0x0000000000000000000000000000000000000000000000000000000000001076', '0x0000000000000000000000000000000000000000000000000000000000000000',
515
- '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
516
- ],
517
- ['4214', 0, ChainId.Ethereum]
518
- ],
519
- [
520
- [
521
- '0x00000000000000000000000000000000000000000000000000000000000002b8', '0x0000000000000000000000000000000000000000000000000000000000000001',
522
- '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
523
- ],
524
- ['696', 1]
525
- ],
526
- ];
527
- examples.forEach(([expected, actual]) => {
528
- it(`Given ${actual} should return expected value: ${expected}`, () => {
529
- expect(liquityPaybackUsingChickenBondSubData.encode(...actual)).to.eql(expected);
530
- });
531
- });
532
- });
533
- describe('decode()', () => {
534
- const examples = [
535
- [
536
- { sourceId: '4214', sourceType: '0' },
537
- [
538
- '0x0000000000000000000000000000000000000000000000000000000000001076', '0x0000000000000000000000000000000000000000000000000000000000000000',
539
- '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
540
- ],
541
- ],
542
- [
543
- { sourceId: '696', sourceType: '1' },
544
- [
545
- '0x00000000000000000000000000000000000000000000000000000000000002b8', '0x0000000000000000000000000000000000000000000000000000000000000001',
546
- '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
547
- ],
548
- ],
549
- ];
550
- examples.forEach(([expected, actual]) => {
551
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
552
- expect(liquityPaybackUsingChickenBondSubData.decode(actual)).to.eql(expected);
553
- });
554
- });
555
- });
556
- });
557
- describe('When testing subDataService.exchangeDcaSubData', () => {
558
- describe('encode()', () => {
559
- const examples = [
560
- [
561
- [
562
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
563
- '0x0000000000000000000000000000000000000000000000000000000000000853', '0x0000000000000000000000000000000000000000000000000000000000231860'
564
- ],
565
- [
566
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
567
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
568
- '2131',
569
- 2300000,
570
- ]
571
- ],
572
- [
573
- [
574
- '0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f', '0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4',
575
- '0x00000000000000000000000000000000000000000000000000000000003eddd7', '0x0000000000000000000000000000000000000000000000000000000008f57500'
576
- ],
577
- [
578
- web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
579
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
580
- '4120023',
581
- 150304000,
582
- ]
583
- ],
584
- ];
585
- examples.forEach(([expected, actual]) => {
586
- it(`Given ${actual} should return expected value: ${expected}`, () => {
587
- expect(exchangeDcaSubData.encode(...actual)).to.eql(expected);
588
- });
589
- });
590
- });
591
- describe('decode()', () => {
592
- const examples = [
593
- [
594
- {
595
- fromToken: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
596
- toToken: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
597
- amount: '0.000000000000002131',
598
- interval: '2300000',
599
- },
600
- [
601
- [
602
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
603
- '0x0000000000000000000000000000000000000000000000000000000000000853', '0x0000000000000000000000000000000000000000000000000000000000231860'
604
- ],
605
- ChainId.Ethereum
606
- ],
607
- ],
608
- [
609
- {
610
- fromToken: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
611
- toToken: web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
612
- amount: '0.04120023',
613
- interval: '150304000',
614
- },
615
- [
616
- [
617
- '0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f', '0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4',
618
- '0x00000000000000000000000000000000000000000000000000000000003eddd7', '0x0000000000000000000000000000000000000000000000000000000008f57500'
619
- ],
620
- ChainId.Arbitrum
621
- ]
622
- ],
623
- ];
624
- examples.forEach(([expected, actual]) => {
625
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
626
- expect(exchangeDcaSubData.decode(...actual)).to.eql(expected);
627
- });
628
- });
629
- });
630
- });
631
- describe('When testing subDataService.exchangeLimitOrderSubData', () => {
632
- describe('encode()', () => {
633
- const examples = [
634
- [
635
- [
636
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
637
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
638
- '2131',
639
- '0.53123',
640
- '1696590921159',
641
- `${OrderType.STOP_LOSS}`
642
- ],
643
- [
644
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
645
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
646
- '2131',
647
- '0.53123',
648
- 1696590921159,
649
- OrderType.STOP_LOSS
650
- ]
651
- ],
652
- [
653
- [
654
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
655
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
656
- '2131',
657
- '0.43123',
658
- '1646590921159',
659
- `${OrderType.TAKE_PROFIT}`
660
- ],
661
- [
662
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
663
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
664
- '2131',
665
- '0.43123',
666
- 1646590921159,
667
- OrderType.TAKE_PROFIT
668
- ]
669
- ],
670
- ];
671
- examples.forEach(([expected, actual]) => {
672
- it(`Given ${actual} should return expected value: ${expected}`, () => {
673
- expect(exchangeLimitOrderSubData.encode(...actual)).to.eql(expected);
674
- });
675
- });
676
- });
677
- describe('decode()', () => {
678
- const examples = [
679
- [
680
- {
681
- fromToken: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
682
- toToken: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
683
- amount: '0.000000000000002131',
684
- },
685
- [
686
- [
687
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
688
- '0x0000000000000000000000000000000000000000000000000000000000000853', '0x0000000000000000000000000000000000000000000000000000000000231860'
689
- ],
690
- ChainId.Ethereum
691
- ],
692
- ],
693
- [
694
- {
695
- fromToken: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
696
- toToken: web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
697
- amount: '0.04120023',
698
- },
699
- [
700
- [
701
- '0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f', '0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4',
702
- '0x00000000000000000000000000000000000000000000000000000000003eddd7', '0x0000000000000000000000000000000000000000000000000000000008f57500'
703
- ],
704
- ChainId.Arbitrum
705
- ]
706
- ],
707
- ];
708
- examples.forEach(([expected, actual]) => {
709
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
710
- expect(exchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
711
- });
712
- });
713
- });
714
- });
715
- describe('When testing subDataService.sparkLeverageManagementSubData', () => {
716
- describe('decode()', () => {
717
- const examples = [
718
- [
719
- { targetRatio: 200 },
720
- ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
721
- ],
722
- [
723
- { targetRatio: 123 },
724
- ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
725
- ],
726
- ];
727
- examples.forEach(([expected, actual]) => {
728
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
729
- expect(sparkLeverageManagementSubData.decode(actual)).to.eql(expected);
730
- });
731
- });
732
- });
733
- });
734
- describe('When testing subDataService.sparkQuotePriceSubData', () => {
735
- describe('encode()', () => {
736
- const examples = [
737
- [
738
- [
739
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
740
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
741
- '0x0000000000000000000000000000000000000000000000000000000000000000',
742
- ],
743
- [
744
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
745
- 2,
746
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
747
- 4,
748
- ]
749
- ],
750
- [
751
- [
752
- '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
753
- '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
754
- '0x0000000000000000000000000000000000000000000000000000000000000000',
755
- ],
756
- [
757
- web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
758
- 6,
759
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
760
- 2,
761
- ]
762
- ],
763
- ];
764
- examples.forEach(([expected, actual]) => {
765
- it(`Given ${actual} should return expected value: ${expected}`, () => {
766
- expect(sparkQuotePriceSubData.encode(...actual)).to.eql(expected);
767
- });
768
- });
769
- });
770
- describe('decode()', () => {
771
- const examples = [
772
- [
773
- {
774
- collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
775
- collAssetId: 2,
776
- debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
777
- debtAssetId: 4,
778
- },
779
- [
780
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
781
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
782
- '0x0000000000000000000000000000000000000000000000000000000000000000',
783
- ],
784
- ],
785
- [
786
- {
787
- collAsset: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
788
- collAssetId: 6,
789
- debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
790
- debtAssetId: 2,
791
- },
792
- [
793
- '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
794
- '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
795
- '0x0000000000000000000000000000000000000000000000000000000000000000',
796
- ],
797
- ],
798
- ];
799
- examples.forEach(([expected, actual]) => {
800
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
801
- expect(sparkQuotePriceSubData.decode(actual)).to.eql(expected);
802
- });
803
- });
804
- });
805
- });
806
- describe('When testing subDataService.liquityDsrPaybackSubData', () => {
807
- describe('encode()', () => {
808
- const examples = [
809
- [
810
- [
811
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
812
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
813
- ],
814
- [123]
815
- ],
816
- [
817
- [
818
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
819
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
820
- ],
821
- [420]
822
- ],
823
- ];
824
- examples.forEach(([expected, actual]) => {
825
- it(`Given ${actual} should return expected value: ${expected}`, () => {
826
- expect(liquityDsrPaybackSubData.encode(...actual)).to.eql(expected);
827
- });
828
- });
829
- });
830
- describe('decode()', () => {
831
- const examples = [
832
- [
833
- {
834
- targetRatio: 123,
835
- },
836
- [
837
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
838
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
839
- ],
840
- ],
841
- [
842
- {
843
- targetRatio: 420,
844
- },
845
- [
846
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
847
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
848
- ],
849
- ],
850
- ];
851
- examples.forEach(([expected, actual]) => {
852
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
853
- expect(liquityDsrPaybackSubData.decode(actual)).to.eql(expected);
854
- });
855
- });
856
- });
857
- });
858
- describe('When testing subDataService.liquityDsrSupplySubData', () => {
859
- describe('encode()', () => {
860
- const examples = [
861
- [
862
- [
863
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
864
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
865
- ],
866
- [320]
867
- ],
868
- [
869
- [
870
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001eab7f4a799d0000',
871
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
872
- ],
873
- [221]
874
- ],
875
- ];
876
- examples.forEach(([expected, actual]) => {
877
- it(`Given ${actual} should return expected value: ${expected}`, () => {
878
- expect(liquityDsrSupplySubData.encode(...actual)).to.eql(expected);
879
- });
880
- });
881
- });
882
- describe('decode()', () => {
883
- const examples = [
884
- [
885
- {
886
- targetRatio: 320,
887
- },
888
- [
889
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
890
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
891
- ],
892
- ],
893
- [
894
- {
895
- targetRatio: 221,
896
- },
897
- [
898
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001eab7f4a799d0000',
899
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
900
- ],
901
- ],
902
- ];
903
- examples.forEach(([expected, actual]) => {
904
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
905
- expect(liquityDsrSupplySubData.decode(actual)).to.eql(expected);
906
- });
907
- });
908
- });
909
- });
910
- describe('When testing subDataService.liquityDebtInFrontRepaySubData', () => {
911
- describe('encode()', () => {
912
- const examples = [
913
- [
914
- [
915
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
916
- '0x000000000000000000000000000000000000000000000000016345785d8a0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
917
- '0x0000000000000000000000000000000000000000000000000000000000000000',
918
- ],
919
- [10]
920
- ],
921
- [
922
- [
923
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
924
- '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
925
- '0x0000000000000000000000000000000000000000000000000000000000000000',
926
- ],
927
- [45]
928
- ],
929
- ];
930
- examples.forEach(([expected, actual]) => {
931
- it(`Given ${actual} should return expected value: ${expected}`, () => {
932
- expect(liquityDebtInFrontRepaySubData.encode(...actual)).to.eql(expected);
933
- });
934
- });
935
- });
936
- describe('decode()', () => {
937
- const examples = [
938
- [
939
- {
940
- targetRatioIncrease: 10,
941
- },
942
- [
943
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
944
- '0x000000000000000000000000000000000000000000000000016345785d8a0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
945
- '0x0000000000000000000000000000000000000000000000000000000000000000',
946
- ],
947
- ],
948
- [
949
- {
950
- targetRatioIncrease: 45,
951
- },
952
- [
953
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
954
- '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
955
- '0x0000000000000000000000000000000000000000000000000000000000000000',
956
- ],
957
- ],
958
- ];
959
- examples.forEach(([expected, actual]) => {
960
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
961
- expect(liquityDebtInFrontRepaySubData.decode(actual)).to.eql(expected);
962
- });
963
- });
964
- });
965
- });
966
- describe('When testing subDataService.crvUSDLeverageManagementSubData', () => {
967
- describe('encode()', () => {
968
- const examples = [
969
- [
970
- [
971
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
972
- '0x0000000000000000000000000000000000000000000000000000000000000001',
973
- '0x00000000000000000000000000000000000000000000000010a741a462780000',
974
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
975
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
976
- ],
977
- ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', RatioState.UNDER, 120, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E'],
978
- ],
979
- [
980
- [
981
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
982
- '0x0000000000000000000000000000000000000000000000000000000000000000',
983
- '0x00000000000000000000000000000000000000000000000018fae27693b40000',
984
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
985
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
986
- ],
987
- ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', RatioState.OVER, 180, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E']
988
- ],
989
- ];
990
- examples.forEach(([expected, actual]) => {
991
- it(`Given ${actual} should return expected value: ${expected}`, () => {
992
- expect(crvUSDLeverageManagementSubData.encode(...actual)).to.eql(expected);
993
- });
994
- });
995
- });
996
- describe('decode()', () => {
997
- const examples = [
998
- [
999
- {
1000
- controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1001
- targetRatio: 120,
1002
- },
1003
- ['0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635', '0x0000000000000000000000000000000000000000000000000000000000000001', '0x00000000000000000000000000000000000000000000000010a741a462780000', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',],
1004
- ],
1005
- [
1006
- {
1007
- controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1008
- targetRatio: 180,
1009
- },
1010
- ['0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x00000000000000000000000000000000000000000000000018fae27693b40000', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',],
1011
- ],
1012
- ];
1013
- examples.forEach(([expected, actual]) => {
1014
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1015
- expect(crvUSDLeverageManagementSubData.decode(actual)).to.eql(expected);
1016
- });
1017
- });
1018
- });
1019
- });
1020
- describe('When testing subDataService.crvUSDPaybackSubData', () => {
1021
- describe('encode()', () => {
1022
- const examples = [
1023
- [
1024
- [
1025
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1026
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1027
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1028
- '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1029
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1030
- ],
1031
- ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280', '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280', '20000', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E'],
1032
- ]
1033
- ];
1034
- examples.forEach(([expected, actual]) => {
1035
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1036
- expect(crvUSDPaybackSubData.encode(...actual)).to.eql(expected);
1037
- });
1038
- });
1039
- });
1040
- describe('decode()', () => {
1041
- const examples = [
1042
- [
1043
- {
1044
- controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1045
- addressToPullTokensFrom: '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280',
1046
- positionOwner: '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280',
1047
- paybackAmount: '20000'
1048
- },
1049
- [
1050
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1051
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1052
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1053
- '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1054
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1055
- ]
1056
- ]
1057
- ];
1058
- examples.forEach(([expected, actual]) => {
1059
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1060
- expect(crvUSDPaybackSubData.decode(actual)).to.eql(expected);
1061
- });
1062
- });
1063
- });
1064
- });
1065
- describe('When testing subDataService.compoundV3L2LeverageManagementSubData', () => {
1066
- describe('encode()', () => {
1067
- const examples = [
1068
- [
1069
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
1070
- [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 190, true]
1071
- ],
1072
- [
1073
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee000000',
1074
- [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 110, false]
1075
- ],
1076
- ];
1077
- examples.forEach(([expected, actual]) => {
1078
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1079
- expect(compoundV3L2LeverageManagementSubData.encode(...actual)).to.eql(expected);
1080
- });
1081
- });
1082
- });
1083
- describe('decode()', () => {
1084
- const examples = [
1085
- [
1086
- { targetRatio: 200 },
1087
- [
1088
- '0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000213d212133AFaB8F2B829B1066c7E43cAd94E2c',
1089
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1090
- ],
1091
- ],
1092
- [
1093
- { targetRatio: 123 },
1094
- [
1095
- '0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000413d212133AFaB8F2B829B1066c7E43cAd94E2c',
1096
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
1097
- ],
1098
- ],
1099
- ];
1100
- examples.forEach(([expected, actual]) => {
1101
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1102
- expect(compoundV3L2LeverageManagementSubData.decode(actual)).to.eql(expected);
1103
- });
1104
- });
1105
- });
1106
- });
1107
- describe('When testing subDataService.morphoBlueLeverageManagementSubData', () => {
1108
- describe('encode()', () => {
1109
- const examples = [
1110
- [
1111
- [
1112
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1113
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1114
- '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1115
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1116
- '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1117
- '0x0000000000000000000000000000000000000000000000000000000000000001',
1118
- '0x00000000000000000000000000000000000000000000000010a741a462780000',
1119
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1120
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1121
- ],
1122
- [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '945000000000000000', RatioState.UNDER, 120, web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), false]
1123
- ],
1124
- [
1125
- [
1126
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1127
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1128
- '0x00000000000000000000000048f7e36eb6b826b2df4b2e630b62cd25e89e40e2',
1129
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1130
- '0x0000000000000000000000000000000000000000000000000bef55718ad60000',
1131
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1132
- '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1133
- '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c',
1134
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1135
- ],
1136
- [web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '860000000000000000', RatioState.OVER, 200, web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), false]
1137
- ],
1138
- ];
1139
- examples.forEach(([expected, actual]) => {
1140
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1141
- expect(morphoBlueLeverageManagementSubData.encode(...actual)).to.eql(expected);
1142
- });
1143
- });
1144
- });
1145
- describe('decode()', () => {
1146
- const examples = [
1147
- [
1148
- {
1149
- 'collToken': '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1150
- 'irm': '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1151
- 'lltv': '945000000000000000',
1152
- 'loanToken': '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1153
- 'oracle': '0x2a01EB9496094dA03c4E364Def50f5aD1280AD72',
1154
- 'targetRatio': 120,
1155
- 'user': '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
1156
- },
1157
- [
1158
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1159
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1160
- '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1161
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1162
- '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1163
- '0x0000000000000000000000000000000000000000000000000000000000000001',
1164
- '0x00000000000000000000000000000000000000000000000010a741a462780000',
1165
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1166
- ],
1167
- ],
1168
- [
1169
- {
1170
- 'collToken': '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1171
- 'irm': '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1172
- 'lltv': '860000000000000000',
1173
- 'loanToken': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
1174
- 'oracle': '0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2',
1175
- 'targetRatio': 200,
1176
- 'user': '0x0043d218133aFaB8F2b829B106633E434aD94e2C',
1177
- },
1178
- [
1179
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1180
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1181
- '0x00000000000000000000000048f7e36eb6b826b2df4b2e630b62cd25e89e40e2',
1182
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1183
- '0x0000000000000000000000000000000000000000000000000bef55718ad60000',
1184
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1185
- '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1186
- '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c',
1187
- ],
1188
- ],
1189
- ];
1190
- examples.forEach(([expected, actual]) => {
1191
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1192
- expect(morphoBlueLeverageManagementSubData.decode(actual)).to.eql(expected);
1193
- });
1194
- });
1195
- });
1196
- });
1197
- describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
1198
- describe('encode()', () => {
1199
- const examples = [
1200
- [
1201
- [
1202
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1203
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1204
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1205
- '0x0000000000000000000000000000000000000000000000000000000000000004',
1206
- '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
1207
- '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1208
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1209
- ],
1210
- [
1211
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1212
- 0,
1213
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1214
- 4,
1215
- web3Utils.toChecksumAddress('0x2f39d218133afab8f2b819b1066c7e434ad94e9e'),
1216
- 200,
1217
- ]
1218
- ],
1219
- ];
1220
- examples.forEach(([expected, actual]) => {
1221
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1222
- expect(aaveV3LeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
1223
- });
1224
- });
1225
- });
1226
- describe('decode()', () => {
1227
- const examples = [
1228
- [
1229
- {
1230
- collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1231
- collAssetId: 0,
1232
- debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1233
- debtAssetId: 4,
1234
- marketAddr: web3Utils.toChecksumAddress('0x2f39d218133afab8f2b819b1066c7e434ad94e9e'),
1235
- targetRatio: 200,
1236
- },
1237
- [
1238
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1239
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1240
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1241
- '0x0000000000000000000000000000000000000000000000000000000000000004',
1242
- '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
1243
- '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1244
- ],
1245
- ],
1246
- ];
1247
- examples.forEach(([expected, actual]) => {
1248
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1249
- expect(aaveV3LeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
1250
- });
1251
- });
1252
- });
1253
- });
1254
- });
1
+ import Dec from 'decimal.js';
2
+ import { expect } from 'chai';
3
+ import { getAssetInfo } from '@defisaver/tokens';
4
+ import * as web3Utils from 'web3-utils';
5
+ import { MAXUINT } from '@defisaver/tokens';
6
+ import { ChainId, CloseStrategyType, OrderType, RatioState } from '../types/enums';
7
+ import '../configuration';
8
+ import * as subDataService from './subDataService';
9
+ describe('Feature: subDataService.ts', () => {
10
+ describe('When testing subDataService.makerRepayFromSavingsSubData', () => {
11
+ describe('encode()', () => {
12
+ const examples = [
13
+ [
14
+ [
15
+ '0x000000000000000000000000000000000000000000000000000000000000007b', '0x00000000000000000000000000000000000000000000000010a741a462780000',
16
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
17
+ ],
18
+ [123, 120, ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e')]
19
+ ],
20
+ ];
21
+ examples.forEach(([expected, actual]) => {
22
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
23
+ expect(subDataService.makerRepayFromSavingsSubData.encode(...actual)).to.eql(expected);
24
+ });
25
+ });
26
+ });
27
+ describe('decode()', () => {
28
+ const examples = [
29
+ [
30
+ {
31
+ vaultId: 123,
32
+ daiAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
33
+ mcdManagerAddr: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
34
+ targetRatio: 120,
35
+ },
36
+ [
37
+ '0x000000000000000000000000000000000000000000000000000000000000007b', '0x00000000000000000000000000000000000000000000000010a741a462780000',
38
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
39
+ ],
40
+ ],
41
+ ];
42
+ examples.forEach(([expected, actual]) => {
43
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
44
+ expect(subDataService.makerRepayFromSavingsSubData.decode(actual)).to.eql(expected);
45
+ });
46
+ });
47
+ });
48
+ });
49
+ describe('When testing subDataService.liquityRepayFromSavingsSubData', () => {
50
+ describe('decode()', () => {
51
+ const examples = [
52
+ [
53
+ { targetRatio: 120 },
54
+ [
55
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x00000000000000000000000000000000000000000000000010a741a462780000',
56
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
57
+ ],
58
+ ],
59
+ ];
60
+ examples.forEach(([expected, actual]) => {
61
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
62
+ expect(subDataService.liquityRepayFromSavingsSubData.decode(actual)).to.eql(expected);
63
+ });
64
+ });
65
+ });
66
+ });
67
+ describe('When testing subDataService.makerCloseSubData', () => {
68
+ describe('encode()', () => {
69
+ const examples = [
70
+ [
71
+ [
72
+ '0x0000000000000000000000000000000000000000000000000000000000000141', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
73
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
74
+ ],
75
+ [321, web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e')]
76
+ ],
77
+ [
78
+ [
79
+ '0x00000000000000000000000000000000000000000000000000000000000001a4', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
80
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002439d218133afab8f2b819b1066c7e434ad94e9e',
81
+ ],
82
+ [420, web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2439d218133AFaB8F2B819B1066c7E434Ad94E9e')]
83
+ ],
84
+ ];
85
+ examples.forEach(([expected, actual]) => {
86
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
87
+ expect(subDataService.makerCloseSubData.encode(...actual)).to.eql(expected);
88
+ });
89
+ });
90
+ });
91
+ describe('decode()', () => {
92
+ const examples = [
93
+ [
94
+ {
95
+ vaultId: 321,
96
+ closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
97
+ },
98
+ [
99
+ '0x0000000000000000000000000000000000000000000000000000000000000141', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
100
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
101
+ ],
102
+ ],
103
+ [
104
+ {
105
+ vaultId: 420,
106
+ closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
107
+ },
108
+ [
109
+ '0x00000000000000000000000000000000000000000000000000000000000001a4', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
110
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002439d218133afab8f2b819b1066c7e434ad94e9e',
111
+ ],
112
+ ],
113
+ ];
114
+ examples.forEach(([expected, actual]) => {
115
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
116
+ expect(subDataService.makerCloseSubData.decode(actual)).to.eql(expected);
117
+ });
118
+ });
119
+ });
120
+ });
121
+ describe('When testing subDataService.makerLeverageManagementSubData', () => {
122
+ describe('decode()', () => {
123
+ const examples = [
124
+ [
125
+ { vaultId: 321, targetRatio: 200 },
126
+ [
127
+ '0x0000000000000000000000000000000000000000000000000000000000000141', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
128
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
129
+ ],
130
+ ],
131
+ ];
132
+ examples.forEach(([expected, actual]) => {
133
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
134
+ expect(subDataService.makerLeverageManagementSubData.decode(actual)).to.eql(expected);
135
+ });
136
+ });
137
+ });
138
+ });
139
+ describe('When testing subDataService.makerLeverageManagementWithoutSubProxy', () => {
140
+ describe('encode()', () => {
141
+ const examples = [
142
+ [
143
+ [
144
+ '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
145
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
146
+ ],
147
+ [222, 180], // Uses default DAI address
148
+ ],
149
+ [
150
+ [
151
+ '0x000000000000000000000000000000000000000000000000000000000000014d', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
152
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
153
+ ],
154
+ [333, 200, web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address)], // Custom address
155
+ ],
156
+ ];
157
+ examples.forEach(([expected, actual]) => {
158
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
159
+ expect(subDataService.makerLeverageManagementWithoutSubProxy.encode(...actual)).to.eql(expected);
160
+ });
161
+ });
162
+ });
163
+ describe('decode()', () => {
164
+ const examples = [
165
+ [
166
+ {
167
+ vaultId: 222,
168
+ targetRatio: 180,
169
+ daiAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
170
+ },
171
+ [
172
+ '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
173
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
174
+ ],
175
+ ],
176
+ [
177
+ {
178
+ vaultId: 333,
179
+ targetRatio: 200,
180
+ daiAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
181
+ },
182
+ [
183
+ '0x000000000000000000000000000000000000000000000000000000000000014d', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
184
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
185
+ ],
186
+ ],
187
+ ];
188
+ examples.forEach(([expected, actual]) => {
189
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
190
+ expect(subDataService.makerLeverageManagementWithoutSubProxy.decode(actual)).to.eql(expected);
191
+ });
192
+ });
193
+ });
194
+ });
195
+ describe('When testing subDataService.liquityLeverageManagementSubData', () => {
196
+ describe('decode()', () => {
197
+ const examples = [
198
+ [
199
+ { targetRatio: 200 },
200
+ [
201
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
202
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
203
+ ],
204
+ ],
205
+ ];
206
+ examples.forEach(([expected, actual]) => {
207
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
208
+ expect(subDataService.liquityLeverageManagementSubData.decode(actual)).to.eql(expected);
209
+ });
210
+ });
211
+ });
212
+ });
213
+ describe('When testing subDataService.liquityCloseSubData', () => {
214
+ describe('encode()', () => {
215
+ const examples = [
216
+ [
217
+ [
218
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
219
+ ],
220
+ [web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address)]
221
+ ],
222
+ [
223
+ [
224
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
225
+ ],
226
+ [web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address), ChainId.Ethereum]
227
+ ],
228
+ ];
229
+ examples.forEach(([expected, actual]) => {
230
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
231
+ expect(subDataService.liquityCloseSubData.encode(...actual)).to.eql(expected);
232
+ });
233
+ });
234
+ });
235
+ describe('decode()', () => {
236
+ const examples = [
237
+ [
238
+ {
239
+ closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
240
+ debtAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
241
+ },
242
+ [
243
+ '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
244
+ ],
245
+ ],
246
+ [
247
+ {
248
+ closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
249
+ debtAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
250
+ },
251
+ [
252
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
253
+ ],
254
+ ],
255
+ ];
256
+ examples.forEach(([expected, actual]) => {
257
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
258
+ expect(subDataService.liquityCloseSubData.decode(actual)).to.eql(expected);
259
+ });
260
+ });
261
+ });
262
+ });
263
+ describe('When testing subDataService.aaveV2LeverageManagementSubData', () => {
264
+ describe('encode()', () => {
265
+ const examples = [
266
+ [
267
+ [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],
268
+ [160, 220, 180, 190, true]
269
+ ],
270
+ [
271
+ [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],
272
+ [160, 200, 180, 190, false]
273
+ ],
274
+ ];
275
+ examples.forEach(([expected, actual]) => {
276
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
277
+ expect(subDataService.aaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
278
+ });
279
+ });
280
+ });
281
+ describe('decode()', () => {
282
+ const examples = [
283
+ [
284
+ { targetRatio: 200 },
285
+ ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
286
+ ],
287
+ [
288
+ { targetRatio: 123 },
289
+ ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
290
+ ],
291
+ ];
292
+ examples.forEach(([expected, actual]) => {
293
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
294
+ expect(subDataService.aaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
295
+ });
296
+ });
297
+ });
298
+ });
299
+ describe('When testing subDataService.aaveV3LeverageManagementSubData', () => {
300
+ describe('decode()', () => {
301
+ const examples = [
302
+ [
303
+ { targetRatio: 200 },
304
+ ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
305
+ ],
306
+ [
307
+ { targetRatio: 123 },
308
+ ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
309
+ ],
310
+ ];
311
+ examples.forEach(([expected, actual]) => {
312
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
313
+ expect(subDataService.aaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
314
+ });
315
+ });
316
+ });
317
+ });
318
+ describe('When testing subDataService.aaveV3QuotePriceSubData', () => {
319
+ describe('encode()', () => {
320
+ const examples = [
321
+ [
322
+ [
323
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
324
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
325
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
326
+ ],
327
+ [
328
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
329
+ 2,
330
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
331
+ 4,
332
+ ]
333
+ ],
334
+ [
335
+ [
336
+ '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
337
+ '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
338
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
339
+ ],
340
+ [
341
+ web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
342
+ 6,
343
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
344
+ 2,
345
+ ]
346
+ ],
347
+ ];
348
+ examples.forEach(([expected, actual]) => {
349
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
350
+ expect(subDataService.aaveV3QuotePriceSubData.encode(...actual)).to.eql(expected);
351
+ });
352
+ });
353
+ });
354
+ describe('decode()', () => {
355
+ const examples = [
356
+ [
357
+ {
358
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
359
+ collAssetId: 2,
360
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
361
+ debtAssetId: 4,
362
+ },
363
+ [
364
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
365
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
366
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
367
+ ],
368
+ ],
369
+ [
370
+ {
371
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
372
+ collAssetId: 6,
373
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
374
+ debtAssetId: 2,
375
+ },
376
+ [
377
+ '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
378
+ '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
379
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
380
+ ],
381
+ ],
382
+ ];
383
+ examples.forEach(([expected, actual]) => {
384
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
385
+ expect(subDataService.aaveV3QuotePriceSubData.decode(actual)).to.eql(expected);
386
+ });
387
+ });
388
+ });
389
+ });
390
+ describe('When testing subDataService.aaveV3CollateralSwitchSubData', () => {
391
+ describe('encode()', () => {
392
+ const examples = [
393
+ // WETH -> USDC
394
+ [
395
+ [
396
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
397
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
398
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
399
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
400
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
401
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
402
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
403
+ ],
404
+ [
405
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
406
+ 0,
407
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
408
+ 1,
409
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
410
+ '10000000000000000000',
411
+ false,
412
+ ]
413
+ ],
414
+ // USDC -> WETH (MaxUint256)
415
+ [
416
+ [
417
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
418
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
419
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
420
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
421
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
422
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
423
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
424
+ ],
425
+ [
426
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
427
+ 1,
428
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
429
+ 0,
430
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
431
+ MAXUINT, // MaxUint256
432
+ ]
433
+ ],
434
+ // WETH -> WBTC
435
+ [
436
+ [
437
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
438
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
439
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
440
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
441
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
442
+ '0x0000000000000000000000000000000000000000000000004563918244f40000',
443
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
444
+ ],
445
+ [
446
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
447
+ 0,
448
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
449
+ 2,
450
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
451
+ '5000000000000000000', // 5 WETH
452
+ ]
453
+ ],
454
+ ];
455
+ examples.forEach(([expected, actual]) => {
456
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
457
+ expect(subDataService.aaveV3CollateralSwitchSubData.encode(...actual)).to.eql(expected);
458
+ });
459
+ });
460
+ });
461
+ describe('decode()', () => {
462
+ const examples = [
463
+ // WETH -> USDC
464
+ [
465
+ {
466
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
467
+ fromAssetId: 0,
468
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
469
+ toAssetId: 1,
470
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
471
+ amountToSwitch: '10000000000000000000',
472
+ },
473
+ [
474
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
475
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
476
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
477
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
478
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
479
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
480
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
481
+ ],
482
+ ],
483
+ // USDC -> WETH (MaxUint256)
484
+ [
485
+ {
486
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
487
+ fromAssetId: 1,
488
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
489
+ toAssetId: 0,
490
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
491
+ amountToSwitch: MAXUINT,
492
+ },
493
+ [
494
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
495
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
496
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
497
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
498
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
499
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
500
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
501
+ ],
502
+ ],
503
+ // WETH -> WBTC
504
+ [
505
+ {
506
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
507
+ fromAssetId: 0,
508
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
509
+ toAssetId: 2,
510
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
511
+ amountToSwitch: '5000000000000000000',
512
+ },
513
+ [
514
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
515
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
516
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
517
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
518
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
519
+ '0x0000000000000000000000000000000000000000000000004563918244f40000',
520
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
521
+ ],
522
+ ],
523
+ ];
524
+ examples.forEach(([expected, actual]) => {
525
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
526
+ expect(subDataService.aaveV3CollateralSwitchSubData.decode(actual)).to.eql(expected);
527
+ });
528
+ });
529
+ });
530
+ });
531
+ describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
532
+ describe('encode()', () => {
533
+ const examples = [
534
+ // WETH -> cbBTC
535
+ [
536
+ [
537
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
538
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
539
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
540
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
541
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
542
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
543
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
544
+ ],
545
+ [
546
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
547
+ 0,
548
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
549
+ 7,
550
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
551
+ '10000000000000000000',
552
+ false,
553
+ ]
554
+ ],
555
+ // cbBTC -> WETH (MaxUint256)
556
+ [
557
+ [
558
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
559
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
560
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
561
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
562
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
563
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
564
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
565
+ ],
566
+ [
567
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
568
+ 7,
569
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
570
+ 0,
571
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
572
+ MAXUINT,
573
+ ]
574
+ ],
575
+ // WETH -> cbBTC (5 WETH)
576
+ [
577
+ [
578
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
579
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
580
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
581
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
582
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
583
+ '0x0000000000000000000000000000000000000000000000004563918244f40000',
584
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
585
+ ],
586
+ [
587
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
588
+ 0,
589
+ web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
590
+ 7,
591
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
592
+ '5000000000000000000', // 5 WETH
593
+ ]
594
+ ],
595
+ ];
596
+ examples.forEach(([expected, actual]) => {
597
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
598
+ expect(subDataService.sparkCollateralSwitchSubData.encode(...actual)).to.eql(expected);
599
+ });
600
+ });
601
+ });
602
+ describe('decode()', () => {
603
+ const examples = [
604
+ // WETH -> cbBTC
605
+ [
606
+ {
607
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
608
+ fromAssetId: 0,
609
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
610
+ toAssetId: 7,
611
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
612
+ amountToSwitch: '10000000000000000000',
613
+ },
614
+ [
615
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
616
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
617
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
618
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
619
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
620
+ '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
621
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
622
+ ],
623
+ ],
624
+ // cbBTC -> WETH (MaxUint256)
625
+ [
626
+ {
627
+ fromAsset: web3Utils.toChecksumAddress(getAssetInfo('cbBTC', ChainId.Ethereum).address),
628
+ fromAssetId: 7,
629
+ toAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
630
+ toAssetId: 0,
631
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
632
+ amountToSwitch: MAXUINT,
633
+ },
634
+ [
635
+ '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
636
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
637
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
638
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
639
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
640
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
641
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
642
+ ],
643
+ ],
644
+ ];
645
+ examples.forEach(([expected, actual]) => {
646
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
647
+ expect(subDataService.sparkCollateralSwitchSubData.decode(actual)).to.eql(expected);
648
+ });
649
+ });
650
+ });
651
+ });
652
+ describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
653
+ describe('encode()', () => {
654
+ const examples = [
655
+ [
656
+ [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],
657
+ [160, 220, 180, 190, true]
658
+ ],
659
+ [
660
+ [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],
661
+ [160, 200, 180, 190, false]
662
+ ],
663
+ ];
664
+ examples.forEach(([expected, actual]) => {
665
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
666
+ expect(subDataService.compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
667
+ });
668
+ });
669
+ });
670
+ describe('decode()', () => {
671
+ const examples = [
672
+ [
673
+ { targetRatio: 200 },
674
+ ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
675
+ ],
676
+ [
677
+ { targetRatio: 123 },
678
+ ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
679
+ ],
680
+ ];
681
+ examples.forEach(([expected, actual]) => {
682
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
683
+ expect(subDataService.compoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
684
+ });
685
+ });
686
+ });
687
+ });
688
+ describe('When testing subDataService.compoundV3LeverageManagementSubData', () => {
689
+ describe('encode()', () => {
690
+ const examples = [
691
+ [
692
+ [
693
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
694
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
695
+ new Dec(160).mul(1e16).toString(),
696
+ new Dec(220).mul(1e16).toString(),
697
+ new Dec(180).mul(1e16).toString(),
698
+ new Dec(190).mul(1e16).toString(),
699
+ true, false,
700
+ ],
701
+ [
702
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
703
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
704
+ 160, 220, 180, 190,
705
+ true, false,
706
+ ]
707
+ ],
708
+ [
709
+ [
710
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
711
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
712
+ new Dec(160).mul(1e16).toString(),
713
+ new Dec(210).mul(1e16).toString(),
714
+ new Dec(180).mul(1e16).toString(),
715
+ new Dec(190).mul(1e16).toString(),
716
+ false, true,
717
+ ],
718
+ [
719
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
720
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
721
+ 160, 210, 180, 190,
722
+ false, true,
723
+ ]
724
+ ],
725
+ ];
726
+ examples.forEach(([expected, actual]) => {
727
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
728
+ expect(subDataService.compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
729
+ });
730
+ });
731
+ });
732
+ describe('decode()', () => {
733
+ const examples = [
734
+ [
735
+ { targetRatio: 123 },
736
+ [
737
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
738
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
739
+ ],
740
+ ],
741
+ [
742
+ { targetRatio: 200 },
743
+ [
744
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
745
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
746
+ ],
747
+ ],
748
+ ];
749
+ examples.forEach(([expected, actual]) => {
750
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
751
+ expect(subDataService.compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
752
+ });
753
+ });
754
+ });
755
+ });
756
+ describe('When testing subDataService.morphoAaveV2LeverageManagementSubData', () => {
757
+ describe('encode()', () => {
758
+ const examples = [
759
+ [
760
+ [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],
761
+ [160, 220, 180, 190, true]
762
+ ],
763
+ [
764
+ [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],
765
+ [160, 200, 180, 190, false]
766
+ ],
767
+ ];
768
+ examples.forEach(([expected, actual]) => {
769
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
770
+ expect(subDataService.morphoAaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
771
+ });
772
+ });
773
+ });
774
+ describe('decode()', () => {
775
+ const examples = [
776
+ [
777
+ { targetRatio: 200 },
778
+ ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
779
+ ],
780
+ [
781
+ { targetRatio: 123 },
782
+ ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
783
+ ],
784
+ ];
785
+ examples.forEach(([expected, actual]) => {
786
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
787
+ expect(subDataService.morphoAaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
788
+ });
789
+ });
790
+ });
791
+ });
792
+ describe('When testing subDataService.cBondsRebondSubData', () => {
793
+ describe('encode()', () => {
794
+ const examples = [
795
+ [
796
+ ['0x00000000000000000000000000000000000000000000000000000000000000c8'],
797
+ [200]
798
+ ],
799
+ [
800
+ ['0x000000000000000000000000000000000000000000000000000000000000a119'],
801
+ [41241]
802
+ ],
803
+ ];
804
+ examples.forEach(([expected, actual]) => {
805
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
806
+ expect(subDataService.cBondsRebondSubData.encode(...actual)).to.eql(expected);
807
+ });
808
+ });
809
+ });
810
+ describe('decode()', () => {
811
+ const examples = [
812
+ [
813
+ { bondId: '200' },
814
+ ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x00000000000000000000000000000000000000000000000000000000000000c8'],
815
+ ],
816
+ [
817
+ { bondId: '41241' },
818
+ ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000000000000000000000000000000000000000a119'],
819
+ ],
820
+ ];
821
+ examples.forEach(([expected, actual]) => {
822
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
823
+ expect(subDataService.cBondsRebondSubData.decode(actual)).to.eql(expected);
824
+ });
825
+ });
826
+ });
827
+ });
828
+ describe('When testing subDataService.liquityPaybackUsingChickenBondSubData', () => {
829
+ describe('encode()', () => {
830
+ const examples = [
831
+ [
832
+ [
833
+ '0x0000000000000000000000000000000000000000000000000000000000001076', '0x0000000000000000000000000000000000000000000000000000000000000000',
834
+ '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
835
+ ],
836
+ ['4214', 0, ChainId.Ethereum]
837
+ ],
838
+ [
839
+ [
840
+ '0x00000000000000000000000000000000000000000000000000000000000002b8', '0x0000000000000000000000000000000000000000000000000000000000000001',
841
+ '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
842
+ ],
843
+ ['696', 1]
844
+ ],
845
+ ];
846
+ examples.forEach(([expected, actual]) => {
847
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
848
+ expect(subDataService.liquityPaybackUsingChickenBondSubData.encode(...actual)).to.eql(expected);
849
+ });
850
+ });
851
+ });
852
+ describe('decode()', () => {
853
+ const examples = [
854
+ [
855
+ { sourceId: '4214', sourceType: '0' },
856
+ [
857
+ '0x0000000000000000000000000000000000000000000000000000000000001076', '0x0000000000000000000000000000000000000000000000000000000000000000',
858
+ '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
859
+ ],
860
+ ],
861
+ [
862
+ { sourceId: '696', sourceType: '1' },
863
+ [
864
+ '0x00000000000000000000000000000000000000000000000000000000000002b8', '0x0000000000000000000000000000000000000000000000000000000000000001',
865
+ '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
866
+ ],
867
+ ],
868
+ ];
869
+ examples.forEach(([expected, actual]) => {
870
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
871
+ expect(subDataService.liquityPaybackUsingChickenBondSubData.decode(actual)).to.eql(expected);
872
+ });
873
+ });
874
+ });
875
+ });
876
+ describe('When testing subDataService.exchangeDcaSubData', () => {
877
+ describe('encode()', () => {
878
+ const examples = [
879
+ [
880
+ [
881
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
882
+ '0x0000000000000000000000000000000000000000000000000000000000000853', '0x0000000000000000000000000000000000000000000000000000000000231860'
883
+ ],
884
+ [
885
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
886
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
887
+ '2131',
888
+ 2300000,
889
+ ]
890
+ ],
891
+ [
892
+ [
893
+ '0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f', '0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4',
894
+ '0x00000000000000000000000000000000000000000000000000000000003eddd7', '0x0000000000000000000000000000000000000000000000000000000008f57500'
895
+ ],
896
+ [
897
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
898
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
899
+ '4120023',
900
+ 150304000,
901
+ ]
902
+ ],
903
+ ];
904
+ examples.forEach(([expected, actual]) => {
905
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
906
+ expect(subDataService.exchangeDcaSubData.encode(...actual)).to.eql(expected);
907
+ });
908
+ });
909
+ });
910
+ describe('decode()', () => {
911
+ const examples = [
912
+ [
913
+ {
914
+ fromToken: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
915
+ toToken: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
916
+ amount: '0.000000000000002131',
917
+ interval: '2300000',
918
+ },
919
+ [
920
+ [
921
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
922
+ '0x0000000000000000000000000000000000000000000000000000000000000853', '0x0000000000000000000000000000000000000000000000000000000000231860'
923
+ ],
924
+ ChainId.Ethereum
925
+ ],
926
+ ],
927
+ [
928
+ {
929
+ fromToken: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
930
+ toToken: web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
931
+ amount: '0.04120023',
932
+ interval: '150304000',
933
+ },
934
+ [
935
+ [
936
+ '0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f', '0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4',
937
+ '0x00000000000000000000000000000000000000000000000000000000003eddd7', '0x0000000000000000000000000000000000000000000000000000000008f57500'
938
+ ],
939
+ ChainId.Arbitrum
940
+ ]
941
+ ],
942
+ ];
943
+ examples.forEach(([expected, actual]) => {
944
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
945
+ expect(subDataService.exchangeDcaSubData.decode(...actual)).to.eql(expected);
946
+ });
947
+ });
948
+ });
949
+ });
950
+ describe('When testing subDataService.exchangeLimitOrderSubData', () => {
951
+ describe('encode()', () => {
952
+ const examples = [
953
+ [
954
+ [
955
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
956
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
957
+ '2131',
958
+ '0.53123',
959
+ '1696590921159',
960
+ `${OrderType.STOP_LOSS}`
961
+ ],
962
+ [
963
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
964
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
965
+ '2131',
966
+ '0.53123',
967
+ 1696590921159,
968
+ OrderType.STOP_LOSS
969
+ ]
970
+ ],
971
+ [
972
+ [
973
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
974
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
975
+ '2131',
976
+ '0.43123',
977
+ '1646590921159',
978
+ `${OrderType.TAKE_PROFIT}`
979
+ ],
980
+ [
981
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
982
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
983
+ '2131',
984
+ '0.43123',
985
+ 1646590921159,
986
+ OrderType.TAKE_PROFIT
987
+ ]
988
+ ],
989
+ ];
990
+ examples.forEach(([expected, actual]) => {
991
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
992
+ expect(subDataService.exchangeLimitOrderSubData.encode(...actual)).to.eql(expected);
993
+ });
994
+ });
995
+ });
996
+ describe('decode()', () => {
997
+ const examples = [
998
+ [
999
+ {
1000
+ fromToken: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1001
+ toToken: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1002
+ amount: '0.000000000000002131',
1003
+ },
1004
+ [
1005
+ [
1006
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1007
+ '0x0000000000000000000000000000000000000000000000000000000000000853', '0x0000000000000000000000000000000000000000000000000000000000231860'
1008
+ ],
1009
+ ChainId.Ethereum
1010
+ ],
1011
+ ],
1012
+ [
1013
+ {
1014
+ fromToken: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
1015
+ toToken: web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
1016
+ amount: '0.04120023',
1017
+ },
1018
+ [
1019
+ [
1020
+ '0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f', '0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4',
1021
+ '0x00000000000000000000000000000000000000000000000000000000003eddd7', '0x0000000000000000000000000000000000000000000000000000000008f57500'
1022
+ ],
1023
+ ChainId.Arbitrum
1024
+ ]
1025
+ ],
1026
+ ];
1027
+ examples.forEach(([expected, actual]) => {
1028
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1029
+ expect(subDataService.exchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
1030
+ });
1031
+ });
1032
+ });
1033
+ });
1034
+ describe('When testing subDataService.sparkLeverageManagementSubData', () => {
1035
+ describe('decode()', () => {
1036
+ const examples = [
1037
+ [
1038
+ { targetRatio: 200 },
1039
+ ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
1040
+ ],
1041
+ [
1042
+ { targetRatio: 123 },
1043
+ ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
1044
+ ],
1045
+ ];
1046
+ examples.forEach(([expected, actual]) => {
1047
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1048
+ expect(subDataService.sparkLeverageManagementSubData.decode(actual)).to.eql(expected);
1049
+ });
1050
+ });
1051
+ });
1052
+ });
1053
+ describe('When testing subDataService.liquityDsrPaybackSubData', () => {
1054
+ describe('encode()', () => {
1055
+ const examples = [
1056
+ [
1057
+ [
1058
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
1059
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1060
+ ],
1061
+ [123]
1062
+ ],
1063
+ [
1064
+ [
1065
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
1066
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1067
+ ],
1068
+ [420]
1069
+ ],
1070
+ ];
1071
+ examples.forEach(([expected, actual]) => {
1072
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1073
+ expect(subDataService.liquityDsrPaybackSubData.encode(...actual)).to.eql(expected);
1074
+ });
1075
+ });
1076
+ });
1077
+ describe('decode()', () => {
1078
+ const examples = [
1079
+ [
1080
+ {
1081
+ targetRatio: 123,
1082
+ },
1083
+ [
1084
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
1085
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1086
+ ],
1087
+ ],
1088
+ [
1089
+ {
1090
+ targetRatio: 420,
1091
+ },
1092
+ [
1093
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
1094
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1095
+ ],
1096
+ ],
1097
+ ];
1098
+ examples.forEach(([expected, actual]) => {
1099
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1100
+ expect(subDataService.liquityDsrPaybackSubData.decode(actual)).to.eql(expected);
1101
+ });
1102
+ });
1103
+ });
1104
+ });
1105
+ describe('When testing subDataService.liquityDsrSupplySubData', () => {
1106
+ describe('encode()', () => {
1107
+ const examples = [
1108
+ [
1109
+ [
1110
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
1111
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1112
+ ],
1113
+ [320]
1114
+ ],
1115
+ [
1116
+ [
1117
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001eab7f4a799d0000',
1118
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1119
+ ],
1120
+ [221]
1121
+ ],
1122
+ ];
1123
+ examples.forEach(([expected, actual]) => {
1124
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1125
+ expect(subDataService.liquityDsrSupplySubData.encode(...actual)).to.eql(expected);
1126
+ });
1127
+ });
1128
+ });
1129
+ describe('decode()', () => {
1130
+ const examples = [
1131
+ [
1132
+ {
1133
+ targetRatio: 320,
1134
+ },
1135
+ [
1136
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
1137
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1138
+ ],
1139
+ ],
1140
+ [
1141
+ {
1142
+ targetRatio: 221,
1143
+ },
1144
+ [
1145
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001eab7f4a799d0000',
1146
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1147
+ ],
1148
+ ],
1149
+ ];
1150
+ examples.forEach(([expected, actual]) => {
1151
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1152
+ expect(subDataService.liquityDsrSupplySubData.decode(actual)).to.eql(expected);
1153
+ });
1154
+ });
1155
+ });
1156
+ });
1157
+ describe('When testing subDataService.liquityDebtInFrontRepaySubData', () => {
1158
+ describe('encode()', () => {
1159
+ const examples = [
1160
+ [
1161
+ [
1162
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1163
+ '0x000000000000000000000000000000000000000000000000016345785d8a0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
1164
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1165
+ ],
1166
+ [10]
1167
+ ],
1168
+ [
1169
+ [
1170
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1171
+ '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
1172
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1173
+ ],
1174
+ [45]
1175
+ ],
1176
+ ];
1177
+ examples.forEach(([expected, actual]) => {
1178
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1179
+ expect(subDataService.liquityDebtInFrontRepaySubData.encode(...actual)).to.eql(expected);
1180
+ });
1181
+ });
1182
+ });
1183
+ describe('decode()', () => {
1184
+ const examples = [
1185
+ [
1186
+ {
1187
+ targetRatioIncrease: 10,
1188
+ },
1189
+ [
1190
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1191
+ '0x000000000000000000000000000000000000000000000000016345785d8a0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
1192
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1193
+ ],
1194
+ ],
1195
+ [
1196
+ {
1197
+ targetRatioIncrease: 45,
1198
+ },
1199
+ [
1200
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1201
+ '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
1202
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1203
+ ],
1204
+ ],
1205
+ ];
1206
+ examples.forEach(([expected, actual]) => {
1207
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1208
+ expect(subDataService.liquityDebtInFrontRepaySubData.decode(actual)).to.eql(expected);
1209
+ });
1210
+ });
1211
+ });
1212
+ });
1213
+ describe('When testing subDataService.crvUSDLeverageManagementSubData', () => {
1214
+ describe('encode()', () => {
1215
+ const examples = [
1216
+ [
1217
+ [
1218
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1219
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1220
+ '0x00000000000000000000000000000000000000000000000010a741a462780000',
1221
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1222
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1223
+ ],
1224
+ ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', RatioState.UNDER, 120, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E'],
1225
+ ],
1226
+ [
1227
+ [
1228
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1229
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1230
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1231
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1232
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1233
+ ],
1234
+ ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', RatioState.OVER, 180, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E']
1235
+ ],
1236
+ ];
1237
+ examples.forEach(([expected, actual]) => {
1238
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1239
+ expect(subDataService.crvUSDLeverageManagementSubData.encode(...actual)).to.eql(expected);
1240
+ });
1241
+ });
1242
+ });
1243
+ describe('decode()', () => {
1244
+ const examples = [
1245
+ [
1246
+ {
1247
+ controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1248
+ targetRatio: 120,
1249
+ },
1250
+ ['0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635', '0x0000000000000000000000000000000000000000000000000000000000000001', '0x00000000000000000000000000000000000000000000000010a741a462780000', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',],
1251
+ ],
1252
+ [
1253
+ {
1254
+ controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1255
+ targetRatio: 180,
1256
+ },
1257
+ ['0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x00000000000000000000000000000000000000000000000018fae27693b40000', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',],
1258
+ ],
1259
+ ];
1260
+ examples.forEach(([expected, actual]) => {
1261
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1262
+ expect(subDataService.crvUSDLeverageManagementSubData.decode(actual)).to.eql(expected);
1263
+ });
1264
+ });
1265
+ });
1266
+ });
1267
+ describe('When testing subDataService.crvUSDPaybackSubData', () => {
1268
+ describe('encode()', () => {
1269
+ const examples = [
1270
+ [
1271
+ [
1272
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1273
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1274
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1275
+ '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1276
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1277
+ ],
1278
+ ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280', '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280', '20000', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E'],
1279
+ ]
1280
+ ];
1281
+ examples.forEach(([expected, actual]) => {
1282
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1283
+ expect(subDataService.crvUSDPaybackSubData.encode(...actual)).to.eql(expected);
1284
+ });
1285
+ });
1286
+ });
1287
+ describe('decode()', () => {
1288
+ const examples = [
1289
+ [
1290
+ {
1291
+ controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1292
+ addressToPullTokensFrom: '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280',
1293
+ positionOwner: '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280',
1294
+ paybackAmount: '20000'
1295
+ },
1296
+ [
1297
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1298
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1299
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1300
+ '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1301
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1302
+ ]
1303
+ ]
1304
+ ];
1305
+ examples.forEach(([expected, actual]) => {
1306
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1307
+ expect(subDataService.crvUSDPaybackSubData.decode(actual)).to.eql(expected);
1308
+ });
1309
+ });
1310
+ });
1311
+ });
1312
+ describe('When testing subDataService.compoundV3L2LeverageManagementSubData', () => {
1313
+ describe('encode()', () => {
1314
+ const examples = [
1315
+ [
1316
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
1317
+ [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 190, true, false]
1318
+ ],
1319
+ [
1320
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
1321
+ [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 110, false, false]
1322
+ ],
1323
+ ];
1324
+ examples.forEach(([expected, actual]) => {
1325
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1326
+ expect(subDataService.compoundV3L2LeverageManagementSubData.encode(...actual)).to.eql(expected);
1327
+ });
1328
+ });
1329
+ });
1330
+ describe('decode()', () => {
1331
+ const examples = [
1332
+ [
1333
+ { targetRatio: 200 },
1334
+ [
1335
+ '0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000213d212133AFaB8F2B829B1066c7E43cAd94E2c',
1336
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1337
+ ],
1338
+ ],
1339
+ [
1340
+ { targetRatio: 123 },
1341
+ [
1342
+ '0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000413d212133AFaB8F2B829B1066c7E43cAd94E2c',
1343
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
1344
+ ],
1345
+ ],
1346
+ ];
1347
+ examples.forEach(([expected, actual]) => {
1348
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1349
+ expect(subDataService.compoundV3L2LeverageManagementSubData.decode(actual)).to.eql(expected);
1350
+ });
1351
+ });
1352
+ });
1353
+ });
1354
+ describe('When testing subDataService.morphoBlueLeverageManagementSubData', () => {
1355
+ describe('encode()', () => {
1356
+ const examples = [
1357
+ [
1358
+ [
1359
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1360
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1361
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1362
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1363
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1364
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1365
+ '0x00000000000000000000000000000000000000000000000010a741a462780000',
1366
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1367
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1368
+ ],
1369
+ [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '945000000000000000', RatioState.UNDER, 120, web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), false]
1370
+ ],
1371
+ [
1372
+ [
1373
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1374
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1375
+ '0x00000000000000000000000048f7e36eb6b826b2df4b2e630b62cd25e89e40e2',
1376
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1377
+ '0x0000000000000000000000000000000000000000000000000bef55718ad60000',
1378
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1379
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1380
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c',
1381
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1382
+ ],
1383
+ [web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '860000000000000000', RatioState.OVER, 200, web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), false]
1384
+ ],
1385
+ ];
1386
+ examples.forEach(([expected, actual]) => {
1387
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1388
+ expect(subDataService.morphoBlueLeverageManagementSubData.encode(...actual)).to.eql(expected);
1389
+ });
1390
+ });
1391
+ });
1392
+ describe('decode()', () => {
1393
+ const examples = [
1394
+ [
1395
+ {
1396
+ 'collToken': '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1397
+ 'irm': '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1398
+ 'lltv': '945000000000000000',
1399
+ 'loanToken': '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1400
+ 'oracle': '0x2a01EB9496094dA03c4E364Def50f5aD1280AD72',
1401
+ 'targetRatio': 120,
1402
+ 'user': '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
1403
+ },
1404
+ [
1405
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1406
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1407
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1408
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1409
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1410
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1411
+ '0x00000000000000000000000000000000000000000000000010a741a462780000',
1412
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1413
+ ],
1414
+ ],
1415
+ [
1416
+ {
1417
+ 'collToken': '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1418
+ 'irm': '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1419
+ 'lltv': '860000000000000000',
1420
+ 'loanToken': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
1421
+ 'oracle': '0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2',
1422
+ 'targetRatio': 200,
1423
+ 'user': '0x0043d218133aFaB8F2b829B106633E434aD94e2C',
1424
+ },
1425
+ [
1426
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1427
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1428
+ '0x00000000000000000000000048f7e36eb6b826b2df4b2e630b62cd25e89e40e2',
1429
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1430
+ '0x0000000000000000000000000000000000000000000000000bef55718ad60000',
1431
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1432
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1433
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c',
1434
+ ],
1435
+ ],
1436
+ ];
1437
+ examples.forEach(([expected, actual]) => {
1438
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1439
+ expect(subDataService.morphoBlueLeverageManagementSubData.decode(actual)).to.eql(expected);
1440
+ });
1441
+ });
1442
+ });
1443
+ });
1444
+ describe('When testing subDataService.morphoBlueCloseOnPriceSubData', () => {
1445
+ describe('encode()', () => {
1446
+ const examples = [
1447
+ [
1448
+ [
1449
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1450
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1451
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1452
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1453
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1454
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1455
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1456
+ ],
1457
+ [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'), '945000000000000000', web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT]
1458
+ ],
1459
+ ];
1460
+ examples.forEach(([expected, actual]) => {
1461
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1462
+ expect(subDataService.morphoBlueCloseOnPriceSubData.encode(...actual)).to.eql(expected);
1463
+ });
1464
+ });
1465
+ });
1466
+ describe('decode()', () => {
1467
+ const examples = [
1468
+ [
1469
+ {
1470
+ loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1471
+ collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1472
+ oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1473
+ irm: '0x0000000000000000000000000000000000000000',
1474
+ lltv: '945000000000000000',
1475
+ user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
1476
+ closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1477
+ },
1478
+ [
1479
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1480
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1481
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1482
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1483
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1484
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1485
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1486
+ ],
1487
+ ],
1488
+ ];
1489
+ examples.forEach(([expected, actual]) => {
1490
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1491
+ expect(subDataService.morphoBlueCloseOnPriceSubData.decode(actual)).to.eql(expected);
1492
+ });
1493
+ });
1494
+ });
1495
+ });
1496
+ describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
1497
+ describe('encode()', () => {
1498
+ const examples = [
1499
+ [
1500
+ [
1501
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1502
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1503
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1504
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1505
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
1506
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1507
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1508
+ ],
1509
+ [
1510
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1511
+ 0,
1512
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1513
+ 4,
1514
+ web3Utils.toChecksumAddress('0x2f39d218133afab8f2b819b1066c7e434ad94e9e'),
1515
+ 200,
1516
+ ]
1517
+ ],
1518
+ ];
1519
+ examples.forEach(([expected, actual]) => {
1520
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1521
+ expect(subDataService.aaveV3LeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
1522
+ });
1523
+ });
1524
+ });
1525
+ describe('decode()', () => {
1526
+ const examples = [
1527
+ [
1528
+ {
1529
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1530
+ collAssetId: 0,
1531
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
1532
+ debtAssetId: 4,
1533
+ marketAddr: web3Utils.toChecksumAddress('0x2f39d218133afab8f2b819b1066c7e434ad94e9e'),
1534
+ targetRatio: 200,
1535
+ },
1536
+ [
1537
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1538
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1539
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
1540
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1541
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
1542
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1543
+ ],
1544
+ ],
1545
+ ];
1546
+ examples.forEach(([expected, actual]) => {
1547
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1548
+ expect(subDataService.aaveV3LeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
1549
+ });
1550
+ });
1551
+ });
1552
+ });
1553
+ describe('When testing subDataService.compoundV3LeverageManagementOnPriceSubData', () => {
1554
+ describe('encode()', () => {
1555
+ const examples = [
1556
+ [
1557
+ [
1558
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1559
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1560
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1561
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1562
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1563
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c'
1564
+ ],
1565
+ [
1566
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1567
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1568
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1569
+ 200,
1570
+ RatioState.UNDER,
1571
+ web3Utils.toChecksumAddress('0x1031d218133afab8c2b819b1366c7e434ad91e9c')
1572
+ ]
1573
+ ],
1574
+ [
1575
+ [
1576
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1577
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1578
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1579
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
1580
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1581
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c'
1582
+ ],
1583
+ [
1584
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1585
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1586
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1587
+ 190,
1588
+ RatioState.OVER,
1589
+ web3Utils.toChecksumAddress('0x0043d218133afab8f2b829b106633e434ad94e2c')
1590
+ ]
1591
+ ],
1592
+ ];
1593
+ examples.forEach(([expected, actual]) => {
1594
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1595
+ expect(subDataService.compoundV3LeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
1596
+ });
1597
+ });
1598
+ });
1599
+ describe('decode()', () => {
1600
+ const examples = [
1601
+ [
1602
+ {
1603
+ market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1604
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1605
+ baseToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1606
+ targetRatio: 200,
1607
+ ratioState: RatioState.UNDER,
1608
+ owner: web3Utils.toChecksumAddress('0x1031d218133afab8c2b819b1366c7e434ad91e9c')
1609
+ },
1610
+ [
1611
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1612
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1613
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1614
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1615
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1616
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c'
1617
+ ]
1618
+ ],
1619
+ [
1620
+ {
1621
+ market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1622
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1623
+ baseToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1624
+ targetRatio: 190,
1625
+ ratioState: RatioState.OVER,
1626
+ owner: web3Utils.toChecksumAddress('0x0043d218133afab8f2b829b106633e434ad94e2c')
1627
+ },
1628
+ [
1629
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1630
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1631
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1632
+ '0x0000000000000000000000000000000000000000000000001a5e27eef13e0000',
1633
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1634
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c'
1635
+ ]
1636
+ ],
1637
+ ];
1638
+ examples.forEach(([expected, actual]) => {
1639
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1640
+ expect(subDataService.compoundV3LeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
1641
+ });
1642
+ });
1643
+ });
1644
+ });
1645
+ describe('When testing subDataService.compoundV3CloseSubData', () => {
1646
+ describe('encode()', () => {
1647
+ const examples = [
1648
+ [
1649
+ [
1650
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1651
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1652
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1653
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1654
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1655
+ ],
1656
+ [
1657
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1658
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1659
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1660
+ CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1661
+ web3Utils.toChecksumAddress('0x1031d218133afab8c2b819b1366c7e434ad91e9c'),
1662
+ ]
1663
+ ],
1664
+ [
1665
+ [
1666
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1667
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1668
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1669
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1670
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1671
+ ],
1672
+ [
1673
+ web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1674
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1675
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1676
+ CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
1677
+ web3Utils.toChecksumAddress('0x1031d218133afab8c2b819b1366c7e434ad91e9c'),
1678
+ ]
1679
+ ],
1680
+ ];
1681
+ examples.forEach(([expected, actual]) => {
1682
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1683
+ expect(subDataService.compoundV3CloseSubData.encode(...actual)).to.eql(expected);
1684
+ });
1685
+ });
1686
+ });
1687
+ describe('decode()', () => {
1688
+ const examples = [
1689
+ [
1690
+ {
1691
+ market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1692
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1693
+ baseToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1694
+ closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1695
+ owner: web3Utils.toChecksumAddress('0x1031d218133afab8c2b819b1366c7e434ad91e9c')
1696
+ },
1697
+ [
1698
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1699
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1700
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1701
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1702
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c'
1703
+ ]
1704
+ ],
1705
+ [
1706
+ {
1707
+ market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
1708
+ collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1709
+ baseToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1710
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
1711
+ owner: web3Utils.toChecksumAddress('0x1031d218133afab8c2b819b1366c7e434ad91e9c')
1712
+ },
1713
+ [
1714
+ '0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3',
1715
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1716
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1717
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1718
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c'
1719
+ ]
1720
+ ],
1721
+ ];
1722
+ examples.forEach(([expected, actual]) => {
1723
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1724
+ expect(subDataService.compoundV3CloseSubData.decode(actual)).to.eql(expected);
1725
+ });
1726
+ });
1727
+ });
1728
+ });
1729
+ describe("When testing subDataService.aaveV3LeverageManagementOnPriceGeneric", () => {
1730
+ describe("encode()", () => {
1731
+ const examples = [
1732
+ [
1733
+ [
1734
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1735
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1736
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1737
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1738
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1739
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1740
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1741
+ ],
1742
+ [
1743
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1744
+ 0,
1745
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1746
+ 1,
1747
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1748
+ 200,
1749
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1750
+ ]
1751
+ ],
1752
+ [
1753
+ [
1754
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1755
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1756
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1757
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1758
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1759
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1760
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1761
+ ],
1762
+ [
1763
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1764
+ 2,
1765
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1766
+ 1,
1767
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1768
+ 200,
1769
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1770
+ ]
1771
+ ],
1772
+ ];
1773
+ examples.forEach(([expected, actual]) => {
1774
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1775
+ expect(subDataService.aaveV3LeverageManagementOnPriceGeneric.encode(...actual)).to.eql(expected);
1776
+ });
1777
+ });
1778
+ });
1779
+ describe("decode()", () => {
1780
+ const examples = [
1781
+ [
1782
+ {
1783
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1784
+ collAssetId: 0,
1785
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1786
+ debtAssetId: 1,
1787
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1788
+ targetRatio: 200,
1789
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1790
+ },
1791
+ [
1792
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1793
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1794
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1795
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1796
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1797
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1798
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1799
+ ]
1800
+ ],
1801
+ [
1802
+ {
1803
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1804
+ collAssetId: 2,
1805
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1806
+ debtAssetId: 1,
1807
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1808
+ targetRatio: 200,
1809
+ owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1810
+ },
1811
+ [
1812
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1813
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1814
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1815
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1816
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1817
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1818
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1819
+ ]
1820
+ ],
1821
+ ];
1822
+ examples.forEach(([expected, actual]) => {
1823
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1824
+ expect(subDataService.aaveV3LeverageManagementOnPriceGeneric.decode(actual)).to.eql(expected);
1825
+ });
1826
+ });
1827
+ });
1828
+ });
1829
+ describe("When testing subDataService.aaveV3CloseGenericSubData", () => {
1830
+ describe("encode()", () => {
1831
+ const examples = [
1832
+ // TAKE_PROFIT_IN_COLLATERAL
1833
+ [
1834
+ [
1835
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1836
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1837
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1838
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1839
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1840
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1841
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1842
+ ],
1843
+ [
1844
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1845
+ 0,
1846
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1847
+ 1,
1848
+ CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
1849
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1850
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1851
+ ]
1852
+ ],
1853
+ // STOP_LOSS_IN_COLLATERAL
1854
+ [
1855
+ [
1856
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1857
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1858
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1859
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1860
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1861
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1862
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1863
+ ],
1864
+ [
1865
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1866
+ 0,
1867
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1868
+ 1,
1869
+ CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
1870
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1871
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1872
+ ]
1873
+ ],
1874
+ // TAKE_PROFIT_IN_DEBT
1875
+ [
1876
+ [
1877
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1878
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1879
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1880
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1881
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1882
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1883
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1884
+ ],
1885
+ [
1886
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1887
+ 0,
1888
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1889
+ 1,
1890
+ CloseStrategyType.TAKE_PROFIT_IN_DEBT,
1891
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1892
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1893
+ ]
1894
+ ],
1895
+ // STOP_LOSS_IN_DEBT
1896
+ [
1897
+ [
1898
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1899
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1900
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1901
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1902
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
1903
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1904
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1905
+ ],
1906
+ [
1907
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1908
+ 0,
1909
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1910
+ 1,
1911
+ CloseStrategyType.STOP_LOSS_IN_DEBT,
1912
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1913
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1914
+ ]
1915
+ ],
1916
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL
1917
+ [
1918
+ [
1919
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1920
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1921
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1922
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1923
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
1924
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1925
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
1926
+ ],
1927
+ [
1928
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
1929
+ 0,
1930
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1931
+ 1,
1932
+ CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
1933
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1934
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
1935
+ ]
1936
+ ],
1937
+ // TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
1938
+ [
1939
+ [
1940
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1941
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1942
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1943
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1944
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
1945
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1946
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1947
+ ],
1948
+ [
1949
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1950
+ 2,
1951
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1952
+ 1,
1953
+ CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
1954
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1955
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1956
+ ]
1957
+ ],
1958
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
1959
+ [
1960
+ [
1961
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1962
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1963
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1964
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1965
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
1966
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1967
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1968
+ ],
1969
+ [
1970
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1971
+ 2,
1972
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1973
+ 1,
1974
+ CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
1975
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1976
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1977
+ ]
1978
+ ],
1979
+ // TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
1980
+ [
1981
+ [
1982
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
1983
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
1984
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1985
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1986
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
1987
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
1988
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1989
+ ],
1990
+ [
1991
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
1992
+ 2,
1993
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
1994
+ 1,
1995
+ CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
1996
+ web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
1997
+ web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
1998
+ ]
1999
+ ],
2000
+ ];
2001
+ examples.forEach(([expected, actual]) => {
2002
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2003
+ expect(subDataService.aaveV3CloseGenericSubData.encode(...actual)).to.eql(expected);
2004
+ });
2005
+ });
2006
+ });
2007
+ describe("decode()", () => {
2008
+ const examples = [
2009
+ // TAKE_PROFIT_IN_COLLATERAL
2010
+ [
2011
+ {
2012
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2013
+ collAssetId: 0,
2014
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2015
+ debtAssetId: 1,
2016
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
2017
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2018
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2019
+ },
2020
+ [
2021
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2022
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2023
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2024
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2025
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2026
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2027
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2028
+ ]
2029
+ ],
2030
+ // STOP_LOSS_IN_COLLATERAL
2031
+ [
2032
+ {
2033
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2034
+ collAssetId: 0,
2035
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2036
+ debtAssetId: 1,
2037
+ closeType: CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
2038
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2039
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2040
+ },
2041
+ [
2042
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2043
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2044
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2045
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2046
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2047
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2048
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2049
+ ]
2050
+ ],
2051
+ // TAKE_PROFIT_IN_DEBT
2052
+ [
2053
+ {
2054
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2055
+ collAssetId: 0,
2056
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2057
+ debtAssetId: 1,
2058
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT,
2059
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2060
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2061
+ },
2062
+ [
2063
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2064
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2065
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2066
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2067
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2068
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2069
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2070
+ ]
2071
+ ],
2072
+ // STOP_LOSS_IN_DEBT
2073
+ [
2074
+ {
2075
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2076
+ collAssetId: 0,
2077
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2078
+ debtAssetId: 1,
2079
+ closeType: CloseStrategyType.STOP_LOSS_IN_DEBT,
2080
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2081
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2082
+ },
2083
+ [
2084
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2085
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2086
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2087
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2088
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
2089
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2090
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2091
+ ]
2092
+ ],
2093
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL
2094
+ [
2095
+ {
2096
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2097
+ collAssetId: 0,
2098
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2099
+ debtAssetId: 1,
2100
+ closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
2101
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2102
+ owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
2103
+ },
2104
+ [
2105
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2106
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2107
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2108
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2109
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2110
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2111
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
2112
+ ]
2113
+ ],
2114
+ // TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT
2115
+ [
2116
+ {
2117
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2118
+ collAssetId: 2,
2119
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2120
+ debtAssetId: 1,
2121
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
2122
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2123
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2124
+ },
2125
+ [
2126
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2127
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2128
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2129
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2130
+ '0x0000000000000000000000000000000000000000000000000000000000000005',
2131
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2132
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2133
+ ]
2134
+ ],
2135
+ // TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT
2136
+ [
2137
+ {
2138
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2139
+ collAssetId: 2,
2140
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2141
+ debtAssetId: 1,
2142
+ closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
2143
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2144
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2145
+ },
2146
+ [
2147
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2148
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2149
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2150
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2151
+ '0x0000000000000000000000000000000000000000000000000000000000000006',
2152
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2153
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2154
+ ]
2155
+ ],
2156
+ // TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL
2157
+ [
2158
+ {
2159
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2160
+ collAssetId: 2,
2161
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2162
+ debtAssetId: 1,
2163
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
2164
+ marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
2165
+ owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
2166
+ },
2167
+ [
2168
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2169
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2170
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2171
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2172
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
2173
+ '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
2174
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2175
+ ]
2176
+ ],
2177
+ ];
2178
+ examples.forEach(([expected, actual]) => {
2179
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2180
+ expect(subDataService.aaveV3CloseGenericSubData.decode(actual)).to.eql(expected);
2181
+ });
2182
+ });
2183
+ });
2184
+ });
2185
+ describe('When testing subDataService.sparkLeverageManagementOnPriceSubData', () => {
2186
+ describe('encode()', () => {
2187
+ const examples = [
2188
+ [
2189
+ [
2190
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
2191
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2192
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
2193
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
2194
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2195
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
2196
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
2197
+ ],
2198
+ [
2199
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
2200
+ 0,
2201
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
2202
+ 1,
2203
+ web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2204
+ 200,
2205
+ ]
2206
+ ]
2207
+ ];
2208
+ examples.forEach(([expected, actual]) => {
2209
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2210
+ expect(subDataService.sparkLeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
2211
+ });
2212
+ });
2213
+ });
2214
+ describe('decode()', () => {
2215
+ const examples = [
2216
+ [
2217
+ {
2218
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
2219
+ collAssetId: 2,
2220
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
2221
+ debtAssetId: 4,
2222
+ marketAddr: web3Utils.toChecksumAddress('0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE'),
2223
+ targetRatio: 175
2224
+ },
2225
+ [
2226
+ '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
2227
+ '0x0000000000000000000000000000000000000000000000000000000000000002',
2228
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
2229
+ '0x0000000000000000000000000000000000000000000000000000000000000004',
2230
+ '0x00000000000000000000000002c3ea4e34c0cbd694d2adfa2c690eecbc1793ee',
2231
+ '0x00000000000000000000000000000000000000000000000018493fba64ef0000'
2232
+ ]
2233
+ ]
2234
+ ];
2235
+ examples.forEach(([expected, actual]) => {
2236
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
2237
+ expect(subDataService.sparkLeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
2238
+ });
2239
+ });
2240
+ });
2241
+ });
2242
+ describe('When testing subDataService.aaveV4LeverageManagementSubData', () => {
2243
+ describe('encode()', () => {
2244
+ const examples = [
2245
+ [
2246
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2247
+ [web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), RatioState.UNDER, 150]
2248
+ ],
2249
+ ];
2250
+ examples.forEach(([expected, actual]) => {
2251
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2252
+ expect(subDataService.aaveV4LeverageManagementSubData.encode(...actual)).to.eql(expected);
2253
+ });
2254
+ });
2255
+ });
2256
+ describe('decode()', () => {
2257
+ const examples = [
2258
+ [
2259
+ {
2260
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2261
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2262
+ ratioState: RatioState.UNDER,
2263
+ targetRatio: 150,
2264
+ },
2265
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2266
+ ],
2267
+ ];
2268
+ examples.forEach(([expected, actual]) => {
2269
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2270
+ expect(subDataService.aaveV4LeverageManagementSubData.decode(actual)).to.eql(expected);
2271
+ });
2272
+ });
2273
+ });
2274
+ });
2275
+ describe('When testing subDataService.aaveV4LeverageManagementOnPriceSubData', () => {
2276
+ describe('encode()', () => {
2277
+ const examples = [
2278
+ [
2279
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2280
+ [
2281
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2282
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
2283
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
2284
+ RatioState.OVER, 160
2285
+ ]
2286
+ ],
2287
+ ];
2288
+ examples.forEach(([expected, actual]) => {
2289
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2290
+ expect(subDataService.aaveV4LeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
2291
+ });
2292
+ });
2293
+ });
2294
+ describe('decode()', () => {
2295
+ const examples = [
2296
+ [
2297
+ {
2298
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2299
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2300
+ collAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2301
+ collAssetId: 10,
2302
+ debtAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2303
+ debtAssetId: 20,
2304
+ ratioState: RatioState.OVER,
2305
+ targetRatio: 160,
2306
+ },
2307
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2308
+ ],
2309
+ ];
2310
+ examples.forEach(([expected, actual]) => {
2311
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2312
+ expect(subDataService.aaveV4LeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
2313
+ });
2314
+ });
2315
+ });
2316
+ });
2317
+ describe('When testing subDataService.aaveV4CloseSubData', () => {
2318
+ describe('encode()', () => {
2319
+ const examples = [
2320
+ [
2321
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2322
+ [
2323
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2324
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
2325
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
2326
+ CloseStrategyType.STOP_LOSS_IN_COLLATERAL
2327
+ ]
2328
+ ],
2329
+ ];
2330
+ examples.forEach(([expected, actual]) => {
2331
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2332
+ expect(subDataService.aaveV4CloseSubData.encode(...actual)).to.eql(expected);
2333
+ });
2334
+ });
2335
+ });
2336
+ describe('decode()', () => {
2337
+ const examples = [
2338
+ [
2339
+ {
2340
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2341
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2342
+ collAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2343
+ collAssetId: 10,
2344
+ debtAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2345
+ debtAssetId: 20,
2346
+ closeType: CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
2347
+ },
2348
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2349
+ ],
2350
+ ];
2351
+ examples.forEach(([expected, actual]) => {
2352
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2353
+ expect(subDataService.aaveV4CloseSubData.decode(actual)).to.eql(expected);
2354
+ });
2355
+ });
2356
+ });
2357
+ });
2358
+ describe('When testing subDataService.aaveV4CollateralSwitchSubData', () => {
2359
+ describe('encode()', () => {
2360
+ const examples = [
2361
+ [
2362
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2363
+ [
2364
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2365
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
2366
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
2367
+ '1000000000000000000'
2368
+ ]
2369
+ ],
2370
+ ];
2371
+ examples.forEach(([expected, actual]) => {
2372
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2373
+ expect(subDataService.aaveV4CollateralSwitchSubData.encode(...actual)).to.eql(expected);
2374
+ });
2375
+ });
2376
+ });
2377
+ describe('decode()', () => {
2378
+ const examples = [
2379
+ [
2380
+ {
2381
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2382
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2383
+ fromAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2384
+ fromAssetId: 10,
2385
+ toAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2386
+ toAssetId: 20,
2387
+ amountToSwitch: '1000000000000000000'
2388
+ },
2389
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"],
2390
+ ],
2391
+ ];
2392
+ examples.forEach(([expected, actual]) => {
2393
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2394
+ expect(subDataService.aaveV4CollateralSwitchSubData.decode(actual)).to.eql(expected);
2395
+ });
2396
+ });
2397
+ });
2398
+ });
2399
+ });