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