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