@defisaver/automation-sdk 3.2.3 → 3.2.4

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.
@@ -90,6 +90,21 @@ export declare const liquityDebtInFrontWithLimitTrigger: {
90
90
  debtInFrontMin: string;
91
91
  };
92
92
  };
93
+ export declare const liquityV2DebtInFrontTrigger: {
94
+ encode(market: EthereumAddress, troveId: string, debtInFrontMin: string): string[];
95
+ decode(triggerData: string[]): {
96
+ market: EthereumAddress;
97
+ troveId: string;
98
+ debtInFrontMin: string;
99
+ };
100
+ };
101
+ export declare const liquityV2AdjustTimeTrigger: {
102
+ encode(market: EthereumAddress, troveId: string): string[];
103
+ decode(triggerData: string[]): {
104
+ market: EthereumAddress;
105
+ troveId: string;
106
+ };
107
+ };
93
108
  export declare const aaveV2RatioTrigger: {
94
109
  encode(owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState): string[];
95
110
  decode(triggerData: string[]): {
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
29
+ exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkQuotePriceTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityV2AdjustTimeTrigger = exports.liquityV2DebtInFrontTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
30
30
  const decimal_js_1 = __importDefault(require("decimal.js"));
31
31
  const tokens_1 = require("@defisaver/tokens");
32
32
  const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
@@ -179,6 +179,32 @@ exports.liquityDebtInFrontTrigger = {
179
179
  },
180
180
  };
181
181
  exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger;
182
+ exports.liquityV2DebtInFrontTrigger = {
183
+ encode(market, troveId, debtInFrontMin) {
184
+ const debtInFrontMinWei = web3Utils.toWei(new decimal_js_1.default(debtInFrontMin).toString(), 'ether');
185
+ return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint256'], [market, troveId, debtInFrontMinWei])];
186
+ },
187
+ decode(triggerData) {
188
+ const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint256'], triggerData[0]);
189
+ return {
190
+ market: decodedData[0],
191
+ troveId: decodedData[1],
192
+ debtInFrontMin: new decimal_js_1.default(decodedData[2]).div(Math.pow(10, 18)).toString(),
193
+ };
194
+ },
195
+ };
196
+ exports.liquityV2AdjustTimeTrigger = {
197
+ encode(market, troveId) {
198
+ return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256'], [market, troveId])];
199
+ },
200
+ decode(triggerData) {
201
+ const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256'], triggerData[0]);
202
+ return {
203
+ market: decodedData[0],
204
+ troveId: decodedData[1],
205
+ };
206
+ },
207
+ };
182
208
  exports.aaveV2RatioTrigger = {
183
209
  encode(owner, market, ratioPercentage, ratioState) {
184
210
  const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
@@ -448,6 +448,125 @@ describe('Feature: triggerService.ts', () => {
448
448
  });
449
449
  });
450
450
  });
451
+ describe('When testing triggerService.liquityV2DebtInFrontTrigger', () => {
452
+ describe('encode()', () => {
453
+ const examples = [
454
+ [
455
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd1500000000000000000000000000000000000000000000006e0be8c4995af80000'],
456
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '123456789', '2030']
457
+ ],
458
+ [
459
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1000000000000000000000000000000000000000000004697f83e6356dd440000'],
460
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '987654321', '333369']
461
+ ],
462
+ [
463
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf00000000000000000000000000000000000000000000000000000000075bd924000000000000000000000000000000000000000000084595161401484a000000'],
464
+ [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '123459876', '10000000']
465
+ ],
466
+ [
467
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000000000000000002060d4950000000000000000000000000000000000000000000000000000000000989680'],
468
+ [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '543216789', '0.00000000001']
469
+ ],
470
+ [
471
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a000000000000000000000000000000000000000000000000000000003ade5ca20000000000000000000000000000000000000000019d971e4fe8401e74000000'],
472
+ [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '987651234', '500000000']
473
+ ],
474
+ ];
475
+ examples.forEach(([expected, actual]) => {
476
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
477
+ (0, chai_1.expect)(triggerService_1.liquityV2DebtInFrontTrigger.encode(...actual)).to.eql(expected);
478
+ });
479
+ });
480
+ });
481
+ describe('decode()', () => {
482
+ const examples = [
483
+ [
484
+ {
485
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
486
+ troveId: '123456789',
487
+ debtInFrontMin: '2030',
488
+ },
489
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd1500000000000000000000000000000000000000000000006e0be8c4995af80000'],
490
+ ],
491
+ [
492
+ {
493
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
494
+ troveId: '987654321',
495
+ debtInFrontMin: '333369',
496
+ },
497
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1000000000000000000000000000000000000000000004697f83e6356dd440000'],
498
+ ], [
499
+ {
500
+ market: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
501
+ troveId: '123459876',
502
+ debtInFrontMin: '10000000',
503
+ },
504
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf00000000000000000000000000000000000000000000000000000000075bd924000000000000000000000000000000000000000000084595161401484a000000'],
505
+ ], [
506
+ {
507
+ market: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
508
+ troveId: '543216789',
509
+ debtInFrontMin: '0.00000000001',
510
+ },
511
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000000000000000002060d4950000000000000000000000000000000000000000000000000000000000989680'],
512
+ ], [
513
+ {
514
+ market: web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'),
515
+ troveId: '987651234',
516
+ debtInFrontMin: '500000000',
517
+ },
518
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a000000000000000000000000000000000000000000000000000000003ade5ca20000000000000000000000000000000000000000019d971e4fe8401e74000000'],
519
+ ]
520
+ ];
521
+ examples.forEach(([expected, actual]) => {
522
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
523
+ (0, chai_1.expect)(triggerService_1.liquityV2DebtInFrontTrigger.decode(actual)).to.eql(expected);
524
+ });
525
+ });
526
+ });
527
+ });
528
+ describe('When testing triggerService.liquityV2AdjustTimeTrigger', () => {
529
+ describe('encode()', () => {
530
+ const examples = [
531
+ [
532
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd15'],
533
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '123456789']
534
+ ],
535
+ [
536
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1'],
537
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '987654321']
538
+ ],
539
+ ];
540
+ examples.forEach(([expected, actual]) => {
541
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
542
+ (0, chai_1.expect)(triggerService_1.liquityV2AdjustTimeTrigger.encode(...actual)).to.eql(expected);
543
+ });
544
+ });
545
+ });
546
+ describe('decode()', () => {
547
+ const examples = [
548
+ [
549
+ {
550
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
551
+ troveId: '123456789',
552
+ },
553
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd15'],
554
+ ],
555
+ [
556
+ {
557
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
558
+ troveId: '987654321',
559
+ },
560
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1'],
561
+ ]
562
+ ];
563
+ examples.forEach(([expected, actual]) => {
564
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
565
+ (0, chai_1.expect)(triggerService_1.liquityV2AdjustTimeTrigger.decode(actual)).to.eql(expected);
566
+ });
567
+ });
568
+ });
569
+ });
451
570
  describe('When testing triggerService.aaveV2RatioTrigger', () => {
452
571
  describe('encode()', () => {
453
572
  const examples = [
@@ -90,6 +90,21 @@ export declare const liquityDebtInFrontWithLimitTrigger: {
90
90
  debtInFrontMin: string;
91
91
  };
92
92
  };
93
+ export declare const liquityV2DebtInFrontTrigger: {
94
+ encode(market: EthereumAddress, troveId: string, debtInFrontMin: string): string[];
95
+ decode(triggerData: string[]): {
96
+ market: EthereumAddress;
97
+ troveId: string;
98
+ debtInFrontMin: string;
99
+ };
100
+ };
101
+ export declare const liquityV2AdjustTimeTrigger: {
102
+ encode(market: EthereumAddress, troveId: string): string[];
103
+ decode(triggerData: string[]): {
104
+ market: EthereumAddress;
105
+ troveId: string;
106
+ };
107
+ };
93
108
  export declare const aaveV2RatioTrigger: {
94
109
  encode(owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState): string[];
95
110
  decode(triggerData: string[]): {
@@ -150,6 +150,32 @@ export const liquityDebtInFrontTrigger = {
150
150
  },
151
151
  };
152
152
  export const liquityDebtInFrontWithLimitTrigger = liquityDebtInFrontTrigger;
153
+ export const liquityV2DebtInFrontTrigger = {
154
+ encode(market, troveId, debtInFrontMin) {
155
+ const debtInFrontMinWei = web3Utils.toWei(new Dec(debtInFrontMin).toString(), 'ether');
156
+ return [AbiCoder.encodeParameters(['address', 'uint256', 'uint256'], [market, troveId, debtInFrontMinWei])];
157
+ },
158
+ decode(triggerData) {
159
+ const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256'], triggerData[0]);
160
+ return {
161
+ market: decodedData[0],
162
+ troveId: decodedData[1],
163
+ debtInFrontMin: new Dec(decodedData[2]).div(Math.pow(10, 18)).toString(),
164
+ };
165
+ },
166
+ };
167
+ export const liquityV2AdjustTimeTrigger = {
168
+ encode(market, troveId) {
169
+ return [AbiCoder.encodeParameters(['address', 'uint256'], [market, troveId])];
170
+ },
171
+ decode(triggerData) {
172
+ const decodedData = AbiCoder.decodeParameters(['address', 'uint256'], triggerData[0]);
173
+ return {
174
+ market: decodedData[0],
175
+ troveId: decodedData[1],
176
+ };
177
+ },
178
+ };
153
179
  export const aaveV2RatioTrigger = {
154
180
  encode(owner, market, ratioPercentage, ratioState) {
155
181
  const ratioWei = ratioPercentageToWei(ratioPercentage);
@@ -3,7 +3,7 @@ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
3
3
  import * as web3Utils from 'web3-utils';
4
4
  import { ChainId, OrderType, RatioState } from '../types/enums';
5
5
  import '../configuration';
6
- import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkQuotePriceTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, } from './triggerService';
6
+ import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkQuotePriceTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, } from './triggerService';
7
7
  describe('Feature: triggerService.ts', () => {
8
8
  describe('When testing triggerService.chainlinkPriceTrigger', () => {
9
9
  describe('encode()', () => {
@@ -423,6 +423,125 @@ describe('Feature: triggerService.ts', () => {
423
423
  });
424
424
  });
425
425
  });
426
+ describe('When testing triggerService.liquityV2DebtInFrontTrigger', () => {
427
+ describe('encode()', () => {
428
+ const examples = [
429
+ [
430
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd1500000000000000000000000000000000000000000000006e0be8c4995af80000'],
431
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '123456789', '2030']
432
+ ],
433
+ [
434
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1000000000000000000000000000000000000000000004697f83e6356dd440000'],
435
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '987654321', '333369']
436
+ ],
437
+ [
438
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf00000000000000000000000000000000000000000000000000000000075bd924000000000000000000000000000000000000000000084595161401484a000000'],
439
+ [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '123459876', '10000000']
440
+ ],
441
+ [
442
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000000000000000002060d4950000000000000000000000000000000000000000000000000000000000989680'],
443
+ [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '543216789', '0.00000000001']
444
+ ],
445
+ [
446
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a000000000000000000000000000000000000000000000000000000003ade5ca20000000000000000000000000000000000000000019d971e4fe8401e74000000'],
447
+ [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '987651234', '500000000']
448
+ ],
449
+ ];
450
+ examples.forEach(([expected, actual]) => {
451
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
452
+ expect(liquityV2DebtInFrontTrigger.encode(...actual)).to.eql(expected);
453
+ });
454
+ });
455
+ });
456
+ describe('decode()', () => {
457
+ const examples = [
458
+ [
459
+ {
460
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
461
+ troveId: '123456789',
462
+ debtInFrontMin: '2030',
463
+ },
464
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd1500000000000000000000000000000000000000000000006e0be8c4995af80000'],
465
+ ],
466
+ [
467
+ {
468
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
469
+ troveId: '987654321',
470
+ debtInFrontMin: '333369',
471
+ },
472
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1000000000000000000000000000000000000000000004697f83e6356dd440000'],
473
+ ], [
474
+ {
475
+ market: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
476
+ troveId: '123459876',
477
+ debtInFrontMin: '10000000',
478
+ },
479
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf00000000000000000000000000000000000000000000000000000000075bd924000000000000000000000000000000000000000000084595161401484a000000'],
480
+ ], [
481
+ {
482
+ market: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
483
+ troveId: '543216789',
484
+ debtInFrontMin: '0.00000000001',
485
+ },
486
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000000000000000002060d4950000000000000000000000000000000000000000000000000000000000989680'],
487
+ ], [
488
+ {
489
+ market: web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'),
490
+ troveId: '987651234',
491
+ debtInFrontMin: '500000000',
492
+ },
493
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a000000000000000000000000000000000000000000000000000000003ade5ca20000000000000000000000000000000000000000019d971e4fe8401e74000000'],
494
+ ]
495
+ ];
496
+ examples.forEach(([expected, actual]) => {
497
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
498
+ expect(liquityV2DebtInFrontTrigger.decode(actual)).to.eql(expected);
499
+ });
500
+ });
501
+ });
502
+ });
503
+ describe('When testing triggerService.liquityV2AdjustTimeTrigger', () => {
504
+ describe('encode()', () => {
505
+ const examples = [
506
+ [
507
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd15'],
508
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '123456789']
509
+ ],
510
+ [
511
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1'],
512
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '987654321']
513
+ ],
514
+ ];
515
+ examples.forEach(([expected, actual]) => {
516
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
517
+ expect(liquityV2AdjustTimeTrigger.encode(...actual)).to.eql(expected);
518
+ });
519
+ });
520
+ });
521
+ describe('decode()', () => {
522
+ const examples = [
523
+ [
524
+ {
525
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
526
+ troveId: '123456789',
527
+ },
528
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd15'],
529
+ ],
530
+ [
531
+ {
532
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
533
+ troveId: '987654321',
534
+ },
535
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1'],
536
+ ]
537
+ ];
538
+ examples.forEach(([expected, actual]) => {
539
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
540
+ expect(liquityV2AdjustTimeTrigger.decode(actual)).to.eql(expected);
541
+ });
542
+ });
543
+ });
544
+ });
426
545
  describe('When testing triggerService.aaveV2RatioTrigger', () => {
427
546
  describe('encode()', () => {
428
547
  const examples = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.2.3",
3
+ "version": "3.2.4",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -28,7 +28,7 @@ import {
28
28
  liquityDebtInFrontWithLimitTrigger,
29
29
  crvUSDRatioTrigger,
30
30
  morphoBlueRatioTrigger,
31
- crvUsdHealthRatioTrigger,
31
+ crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger,
32
32
  } from './triggerService';
33
33
 
34
34
  describe('Feature: triggerService.ts', () => {
@@ -487,6 +487,132 @@ describe('Feature: triggerService.ts', () => {
487
487
  });
488
488
  });
489
489
 
490
+ describe('When testing triggerService.liquityV2DebtInFrontTrigger', () => {
491
+ describe('encode()', () => {
492
+ const examples: Array<[[string], [market: EthereumAddress, troveId: string, debtInFrontMin: string]]> = [
493
+ [
494
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd1500000000000000000000000000000000000000000000006e0be8c4995af80000'],
495
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '123456789', '2030']
496
+ ],
497
+ [
498
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1000000000000000000000000000000000000000000004697f83e6356dd440000'],
499
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '987654321', '333369']
500
+ ],
501
+ [
502
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf00000000000000000000000000000000000000000000000000000000075bd924000000000000000000000000000000000000000000084595161401484a000000'],
503
+ [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '123459876', '10000000']
504
+ ],
505
+ [
506
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000000000000000002060d4950000000000000000000000000000000000000000000000000000000000989680'],
507
+ [web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'), '543216789', '0.00000000001']
508
+ ],
509
+ [
510
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a000000000000000000000000000000000000000000000000000000003ade5ca20000000000000000000000000000000000000000019d971e4fe8401e74000000'],
511
+ [web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'), '987651234', '500000000']
512
+ ],
513
+ ];
514
+
515
+ examples.forEach(([expected, actual]) => {
516
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
517
+ expect(liquityV2DebtInFrontTrigger.encode(...actual)).to.eql(expected);
518
+ });
519
+ });
520
+ });
521
+
522
+ describe('decode()', () => {
523
+ const examples: Array<[{ market: EthereumAddress, troveId: string, debtInFrontMin: string }, TriggerData]> = [
524
+ [
525
+ {
526
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
527
+ troveId: '123456789',
528
+ debtInFrontMin: '2030',
529
+ },
530
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd1500000000000000000000000000000000000000000000006e0be8c4995af80000'],
531
+ ],
532
+ [
533
+ {
534
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
535
+ troveId: '987654321',
536
+ debtInFrontMin: '333369',
537
+ },
538
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1000000000000000000000000000000000000000000004697f83e6356dd440000'],
539
+ ], [
540
+ {
541
+ market: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
542
+ troveId: '123459876',
543
+ debtInFrontMin: '10000000',
544
+ },
545
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf00000000000000000000000000000000000000000000000000000000075bd924000000000000000000000000000000000000000000084595161401484a000000'],
546
+ ], [
547
+ {
548
+ market: web3Utils.toChecksumAddress('0x30462AD9D8F01A20A2EC7E7F1A8F1B303662AEBF'),
549
+ troveId: '543216789',
550
+ debtInFrontMin: '0.00000000001',
551
+ },
552
+ ['0x00000000000000000000000030462ad9d8f01a20a2ec7e7f1a8f1b303662aebf000000000000000000000000000000000000000000000000000000002060d4950000000000000000000000000000000000000000000000000000000000989680'],
553
+ ], [
554
+ {
555
+ market: web3Utils.toChecksumAddress('0x235d6A8DB3C57c3f7b4ebA749E1738Db6093732a'),
556
+ troveId: '987651234',
557
+ debtInFrontMin: '500000000',
558
+ },
559
+ ['0x000000000000000000000000235d6a8db3c57c3f7b4eba749e1738db6093732a000000000000000000000000000000000000000000000000000000003ade5ca20000000000000000000000000000000000000000019d971e4fe8401e74000000'],
560
+ ]
561
+ ];
562
+
563
+ examples.forEach(([expected, actual]) => {
564
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
565
+ expect(liquityV2DebtInFrontTrigger.decode(actual)).to.eql(expected);
566
+ });
567
+ });
568
+ });
569
+ });
570
+
571
+ describe('When testing triggerService.liquityV2AdjustTimeTrigger', () => {
572
+ describe('encode()', () => {
573
+ const examples: Array<[[string], [market: EthereumAddress, troveId: string]]> = [
574
+ [
575
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd15'],
576
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'), '123456789']
577
+ ],
578
+ [
579
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1'],
580
+ [web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'), '987654321']
581
+ ],
582
+ ];
583
+
584
+ examples.forEach(([expected, actual]) => {
585
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
586
+ expect(liquityV2AdjustTimeTrigger.encode(...actual)).to.eql(expected);
587
+ });
588
+ });
589
+ });
590
+
591
+ describe('decode()', () => {
592
+ const examples: Array<[{ market: EthereumAddress, troveId: string }, TriggerData]> = [
593
+ [
594
+ {
595
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434Ad94E2c'),
596
+ troveId: '123456789',
597
+ },
598
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434ad94e2c00000000000000000000000000000000000000000000000000000000075bcd15'],
599
+ ],
600
+ [
601
+ {
602
+ market: web3Utils.toChecksumAddress('0x0049d218133AFaB8F2B829B1066c7E434A192E2c'),
603
+ troveId: '987654321',
604
+ },
605
+ ['0x0000000000000000000000000049d218133afab8f2b829b1066c7e434a192e2c000000000000000000000000000000000000000000000000000000003ade68b1'],
606
+ ]
607
+ ];
608
+
609
+ examples.forEach(([expected, actual]) => {
610
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
611
+ expect(liquityV2AdjustTimeTrigger.decode(actual)).to.eql(expected);
612
+ });
613
+ });
614
+ });
615
+ });
490
616
  describe('When testing triggerService.aaveV2RatioTrigger', () => {
491
617
  describe('encode()', () => {
492
618
  const examples: Array<[[string], [owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
@@ -187,6 +187,34 @@ export const liquityDebtInFrontTrigger = {
187
187
 
188
188
  export const liquityDebtInFrontWithLimitTrigger = liquityDebtInFrontTrigger;
189
189
 
190
+ export const liquityV2DebtInFrontTrigger = {
191
+ encode(market: EthereumAddress, troveId: string, debtInFrontMin: string) {
192
+ const debtInFrontMinWei = web3Utils.toWei(new Dec(debtInFrontMin).toString(), 'ether');
193
+ return [AbiCoder.encodeParameters(['address', 'uint256', 'uint256'], [market, troveId, debtInFrontMinWei])];
194
+ },
195
+ decode(triggerData: TriggerData): { market: EthereumAddress, troveId: string, debtInFrontMin: string } {
196
+ const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256'], triggerData[0]);
197
+ return {
198
+ market: decodedData[0] as EthereumAddress,
199
+ troveId: decodedData[1] as string,
200
+ debtInFrontMin: new Dec(decodedData[2] as string).div(10 ** 18).toString(),
201
+ };
202
+ },
203
+ };
204
+
205
+ export const liquityV2AdjustTimeTrigger = {
206
+ encode(market: EthereumAddress, troveId: string) {
207
+ return [AbiCoder.encodeParameters(['address', 'uint256'], [market, troveId])];
208
+ },
209
+ decode(triggerData: TriggerData): { market: EthereumAddress, troveId: string } {
210
+ const decodedData = AbiCoder.decodeParameters(['address', 'uint256'], triggerData[0]);
211
+ return {
212
+ market: decodedData[0] as EthereumAddress,
213
+ troveId: decodedData[1] as string,
214
+ };
215
+ },
216
+ };
217
+
190
218
  export const aaveV2RatioTrigger = {
191
219
  encode(owner: EthereumAddress, market: EthereumAddress, ratioPercentage: number, ratioState: RatioState) {
192
220
  const ratioWei = ratioPercentageToWei(ratioPercentage);
@@ -571,4 +599,4 @@ export const fluidRatioTrigger = {
571
599
  ratioState: Number(decodedData[2]),
572
600
  };
573
601
  },
574
- };
602
+ };