@defisaver/automation-sdk 2.0.4 → 2.0.6

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.
@@ -0,0 +1,785 @@
1
+ import { expect } from 'chai';
2
+ import { getAssetInfo } from '@defisaver/tokens';
3
+ import * as web3Utils from 'web3-utils';
4
+
5
+ import { ChainId, OrderType, RatioState } from '../types/enums';
6
+ import { EthereumAddress, TriggerData } from '../types';
7
+
8
+ import {
9
+ aaveV2RatioTrigger,
10
+ aaveV3QuotePriceTrigger,
11
+ aaveV3RatioTrigger,
12
+ cBondsRebondTrigger,
13
+ chainlinkPriceTrigger,
14
+ compoundV2RatioTrigger,
15
+ compoundV3RatioTrigger,
16
+ curveUsdBorrowRateTrigger,
17
+ curveUsdSoftLiquidationTrigger,
18
+ exchangeOffchainPriceTrigger,
19
+ exchangeTimestampTrigger,
20
+ liquityDebtInFrontTrigger,
21
+ makerRatioTrigger,
22
+ morphoAaveV2RatioTrigger,
23
+ sparkQuotePriceTrigger,
24
+ sparkRatioTrigger,
25
+ trailingStopTrigger,
26
+ } from './triggerService';
27
+
28
+ describe('Feature: triggerService.ts', () => {
29
+
30
+ describe('When testing triggerService.chainlinkPriceTrigger', () => {
31
+ describe('encode()', () => {
32
+ const examples: Array<[[string], [EthereumAddress, string, RatioState]]> = [
33
+ [
34
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002794ca24000000000000000000000000000000000000000000000000000000000000000000'],
35
+ [getAssetInfo('WETH', ChainId.Ethereum).address, '1700', RatioState.OVER]
36
+ ],
37
+ [
38
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002c3ce1ec000000000000000000000000000000000000000000000000000000000000000001'],
39
+ [getAssetInfo('WETH', ChainId.Ethereum).address, '1900', RatioState.UNDER]
40
+ ],
41
+ ];
42
+
43
+ examples.forEach(([expected, actual]) => {
44
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
45
+ expect(chainlinkPriceTrigger.encode(...actual)).to.eql(expected);
46
+ });
47
+ });
48
+ });
49
+
50
+ describe('decode()', () => {
51
+ const examples: Array<[{ tokenAddr: EthereumAddress, price: string, state: RatioState}, TriggerData]> = [
52
+ [
53
+ { tokenAddr: getAssetInfo('WETH', ChainId.Ethereum).address, price: '1700', state: RatioState.OVER },
54
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002794ca24000000000000000000000000000000000000000000000000000000000000000000'],
55
+ ],
56
+ [
57
+ { tokenAddr: getAssetInfo('WETH', ChainId.Ethereum).address, price: '1900', state: RatioState.UNDER },
58
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000002c3ce1ec000000000000000000000000000000000000000000000000000000000000000001'],
59
+ ],
60
+ ];
61
+
62
+ examples.forEach(([expected, actual]) => {
63
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
64
+ expect(chainlinkPriceTrigger.decode(actual)).to.eql(expected);
65
+ });
66
+ });
67
+ });
68
+ });
69
+
70
+ describe('When testing triggerService.trailingStopTrigger', () => {
71
+ describe('encode()', () => {
72
+ const examples: Array<[[string], [EthereumAddress, number, number]]> = [
73
+ [
74
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000002cb417800000000000000000000000000000000000000000000000000000000000000000a'],
75
+ [getAssetInfo('WETH', ChainId.Ethereum).address, 120, 10]
76
+ ],
77
+ [
78
+ ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000002cb417800000000000000000000000000000000000000000000000000000000000000000c'],
79
+ [getAssetInfo('DAI', ChainId.Ethereum).address, 120, 12]
80
+ ],
81
+ ];
82
+
83
+ examples.forEach(([expected, actual]) => {
84
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
85
+ expect(trailingStopTrigger.encode(...actual)).to.eql(expected);
86
+ });
87
+ });
88
+ });
89
+
90
+ describe('decode()', () => {
91
+ const examples: Array<[{ triggerPercentage: number, tokenAddr: EthereumAddress, roundId: string }, TriggerData]> = [
92
+ [
93
+ { tokenAddr: getAssetInfo('WETH', ChainId.Ethereum).address, triggerPercentage: 120, roundId: '10' },
94
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000002cb417800000000000000000000000000000000000000000000000000000000000000000a'],
95
+ ],
96
+ [
97
+ { tokenAddr: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address), triggerPercentage: 120, roundId: '12' },
98
+ ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f00000000000000000000000000000000000000000000000000000002cb417800000000000000000000000000000000000000000000000000000000000000000c'],
99
+ ],
100
+ ];
101
+
102
+ examples.forEach(([expected, actual]) => {
103
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
104
+ expect(trailingStopTrigger.decode(actual)).to.eql(expected);
105
+ });
106
+ });
107
+ });
108
+ });
109
+
110
+ describe('When testing triggerService.makerRatioTrigger', () => {
111
+ describe('encode()', () => {
112
+ const examples: Array<[[string], [number, number, RatioState]]> = [
113
+ [
114
+ ['0x0000000000000000000000000000000000000000000000000000000000000520000000000000000000000000000000000000000000000000122e0e0f2fc300000000000000000000000000000000000000000000000000000000000000000001'],
115
+ [1312, 131, RatioState.UNDER]
116
+ ],
117
+ [
118
+ ['0x000000000000000000000000000000000000000000000000000000000000a455000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
119
+ [42069, 231, RatioState.OVER]
120
+ ],
121
+ ];
122
+
123
+ examples.forEach(([expected, actual]) => {
124
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
125
+ expect(makerRatioTrigger.encode(...actual)).to.eql(expected);
126
+ });
127
+ });
128
+ });
129
+
130
+ describe('decode()', () => {
131
+ const examples: Array<[{ vaultId: number, ratioState: number, ratio: number }, TriggerData]> = [
132
+ [
133
+ { vaultId: 1312, ratioState: RatioState.UNDER, ratio: 131 },
134
+ ['0x0000000000000000000000000000000000000000000000000000000000000520000000000000000000000000000000000000000000000000122e0e0f2fc300000000000000000000000000000000000000000000000000000000000000000001'],
135
+ ],
136
+ [
137
+ { vaultId: 42069, ratioState: RatioState.OVER, ratio: 231 },
138
+ ['0x000000000000000000000000000000000000000000000000000000000000a455000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
139
+ ],
140
+ ];
141
+
142
+ examples.forEach(([expected, actual]) => {
143
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
144
+ expect(makerRatioTrigger.decode(actual)).to.eql(expected);
145
+ });
146
+ });
147
+ });
148
+ });
149
+
150
+ describe('When testing triggerService.aaveV3RatioTrigger', () => {
151
+ describe('encode()', () => {
152
+ const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
153
+ [
154
+ ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
155
+ [web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E9c'), '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e', 120, RatioState.OVER]
156
+ ],
157
+ [
158
+ ['0x0000000000000000000000000039d218ff3afab8f2b819b1066c7e434ad94e9f000000000000000000000000a97684ead0e402dc232d5a977953df7ecbab3cdb0000000000000000000000000000000000000000000000002c8c35fe210100000000000000000000000000000000000000000000000000000000000000000001'],
159
+ [web3Utils.toChecksumAddress('0x0039d218ff3AFaB8F2B819B1066c7E434Ad94E9f'), '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb', 321, RatioState.UNDER]
160
+ ],
161
+ ];
162
+
163
+ examples.forEach(([expected, actual]) => {
164
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
165
+ expect(aaveV3RatioTrigger.encode(...actual)).to.eql(expected);
166
+ });
167
+ });
168
+ });
169
+
170
+ describe('decode()', () => {
171
+ const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
172
+ [
173
+ { owner: web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E9c'), market: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e', ratio: 120, ratioState: RatioState.OVER },
174
+ ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
175
+ ],
176
+ [
177
+ { owner: web3Utils.toChecksumAddress('0x0039d218ff3AFaB8F2B819B1066c7E434Ad94E9f'), market: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb', ratio: 321, ratioState: RatioState.UNDER },
178
+ ['0x0000000000000000000000000039d218ff3afab8f2b819b1066c7e434ad94e9f000000000000000000000000a97684ead0e402dc232d5a977953df7ecbab3cdb0000000000000000000000000000000000000000000000002c8c35fe210100000000000000000000000000000000000000000000000000000000000000000001'],
179
+ ],
180
+ ];
181
+
182
+ examples.forEach(([expected, actual]) => {
183
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
184
+ expect(aaveV3RatioTrigger.decode(actual)).to.eql(expected);
185
+ });
186
+ });
187
+ });
188
+ });
189
+
190
+ describe('When testing triggerService.morphoAaveV2RatioTrigger', () => {
191
+ describe('encode()', () => {
192
+ const examples: Array<[[string], [owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
193
+ [
194
+ ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e2c0000000000000000000000000000000000000000000000001eab7f4a799d00000000000000000000000000000000000000000000000000000000000000000001'],
195
+ [web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E2c'), 221, RatioState.UNDER]
196
+ ],
197
+ [
198
+ ['0x0000000000000000000000000032d218133afab8f2b819b1066c7e434ad94e2c0000000000000000000000000000000000000000000000003d3377a2837900000000000000000000000000000000000000000000000000000000000000000000'],
199
+ [web3Utils.toChecksumAddress('0x0032d218133AFaB8F2B819B1066c7E434Ad94E2c'), 441, RatioState.OVER]
200
+ ],
201
+ ];
202
+
203
+ examples.forEach(([expected, actual]) => {
204
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
205
+ expect(morphoAaveV2RatioTrigger.encode(...actual)).to.eql(expected);
206
+ });
207
+ });
208
+ });
209
+
210
+ describe('decode()', () => {
211
+ const examples: Array<[{ owner: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
212
+ [
213
+ { owner: web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E2c'), ratio: 221, ratioState: RatioState.UNDER },
214
+ ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e2c0000000000000000000000000000000000000000000000001eab7f4a799d00000000000000000000000000000000000000000000000000000000000000000001'],
215
+ ],
216
+ [
217
+ { owner: web3Utils.toChecksumAddress('0x0032d218133AFaB8F2B819B1066c7E434Ad94E2c'), ratio: 441, ratioState: RatioState.OVER },
218
+ ['0x0000000000000000000000000032d218133afab8f2b819b1066c7e434ad94e2c0000000000000000000000000000000000000000000000003d3377a2837900000000000000000000000000000000000000000000000000000000000000000000'],
219
+ ],
220
+ ];
221
+
222
+ examples.forEach(([expected, actual]) => {
223
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
224
+ expect(morphoAaveV2RatioTrigger.decode(actual)).to.eql(expected);
225
+ });
226
+ });
227
+ });
228
+ });
229
+
230
+ describe('When testing triggerService.aaveV3QuotePriceTrigger', () => {
231
+ describe('encode()', () => {
232
+ const examples: Array<[[string], [baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState]]> = [
233
+ [
234
+ ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000009c400000000000000000000000000000000000000000000000000000000000000001'],
235
+ [getAssetInfo('DAI', ChainId.Ethereum).address, getAssetInfo('WETH', ChainId.Ethereum).address, 0.0004, RatioState.UNDER]
236
+ ],
237
+ [
238
+ ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000fd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb900000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000000'],
239
+ [getAssetInfo('WBTC', ChainId.Arbitrum).address, getAssetInfo('USDT', ChainId.Arbitrum).address, 0.00000023, RatioState.OVER]
240
+ ],
241
+ ];
242
+
243
+ examples.forEach(([expected, actual]) => {
244
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
245
+ expect(aaveV3QuotePriceTrigger.encode(...actual)).to.eql(expected);
246
+ });
247
+ });
248
+ });
249
+
250
+ describe('decode()', () => {
251
+ const examples: Array<[{ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState }, TriggerData]> = [
252
+ [
253
+ {
254
+ baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
255
+ quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
256
+ price: '0.0004',
257
+ ratioState: RatioState.UNDER,
258
+ },
259
+ ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000009c400000000000000000000000000000000000000000000000000000000000000001'],
260
+ ],
261
+ [
262
+ {
263
+ baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
264
+ quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Arbitrum).address),
265
+ price: '0.00000023',
266
+ ratioState: RatioState.OVER,
267
+ },
268
+ ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000fd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb900000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000000'],
269
+ ]
270
+ ];
271
+
272
+ examples.forEach(([expected, actual]) => {
273
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
274
+ expect(aaveV3QuotePriceTrigger.decode(actual)).to.eql(expected);
275
+ });
276
+ });
277
+ });
278
+ });
279
+
280
+ describe('When testing triggerService.liquityRatioTrigger', () => {
281
+ describe('encode()', () => {
282
+ const examples: Array<[[string], [owner: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
283
+ [
284
+ ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e2c00000000000000000000000000000000000000000000000029c5ab0d65ed00000000000000000000000000000000000000000000000000000000000000000001'],
285
+ [web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E2c'), 301, RatioState.UNDER]
286
+ ],
287
+ [
288
+ ['0x0000000000000000000000000039d218133afab832b819b1066c7e434ad94e2c000000000000000000000000000000000000000000000000122e0e0f2fc300000000000000000000000000000000000000000000000000000000000000000000'],
289
+ [web3Utils.toChecksumAddress('0x0039d218133AFaB832B819B1066c7E434Ad94E2c'), 131, RatioState.OVER]
290
+ ],
291
+ ];
292
+
293
+ examples.forEach(([expected, actual]) => {
294
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
295
+ expect(compoundV2RatioTrigger.encode(...actual)).to.eql(expected);
296
+ });
297
+ });
298
+ });
299
+
300
+ describe('decode()', () => {
301
+ const examples: Array<[{ owner: EthereumAddress, ratioState: RatioState, ratio: number }, TriggerData]> = [
302
+ [
303
+ {
304
+ owner: web3Utils.toChecksumAddress('0x0039d218133AFaB8F2B819B1066c7E434Ad94E2c'),
305
+ ratio: 301,
306
+ ratioState: RatioState.UNDER,
307
+ },
308
+ ['0x0000000000000000000000000039d218133afab8f2b819b1066c7e434ad94e2c00000000000000000000000000000000000000000000000029c5ab0d65ed00000000000000000000000000000000000000000000000000000000000000000001'],
309
+ ],
310
+ [
311
+ {
312
+ owner: web3Utils.toChecksumAddress('0x0039d218133AFaB832B819B1066c7E434Ad94E2c'),
313
+ ratio: 131,
314
+ ratioState: RatioState.OVER,
315
+ },
316
+ ['0x0000000000000000000000000039d218133afab832b819b1066c7e434ad94e2c000000000000000000000000000000000000000000000000122e0e0f2fc300000000000000000000000000000000000000000000000000000000000000000000'],
317
+ ],
318
+ ];
319
+
320
+ examples.forEach(([expected, actual]) => {
321
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
322
+ expect(compoundV2RatioTrigger.decode(actual)).to.eql(expected);
323
+ });
324
+ });
325
+ });
326
+ });
327
+
328
+ describe('When testing triggerService.liquityDebtInFrontTrigger', () => {
329
+ describe('encode()', () => {
330
+ const examples: Array<[[string], [owner: EthereumAddress, debtInFrontMin: string]]> = [
331
+ [
332
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000000007ee'],
333
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '2030']
334
+ ],
335
+ [
336
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c0000000000000000000000000000000000000000000000000000000000051639'],
337
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '333369']
338
+ ],
339
+ ];
340
+
341
+ examples.forEach(([expected, actual]) => {
342
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
343
+ expect(liquityDebtInFrontTrigger.encode(...actual)).to.eql(expected);
344
+ });
345
+ });
346
+ });
347
+
348
+ describe('decode()', () => {
349
+ const examples: Array<[{ owner: EthereumAddress, debtInFrontMin: string }, TriggerData]> = [
350
+ [
351
+ {
352
+ owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
353
+ debtInFrontMin: '2030',
354
+ },
355
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000000007ee'],
356
+ ],
357
+ [
358
+ {
359
+ owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
360
+ debtInFrontMin: '333369',
361
+ },
362
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c0000000000000000000000000000000000000000000000000000000000051639'],
363
+ ],
364
+ ];
365
+
366
+ examples.forEach(([expected, actual]) => {
367
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
368
+ expect(liquityDebtInFrontTrigger.decode(actual)).to.eql(expected);
369
+ });
370
+ });
371
+ });
372
+ });
373
+
374
+ describe('When testing triggerService.aaveV2RatioTrigger', () => {
375
+ describe('encode()', () => {
376
+ const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
377
+ [
378
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c0000000000000000000000000249d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
379
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), web3Utils.toChecksumAddress('0x0249d218133AFaB8F2B829B1066c7E434Ad94E2c'), 120, RatioState.OVER]
380
+ ],
381
+ ];
382
+
383
+ examples.forEach(([expected, actual]) => {
384
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
385
+ expect(aaveV2RatioTrigger.encode(...actual)).to.eql(expected);
386
+ });
387
+ });
388
+ });
389
+
390
+ describe('decode()', () => {
391
+ const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratioState: RatioState, ratio: number }, TriggerData]> = [
392
+ [
393
+ {
394
+ owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
395
+ market: web3Utils.toChecksumAddress('0x0249d218133AFaB8F2B829B1066c7E434Ad94E2c'),
396
+ ratio: 120,
397
+ ratioState: RatioState.OVER,
398
+ },
399
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c0000000000000000000000000249d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000000'],
400
+ ],
401
+ ];
402
+
403
+ examples.forEach(([expected, actual]) => {
404
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
405
+ expect(aaveV2RatioTrigger.decode(actual)).to.eql(expected);
406
+ });
407
+ });
408
+ });
409
+ });
410
+
411
+ describe('When testing triggerService.cBondsRebondTrigger', () => {
412
+ describe('encode()', () => {
413
+ const examples: Array<[[string], [bondId: number | string]]> = [
414
+ [
415
+ ['0x0000000000000000000000000000000000000000000000000000000000000141'],
416
+ [321]
417
+ ],
418
+ [
419
+ ['0x000000000000000000000000000000000000000000000000000000000000002c'],
420
+ [44]
421
+ ],
422
+ ];
423
+
424
+ examples.forEach(([expected, actual]) => {
425
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
426
+ expect(cBondsRebondTrigger.encode(...actual)).to.eql(expected);
427
+ });
428
+ });
429
+ });
430
+
431
+ describe('decode()', () => {
432
+ const examples: Array<[{ bondId: string }, TriggerData]> = [
433
+ [
434
+ { bondId: '321' },
435
+ ['0x0000000000000000000000000000000000000000000000000000000000000141'],
436
+ ],
437
+ [
438
+ { bondId: '44' },
439
+ ['0x000000000000000000000000000000000000000000000000000000000000002c'],
440
+ ],
441
+ ];
442
+
443
+ examples.forEach(([expected, actual]) => {
444
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
445
+ expect(cBondsRebondTrigger.decode(actual)).to.eql(expected);
446
+ });
447
+ });
448
+ });
449
+ });
450
+
451
+ describe('When testing triggerService.compoundV3RatioTrigger', () => {
452
+ describe('encode()', () => {
453
+ const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
454
+ [
455
+ ['0x0000000000000000000000000049d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d218133afab8f2b829b1066c7e43cad94e2c000000000000000000000000000000000000000000000000245c1c1e5f8600000000000000000000000000000000000000000000000000000000000000000000'],
456
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B106633E434Ad94E2c'), web3Utils.toChecksumAddress('0x0213d218133AFaB8F2B829B1066c7E43cAd94E2c'), 262, RatioState.OVER]
457
+ ],
458
+ [
459
+ ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d212133afab8f2b829b1066c7e43cad94e2c0000000000000000000000000000000000000000000000002def7b767e8b00000000000000000000000000000000000000000000000000000000000000000001'],
460
+ [web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 331, RatioState.UNDER]
461
+ ],
462
+ ];
463
+
464
+ examples.forEach(([expected, actual]) => {
465
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
466
+ expect(compoundV3RatioTrigger.encode(...actual)).to.eql(expected);
467
+ });
468
+ });
469
+ });
470
+
471
+ describe('decode()', () => {
472
+ const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratioState: RatioState, ratio: number }, TriggerData]> = [
473
+ [
474
+ {
475
+ owner: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B106633E434Ad94E2c'),
476
+ market: web3Utils.toChecksumAddress('0x0213d218133AFaB8F2B829B1066c7E43cAd94E2c'),
477
+ ratio: 262,
478
+ ratioState: RatioState.OVER,
479
+ },
480
+ ['0x0000000000000000000000000049d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d218133afab8f2b829b1066c7e43cad94e2c000000000000000000000000000000000000000000000000245c1c1e5f8600000000000000000000000000000000000000000000000000000000000000000000'],
481
+ ],
482
+ [
483
+ {
484
+ owner: web3Utils.toChecksumAddress('0x0043d218133AFaB8F2B829B106633E434Ad94E2c'),
485
+ market: web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'),
486
+ ratio: 331,
487
+ ratioState: RatioState.UNDER,
488
+ },
489
+ ['0x0000000000000000000000000043d218133afab8f2b829b106633e434ad94e2c0000000000000000000000000213d212133afab8f2b829b1066c7e43cad94e2c0000000000000000000000000000000000000000000000002def7b767e8b00000000000000000000000000000000000000000000000000000000000000000001'],
490
+ ],
491
+ ];
492
+
493
+ examples.forEach(([expected, actual]) => {
494
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
495
+ expect(compoundV3RatioTrigger.decode(actual)).to.eql(expected);
496
+ });
497
+ });
498
+ });
499
+ });
500
+
501
+ describe('When testing triggerService.exchangeTimestampTrigger', () => {
502
+ describe('encode()', () => {
503
+ const examples: Array<[[string], [timestamp: number, interval: number]]> = [
504
+ [
505
+ ['0x0000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000077359fb8'],
506
+ [1695904822209, 2000003000]
507
+ ],
508
+ [
509
+ ['0x00000000000000000000000000000000000000000000000000000189ed59a4010000000000000000000000000000000000000000000000000000000011e378b8'],
510
+ [1691904222209, 300120248]
511
+ ],
512
+ ];
513
+
514
+ examples.forEach(([expected, actual]) => {
515
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
516
+ expect(exchangeTimestampTrigger.encode(...actual)).to.eql(expected);
517
+ });
518
+ });
519
+ });
520
+
521
+ describe('decode()', () => {
522
+ const examples: Array<[{ timestamp: number, interval: number }, TriggerData]> = [
523
+ [
524
+ {
525
+ timestamp: 1695904822209, interval: 2000003000,
526
+ },
527
+ ['0x0000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000077359fb8'],
528
+ ],
529
+ [
530
+ {
531
+ timestamp: 1691904222209, interval: 300120248,
532
+ },
533
+ ['0x00000000000000000000000000000000000000000000000000000189ed59a4010000000000000000000000000000000000000000000000000000000011e378b8'],
534
+ ],
535
+ ];
536
+
537
+ examples.forEach(([expected, actual]) => {
538
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
539
+ expect(exchangeTimestampTrigger.decode(actual)).to.eql(expected);
540
+ });
541
+ });
542
+ });
543
+ });
544
+
545
+ describe('When testing triggerService.exchangeOffchainPriceTrigger', () => {
546
+ describe('encode()', () => {
547
+ const examples: Array<[[string], [targetPrice: string, goodUntil: number, orderType: OrderType, fromTokenDecimals: number, toTokenDecimals: number]]> = [
548
+ [
549
+ ['0x00000000000000000000000000000000000000000000000001b4fbd92b5f80000000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000000000000'],
550
+ ['0.123', 1695904822209, OrderType.TAKE_PROFIT, 12, 12]
551
+ ],
552
+ [
553
+ ['0x00000000000000000000000000000000000000000000000000000000003432120000000000000000000000000000000000000000000000000000018adbbead990000000000000000000000000000000000000000000000000000000000000001'],
554
+ ['3.42069', 1695903821209, OrderType.STOP_LOSS, 18, 6]
555
+ ],
556
+ ];
557
+
558
+ examples.forEach(([expected, actual]) => {
559
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
560
+ expect(exchangeOffchainPriceTrigger.encode(...actual)).to.eql(expected);
561
+ });
562
+ });
563
+ });
564
+
565
+ describe('decode()', () => {
566
+ const examples: Array<[{ orderType: OrderType; targetPrice: string; goodUntil: any }, [TriggerData, number, number]]> = [
567
+ [
568
+ {
569
+ orderType: OrderType.TAKE_PROFIT, targetPrice: '0.123', goodUntil: 1695904822209,
570
+ },
571
+ [
572
+ ['0x00000000000000000000000000000000000000000000000001b4fbd92b5f80000000000000000000000000000000000000000000000000000000018adbcdf3c10000000000000000000000000000000000000000000000000000000000000000'],
573
+ 12,
574
+ 12,
575
+ ],
576
+ ],
577
+ [
578
+ {
579
+ orderType: OrderType.STOP_LOSS, targetPrice: '3.42069', goodUntil: 1695903821209,
580
+ },
581
+ [
582
+ ['0x00000000000000000000000000000000000000000000000000000000003432120000000000000000000000000000000000000000000000000000018adbbead990000000000000000000000000000000000000000000000000000000000000001'],
583
+ 18,
584
+ 6,
585
+ ],
586
+ ],
587
+ ];
588
+
589
+ examples.forEach(([expected, actual]) => {
590
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
591
+ expect(exchangeOffchainPriceTrigger.decode(...actual)).to.eql(expected);
592
+ });
593
+ });
594
+ });
595
+ });
596
+
597
+ describe('When testing triggerService.sparkRatioTrigger', () => {
598
+ describe('encode()', () => {
599
+ const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
600
+ [
601
+ ['0x0000000000000000000000000031d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000001131d218133afab8f2b819b1066c7e434ad94e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
602
+ [web3Utils.toChecksumAddress('0x0031d218133AFaB8F2B819B1066c7E434Ad94E9c'), web3Utils.toChecksumAddress('0x1131d218133AFaB8F2B819B1066c7E434Ad94E9c'), 120, RatioState.UNDER]
603
+ ],
604
+ [
605
+ ['0x0000000000000000000000000231d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000000131d218133afab8f2b819b1066c7e434ad94e9c000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
606
+ [web3Utils.toChecksumAddress('0x0231d218133AFaB8F2B819B1066c7E434Ad94E9c'), web3Utils.toChecksumAddress('0x0131d218133AFaB8F2B819B1066c7E434Ad94E9c'), 231, RatioState.OVER]
607
+ ],
608
+ ];
609
+
610
+ examples.forEach(([expected, actual]) => {
611
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
612
+ expect(sparkRatioTrigger.encode(...actual)).to.eql(expected);
613
+ });
614
+ });
615
+ });
616
+
617
+ describe('decode()', () => {
618
+ const examples: Array<[{ owner: EthereumAddress, market: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
619
+ [
620
+ { owner: web3Utils.toChecksumAddress('0x0031d218133AFaB8F2B819B1066c7E434Ad94E9c'), market: web3Utils.toChecksumAddress('0x1131d218133AFaB8F2B819B1066c7E434Ad94E9c'), ratio: 120, ratioState: RatioState.UNDER },
621
+ ['0x0000000000000000000000000031d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000001131d218133afab8f2b819b1066c7e434ad94e9c00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
622
+ ],
623
+ [
624
+ { owner: web3Utils.toChecksumAddress('0x0231d218133AFaB8F2B819B1066c7E434Ad94E9c'), market: web3Utils.toChecksumAddress('0x0131d218133AFaB8F2B819B1066c7E434Ad94E9c'), ratio: 231, ratioState: RatioState.OVER },
625
+ ['0x0000000000000000000000000231d218133afab8f2b819b1066c7e434ad94e9c0000000000000000000000000131d218133afab8f2b819b1066c7e434ad94e9c000000000000000000000000000000000000000000000000200ec4c2d72700000000000000000000000000000000000000000000000000000000000000000000'],
626
+ ],
627
+ ];
628
+
629
+ examples.forEach(([expected, actual]) => {
630
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
631
+ expect(sparkRatioTrigger.decode(actual)).to.eql(expected);
632
+ });
633
+ });
634
+ });
635
+ });
636
+
637
+ describe('When testing triggerService.sparkQuotePriceTrigger', () => {
638
+ describe('encode()', () => {
639
+ const examples: Array<[[string], [baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState]]> = [
640
+ [
641
+ ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
642
+ [getAssetInfo('DAI', ChainId.Ethereum).address, getAssetInfo('wstETH', ChainId.Ethereum).address, 0.0004321, RatioState.UNDER]
643
+ ],
644
+ [
645
+ ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
646
+ [getAssetInfo('WBTC', ChainId.Arbitrum).address, getAssetInfo('USDC', ChainId.Arbitrum).address, 0.00100023, RatioState.OVER]
647
+ ],
648
+ ];
649
+
650
+ examples.forEach(([expected, actual]) => {
651
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
652
+ expect(sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
653
+ });
654
+ });
655
+ });
656
+
657
+ describe('decode()', () => {
658
+ const examples: Array<[{ baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: string, ratioState: RatioState }, TriggerData]> = [
659
+ [
660
+ {
661
+ baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
662
+ quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('wstETH', ChainId.Ethereum).address),
663
+ price: '0.0004321',
664
+ ratioState: RatioState.UNDER,
665
+ },
666
+ ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
667
+ ],
668
+ [
669
+ {
670
+ baseTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Arbitrum).address),
671
+ quoteTokenAddress: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Arbitrum).address),
672
+ price: '0.00100023',
673
+ ratioState: RatioState.OVER,
674
+ },
675
+ ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
676
+ ]
677
+ ];
678
+
679
+ examples.forEach(([expected, actual]) => {
680
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
681
+ expect(sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
682
+ });
683
+ });
684
+ });
685
+ });
686
+
687
+ describe('When testing triggerService.curveUsdBorrowRateTrigger', () => {
688
+ describe('encode()', () => {
689
+ const examples: Array<[[string], [market: EthereumAddress, targetRate: string, rateState: RatioState]]> = [
690
+ [
691
+ ['0x0000000000000000000000000031d218133afab8c2b819b1066c7e434ad91e9c000000000000000000000000000000000000000000000000000000005c3744c40000000000000000000000000000000000000000000000000000000000000001'],
692
+ [web3Utils.toChecksumAddress('0x0031d218133AFaB8c2B819B1066c7E434Ad91E9c'), '5', RatioState.UNDER]
693
+ ],
694
+ [
695
+ ['0x0000000000000000000000000031d318133afab8c2b819b1066c7e434ad91e9c0000000000000000000000000000000000000000000000000000000037de1dae0000000000000000000000000000000000000000000000000000000000000000'],
696
+ [web3Utils.toChecksumAddress('0x0031d318133AFaB8c2B819B1066c7E434Ad91E9c'), '3', RatioState.OVER]
697
+ ],
698
+ ];
699
+
700
+ examples.forEach(([expected, actual]) => {
701
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
702
+ expect(curveUsdBorrowRateTrigger.encode(...actual)).to.eql(expected);
703
+ });
704
+ });
705
+ });
706
+
707
+ describe('decode()', () => {
708
+ const examples: Array<[{ market: EthereumAddress, targetRate: string, rateState: RatioState }, TriggerData]> = [
709
+ [
710
+ {
711
+ market: web3Utils.toChecksumAddress('0x0031d218133AFaB8c2B819B1066c7E434Ad91E9c'),
712
+ // Because of precision of reverse engineered rate we can't get exact number
713
+ targetRate: '4.9999999977932344260462314517997495470601974794180145018256513213117735079327887085499910715825462',
714
+ rateState: RatioState.UNDER,
715
+ },
716
+ ['0x0000000000000000000000000031d218133afab8c2b819b1066c7e434ad91e9c000000000000000000000000000000000000000000000000000000005c3744c40000000000000000000000000000000000000000000000000000000000000001'],
717
+ ],
718
+ [
719
+ {
720
+ market: web3Utils.toChecksumAddress('0x0031d318133AFaB8c2B819B1066c7E434Ad91E9c'),
721
+ // Because of precision of reverse engineered rate we can't get exact number
722
+ targetRate: '2.999999998802635853596007720123861222767915626254160712723033189270277420764438661596057080730334',
723
+ rateState: RatioState.OVER,
724
+ },
725
+ ['0x0000000000000000000000000031d318133afab8c2b819b1066c7e434ad91e9c0000000000000000000000000000000000000000000000000000000037de1dae0000000000000000000000000000000000000000000000000000000000000000'],
726
+ ],
727
+ ];
728
+
729
+ examples.forEach(([expected, actual]) => {
730
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
731
+ expect(curveUsdBorrowRateTrigger.decode(actual)).to.eql(expected);
732
+ });
733
+ });
734
+ });
735
+ });
736
+
737
+ describe('When testing triggerService.curveUsdSoftLiquidationTrigger', () => {
738
+ describe('encode()', () => {
739
+ const examples: Array<[[string], [market: EthereumAddress, market: EthereumAddress, percentage: string]]> = [
740
+ [
741
+ ['0x0000000000000000000000000031d218133afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000000b1a2bc2ec50000'],
742
+ [web3Utils.toChecksumAddress('0x0031d218133AFaB8c2a819B1066c7E434Ad91E9c'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), '5']
743
+ ],
744
+ [
745
+ ['0x0000000000000000000000000031d218233afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001298a2e67f060000'],
746
+ [web3Utils.toChecksumAddress('0x0031d218233AFaB8c2a819B1066c7E434Ad91E9c'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), '134']
747
+ ],
748
+ ];
749
+
750
+ examples.forEach(([expected, actual]) => {
751
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
752
+ expect(curveUsdSoftLiquidationTrigger.encode(...actual)).to.eql(expected);
753
+ });
754
+ });
755
+ });
756
+
757
+ describe('decode()', () => {
758
+ const examples: Array<[{ market: EthereumAddress, owner: EthereumAddress, percentage: string }, TriggerData]> = [
759
+ [
760
+ {
761
+ market: web3Utils.toChecksumAddress('0x0031d218133AFaB8c2a819B1066c7E434Ad91E9c'),
762
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
763
+ percentage: '5',
764
+ },
765
+ ['0x0000000000000000000000000031d218133afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c00000000000000000000000000000000000000000000000000b1a2bc2ec50000'],
766
+ ],
767
+ [
768
+ {
769
+ market: web3Utils.toChecksumAddress('0x0031d218233AFaB8c2a819B1066c7E434Ad91E9c'),
770
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
771
+ percentage: '134',
772
+ },
773
+ ['0x0000000000000000000000000031d218233afab8c2a819b1066c7e434ad91e9c0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000000000000000000000000000001298a2e67f060000'],
774
+ ],
775
+ ];
776
+
777
+ examples.forEach(([expected, actual]) => {
778
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
779
+ expect(curveUsdSoftLiquidationTrigger.decode(actual)).to.eql(expected);
780
+ });
781
+ });
782
+ });
783
+ });
784
+
785
+ });