@defisaver/automation-sdk 3.3.10 → 3.3.11-aave-v4-1-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 +2 -0
- package/cjs/automation/private/StrategiesAutomation.js +10 -1
- package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
- package/cjs/constants/index.d.ts +1 -0
- package/cjs/constants/index.js +72 -1
- package/cjs/services/ethereumService.test.js +2 -0
- package/cjs/services/strategiesService.js +129 -0
- package/cjs/services/strategySubService.d.ts +19 -0
- package/cjs/services/strategySubService.js +37 -1
- package/cjs/services/strategySubService.test.js +229 -0
- package/cjs/services/subDataService.d.ts +298 -129
- package/cjs/services/subDataService.js +639 -369
- package/cjs/services/subDataService.test.js +214 -0
- package/cjs/services/triggerService.d.ts +38 -0
- package/cjs/services/triggerService.js +68 -1
- package/cjs/services/triggerService.test.js +130 -0
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +10 -2
- package/cjs/types/enums.d.ts +19 -3
- package/cjs/types/enums.js +16 -0
- package/cjs/types/index.d.ts +33 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +2 -0
- package/esm/automation/private/StrategiesAutomation.js +10 -1
- package/esm/automation/private/StrategiesAutomation.test.js +25 -0
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +71 -0
- package/esm/services/ethereumService.test.js +2 -0
- package/esm/services/strategiesService.js +130 -1
- package/esm/services/strategySubService.d.ts +19 -0
- package/esm/services/strategySubService.js +36 -0
- package/esm/services/strategySubService.test.js +230 -1
- package/esm/services/subDataService.d.ts +298 -129
- package/esm/services/subDataService.js +639 -369
- package/esm/services/subDataService.test.js +214 -0
- package/esm/services/triggerService.d.ts +38 -0
- package/esm/services/triggerService.js +67 -0
- package/esm/services/triggerService.test.js +131 -1
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +10 -2
- package/esm/types/enums.d.ts +19 -3
- package/esm/types/enums.js +16 -0
- package/esm/types/index.d.ts +33 -1
- package/package.json +2 -2
- package/src/automation/private/StrategiesAutomation.test.ts +40 -0
- package/src/automation/private/StrategiesAutomation.ts +11 -0
- package/src/constants/index.ts +72 -0
- package/src/services/ethereumService.test.ts +2 -0
- package/src/services/strategiesService.ts +150 -2
- package/src/services/strategySubService.test.ts +286 -0
- package/src/services/strategySubService.ts +140 -0
- package/src/services/subDataService.test.ts +239 -0
- package/src/services/subDataService.ts +1072 -784
- package/src/services/triggerService.test.ts +148 -0
- package/src/services/triggerService.ts +97 -1
- package/src/services/utils.ts +15 -4
- package/src/types/enums.ts +16 -0
- package/src/types/index.ts +40 -1
|
@@ -32,6 +32,10 @@ import {
|
|
|
32
32
|
compoundV3PriceRangeTrigger,
|
|
33
33
|
aaveV3QuotePriceRangeTrigger,
|
|
34
34
|
morphoBluePriceRangeTrigger,
|
|
35
|
+
sparkQuotePriceTrigger,
|
|
36
|
+
aaveV4RatioTrigger,
|
|
37
|
+
aaveV4QuotePriceTrigger,
|
|
38
|
+
aaveV4QuotePriceRangeTrigger,
|
|
35
39
|
} from './triggerService';
|
|
36
40
|
|
|
37
41
|
describe('Feature: triggerService.ts', () => {
|
|
@@ -1283,4 +1287,148 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1283
1287
|
});
|
|
1284
1288
|
});
|
|
1285
1289
|
});
|
|
1290
|
+
describe('When testing triggerService.aaveV4RatioTrigger', () => {
|
|
1291
|
+
describe('encode()', () => {
|
|
1292
|
+
const examples: Array<[[string], [owner: EthereumAddress, spoke: EthereumAddress, ratioPercentage: number, ratioState: RatioState]]> = [
|
|
1293
|
+
[
|
|
1294
|
+
['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1295
|
+
[web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 120, RatioState.UNDER]
|
|
1296
|
+
],
|
|
1297
|
+
];
|
|
1298
|
+
|
|
1299
|
+
examples.forEach(([expected, actual]) => {
|
|
1300
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1301
|
+
expect(aaveV4RatioTrigger.encode(...actual)).to.eql(expected);
|
|
1302
|
+
});
|
|
1303
|
+
});
|
|
1304
|
+
});
|
|
1305
|
+
|
|
1306
|
+
describe('decode()', () => {
|
|
1307
|
+
const examples: Array<[{ owner: EthereumAddress, spoke: EthereumAddress, ratio: number, ratioState: RatioState }, TriggerData]> = [
|
|
1308
|
+
[
|
|
1309
|
+
{ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), ratio: 120, ratioState: RatioState.UNDER },
|
|
1310
|
+
['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1311
|
+
],
|
|
1312
|
+
];
|
|
1313
|
+
|
|
1314
|
+
examples.forEach(([expected, actual]) => {
|
|
1315
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1316
|
+
expect(aaveV4RatioTrigger.decode(actual)).to.eql(expected);
|
|
1317
|
+
});
|
|
1318
|
+
});
|
|
1319
|
+
});
|
|
1320
|
+
});
|
|
1321
|
+
|
|
1322
|
+
describe('When testing triggerService.aaveV4QuotePriceTrigger', () => {
|
|
1323
|
+
describe('encode()', () => {
|
|
1324
|
+
const examples: Array<[[string], [spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, price: string, ratioState: RatioState]]> = [
|
|
1325
|
+
[
|
|
1326
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1327
|
+
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, '1500', RatioState.OVER]
|
|
1328
|
+
],
|
|
1329
|
+
];
|
|
1330
|
+
|
|
1331
|
+
examples.forEach(([expected, actual]) => {
|
|
1332
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1333
|
+
expect(aaveV4QuotePriceTrigger.encode(...actual)).to.eql(expected);
|
|
1334
|
+
});
|
|
1335
|
+
});
|
|
1336
|
+
});
|
|
1337
|
+
|
|
1338
|
+
describe('decode()', () => {
|
|
1339
|
+
const examples: Array<[{ spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, price: string, ratioState: RatioState }, TriggerData]> = [
|
|
1340
|
+
[
|
|
1341
|
+
{ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, price: '1500', ratioState: RatioState.OVER },
|
|
1342
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000'],
|
|
1343
|
+
],
|
|
1344
|
+
];
|
|
1345
|
+
|
|
1346
|
+
examples.forEach(([expected, actual]) => {
|
|
1347
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1348
|
+
expect(aaveV4QuotePriceTrigger.decode(actual)).to.eql(expected);
|
|
1349
|
+
});
|
|
1350
|
+
});
|
|
1351
|
+
});
|
|
1352
|
+
});
|
|
1353
|
+
|
|
1354
|
+
describe('When testing triggerService.aaveV4QuotePriceRangeTrigger', () => {
|
|
1355
|
+
describe('encode()', () => {
|
|
1356
|
+
const examples: Array<[[string], [spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, lowerPrice: string, upperPrice: string]]> = [
|
|
1357
|
+
[
|
|
1358
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae00000000000000000000000000000000000000000000000000056bc75e2d631000000'],
|
|
1359
|
+
[web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, '1400', '1600']
|
|
1360
|
+
],
|
|
1361
|
+
];
|
|
1362
|
+
|
|
1363
|
+
examples.forEach(([expected, actual]) => {
|
|
1364
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1365
|
+
expect(aaveV4QuotePriceRangeTrigger.encode(...actual)).to.eql(expected);
|
|
1366
|
+
});
|
|
1367
|
+
});
|
|
1368
|
+
});
|
|
1369
|
+
|
|
1370
|
+
describe('decode()', () => {
|
|
1371
|
+
const examples: Array<[{ spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, lowerPrice: string, upperPrice: string }, TriggerData]> = [
|
|
1372
|
+
[
|
|
1373
|
+
{ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, lowerPrice: '1400', upperPrice: '1600' },
|
|
1374
|
+
['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae00000000000000000000000000000000000000000000000000056bc75e2d631000000'],
|
|
1375
|
+
],
|
|
1376
|
+
];
|
|
1377
|
+
|
|
1378
|
+
examples.forEach(([expected, actual]) => {
|
|
1379
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1380
|
+
expect(aaveV4QuotePriceRangeTrigger.decode(actual)).to.eql(expected);
|
|
1381
|
+
});
|
|
1382
|
+
});
|
|
1383
|
+
});
|
|
1384
|
+
});
|
|
1385
|
+
describe('When testing triggerService.sparkQuotePriceTrigger', () => {
|
|
1386
|
+
describe('encode()', () => {
|
|
1387
|
+
const examples: Array<[[string], [baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: number, ratioState: RatioState]]> = [
|
|
1388
|
+
[
|
|
1389
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1390
|
+
[web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address), 2500, RatioState.UNDER]
|
|
1391
|
+
],
|
|
1392
|
+
[
|
|
1393
|
+
['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000'],
|
|
1394
|
+
[web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Ethereum).address), web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address), 0.000031, RatioState.OVER]
|
|
1395
|
+
],
|
|
1396
|
+
];
|
|
1397
|
+
|
|
1398
|
+
examples.forEach(([expected, actual]) => {
|
|
1399
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1400
|
+
expect(sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
|
|
1401
|
+
});
|
|
1402
|
+
});
|
|
1403
|
+
});
|
|
1404
|
+
|
|
1405
|
+
describe('decode()', () => {
|
|
1406
|
+
const examples: Array<[{ baseTokenAddr: EthereumAddress, quoteTokenAddr: EthereumAddress, price: string, ratioState: RatioState }, TriggerData]> = [
|
|
1407
|
+
[
|
|
1408
|
+
{
|
|
1409
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1410
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1411
|
+
price: '2500',
|
|
1412
|
+
ratioState: RatioState.UNDER
|
|
1413
|
+
},
|
|
1414
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000003a352944000000000000000000000000000000000000000000000000000000000000000001']
|
|
1415
|
+
],
|
|
1416
|
+
[
|
|
1417
|
+
{
|
|
1418
|
+
baseTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('USDT', ChainId.Ethereum).address),
|
|
1419
|
+
quoteTokenAddr: web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1420
|
+
price: '0.000031',
|
|
1421
|
+
ratioState: RatioState.OVER
|
|
1422
|
+
},
|
|
1423
|
+
['0x000000000000000000000000dac17f958d2ee523a2206206994597c13d831ec70000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000000000c1c0000000000000000000000000000000000000000000000000000000000000000']
|
|
1424
|
+
]
|
|
1425
|
+
];
|
|
1426
|
+
|
|
1427
|
+
examples.forEach(([expected, actual]) => {
|
|
1428
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1429
|
+
expect(sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
|
|
1430
|
+
});
|
|
1431
|
+
});
|
|
1432
|
+
});
|
|
1433
|
+
});
|
|
1286
1434
|
});
|
|
@@ -720,4 +720,100 @@ export const morphoBluePriceRangeTrigger = {
|
|
|
720
720
|
upperPrice: new Dec(decodedData[4] as string).div(1e8).toString(),
|
|
721
721
|
};
|
|
722
722
|
},
|
|
723
|
-
};
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
export const sparkQuotePriceTrigger = {
|
|
726
|
+
encode(
|
|
727
|
+
baseTokenAddr: EthereumAddress,
|
|
728
|
+
quoteTokenAddr: EthereumAddress,
|
|
729
|
+
price: number,
|
|
730
|
+
ratioState: RatioState,
|
|
731
|
+
) {
|
|
732
|
+
const _price = new Dec(price.toString()).mul(1e8).floor().toString();
|
|
733
|
+
return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddr, quoteTokenAddr, _price, ratioState])];
|
|
734
|
+
},
|
|
735
|
+
decode(
|
|
736
|
+
triggerData: TriggerData,
|
|
737
|
+
) {
|
|
738
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
739
|
+
return {
|
|
740
|
+
baseTokenAddr: decodedData[0] as EthereumAddress,
|
|
741
|
+
quoteTokenAddr: decodedData[1] as EthereumAddress,
|
|
742
|
+
price: new Dec(decodedData[2] as string).div(1e8).toString(),
|
|
743
|
+
ratioState: Number(decodedData[3]),
|
|
744
|
+
};
|
|
745
|
+
},
|
|
746
|
+
};
|
|
747
|
+
|
|
748
|
+
export const aaveV4RatioTrigger = {
|
|
749
|
+
encode(owner: EthereumAddress, spoke: EthereumAddress, ratioPercentage: number, ratioState: RatioState) {
|
|
750
|
+
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
751
|
+
return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, spoke, ratioWei, ratioState])];
|
|
752
|
+
},
|
|
753
|
+
decode(triggerData: TriggerData) {
|
|
754
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
|
|
755
|
+
return {
|
|
756
|
+
owner: decodedData[0] as EthereumAddress,
|
|
757
|
+
spoke: decodedData[1] as EthereumAddress,
|
|
758
|
+
ratio: weiToRatioPercentage(decodedData[2] as string),
|
|
759
|
+
ratioState: Number(decodedData[3]),
|
|
760
|
+
};
|
|
761
|
+
},
|
|
762
|
+
};
|
|
763
|
+
|
|
764
|
+
export const aaveV4QuotePriceTrigger = {
|
|
765
|
+
encode(
|
|
766
|
+
spoke: EthereumAddress,
|
|
767
|
+
baseTokenId: number,
|
|
768
|
+
quoteTokenId: number,
|
|
769
|
+
price: string,
|
|
770
|
+
ratioState: RatioState,
|
|
771
|
+
) {
|
|
772
|
+
// Price is intentionally scaled to 1e18 for higher precision.
|
|
773
|
+
const _price = new Dec(price).mul(1e18).floor().toString();
|
|
774
|
+
return [AbiCoder.encodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], [spoke, baseTokenId, quoteTokenId, _price, ratioState])];
|
|
775
|
+
},
|
|
776
|
+
decode(
|
|
777
|
+
triggerData: TriggerData,
|
|
778
|
+
) {
|
|
779
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], triggerData[0]);
|
|
780
|
+
return {
|
|
781
|
+
spoke: decodedData[0] as EthereumAddress,
|
|
782
|
+
baseTokenId: Number(decodedData[1]),
|
|
783
|
+
quoteTokenId: Number(decodedData[2]),
|
|
784
|
+
price: new Dec(decodedData[3] as string).div(1e18).toString(),
|
|
785
|
+
ratioState: Number(decodedData[4]),
|
|
786
|
+
};
|
|
787
|
+
},
|
|
788
|
+
};
|
|
789
|
+
|
|
790
|
+
export const aaveV4QuotePriceRangeTrigger = {
|
|
791
|
+
encode(
|
|
792
|
+
spoke: EthereumAddress,
|
|
793
|
+
baseTokenId: number,
|
|
794
|
+
quoteTokenId: number,
|
|
795
|
+
lowerPrice: string,
|
|
796
|
+
upperPrice: string,
|
|
797
|
+
) {
|
|
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();
|
|
801
|
+
return [
|
|
802
|
+
AbiCoder.encodeParameters(
|
|
803
|
+
['address', 'uint256', 'uint256', 'uint256', 'uint256'],
|
|
804
|
+
[spoke, baseTokenId, quoteTokenId, lowerPriceFormatted, upperPriceFormatted]),
|
|
805
|
+
];
|
|
806
|
+
},
|
|
807
|
+
decode(
|
|
808
|
+
triggerData: TriggerData,
|
|
809
|
+
) {
|
|
810
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint256'], triggerData[0]);
|
|
811
|
+
return {
|
|
812
|
+
spoke: decodedData[0] as EthereumAddress,
|
|
813
|
+
baseTokenId: Number(decodedData[1]),
|
|
814
|
+
quoteTokenId: Number(decodedData[2]),
|
|
815
|
+
lowerPrice: new Dec(decodedData[3] as string).div(1e18).toString(),
|
|
816
|
+
upperPrice: new Dec(decodedData[4] as string).div(1e18).toString(),
|
|
817
|
+
};
|
|
818
|
+
},
|
|
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
|
@@ -64,6 +64,7 @@ export namespace ProtocolIdentifiers {
|
|
|
64
64
|
CompoundV3 = 'Compound__V3',
|
|
65
65
|
AaveV2 = 'Aave__V2',
|
|
66
66
|
AaveV3 = 'Aave__V3',
|
|
67
|
+
AaveV4 = 'Aave__V4',
|
|
67
68
|
MorphoAaveV2 = 'Morpho-Aave__V2',
|
|
68
69
|
Exchange = 'Exchange',
|
|
69
70
|
Spark = 'Spark',
|
|
@@ -97,6 +98,8 @@ export namespace Strategies {
|
|
|
97
98
|
CURVEUSD_PAYBACK = 92,
|
|
98
99
|
LIQUITY_V2_PAYBACK = 113,
|
|
99
100
|
AAVE_V3_COLLATERAL_SWITCH = 135,
|
|
101
|
+
AAVE_V4_COLLATERAL_SWITCH = 154,
|
|
102
|
+
AAVE_V4_COLLATERAL_SWITCH_EOA = 155,
|
|
100
103
|
}
|
|
101
104
|
|
|
102
105
|
export enum OptimismIds {
|
|
@@ -148,6 +151,7 @@ export namespace Strategies {
|
|
|
148
151
|
EoaBoostOnPrice = 'eoa-boost-on-price',
|
|
149
152
|
EoaRepayOnPrice = 'eoa-repay-on-price',
|
|
150
153
|
CollateralSwitch = 'collateral-switch',
|
|
154
|
+
EoaCollateralSwitch = 'eoa-collateral-switch',
|
|
151
155
|
}
|
|
152
156
|
export enum IdOverrides {
|
|
153
157
|
TakeProfit = 'take-profit',
|
|
@@ -223,6 +227,18 @@ export namespace Bundles {
|
|
|
223
227
|
AAVE_V3_EOA_CLOSE = 56,
|
|
224
228
|
SPARK_CLOSE = 57,
|
|
225
229
|
MORPHO_BLUE_CLOSE = 58,
|
|
230
|
+
SPARK_REPAY_ON_PRICE = 59,
|
|
231
|
+
SPARK_BOOST_ON_PRICE = 60,
|
|
232
|
+
AAVE_V4_REPAY = 61,
|
|
233
|
+
AAVE_V4_BOOST = 62,
|
|
234
|
+
AAVE_V4_REPAY_ON_PRICE = 63,
|
|
235
|
+
AAVE_V4_BOOST_ON_PRICE = 64,
|
|
236
|
+
AAVE_V4_CLOSE = 65,
|
|
237
|
+
AAVE_V4_EOA_REPAY = 66,
|
|
238
|
+
AAVE_V4_EOA_BOOST = 67,
|
|
239
|
+
AAVE_V4_EOA_REPAY_ON_PRICE = 68,
|
|
240
|
+
AAVE_V4_EOA_BOOST_ON_PRICE = 69,
|
|
241
|
+
AAVE_V4_EOA_CLOSE = 70,
|
|
226
242
|
}
|
|
227
243
|
|
|
228
244
|
export enum OptimismIds {
|
package/src/types/index.ts
CHANGED
|
@@ -236,6 +236,42 @@ export declare namespace Position {
|
|
|
236
236
|
stopLossType: CloseToAssetType | undefined,
|
|
237
237
|
takeProfitType: CloseToAssetType | undefined,
|
|
238
238
|
}
|
|
239
|
+
|
|
240
|
+
interface SparkOnPrice extends Base {
|
|
241
|
+
collAsset: EthereumAddress,
|
|
242
|
+
collAssetId: number,
|
|
243
|
+
debtAsset: EthereumAddress,
|
|
244
|
+
debtAssetId: number,
|
|
245
|
+
baseToken: EthereumAddress,
|
|
246
|
+
quoteToken: EthereumAddress,
|
|
247
|
+
price: string,
|
|
248
|
+
ratioState: RatioState,
|
|
249
|
+
ratio: number,
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
interface CloseBase extends Base {
|
|
253
|
+
stopLossPrice: string,
|
|
254
|
+
takeProfitPrice: string,
|
|
255
|
+
stopLossType: CloseToAssetType | undefined,
|
|
256
|
+
takeProfitType: CloseToAssetType | undefined,
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
interface AaveV4LeverageManagementOnPrice extends Base {
|
|
260
|
+
collAsset: EthereumAddress,
|
|
261
|
+
collAssetId: number,
|
|
262
|
+
debtAsset: EthereumAddress,
|
|
263
|
+
debtAssetId: number,
|
|
264
|
+
price: string,
|
|
265
|
+
ratioState: number,
|
|
266
|
+
ratio: number,
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
interface AaveV4CloseOnPrice extends CloseBase {
|
|
270
|
+
collAsset: EthereumAddress,
|
|
271
|
+
collAssetId: number,
|
|
272
|
+
debtAsset: EthereumAddress,
|
|
273
|
+
debtAssetId: number,
|
|
274
|
+
}
|
|
239
275
|
}
|
|
240
276
|
|
|
241
277
|
type SpecificAny =
|
|
@@ -253,7 +289,10 @@ export declare namespace Position {
|
|
|
253
289
|
| Specific.PaybackLiquityV2
|
|
254
290
|
| Specific.CompoundV3LeverageManagementOnPrice
|
|
255
291
|
| Specific.CompoundV3CloseOnPrice
|
|
256
|
-
| Specific.AaveV3CloseOnPriceGeneric
|
|
292
|
+
| Specific.AaveV3CloseOnPriceGeneric
|
|
293
|
+
| Specific.AaveV4LeverageManagementOnPrice
|
|
294
|
+
| Specific.AaveV4CloseOnPrice
|
|
295
|
+
| Specific.SparkOnPrice;
|
|
257
296
|
|
|
258
297
|
export interface Automated {
|
|
259
298
|
chainId: ChainId,
|