@defisaver/automation-sdk 3.3.10-aave-v4-5-dev → 3.3.10-aave-v4-7-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/services/strategySubService.d.ts +3 -3
- package/cjs/services/strategySubService.js +1 -1
- package/cjs/services/strategySubService.test.js +7 -7
- package/cjs/services/triggerService.d.ts +2 -2
- package/cjs/services/triggerService.js +8 -10
- package/cjs/services/triggerService.test.js +6 -6
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +10 -2
- package/cjs/types/enums.d.ts +1 -1
- package/cjs/types/enums.js +1 -1
- package/esm/services/strategySubService.d.ts +3 -3
- package/esm/services/strategySubService.js +1 -1
- package/esm/services/strategySubService.test.js +7 -7
- package/esm/services/triggerService.d.ts +2 -2
- package/esm/services/triggerService.js +8 -10
- package/esm/services/triggerService.test.js +6 -6
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +10 -2
- package/esm/types/enums.d.ts +1 -1
- package/esm/types/enums.js +1 -1
- package/package.json +2 -2
- package/src/services/strategySubService.test.ts +10 -10
- package/src/services/strategySubService.ts +4 -4
- package/src/services/triggerService.test.ts +8 -8
- package/src/services/triggerService.ts +11 -13
- package/src/services/utils.ts +15 -4
- package/src/types/enums.ts +1 -1
|
@@ -122,7 +122,7 @@ export declare const fluidEncode: {
|
|
|
122
122
|
};
|
|
123
123
|
export declare const aaveV4Encode: {
|
|
124
124
|
leverageManagement(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
125
|
-
leverageManagementOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price:
|
|
126
|
-
closeOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice?:
|
|
127
|
-
collateralSwitch(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price:
|
|
125
|
+
leverageManagementOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price: string, priceState: RatioState, ratioState: RatioState): (number | boolean | string[])[];
|
|
126
|
+
closeOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice?: string, stopLossType?: CloseToAssetType, takeProfitPrice?: string, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
127
|
+
collateralSwitch(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: string, ratioState: RatioState): (number | boolean | string[])[];
|
|
128
128
|
};
|
|
@@ -390,7 +390,7 @@ exports.aaveV4Encode = {
|
|
|
390
390
|
const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(spoke, collAssetId, debtAssetId, price, priceState);
|
|
391
391
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
392
392
|
},
|
|
393
|
-
closeOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, stopLossPrice = 0, stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
|
|
393
|
+
closeOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, stopLossPrice = '0', stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = '0', takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
|
|
394
394
|
const isBundle = true;
|
|
395
395
|
const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
396
396
|
const subData = subDataService.aaveV4CloseSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, closeType);
|
|
@@ -1638,7 +1638,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1638
1638
|
describe('leverageManagementOnPrice()', () => {
|
|
1639
1639
|
const examples = [
|
|
1640
1640
|
[
|
|
1641
|
-
[2, true, ["
|
|
1641
|
+
[2, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1642
1642
|
[
|
|
1643
1643
|
2,
|
|
1644
1644
|
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
@@ -1648,7 +1648,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1648
1648
|
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1649
1649
|
20,
|
|
1650
1650
|
160,
|
|
1651
|
-
1500,
|
|
1651
|
+
'1500',
|
|
1652
1652
|
enums_1.RatioState.OVER,
|
|
1653
1653
|
enums_1.RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
|
|
1654
1654
|
]
|
|
@@ -1663,7 +1663,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1663
1663
|
describe('closeOnPrice()', () => {
|
|
1664
1664
|
const examples = [
|
|
1665
1665
|
[
|
|
1666
|
-
[3, true, ["
|
|
1666
|
+
[3, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000003", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1667
1667
|
[
|
|
1668
1668
|
3,
|
|
1669
1669
|
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
@@ -1672,9 +1672,9 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1672
1672
|
10,
|
|
1673
1673
|
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1674
1674
|
20,
|
|
1675
|
-
1400,
|
|
1675
|
+
'1400',
|
|
1676
1676
|
enums_1.CloseToAssetType.DEBT,
|
|
1677
|
-
0,
|
|
1677
|
+
'0',
|
|
1678
1678
|
enums_1.CloseToAssetType.COLLATERAL
|
|
1679
1679
|
]
|
|
1680
1680
|
]
|
|
@@ -1688,7 +1688,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1688
1688
|
describe('collateralSwitch()', () => {
|
|
1689
1689
|
const examples = [
|
|
1690
1690
|
[
|
|
1691
|
-
[4, false, ["
|
|
1691
|
+
[4, false, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1692
1692
|
[
|
|
1693
1693
|
4,
|
|
1694
1694
|
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
@@ -1698,7 +1698,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1698
1698
|
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1699
1699
|
20,
|
|
1700
1700
|
'1000000000000000000',
|
|
1701
|
-
1500,
|
|
1701
|
+
'1500',
|
|
1702
1702
|
enums_1.RatioState.UNDER,
|
|
1703
1703
|
]
|
|
1704
1704
|
]
|
|
@@ -304,7 +304,7 @@ export declare const aaveV4RatioTrigger: {
|
|
|
304
304
|
};
|
|
305
305
|
};
|
|
306
306
|
export declare const aaveV4QuotePriceTrigger: {
|
|
307
|
-
encode(spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, price:
|
|
307
|
+
encode(spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, price: string, ratioState: RatioState): string[];
|
|
308
308
|
decode(triggerData: string[]): {
|
|
309
309
|
spoke: string;
|
|
310
310
|
baseTokenId: number;
|
|
@@ -314,7 +314,7 @@ export declare const aaveV4QuotePriceTrigger: {
|
|
|
314
314
|
};
|
|
315
315
|
};
|
|
316
316
|
export declare const aaveV4QuotePriceRangeTrigger: {
|
|
317
|
-
encode(spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, lowerPrice:
|
|
317
|
+
encode(spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, lowerPrice: string, upperPrice: string): string[];
|
|
318
318
|
decode(triggerData: string[]): {
|
|
319
319
|
spoke: string;
|
|
320
320
|
baseTokenId: number;
|
|
@@ -579,28 +579,26 @@ exports.aaveV4RatioTrigger = {
|
|
|
579
579
|
};
|
|
580
580
|
exports.aaveV4QuotePriceTrigger = {
|
|
581
581
|
encode(spoke, baseTokenId, quoteTokenId, price, ratioState) {
|
|
582
|
-
// Price is
|
|
583
|
-
const _price = new decimal_js_1.default(price
|
|
582
|
+
// Price is intentionally scaled to 1e18 for higher precision.
|
|
583
|
+
const _price = new decimal_js_1.default(price).mul(1e18).floor().toString();
|
|
584
584
|
return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], [spoke, baseTokenId, quoteTokenId, _price, ratioState])];
|
|
585
585
|
},
|
|
586
586
|
decode(triggerData) {
|
|
587
587
|
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
588
|
-
// Price is always in 8 decimals
|
|
589
|
-
const price = new decimal_js_1.default(decodedData[3]).div(Math.pow(10, 8)).toDP(8).toString();
|
|
590
588
|
return {
|
|
591
589
|
spoke: decodedData[0],
|
|
592
590
|
baseTokenId: Number(decodedData[1]),
|
|
593
591
|
quoteTokenId: Number(decodedData[2]),
|
|
594
|
-
price,
|
|
592
|
+
price: new decimal_js_1.default(decodedData[3]).div(1e18).toString(),
|
|
595
593
|
ratioState: Number(decodedData[4]),
|
|
596
594
|
};
|
|
597
595
|
},
|
|
598
596
|
};
|
|
599
597
|
exports.aaveV4QuotePriceRangeTrigger = {
|
|
600
598
|
encode(spoke, baseTokenId, quoteTokenId, lowerPrice, upperPrice) {
|
|
601
|
-
// Price is scaled to
|
|
602
|
-
const lowerPriceFormatted = new decimal_js_1.default(lowerPrice).mul(
|
|
603
|
-
const upperPriceFormatted = new decimal_js_1.default(upperPrice).mul(
|
|
599
|
+
// Price is intentionally scaled to 1e18 for higher precision.
|
|
600
|
+
const lowerPriceFormatted = new decimal_js_1.default(lowerPrice).mul(1e18).floor().toString();
|
|
601
|
+
const upperPriceFormatted = new decimal_js_1.default(upperPrice).mul(1e18).floor().toString();
|
|
604
602
|
return [
|
|
605
603
|
web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint256'], [spoke, baseTokenId, quoteTokenId, lowerPriceFormatted, upperPriceFormatted]),
|
|
606
604
|
];
|
|
@@ -611,8 +609,8 @@ exports.aaveV4QuotePriceRangeTrigger = {
|
|
|
611
609
|
spoke: decodedData[0],
|
|
612
610
|
baseTokenId: Number(decodedData[1]),
|
|
613
611
|
quoteTokenId: Number(decodedData[2]),
|
|
614
|
-
lowerPrice: new decimal_js_1.default(decodedData[3]).div(
|
|
615
|
-
upperPrice: new decimal_js_1.default(decodedData[4]).div(
|
|
612
|
+
lowerPrice: new decimal_js_1.default(decodedData[3]).div(1e18).toString(),
|
|
613
|
+
upperPrice: new decimal_js_1.default(decodedData[4]).div(1e18).toString(),
|
|
616
614
|
};
|
|
617
615
|
},
|
|
618
616
|
};
|
|
@@ -1216,8 +1216,8 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1216
1216
|
describe('encode()', () => {
|
|
1217
1217
|
const examples = [
|
|
1218
1218
|
[
|
|
1219
|
-
['
|
|
1220
|
-
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, 1500, enums_1.RatioState.OVER]
|
|
1219
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1220
|
+
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, '1500', enums_1.RatioState.OVER]
|
|
1221
1221
|
],
|
|
1222
1222
|
];
|
|
1223
1223
|
examples.forEach(([expected, actual]) => {
|
|
@@ -1230,7 +1230,7 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1230
1230
|
const examples = [
|
|
1231
1231
|
[
|
|
1232
1232
|
{ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, price: '1500', ratioState: enums_1.RatioState.OVER },
|
|
1233
|
-
['
|
|
1233
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1234
1234
|
],
|
|
1235
1235
|
];
|
|
1236
1236
|
examples.forEach(([expected, actual]) => {
|
|
@@ -1244,8 +1244,8 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1244
1244
|
describe('encode()', () => {
|
|
1245
1245
|
const examples = [
|
|
1246
1246
|
[
|
|
1247
|
-
['
|
|
1248
|
-
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, 1400, 1600]
|
|
1247
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae00000000000000000000000000000000000000000000000000056bc75e2d631000000'],
|
|
1248
|
+
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, '1400', '1600']
|
|
1249
1249
|
],
|
|
1250
1250
|
];
|
|
1251
1251
|
examples.forEach(([expected, actual]) => {
|
|
@@ -1258,7 +1258,7 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1258
1258
|
const examples = [
|
|
1259
1259
|
[
|
|
1260
1260
|
{ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, lowerPrice: '1400', upperPrice: '1600' },
|
|
1261
|
-
['
|
|
1261
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae00000000000000000000000000000000000000000000000000056bc75e2d631000000'],
|
|
1262
1262
|
],
|
|
1263
1263
|
];
|
|
1264
1264
|
examples.forEach(([expected, actual]) => {
|
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
|
}
|
package/cjs/types/enums.d.ts
CHANGED
|
@@ -89,7 +89,7 @@ export declare namespace Strategies {
|
|
|
89
89
|
LIQUITY_V2_PAYBACK = 113,
|
|
90
90
|
AAVE_V3_COLLATERAL_SWITCH = 135,
|
|
91
91
|
AAVE_V4_COLLATERAL_SWITCH = 154,
|
|
92
|
-
AAVE_V4_COLLATERAL_SWITCH_EOA =
|
|
92
|
+
AAVE_V4_COLLATERAL_SWITCH_EOA = 155
|
|
93
93
|
}
|
|
94
94
|
enum OptimismIds {
|
|
95
95
|
EXCHANGE_DCA = 8,
|
package/cjs/types/enums.js
CHANGED
|
@@ -105,7 +105,7 @@ var Strategies;
|
|
|
105
105
|
MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
|
|
106
106
|
MainnetIds[MainnetIds["AAVE_V3_COLLATERAL_SWITCH"] = 135] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
107
107
|
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH"] = 154] = "AAVE_V4_COLLATERAL_SWITCH";
|
|
108
|
-
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] =
|
|
108
|
+
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] = 155] = "AAVE_V4_COLLATERAL_SWITCH_EOA";
|
|
109
109
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
110
110
|
let OptimismIds;
|
|
111
111
|
(function (OptimismIds) {
|
|
@@ -122,7 +122,7 @@ export declare const fluidEncode: {
|
|
|
122
122
|
};
|
|
123
123
|
export declare const aaveV4Encode: {
|
|
124
124
|
leverageManagement(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
125
|
-
leverageManagementOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price:
|
|
126
|
-
closeOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice?:
|
|
127
|
-
collateralSwitch(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price:
|
|
125
|
+
leverageManagementOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price: string, priceState: RatioState, ratioState: RatioState): (number | boolean | string[])[];
|
|
126
|
+
closeOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice?: string, stopLossType?: CloseToAssetType, takeProfitPrice?: string, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
127
|
+
collateralSwitch(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: string, ratioState: RatioState): (number | boolean | string[])[];
|
|
128
128
|
};
|
|
@@ -361,7 +361,7 @@ export const aaveV4Encode = {
|
|
|
361
361
|
const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(spoke, collAssetId, debtAssetId, price, priceState);
|
|
362
362
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
363
363
|
},
|
|
364
|
-
closeOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
|
|
364
|
+
closeOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, stopLossPrice = '0', stopLossType = CloseToAssetType.DEBT, takeProfitPrice = '0', takeProfitType = CloseToAssetType.COLLATERAL) {
|
|
365
365
|
const isBundle = true;
|
|
366
366
|
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
367
367
|
const subData = subDataService.aaveV4CloseSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, closeType);
|
|
@@ -1610,7 +1610,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1610
1610
|
describe('leverageManagementOnPrice()', () => {
|
|
1611
1611
|
const examples = [
|
|
1612
1612
|
[
|
|
1613
|
-
[2, true, ["
|
|
1613
|
+
[2, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1614
1614
|
[
|
|
1615
1615
|
2,
|
|
1616
1616
|
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
@@ -1620,7 +1620,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1620
1620
|
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1621
1621
|
20,
|
|
1622
1622
|
160,
|
|
1623
|
-
1500,
|
|
1623
|
+
'1500',
|
|
1624
1624
|
RatioState.OVER,
|
|
1625
1625
|
RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
|
|
1626
1626
|
]
|
|
@@ -1635,7 +1635,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1635
1635
|
describe('closeOnPrice()', () => {
|
|
1636
1636
|
const examples = [
|
|
1637
1637
|
[
|
|
1638
|
-
[3, true, ["
|
|
1638
|
+
[3, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000003", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1639
1639
|
[
|
|
1640
1640
|
3,
|
|
1641
1641
|
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
@@ -1644,9 +1644,9 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1644
1644
|
10,
|
|
1645
1645
|
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1646
1646
|
20,
|
|
1647
|
-
1400,
|
|
1647
|
+
'1400',
|
|
1648
1648
|
CloseToAssetType.DEBT,
|
|
1649
|
-
0,
|
|
1649
|
+
'0',
|
|
1650
1650
|
CloseToAssetType.COLLATERAL
|
|
1651
1651
|
]
|
|
1652
1652
|
]
|
|
@@ -1660,7 +1660,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1660
1660
|
describe('collateralSwitch()', () => {
|
|
1661
1661
|
const examples = [
|
|
1662
1662
|
[
|
|
1663
|
-
[4, false, ["
|
|
1663
|
+
[4, false, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1664
1664
|
[
|
|
1665
1665
|
4,
|
|
1666
1666
|
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
@@ -1670,7 +1670,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1670
1670
|
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1671
1671
|
20,
|
|
1672
1672
|
'1000000000000000000',
|
|
1673
|
-
1500,
|
|
1673
|
+
'1500',
|
|
1674
1674
|
RatioState.UNDER,
|
|
1675
1675
|
]
|
|
1676
1676
|
]
|
|
@@ -304,7 +304,7 @@ export declare const aaveV4RatioTrigger: {
|
|
|
304
304
|
};
|
|
305
305
|
};
|
|
306
306
|
export declare const aaveV4QuotePriceTrigger: {
|
|
307
|
-
encode(spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, price:
|
|
307
|
+
encode(spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, price: string, ratioState: RatioState): string[];
|
|
308
308
|
decode(triggerData: string[]): {
|
|
309
309
|
spoke: string;
|
|
310
310
|
baseTokenId: number;
|
|
@@ -314,7 +314,7 @@ export declare const aaveV4QuotePriceTrigger: {
|
|
|
314
314
|
};
|
|
315
315
|
};
|
|
316
316
|
export declare const aaveV4QuotePriceRangeTrigger: {
|
|
317
|
-
encode(spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, lowerPrice:
|
|
317
|
+
encode(spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, lowerPrice: string, upperPrice: string): string[];
|
|
318
318
|
decode(triggerData: string[]): {
|
|
319
319
|
spoke: string;
|
|
320
320
|
baseTokenId: number;
|
|
@@ -550,28 +550,26 @@ export const aaveV4RatioTrigger = {
|
|
|
550
550
|
};
|
|
551
551
|
export const aaveV4QuotePriceTrigger = {
|
|
552
552
|
encode(spoke, baseTokenId, quoteTokenId, price, ratioState) {
|
|
553
|
-
// Price is
|
|
554
|
-
const _price = new Dec(price
|
|
553
|
+
// Price is intentionally scaled to 1e18 for higher precision.
|
|
554
|
+
const _price = new Dec(price).mul(1e18).floor().toString();
|
|
555
555
|
return [AbiCoder.encodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], [spoke, baseTokenId, quoteTokenId, _price, ratioState])];
|
|
556
556
|
},
|
|
557
557
|
decode(triggerData) {
|
|
558
558
|
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
559
|
-
// Price is always in 8 decimals
|
|
560
|
-
const price = new Dec(decodedData[3]).div(Math.pow(10, 8)).toDP(8).toString();
|
|
561
559
|
return {
|
|
562
560
|
spoke: decodedData[0],
|
|
563
561
|
baseTokenId: Number(decodedData[1]),
|
|
564
562
|
quoteTokenId: Number(decodedData[2]),
|
|
565
|
-
price,
|
|
563
|
+
price: new Dec(decodedData[3]).div(1e18).toString(),
|
|
566
564
|
ratioState: Number(decodedData[4]),
|
|
567
565
|
};
|
|
568
566
|
},
|
|
569
567
|
};
|
|
570
568
|
export const aaveV4QuotePriceRangeTrigger = {
|
|
571
569
|
encode(spoke, baseTokenId, quoteTokenId, lowerPrice, upperPrice) {
|
|
572
|
-
// Price is scaled to
|
|
573
|
-
const lowerPriceFormatted = new Dec(lowerPrice).mul(
|
|
574
|
-
const upperPriceFormatted = new Dec(upperPrice).mul(
|
|
570
|
+
// Price is intentionally scaled to 1e18 for higher precision.
|
|
571
|
+
const lowerPriceFormatted = new Dec(lowerPrice).mul(1e18).floor().toString();
|
|
572
|
+
const upperPriceFormatted = new Dec(upperPrice).mul(1e18).floor().toString();
|
|
575
573
|
return [
|
|
576
574
|
AbiCoder.encodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint256'], [spoke, baseTokenId, quoteTokenId, lowerPriceFormatted, upperPriceFormatted]),
|
|
577
575
|
];
|
|
@@ -582,8 +580,8 @@ export const aaveV4QuotePriceRangeTrigger = {
|
|
|
582
580
|
spoke: decodedData[0],
|
|
583
581
|
baseTokenId: Number(decodedData[1]),
|
|
584
582
|
quoteTokenId: Number(decodedData[2]),
|
|
585
|
-
lowerPrice: new Dec(decodedData[3]).div(
|
|
586
|
-
upperPrice: new Dec(decodedData[4]).div(
|
|
583
|
+
lowerPrice: new Dec(decodedData[3]).div(1e18).toString(),
|
|
584
|
+
upperPrice: new Dec(decodedData[4]).div(1e18).toString(),
|
|
587
585
|
};
|
|
588
586
|
},
|
|
589
587
|
};
|
|
@@ -1191,8 +1191,8 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1191
1191
|
describe('encode()', () => {
|
|
1192
1192
|
const examples = [
|
|
1193
1193
|
[
|
|
1194
|
-
['
|
|
1195
|
-
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, 1500, RatioState.OVER]
|
|
1194
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1195
|
+
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, '1500', RatioState.OVER]
|
|
1196
1196
|
],
|
|
1197
1197
|
];
|
|
1198
1198
|
examples.forEach(([expected, actual]) => {
|
|
@@ -1205,7 +1205,7 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1205
1205
|
const examples = [
|
|
1206
1206
|
[
|
|
1207
1207
|
{ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, price: '1500', ratioState: RatioState.OVER },
|
|
1208
|
-
['
|
|
1208
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1209
1209
|
],
|
|
1210
1210
|
];
|
|
1211
1211
|
examples.forEach(([expected, actual]) => {
|
|
@@ -1219,8 +1219,8 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1219
1219
|
describe('encode()', () => {
|
|
1220
1220
|
const examples = [
|
|
1221
1221
|
[
|
|
1222
|
-
['
|
|
1223
|
-
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, 1400, 1600]
|
|
1222
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae00000000000000000000000000000000000000000000000000056bc75e2d631000000'],
|
|
1223
|
+
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, '1400', '1600']
|
|
1224
1224
|
],
|
|
1225
1225
|
];
|
|
1226
1226
|
examples.forEach(([expected, actual]) => {
|
|
@@ -1233,7 +1233,7 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1233
1233
|
const examples = [
|
|
1234
1234
|
[
|
|
1235
1235
|
{ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, lowerPrice: '1400', upperPrice: '1600' },
|
|
1236
|
-
['
|
|
1236
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae00000000000000000000000000000000000000000000000000056bc75e2d631000000'],
|
|
1237
1237
|
],
|
|
1238
1238
|
];
|
|
1239
1239
|
examples.forEach(([expected, actual]) => {
|
package/esm/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/esm/services/utils.js
CHANGED
|
@@ -81,8 +81,16 @@ export function getPositionId(...args) {
|
|
|
81
81
|
return args.map(arg => arg.toString().toLowerCase().split(' ').join('_')).join('-');
|
|
82
82
|
}
|
|
83
83
|
export function getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType) {
|
|
84
|
-
const
|
|
85
|
-
const
|
|
84
|
+
const stopLossPriceDec = new Dec(stopLossPrice);
|
|
85
|
+
const takeProfitPriceDec = new Dec(takeProfitPrice);
|
|
86
|
+
if (!stopLossPriceDec.isFinite() || stopLossPriceDec.isNegative()) {
|
|
87
|
+
throw new Error('CloseOnPrice: stopLossPrice must be a finite non-negative number');
|
|
88
|
+
}
|
|
89
|
+
if (!takeProfitPriceDec.isFinite() || takeProfitPriceDec.isNegative()) {
|
|
90
|
+
throw new Error('CloseOnPrice: takeProfitPrice must be a finite non-negative number');
|
|
91
|
+
}
|
|
92
|
+
const isStopLoss = stopLossPriceDec.gt(0);
|
|
93
|
+
const isTakeProfit = takeProfitPriceDec.gt(0);
|
|
86
94
|
if (!isStopLoss && !isTakeProfit) {
|
|
87
95
|
throw new Error('CloseOnPrice: At least one price must be defined');
|
|
88
96
|
}
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -89,7 +89,7 @@ export declare namespace Strategies {
|
|
|
89
89
|
LIQUITY_V2_PAYBACK = 113,
|
|
90
90
|
AAVE_V3_COLLATERAL_SWITCH = 135,
|
|
91
91
|
AAVE_V4_COLLATERAL_SWITCH = 154,
|
|
92
|
-
AAVE_V4_COLLATERAL_SWITCH_EOA =
|
|
92
|
+
AAVE_V4_COLLATERAL_SWITCH_EOA = 155
|
|
93
93
|
}
|
|
94
94
|
enum OptimismIds {
|
|
95
95
|
EXCHANGE_DCA = 8,
|
package/esm/types/enums.js
CHANGED
|
@@ -102,7 +102,7 @@ export var Strategies;
|
|
|
102
102
|
MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
|
|
103
103
|
MainnetIds[MainnetIds["AAVE_V3_COLLATERAL_SWITCH"] = 135] = "AAVE_V3_COLLATERAL_SWITCH";
|
|
104
104
|
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH"] = 154] = "AAVE_V4_COLLATERAL_SWITCH";
|
|
105
|
-
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] =
|
|
105
|
+
MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH_EOA"] = 155] = "AAVE_V4_COLLATERAL_SWITCH_EOA";
|
|
106
106
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
107
107
|
let OptimismIds;
|
|
108
108
|
(function (OptimismIds) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/automation-sdk",
|
|
3
|
-
"version": "3.3.10-aave-v4-
|
|
3
|
+
"version": "3.3.10-aave-v4-7-dev",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"repository": "https://github.com/defisaver/automation-sdk",
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@defisaver/sdk": "1.3.18-aave-v4-
|
|
26
|
+
"@defisaver/sdk": "1.3.18-aave-v4-3-dev",
|
|
27
27
|
"@defisaver/tokens": "^1.6.19",
|
|
28
28
|
"@ethersproject/address": "^5.0.10",
|
|
29
29
|
"@ethersproject/solidity": "^5.0.9",
|
|
@@ -1925,11 +1925,11 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1925
1925
|
const examples: Array<[
|
|
1926
1926
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1927
1927
|
[
|
|
1928
|
-
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price:
|
|
1928
|
+
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price: string, priceState: RatioState, ratioState: RatioState
|
|
1929
1929
|
]
|
|
1930
1930
|
]> = [
|
|
1931
1931
|
[
|
|
1932
|
-
[2,true,["
|
|
1932
|
+
[2,true,["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x000000000000000000000000000000000000000000000000000000000000000a","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x0000000000000000000000000000000000000000000000000000000000000014","0x0000000000000000000000000000000000000000000000000000000000000000","0x00000000000000000000000000000000000000000000000016345785d8a00000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1933
1933
|
[
|
|
1934
1934
|
2,
|
|
1935
1935
|
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
@@ -1939,7 +1939,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1939
1939
|
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1940
1940
|
20,
|
|
1941
1941
|
160,
|
|
1942
|
-
1500,
|
|
1942
|
+
'1500',
|
|
1943
1943
|
RatioState.OVER, // priceState - goes to trigger
|
|
1944
1944
|
RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
|
|
1945
1945
|
]
|
|
@@ -1957,11 +1957,11 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1957
1957
|
const examples: Array<[
|
|
1958
1958
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1959
1959
|
[
|
|
1960
|
-
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice:
|
|
1960
|
+
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice: string, stopLossType: CloseToAssetType, takeProfitPrice: string, takeProfitType: CloseToAssetType
|
|
1961
1961
|
]
|
|
1962
1962
|
]> = [
|
|
1963
1963
|
[
|
|
1964
|
-
[3,true,["
|
|
1964
|
+
[3,true,["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae000000000000000000000000000000000000000000000000000000000000000000000"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x000000000000000000000000000000000000000000000000000000000000000a","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x0000000000000000000000000000000000000000000000000000000000000014","0x0000000000000000000000000000000000000000000000000000000000000003","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1965
1965
|
[
|
|
1966
1966
|
3,
|
|
1967
1967
|
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
@@ -1970,9 +1970,9 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1970
1970
|
10,
|
|
1971
1971
|
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1972
1972
|
20,
|
|
1973
|
-
1400,
|
|
1973
|
+
'1400',
|
|
1974
1974
|
CloseToAssetType.DEBT,
|
|
1975
|
-
0,
|
|
1975
|
+
'0',
|
|
1976
1976
|
CloseToAssetType.COLLATERAL
|
|
1977
1977
|
]
|
|
1978
1978
|
]
|
|
@@ -1989,11 +1989,11 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1989
1989
|
const examples: Array<[
|
|
1990
1990
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1991
1991
|
[
|
|
1992
|
-
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price:
|
|
1992
|
+
strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: string, ratioState: RatioState
|
|
1993
1993
|
]
|
|
1994
1994
|
]> = [
|
|
1995
1995
|
[
|
|
1996
|
-
[4,false,["
|
|
1996
|
+
[4,false,["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000001"],["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e","0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c","0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2","0x000000000000000000000000000000000000000000000000000000000000000a","0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48","0x0000000000000000000000000000000000000000000000000000000000000014","0x0000000000000000000000000000000000000000000000000de0b6b3a7640000","0x0000000000000000000000000000000000000000000000000000000000000000","0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1997
1997
|
[
|
|
1998
1998
|
4,
|
|
1999
1999
|
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
@@ -2003,7 +2003,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
2003
2003
|
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
2004
2004
|
20,
|
|
2005
2005
|
'1000000000000000000',
|
|
2006
|
-
1500,
|
|
2006
|
+
'1500',
|
|
2007
2007
|
RatioState.UNDER,
|
|
2008
2008
|
]
|
|
2009
2009
|
]
|
|
@@ -871,7 +871,7 @@ export const aaveV4Encode = {
|
|
|
871
871
|
debtAsset: EthereumAddress,
|
|
872
872
|
debtAssetId: number,
|
|
873
873
|
targetRatio: number,
|
|
874
|
-
price:
|
|
874
|
+
price: string,
|
|
875
875
|
priceState: RatioState,
|
|
876
876
|
ratioState: RatioState, // UNDER for repay, OVER for boost
|
|
877
877
|
) {
|
|
@@ -904,9 +904,9 @@ export const aaveV4Encode = {
|
|
|
904
904
|
collAssetId: number,
|
|
905
905
|
debtAsset: EthereumAddress,
|
|
906
906
|
debtAssetId: number,
|
|
907
|
-
stopLossPrice:
|
|
907
|
+
stopLossPrice: string = '0',
|
|
908
908
|
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
909
|
-
takeProfitPrice:
|
|
909
|
+
takeProfitPrice: string = '0',
|
|
910
910
|
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
911
911
|
) {
|
|
912
912
|
const isBundle = true;
|
|
@@ -940,7 +940,7 @@ export const aaveV4Encode = {
|
|
|
940
940
|
toAsset: EthereumAddress,
|
|
941
941
|
toAssetId: number,
|
|
942
942
|
amountToSwitch: string,
|
|
943
|
-
price:
|
|
943
|
+
price: string,
|
|
944
944
|
ratioState: RatioState,
|
|
945
945
|
) {
|
|
946
946
|
const isBundle = false;
|
|
@@ -1321,10 +1321,10 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1321
1321
|
|
|
1322
1322
|
describe('When testing triggerService.aaveV4QuotePriceTrigger', () => {
|
|
1323
1323
|
describe('encode()', () => {
|
|
1324
|
-
const examples: Array<[[string], [spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, price:
|
|
1324
|
+
const examples: Array<[[string], [spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, price: string, ratioState: RatioState]]> = [
|
|
1325
1325
|
[
|
|
1326
|
-
['
|
|
1327
|
-
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, 1500, RatioState.OVER]
|
|
1326
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1327
|
+
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, '1500', RatioState.OVER]
|
|
1328
1328
|
],
|
|
1329
1329
|
];
|
|
1330
1330
|
|
|
@@ -1339,7 +1339,7 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1339
1339
|
const examples: Array<[{ spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, price: string, ratioState: RatioState }, TriggerData]> = [
|
|
1340
1340
|
[
|
|
1341
1341
|
{ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, price: '1500', ratioState: RatioState.OVER },
|
|
1342
|
-
['
|
|
1342
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1343
1343
|
],
|
|
1344
1344
|
];
|
|
1345
1345
|
|
|
@@ -1353,10 +1353,10 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1353
1353
|
|
|
1354
1354
|
describe('When testing triggerService.aaveV4QuotePriceRangeTrigger', () => {
|
|
1355
1355
|
describe('encode()', () => {
|
|
1356
|
-
const examples: Array<[[string], [spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, lowerPrice:
|
|
1356
|
+
const examples: Array<[[string], [spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, lowerPrice: string, upperPrice: string]]> = [
|
|
1357
1357
|
[
|
|
1358
|
-
['
|
|
1359
|
-
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, 1400, 1600]
|
|
1358
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae00000000000000000000000000000000000000000000000000056bc75e2d631000000'],
|
|
1359
|
+
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, '1400', '1600']
|
|
1360
1360
|
],
|
|
1361
1361
|
];
|
|
1362
1362
|
|
|
@@ -1371,7 +1371,7 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1371
1371
|
const examples: Array<[{ spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, lowerPrice: string, upperPrice: string }, TriggerData]> = [
|
|
1372
1372
|
[
|
|
1373
1373
|
{ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, lowerPrice: '1400', upperPrice: '1600' },
|
|
1374
|
-
['
|
|
1374
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae00000000000000000000000000000000000000000000000000056bc75e2d631000000'],
|
|
1375
1375
|
],
|
|
1376
1376
|
];
|
|
1377
1377
|
|
|
@@ -766,24 +766,22 @@ export const aaveV4QuotePriceTrigger = {
|
|
|
766
766
|
spoke: EthereumAddress,
|
|
767
767
|
baseTokenId: number,
|
|
768
768
|
quoteTokenId: number,
|
|
769
|
-
price:
|
|
769
|
+
price: string,
|
|
770
770
|
ratioState: RatioState,
|
|
771
771
|
) {
|
|
772
|
-
// Price is
|
|
773
|
-
const _price = new Dec(price
|
|
772
|
+
// Price is intentionally scaled to 1e18 for higher precision.
|
|
773
|
+
const _price = new Dec(price).mul(1e18).floor().toString();
|
|
774
774
|
return [AbiCoder.encodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], [spoke, baseTokenId, quoteTokenId, _price, ratioState])];
|
|
775
775
|
},
|
|
776
776
|
decode(
|
|
777
777
|
triggerData: TriggerData,
|
|
778
778
|
) {
|
|
779
779
|
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
780
|
-
// Price is always in 8 decimals
|
|
781
|
-
const price = new Dec(decodedData[3] as string).div(10 ** 8).toDP(8).toString();
|
|
782
780
|
return {
|
|
783
781
|
spoke: decodedData[0] as EthereumAddress,
|
|
784
782
|
baseTokenId: Number(decodedData[1]),
|
|
785
783
|
quoteTokenId: Number(decodedData[2]),
|
|
786
|
-
price,
|
|
784
|
+
price: new Dec(decodedData[3] as string).div(1e18).toString(),
|
|
787
785
|
ratioState: Number(decodedData[4]),
|
|
788
786
|
};
|
|
789
787
|
},
|
|
@@ -794,12 +792,12 @@ export const aaveV4QuotePriceRangeTrigger = {
|
|
|
794
792
|
spoke: EthereumAddress,
|
|
795
793
|
baseTokenId: number,
|
|
796
794
|
quoteTokenId: number,
|
|
797
|
-
lowerPrice:
|
|
798
|
-
upperPrice:
|
|
795
|
+
lowerPrice: string,
|
|
796
|
+
upperPrice: string,
|
|
799
797
|
) {
|
|
800
|
-
// Price is scaled to
|
|
801
|
-
const lowerPriceFormatted = new Dec(lowerPrice).mul(
|
|
802
|
-
const upperPriceFormatted = new Dec(upperPrice).mul(
|
|
798
|
+
// Price is intentionally scaled to 1e18 for higher precision.
|
|
799
|
+
const lowerPriceFormatted = new Dec(lowerPrice).mul(1e18).floor().toString();
|
|
800
|
+
const upperPriceFormatted = new Dec(upperPrice).mul(1e18).floor().toString();
|
|
803
801
|
return [
|
|
804
802
|
AbiCoder.encodeParameters(
|
|
805
803
|
['address', 'uint256', 'uint256', 'uint256', 'uint256'],
|
|
@@ -814,8 +812,8 @@ export const aaveV4QuotePriceRangeTrigger = {
|
|
|
814
812
|
spoke: decodedData[0] as EthereumAddress,
|
|
815
813
|
baseTokenId: Number(decodedData[1]),
|
|
816
814
|
quoteTokenId: Number(decodedData[2]),
|
|
817
|
-
lowerPrice: new Dec(decodedData[3] as string).div(
|
|
818
|
-
upperPrice: new Dec(decodedData[4] as string).div(
|
|
815
|
+
lowerPrice: new Dec(decodedData[3] as string).div(1e18).toString(),
|
|
816
|
+
upperPrice: new Dec(decodedData[4] as string).div(1e18).toString(),
|
|
819
817
|
};
|
|
820
818
|
},
|
|
821
819
|
};
|
package/src/services/utils.ts
CHANGED
|
@@ -106,13 +106,24 @@ export function getPositionId(...args: (number | string)[]) {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
export function getCloseStrategyType(
|
|
109
|
-
stopLossPrice: number,
|
|
109
|
+
stopLossPrice: number | string,
|
|
110
110
|
stopLossType: CloseToAssetType,
|
|
111
|
-
takeProfitPrice: number,
|
|
111
|
+
takeProfitPrice: number | string,
|
|
112
112
|
takeProfitType: CloseToAssetType,
|
|
113
113
|
): CloseStrategyType {
|
|
114
|
-
const
|
|
115
|
-
const
|
|
114
|
+
const stopLossPriceDec = new Dec(stopLossPrice);
|
|
115
|
+
const takeProfitPriceDec = new Dec(takeProfitPrice);
|
|
116
|
+
|
|
117
|
+
if (!stopLossPriceDec.isFinite() || stopLossPriceDec.isNegative()) {
|
|
118
|
+
throw new Error('CloseOnPrice: stopLossPrice must be a finite non-negative number');
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!takeProfitPriceDec.isFinite() || takeProfitPriceDec.isNegative()) {
|
|
122
|
+
throw new Error('CloseOnPrice: takeProfitPrice must be a finite non-negative number');
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const isStopLoss = stopLossPriceDec.gt(0);
|
|
126
|
+
const isTakeProfit = takeProfitPriceDec.gt(0);
|
|
116
127
|
|
|
117
128
|
if (!isStopLoss && !isTakeProfit) {
|
|
118
129
|
throw new Error('CloseOnPrice: At least one price must be defined');
|
package/src/types/enums.ts
CHANGED