@defisaver/automation-sdk 2.0.6 → 2.0.8

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 (48) hide show
  1. package/.env.dev +5 -0
  2. package/.tests.sh +3 -0
  3. package/README.md +3 -1
  4. package/esm/automation/private/LegacyProtocol.test.d.ts +1 -0
  5. package/esm/automation/private/LegacyProtocol.test.js +25 -0
  6. package/esm/automation/private/Protocol.test.d.ts +1 -0
  7. package/esm/automation/private/Protocol.test.js +25 -0
  8. package/esm/constants/index.js +5 -0
  9. package/esm/services/contractService.d.ts +3 -2
  10. package/esm/services/contractService.js +7 -1
  11. package/esm/services/ethereumService.test.d.ts +1 -0
  12. package/esm/services/ethereumService.test.js +241 -0
  13. package/esm/services/strategiesService.js +14 -0
  14. package/esm/services/strategiesService.test.d.ts +1 -0
  15. package/esm/services/strategiesService.test.js +108 -0
  16. package/esm/services/strategySubService.d.ts +5 -3
  17. package/esm/services/strategySubService.js +10 -6
  18. package/esm/services/strategySubService.test.d.ts +1 -0
  19. package/esm/services/strategySubService.test.js +692 -0
  20. package/esm/services/subDataService.d.ts +8 -1
  21. package/esm/services/subDataService.js +23 -14
  22. package/esm/services/subDataService.test.d.ts +1 -0
  23. package/esm/services/subDataService.test.js +993 -0
  24. package/esm/services/triggerService.d.ts +7 -0
  25. package/esm/services/triggerService.js +14 -1
  26. package/esm/services/triggerService.test.js +119 -17
  27. package/esm/types/enums.d.ts +4 -2
  28. package/esm/types/enums.js +2 -0
  29. package/esm/types/index.d.ts +8 -2
  30. package/package.json +3 -3
  31. package/src/automation/private/LegacyProtocol.test.ts +24 -0
  32. package/src/automation/private/Protocol.test.ts +24 -0
  33. package/src/constants/index.ts +5 -0
  34. package/src/services/contractService.ts +17 -4
  35. package/src/services/ethereumService.test.ts +256 -0
  36. package/src/services/ethereumService.ts +2 -1
  37. package/src/services/strategiesService.test.ts +103 -0
  38. package/src/services/strategiesService.ts +27 -3
  39. package/src/services/strategySubService.test.ts +835 -0
  40. package/src/services/strategySubService.ts +28 -15
  41. package/src/services/subDataService.test.ts +1063 -0
  42. package/src/services/subDataService.ts +29 -14
  43. package/src/services/triggerService.test.ts +131 -19
  44. package/src/services/triggerService.ts +14 -0
  45. package/src/services/utils.test.ts +1 -1
  46. package/src/types/enums.ts +2 -0
  47. package/src/types/index.ts +14 -3
  48. package/umd/index.js +148 -74
@@ -0,0 +1,1063 @@
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 } from '../types/enums';
7
+ import type { EthereumAddress, SubData } from '../types';
8
+
9
+ import {
10
+ aaveV2LeverageManagementSubData,
11
+ aaveV3LeverageManagementSubData,
12
+ aaveV3QuotePriceSubData,
13
+ cBondsRebondSubData,
14
+ compoundV2LeverageManagementSubData,
15
+ compoundV3LeverageManagementSubData,
16
+ exchangeDcaSubData, exchangeLimitOrderSubData,
17
+ liquityCloseSubData, liquityDsrPaybackSubData, liquityDsrSupplySubData,
18
+ liquityLeverageManagementSubData,
19
+ liquityPaybackUsingChickenBondSubData,
20
+ liquityRepayFromSavingsSubData,
21
+ makerCloseSubData,
22
+ makerLeverageManagementSubData,
23
+ makerRepayFromSavingsSubData,
24
+ morphoAaveV2LeverageManagementSubData,
25
+ sparkLeverageManagementSubData,
26
+ sparkQuotePriceSubData,
27
+ liquityDebtInFrontRepaySubData,
28
+ } from './subDataService';
29
+
30
+ describe('Feature: subDataService.ts', () => {
31
+
32
+ describe('When testing subDataService.makerRepayFromSavingsSubData', () => {
33
+ describe('encode()', () => {
34
+ const examples: Array<[SubData, [vaultId: number, targetRatioPercentage: number, chainId: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress]]> = [
35
+ [
36
+ [
37
+ "0x000000000000000000000000000000000000000000000000000000000000007b", "0x00000000000000000000000000000000000000000000000010a741a462780000",
38
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e",
39
+ ],
40
+ [123, 120, ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e')]
41
+ ],
42
+ ];
43
+
44
+ examples.forEach(([expected, actual]) => {
45
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
46
+ expect(makerRepayFromSavingsSubData.encode(...actual)).to.eql(expected);
47
+ });
48
+ });
49
+ });
50
+
51
+ describe('decode()', () => {
52
+ const examples: Array<[{ vaultId: number, daiAddr: string, mcdManagerAddr: string, targetRatio: number }, SubData]> = [
53
+ [
54
+ {
55
+ vaultId: 123,
56
+ daiAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
57
+ mcdManagerAddr: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
58
+ targetRatio: 120,
59
+ },
60
+ [
61
+ "0x000000000000000000000000000000000000000000000000000000000000007b", "0x00000000000000000000000000000000000000000000000010a741a462780000",
62
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e",
63
+ ],
64
+ ],
65
+ ];
66
+
67
+ examples.forEach(([expected, actual]) => {
68
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
69
+ expect(makerRepayFromSavingsSubData.decode(actual)).to.eql(expected);
70
+ });
71
+ });
72
+ });
73
+ });
74
+
75
+ describe('When testing subDataService.liquityRepayFromSavingsSubData', () => {
76
+ describe('decode()', () => {
77
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
78
+ [
79
+ { targetRatio: 120 },
80
+ [
81
+ "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000010a741a462780000",
82
+ "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000",
83
+ ],
84
+ ],
85
+ ];
86
+
87
+ examples.forEach(([expected, actual]) => {
88
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
89
+ expect(liquityRepayFromSavingsSubData.decode(actual)).to.eql(expected);
90
+ });
91
+ });
92
+ });
93
+ });
94
+
95
+ describe('When testing subDataService.makerCloseSubData', () => {
96
+ describe('encode()', () => {
97
+ const examples: Array<[SubData, [vaultId: number, closeToAssetAddr: EthereumAddress, chainId: ChainId, daiAddr?: EthereumAddress, mcdCdpManagerAddr?: EthereumAddress]]> = [
98
+ [
99
+ [
100
+ "0x0000000000000000000000000000000000000000000000000000000000000141", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
101
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e",
102
+ ],
103
+ [321, web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e')]
104
+ ],
105
+ [
106
+ [
107
+ "0x00000000000000000000000000000000000000000000000000000000000001a4", "0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599",
108
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000002439d218133afab8f2b819b1066c7e434ad94e9e",
109
+ ],
110
+ [420, web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), web3Utils.toChecksumAddress('0x2439d218133AFaB8F2B819B1066c7E434Ad94E9e')]
111
+ ],
112
+ ];
113
+
114
+ examples.forEach(([expected, actual]) => {
115
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
116
+ expect(makerCloseSubData.encode(...actual)).to.eql(expected);
117
+ });
118
+ });
119
+ });
120
+
121
+ describe('decode()', () => {
122
+ const examples: Array<[{ vaultId: number, closeToAssetAddr: EthereumAddress }, SubData]> = [
123
+ [
124
+ {
125
+ vaultId: 321,
126
+ closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
127
+ },
128
+ [
129
+ "0x0000000000000000000000000000000000000000000000000000000000000141", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
130
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e",
131
+ ],
132
+ ],
133
+ [
134
+ {
135
+ vaultId: 420,
136
+ closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
137
+ },
138
+ [
139
+ "0x00000000000000000000000000000000000000000000000000000000000001a4", "0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599",
140
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000002439d218133afab8f2b819b1066c7e434ad94e9e",
141
+ ],
142
+ ],
143
+ ];
144
+
145
+ examples.forEach(([expected, actual]) => {
146
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
147
+ expect(makerCloseSubData.decode(actual)).to.eql(expected);
148
+ });
149
+ });
150
+ });
151
+ });
152
+
153
+ describe('When testing subDataService.makerLeverageManagementSubData', () => {
154
+ describe('decode()', () => {
155
+ const examples: Array<[{ vaultId: number, targetRatio: number }, SubData]> = [
156
+ [
157
+ { vaultId: 321, targetRatio: 200 },
158
+ [
159
+ '0x0000000000000000000000000000000000000000000000000000000000000141', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
160
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
161
+ ],
162
+ ],
163
+ ];
164
+
165
+ examples.forEach(([expected, actual]) => {
166
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
167
+ expect(makerLeverageManagementSubData.decode(actual)).to.eql(expected);
168
+ });
169
+ });
170
+ });
171
+ });
172
+
173
+ describe('When testing subDataService.liquityLeverageManagementSubData', () => {
174
+ describe('decode()', () => {
175
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
176
+ [
177
+ { targetRatio: 200 },
178
+ [
179
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
180
+ '0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000000000000000000000',
181
+ ],
182
+ ],
183
+ ];
184
+
185
+ examples.forEach(([expected, actual]) => {
186
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
187
+ expect(liquityLeverageManagementSubData.decode(actual)).to.eql(expected);
188
+ });
189
+ });
190
+ });
191
+ });
192
+
193
+ describe('When testing subDataService.liquityCloseSubData', () => {
194
+ describe('encode()', () => {
195
+ const examples: Array<[SubData, [closeToAssetAddr: EthereumAddress, chainId: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress]]> = [
196
+ [
197
+ [
198
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0",
199
+ ],
200
+ [web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address), ChainId.Ethereum, web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address)]
201
+ ],
202
+ [
203
+ [
204
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0",
205
+ ],
206
+ [web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address), ChainId.Ethereum]
207
+ ],
208
+ ];
209
+
210
+ examples.forEach(([expected, actual]) => {
211
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
212
+ expect(liquityCloseSubData.encode(...actual)).to.eql(expected);
213
+ });
214
+ });
215
+ });
216
+
217
+ describe('decode()', () => {
218
+ const examples: Array<[{ closeToAssetAddr: EthereumAddress, debtAddr: string }, SubData]> = [
219
+ [
220
+ {
221
+ closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
222
+ debtAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
223
+ },
224
+ [
225
+ "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0", "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0",
226
+ ],
227
+ ],
228
+ [
229
+ {
230
+ closeToAssetAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
231
+ debtAddr: web3Utils.toChecksumAddress(getAssetInfo('LUSD', ChainId.Ethereum).address),
232
+ },
233
+ [
234
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0",
235
+ ],
236
+ ],
237
+ ];
238
+
239
+ examples.forEach(([expected, actual]) => {
240
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
241
+ expect(liquityCloseSubData.decode(actual)).to.eql(expected);
242
+ });
243
+ });
244
+ });
245
+ });
246
+
247
+ describe('When testing subDataService.aaveV2LeverageManagementSubData', () => {
248
+ describe('encode()', () => {
249
+ const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
250
+ [
251
+ [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],
252
+ [160, 220, 180, 190, true]
253
+ ],
254
+ [
255
+ [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],
256
+ [160, 200, 180, 190, false]
257
+ ],
258
+ ];
259
+
260
+ examples.forEach(([expected, actual]) => {
261
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
262
+ expect(aaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
263
+ });
264
+ });
265
+ });
266
+
267
+ describe('decode()', () => {
268
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
269
+ [
270
+ { targetRatio: 200 },
271
+ ["0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000001bc16d674ec80000"],
272
+ ],
273
+ [
274
+ { targetRatio: 123 },
275
+ ["0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000001111d67bb1bb0000"],
276
+ ],
277
+ ];
278
+
279
+ examples.forEach(([expected, actual]) => {
280
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
281
+ expect(aaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
282
+ });
283
+ });
284
+ });
285
+ });
286
+
287
+ describe('When testing subDataService.aaveV3LeverageManagementSubData', () => {
288
+ describe('decode()', () => {
289
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
290
+ [
291
+ { targetRatio: 200 },
292
+ ["0x0000000000000000000000000000000000000000000000001bc16d674ec80000"],
293
+ ],
294
+ [
295
+ { targetRatio: 123 },
296
+ ["0x0000000000000000000000000000000000000000000000001111d67bb1bb0000"],
297
+ ],
298
+ ];
299
+
300
+ examples.forEach(([expected, actual]) => {
301
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
302
+ expect(aaveV3LeverageManagementSubData.decode(actual)).to.eql(expected);
303
+ });
304
+ });
305
+ });
306
+ });
307
+
308
+ describe('When testing subDataService.aaveV3QuotePriceSubData', () => {
309
+ describe('encode()', () => {
310
+ const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress]]> = [
311
+ [
312
+ [
313
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000000000000000000000000000000000000000000002",
314
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000000000000000000000000000000000000000000004",
315
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
316
+ ],
317
+ [
318
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
319
+ 2,
320
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
321
+ 4,
322
+ ]
323
+ ],
324
+ [
325
+ [
326
+ "0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529", "0x0000000000000000000000000000000000000000000000000000000000000006",
327
+ "0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831", "0x0000000000000000000000000000000000000000000000000000000000000002",
328
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
329
+ ],
330
+ [
331
+ web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
332
+ 6,
333
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
334
+ 2,
335
+ ]
336
+ ],
337
+ ];
338
+
339
+ examples.forEach(([expected, actual]) => {
340
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
341
+ expect(aaveV3QuotePriceSubData.encode(...actual)).to.eql(expected);
342
+ });
343
+ });
344
+ });
345
+
346
+ describe('decode()', () => {
347
+ const examples: Array<[{ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number }, SubData]> = [
348
+ [
349
+ {
350
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
351
+ collAssetId: 2,
352
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
353
+ debtAssetId: 4,
354
+ },
355
+ [
356
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000000000000000000000000000000000000000000002",
357
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000000000000000000000000000000000000000000004",
358
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
359
+ ],
360
+ ],
361
+ [
362
+ {
363
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
364
+ collAssetId: 6,
365
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
366
+ debtAssetId: 2,
367
+ },
368
+ [
369
+ "0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529", "0x0000000000000000000000000000000000000000000000000000000000000006",
370
+ "0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831", "0x0000000000000000000000000000000000000000000000000000000000000002",
371
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
372
+ ],
373
+ ],
374
+ ];
375
+
376
+ examples.forEach(([expected, actual]) => {
377
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
378
+ expect(aaveV3QuotePriceSubData.decode(actual)).to.eql(expected);
379
+ });
380
+ });
381
+ });
382
+ });
383
+
384
+ describe('When testing subDataService.compoundV2LeverageManagementSubData', () => {
385
+ describe('encode()', () => {
386
+ const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
387
+ [
388
+ [new Dec(160).mul(1e16).toString(), new Dec(220).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), true],
389
+ [160, 220, 180, 190, true]
390
+ ],
391
+ [
392
+ [new Dec(160).mul(1e16).toString(), new Dec(200).mul(1e16).toString(), new Dec(180).mul(1e16).toString(), new Dec(190).mul(1e16).toString(), false],
393
+ [160, 200, 180, 190, false]
394
+ ],
395
+ ];
396
+
397
+ examples.forEach(([expected, actual]) => {
398
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
399
+ expect(compoundV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
400
+ });
401
+ });
402
+ });
403
+
404
+ describe('decode()', () => {
405
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
406
+ [
407
+ { targetRatio: 200 },
408
+ ["0x0000000000000000000000000000000000000000000000001bc16d674ec80000"],
409
+ ],
410
+ [
411
+ { targetRatio: 123 },
412
+ ["0x0000000000000000000000000000000000000000000000001111d67bb1bb0000"],
413
+ ],
414
+ ];
415
+
416
+ examples.forEach(([expected, actual]) => {
417
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
418
+ expect(compoundV2LeverageManagementSubData.decode(actual)).to.eql(expected);
419
+ });
420
+ });
421
+ });
422
+ });
423
+
424
+ describe('When testing subDataService.compoundV3LeverageManagementSubData', () => {
425
+ describe('encode()', () => {
426
+ 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]]> = [
427
+ [
428
+ [
429
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
430
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
431
+ new Dec(160).mul(1e16).toString(),
432
+ new Dec(220).mul(1e16).toString(),
433
+ new Dec(180).mul(1e16).toString(),
434
+ new Dec(190).mul(1e16).toString(),
435
+ true, false,
436
+ ],
437
+ [
438
+ web3Utils.toChecksumAddress('0x1C0F620155e85491f8D35440eb17538Ca5c55212'),
439
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
440
+ 160, 220, 180, 190,
441
+ true, false,
442
+ ]
443
+ ],
444
+ [
445
+ [
446
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
447
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
448
+ new Dec(160).mul(1e16).toString(),
449
+ new Dec(210).mul(1e16).toString(),
450
+ new Dec(180).mul(1e16).toString(),
451
+ new Dec(190).mul(1e16).toString(),
452
+ false, true,
453
+ ],
454
+ [
455
+ web3Utils.toChecksumAddress('0xaC0F620155e85491f8D35440eb17538Ca5c55212'),
456
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
457
+ 160, 210, 180, 190,
458
+ false, true,
459
+ ]
460
+ ],
461
+ ];
462
+
463
+ examples.forEach(([expected, actual]) => {
464
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
465
+ expect(compoundV3LeverageManagementSubData.encode(...actual)).to.eql(expected);
466
+ });
467
+ });
468
+ });
469
+
470
+ describe('decode()', () => {
471
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
472
+ [
473
+ { targetRatio: 123 },
474
+ [
475
+ "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000",
476
+ "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000001111d67bb1bb0000",
477
+ ],
478
+ ],
479
+ [
480
+ { targetRatio: 200 },
481
+ [
482
+ "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000",
483
+ "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000001bc16d674ec80000",
484
+ ],
485
+ ],
486
+ ];
487
+
488
+ examples.forEach(([expected, actual]) => {
489
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
490
+ expect(compoundV3LeverageManagementSubData.decode(actual)).to.eql(expected);
491
+ });
492
+ });
493
+ });
494
+ });
495
+
496
+ describe('When testing subDataService.morphoAaveV2LeverageManagementSubData', () => {
497
+ describe('encode()', () => {
498
+ const examples: Array<[[string, string, string, string, boolean], [triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean]]> = [
499
+ [
500
+ [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],
501
+ [160, 220, 180, 190, true]
502
+ ],
503
+ [
504
+ [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],
505
+ [160, 200, 180, 190, false]
506
+ ],
507
+ ];
508
+
509
+ examples.forEach(([expected, actual]) => {
510
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
511
+ expect(morphoAaveV2LeverageManagementSubData.encode(...actual)).to.eql(expected);
512
+ });
513
+ });
514
+ });
515
+
516
+ describe('decode()', () => {
517
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
518
+ [
519
+ { targetRatio: 200 },
520
+ ["0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000001bc16d674ec80000"],
521
+ ],
522
+ [
523
+ { targetRatio: 123 },
524
+ ["0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000001111d67bb1bb0000"],
525
+ ],
526
+ ];
527
+
528
+ examples.forEach(([expected, actual]) => {
529
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
530
+ expect(morphoAaveV2LeverageManagementSubData.decode(actual)).to.eql(expected);
531
+ });
532
+ });
533
+ });
534
+ });
535
+
536
+ describe('When testing subDataService.cBondsRebondSubData', () => {
537
+ describe('encode()', () => {
538
+ const examples: Array<[SubData, [bondId: number | string]]> = [
539
+ [
540
+ ["0x00000000000000000000000000000000000000000000000000000000000000c8"],
541
+ [200]
542
+ ],
543
+ [
544
+ ["0x000000000000000000000000000000000000000000000000000000000000a119"],
545
+ [41241]
546
+ ],
547
+ ];
548
+
549
+ examples.forEach(([expected, actual]) => {
550
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
551
+ expect(cBondsRebondSubData.encode(...actual)).to.eql(expected);
552
+ });
553
+ });
554
+ });
555
+
556
+ describe('decode()', () => {
557
+ const examples: Array<[{ bondId: string }, SubData]> = [
558
+ [
559
+ { bondId: '200' },
560
+ ["0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000000000000000000c8"],
561
+ ],
562
+ [
563
+ { bondId: '41241' },
564
+ ["0x0000000000000000000000000000000000000000000000000000000000000000", "0x000000000000000000000000000000000000000000000000000000000000a119"],
565
+ ],
566
+ ];
567
+
568
+ examples.forEach(([expected, actual]) => {
569
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
570
+ expect(cBondsRebondSubData.decode(actual)).to.eql(expected);
571
+ });
572
+ });
573
+ });
574
+ });
575
+
576
+ describe('When testing subDataService.liquityPaybackUsingChickenBondSubData', () => {
577
+ describe('encode()', () => {
578
+ const examples: Array<[SubData, [sourceId: string, sourceType: number, chainId?: ChainId]]> = [
579
+ [
580
+ [
581
+ "0x0000000000000000000000000000000000000000000000000000000000001076", "0x0000000000000000000000000000000000000000000000000000000000000000",
582
+ "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0", "0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3",
583
+ ],
584
+ ['4214', 0, ChainId.Ethereum]
585
+ ],
586
+ [
587
+ [
588
+ "0x00000000000000000000000000000000000000000000000000000000000002b8", "0x0000000000000000000000000000000000000000000000000000000000000001",
589
+ "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0", "0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3",
590
+ ],
591
+ ['696', 1]
592
+ ],
593
+ ];
594
+
595
+ examples.forEach(([expected, actual]) => {
596
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
597
+ expect(liquityPaybackUsingChickenBondSubData.encode(...actual)).to.eql(expected);
598
+ });
599
+ });
600
+ });
601
+
602
+ describe('decode()', () => {
603
+ const examples: Array<[{ sourceId: string, sourceType: string }, SubData]> = [
604
+ [
605
+ { sourceId: '4214', sourceType: '0' },
606
+ [
607
+ "0x0000000000000000000000000000000000000000000000000000000000001076", "0x0000000000000000000000000000000000000000000000000000000000000000",
608
+ "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0", "0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3",
609
+ ],
610
+ ],
611
+ [
612
+ { sourceId: '696', sourceType: '1' },
613
+ [
614
+ "0x00000000000000000000000000000000000000000000000000000000000002b8", "0x0000000000000000000000000000000000000000000000000000000000000001",
615
+ "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0", "0x000000000000000000000000b9d7dddca9a4ac480991865efef82e01273f79c3",
616
+ ],
617
+ ],
618
+ ];
619
+
620
+ examples.forEach(([expected, actual]) => {
621
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
622
+ expect(liquityPaybackUsingChickenBondSubData.decode(actual)).to.eql(expected);
623
+ });
624
+ });
625
+ });
626
+ });
627
+
628
+ describe('When testing subDataService.exchangeDcaSubData', () => {
629
+ describe('encode()', () => {
630
+ const examples: Array<[SubData, [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, interval: number]]> = [
631
+ [
632
+ [
633
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f",
634
+ "0x0000000000000000000000000000000000000000000000000000000000000853", "0x0000000000000000000000000000000000000000000000000000000000231860"
635
+ ],
636
+ [
637
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
638
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
639
+ '2131',
640
+ 2300000,
641
+ ]
642
+ ],
643
+ [
644
+ [
645
+ "0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f", "0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4",
646
+ "0x00000000000000000000000000000000000000000000000000000000003eddd7", "0x0000000000000000000000000000000000000000000000000000000008f57500"
647
+ ],
648
+ [
649
+ web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
650
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
651
+ '4120023',
652
+ 150304000,
653
+ ]
654
+ ],
655
+ ];
656
+
657
+ examples.forEach(([expected, actual]) => {
658
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
659
+ expect(exchangeDcaSubData.encode(...actual)).to.eql(expected);
660
+ });
661
+ });
662
+ });
663
+
664
+ describe('decode()', () => {
665
+ const examples: Array<[{ fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, interval: string }, [SubData, ChainId]]> = [
666
+ [
667
+ {
668
+ fromToken: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
669
+ toToken: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
670
+ amount: '0.000000000000002131',
671
+ interval: '2300000',
672
+ },
673
+ [
674
+ [
675
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f",
676
+ "0x0000000000000000000000000000000000000000000000000000000000000853", "0x0000000000000000000000000000000000000000000000000000000000231860"
677
+ ],
678
+ ChainId.Ethereum
679
+ ],
680
+ ],
681
+ [
682
+ {
683
+ fromToken: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
684
+ toToken: web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
685
+ amount: '0.04120023',
686
+ interval: '150304000',
687
+ },
688
+ [
689
+ [
690
+ "0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f", "0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4",
691
+ "0x00000000000000000000000000000000000000000000000000000000003eddd7", "0x0000000000000000000000000000000000000000000000000000000008f57500"
692
+ ],
693
+ ChainId.Arbitrum
694
+ ]
695
+ ],
696
+ ];
697
+
698
+ examples.forEach(([expected, actual]) => {
699
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
700
+ expect(exchangeDcaSubData.decode(...actual)).to.eql(expected);
701
+ });
702
+ });
703
+ });
704
+ });
705
+
706
+ describe('When testing subDataService.exchangeLimitOrderSubData', () => {
707
+ describe('encode()', () => {
708
+ const examples: Array<[[EthereumAddress, EthereumAddress, string, string, string, string], [fromToken: EthereumAddress, toToken: EthereumAddress, amount: string, targetPrice: string, goodUntil: string | number, orderType: OrderType]]> = [
709
+ [
710
+ [
711
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
712
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
713
+ '2131',
714
+ '0.53123',
715
+ '1696590921159',
716
+ `${OrderType.STOP_LOSS}`
717
+ ],
718
+ [
719
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
720
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
721
+ '2131',
722
+ '0.53123',
723
+ 1696590921159,
724
+ OrderType.STOP_LOSS
725
+ ]
726
+ ],
727
+ [
728
+ [
729
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
730
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
731
+ '2131',
732
+ '0.43123',
733
+ '1646590921159',
734
+ `${OrderType.TAKE_PROFIT}`
735
+ ],
736
+ [
737
+ web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
738
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
739
+ '2131',
740
+ '0.43123',
741
+ 1646590921159,
742
+ OrderType.TAKE_PROFIT
743
+ ]
744
+ ],
745
+ ];
746
+
747
+ examples.forEach(([expected, actual]) => {
748
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
749
+ expect(exchangeLimitOrderSubData.encode(...actual)).to.eql(expected);
750
+ });
751
+ });
752
+ });
753
+
754
+ describe('decode()', () => {
755
+ const examples: Array<[{ fromToken: EthereumAddress, toToken: EthereumAddress, amount: string }, [SubData, ChainId]]> = [
756
+ [
757
+ {
758
+ fromToken: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
759
+ toToken: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
760
+ amount: '0.000000000000002131',
761
+ },
762
+ [
763
+ [
764
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f",
765
+ "0x0000000000000000000000000000000000000000000000000000000000000853", "0x0000000000000000000000000000000000000000000000000000000000231860"
766
+ ],
767
+ ChainId.Ethereum
768
+ ],
769
+ ],
770
+ [
771
+ {
772
+ fromToken: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
773
+ toToken: web3Utils.toChecksumAddress(getAssetInfo('LINK', ChainId.Arbitrum).address),
774
+ amount: '0.04120023',
775
+ },
776
+ [
777
+ [
778
+ "0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f", "0x000000000000000000000000f97f4df75117a78c1a5a0dbb814af92458539fb4",
779
+ "0x00000000000000000000000000000000000000000000000000000000003eddd7", "0x0000000000000000000000000000000000000000000000000000000008f57500"
780
+ ],
781
+ ChainId.Arbitrum
782
+ ]
783
+ ],
784
+ ];
785
+
786
+ examples.forEach(([expected, actual]) => {
787
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
788
+ expect(exchangeLimitOrderSubData.decode(...actual)).to.eql(expected);
789
+ });
790
+ });
791
+ });
792
+ });
793
+
794
+ describe('When testing subDataService.sparkLeverageManagementSubData', () => {
795
+ describe('decode()', () => {
796
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
797
+ [
798
+ { targetRatio: 200 },
799
+ ["0x0000000000000000000000000000000000000000000000001bc16d674ec80000"],
800
+ ],
801
+ [
802
+ { targetRatio: 123 },
803
+ ["0x0000000000000000000000000000000000000000000000001111d67bb1bb0000"],
804
+ ],
805
+ ];
806
+
807
+ examples.forEach(([expected, actual]) => {
808
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
809
+ expect(sparkLeverageManagementSubData.decode(actual)).to.eql(expected);
810
+ });
811
+ });
812
+ });
813
+ });
814
+
815
+ describe('When testing subDataService.sparkQuotePriceSubData', () => {
816
+ describe('encode()', () => {
817
+ const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress]]> = [
818
+ [
819
+ [
820
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000000000000000000000000000000000000000000002",
821
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000000000000000000000000000000000000000000004",
822
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
823
+ ],
824
+ [
825
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
826
+ 2,
827
+ web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
828
+ 4,
829
+ ]
830
+ ],
831
+ [
832
+ [
833
+ "0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529", "0x0000000000000000000000000000000000000000000000000000000000000006",
834
+ "0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831", "0x0000000000000000000000000000000000000000000000000000000000000002",
835
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
836
+ ],
837
+ [
838
+ web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
839
+ 6,
840
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
841
+ 2,
842
+ ]
843
+ ],
844
+ ];
845
+
846
+ examples.forEach(([expected, actual]) => {
847
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
848
+ expect(sparkQuotePriceSubData.encode(...actual)).to.eql(expected);
849
+ });
850
+ });
851
+ });
852
+
853
+ describe('decode()', () => {
854
+ const examples: Array<[{ collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number }, SubData]> = [
855
+ [
856
+ {
857
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
858
+ collAssetId: 2,
859
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
860
+ debtAssetId: 4,
861
+ },
862
+ [
863
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000000000000000000000000000000000000000000002",
864
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000000000000000000000000000000000000000000004",
865
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
866
+ ],
867
+ ],
868
+ [
869
+ {
870
+ collAsset: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Arbitrum).address),
871
+ collAssetId: 6,
872
+ debtAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
873
+ debtAssetId: 2,
874
+ },
875
+ [
876
+ "0x0000000000000000000000005979d7b546e38e414f7e9822514be443a4800529", "0x0000000000000000000000000000000000000000000000000000000000000006",
877
+ "0x000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e5831", "0x0000000000000000000000000000000000000000000000000000000000000002",
878
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
879
+ ],
880
+ ],
881
+ ];
882
+
883
+ examples.forEach(([expected, actual]) => {
884
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
885
+ expect(sparkQuotePriceSubData.decode(actual)).to.eql(expected);
886
+ });
887
+ });
888
+ });
889
+ });
890
+
891
+ describe('When testing subDataService.liquityDsrPaybackSubData', () => {
892
+ describe('encode()', () => {
893
+ const examples: Array<[SubData, [targetRatio: number]]> = [
894
+ [
895
+ [
896
+ "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000001111d67bb1bb0000",
897
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0",
898
+ ],
899
+ [123]
900
+ ],
901
+ [
902
+ [
903
+ "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000003a4965bf58a40000",
904
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0",
905
+ ],
906
+ [420]
907
+ ],
908
+ ];
909
+
910
+ examples.forEach(([expected, actual]) => {
911
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
912
+ expect(liquityDsrPaybackSubData.encode(...actual)).to.eql(expected);
913
+ });
914
+ });
915
+ });
916
+
917
+ describe('decode()', () => {
918
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
919
+ [
920
+ {
921
+ targetRatio: 123,
922
+ },
923
+ [
924
+ "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000001111d67bb1bb0000",
925
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0",
926
+ ],
927
+ ],
928
+ [
929
+ {
930
+ targetRatio: 420,
931
+ },
932
+ [
933
+ "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000003a4965bf58a40000",
934
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0",
935
+ ],
936
+ ],
937
+ ];
938
+
939
+ examples.forEach(([expected, actual]) => {
940
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
941
+ expect(liquityDsrPaybackSubData.decode(actual)).to.eql(expected);
942
+ });
943
+ });
944
+ });
945
+ });
946
+
947
+ describe('When testing subDataService.liquityDsrSupplySubData', () => {
948
+ describe('encode()', () => {
949
+ const examples: Array<[SubData, [targetRatio: number]]> = [
950
+ [
951
+ [
952
+ "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000002c68af0bb1400000",
953
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
954
+ ],
955
+ [320]
956
+ ],
957
+ [
958
+ [
959
+ "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000001eab7f4a799d0000",
960
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
961
+ ],
962
+ [221]
963
+ ],
964
+ ];
965
+
966
+ examples.forEach(([expected, actual]) => {
967
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
968
+ expect(liquityDsrSupplySubData.encode(...actual)).to.eql(expected);
969
+ });
970
+ });
971
+ });
972
+
973
+ describe('decode()', () => {
974
+ const examples: Array<[{ targetRatio: number }, SubData]> = [
975
+ [
976
+ {
977
+ targetRatio: 320,
978
+ },
979
+ [
980
+ "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000002c68af0bb1400000",
981
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
982
+ ],
983
+ ],
984
+ [
985
+ {
986
+ targetRatio: 221,
987
+ },
988
+ [
989
+ "0x0000000000000000000000000000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000000000000001eab7f4a799d0000",
990
+ "0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
991
+ ],
992
+ ],
993
+ ];
994
+
995
+ examples.forEach(([expected, actual]) => {
996
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
997
+ expect(liquityDsrSupplySubData.decode(actual)).to.eql(expected);
998
+ });
999
+ });
1000
+ });
1001
+ });
1002
+
1003
+ describe('When testing subDataService.liquityDebtInFrontRepaySubData', () => {
1004
+ describe('encode()', () => {
1005
+ const examples: Array<[SubData, [targetRatioIncrease: number]]> = [
1006
+ [
1007
+ [
1008
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0",
1009
+ "0x000000000000000000000000000000000000000000000000016345785d8a0000", "0x0000000000000000000000000000000000000000000000000000000000000001",
1010
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
1011
+ ],
1012
+ [10]
1013
+ ],
1014
+ [
1015
+ [
1016
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0",
1017
+ "0x000000000000000000000000000000000000000000000000063eb89da4ed0000", "0x0000000000000000000000000000000000000000000000000000000000000001",
1018
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
1019
+ ],
1020
+ [45]
1021
+ ],
1022
+ ];
1023
+
1024
+ examples.forEach(([expected, actual]) => {
1025
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1026
+ expect(liquityDebtInFrontRepaySubData.encode(...actual)).to.eql(expected);
1027
+ });
1028
+ });
1029
+ });
1030
+
1031
+ describe('decode()', () => {
1032
+ const examples: Array<[{ targetRatioIncrease: number }, SubData]> = [
1033
+ [
1034
+ {
1035
+ targetRatioIncrease: 10,
1036
+ },
1037
+ [
1038
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0",
1039
+ "0x000000000000000000000000000000000000000000000000016345785d8a0000", "0x0000000000000000000000000000000000000000000000000000000000000001",
1040
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
1041
+ ],
1042
+ ],
1043
+ [
1044
+ {
1045
+ targetRatioIncrease: 45,
1046
+ },
1047
+ [
1048
+ "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x0000000000000000000000005f98805a4e8be255a32880fdec7f6728c6568ba0",
1049
+ "0x000000000000000000000000000000000000000000000000063eb89da4ed0000", "0x0000000000000000000000000000000000000000000000000000000000000001",
1050
+ "0x0000000000000000000000000000000000000000000000000000000000000000",
1051
+ ],
1052
+ ],
1053
+ ];
1054
+
1055
+ examples.forEach(([expected, actual]) => {
1056
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1057
+ expect(liquityDebtInFrontRepaySubData.decode(actual)).to.eql(expected);
1058
+ });
1059
+ });
1060
+ });
1061
+ });
1062
+
1063
+ });