@defisaver/automation-sdk 3.3.8 → 3.3.10-aave-v4-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.
Files changed (42) hide show
  1. package/cjs/constants/index.js +55 -0
  2. package/cjs/services/ethereumService.js +21 -14
  3. package/cjs/services/strategiesService.js +101 -0
  4. package/cjs/services/strategySubService.d.ts +8 -0
  5. package/cjs/services/strategySubService.js +47 -1
  6. package/cjs/services/strategySubService.test.js +143 -0
  7. package/cjs/services/subDataService.d.ts +302 -129
  8. package/cjs/services/subDataService.js +629 -372
  9. package/cjs/services/subDataService.test.js +213 -0
  10. package/cjs/services/triggerService.d.ts +29 -0
  11. package/cjs/services/triggerService.js +55 -1
  12. package/cjs/services/triggerService.test.js +84 -0
  13. package/cjs/types/enums.d.ts +14 -2
  14. package/cjs/types/enums.js +12 -0
  15. package/cjs/types/index.d.ts +22 -1
  16. package/esm/constants/index.js +55 -0
  17. package/esm/services/ethereumService.js +21 -14
  18. package/esm/services/strategiesService.js +102 -1
  19. package/esm/services/strategySubService.d.ts +8 -0
  20. package/esm/services/strategySubService.js +46 -0
  21. package/esm/services/strategySubService.test.js +144 -1
  22. package/esm/services/subDataService.d.ts +302 -129
  23. package/esm/services/subDataService.js +628 -371
  24. package/esm/services/subDataService.test.js +213 -0
  25. package/esm/services/triggerService.d.ts +29 -0
  26. package/esm/services/triggerService.js +54 -0
  27. package/esm/services/triggerService.test.js +85 -1
  28. package/esm/types/enums.d.ts +14 -2
  29. package/esm/types/enums.js +12 -0
  30. package/esm/types/index.d.ts +22 -1
  31. package/package.json +1 -1
  32. package/src/constants/index.ts +55 -0
  33. package/src/services/ethereumService.ts +23 -16
  34. package/src/services/strategiesService.ts +116 -1
  35. package/src/services/strategySubService.test.ts +180 -0
  36. package/src/services/strategySubService.ts +162 -2
  37. package/src/services/subDataService.test.ts +233 -0
  38. package/src/services/subDataService.ts +977 -703
  39. package/src/services/triggerService.test.ts +99 -0
  40. package/src/services/triggerService.ts +76 -1
  41. package/src/types/enums.ts +12 -0
  42. package/src/types/index.ts +27 -1
@@ -32,6 +32,9 @@ import {
32
32
  compoundV3PriceRangeTrigger,
33
33
  aaveV3QuotePriceRangeTrigger,
34
34
  morphoBluePriceRangeTrigger,
35
+ aaveV4RatioTrigger,
36
+ aaveV4QuotePriceTrigger,
37
+ aaveV4QuotePriceRangeTrigger,
35
38
  } from './triggerService';
36
39
 
37
40
  describe('Feature: triggerService.ts', () => {
@@ -1283,4 +1286,100 @@ describe('Feature: triggerService.ts', () => {
1283
1286
  });
1284
1287
  });
1285
1288
  });
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: number, ratioState: RatioState]]> = [
1325
+ [
1326
+ ['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
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
+ ['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
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: number, upperPrice: number]]> = [
1357
+ [
1358
+ ['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000002098a678000000000000000000000000000000000000000000000000000000002540be4000'],
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
+ ['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000002098a678000000000000000000000000000000000000000000000000000000002540be4000'],
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
+ });
1286
1385
  });
@@ -720,4 +720,79 @@ 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 aaveV4RatioTrigger = {
726
+ encode(owner: EthereumAddress, spoke: EthereumAddress, ratioPercentage: number, ratioState: RatioState) {
727
+ const ratioWei = ratioPercentageToWei(ratioPercentage);
728
+ return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, spoke, ratioWei, ratioState])];
729
+ },
730
+ decode(triggerData: TriggerData) {
731
+ const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
732
+ return {
733
+ owner: decodedData[0] as EthereumAddress,
734
+ spoke: decodedData[1] as EthereumAddress,
735
+ ratio: weiToRatioPercentage(decodedData[2] as string),
736
+ ratioState: Number(decodedData[3]),
737
+ };
738
+ },
739
+ };
740
+
741
+ export const aaveV4QuotePriceTrigger = {
742
+ encode(
743
+ spoke: EthereumAddress,
744
+ baseTokenId: number,
745
+ quoteTokenId: number,
746
+ price: number,
747
+ ratioState: RatioState,
748
+ ) {
749
+ // Price is always in 8 decimals
750
+ const _price = new Dec(price.toString()).mul(10 ** 8).floor().toString();
751
+ return [AbiCoder.encodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], [spoke, baseTokenId, quoteTokenId, _price, ratioState])];
752
+ },
753
+ decode(
754
+ triggerData: TriggerData,
755
+ ) {
756
+ const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], triggerData[0]);
757
+ // Price is always in 8 decimals
758
+ const price = new Dec(decodedData[3] as string).div(10 ** 8).toDP(8).toString();
759
+ return {
760
+ spoke: decodedData[0] as EthereumAddress,
761
+ baseTokenId: Number(decodedData[1]),
762
+ quoteTokenId: Number(decodedData[2]),
763
+ price,
764
+ ratioState: Number(decodedData[4]),
765
+ };
766
+ },
767
+ };
768
+
769
+ export const aaveV4QuotePriceRangeTrigger = {
770
+ encode(
771
+ spoke: EthereumAddress,
772
+ baseTokenId: number,
773
+ quoteTokenId: number,
774
+ lowerPrice: number,
775
+ upperPrice: number,
776
+ ) {
777
+ // Price is scaled to 1e8
778
+ const lowerPriceFormatted = new Dec(lowerPrice).mul(1e8).floor().toString();
779
+ const upperPriceFormatted = new Dec(upperPrice).mul(1e8).floor().toString();
780
+ return [
781
+ AbiCoder.encodeParameters(
782
+ ['address', 'uint256', 'uint256', 'uint256', 'uint256'],
783
+ [spoke, baseTokenId, quoteTokenId, lowerPriceFormatted, upperPriceFormatted]),
784
+ ];
785
+ },
786
+ decode(
787
+ triggerData: TriggerData,
788
+ ) {
789
+ const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint256'], triggerData[0]);
790
+ return {
791
+ spoke: decodedData[0] as EthereumAddress,
792
+ baseTokenId: Number(decodedData[1]),
793
+ quoteTokenId: Number(decodedData[2]),
794
+ lowerPrice: new Dec(decodedData[3] as string).div(1e8).toString(),
795
+ upperPrice: new Dec(decodedData[4] as string).div(1e8).toString(),
796
+ };
797
+ },
798
+ };
@@ -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,7 @@ 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 = 151,
100
102
  }
101
103
 
102
104
  export enum OptimismIds {
@@ -223,6 +225,16 @@ export namespace Bundles {
223
225
  AAVE_V3_EOA_CLOSE = 56,
224
226
  SPARK_CLOSE = 57,
225
227
  MORPHO_BLUE_CLOSE = 58,
228
+ AAVE_V4_REPAY = 59,
229
+ AAVE_V4_BOOST = 60,
230
+ AAVE_V4_REPAY_ON_PRICE = 61,
231
+ AAVE_V4_BOOST_ON_PRICE = 62,
232
+ AAVE_V4_CLOSE = 63,
233
+ AAVE_V4_EOA_REPAY = 64,
234
+ AAVE_V4_EOA_BOOST = 65,
235
+ AAVE_V4_EOA_REPAY_ON_PRICE = 66,
236
+ AAVE_V4_EOA_BOOST_ON_PRICE = 67,
237
+ AAVE_V4_EOA_CLOSE = 68,
226
238
  }
227
239
 
228
240
  export enum OptimismIds {
@@ -236,6 +236,30 @@ export declare namespace Position {
236
236
  stopLossType: CloseToAssetType | undefined,
237
237
  takeProfitType: CloseToAssetType | undefined,
238
238
  }
239
+
240
+ interface CloseBase extends Base {
241
+ stopLossPrice: string,
242
+ takeProfitPrice: string,
243
+ stopLossType: CloseToAssetType | undefined,
244
+ takeProfitType: CloseToAssetType | undefined,
245
+ }
246
+
247
+ interface AaveV4LeverageManagementOnPrice extends Base {
248
+ collAsset: EthereumAddress,
249
+ collAssetId: number,
250
+ debtAsset: EthereumAddress,
251
+ debtAssetId: number,
252
+ price: string,
253
+ ratioState: number,
254
+ ratio: number,
255
+ }
256
+
257
+ interface AaveV4CloseOnPrice extends CloseBase {
258
+ collAsset: EthereumAddress,
259
+ collAssetId: number,
260
+ debtAsset: EthereumAddress,
261
+ debtAssetId: number,
262
+ }
239
263
  }
240
264
 
241
265
  type SpecificAny =
@@ -253,7 +277,9 @@ export declare namespace Position {
253
277
  | Specific.PaybackLiquityV2
254
278
  | Specific.CompoundV3LeverageManagementOnPrice
255
279
  | Specific.CompoundV3CloseOnPrice
256
- | Specific.AaveV3CloseOnPriceGeneric;
280
+ | Specific.AaveV3CloseOnPriceGeneric
281
+ | Specific.AaveV4LeverageManagementOnPrice
282
+ | Specific.AaveV4CloseOnPrice;
257
283
 
258
284
  export interface Automated {
259
285
  chainId: ChainId,