@defisaver/automation-sdk 3.0.4 → 3.0.5

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 (143) 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 +41 -41
  6. package/.tests.sh +2 -2
  7. package/README.md +41 -41
  8. package/esm/abis/Erc20.json +223 -223
  9. package/esm/abis/SubStorage.json +17 -17
  10. package/esm/abis/UniMulticall.json +14 -14
  11. package/esm/abis/index.d.ts +9 -9
  12. package/esm/abis/index.js +30 -30
  13. package/esm/abis/legacy_AaveV2Subscriptions.json +8 -8
  14. package/esm/abis/legacy_AuthCheck.json +8 -8
  15. package/esm/abis/legacy_CompoundV2Subscriptions.json +9 -9
  16. package/esm/abis/legacy_MakerSubscriptions.json +9 -9
  17. package/esm/automation/private/Automation.d.ts +12 -12
  18. package/esm/automation/private/Automation.js +42 -42
  19. package/esm/automation/private/LegacyAutomation.d.ts +25 -25
  20. package/esm/automation/private/LegacyAutomation.js +118 -118
  21. package/esm/automation/private/LegacyProtocol.d.ts +22 -22
  22. package/esm/automation/private/LegacyProtocol.js +41 -41
  23. package/esm/automation/private/LegacyProtocol.test.d.ts +1 -1
  24. package/esm/automation/private/LegacyProtocol.test.js +25 -25
  25. package/esm/automation/private/Protocol.d.ts +22 -22
  26. package/esm/automation/private/Protocol.js +41 -41
  27. package/esm/automation/private/Protocol.test.d.ts +1 -1
  28. package/esm/automation/private/Protocol.test.js +25 -25
  29. package/esm/automation/private/StrategiesAutomation.d.ts +33 -33
  30. package/esm/automation/private/StrategiesAutomation.js +181 -181
  31. package/esm/automation/private/StrategiesAutomation.test.d.ts +1 -1
  32. package/esm/automation/private/StrategiesAutomation.test.js +671 -671
  33. package/esm/automation/public/ArbitrumStrategies.d.ts +5 -5
  34. package/esm/automation/public/ArbitrumStrategies.js +13 -13
  35. package/esm/automation/public/EthereumStrategies.d.ts +5 -5
  36. package/esm/automation/public/EthereumStrategies.js +13 -13
  37. package/esm/automation/public/OptimismStrategies.d.ts +5 -5
  38. package/esm/automation/public/OptimismStrategies.js +13 -13
  39. package/esm/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
  40. package/esm/automation/public/legacy/LegacyAaveAutomation.js +20 -20
  41. package/esm/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
  42. package/esm/automation/public/legacy/LegacyCompoundAutomation.js +20 -20
  43. package/esm/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
  44. package/esm/automation/public/legacy/LegacyMakerAutomation.js +20 -20
  45. package/esm/configuration.d.ts +1 -1
  46. package/esm/configuration.js +12 -12
  47. package/esm/constants/index.d.ts +45 -45
  48. package/esm/constants/index.js +395 -385
  49. package/esm/index.d.ts +22 -22
  50. package/esm/index.js +63 -63
  51. package/esm/services/contractService.d.ts +12 -12
  52. package/esm/services/contractService.js +54 -54
  53. package/esm/services/ethereumService.d.ts +7 -7
  54. package/esm/services/ethereumService.js +49 -49
  55. package/esm/services/ethereumService.test.d.ts +1 -1
  56. package/esm/services/ethereumService.test.js +242 -242
  57. package/esm/services/strategiesService.d.ts +2 -2
  58. package/esm/services/strategiesService.js +701 -698
  59. package/esm/services/strategiesService.test.d.ts +1 -1
  60. package/esm/services/strategiesService.test.js +110 -110
  61. package/esm/services/strategySubService.d.ts +87 -87
  62. package/esm/services/strategySubService.js +257 -252
  63. package/esm/services/strategySubService.test.d.ts +1 -1
  64. package/esm/services/strategySubService.test.js +892 -890
  65. package/esm/services/subDataService.d.ts +181 -181
  66. package/esm/services/subDataService.js +442 -442
  67. package/esm/services/subDataService.test.d.ts +1 -1
  68. package/esm/services/subDataService.test.js +1223 -1223
  69. package/esm/services/triggerService.d.ts +191 -191
  70. package/esm/services/triggerService.js +367 -367
  71. package/esm/services/triggerService.test.d.ts +1 -1
  72. package/esm/services/triggerService.test.js +926 -926
  73. package/esm/services/utils.d.ts +25 -25
  74. package/esm/services/utils.js +131 -131
  75. package/esm/services/utils.test.d.ts +1 -1
  76. package/esm/services/utils.test.js +376 -376
  77. package/esm/types/contracts/generated/Erc20.d.ts +53 -53
  78. package/esm/types/contracts/generated/Erc20.js +5 -5
  79. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
  80. package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +5 -5
  81. package/esm/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
  82. package/esm/types/contracts/generated/Legacy_AuthCheck.js +5 -5
  83. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
  84. package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +5 -5
  85. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
  86. package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +5 -5
  87. package/esm/types/contracts/generated/SubStorage.d.ts +114 -114
  88. package/esm/types/contracts/generated/SubStorage.js +5 -5
  89. package/esm/types/contracts/generated/UniMulticall.d.ts +55 -55
  90. package/esm/types/contracts/generated/UniMulticall.js +5 -5
  91. package/esm/types/contracts/generated/index.d.ts +7 -7
  92. package/esm/types/contracts/generated/index.js +2 -2
  93. package/esm/types/contracts/generated/types.d.ts +54 -54
  94. package/esm/types/contracts/generated/types.js +2 -2
  95. package/esm/types/enums.d.ts +160 -158
  96. package/esm/types/enums.js +180 -178
  97. package/esm/types/index.d.ts +217 -217
  98. package/esm/types/index.js +2 -2
  99. package/package.json +71 -71
  100. package/scripts/generateContractTypes.js +39 -39
  101. package/src/abis/Erc20.json +222 -222
  102. package/src/abis/SubStorage.json +17 -17
  103. package/src/abis/UniMulticall.json +14 -14
  104. package/src/abis/index.ts +28 -28
  105. package/src/abis/legacy_AaveV2Subscriptions.json +7 -7
  106. package/src/abis/legacy_AuthCheck.json +7 -7
  107. package/src/abis/legacy_CompoundV2Subscriptions.json +8 -8
  108. package/src/abis/legacy_MakerSubscriptions.json +8 -8
  109. package/src/automation/private/Automation.ts +44 -44
  110. package/src/automation/private/LegacyAutomation.ts +135 -135
  111. package/src/automation/private/LegacyProtocol.test.ts +23 -23
  112. package/src/automation/private/LegacyProtocol.ts +51 -51
  113. package/src/automation/private/Protocol.test.ts +23 -23
  114. package/src/automation/private/Protocol.ts +51 -51
  115. package/src/automation/private/StrategiesAutomation.test.ts +663 -663
  116. package/src/automation/private/StrategiesAutomation.ts +242 -242
  117. package/src/automation/public/ArbitrumStrategies.ts +10 -10
  118. package/src/automation/public/EthereumStrategies.ts +10 -10
  119. package/src/automation/public/OptimismStrategies.ts +10 -10
  120. package/src/automation/public/legacy/LegacyAaveAutomation.ts +20 -20
  121. package/src/automation/public/legacy/LegacyCompoundAutomation.ts +20 -20
  122. package/src/automation/public/legacy/LegacyMakerAutomation.ts +20 -20
  123. package/src/configuration.ts +8 -8
  124. package/src/constants/index.ts +409 -399
  125. package/src/index.ts +38 -38
  126. package/src/services/contractService.ts +77 -77
  127. package/src/services/ethereumService.test.ts +257 -257
  128. package/src/services/ethereumService.ts +69 -69
  129. package/src/services/strategiesService.test.ts +105 -105
  130. package/src/services/strategiesService.ts +905 -901
  131. package/src/services/strategySubService.test.ts +1063 -1060
  132. package/src/services/strategySubService.ts +496 -492
  133. package/src/services/subDataService.test.ts +1324 -1324
  134. package/src/services/subDataService.ts +594 -593
  135. package/src/services/triggerService.test.ts +1004 -1004
  136. package/src/services/triggerService.ts +449 -449
  137. package/src/services/utils.test.ts +430 -430
  138. package/src/services/utils.ts +103 -103
  139. package/src/types/enums.ts +174 -172
  140. package/src/types/index.ts +262 -262
  141. package/tsconfig.json +79 -79
  142. package/umd/index.js +41 -24
  143. package/webpack.umd.js +52 -52
@@ -1,1324 +1,1324 @@
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
- } from './subDataService';
35
-
36
- describe('Feature: subDataService.ts', () => {
37
-
38
- describe('When testing subDataService.makerRepayFromSavingsSubData', () => {
39
- describe('encode()', () => {
40
- const examples: Array<[SubData, [vaultId: number, targetRatioPercentage: number, chainId: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress]]> = [
41
- [
42
- [
43
- '0x000000000000000000000000000000000000000000000000000000000000007b', '0x00000000000000000000000000000000000000000000000010a741a462780000',
44
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
45
- ],
46
- [123, 120, ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e')]
47
- ],
48
- ];
49
-
50
- examples.forEach(([expected, actual]) => {
51
- it(`Given ${actual} should return expected value: ${expected}`, () => {
52
- expect(makerRepayFromSavingsSubData.encode(...actual)).to.eql(expected);
53
- });
54
- });
55
- });
56
-
57
- describe('decode()', () => {
58
- const examples: Array<[{ vaultId: number, daiAddr: string, mcdManagerAddr: string, targetRatio: number }, SubData]> = [
59
- [
60
- {
61
- vaultId: 123,
62
- daiAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
63
- mcdManagerAddr: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
64
- targetRatio: 120,
65
- },
66
- [
67
- '0x000000000000000000000000000000000000000000000000000000000000007b', '0x00000000000000000000000000000000000000000000000010a741a462780000',
68
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
69
- ],
70
- ],
71
- ];
72
-
73
- examples.forEach(([expected, actual]) => {
74
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
75
- expect(makerRepayFromSavingsSubData.decode(actual)).to.eql(expected);
76
- });
77
- });
78
- });
79
- });
80
-
81
- describe('When testing subDataService.liquityRepayFromSavingsSubData', () => {
82
- describe('decode()', () => {
83
- const examples: Array<[{ targetRatio: number }, SubData]> = [
84
- [
85
- { targetRatio: 120 },
86
- [
87
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x00000000000000000000000000000000000000000000000010a741a462780000',
88
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
89
- ],
90
- ],
91
- ];
92
-
93
- examples.forEach(([expected, actual]) => {
94
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
95
- expect(liquityRepayFromSavingsSubData.decode(actual)).to.eql(expected);
96
- });
97
- });
98
- });
99
- });
100
-
101
- describe('When testing subDataService.makerCloseSubData', () => {
102
- describe('encode()', () => {
103
- const examples: Array<[SubData, [vaultId: number, closeToAssetAddr: EthereumAddress, chainId: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress]]> = [
104
- [
105
- [
106
- '0x0000000000000000000000000000000000000000000000000000000000000141', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
107
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
108
- ],
109
- [321, web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e')]
110
- ],
111
- [
112
- [
113
- '0x00000000000000000000000000000000000000000000000000000000000001a4', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
114
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002439d218133afab8f2b819b1066c7e434ad94e9e',
115
- ],
116
- [420, web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2439d218133AFaB8F2B819B1066c7E434Ad94E9e')]
117
- ],
118
- ];
119
-
120
- examples.forEach(([expected, actual]) => {
121
- it(`Given ${actual} should return expected value: ${expected}`, () => {
122
- expect(makerCloseSubData.encode(...actual)).to.eql(expected);
123
- });
124
- });
125
- });
126
-
127
- describe('decode()', () => {
128
- const examples: Array<[{ vaultId: number, closeToAssetAddr: EthereumAddress }, SubData]> = [
129
- [
130
- {
131
- vaultId: 321,
132
- closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
133
- },
134
- [
135
- '0x0000000000000000000000000000000000000000000000000000000000000141', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
136
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
137
- ],
138
- ],
139
- [
140
- {
141
- vaultId: 420,
142
- closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
143
- },
144
- [
145
- '0x00000000000000000000000000000000000000000000000000000000000001a4', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
146
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002439d218133afab8f2b819b1066c7e434ad94e9e',
147
- ],
148
- ],
149
- ];
150
-
151
- examples.forEach(([expected, actual]) => {
152
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
153
- expect(makerCloseSubData.decode(actual)).to.eql(expected);
154
- });
155
- });
156
- });
157
- });
158
-
159
- describe('When testing subDataService.makerLeverageManagementSubData', () => {
160
- describe('decode()', () => {
161
- const examples: Array<[{ vaultId: number, targetRatio: number }, SubData]> = [
162
- [
163
- { vaultId: 321, targetRatio: 200 },
164
- [
165
- '0x0000000000000000000000000000000000000000000000000000000000000141', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
166
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
167
- ],
168
- ],
169
- ];
170
-
171
- examples.forEach(([expected, actual]) => {
172
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
173
- expect(makerLeverageManagementSubData.decode(actual)).to.eql(expected);
174
- });
175
- });
176
- });
177
- });
178
-
179
- describe('When testing subDataService.liquityLeverageManagementSubData', () => {
180
- describe('decode()', () => {
181
- const examples: Array<[{ targetRatio: number }, SubData]> = [
182
- [
183
- { targetRatio: 200 },
184
- [
185
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
186
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
187
- ],
188
- ],
189
- ];
190
-
191
- examples.forEach(([expected, actual]) => {
192
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
193
- expect(liquityLeverageManagementSubData.decode(actual)).to.eql(expected);
194
- });
195
- });
196
- });
197
- });
198
-
199
- describe('When testing subDataService.liquityCloseSubData', () => {
200
- describe('encode()', () => {
201
- const examples: Array<[SubData, [closeToAssetAddr: EthereumAddress, chainId: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress]]> = [
202
- [
203
- [
204
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
205
- ],
206
- [web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address)]
207
- ],
208
- [
209
- [
210
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
211
- ],
212
- [web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address), ChainId.Ethereum]
213
- ],
214
- ];
215
-
216
- examples.forEach(([expected, actual]) => {
217
- it(`Given ${actual} should return expected value: ${expected}`, () => {
218
- expect(liquityCloseSubData.encode(...actual)).to.eql(expected);
219
- });
220
- });
221
- });
222
-
223
- describe('decode()', () => {
224
- const examples: Array<[{ closeToAssetAddr: EthereumAddress, debtAddr: string }, SubData]> = [
225
- [
226
- {
227
- closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
228
- debtAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
229
- },
230
- [
231
- '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
232
- ],
233
- ],
234
- [
235
- {
236
- closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
237
- debtAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
238
- },
239
- [
240
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
241
- ],
242
- ],
243
- ];
244
-
245
- examples.forEach(([expected, actual]) => {
246
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
247
- expect(liquityCloseSubData.decode(actual)).to.eql(expected);
248
- });
249
- });
250
- });
251
- });
252
-
253
- describe('When testing subDataService.aaveV2LeverageManagementSubData', () => {
254
- describe('encode()', () => {
255
- const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
256
- [
257
- [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],
258
- [160, 220, 180, 190, true]
259
- ],
260
- [
261
- [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],
262
- [160, 200, 180, 190, false]
263
- ],
264
- ];
265
-
266
- examples.forEach(([expected, actual]) => {
267
- it(`Given ${actual} should return expected value: ${expected}`, () => {
268
- expect(aaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
269
- });
270
- });
271
- });
272
-
273
- describe('decode()', () => {
274
- const examples: Array<[{ targetRatio: number }, SubData]> = [
275
- [
276
- { targetRatio: 200 },
277
- ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
278
- ],
279
- [
280
- { targetRatio: 123 },
281
- ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
282
- ],
283
- ];
284
-
285
- examples.forEach(([expected, actual]) => {
286
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
287
- expect(aaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
288
- });
289
- });
290
- });
291
- });
292
-
293
- describe('When testing subDataService.aaveV3LeverageManagementSubData', () => {
294
- describe('decode()', () => {
295
- const examples: Array<[{ targetRatio: number }, SubData]> = [
296
- [
297
- { targetRatio: 200 },
298
- ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
299
- ],
300
- [
301
- { targetRatio: 123 },
302
- ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
303
- ],
304
- ];
305
-
306
- examples.forEach(([expected, actual]) => {
307
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
308
- expect(aaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
309
- });
310
- });
311
- });
312
- });
313
-
314
- describe('When testing subDataService.aaveV3QuotePriceSubData', () => {
315
- describe('encode()', () => {
316
- const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress]]> = [
317
- [
318
- [
319
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
320
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
321
- '0x0000000000000000000000000000000000000000000000000000000000000000',
322
- ],
323
- [
324
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
325
- 2,
326
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
327
- 4,
328
- ]
329
- ],
330
- [
331
- [
332
- '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
333
- '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
334
- '0x0000000000000000000000000000000000000000000000000000000000000000',
335
- ],
336
- [
337
- web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
338
- 6,
339
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
340
- 2,
341
- ]
342
- ],
343
- ];
344
-
345
- examples.forEach(([expected, actual]) => {
346
- it(`Given ${actual} should return expected value: ${expected}`, () => {
347
- expect(aaveV3QuotePriceSubData.encode(...actual)).to.eql(expected);
348
- });
349
- });
350
- });
351
-
352
- describe('decode()', () => {
353
- const examples: Array<[{ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number }, SubData]> = [
354
- [
355
- {
356
- collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
357
- collAssetId: 2,
358
- debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
359
- debtAssetId: 4,
360
- },
361
- [
362
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
363
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
364
- '0x0000000000000000000000000000000000000000000000000000000000000000',
365
- ],
366
- ],
367
- [
368
- {
369
- collAsset: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
370
- collAssetId: 6,
371
- debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
372
- debtAssetId: 2,
373
- },
374
- [
375
- '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
376
- '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
377
- '0x0000000000000000000000000000000000000000000000000000000000000000',
378
- ],
379
- ],
380
- ];
381
-
382
- examples.forEach(([expected, actual]) => {
383
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
384
- expect(aaveV3QuotePriceSubData.decode(actual)).to.eql(expected);
385
- });
386
- });
387
- });
388
- });
389
-
390
- describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
391
- describe('encode()', () => {
392
- const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
393
- [
394
- [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],
395
- [160, 220, 180, 190, true]
396
- ],
397
- [
398
- [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],
399
- [160, 200, 180, 190, false]
400
- ],
401
- ];
402
-
403
- examples.forEach(([expected, actual]) => {
404
- it(`Given ${actual} should return expected value: ${expected}`, () => {
405
- expect(compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
406
- });
407
- });
408
- });
409
-
410
- describe('decode()', () => {
411
- const examples: Array<[{ targetRatio: number }, SubData]> = [
412
- [
413
- { targetRatio: 200 },
414
- ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
415
- ],
416
- [
417
- { targetRatio: 123 },
418
- ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
419
- ],
420
- ];
421
-
422
- examples.forEach(([expected, actual]) => {
423
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
424
- expect(compoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
425
- });
426
- });
427
- });
428
- });
429
-
430
- describe('When testing subDataService.compoundV3LeverageManagementSubData', () => {
431
- describe('encode()', () => {
432
- 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]]> = [
433
- [
434
- [
435
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
436
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
437
- new Dec(160).mul(1e16).toString(),
438
- new Dec(220).mul(1e16).toString(),
439
- new Dec(180).mul(1e16).toString(),
440
- new Dec(190).mul(1e16).toString(),
441
- true, false,
442
- ],
443
- [
444
- web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
445
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
446
- 160, 220, 180, 190,
447
- true, false,
448
- ]
449
- ],
450
- [
451
- [
452
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
453
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
454
- new Dec(160).mul(1e16).toString(),
455
- new Dec(210).mul(1e16).toString(),
456
- new Dec(180).mul(1e16).toString(),
457
- new Dec(190).mul(1e16).toString(),
458
- false, true,
459
- ],
460
- [
461
- web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
462
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
463
- 160, 210, 180, 190,
464
- false, true,
465
- ]
466
- ],
467
- ];
468
-
469
- examples.forEach(([expected, actual]) => {
470
- it(`Given ${actual} should return expected value: ${expected}`, () => {
471
- expect(compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
472
- });
473
- });
474
- });
475
-
476
- describe('decode()', () => {
477
- const examples: Array<[{ targetRatio: number }, SubData]> = [
478
- [
479
- { targetRatio: 123 },
480
- [
481
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
482
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
483
- ],
484
- ],
485
- [
486
- { targetRatio: 200 },
487
- [
488
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
489
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
490
- ],
491
- ],
492
- ];
493
-
494
- examples.forEach(([expected, actual]) => {
495
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
496
- expect(compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
497
- });
498
- });
499
- });
500
- });
501
-
502
- describe('When testing subDataService.morphoAaveV2LeverageManagementSubData', () => {
503
- describe('encode()', () => {
504
- const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
505
- [
506
- [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],
507
- [160, 220, 180, 190, true]
508
- ],
509
- [
510
- [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],
511
- [160, 200, 180, 190, false]
512
- ],
513
- ];
514
-
515
- examples.forEach(([expected, actual]) => {
516
- it(`Given ${actual} should return expected value: ${expected}`, () => {
517
- expect(morphoAaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
518
- });
519
- });
520
- });
521
-
522
- describe('decode()', () => {
523
- const examples: Array<[{ targetRatio: number }, SubData]> = [
524
- [
525
- { targetRatio: 200 },
526
- ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
527
- ],
528
- [
529
- { targetRatio: 123 },
530
- ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
531
- ],
532
- ];
533
-
534
- examples.forEach(([expected, actual]) => {
535
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
536
- expect(morphoAaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
537
- });
538
- });
539
- });
540
- });
541
-
542
- describe('When testing subDataService.cBondsRebondSubData', () => {
543
- describe('encode()', () => {
544
- const examples: Array<[SubData, [bondId: number | string]]> = [
545
- [
546
- ['0x00000000000000000000000000000000000000000000000000000000000000c8'],
547
- [200]
548
- ],
549
- [
550
- ['0x000000000000000000000000000000000000000000000000000000000000a119'],
551
- [41241]
552
- ],
553
- ];
554
-
555
- examples.forEach(([expected, actual]) => {
556
- it(`Given ${actual} should return expected value: ${expected}`, () => {
557
- expect(cBondsRebondSubData.encode(...actual)).to.eql(expected);
558
- });
559
- });
560
- });
561
-
562
- describe('decode()', () => {
563
- const examples: Array<[{ bondId: string }, SubData]> = [
564
- [
565
- { bondId: '200' },
566
- ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x00000000000000000000000000000000000000000000000000000000000000c8'],
567
- ],
568
- [
569
- { bondId: '41241' },
570
- ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000000000000000000000000000000000000000a119'],
571
- ],
572
- ];
573
-
574
- examples.forEach(([expected, actual]) => {
575
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
576
- expect(cBondsRebondSubData.decode(actual)).to.eql(expected);
577
- });
578
- });
579
- });
580
- });
581
-
582
- describe('When testing subDataService.liquityPaybackUsingChickenBondSubData', () => {
583
- describe('encode()', () => {
584
- const examples: Array<[SubData, [sourceId: string, sourceType: number, chainId?: ChainId]]> = [
585
- [
586
- [
587
- '0x0000000000000000000000000000000000000000000000000000000000001076', '0x0000000000000000000000000000000000000000000000000000000000000000',
588
- '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
589
- ],
590
- ['4214', 0, ChainId.Ethereum]
591
- ],
592
- [
593
- [
594
- '0x00000000000000000000000000000000000000000000000000000000000002b8', '0x0000000000000000000000000000000000000000000000000000000000000001',
595
- '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
596
- ],
597
- ['696', 1]
598
- ],
599
- ];
600
-
601
- examples.forEach(([expected, actual]) => {
602
- it(`Given ${actual} should return expected value: ${expected}`, () => {
603
- expect(liquityPaybackUsingChickenBondSubData.encode(...actual)).to.eql(expected);
604
- });
605
- });
606
- });
607
-
608
- describe('decode()', () => {
609
- const examples: Array<[{ sourceId: string, sourceType: string }, SubData]> = [
610
- [
611
- { sourceId: '4214', sourceType: '0' },
612
- [
613
- '0x0000000000000000000000000000000000000000000000000000000000001076', '0x0000000000000000000000000000000000000000000000000000000000000000',
614
- '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
615
- ],
616
- ],
617
- [
618
- { sourceId: '696', sourceType: '1' },
619
- [
620
- '0x00000000000000000000000000000000000000000000000000000000000002b8', '0x0000000000000000000000000000000000000000000000000000000000000001',
621
- '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
622
- ],
623
- ],
624
- ];
625
-
626
- examples.forEach(([expected, actual]) => {
627
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
628
- expect(liquityPaybackUsingChickenBondSubData.decode(actual)).to.eql(expected);
629
- });
630
- });
631
- });
632
- });
633
-
634
- describe('When testing subDataService.exchangeDcaSubData', () => {
635
- describe('encode()', () => {
636
- const examples: Array<[SubData, [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, interval: number]]> = [
637
- [
638
- [
639
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
640
- '0x0000000000000000000000000000000000000000000000000000000000000853', '0x0000000000000000000000000000000000000000000000000000000000231860'
641
- ],
642
- [
643
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
644
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
645
- '2131',
646
- 2300000,
647
- ]
648
- ],
649
- [
650
- [
651
- '0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f', '0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4',
652
- '0x00000000000000000000000000000000000000000000000000000000003eddd7', '0x0000000000000000000000000000000000000000000000000000000008f57500'
653
- ],
654
- [
655
- web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
656
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
657
- '4120023',
658
- 150304000,
659
- ]
660
- ],
661
- ];
662
-
663
- examples.forEach(([expected, actual]) => {
664
- it(`Given ${actual} should return expected value: ${expected}`, () => {
665
- expect(exchangeDcaSubData.encode(...actual)).to.eql(expected);
666
- });
667
- });
668
- });
669
-
670
- describe('decode()', () => {
671
- const examples: Array<[{ fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, interval: string }, [SubData, ChainId]]> = [
672
- [
673
- {
674
- fromToken: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
675
- toToken: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
676
- amount: '0.000000000000002131',
677
- interval: '2300000',
678
- },
679
- [
680
- [
681
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
682
- '0x0000000000000000000000000000000000000000000000000000000000000853', '0x0000000000000000000000000000000000000000000000000000000000231860'
683
- ],
684
- ChainId.Ethereum
685
- ],
686
- ],
687
- [
688
- {
689
- fromToken: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
690
- toToken: web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
691
- amount: '0.04120023',
692
- interval: '150304000',
693
- },
694
- [
695
- [
696
- '0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f', '0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4',
697
- '0x00000000000000000000000000000000000000000000000000000000003eddd7', '0x0000000000000000000000000000000000000000000000000000000008f57500'
698
- ],
699
- ChainId.Arbitrum
700
- ]
701
- ],
702
- ];
703
-
704
- examples.forEach(([expected, actual]) => {
705
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
706
- expect(exchangeDcaSubData.decode(...actual)).to.eql(expected);
707
- });
708
- });
709
- });
710
- });
711
-
712
- describe('When testing subDataService.exchangeLimitOrderSubData', () => {
713
- describe('encode()', () => {
714
- const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string], [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType]]> = [
715
- [
716
- [
717
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
718
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
719
- '2131',
720
- '0.53123',
721
- '1696590921159',
722
- `${OrderType.STOP_LOSS}`
723
- ],
724
- [
725
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
726
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
727
- '2131',
728
- '0.53123',
729
- 1696590921159,
730
- OrderType.STOP_LOSS
731
- ]
732
- ],
733
- [
734
- [
735
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
736
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
737
- '2131',
738
- '0.43123',
739
- '1646590921159',
740
- `${OrderType.TAKE_PROFIT}`
741
- ],
742
- [
743
- web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
744
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
745
- '2131',
746
- '0.43123',
747
- 1646590921159,
748
- OrderType.TAKE_PROFIT
749
- ]
750
- ],
751
- ];
752
-
753
- examples.forEach(([expected, actual]) => {
754
- it(`Given ${actual} should return expected value: ${expected}`, () => {
755
- expect(exchangeLimitOrderSubData.encode(...actual)).to.eql(expected);
756
- });
757
- });
758
- });
759
-
760
- describe('decode()', () => {
761
- const examples: Array<[{ fromToken: EthereumAddress, toToken: EthereumAddress, amount: string }, [SubData, ChainId]]> = [
762
- [
763
- {
764
- fromToken: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
765
- toToken: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
766
- amount: '0.000000000000002131',
767
- },
768
- [
769
- [
770
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
771
- '0x0000000000000000000000000000000000000000000000000000000000000853', '0x0000000000000000000000000000000000000000000000000000000000231860'
772
- ],
773
- ChainId.Ethereum
774
- ],
775
- ],
776
- [
777
- {
778
- fromToken: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
779
- toToken: web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
780
- amount: '0.04120023',
781
- },
782
- [
783
- [
784
- '0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f', '0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4',
785
- '0x00000000000000000000000000000000000000000000000000000000003eddd7', '0x0000000000000000000000000000000000000000000000000000000008f57500'
786
- ],
787
- ChainId.Arbitrum
788
- ]
789
- ],
790
- ];
791
-
792
- examples.forEach(([expected, actual]) => {
793
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
794
- expect(exchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
795
- });
796
- });
797
- });
798
- });
799
-
800
- describe('When testing subDataService.sparkLeverageManagementSubData', () => {
801
- describe('decode()', () => {
802
- const examples: Array<[{ targetRatio: number }, SubData]> = [
803
- [
804
- { targetRatio: 200 },
805
- ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
806
- ],
807
- [
808
- { targetRatio: 123 },
809
- ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
810
- ],
811
- ];
812
-
813
- examples.forEach(([expected, actual]) => {
814
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
815
- expect(sparkLeverageManagementSubData.decode(actual)).to.eql(expected);
816
- });
817
- });
818
- });
819
- });
820
-
821
- describe('When testing subDataService.sparkQuotePriceSubData', () => {
822
- describe('encode()', () => {
823
- const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress]]> = [
824
- [
825
- [
826
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
827
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
828
- '0x0000000000000000000000000000000000000000000000000000000000000000',
829
- ],
830
- [
831
- web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
832
- 2,
833
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
834
- 4,
835
- ]
836
- ],
837
- [
838
- [
839
- '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
840
- '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
841
- '0x0000000000000000000000000000000000000000000000000000000000000000',
842
- ],
843
- [
844
- web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
845
- 6,
846
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
847
- 2,
848
- ]
849
- ],
850
- ];
851
-
852
- examples.forEach(([expected, actual]) => {
853
- it(`Given ${actual} should return expected value: ${expected}`, () => {
854
- expect(sparkQuotePriceSubData.encode(...actual)).to.eql(expected);
855
- });
856
- });
857
- });
858
-
859
- describe('decode()', () => {
860
- const examples: Array<[{ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number }, SubData]> = [
861
- [
862
- {
863
- collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
864
- collAssetId: 2,
865
- debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
866
- debtAssetId: 4,
867
- },
868
- [
869
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
870
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
871
- '0x0000000000000000000000000000000000000000000000000000000000000000',
872
- ],
873
- ],
874
- [
875
- {
876
- collAsset: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
877
- collAssetId: 6,
878
- debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
879
- debtAssetId: 2,
880
- },
881
- [
882
- '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
883
- '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
884
- '0x0000000000000000000000000000000000000000000000000000000000000000',
885
- ],
886
- ],
887
- ];
888
-
889
- examples.forEach(([expected, actual]) => {
890
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
891
- expect(sparkQuotePriceSubData.decode(actual)).to.eql(expected);
892
- });
893
- });
894
- });
895
- });
896
-
897
- describe('When testing subDataService.liquityDsrPaybackSubData', () => {
898
- describe('encode()', () => {
899
- const examples: Array<[SubData, [targetRatio: number]]> = [
900
- [
901
- [
902
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
903
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
904
- ],
905
- [123]
906
- ],
907
- [
908
- [
909
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
910
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
911
- ],
912
- [420]
913
- ],
914
- ];
915
-
916
- examples.forEach(([expected, actual]) => {
917
- it(`Given ${actual} should return expected value: ${expected}`, () => {
918
- expect(liquityDsrPaybackSubData.encode(...actual)).to.eql(expected);
919
- });
920
- });
921
- });
922
-
923
- describe('decode()', () => {
924
- const examples: Array<[{ targetRatio: number }, SubData]> = [
925
- [
926
- {
927
- targetRatio: 123,
928
- },
929
- [
930
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
931
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
932
- ],
933
- ],
934
- [
935
- {
936
- targetRatio: 420,
937
- },
938
- [
939
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
940
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
941
- ],
942
- ],
943
- ];
944
-
945
- examples.forEach(([expected, actual]) => {
946
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
947
- expect(liquityDsrPaybackSubData.decode(actual)).to.eql(expected);
948
- });
949
- });
950
- });
951
- });
952
-
953
- describe('When testing subDataService.liquityDsrSupplySubData', () => {
954
- describe('encode()', () => {
955
- const examples: Array<[SubData, [targetRatio: number]]> = [
956
- [
957
- [
958
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
959
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
960
- ],
961
- [320]
962
- ],
963
- [
964
- [
965
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001eab7f4a799d0000',
966
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
967
- ],
968
- [221]
969
- ],
970
- ];
971
-
972
- examples.forEach(([expected, actual]) => {
973
- it(`Given ${actual} should return expected value: ${expected}`, () => {
974
- expect(liquityDsrSupplySubData.encode(...actual)).to.eql(expected);
975
- });
976
- });
977
- });
978
-
979
- describe('decode()', () => {
980
- const examples: Array<[{ targetRatio: number }, SubData]> = [
981
- [
982
- {
983
- targetRatio: 320,
984
- },
985
- [
986
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
987
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
988
- ],
989
- ],
990
- [
991
- {
992
- targetRatio: 221,
993
- },
994
- [
995
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001eab7f4a799d0000',
996
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
997
- ],
998
- ],
999
- ];
1000
-
1001
- examples.forEach(([expected, actual]) => {
1002
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1003
- expect(liquityDsrSupplySubData.decode(actual)).to.eql(expected);
1004
- });
1005
- });
1006
- });
1007
- });
1008
-
1009
- describe('When testing subDataService.liquityDebtInFrontRepaySubData', () => {
1010
- describe('encode()', () => {
1011
- const examples: Array<[SubData, [targetRatioIncrease: number]]> = [
1012
- [
1013
- [
1014
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1015
- '0x000000000000000000000000000000000000000000000000016345785d8a0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
1016
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1017
- ],
1018
- [10]
1019
- ],
1020
- [
1021
- [
1022
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1023
- '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
1024
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1025
- ],
1026
- [45]
1027
- ],
1028
- ];
1029
-
1030
- examples.forEach(([expected, actual]) => {
1031
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1032
- expect(liquityDebtInFrontRepaySubData.encode(...actual)).to.eql(expected);
1033
- });
1034
- });
1035
- });
1036
-
1037
- describe('decode()', () => {
1038
- const examples: Array<[{ targetRatioIncrease: number }, SubData]> = [
1039
- [
1040
- {
1041
- targetRatioIncrease: 10,
1042
- },
1043
- [
1044
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1045
- '0x000000000000000000000000000000000000000000000000016345785d8a0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
1046
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1047
- ],
1048
- ],
1049
- [
1050
- {
1051
- targetRatioIncrease: 45,
1052
- },
1053
- [
1054
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1055
- '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
1056
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1057
- ],
1058
- ],
1059
- ];
1060
-
1061
- examples.forEach(([expected, actual]) => {
1062
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1063
- expect(liquityDebtInFrontRepaySubData.decode(actual)).to.eql(expected);
1064
- });
1065
- });
1066
- });
1067
- });
1068
-
1069
- describe('When testing subDataService.crvUSDLeverageManagementSubData', () => {
1070
- describe('encode()', () => {
1071
- const examples: Array<[SubData, [controller: EthereumAddress, ratioState: RatioState, targetRatio: number, collToken: EthereumAddress, crvUSD: EthereumAddress]]> = [
1072
- [
1073
- [
1074
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1075
- '0x0000000000000000000000000000000000000000000000000000000000000001',
1076
- '0x00000000000000000000000000000000000000000000000010a741a462780000',
1077
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1078
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1079
- ],
1080
- ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', RatioState.UNDER, 120, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E'],
1081
- ],
1082
- [
1083
- [
1084
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1085
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1086
- '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1087
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1088
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1089
- ],
1090
- ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', RatioState.OVER, 180, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E']
1091
- ],
1092
- ];
1093
- examples.forEach(([expected, actual]) => {
1094
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1095
- expect(crvUSDLeverageManagementSubData.encode(...actual)).to.eql(expected);
1096
- });
1097
- });
1098
- });
1099
- describe('decode()', () => {
1100
- const examples: Array<[{
1101
- controller: EthereumAddress,
1102
- targetRatio: number,
1103
- }, SubData]> = [
1104
- [
1105
- {
1106
- controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1107
- targetRatio: 120,
1108
- },
1109
- ['0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635', '0x0000000000000000000000000000000000000000000000000000000000000001', '0x00000000000000000000000000000000000000000000000010a741a462780000', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',],
1110
- ],
1111
- [
1112
- {
1113
- controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1114
- targetRatio: 180,
1115
- },
1116
- ['0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x00000000000000000000000000000000000000000000000018fae27693b40000', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',],
1117
- ],
1118
- ];
1119
-
1120
- examples.forEach(([expected, actual]) => {
1121
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1122
- expect(crvUSDLeverageManagementSubData.decode(actual)).to.eql(expected);
1123
- });
1124
- });
1125
- });
1126
- });
1127
-
1128
- describe('When testing subDataService.crvUSDPaybackSubData', () => {
1129
- describe('encode()', () => {
1130
- const examples: Array<[SubData, [controller: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress]]> = [
1131
- [
1132
- [
1133
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1134
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1135
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1136
- '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1137
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1138
- ],
1139
- ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280', '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280', '20000', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E'],
1140
- ]
1141
- ];
1142
- examples.forEach(([expected, actual]) => {
1143
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1144
- expect(crvUSDPaybackSubData.encode(...actual)).to.eql(expected);
1145
- });
1146
- });
1147
- });
1148
- describe('decode()', () => {
1149
- const examples: Array<[{
1150
- controller: EthereumAddress,
1151
- addressToPullTokensFrom: EthereumAddress,
1152
- positionOwner: EthereumAddress,
1153
- paybackAmount: string,
1154
- }, SubData]> = [
1155
- [
1156
- {
1157
- controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1158
- addressToPullTokensFrom: '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280',
1159
- positionOwner: '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280',
1160
- paybackAmount: '20000'
1161
- },
1162
- [
1163
- '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1164
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1165
- '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1166
- '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1167
- '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1168
- ]
1169
- ]
1170
- ];
1171
-
1172
- examples.forEach(([expected, actual]) => {
1173
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1174
- expect(crvUSDPaybackSubData.decode(actual)).to.eql(expected);
1175
- });
1176
- });
1177
- });
1178
- });
1179
-
1180
- describe('When testing subDataService.compoundV3L2LeverageManagementSubData', () => {
1181
- describe('encode()', () => {
1182
- const examples: Array<[
1183
- string,
1184
- [market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
1185
- ]> = [
1186
- [
1187
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
1188
- [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 190, true]
1189
- ],
1190
- [
1191
- '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee000000',
1192
- [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 110, false]
1193
- ],
1194
- ];
1195
-
1196
- examples.forEach(([expected, actual]) => {
1197
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1198
- expect(compoundV3L2LeverageManagementSubData.encode(...actual)).to.eql(expected);
1199
- });
1200
- });
1201
- });
1202
- describe('decode()', () => {
1203
- const examples: Array<[{ targetRatio: number }, SubData]> = [
1204
- [
1205
- { targetRatio: 200 },
1206
- [
1207
- '0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000213d212133AFaB8F2B829B1066c7E43cAd94E2c',
1208
- '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1209
- ],
1210
- ],
1211
- [
1212
- { targetRatio: 123 },
1213
- [
1214
- '0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000413d212133AFaB8F2B829B1066c7E43cAd94E2c',
1215
- '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
1216
- ],
1217
- ],
1218
- ];
1219
-
1220
- examples.forEach(([expected, actual]) => {
1221
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1222
- expect(compoundV3L2LeverageManagementSubData.decode(actual)).to.eql(expected);
1223
- });
1224
- });
1225
- });
1226
- });
1227
-
1228
- describe('When testing subDataService.morphoBlueLeverageManagementSubData', () => {
1229
- describe('encode()', () => {
1230
- const examples: Array<[
1231
- SubData,
1232
- [loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, user: EthereumAddress],
1233
- ]> = [
1234
- [
1235
- [
1236
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1237
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1238
- '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1239
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1240
- '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1241
- '0x0000000000000000000000000000000000000000000000000000000000000001',
1242
- '0x00000000000000000000000000000000000000000000000010a741a462780000',
1243
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1244
- ],
1245
- [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '945000000000000000', RatioState.UNDER, 120, web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c')]
1246
- ],
1247
- [
1248
- [
1249
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1250
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1251
- '0x00000000000000000000000048f7e36eb6b826b2df4b2e630b62cd25e89e40e2',
1252
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1253
- '0x0000000000000000000000000000000000000000000000000bef55718ad60000',
1254
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1255
- '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1256
- '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c',
1257
- ],
1258
- [web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '860000000000000000', RatioState.OVER, 200, web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c')]
1259
- ],
1260
- ];
1261
-
1262
- examples.forEach(([expected, actual]) => {
1263
- it(`Given ${actual} should return expected value: ${expected}`, () => {
1264
- expect(morphoBlueLeverageManagementSubData.encode(...actual)).to.eql(expected);
1265
- });
1266
- });
1267
- });
1268
-
1269
- describe('decode()', () => {
1270
- const examples: Array<[{ collToken: EthereumAddress, loanToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, targetRatio: number, user: EthereumAddress }, SubData]> = [
1271
- [
1272
- {
1273
- 'collToken': '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1274
- 'irm': '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1275
- 'lltv': '945000000000000000',
1276
- 'loanToken': '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1277
- 'oracle': '0x2a01EB9496094dA03c4E364Def50f5aD1280AD72',
1278
- 'targetRatio': 120,
1279
- 'user': '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
1280
- },
1281
- [
1282
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1283
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1284
- '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1285
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1286
- '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1287
- '0x0000000000000000000000000000000000000000000000000000000000000001',
1288
- '0x00000000000000000000000000000000000000000000000010a741a462780000',
1289
- '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1290
- ],
1291
- ],
1292
- [
1293
- {
1294
- 'collToken': '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1295
- 'irm': '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1296
- 'lltv': '860000000000000000',
1297
- 'loanToken': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
1298
- 'oracle': '0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2',
1299
- 'targetRatio': 200,
1300
- 'user': '0x0043d218133aFaB8F2b829B106633E434aD94e2C',
1301
- },
1302
- [
1303
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1304
- '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1305
- '0x00000000000000000000000048f7e36eb6b826b2df4b2e630b62cd25e89e40e2',
1306
- '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1307
- '0x0000000000000000000000000000000000000000000000000bef55718ad60000',
1308
- '0x0000000000000000000000000000000000000000000000000000000000000000',
1309
- '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1310
- '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c',
1311
- ],
1312
- ],
1313
- ];
1314
-
1315
- examples.forEach(([expected, actual]) => {
1316
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1317
- expect(morphoBlueLeverageManagementSubData.decode(actual)).to.eql(expected);
1318
- });
1319
- });
1320
- });
1321
- });
1322
-
1323
-
1324
- });
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
+ } from './subDataService';
35
+
36
+ describe('Feature: subDataService.ts', () => {
37
+
38
+ describe('When testing subDataService.makerRepayFromSavingsSubData', () => {
39
+ describe('encode()', () => {
40
+ const examples: Array<[SubData, [vaultId: number, targetRatioPercentage: number, chainId: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress]]> = [
41
+ [
42
+ [
43
+ '0x000000000000000000000000000000000000000000000000000000000000007b', '0x00000000000000000000000000000000000000000000000010a741a462780000',
44
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
45
+ ],
46
+ [123, 120, ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e')]
47
+ ],
48
+ ];
49
+
50
+ examples.forEach(([expected, actual]) => {
51
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
52
+ expect(makerRepayFromSavingsSubData.encode(...actual)).to.eql(expected);
53
+ });
54
+ });
55
+ });
56
+
57
+ describe('decode()', () => {
58
+ const examples: Array<[{ vaultId: number, daiAddr: string, mcdManagerAddr: string, targetRatio: number }, SubData]> = [
59
+ [
60
+ {
61
+ vaultId: 123,
62
+ daiAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
63
+ mcdManagerAddr: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
64
+ targetRatio: 120,
65
+ },
66
+ [
67
+ '0x000000000000000000000000000000000000000000000000000000000000007b', '0x00000000000000000000000000000000000000000000000010a741a462780000',
68
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
69
+ ],
70
+ ],
71
+ ];
72
+
73
+ examples.forEach(([expected, actual]) => {
74
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
75
+ expect(makerRepayFromSavingsSubData.decode(actual)).to.eql(expected);
76
+ });
77
+ });
78
+ });
79
+ });
80
+
81
+ describe('When testing subDataService.liquityRepayFromSavingsSubData', () => {
82
+ describe('decode()', () => {
83
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
84
+ [
85
+ { targetRatio: 120 },
86
+ [
87
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x00000000000000000000000000000000000000000000000010a741a462780000',
88
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
89
+ ],
90
+ ],
91
+ ];
92
+
93
+ examples.forEach(([expected, actual]) => {
94
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
95
+ expect(liquityRepayFromSavingsSubData.decode(actual)).to.eql(expected);
96
+ });
97
+ });
98
+ });
99
+ });
100
+
101
+ describe('When testing subDataService.makerCloseSubData', () => {
102
+ describe('encode()', () => {
103
+ const examples: Array<[SubData, [vaultId: number, closeToAssetAddr: EthereumAddress, chainId: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress]]> = [
104
+ [
105
+ [
106
+ '0x0000000000000000000000000000000000000000000000000000000000000141', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
107
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
108
+ ],
109
+ [321, web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e')]
110
+ ],
111
+ [
112
+ [
113
+ '0x00000000000000000000000000000000000000000000000000000000000001a4', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
114
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002439d218133afab8f2b819b1066c7e434ad94e9e',
115
+ ],
116
+ [420, web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2439d218133AFaB8F2B819B1066c7E434Ad94E9e')]
117
+ ],
118
+ ];
119
+
120
+ examples.forEach(([expected, actual]) => {
121
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
122
+ expect(makerCloseSubData.encode(...actual)).to.eql(expected);
123
+ });
124
+ });
125
+ });
126
+
127
+ describe('decode()', () => {
128
+ const examples: Array<[{ vaultId: number, closeToAssetAddr: EthereumAddress }, SubData]> = [
129
+ [
130
+ {
131
+ vaultId: 321,
132
+ closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
133
+ },
134
+ [
135
+ '0x0000000000000000000000000000000000000000000000000000000000000141', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
136
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
137
+ ],
138
+ ],
139
+ [
140
+ {
141
+ vaultId: 420,
142
+ closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
143
+ },
144
+ [
145
+ '0x00000000000000000000000000000000000000000000000000000000000001a4', '0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
146
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000002439d218133afab8f2b819b1066c7e434ad94e9e',
147
+ ],
148
+ ],
149
+ ];
150
+
151
+ examples.forEach(([expected, actual]) => {
152
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
153
+ expect(makerCloseSubData.decode(actual)).to.eql(expected);
154
+ });
155
+ });
156
+ });
157
+ });
158
+
159
+ describe('When testing subDataService.makerLeverageManagementSubData', () => {
160
+ describe('decode()', () => {
161
+ const examples: Array<[{ vaultId: number, targetRatio: number }, SubData]> = [
162
+ [
163
+ { vaultId: 321, targetRatio: 200 },
164
+ [
165
+ '0x0000000000000000000000000000000000000000000000000000000000000141', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
166
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
167
+ ],
168
+ ],
169
+ ];
170
+
171
+ examples.forEach(([expected, actual]) => {
172
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
173
+ expect(makerLeverageManagementSubData.decode(actual)).to.eql(expected);
174
+ });
175
+ });
176
+ });
177
+ });
178
+
179
+ describe('When testing subDataService.liquityLeverageManagementSubData', () => {
180
+ describe('decode()', () => {
181
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
182
+ [
183
+ { targetRatio: 200 },
184
+ [
185
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
186
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
187
+ ],
188
+ ],
189
+ ];
190
+
191
+ examples.forEach(([expected, actual]) => {
192
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
193
+ expect(liquityLeverageManagementSubData.decode(actual)).to.eql(expected);
194
+ });
195
+ });
196
+ });
197
+ });
198
+
199
+ describe('When testing subDataService.liquityCloseSubData', () => {
200
+ describe('encode()', () => {
201
+ const examples: Array<[SubData, [closeToAssetAddr: EthereumAddress, chainId: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress]]> = [
202
+ [
203
+ [
204
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
205
+ ],
206
+ [web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address)]
207
+ ],
208
+ [
209
+ [
210
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
211
+ ],
212
+ [web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address), ChainId.Ethereum]
213
+ ],
214
+ ];
215
+
216
+ examples.forEach(([expected, actual]) => {
217
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
218
+ expect(liquityCloseSubData.encode(...actual)).to.eql(expected);
219
+ });
220
+ });
221
+ });
222
+
223
+ describe('decode()', () => {
224
+ const examples: Array<[{ closeToAssetAddr: EthereumAddress, debtAddr: string }, SubData]> = [
225
+ [
226
+ {
227
+ closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
228
+ debtAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
229
+ },
230
+ [
231
+ '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
232
+ ],
233
+ ],
234
+ [
235
+ {
236
+ closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
237
+ debtAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
238
+ },
239
+ [
240
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
241
+ ],
242
+ ],
243
+ ];
244
+
245
+ examples.forEach(([expected, actual]) => {
246
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
247
+ expect(liquityCloseSubData.decode(actual)).to.eql(expected);
248
+ });
249
+ });
250
+ });
251
+ });
252
+
253
+ describe('When testing subDataService.aaveV2LeverageManagementSubData', () => {
254
+ describe('encode()', () => {
255
+ const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
256
+ [
257
+ [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],
258
+ [160, 220, 180, 190, true]
259
+ ],
260
+ [
261
+ [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],
262
+ [160, 200, 180, 190, false]
263
+ ],
264
+ ];
265
+
266
+ examples.forEach(([expected, actual]) => {
267
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
268
+ expect(aaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
269
+ });
270
+ });
271
+ });
272
+
273
+ describe('decode()', () => {
274
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
275
+ [
276
+ { targetRatio: 200 },
277
+ ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
278
+ ],
279
+ [
280
+ { targetRatio: 123 },
281
+ ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
282
+ ],
283
+ ];
284
+
285
+ examples.forEach(([expected, actual]) => {
286
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
287
+ expect(aaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
288
+ });
289
+ });
290
+ });
291
+ });
292
+
293
+ describe('When testing subDataService.aaveV3LeverageManagementSubData', () => {
294
+ describe('decode()', () => {
295
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
296
+ [
297
+ { targetRatio: 200 },
298
+ ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
299
+ ],
300
+ [
301
+ { targetRatio: 123 },
302
+ ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
303
+ ],
304
+ ];
305
+
306
+ examples.forEach(([expected, actual]) => {
307
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
308
+ expect(aaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
309
+ });
310
+ });
311
+ });
312
+ });
313
+
314
+ describe('When testing subDataService.aaveV3QuotePriceSubData', () => {
315
+ describe('encode()', () => {
316
+ const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress]]> = [
317
+ [
318
+ [
319
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
320
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
321
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
322
+ ],
323
+ [
324
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
325
+ 2,
326
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
327
+ 4,
328
+ ]
329
+ ],
330
+ [
331
+ [
332
+ '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
333
+ '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
334
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
335
+ ],
336
+ [
337
+ web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
338
+ 6,
339
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
340
+ 2,
341
+ ]
342
+ ],
343
+ ];
344
+
345
+ examples.forEach(([expected, actual]) => {
346
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
347
+ expect(aaveV3QuotePriceSubData.encode(...actual)).to.eql(expected);
348
+ });
349
+ });
350
+ });
351
+
352
+ describe('decode()', () => {
353
+ const examples: Array<[{ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number }, SubData]> = [
354
+ [
355
+ {
356
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
357
+ collAssetId: 2,
358
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
359
+ debtAssetId: 4,
360
+ },
361
+ [
362
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
363
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
364
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
365
+ ],
366
+ ],
367
+ [
368
+ {
369
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
370
+ collAssetId: 6,
371
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
372
+ debtAssetId: 2,
373
+ },
374
+ [
375
+ '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
376
+ '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
377
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
378
+ ],
379
+ ],
380
+ ];
381
+
382
+ examples.forEach(([expected, actual]) => {
383
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
384
+ expect(aaveV3QuotePriceSubData.decode(actual)).to.eql(expected);
385
+ });
386
+ });
387
+ });
388
+ });
389
+
390
+ describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
391
+ describe('encode()', () => {
392
+ const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
393
+ [
394
+ [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],
395
+ [160, 220, 180, 190, true]
396
+ ],
397
+ [
398
+ [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],
399
+ [160, 200, 180, 190, false]
400
+ ],
401
+ ];
402
+
403
+ examples.forEach(([expected, actual]) => {
404
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
405
+ expect(compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
406
+ });
407
+ });
408
+ });
409
+
410
+ describe('decode()', () => {
411
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
412
+ [
413
+ { targetRatio: 200 },
414
+ ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
415
+ ],
416
+ [
417
+ { targetRatio: 123 },
418
+ ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
419
+ ],
420
+ ];
421
+
422
+ examples.forEach(([expected, actual]) => {
423
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
424
+ expect(compoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
425
+ });
426
+ });
427
+ });
428
+ });
429
+
430
+ describe('When testing subDataService.compoundV3LeverageManagementSubData', () => {
431
+ describe('encode()', () => {
432
+ 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]]> = [
433
+ [
434
+ [
435
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
436
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
437
+ new Dec(160).mul(1e16).toString(),
438
+ new Dec(220).mul(1e16).toString(),
439
+ new Dec(180).mul(1e16).toString(),
440
+ new Dec(190).mul(1e16).toString(),
441
+ true, false,
442
+ ],
443
+ [
444
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
445
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
446
+ 160, 220, 180, 190,
447
+ true, false,
448
+ ]
449
+ ],
450
+ [
451
+ [
452
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
453
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
454
+ new Dec(160).mul(1e16).toString(),
455
+ new Dec(210).mul(1e16).toString(),
456
+ new Dec(180).mul(1e16).toString(),
457
+ new Dec(190).mul(1e16).toString(),
458
+ false, true,
459
+ ],
460
+ [
461
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
462
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
463
+ 160, 210, 180, 190,
464
+ false, true,
465
+ ]
466
+ ],
467
+ ];
468
+
469
+ examples.forEach(([expected, actual]) => {
470
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
471
+ expect(compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
472
+ });
473
+ });
474
+ });
475
+
476
+ describe('decode()', () => {
477
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
478
+ [
479
+ { targetRatio: 123 },
480
+ [
481
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
482
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
483
+ ],
484
+ ],
485
+ [
486
+ { targetRatio: 200 },
487
+ [
488
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
489
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
490
+ ],
491
+ ],
492
+ ];
493
+
494
+ examples.forEach(([expected, actual]) => {
495
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
496
+ expect(compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
497
+ });
498
+ });
499
+ });
500
+ });
501
+
502
+ describe('When testing subDataService.morphoAaveV2LeverageManagementSubData', () => {
503
+ describe('encode()', () => {
504
+ const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
505
+ [
506
+ [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],
507
+ [160, 220, 180, 190, true]
508
+ ],
509
+ [
510
+ [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],
511
+ [160, 200, 180, 190, false]
512
+ ],
513
+ ];
514
+
515
+ examples.forEach(([expected, actual]) => {
516
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
517
+ expect(morphoAaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
518
+ });
519
+ });
520
+ });
521
+
522
+ describe('decode()', () => {
523
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
524
+ [
525
+ { targetRatio: 200 },
526
+ ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
527
+ ],
528
+ [
529
+ { targetRatio: 123 },
530
+ ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
531
+ ],
532
+ ];
533
+
534
+ examples.forEach(([expected, actual]) => {
535
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
536
+ expect(morphoAaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
537
+ });
538
+ });
539
+ });
540
+ });
541
+
542
+ describe('When testing subDataService.cBondsRebondSubData', () => {
543
+ describe('encode()', () => {
544
+ const examples: Array<[SubData, [bondId: number | string]]> = [
545
+ [
546
+ ['0x00000000000000000000000000000000000000000000000000000000000000c8'],
547
+ [200]
548
+ ],
549
+ [
550
+ ['0x000000000000000000000000000000000000000000000000000000000000a119'],
551
+ [41241]
552
+ ],
553
+ ];
554
+
555
+ examples.forEach(([expected, actual]) => {
556
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
557
+ expect(cBondsRebondSubData.encode(...actual)).to.eql(expected);
558
+ });
559
+ });
560
+ });
561
+
562
+ describe('decode()', () => {
563
+ const examples: Array<[{ bondId: string }, SubData]> = [
564
+ [
565
+ { bondId: '200' },
566
+ ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x00000000000000000000000000000000000000000000000000000000000000c8'],
567
+ ],
568
+ [
569
+ { bondId: '41241' },
570
+ ['0x0000000000000000000000000000000000000000000000000000000000000000', '0x000000000000000000000000000000000000000000000000000000000000a119'],
571
+ ],
572
+ ];
573
+
574
+ examples.forEach(([expected, actual]) => {
575
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
576
+ expect(cBondsRebondSubData.decode(actual)).to.eql(expected);
577
+ });
578
+ });
579
+ });
580
+ });
581
+
582
+ describe('When testing subDataService.liquityPaybackUsingChickenBondSubData', () => {
583
+ describe('encode()', () => {
584
+ const examples: Array<[SubData, [sourceId: string, sourceType: number, chainId?: ChainId]]> = [
585
+ [
586
+ [
587
+ '0x0000000000000000000000000000000000000000000000000000000000001076', '0x0000000000000000000000000000000000000000000000000000000000000000',
588
+ '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
589
+ ],
590
+ ['4214', 0, ChainId.Ethereum]
591
+ ],
592
+ [
593
+ [
594
+ '0x00000000000000000000000000000000000000000000000000000000000002b8', '0x0000000000000000000000000000000000000000000000000000000000000001',
595
+ '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
596
+ ],
597
+ ['696', 1]
598
+ ],
599
+ ];
600
+
601
+ examples.forEach(([expected, actual]) => {
602
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
603
+ expect(liquityPaybackUsingChickenBondSubData.encode(...actual)).to.eql(expected);
604
+ });
605
+ });
606
+ });
607
+
608
+ describe('decode()', () => {
609
+ const examples: Array<[{ sourceId: string, sourceType: string }, SubData]> = [
610
+ [
611
+ { sourceId: '4214', sourceType: '0' },
612
+ [
613
+ '0x0000000000000000000000000000000000000000000000000000000000001076', '0x0000000000000000000000000000000000000000000000000000000000000000',
614
+ '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
615
+ ],
616
+ ],
617
+ [
618
+ { sourceId: '696', sourceType: '1' },
619
+ [
620
+ '0x00000000000000000000000000000000000000000000000000000000000002b8', '0x0000000000000000000000000000000000000000000000000000000000000001',
621
+ '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0', '0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3',
622
+ ],
623
+ ],
624
+ ];
625
+
626
+ examples.forEach(([expected, actual]) => {
627
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
628
+ expect(liquityPaybackUsingChickenBondSubData.decode(actual)).to.eql(expected);
629
+ });
630
+ });
631
+ });
632
+ });
633
+
634
+ describe('When testing subDataService.exchangeDcaSubData', () => {
635
+ describe('encode()', () => {
636
+ const examples: Array<[SubData, [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, interval: number]]> = [
637
+ [
638
+ [
639
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
640
+ '0x0000000000000000000000000000000000000000000000000000000000000853', '0x0000000000000000000000000000000000000000000000000000000000231860'
641
+ ],
642
+ [
643
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
644
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
645
+ '2131',
646
+ 2300000,
647
+ ]
648
+ ],
649
+ [
650
+ [
651
+ '0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f', '0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4',
652
+ '0x00000000000000000000000000000000000000000000000000000000003eddd7', '0x0000000000000000000000000000000000000000000000000000000008f57500'
653
+ ],
654
+ [
655
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
656
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
657
+ '4120023',
658
+ 150304000,
659
+ ]
660
+ ],
661
+ ];
662
+
663
+ examples.forEach(([expected, actual]) => {
664
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
665
+ expect(exchangeDcaSubData.encode(...actual)).to.eql(expected);
666
+ });
667
+ });
668
+ });
669
+
670
+ describe('decode()', () => {
671
+ const examples: Array<[{ fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, interval: string }, [SubData, ChainId]]> = [
672
+ [
673
+ {
674
+ fromToken: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
675
+ toToken: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
676
+ amount: '0.000000000000002131',
677
+ interval: '2300000',
678
+ },
679
+ [
680
+ [
681
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
682
+ '0x0000000000000000000000000000000000000000000000000000000000000853', '0x0000000000000000000000000000000000000000000000000000000000231860'
683
+ ],
684
+ ChainId.Ethereum
685
+ ],
686
+ ],
687
+ [
688
+ {
689
+ fromToken: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
690
+ toToken: web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
691
+ amount: '0.04120023',
692
+ interval: '150304000',
693
+ },
694
+ [
695
+ [
696
+ '0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f', '0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4',
697
+ '0x00000000000000000000000000000000000000000000000000000000003eddd7', '0x0000000000000000000000000000000000000000000000000000000008f57500'
698
+ ],
699
+ ChainId.Arbitrum
700
+ ]
701
+ ],
702
+ ];
703
+
704
+ examples.forEach(([expected, actual]) => {
705
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
706
+ expect(exchangeDcaSubData.decode(...actual)).to.eql(expected);
707
+ });
708
+ });
709
+ });
710
+ });
711
+
712
+ describe('When testing subDataService.exchangeLimitOrderSubData', () => {
713
+ describe('encode()', () => {
714
+ const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string], [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType]]> = [
715
+ [
716
+ [
717
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
718
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
719
+ '2131',
720
+ '0.53123',
721
+ '1696590921159',
722
+ `${OrderType.STOP_LOSS}`
723
+ ],
724
+ [
725
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
726
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
727
+ '2131',
728
+ '0.53123',
729
+ 1696590921159,
730
+ OrderType.STOP_LOSS
731
+ ]
732
+ ],
733
+ [
734
+ [
735
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
736
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
737
+ '2131',
738
+ '0.43123',
739
+ '1646590921159',
740
+ `${OrderType.TAKE_PROFIT}`
741
+ ],
742
+ [
743
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
744
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
745
+ '2131',
746
+ '0.43123',
747
+ 1646590921159,
748
+ OrderType.TAKE_PROFIT
749
+ ]
750
+ ],
751
+ ];
752
+
753
+ examples.forEach(([expected, actual]) => {
754
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
755
+ expect(exchangeLimitOrderSubData.encode(...actual)).to.eql(expected);
756
+ });
757
+ });
758
+ });
759
+
760
+ describe('decode()', () => {
761
+ const examples: Array<[{ fromToken: EthereumAddress, toToken: EthereumAddress, amount: string }, [SubData, ChainId]]> = [
762
+ [
763
+ {
764
+ fromToken: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
765
+ toToken: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
766
+ amount: '0.000000000000002131',
767
+ },
768
+ [
769
+ [
770
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
771
+ '0x0000000000000000000000000000000000000000000000000000000000000853', '0x0000000000000000000000000000000000000000000000000000000000231860'
772
+ ],
773
+ ChainId.Ethereum
774
+ ],
775
+ ],
776
+ [
777
+ {
778
+ fromToken: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
779
+ toToken: web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
780
+ amount: '0.04120023',
781
+ },
782
+ [
783
+ [
784
+ '0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f', '0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4',
785
+ '0x00000000000000000000000000000000000000000000000000000000003eddd7', '0x0000000000000000000000000000000000000000000000000000000008f57500'
786
+ ],
787
+ ChainId.Arbitrum
788
+ ]
789
+ ],
790
+ ];
791
+
792
+ examples.forEach(([expected, actual]) => {
793
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
794
+ expect(exchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
795
+ });
796
+ });
797
+ });
798
+ });
799
+
800
+ describe('When testing subDataService.sparkLeverageManagementSubData', () => {
801
+ describe('decode()', () => {
802
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
803
+ [
804
+ { targetRatio: 200 },
805
+ ['0x0000000000000000000000000000000000000000000000001bc16d674ec80000'],
806
+ ],
807
+ [
808
+ { targetRatio: 123 },
809
+ ['0x0000000000000000000000000000000000000000000000001111d67bb1bb0000'],
810
+ ],
811
+ ];
812
+
813
+ examples.forEach(([expected, actual]) => {
814
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
815
+ expect(sparkLeverageManagementSubData.decode(actual)).to.eql(expected);
816
+ });
817
+ });
818
+ });
819
+ });
820
+
821
+ describe('When testing subDataService.sparkQuotePriceSubData', () => {
822
+ describe('encode()', () => {
823
+ const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress]]> = [
824
+ [
825
+ [
826
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
827
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
828
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
829
+ ],
830
+ [
831
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
832
+ 2,
833
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
834
+ 4,
835
+ ]
836
+ ],
837
+ [
838
+ [
839
+ '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
840
+ '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
841
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
842
+ ],
843
+ [
844
+ web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
845
+ 6,
846
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
847
+ 2,
848
+ ]
849
+ ],
850
+ ];
851
+
852
+ examples.forEach(([expected, actual]) => {
853
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
854
+ expect(sparkQuotePriceSubData.encode(...actual)).to.eql(expected);
855
+ });
856
+ });
857
+ });
858
+
859
+ describe('decode()', () => {
860
+ const examples: Array<[{ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number }, SubData]> = [
861
+ [
862
+ {
863
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
864
+ collAssetId: 2,
865
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
866
+ debtAssetId: 4,
867
+ },
868
+ [
869
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000000000000000000000000000000000000000000002',
870
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000000000000000000000000000000000000000000004',
871
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
872
+ ],
873
+ ],
874
+ [
875
+ {
876
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
877
+ collAssetId: 6,
878
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
879
+ debtAssetId: 2,
880
+ },
881
+ [
882
+ '0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529', '0x0000000000000000000000000000000000000000000000000000000000000006',
883
+ '0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831', '0x0000000000000000000000000000000000000000000000000000000000000002',
884
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
885
+ ],
886
+ ],
887
+ ];
888
+
889
+ examples.forEach(([expected, actual]) => {
890
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
891
+ expect(sparkQuotePriceSubData.decode(actual)).to.eql(expected);
892
+ });
893
+ });
894
+ });
895
+ });
896
+
897
+ describe('When testing subDataService.liquityDsrPaybackSubData', () => {
898
+ describe('encode()', () => {
899
+ const examples: Array<[SubData, [targetRatio: number]]> = [
900
+ [
901
+ [
902
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
903
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
904
+ ],
905
+ [123]
906
+ ],
907
+ [
908
+ [
909
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
910
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
911
+ ],
912
+ [420]
913
+ ],
914
+ ];
915
+
916
+ examples.forEach(([expected, actual]) => {
917
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
918
+ expect(liquityDsrPaybackSubData.encode(...actual)).to.eql(expected);
919
+ });
920
+ });
921
+ });
922
+
923
+ describe('decode()', () => {
924
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
925
+ [
926
+ {
927
+ targetRatio: 123,
928
+ },
929
+ [
930
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
931
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
932
+ ],
933
+ ],
934
+ [
935
+ {
936
+ targetRatio: 420,
937
+ },
938
+ [
939
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000003a4965bf58a40000',
940
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
941
+ ],
942
+ ],
943
+ ];
944
+
945
+ examples.forEach(([expected, actual]) => {
946
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
947
+ expect(liquityDsrPaybackSubData.decode(actual)).to.eql(expected);
948
+ });
949
+ });
950
+ });
951
+ });
952
+
953
+ describe('When testing subDataService.liquityDsrSupplySubData', () => {
954
+ describe('encode()', () => {
955
+ const examples: Array<[SubData, [targetRatio: number]]> = [
956
+ [
957
+ [
958
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
959
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
960
+ ],
961
+ [320]
962
+ ],
963
+ [
964
+ [
965
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001eab7f4a799d0000',
966
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
967
+ ],
968
+ [221]
969
+ ],
970
+ ];
971
+
972
+ examples.forEach(([expected, actual]) => {
973
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
974
+ expect(liquityDsrSupplySubData.encode(...actual)).to.eql(expected);
975
+ });
976
+ });
977
+ });
978
+
979
+ describe('decode()', () => {
980
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
981
+ [
982
+ {
983
+ targetRatio: 320,
984
+ },
985
+ [
986
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000002c68af0bb1400000',
987
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
988
+ ],
989
+ ],
990
+ [
991
+ {
992
+ targetRatio: 221,
993
+ },
994
+ [
995
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001eab7f4a799d0000',
996
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
997
+ ],
998
+ ],
999
+ ];
1000
+
1001
+ examples.forEach(([expected, actual]) => {
1002
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1003
+ expect(liquityDsrSupplySubData.decode(actual)).to.eql(expected);
1004
+ });
1005
+ });
1006
+ });
1007
+ });
1008
+
1009
+ describe('When testing subDataService.liquityDebtInFrontRepaySubData', () => {
1010
+ describe('encode()', () => {
1011
+ const examples: Array<[SubData, [targetRatioIncrease: number]]> = [
1012
+ [
1013
+ [
1014
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1015
+ '0x000000000000000000000000000000000000000000000000016345785d8a0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
1016
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1017
+ ],
1018
+ [10]
1019
+ ],
1020
+ [
1021
+ [
1022
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1023
+ '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
1024
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1025
+ ],
1026
+ [45]
1027
+ ],
1028
+ ];
1029
+
1030
+ examples.forEach(([expected, actual]) => {
1031
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1032
+ expect(liquityDebtInFrontRepaySubData.encode(...actual)).to.eql(expected);
1033
+ });
1034
+ });
1035
+ });
1036
+
1037
+ describe('decode()', () => {
1038
+ const examples: Array<[{ targetRatioIncrease: number }, SubData]> = [
1039
+ [
1040
+ {
1041
+ targetRatioIncrease: 10,
1042
+ },
1043
+ [
1044
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1045
+ '0x000000000000000000000000000000000000000000000000016345785d8a0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
1046
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1047
+ ],
1048
+ ],
1049
+ [
1050
+ {
1051
+ targetRatioIncrease: 45,
1052
+ },
1053
+ [
1054
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0',
1055
+ '0x000000000000000000000000000000000000000000000000063eb89da4ed0000', '0x0000000000000000000000000000000000000000000000000000000000000001',
1056
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1057
+ ],
1058
+ ],
1059
+ ];
1060
+
1061
+ examples.forEach(([expected, actual]) => {
1062
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1063
+ expect(liquityDebtInFrontRepaySubData.decode(actual)).to.eql(expected);
1064
+ });
1065
+ });
1066
+ });
1067
+ });
1068
+
1069
+ describe('When testing subDataService.crvUSDLeverageManagementSubData', () => {
1070
+ describe('encode()', () => {
1071
+ const examples: Array<[SubData, [controller: EthereumAddress, ratioState: RatioState, targetRatio: number, collToken: EthereumAddress, crvUSD: EthereumAddress]]> = [
1072
+ [
1073
+ [
1074
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1075
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1076
+ '0x00000000000000000000000000000000000000000000000010a741a462780000',
1077
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1078
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1079
+ ],
1080
+ ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', RatioState.UNDER, 120, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E'],
1081
+ ],
1082
+ [
1083
+ [
1084
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1085
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1086
+ '0x00000000000000000000000000000000000000000000000018fae27693b40000',
1087
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1088
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1089
+ ],
1090
+ ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', RatioState.OVER, 180, '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E']
1091
+ ],
1092
+ ];
1093
+ examples.forEach(([expected, actual]) => {
1094
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1095
+ expect(crvUSDLeverageManagementSubData.encode(...actual)).to.eql(expected);
1096
+ });
1097
+ });
1098
+ });
1099
+ describe('decode()', () => {
1100
+ const examples: Array<[{
1101
+ controller: EthereumAddress,
1102
+ targetRatio: number,
1103
+ }, SubData]> = [
1104
+ [
1105
+ {
1106
+ controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1107
+ targetRatio: 120,
1108
+ },
1109
+ ['0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635', '0x0000000000000000000000000000000000000000000000000000000000000001', '0x00000000000000000000000000000000000000000000000010a741a462780000', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',],
1110
+ ],
1111
+ [
1112
+ {
1113
+ controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1114
+ targetRatio: 180,
1115
+ },
1116
+ ['0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635', '0x0000000000000000000000000000000000000000000000000000000000000000', '0x00000000000000000000000000000000000000000000000018fae27693b40000', '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',],
1117
+ ],
1118
+ ];
1119
+
1120
+ examples.forEach(([expected, actual]) => {
1121
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1122
+ expect(crvUSDLeverageManagementSubData.decode(actual)).to.eql(expected);
1123
+ });
1124
+ });
1125
+ });
1126
+ });
1127
+
1128
+ describe('When testing subDataService.crvUSDPaybackSubData', () => {
1129
+ describe('encode()', () => {
1130
+ const examples: Array<[SubData, [controller: EthereumAddress, addressToPullTokensFrom: EthereumAddress, positionOwner: EthereumAddress, paybackAmount: string, crvUSDAddr: EthereumAddress]]> = [
1131
+ [
1132
+ [
1133
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1134
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1135
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1136
+ '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1137
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1138
+ ],
1139
+ ['0xa920de414ea4ab66b97da1bfe9e6eca7d4219635', '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280', '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280', '20000', '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E'],
1140
+ ]
1141
+ ];
1142
+ examples.forEach(([expected, actual]) => {
1143
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1144
+ expect(crvUSDPaybackSubData.encode(...actual)).to.eql(expected);
1145
+ });
1146
+ });
1147
+ });
1148
+ describe('decode()', () => {
1149
+ const examples: Array<[{
1150
+ controller: EthereumAddress,
1151
+ addressToPullTokensFrom: EthereumAddress,
1152
+ positionOwner: EthereumAddress,
1153
+ paybackAmount: string,
1154
+ }, SubData]> = [
1155
+ [
1156
+ {
1157
+ controller: '0xA920De414eA4Ab66b97dA1bFE9e6EcA7d4219635',
1158
+ addressToPullTokensFrom: '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280',
1159
+ positionOwner: '0xDc0Ad7a48088f1AA55d26f8b36F7C1E827DdD280',
1160
+ paybackAmount: '20000'
1161
+ },
1162
+ [
1163
+ '0x000000000000000000000000a920de414ea4ab66b97da1bfe9e6eca7d4219635',
1164
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1165
+ '0x000000000000000000000000dc0ad7a48088f1aa55d26f8b36f7c1e827ddd280',
1166
+ '0x00000000000000000000000000000000000000000000043c33c1937564800000',
1167
+ '0x000000000000000000000000f939e0a03fb07f59a73314e73794be0e57ac1b4e',
1168
+ ]
1169
+ ]
1170
+ ];
1171
+
1172
+ examples.forEach(([expected, actual]) => {
1173
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1174
+ expect(crvUSDPaybackSubData.decode(actual)).to.eql(expected);
1175
+ });
1176
+ });
1177
+ });
1178
+ });
1179
+
1180
+ describe('When testing subDataService.compoundV3L2LeverageManagementSubData', () => {
1181
+ describe('encode()', () => {
1182
+ const examples: Array<[
1183
+ string,
1184
+ [market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean],
1185
+ ]> = [
1186
+ [
1187
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e000001',
1188
+ [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 190, true]
1189
+ ],
1190
+ [
1191
+ '0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee000000',
1192
+ [web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 110, false]
1193
+ ],
1194
+ ];
1195
+
1196
+ examples.forEach(([expected, actual]) => {
1197
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1198
+ expect(compoundV3L2LeverageManagementSubData.encode(...actual)).to.eql(expected);
1199
+ });
1200
+ });
1201
+ });
1202
+ describe('decode()', () => {
1203
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
1204
+ [
1205
+ { targetRatio: 200 },
1206
+ [
1207
+ '0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000213d212133AFaB8F2B829B1066c7E43cAd94E2c',
1208
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1209
+ ],
1210
+ ],
1211
+ [
1212
+ { targetRatio: 123 },
1213
+ [
1214
+ '0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000413d212133AFaB8F2B829B1066c7E43cAd94E2c',
1215
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
1216
+ ],
1217
+ ],
1218
+ ];
1219
+
1220
+ examples.forEach(([expected, actual]) => {
1221
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1222
+ expect(compoundV3L2LeverageManagementSubData.decode(actual)).to.eql(expected);
1223
+ });
1224
+ });
1225
+ });
1226
+ });
1227
+
1228
+ describe('When testing subDataService.morphoBlueLeverageManagementSubData', () => {
1229
+ describe('encode()', () => {
1230
+ const examples: Array<[
1231
+ SubData,
1232
+ [loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, user: EthereumAddress, isEOA: boolean],
1233
+ ]> = [
1234
+ [
1235
+ [
1236
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1237
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1238
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1239
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1240
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1241
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1242
+ '0x00000000000000000000000000000000000000000000000010a741a462780000',
1243
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1244
+ ],
1245
+ [web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x2a01eb9496094da03c4e364def50f5ad1280ad72'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '945000000000000000', RatioState.UNDER, 120, web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), false]
1246
+ ],
1247
+ [
1248
+ [
1249
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1250
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1251
+ '0x00000000000000000000000048f7e36eb6b826b2df4b2e630b62cd25e89e40e2',
1252
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1253
+ '0x0000000000000000000000000000000000000000000000000bef55718ad60000',
1254
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1255
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1256
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c',
1257
+ ],
1258
+ [web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), '860000000000000000', RatioState.OVER, 200, web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), false]
1259
+ ],
1260
+ ];
1261
+
1262
+ examples.forEach(([expected, actual]) => {
1263
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1264
+ expect(morphoBlueLeverageManagementSubData.encode(...actual)).to.eql(expected);
1265
+ });
1266
+ });
1267
+ });
1268
+
1269
+ describe('decode()', () => {
1270
+ const examples: Array<[{ collToken: EthereumAddress, loanToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, targetRatio: number, user: EthereumAddress }, SubData]> = [
1271
+ [
1272
+ {
1273
+ 'collToken': '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1274
+ 'irm': '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1275
+ 'lltv': '945000000000000000',
1276
+ 'loanToken': '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
1277
+ 'oracle': '0x2a01EB9496094dA03c4E364Def50f5aD1280AD72',
1278
+ 'targetRatio': 120,
1279
+ 'user': '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
1280
+ },
1281
+ [
1282
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
1283
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1284
+ '0x0000000000000000000000002a01eb9496094da03c4e364def50f5ad1280ad72',
1285
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1286
+ '0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
1287
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
1288
+ '0x00000000000000000000000000000000000000000000000010a741a462780000',
1289
+ '0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
1290
+ ],
1291
+ ],
1292
+ [
1293
+ {
1294
+ 'collToken': '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
1295
+ 'irm': '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
1296
+ 'lltv': '860000000000000000',
1297
+ 'loanToken': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
1298
+ 'oracle': '0x48F7E36EB6B826B2dF4B2E630B62Cd25e89E40e2',
1299
+ 'targetRatio': 200,
1300
+ 'user': '0x0043d218133aFaB8F2b829B106633E434aD94e2C',
1301
+ },
1302
+ [
1303
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
1304
+ '0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
1305
+ '0x00000000000000000000000048f7e36eb6b826b2df4b2e630b62cd25e89e40e2',
1306
+ '0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
1307
+ '0x0000000000000000000000000000000000000000000000000bef55718ad60000',
1308
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
1309
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
1310
+ '0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c',
1311
+ ],
1312
+ ],
1313
+ ];
1314
+
1315
+ examples.forEach(([expected, actual]) => {
1316
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1317
+ expect(morphoBlueLeverageManagementSubData.decode(actual)).to.eql(expected);
1318
+ });
1319
+ });
1320
+ });
1321
+ });
1322
+
1323
+
1324
+ });