@defisaver/automation-sdk 3.1.10 → 3.1.14-spark-dev
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.
- package/cjs/automation/private/StrategiesAutomation.d.ts +5 -3
- package/cjs/automation/private/StrategiesAutomation.js +27 -10
- package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
- package/cjs/constants/index.d.ts +1 -0
- package/cjs/constants/index.js +352 -11
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +1 -1
- package/cjs/services/ethereumService.js +21 -14
- package/cjs/services/ethereumService.test.js +3 -0
- package/cjs/services/strategiesService.js +329 -54
- package/cjs/services/strategiesService.test.js +1 -0
- package/cjs/services/strategySubService.d.ts +24 -5
- package/cjs/services/strategySubService.js +116 -10
- package/cjs/services/strategySubService.test.js +1049 -173
- package/cjs/services/subDataService.d.ts +361 -88
- package/cjs/services/subDataService.js +799 -249
- package/cjs/services/subDataService.test.js +1287 -142
- package/cjs/services/triggerService.d.ts +100 -9
- package/cjs/services/triggerService.js +188 -19
- package/cjs/services/triggerService.test.js +437 -46
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +10 -2
- package/cjs/services/utils.test.js +0 -77
- package/cjs/types/enums.d.ts +88 -12
- package/cjs/types/enums.js +78 -2
- package/cjs/types/index.d.ts +59 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +5 -3
- package/esm/automation/private/StrategiesAutomation.js +27 -10
- package/esm/automation/private/StrategiesAutomation.test.js +25 -0
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +351 -10
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -2
- package/esm/services/ethereumService.js +21 -14
- package/esm/services/ethereumService.test.js +3 -0
- package/esm/services/strategiesService.js +330 -55
- package/esm/services/strategiesService.test.js +1 -0
- package/esm/services/strategySubService.d.ts +24 -5
- package/esm/services/strategySubService.js +115 -9
- package/esm/services/strategySubService.test.js +1052 -176
- package/esm/services/subDataService.d.ts +361 -88
- package/esm/services/subDataService.js +799 -249
- package/esm/services/subDataService.test.js +1288 -143
- package/esm/services/triggerService.d.ts +100 -9
- package/esm/services/triggerService.js +187 -18
- package/esm/services/triggerService.test.js +438 -47
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +10 -2
- package/esm/services/utils.test.js +1 -52
- package/esm/types/enums.d.ts +88 -12
- package/esm/types/enums.js +78 -2
- package/esm/types/index.d.ts +59 -1
- package/package.json +4 -5
- package/src/automation/private/StrategiesAutomation.test.ts +40 -0
- package/src/automation/private/StrategiesAutomation.ts +38 -15
- package/src/constants/index.ts +353 -11
- package/src/index.ts +4 -2
- package/src/services/ethereumService.test.ts +3 -0
- package/src/services/ethereumService.ts +23 -16
- package/src/services/strategiesService.test.ts +1 -0
- package/src/services/strategiesService.ts +387 -72
- package/src/services/strategySubService.test.ts +1330 -316
- package/src/services/strategySubService.ts +365 -12
- package/src/services/subDataService.test.ts +1413 -170
- package/src/services/subDataService.ts +1148 -431
- package/src/services/triggerService.test.ts +482 -52
- package/src/services/triggerService.ts +272 -27
- package/src/services/utils.test.ts +0 -59
- package/src/services/utils.ts +15 -4
- package/src/types/enums.ts +78 -2
- package/src/types/index.ts +74 -1
- package/umd/index.js +0 -34219
|
@@ -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 = [
|
|
@@ -687,52 +806,6 @@ describe('Feature: triggerService.ts', () => {
|
|
|
687
806
|
});
|
|
688
807
|
});
|
|
689
808
|
});
|
|
690
|
-
describe('When testing triggerService.sparkQuotePriceTrigger', () => {
|
|
691
|
-
describe('encode()', () => {
|
|
692
|
-
const examples = [
|
|
693
|
-
[
|
|
694
|
-
['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
|
|
695
|
-
[(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]
|
|
696
|
-
],
|
|
697
|
-
[
|
|
698
|
-
['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
|
|
699
|
-
[(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]
|
|
700
|
-
],
|
|
701
|
-
];
|
|
702
|
-
examples.forEach(([expected, actual]) => {
|
|
703
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
704
|
-
(0, chai_1.expect)(triggerService_1.sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
|
|
705
|
-
});
|
|
706
|
-
});
|
|
707
|
-
});
|
|
708
|
-
describe('decode()', () => {
|
|
709
|
-
const examples = [
|
|
710
|
-
[
|
|
711
|
-
{
|
|
712
|
-
baseTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
|
|
713
|
-
quoteTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('wstETH', enums_1.ChainId.Ethereum).address),
|
|
714
|
-
price: '0.0004321',
|
|
715
|
-
ratioState: enums_1.RatioState.UNDER,
|
|
716
|
-
},
|
|
717
|
-
['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
|
|
718
|
-
],
|
|
719
|
-
[
|
|
720
|
-
{
|
|
721
|
-
baseTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Arbitrum).address),
|
|
722
|
-
quoteTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address),
|
|
723
|
-
price: '0.00100023',
|
|
724
|
-
ratioState: enums_1.RatioState.OVER,
|
|
725
|
-
},
|
|
726
|
-
['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
|
|
727
|
-
]
|
|
728
|
-
];
|
|
729
|
-
examples.forEach(([expected, actual]) => {
|
|
730
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
731
|
-
(0, chai_1.expect)(triggerService_1.sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
|
|
732
|
-
});
|
|
733
|
-
});
|
|
734
|
-
});
|
|
735
|
-
});
|
|
736
809
|
describe('When testing triggerService.curveUsdBorrowRateTrigger', () => {
|
|
737
810
|
describe('encode()', () => {
|
|
738
811
|
const examples = [
|
|
@@ -923,4 +996,322 @@ describe('Feature: triggerService.ts', () => {
|
|
|
923
996
|
});
|
|
924
997
|
});
|
|
925
998
|
});
|
|
999
|
+
describe('When testing triggerService.compoundV3PriceTrigger', () => {
|
|
1000
|
+
describe('encode()', () => {
|
|
1001
|
+
const examples = [
|
|
1002
|
+
[
|
|
1003
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f07775030000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1004
|
+
[web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'), 2000, enums_1.RatioState.UNDER]
|
|
1005
|
+
],
|
|
1006
|
+
[
|
|
1007
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f077750300000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1008
|
+
[web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'), 3000, enums_1.RatioState.OVER]
|
|
1009
|
+
],
|
|
1010
|
+
];
|
|
1011
|
+
examples.forEach(([expected, actual]) => {
|
|
1012
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1013
|
+
(0, chai_1.expect)(triggerService_1.compoundV3PriceTrigger.encode(...actual)).to.eql(expected);
|
|
1014
|
+
});
|
|
1015
|
+
});
|
|
1016
|
+
});
|
|
1017
|
+
describe('decode()', () => {
|
|
1018
|
+
const examples = [
|
|
1019
|
+
[
|
|
1020
|
+
{
|
|
1021
|
+
market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
1022
|
+
collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1023
|
+
user: web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
|
|
1024
|
+
price: '2000',
|
|
1025
|
+
priceState: enums_1.RatioState.UNDER,
|
|
1026
|
+
},
|
|
1027
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f07775030000000000000000000000000000000000000000000000000000002e90edd0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1028
|
+
],
|
|
1029
|
+
[
|
|
1030
|
+
{
|
|
1031
|
+
market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
1032
|
+
collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1033
|
+
user: web3Utils.toChecksumAddress('0x9a959B9ee2847a66A5A3d43Fd1Ec38a4f0777503'),
|
|
1034
|
+
price: '3000',
|
|
1035
|
+
priceState: enums_1.RatioState.OVER,
|
|
1036
|
+
},
|
|
1037
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000009a959b9ee2847a66a5a3d43fd1ec38a4f077750300000000000000000000000000000000000000000000000000000045d964b8000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1038
|
+
],
|
|
1039
|
+
];
|
|
1040
|
+
examples.forEach(([expected, actual]) => {
|
|
1041
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1042
|
+
(0, chai_1.expect)(triggerService_1.compoundV3PriceTrigger.decode(actual)).to.eql(expected);
|
|
1043
|
+
});
|
|
1044
|
+
});
|
|
1045
|
+
});
|
|
1046
|
+
});
|
|
1047
|
+
describe('When testing triggerService.compoundV3PriceRangeTrigger', () => {
|
|
1048
|
+
describe('encode()', () => {
|
|
1049
|
+
const examples = [
|
|
1050
|
+
[
|
|
1051
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1052
|
+
[web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 1500, 4000]
|
|
1053
|
+
],
|
|
1054
|
+
[
|
|
1055
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1056
|
+
[web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 0, 5000]
|
|
1057
|
+
],
|
|
1058
|
+
];
|
|
1059
|
+
examples.forEach(([expected, actual]) => {
|
|
1060
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1061
|
+
(0, chai_1.expect)(triggerService_1.compoundV3PriceRangeTrigger.encode(...actual)).to.eql(expected);
|
|
1062
|
+
});
|
|
1063
|
+
});
|
|
1064
|
+
});
|
|
1065
|
+
describe('decode()', () => {
|
|
1066
|
+
const examples = [
|
|
1067
|
+
[
|
|
1068
|
+
{
|
|
1069
|
+
market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
1070
|
+
collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1071
|
+
lowerPrice: '1500',
|
|
1072
|
+
upperPrice: '4000',
|
|
1073
|
+
},
|
|
1074
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1075
|
+
],
|
|
1076
|
+
[
|
|
1077
|
+
{
|
|
1078
|
+
market: web3Utils.toChecksumAddress('0xc3d688B66703497DAA19211EEdff47f25384cdc3'),
|
|
1079
|
+
collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1080
|
+
lowerPrice: '0',
|
|
1081
|
+
upperPrice: '5000',
|
|
1082
|
+
},
|
|
1083
|
+
['0x000000000000000000000000c3d688b66703497daa19211eedff47f25384cdc3000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1084
|
+
],
|
|
1085
|
+
];
|
|
1086
|
+
examples.forEach(([expected, actual]) => {
|
|
1087
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1088
|
+
(0, chai_1.expect)(triggerService_1.compoundV3PriceRangeTrigger.decode(actual)).to.eql(expected);
|
|
1089
|
+
});
|
|
1090
|
+
});
|
|
1091
|
+
});
|
|
1092
|
+
});
|
|
1093
|
+
describe('When testing triggerService.aaveV3PriceRangeTrigger', () => {
|
|
1094
|
+
describe('encode()', () => {
|
|
1095
|
+
const examples = [
|
|
1096
|
+
[
|
|
1097
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1098
|
+
[web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 1500, 4000]
|
|
1099
|
+
],
|
|
1100
|
+
[
|
|
1101
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1102
|
+
[web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 0, 5000]
|
|
1103
|
+
],
|
|
1104
|
+
];
|
|
1105
|
+
examples.forEach(([expected, actual]) => {
|
|
1106
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1107
|
+
(0, chai_1.expect)(triggerService_1.aaveV3QuotePriceRangeTrigger.encode(...actual)).to.eql(expected);
|
|
1108
|
+
});
|
|
1109
|
+
});
|
|
1110
|
+
});
|
|
1111
|
+
describe('decode()', () => {
|
|
1112
|
+
const examples = [
|
|
1113
|
+
[
|
|
1114
|
+
{
|
|
1115
|
+
collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1116
|
+
debtToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1117
|
+
lowerPrice: '1500',
|
|
1118
|
+
upperPrice: '4000',
|
|
1119
|
+
},
|
|
1120
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1121
|
+
],
|
|
1122
|
+
[
|
|
1123
|
+
{
|
|
1124
|
+
collToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1125
|
+
debtToken: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1126
|
+
lowerPrice: '0',
|
|
1127
|
+
upperPrice: '5000',
|
|
1128
|
+
},
|
|
1129
|
+
['000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1130
|
+
],
|
|
1131
|
+
];
|
|
1132
|
+
examples.forEach(([expected, actual]) => {
|
|
1133
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1134
|
+
(0, chai_1.expect)(triggerService_1.aaveV3QuotePriceRangeTrigger.decode(actual)).to.eql(expected);
|
|
1135
|
+
});
|
|
1136
|
+
});
|
|
1137
|
+
});
|
|
1138
|
+
});
|
|
1139
|
+
describe('When testing triggerService.morphoBluePriceRangeTrigger', () => {
|
|
1140
|
+
describe('encode()', () => {
|
|
1141
|
+
const examples = [
|
|
1142
|
+
[
|
|
1143
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1144
|
+
[web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 1500, 4000]
|
|
1145
|
+
],
|
|
1146
|
+
[
|
|
1147
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1148
|
+
[web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 0, 5000]
|
|
1149
|
+
],
|
|
1150
|
+
];
|
|
1151
|
+
examples.forEach(([expected, actual]) => {
|
|
1152
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1153
|
+
(0, chai_1.expect)(triggerService_1.morphoBluePriceRangeTrigger.encode(...actual)).to.eql(expected);
|
|
1154
|
+
});
|
|
1155
|
+
});
|
|
1156
|
+
});
|
|
1157
|
+
describe('decode()', () => {
|
|
1158
|
+
const examples = [
|
|
1159
|
+
[
|
|
1160
|
+
{
|
|
1161
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1162
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1163
|
+
loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1164
|
+
lowerPrice: '1500',
|
|
1165
|
+
upperPrice: '4000',
|
|
1166
|
+
},
|
|
1167
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1168
|
+
],
|
|
1169
|
+
[
|
|
1170
|
+
{
|
|
1171
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1172
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1173
|
+
loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1174
|
+
lowerPrice: '0',
|
|
1175
|
+
upperPrice: '5000',
|
|
1176
|
+
},
|
|
1177
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8dA6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1178
|
+
],
|
|
1179
|
+
];
|
|
1180
|
+
examples.forEach(([expected, actual]) => {
|
|
1181
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1182
|
+
(0, chai_1.expect)(triggerService_1.morphoBluePriceRangeTrigger.decode(actual)).to.eql(expected);
|
|
1183
|
+
});
|
|
1184
|
+
});
|
|
1185
|
+
});
|
|
1186
|
+
});
|
|
1187
|
+
describe('When testing triggerService.aaveV4RatioTrigger', () => {
|
|
1188
|
+
describe('encode()', () => {
|
|
1189
|
+
const examples = [
|
|
1190
|
+
[
|
|
1191
|
+
['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1192
|
+
[web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 120, enums_1.RatioState.UNDER]
|
|
1193
|
+
],
|
|
1194
|
+
];
|
|
1195
|
+
examples.forEach(([expected, actual]) => {
|
|
1196
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1197
|
+
(0, chai_1.expect)(triggerService_1.aaveV4RatioTrigger.encode(...actual)).to.eql(expected);
|
|
1198
|
+
});
|
|
1199
|
+
});
|
|
1200
|
+
});
|
|
1201
|
+
describe('decode()', () => {
|
|
1202
|
+
const examples = [
|
|
1203
|
+
[
|
|
1204
|
+
{ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), ratio: 120, ratioState: enums_1.RatioState.UNDER },
|
|
1205
|
+
['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1206
|
+
],
|
|
1207
|
+
];
|
|
1208
|
+
examples.forEach(([expected, actual]) => {
|
|
1209
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1210
|
+
(0, chai_1.expect)(triggerService_1.aaveV4RatioTrigger.decode(actual)).to.eql(expected);
|
|
1211
|
+
});
|
|
1212
|
+
});
|
|
1213
|
+
});
|
|
1214
|
+
});
|
|
1215
|
+
describe('When testing triggerService.aaveV4QuotePriceTrigger', () => {
|
|
1216
|
+
describe('encode()', () => {
|
|
1217
|
+
const examples = [
|
|
1218
|
+
[
|
|
1219
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1220
|
+
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, '1500', enums_1.RatioState.OVER]
|
|
1221
|
+
],
|
|
1222
|
+
];
|
|
1223
|
+
examples.forEach(([expected, actual]) => {
|
|
1224
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1225
|
+
(0, chai_1.expect)(triggerService_1.aaveV4QuotePriceTrigger.encode(...actual)).to.eql(expected);
|
|
1226
|
+
});
|
|
1227
|
+
});
|
|
1228
|
+
});
|
|
1229
|
+
describe('decode()', () => {
|
|
1230
|
+
const examples = [
|
|
1231
|
+
[
|
|
1232
|
+
{ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, price: '1500', ratioState: enums_1.RatioState.OVER },
|
|
1233
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1234
|
+
],
|
|
1235
|
+
];
|
|
1236
|
+
examples.forEach(([expected, actual]) => {
|
|
1237
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1238
|
+
(0, chai_1.expect)(triggerService_1.aaveV4QuotePriceTrigger.decode(actual)).to.eql(expected);
|
|
1239
|
+
});
|
|
1240
|
+
});
|
|
1241
|
+
});
|
|
1242
|
+
});
|
|
1243
|
+
describe('When testing triggerService.aaveV4QuotePriceRangeTrigger', () => {
|
|
1244
|
+
describe('encode()', () => {
|
|
1245
|
+
const examples = [
|
|
1246
|
+
[
|
|
1247
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae00000000000000000000000000000000000000000000000000056bc75e2d631000000'],
|
|
1248
|
+
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, '1400', '1600']
|
|
1249
|
+
],
|
|
1250
|
+
];
|
|
1251
|
+
examples.forEach(([expected, actual]) => {
|
|
1252
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1253
|
+
(0, chai_1.expect)(triggerService_1.aaveV4QuotePriceRangeTrigger.encode(...actual)).to.eql(expected);
|
|
1254
|
+
});
|
|
1255
|
+
});
|
|
1256
|
+
});
|
|
1257
|
+
describe('decode()', () => {
|
|
1258
|
+
const examples = [
|
|
1259
|
+
[
|
|
1260
|
+
{ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, lowerPrice: '1400', upperPrice: '1600' },
|
|
1261
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae00000000000000000000000000000000000000000000000000056bc75e2d631000000'],
|
|
1262
|
+
],
|
|
1263
|
+
];
|
|
1264
|
+
examples.forEach(([expected, actual]) => {
|
|
1265
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1266
|
+
(0, chai_1.expect)(triggerService_1.aaveV4QuotePriceRangeTrigger.decode(actual)).to.eql(expected);
|
|
1267
|
+
});
|
|
1268
|
+
});
|
|
1269
|
+
});
|
|
1270
|
+
});
|
|
1271
|
+
describe('When testing triggerService.sparkQuotePriceTrigger', () => {
|
|
1272
|
+
describe('encode()', () => {
|
|
1273
|
+
const examples = [
|
|
1274
|
+
[
|
|
1275
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1276
|
+
[web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address), web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address), 2500, enums_1.RatioState.UNDER]
|
|
1277
|
+
],
|
|
1278
|
+
[
|
|
1279
|
+
['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000'],
|
|
1280
|
+
[web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDT', enums_1.ChainId.Ethereum).address), web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address), 0.000031, enums_1.RatioState.OVER]
|
|
1281
|
+
],
|
|
1282
|
+
];
|
|
1283
|
+
examples.forEach(([expected, actual]) => {
|
|
1284
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1285
|
+
(0, chai_1.expect)(triggerService_1.sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
|
|
1286
|
+
});
|
|
1287
|
+
});
|
|
1288
|
+
});
|
|
1289
|
+
describe('decode()', () => {
|
|
1290
|
+
const examples = [
|
|
1291
|
+
[
|
|
1292
|
+
{
|
|
1293
|
+
baseTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
|
|
1294
|
+
quoteTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Ethereum).address),
|
|
1295
|
+
price: '2500',
|
|
1296
|
+
ratioState: enums_1.RatioState.UNDER
|
|
1297
|
+
},
|
|
1298
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001']
|
|
1299
|
+
],
|
|
1300
|
+
[
|
|
1301
|
+
{
|
|
1302
|
+
baseTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDT', enums_1.ChainId.Ethereum).address),
|
|
1303
|
+
quoteTokenAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Ethereum).address),
|
|
1304
|
+
price: '0.000031',
|
|
1305
|
+
ratioState: enums_1.RatioState.OVER
|
|
1306
|
+
},
|
|
1307
|
+
['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000']
|
|
1308
|
+
]
|
|
1309
|
+
];
|
|
1310
|
+
examples.forEach(([expected, actual]) => {
|
|
1311
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1312
|
+
(0, chai_1.expect)(triggerService_1.sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
|
|
1313
|
+
});
|
|
1314
|
+
});
|
|
1315
|
+
});
|
|
1316
|
+
});
|
|
926
1317
|
});
|
package/cjs/services/utils.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare function getRatioStateInfoForAaveCloseStrategy(currentRatioState:
|
|
|
23
23
|
ratioState: RatioState;
|
|
24
24
|
};
|
|
25
25
|
export declare function getPositionId(...args: (number | string)[]): string;
|
|
26
|
-
export declare function getCloseStrategyType(stopLossPrice: number, stopLossType: CloseToAssetType, takeProfitPrice: number, takeProfitType: CloseToAssetType): CloseStrategyType;
|
|
26
|
+
export declare function getCloseStrategyType(stopLossPrice: number | string, stopLossType: CloseToAssetType, takeProfitPrice: number | string, takeProfitType: CloseToAssetType): CloseStrategyType;
|
|
27
27
|
export declare function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStrategyType: CloseStrategyType): {
|
|
28
28
|
stopLossType: CloseToAssetType | undefined;
|
|
29
29
|
takeProfitType: CloseToAssetType | undefined;
|
package/cjs/services/utils.js
CHANGED
|
@@ -130,8 +130,16 @@ function getPositionId(...args) {
|
|
|
130
130
|
}
|
|
131
131
|
exports.getPositionId = getPositionId;
|
|
132
132
|
function getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType) {
|
|
133
|
-
const
|
|
134
|
-
const
|
|
133
|
+
const stopLossPriceDec = new decimal_js_1.default(stopLossPrice);
|
|
134
|
+
const takeProfitPriceDec = new decimal_js_1.default(takeProfitPrice);
|
|
135
|
+
if (!stopLossPriceDec.isFinite() || stopLossPriceDec.isNegative()) {
|
|
136
|
+
throw new Error('CloseOnPrice: stopLossPrice must be a finite non-negative number');
|
|
137
|
+
}
|
|
138
|
+
if (!takeProfitPriceDec.isFinite() || takeProfitPriceDec.isNegative()) {
|
|
139
|
+
throw new Error('CloseOnPrice: takeProfitPrice must be a finite non-negative number');
|
|
140
|
+
}
|
|
141
|
+
const isStopLoss = stopLossPriceDec.gt(0);
|
|
142
|
+
const isTakeProfit = takeProfitPriceDec.gt(0);
|
|
135
143
|
if (!isStopLoss && !isTakeProfit) {
|
|
136
144
|
throw new Error('CloseOnPrice: At least one price must be defined');
|
|
137
145
|
}
|
|
@@ -1,37 +1,8 @@
|
|
|
1
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
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
3
|
const chai_1 = require("chai");
|
|
30
|
-
const web3Utils = __importStar(require("web3-utils"));
|
|
31
|
-
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
32
4
|
const tokens_1 = require("@defisaver/tokens");
|
|
33
5
|
const enums_1 = require("../types/enums");
|
|
34
|
-
const strategySubService_1 = require("./strategySubService");
|
|
35
6
|
require("../configuration");
|
|
36
7
|
const utils_1 = require("./utils");
|
|
37
8
|
describe('Feature: utils.ts', () => {
|
|
@@ -167,54 +138,6 @@ describe('Feature: utils.ts', () => {
|
|
|
167
138
|
});
|
|
168
139
|
});
|
|
169
140
|
});
|
|
170
|
-
describe('When testing utils.compareSubHashes()', () => {
|
|
171
|
-
const subDataToEncodeOne = [
|
|
172
|
-
12,
|
|
173
|
-
false,
|
|
174
|
-
{
|
|
175
|
-
baseTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
176
|
-
quoteTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
177
|
-
price: 100,
|
|
178
|
-
ratioState: 1,
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
collAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
182
|
-
collAssetId: 2,
|
|
183
|
-
debtAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
184
|
-
debtAssetId: 3,
|
|
185
|
-
},
|
|
186
|
-
];
|
|
187
|
-
const subDataToEncodeTwo = [
|
|
188
|
-
13,
|
|
189
|
-
true,
|
|
190
|
-
{
|
|
191
|
-
baseTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
192
|
-
quoteTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
193
|
-
price: 100,
|
|
194
|
-
ratioState: 2,
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
collAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
198
|
-
collAssetId: 2,
|
|
199
|
-
debtAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
|
|
200
|
-
debtAssetId: 3,
|
|
201
|
-
},
|
|
202
|
-
];
|
|
203
|
-
// @ts-ignore
|
|
204
|
-
const encodedSubDataOne = strategySubService_1.sparkEncode.closeToAsset(...subDataToEncodeOne);
|
|
205
|
-
// @ts-ignore
|
|
206
|
-
const encodedSubDataTwo = strategySubService_1.sparkEncode.closeToAsset(...subDataToEncodeTwo);
|
|
207
|
-
const encodedParams = web3Utils.keccak256(web3_eth_abi_1.default.encodeParameter('(uint64,bool,bytes[],bytes32[])', encodedSubDataOne));
|
|
208
|
-
const examples = [
|
|
209
|
-
[true, [encodedParams, encodedSubDataOne]],
|
|
210
|
-
[false, [encodedParams, encodedSubDataTwo]],
|
|
211
|
-
];
|
|
212
|
-
examples.forEach(([expected, actual]) => {
|
|
213
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
214
|
-
(0, chai_1.expect)((0, utils_1.compareSubHashes)(...actual)).to.equal(expected);
|
|
215
|
-
});
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
141
|
describe('When testing utils.encodeSubId()', () => {
|
|
219
142
|
const examples = [
|
|
220
143
|
['00000001', '1'],
|