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