@defisaver/automation-sdk 3.3.7 → 3.3.8
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/constants/index.js +15 -0
- package/cjs/services/ethereumService.test.js +1 -0
- package/cjs/services/strategiesService.js +30 -0
- package/cjs/services/strategiesService.test.js +1 -0
- package/cjs/services/strategySubService.d.ts +1 -0
- package/cjs/services/strategySubService.js +7 -0
- package/cjs/services/strategySubService.test.js +40 -2
- package/cjs/services/subDataService.d.ts +12 -0
- package/cjs/services/subDataService.js +31 -1
- package/cjs/services/subDataService.test.js +62 -10
- package/cjs/services/triggerService.d.ts +10 -0
- package/cjs/services/triggerService.js +21 -1
- package/cjs/services/triggerService.test.js +48 -0
- package/cjs/types/enums.d.ts +6 -3
- package/cjs/types/enums.js +3 -0
- package/esm/constants/index.js +15 -0
- package/esm/services/ethereumService.test.js +1 -0
- package/esm/services/strategiesService.js +30 -0
- package/esm/services/strategiesService.test.js +1 -0
- package/esm/services/strategySubService.d.ts +1 -0
- package/esm/services/strategySubService.js +7 -0
- package/esm/services/strategySubService.test.js +40 -2
- package/esm/services/subDataService.d.ts +12 -0
- package/esm/services/subDataService.js +30 -0
- package/esm/services/subDataService.test.js +62 -10
- package/esm/services/triggerService.d.ts +10 -0
- package/esm/services/triggerService.js +20 -0
- package/esm/services/triggerService.test.js +49 -1
- package/esm/types/enums.d.ts +6 -3
- package/esm/types/enums.js +3 -0
- package/package.json +2 -2
- package/src/constants/index.ts +15 -0
- package/src/services/ethereumService.test.ts +1 -0
- package/src/services/strategiesService.test.ts +1 -0
- package/src/services/strategiesService.ts +43 -0
- package/src/services/strategySubService.test.ts +57 -2
- package/src/services/strategySubService.ts +21 -0
- package/src/services/subDataService.test.ts +73 -14
- package/src/services/subDataService.ts +40 -0
- package/src/services/triggerService.test.ts +53 -0
- package/src/services/triggerService.ts +32 -0
- package/src/types/enums.ts +3 -0
|
@@ -640,7 +640,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
640
640
|
[
|
|
641
641
|
Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
|
|
642
642
|
true,
|
|
643
|
-
['
|
|
643
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000001'],
|
|
644
644
|
[
|
|
645
645
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
646
646
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
@@ -668,7 +668,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
668
668
|
[
|
|
669
669
|
Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
|
|
670
670
|
true,
|
|
671
|
-
['
|
|
671
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000002faf0800000000000000000000000000000000000000000000000000000000000000000'],
|
|
672
672
|
[
|
|
673
673
|
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
674
674
|
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
@@ -1587,6 +1587,61 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1587
1587
|
});
|
|
1588
1588
|
});
|
|
1589
1589
|
});
|
|
1590
|
+
|
|
1591
|
+
describe('closeOnPrice()', () => {
|
|
1592
|
+
const examples: Array<[
|
|
1593
|
+
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1594
|
+
[
|
|
1595
|
+
strategyOrBundleId: number,
|
|
1596
|
+
loanToken: EthereumAddress,
|
|
1597
|
+
collToken: EthereumAddress,
|
|
1598
|
+
oracle: EthereumAddress,
|
|
1599
|
+
irm: EthereumAddress,
|
|
1600
|
+
lltv: string,
|
|
1601
|
+
user: EthereumAddress,
|
|
1602
|
+
stopLossPrice: number,
|
|
1603
|
+
stopLossType: CloseToAssetType,
|
|
1604
|
+
takeProfitPrice: number,
|
|
1605
|
+
takeProfitType: CloseToAssetType,
|
|
1606
|
+
]
|
|
1607
|
+
]> = [
|
|
1608
|
+
[
|
|
1609
|
+
[
|
|
1610
|
+
Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1611
|
+
true,
|
|
1612
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1613
|
+
[
|
|
1614
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1615
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1616
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1617
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1618
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1619
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1620
|
+
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1621
|
+
],
|
|
1622
|
+
],
|
|
1623
|
+
[
|
|
1624
|
+
Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1625
|
+
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1626
|
+
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1627
|
+
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1628
|
+
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1629
|
+
'945000000000000000',
|
|
1630
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1631
|
+
1500,
|
|
1632
|
+
CloseToAssetType.DEBT,
|
|
1633
|
+
4000,
|
|
1634
|
+
CloseToAssetType.COLLATERAL
|
|
1635
|
+
]
|
|
1636
|
+
],
|
|
1637
|
+
];
|
|
1638
|
+
|
|
1639
|
+
examples.forEach(([expected, actual]) => {
|
|
1640
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1641
|
+
expect(morphoBlueEncode.closeOnPrice(...actual)).to.eql(expected);
|
|
1642
|
+
});
|
|
1643
|
+
});
|
|
1644
|
+
});
|
|
1590
1645
|
});
|
|
1591
1646
|
|
|
1592
1647
|
describe('When testing strategySubService.compoundV3L2Encode', () => {
|
|
@@ -670,6 +670,27 @@ export const morphoBlueEncode = {
|
|
|
670
670
|
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
671
671
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
672
672
|
},
|
|
673
|
+
closeOnPrice(
|
|
674
|
+
strategyOrBundleId: number,
|
|
675
|
+
loanToken: EthereumAddress,
|
|
676
|
+
collToken: EthereumAddress,
|
|
677
|
+
oracle: EthereumAddress,
|
|
678
|
+
irm: EthereumAddress,
|
|
679
|
+
lltv: string,
|
|
680
|
+
user: EthereumAddress,
|
|
681
|
+
stopLossPrice: number = 0,
|
|
682
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
683
|
+
takeProfitPrice: number = 0,
|
|
684
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
685
|
+
) {
|
|
686
|
+
const isBundle = true;
|
|
687
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
688
|
+
|
|
689
|
+
const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
|
|
690
|
+
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
691
|
+
|
|
692
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
693
|
+
},
|
|
673
694
|
};
|
|
674
695
|
|
|
675
696
|
export const liquityV2Encode = {
|
|
@@ -1368,6 +1368,65 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1368
1368
|
});
|
|
1369
1369
|
});
|
|
1370
1370
|
|
|
1371
|
+
describe('When testing subDataService.morphoBlueCloseOnPriceSubData', () => {
|
|
1372
|
+
describe('encode()', () => {
|
|
1373
|
+
const examples: Array<[
|
|
1374
|
+
SubData,
|
|
1375
|
+
[loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, closeType: CloseStrategyType],
|
|
1376
|
+
]> = [
|
|
1377
|
+
[
|
|
1378
|
+
[
|
|
1379
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1380
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1381
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1382
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1383
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1384
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1385
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
1386
|
+
],
|
|
1387
|
+
[web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'), '945000000000000000', web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT]
|
|
1388
|
+
],
|
|
1389
|
+
];
|
|
1390
|
+
|
|
1391
|
+
examples.forEach(([expected, actual]) => {
|
|
1392
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1393
|
+
expect(subDataService.morphoBlueCloseOnPriceSubData.encode(...actual)).to.eql(expected);
|
|
1394
|
+
});
|
|
1395
|
+
});
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1398
|
+
describe('decode()', () => {
|
|
1399
|
+
const examples: Array<[{ loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, closeType: CloseStrategyType }, SubData]> = [
|
|
1400
|
+
[
|
|
1401
|
+
{
|
|
1402
|
+
loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
1403
|
+
collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
|
|
1404
|
+
oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1405
|
+
irm: '0x0000000000000000000000000000000000000000',
|
|
1406
|
+
lltv: '945000000000000000',
|
|
1407
|
+
user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
|
|
1408
|
+
closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
|
|
1409
|
+
},
|
|
1410
|
+
[
|
|
1411
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1412
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1413
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1414
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1415
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1416
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1417
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
1418
|
+
],
|
|
1419
|
+
],
|
|
1420
|
+
];
|
|
1421
|
+
|
|
1422
|
+
examples.forEach(([expected, actual]) => {
|
|
1423
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1424
|
+
expect(subDataService.morphoBlueCloseOnPriceSubData.decode(actual)).to.eql(expected);
|
|
1425
|
+
});
|
|
1426
|
+
});
|
|
1427
|
+
});
|
|
1428
|
+
});
|
|
1429
|
+
|
|
1371
1430
|
describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
|
|
1372
1431
|
describe('encode()', () => {
|
|
1373
1432
|
const examples: Array<[SubData, [collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number]]> = [
|
|
@@ -1625,7 +1684,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1625
1684
|
debtAssetId: number,
|
|
1626
1685
|
marketAddr: EthereumAddress,
|
|
1627
1686
|
targetRatio: number,
|
|
1628
|
-
|
|
1687
|
+
owner: EthereumAddress
|
|
1629
1688
|
]
|
|
1630
1689
|
]
|
|
1631
1690
|
> = [
|
|
@@ -1692,7 +1751,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1692
1751
|
debtAssetId: number,
|
|
1693
1752
|
marketAddr: EthereumAddress,
|
|
1694
1753
|
targetRatio: number,
|
|
1695
|
-
|
|
1754
|
+
owner: EthereumAddress,
|
|
1696
1755
|
},
|
|
1697
1756
|
string[]
|
|
1698
1757
|
]
|
|
@@ -1705,7 +1764,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1705
1764
|
debtAssetId: 1,
|
|
1706
1765
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1707
1766
|
targetRatio: 200,
|
|
1708
|
-
|
|
1767
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1709
1768
|
},
|
|
1710
1769
|
[
|
|
1711
1770
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -1725,7 +1784,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1725
1784
|
debtAssetId: 1,
|
|
1726
1785
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1727
1786
|
targetRatio: 200,
|
|
1728
|
-
|
|
1787
|
+
owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1729
1788
|
},
|
|
1730
1789
|
[
|
|
1731
1790
|
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
@@ -1763,7 +1822,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1763
1822
|
debtAssetId: number,
|
|
1764
1823
|
closeType: CloseStrategyType,
|
|
1765
1824
|
marketAddr: EthereumAddress,
|
|
1766
|
-
|
|
1825
|
+
owner: EthereumAddress
|
|
1767
1826
|
]
|
|
1768
1827
|
]
|
|
1769
1828
|
> = [
|
|
@@ -1958,7 +2017,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1958
2017
|
debtAssetId: number,
|
|
1959
2018
|
closeType: CloseStrategyType,
|
|
1960
2019
|
marketAddr: EthereumAddress,
|
|
1961
|
-
|
|
2020
|
+
owner: EthereumAddress,
|
|
1962
2021
|
},
|
|
1963
2022
|
string[]
|
|
1964
2023
|
]
|
|
@@ -1972,7 +2031,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1972
2031
|
debtAssetId: 1,
|
|
1973
2032
|
closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
|
|
1974
2033
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1975
|
-
|
|
2034
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1976
2035
|
},
|
|
1977
2036
|
[
|
|
1978
2037
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -1993,7 +2052,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1993
2052
|
debtAssetId: 1,
|
|
1994
2053
|
closeType: CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
|
|
1995
2054
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1996
|
-
|
|
2055
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1997
2056
|
},
|
|
1998
2057
|
[
|
|
1999
2058
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -2014,7 +2073,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
2014
2073
|
debtAssetId: 1,
|
|
2015
2074
|
closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT,
|
|
2016
2075
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
2017
|
-
|
|
2076
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
2018
2077
|
},
|
|
2019
2078
|
[
|
|
2020
2079
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -2035,7 +2094,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
2035
2094
|
debtAssetId: 1,
|
|
2036
2095
|
closeType: CloseStrategyType.STOP_LOSS_IN_DEBT,
|
|
2037
2096
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
2038
|
-
|
|
2097
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
2039
2098
|
},
|
|
2040
2099
|
[
|
|
2041
2100
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -2056,7 +2115,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
2056
2115
|
debtAssetId: 1,
|
|
2057
2116
|
closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
|
|
2058
2117
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
2059
|
-
|
|
2118
|
+
owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
2060
2119
|
},
|
|
2061
2120
|
[
|
|
2062
2121
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -2077,7 +2136,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
2077
2136
|
debtAssetId: 1,
|
|
2078
2137
|
closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
|
|
2079
2138
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
2080
|
-
|
|
2139
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
2081
2140
|
},
|
|
2082
2141
|
[
|
|
2083
2142
|
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
@@ -2098,7 +2157,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
2098
2157
|
debtAssetId: 1,
|
|
2099
2158
|
closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
|
|
2100
2159
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
2101
|
-
|
|
2160
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
2102
2161
|
},
|
|
2103
2162
|
[
|
|
2104
2163
|
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
@@ -2119,7 +2178,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
2119
2178
|
debtAssetId: 1,
|
|
2120
2179
|
closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
|
|
2121
2180
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
2122
|
-
|
|
2181
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
2123
2182
|
},
|
|
2124
2183
|
[
|
|
2125
2184
|
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
@@ -1212,3 +1212,43 @@ export const sparkCloseGenericSubData = {
|
|
|
1212
1212
|
};
|
|
1213
1213
|
},
|
|
1214
1214
|
};
|
|
1215
|
+
|
|
1216
|
+
export const morphoBlueCloseOnPriceSubData = {
|
|
1217
|
+
encode(
|
|
1218
|
+
loanToken: EthereumAddress,
|
|
1219
|
+
collToken: EthereumAddress,
|
|
1220
|
+
oracle: EthereumAddress,
|
|
1221
|
+
irm: EthereumAddress,
|
|
1222
|
+
lltv: string,
|
|
1223
|
+
user: EthereumAddress,
|
|
1224
|
+
closeType: CloseStrategyType,
|
|
1225
|
+
): SubData {
|
|
1226
|
+
const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
|
|
1227
|
+
const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
|
|
1228
|
+
const oracleEncoded = AbiCoder.encodeParameter('address', oracle);
|
|
1229
|
+
const irmEncoded = AbiCoder.encodeParameter('address', irm);
|
|
1230
|
+
const lltvEncoded = AbiCoder.encodeParameter('uint256', lltv);
|
|
1231
|
+
const userEncoded = AbiCoder.encodeParameter('address', user);
|
|
1232
|
+
const closeTypeEncoded = AbiCoder.encodeParameter('uint8', closeType);
|
|
1233
|
+
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, userEncoded, closeTypeEncoded];
|
|
1234
|
+
},
|
|
1235
|
+
decode(subData: SubData) {
|
|
1236
|
+
const loanToken = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
1237
|
+
const collToken = AbiCoder.decodeParameter('address', subData[1]) as any as EthereumAddress;
|
|
1238
|
+
const oracle = AbiCoder.decodeParameter('address', subData[2]) as any as EthereumAddress;
|
|
1239
|
+
const irm = AbiCoder.decodeParameter('address', subData[3]) as any as EthereumAddress;
|
|
1240
|
+
const lltv = AbiCoder.decodeParameter('uint256', subData[4]) as any as EthereumAddress;
|
|
1241
|
+
const user = AbiCoder.decodeParameter('address', subData[5]) as any as EthereumAddress;
|
|
1242
|
+
const closeType = Number(AbiCoder.decodeParameter('uint8', subData[6])) as CloseStrategyType;
|
|
1243
|
+
|
|
1244
|
+
return {
|
|
1245
|
+
loanToken,
|
|
1246
|
+
collToken,
|
|
1247
|
+
oracle,
|
|
1248
|
+
irm,
|
|
1249
|
+
lltv,
|
|
1250
|
+
user,
|
|
1251
|
+
closeType,
|
|
1252
|
+
};
|
|
1253
|
+
},
|
|
1254
|
+
};
|
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger,
|
|
32
32
|
compoundV3PriceRangeTrigger,
|
|
33
33
|
aaveV3QuotePriceRangeTrigger,
|
|
34
|
+
morphoBluePriceRangeTrigger,
|
|
34
35
|
} from './triggerService';
|
|
35
36
|
|
|
36
37
|
describe('Feature: triggerService.ts', () => {
|
|
@@ -1230,4 +1231,56 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1230
1231
|
});
|
|
1231
1232
|
});
|
|
1232
1233
|
});
|
|
1234
|
+
|
|
1235
|
+
describe('When testing triggerService.morphoBluePriceRangeTrigger', () => {
|
|
1236
|
+
describe('encode()', () => {
|
|
1237
|
+
const examples: Array<[[string], [oracle: EthereumAddress, collateralToken: EthereumAddress, loanToken: EthereumAddress, lowerPrice: number, upperPrice: number]]> = [
|
|
1238
|
+
[
|
|
1239
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1240
|
+
[web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 1500, 4000]
|
|
1241
|
+
],
|
|
1242
|
+
[
|
|
1243
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1244
|
+
[web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 0, 5000]
|
|
1245
|
+
],
|
|
1246
|
+
];
|
|
1247
|
+
|
|
1248
|
+
examples.forEach(([expected, actual]) => {
|
|
1249
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1250
|
+
expect(morphoBluePriceRangeTrigger.encode(...actual)).to.eql(expected);
|
|
1251
|
+
});
|
|
1252
|
+
});
|
|
1253
|
+
});
|
|
1254
|
+
|
|
1255
|
+
describe('decode()', () => {
|
|
1256
|
+
const examples: Array<[{ oracle: EthereumAddress, collateralToken: EthereumAddress, loanToken: EthereumAddress, lowerPrice: string, upperPrice: string }, TriggerData]> = [
|
|
1257
|
+
[
|
|
1258
|
+
{
|
|
1259
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1260
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1261
|
+
loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1262
|
+
lowerPrice: '1500',
|
|
1263
|
+
upperPrice: '4000',
|
|
1264
|
+
},
|
|
1265
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1266
|
+
],
|
|
1267
|
+
[
|
|
1268
|
+
{
|
|
1269
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1270
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1271
|
+
loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1272
|
+
lowerPrice: '0',
|
|
1273
|
+
upperPrice: '5000',
|
|
1274
|
+
},
|
|
1275
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8dA6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1276
|
+
],
|
|
1277
|
+
];
|
|
1278
|
+
|
|
1279
|
+
examples.forEach(([expected, actual]) => {
|
|
1280
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1281
|
+
expect(morphoBluePriceRangeTrigger.decode(actual)).to.eql(expected);
|
|
1282
|
+
});
|
|
1283
|
+
});
|
|
1284
|
+
});
|
|
1285
|
+
});
|
|
1233
1286
|
});
|
|
@@ -688,4 +688,36 @@ export const sparkQuotePriceRangeTrigger = {
|
|
|
688
688
|
upperPrice: new Dec(decodedData[3] as string).div(1e8).toString(),
|
|
689
689
|
};
|
|
690
690
|
},
|
|
691
|
+
};
|
|
692
|
+
|
|
693
|
+
export const morphoBluePriceRangeTrigger = {
|
|
694
|
+
encode(
|
|
695
|
+
oracle: EthereumAddress,
|
|
696
|
+
collateralToken: EthereumAddress,
|
|
697
|
+
loanToken: EthereumAddress,
|
|
698
|
+
lowerPrice: number,
|
|
699
|
+
upperPrice: number,
|
|
700
|
+
) {
|
|
701
|
+
// Price is scaled to 1e8
|
|
702
|
+
const lowerPriceFormatted = new Dec(lowerPrice).mul(1e8).floor().toString();
|
|
703
|
+
const upperPriceFormatted = new Dec(upperPrice).mul(1e8).floor().toString();
|
|
704
|
+
return [
|
|
705
|
+
AbiCoder.encodeParameters(
|
|
706
|
+
['address', 'address', 'address', 'uint256', 'uint256'],
|
|
707
|
+
[oracle, collateralToken, loanToken, lowerPriceFormatted, upperPriceFormatted],
|
|
708
|
+
),
|
|
709
|
+
];
|
|
710
|
+
},
|
|
711
|
+
decode(
|
|
712
|
+
triggerData: TriggerData,
|
|
713
|
+
) {
|
|
714
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'address', 'uint256', 'uint256'], triggerData[0]);
|
|
715
|
+
return {
|
|
716
|
+
oracle: decodedData[0] as EthereumAddress,
|
|
717
|
+
collateralToken: decodedData[1] as EthereumAddress,
|
|
718
|
+
loanToken: decodedData[2] as EthereumAddress,
|
|
719
|
+
lowerPrice: new Dec(decodedData[3] as string).div(1e8).toString(),
|
|
720
|
+
upperPrice: new Dec(decodedData[4] as string).div(1e8).toString(),
|
|
721
|
+
};
|
|
722
|
+
},
|
|
691
723
|
};
|
package/src/types/enums.ts
CHANGED
|
@@ -222,6 +222,7 @@ export namespace Bundles {
|
|
|
222
222
|
AAVE_V3_EOA_BOOST_ON_PRICE = 55,
|
|
223
223
|
AAVE_V3_EOA_CLOSE = 56,
|
|
224
224
|
SPARK_CLOSE = 57,
|
|
225
|
+
MORPHO_BLUE_CLOSE = 58,
|
|
225
226
|
}
|
|
226
227
|
|
|
227
228
|
export enum OptimismIds {
|
|
@@ -265,6 +266,7 @@ export namespace Bundles {
|
|
|
265
266
|
AAVE_V3_EOA_REPAY_ON_PRICE = 25,
|
|
266
267
|
AAVE_V3_EOA_BOOST_ON_PRICE = 26,
|
|
267
268
|
AAVE_V3_EOA_CLOSE = 27,
|
|
269
|
+
MORPHO_BLUE_CLOSE = 28,
|
|
268
270
|
}
|
|
269
271
|
|
|
270
272
|
export enum ArbitrumIds {
|
|
@@ -296,6 +298,7 @@ export namespace Bundles {
|
|
|
296
298
|
MORPHO_BLUE_BOOST_ON_PRICE = 25,
|
|
297
299
|
MORPHO_BLUE_EOA_REPAY = 26,
|
|
298
300
|
MORPHO_BLUE_EOA_BOOST = 27,
|
|
301
|
+
MORPHO_BLUE_CLOSE = 28,
|
|
299
302
|
}
|
|
300
303
|
}
|
|
301
304
|
|