@defisaver/automation-sdk 3.3.9 → 3.3.10-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.
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 +6 -0
  5. package/cjs/services/strategySubService.js +30 -1
  6. package/cjs/services/strategySubService.test.js +96 -0
  7. package/cjs/services/subDataService.d.ts +290 -132
  8. package/cjs/services/subDataService.js +607 -378
  9. package/cjs/services/subDataService.test.js +157 -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 +6 -0
  20. package/esm/services/strategySubService.js +29 -0
  21. package/esm/services/strategySubService.test.js +97 -1
  22. package/esm/services/subDataService.d.ts +290 -132
  23. package/esm/services/subDataService.js +606 -377
  24. package/esm/services/subDataService.test.js +157 -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 +2 -2
  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 +125 -0
  36. package/src/services/strategySubService.ts +118 -0
  37. package/src/services/subDataService.test.ts +173 -0
  38. package/src/services/subDataService.ts +980 -746
  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
@@ -2061,4 +2061,161 @@ describe('Feature: subDataService.ts', () => {
2061
2061
  });
2062
2062
  });
2063
2063
  });
2064
+ describe('When testing subDataService.aaveV4LeverageManagementSubData', () => {
2065
+ describe('encode()', () => {
2066
+ const examples = [
2067
+ [
2068
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000"],
2069
+ [web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), RatioState.UNDER, 150]
2070
+ ],
2071
+ ];
2072
+ examples.forEach(([expected, actual]) => {
2073
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2074
+ expect(subDataService.aaveV4LeverageManagementSubData.encode(...actual)).to.eql(expected);
2075
+ });
2076
+ });
2077
+ });
2078
+ describe('decode()', () => {
2079
+ const examples = [
2080
+ [
2081
+ {
2082
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2083
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2084
+ ratioState: RatioState.UNDER,
2085
+ targetRatio: 150,
2086
+ },
2087
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000"],
2088
+ ],
2089
+ ];
2090
+ examples.forEach(([expected, actual]) => {
2091
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2092
+ expect(subDataService.aaveV4LeverageManagementSubData.decode(actual)).to.eql(expected);
2093
+ });
2094
+ });
2095
+ });
2096
+ });
2097
+ describe('When testing subDataService.aaveV4LeverageManagementOnPriceSubData', () => {
2098
+ describe('encode()', () => {
2099
+ const examples = [
2100
+ [
2101
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000"],
2102
+ [
2103
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2104
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
2105
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
2106
+ RatioState.OVER, 160
2107
+ ]
2108
+ ],
2109
+ ];
2110
+ examples.forEach(([expected, actual]) => {
2111
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2112
+ expect(subDataService.aaveV4LeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
2113
+ });
2114
+ });
2115
+ });
2116
+ describe('decode()', () => {
2117
+ const examples = [
2118
+ [
2119
+ {
2120
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2121
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2122
+ collAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2123
+ collAssetId: 10,
2124
+ debtAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2125
+ debtAssetId: 20,
2126
+ ratioState: RatioState.OVER,
2127
+ targetRatio: 160,
2128
+ },
2129
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000"],
2130
+ ],
2131
+ ];
2132
+ examples.forEach(([expected, actual]) => {
2133
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2134
+ expect(subDataService.aaveV4LeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
2135
+ });
2136
+ });
2137
+ });
2138
+ });
2139
+ describe('When testing subDataService.aaveV4CloseSubData', () => {
2140
+ describe('encode()', () => {
2141
+ const examples = [
2142
+ [
2143
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000001"],
2144
+ [
2145
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2146
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
2147
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
2148
+ CloseStrategyType.STOP_LOSS_IN_COLLATERAL
2149
+ ]
2150
+ ],
2151
+ ];
2152
+ examples.forEach(([expected, actual]) => {
2153
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2154
+ expect(subDataService.aaveV4CloseSubData.encode(...actual)).to.eql(expected);
2155
+ });
2156
+ });
2157
+ });
2158
+ describe('decode()', () => {
2159
+ const examples = [
2160
+ [
2161
+ {
2162
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2163
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2164
+ collAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2165
+ collAssetId: 10,
2166
+ debtAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2167
+ debtAssetId: 20,
2168
+ closeType: CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
2169
+ },
2170
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000001"],
2171
+ ],
2172
+ ];
2173
+ examples.forEach(([expected, actual]) => {
2174
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2175
+ expect(subDataService.aaveV4CloseSubData.decode(actual)).to.eql(expected);
2176
+ });
2177
+ });
2178
+ });
2179
+ });
2180
+ describe('When testing subDataService.aaveV4CollateralSwitchSubData', () => {
2181
+ describe('encode()', () => {
2182
+ const examples = [
2183
+ [
2184
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000"],
2185
+ [
2186
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2187
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
2188
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
2189
+ '1000000000000000000'
2190
+ ]
2191
+ ],
2192
+ ];
2193
+ examples.forEach(([expected, actual]) => {
2194
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2195
+ expect(subDataService.aaveV4CollateralSwitchSubData.encode(...actual)).to.eql(expected);
2196
+ });
2197
+ });
2198
+ });
2199
+ describe('decode()', () => {
2200
+ const examples = [
2201
+ [
2202
+ {
2203
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2204
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2205
+ fromAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2206
+ fromAssetId: 10,
2207
+ toAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2208
+ toAssetId: 20,
2209
+ amountToSwitch: '1000000000000000000'
2210
+ },
2211
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000"],
2212
+ ],
2213
+ ];
2214
+ examples.forEach(([expected, actual]) => {
2215
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2216
+ expect(subDataService.aaveV4CollateralSwitchSubData.decode(actual)).to.eql(expected);
2217
+ });
2218
+ });
2219
+ });
2220
+ });
2064
2221
  });
@@ -285,3 +285,32 @@ export declare const morphoBluePriceRangeTrigger: {
285
285
  upperPrice: string;
286
286
  };
287
287
  };
288
+ export declare const aaveV4RatioTrigger: {
289
+ encode(owner: EthereumAddress, spoke: EthereumAddress, ratioPercentage: number, ratioState: RatioState): string[];
290
+ decode(triggerData: string[]): {
291
+ owner: string;
292
+ spoke: string;
293
+ ratio: number;
294
+ ratioState: number;
295
+ };
296
+ };
297
+ export declare const aaveV4QuotePriceTrigger: {
298
+ encode(spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, price: number, ratioState: RatioState): string[];
299
+ decode(triggerData: string[]): {
300
+ spoke: string;
301
+ baseTokenId: number;
302
+ quoteTokenId: number;
303
+ price: string;
304
+ ratioState: number;
305
+ };
306
+ };
307
+ export declare const aaveV4QuotePriceRangeTrigger: {
308
+ encode(spoke: EthereumAddress, baseTokenId: number, quoteTokenId: number, lowerPrice: number, upperPrice: number): string[];
309
+ decode(triggerData: string[]): {
310
+ spoke: string;
311
+ baseTokenId: number;
312
+ quoteTokenId: number;
313
+ lowerPrice: string;
314
+ upperPrice: string;
315
+ };
316
+ };
@@ -518,3 +518,57 @@ export const morphoBluePriceRangeTrigger = {
518
518
  };
519
519
  },
520
520
  };
521
+ export const aaveV4RatioTrigger = {
522
+ encode(owner, spoke, ratioPercentage, ratioState) {
523
+ const ratioWei = ratioPercentageToWei(ratioPercentage);
524
+ return [AbiCoder.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, spoke, ratioWei, ratioState])];
525
+ },
526
+ decode(triggerData) {
527
+ const decodedData = AbiCoder.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
528
+ return {
529
+ owner: decodedData[0],
530
+ spoke: decodedData[1],
531
+ ratio: weiToRatioPercentage(decodedData[2]),
532
+ ratioState: Number(decodedData[3]),
533
+ };
534
+ },
535
+ };
536
+ export const aaveV4QuotePriceTrigger = {
537
+ encode(spoke, baseTokenId, quoteTokenId, price, ratioState) {
538
+ // Price is always in 8 decimals
539
+ const _price = new Dec(price.toString()).mul(Math.pow(10, 8)).floor().toString();
540
+ return [AbiCoder.encodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], [spoke, baseTokenId, quoteTokenId, _price, ratioState])];
541
+ },
542
+ decode(triggerData) {
543
+ const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], triggerData[0]);
544
+ // Price is always in 8 decimals
545
+ const price = new Dec(decodedData[3]).div(Math.pow(10, 8)).toDP(8).toString();
546
+ return {
547
+ spoke: decodedData[0],
548
+ baseTokenId: Number(decodedData[1]),
549
+ quoteTokenId: Number(decodedData[2]),
550
+ price,
551
+ ratioState: Number(decodedData[4]),
552
+ };
553
+ },
554
+ };
555
+ export const aaveV4QuotePriceRangeTrigger = {
556
+ encode(spoke, baseTokenId, quoteTokenId, lowerPrice, upperPrice) {
557
+ // Price is scaled to 1e8
558
+ const lowerPriceFormatted = new Dec(lowerPrice).mul(1e8).floor().toString();
559
+ const upperPriceFormatted = new Dec(upperPrice).mul(1e8).floor().toString();
560
+ return [
561
+ AbiCoder.encodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint256'], [spoke, baseTokenId, quoteTokenId, lowerPriceFormatted, upperPriceFormatted]),
562
+ ];
563
+ },
564
+ decode(triggerData) {
565
+ const decodedData = AbiCoder.decodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint256'], triggerData[0]);
566
+ return {
567
+ spoke: decodedData[0],
568
+ baseTokenId: Number(decodedData[1]),
569
+ quoteTokenId: Number(decodedData[2]),
570
+ lowerPrice: new Dec(decodedData[3]).div(1e8).toString(),
571
+ upperPrice: new Dec(decodedData[4]).div(1e8).toString(),
572
+ };
573
+ },
574
+ };
@@ -3,7 +3,7 @@ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
3
3
  import * as web3Utils from 'web3-utils';
4
4
  import { ChainId, OrderType, RatioState } from '../types/enums';
5
5
  import '../configuration';
6
- import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, morphoBluePriceRangeTrigger, } from './triggerService';
6
+ import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, morphoBluePriceRangeTrigger, aaveV4RatioTrigger, aaveV4QuotePriceTrigger, aaveV4QuotePriceRangeTrigger, } from './triggerService';
7
7
  describe('Feature: triggerService.ts', () => {
8
8
  describe('When testing triggerService.chainlinkPriceTrigger', () => {
9
9
  describe('encode()', () => {
@@ -1159,4 +1159,88 @@ describe('Feature: triggerService.ts', () => {
1159
1159
  });
1160
1160
  });
1161
1161
  });
1162
+ describe('When testing triggerService.aaveV4RatioTrigger', () => {
1163
+ describe('encode()', () => {
1164
+ const examples = [
1165
+ [
1166
+ ['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
1167
+ [web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 120, RatioState.UNDER]
1168
+ ],
1169
+ ];
1170
+ examples.forEach(([expected, actual]) => {
1171
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1172
+ expect(aaveV4RatioTrigger.encode(...actual)).to.eql(expected);
1173
+ });
1174
+ });
1175
+ });
1176
+ describe('decode()', () => {
1177
+ const examples = [
1178
+ [
1179
+ { owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), ratio: 120, ratioState: RatioState.UNDER },
1180
+ ['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
1181
+ ],
1182
+ ];
1183
+ examples.forEach(([expected, actual]) => {
1184
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1185
+ expect(aaveV4RatioTrigger.decode(actual)).to.eql(expected);
1186
+ });
1187
+ });
1188
+ });
1189
+ });
1190
+ describe('When testing triggerService.aaveV4QuotePriceTrigger', () => {
1191
+ describe('encode()', () => {
1192
+ const examples = [
1193
+ [
1194
+ ['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
1195
+ [web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, 1500, RatioState.OVER]
1196
+ ],
1197
+ ];
1198
+ examples.forEach(([expected, actual]) => {
1199
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1200
+ expect(aaveV4QuotePriceTrigger.encode(...actual)).to.eql(expected);
1201
+ });
1202
+ });
1203
+ });
1204
+ describe('decode()', () => {
1205
+ const examples = [
1206
+ [
1207
+ { spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, price: '1500', ratioState: RatioState.OVER },
1208
+ ['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
1209
+ ],
1210
+ ];
1211
+ examples.forEach(([expected, actual]) => {
1212
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1213
+ expect(aaveV4QuotePriceTrigger.decode(actual)).to.eql(expected);
1214
+ });
1215
+ });
1216
+ });
1217
+ });
1218
+ describe('When testing triggerService.aaveV4QuotePriceRangeTrigger', () => {
1219
+ describe('encode()', () => {
1220
+ const examples = [
1221
+ [
1222
+ ['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000002098a678000000000000000000000000000000000000000000000000000000002540be4000'],
1223
+ [web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, 1400, 1600]
1224
+ ],
1225
+ ];
1226
+ examples.forEach(([expected, actual]) => {
1227
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1228
+ expect(aaveV4QuotePriceRangeTrigger.encode(...actual)).to.eql(expected);
1229
+ });
1230
+ });
1231
+ });
1232
+ describe('decode()', () => {
1233
+ const examples = [
1234
+ [
1235
+ { spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, lowerPrice: '1400', upperPrice: '1600' },
1236
+ ['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000002098a678000000000000000000000000000000000000000000000000000000002540be4000'],
1237
+ ],
1238
+ ];
1239
+ examples.forEach(([expected, actual]) => {
1240
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1241
+ expect(aaveV4QuotePriceRangeTrigger.decode(actual)).to.eql(expected);
1242
+ });
1243
+ });
1244
+ });
1245
+ });
1162
1246
  });
@@ -56,6 +56,7 @@ export declare namespace ProtocolIdentifiers {
56
56
  CompoundV3 = "Compound__V3",
57
57
  AaveV2 = "Aave__V2",
58
58
  AaveV3 = "Aave__V3",
59
+ AaveV4 = "Aave__V4",
59
60
  MorphoAaveV2 = "Morpho-Aave__V2",
60
61
  Exchange = "Exchange",
61
62
  Spark = "Spark",
@@ -86,7 +87,8 @@ export declare namespace Strategies {
86
87
  LIQUITY_DEBT_IN_FRONT_REPAY = 75,
87
88
  CURVEUSD_PAYBACK = 92,
88
89
  LIQUITY_V2_PAYBACK = 113,
89
- AAVE_V3_COLLATERAL_SWITCH = 135
90
+ AAVE_V3_COLLATERAL_SWITCH = 135,
91
+ AAVE_V4_COLLATERAL_SWITCH = 151
90
92
  }
91
93
  enum OptimismIds {
92
94
  EXCHANGE_DCA = 8,
@@ -207,7 +209,17 @@ export declare namespace Bundles {
207
209
  AAVE_V3_EOA_BOOST_ON_PRICE = 55,
208
210
  AAVE_V3_EOA_CLOSE = 56,
209
211
  SPARK_CLOSE = 57,
210
- MORPHO_BLUE_CLOSE = 58
212
+ MORPHO_BLUE_CLOSE = 58,
213
+ AAVE_V4_REPAY = 59,
214
+ AAVE_V4_BOOST = 60,
215
+ AAVE_V4_REPAY_ON_PRICE = 61,
216
+ AAVE_V4_BOOST_ON_PRICE = 62,
217
+ AAVE_V4_CLOSE = 63,
218
+ AAVE_V4_EOA_REPAY = 64,
219
+ AAVE_V4_EOA_BOOST = 65,
220
+ AAVE_V4_EOA_REPAY_ON_PRICE = 66,
221
+ AAVE_V4_EOA_BOOST_ON_PRICE = 67,
222
+ AAVE_V4_EOA_CLOSE = 68
211
223
  }
212
224
  enum OptimismIds {
213
225
  AAVE_V3_REPAY = 0,
@@ -66,6 +66,7 @@ export var ProtocolIdentifiers;
66
66
  StrategiesAutomation["CompoundV3"] = "Compound__V3";
67
67
  StrategiesAutomation["AaveV2"] = "Aave__V2";
68
68
  StrategiesAutomation["AaveV3"] = "Aave__V3";
69
+ StrategiesAutomation["AaveV4"] = "Aave__V4";
69
70
  StrategiesAutomation["MorphoAaveV2"] = "Morpho-Aave__V2";
70
71
  StrategiesAutomation["Exchange"] = "Exchange";
71
72
  StrategiesAutomation["Spark"] = "Spark";
@@ -100,6 +101,7 @@ export var Strategies;
100
101
  MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
101
102
  MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
102
103
  MainnetIds[MainnetIds["AAVE_V3_COLLATERAL_SWITCH"] = 135] = "AAVE_V3_COLLATERAL_SWITCH";
104
+ MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH"] = 151] = "AAVE_V4_COLLATERAL_SWITCH";
103
105
  })(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
104
106
  let OptimismIds;
105
107
  (function (OptimismIds) {
@@ -228,6 +230,16 @@ export var Bundles;
228
230
  MainnetIds[MainnetIds["AAVE_V3_EOA_CLOSE"] = 56] = "AAVE_V3_EOA_CLOSE";
229
231
  MainnetIds[MainnetIds["SPARK_CLOSE"] = 57] = "SPARK_CLOSE";
230
232
  MainnetIds[MainnetIds["MORPHO_BLUE_CLOSE"] = 58] = "MORPHO_BLUE_CLOSE";
233
+ MainnetIds[MainnetIds["AAVE_V4_REPAY"] = 59] = "AAVE_V4_REPAY";
234
+ MainnetIds[MainnetIds["AAVE_V4_BOOST"] = 60] = "AAVE_V4_BOOST";
235
+ MainnetIds[MainnetIds["AAVE_V4_REPAY_ON_PRICE"] = 61] = "AAVE_V4_REPAY_ON_PRICE";
236
+ MainnetIds[MainnetIds["AAVE_V4_BOOST_ON_PRICE"] = 62] = "AAVE_V4_BOOST_ON_PRICE";
237
+ MainnetIds[MainnetIds["AAVE_V4_CLOSE"] = 63] = "AAVE_V4_CLOSE";
238
+ MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY"] = 64] = "AAVE_V4_EOA_REPAY";
239
+ MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST"] = 65] = "AAVE_V4_EOA_BOOST";
240
+ MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY_ON_PRICE"] = 66] = "AAVE_V4_EOA_REPAY_ON_PRICE";
241
+ MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST_ON_PRICE"] = 67] = "AAVE_V4_EOA_BOOST_ON_PRICE";
242
+ MainnetIds[MainnetIds["AAVE_V4_EOA_CLOSE"] = 68] = "AAVE_V4_EOA_CLOSE";
231
243
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
232
244
  let OptimismIds;
233
245
  (function (OptimismIds) {
@@ -197,8 +197,29 @@ export declare namespace Position {
197
197
  stopLossType: CloseToAssetType | undefined;
198
198
  takeProfitType: CloseToAssetType | undefined;
199
199
  }
200
+ interface CloseBase extends Base {
201
+ stopLossPrice: string;
202
+ takeProfitPrice: string;
203
+ stopLossType: CloseToAssetType | undefined;
204
+ takeProfitType: CloseToAssetType | undefined;
205
+ }
206
+ interface AaveV4LeverageManagementOnPrice extends Base {
207
+ collAsset: EthereumAddress;
208
+ collAssetId: number;
209
+ debtAsset: EthereumAddress;
210
+ debtAssetId: number;
211
+ price: string;
212
+ ratioState: number;
213
+ ratio: number;
214
+ }
215
+ interface AaveV4CloseOnPrice extends CloseBase {
216
+ collAsset: EthereumAddress;
217
+ collAssetId: number;
218
+ debtAsset: EthereumAddress;
219
+ debtAssetId: number;
220
+ }
200
221
  }
201
- type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho | Specific.BoostOnPriceLiquityV2 | Specific.PaybackLiquityV2 | Specific.CompoundV3LeverageManagementOnPrice | Specific.CompoundV3CloseOnPrice | Specific.AaveV3CloseOnPriceGeneric;
222
+ type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho | Specific.BoostOnPriceLiquityV2 | Specific.PaybackLiquityV2 | Specific.CompoundV3LeverageManagementOnPrice | Specific.CompoundV3CloseOnPrice | Specific.AaveV3CloseOnPriceGeneric | Specific.AaveV4LeverageManagementOnPrice | Specific.AaveV4CloseOnPrice;
202
223
  interface Automated {
203
224
  chainId: ChainId;
204
225
  positionId: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/automation-sdk",
3
- "version": "3.3.9",
3
+ "version": "3.3.10-aave-v4-1-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.15",
26
+ "@defisaver/sdk": "1.3.18-aave-v4-dev",
27
27
  "@defisaver/tokens": "^1.6.19",
28
28
  "@ethersproject/address": "^5.0.10",
29
29
  "@ethersproject/solidity": "^5.0.9",
@@ -123,6 +123,11 @@ export const MAINNET_STRATEGIES_INFO: MainnetStrategiesInfo = {
123
123
  strategyId: Strategies.Identifiers.CollateralSwitch,
124
124
  protocol: PROTOCOLS.AaveV3,
125
125
  },
126
+ [Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH]: {
127
+ strategyOrBundleId: Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH,
128
+ strategyId: Strategies.Identifiers.CollateralSwitch,
129
+ protocol: PROTOCOLS.AaveV4,
130
+ },
126
131
  };
127
132
 
128
133
  export const OPTIMISM_STRATEGIES_INFO: OptimismStrategiesInfo = {
@@ -496,6 +501,56 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
496
501
  strategyId: Strategies.Identifiers.CloseOnPrice,
497
502
  protocol: PROTOCOLS.MorphoBlue,
498
503
  },
504
+ [Bundles.MainnetIds.AAVE_V4_REPAY]: {
505
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_REPAY,
506
+ strategyId: Strategies.Identifiers.Repay,
507
+ protocol: PROTOCOLS.AaveV4,
508
+ },
509
+ [Bundles.MainnetIds.AAVE_V4_BOOST]: {
510
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_BOOST,
511
+ strategyId: Strategies.Identifiers.Boost,
512
+ protocol: PROTOCOLS.AaveV4,
513
+ },
514
+ [Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE]: {
515
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE,
516
+ strategyId: Strategies.Identifiers.RepayOnPrice,
517
+ protocol: PROTOCOLS.AaveV4,
518
+ },
519
+ [Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE]: {
520
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE,
521
+ strategyId: Strategies.Identifiers.BoostOnPrice,
522
+ protocol: PROTOCOLS.AaveV4,
523
+ },
524
+ [Bundles.MainnetIds.AAVE_V4_CLOSE]: {
525
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_CLOSE,
526
+ strategyId: Strategies.Identifiers.CloseOnPrice,
527
+ protocol: PROTOCOLS.AaveV4,
528
+ },
529
+ [Bundles.MainnetIds.AAVE_V4_EOA_REPAY]: {
530
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_REPAY,
531
+ strategyId: Strategies.Identifiers.EoaRepay,
532
+ protocol: PROTOCOLS.AaveV4,
533
+ },
534
+ [Bundles.MainnetIds.AAVE_V4_EOA_BOOST]: {
535
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_BOOST,
536
+ strategyId: Strategies.Identifiers.EoaBoost,
537
+ protocol: PROTOCOLS.AaveV4,
538
+ },
539
+ [Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE]: {
540
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE,
541
+ strategyId: Strategies.Identifiers.EoaRepayOnPrice,
542
+ protocol: PROTOCOLS.AaveV4,
543
+ },
544
+ [Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE]: {
545
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE,
546
+ strategyId: Strategies.Identifiers.EoaBoostOnPrice,
547
+ protocol: PROTOCOLS.AaveV4,
548
+ },
549
+ [Bundles.MainnetIds.AAVE_V4_EOA_CLOSE]: {
550
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_CLOSE,
551
+ strategyId: Strategies.Identifiers.EoaCloseOnPrice,
552
+ protocol: PROTOCOLS.AaveV4,
553
+ },
499
554
  };
500
555
 
501
556
  export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
@@ -18,27 +18,34 @@ export async function multicall(
18
18
  block: BlockNumber = 'latest',
19
19
  ): Promise<Multicall.Payload> {
20
20
  const multicallContract = makeUniMulticallContract(web3, chainId).contract;
21
+ const MAX_CALLS_PER_BATCH = 1000;
21
22
 
22
- const formattedCalls: Multicall.FormattedCalls[] = calls.map((call) => ({
23
- callData: AbiCoder.encodeFunctionCall(call.abiItem, call.params),
24
- target: call.target || '0x0',
25
- gasLimit: call.gasLimit || 1e6,
26
- }));
23
+ const allResults: Multicall.Payload = [];
27
24
 
28
- const callResult = await multicallContract.methods.multicall(
29
- formattedCalls.filter(item => item.target !== '0x0'),
30
- ).call({}, block);
25
+ // Process each chunk
26
+ for (let i = 0; i < calls.length; i += MAX_CALLS_PER_BATCH) {
27
+ const chunk = calls.slice(i, i + MAX_CALLS_PER_BATCH);
28
+ const formattedCalls: Multicall.FormattedCalls[] = chunk.map((call) => ({
29
+ callData: AbiCoder.encodeFunctionCall(call.abiItem, call.params),
30
+ target: call.target || '0x0',
31
+ gasLimit: call.gasLimit || 1e6,
32
+ }));
31
33
 
32
- let formattedResult: Multicall.Payload = [];
34
+ const callResult = await multicallContract.methods.multicall(
35
+ formattedCalls,
36
+ ).call({}, block);
33
37
 
34
- callResult.returnData.forEach(([success, gasUsed, result], i) => {
35
- const formattedRes = (result !== '0x'
36
- ? AbiCoder.decodeParameters(calls[i].abiItem.outputs!, result)
37
- : undefined);
38
- formattedResult = [...formattedResult, formattedRes];
39
- });
38
+ let formattedResult: Multicall.Payload = [];
39
+ callResult.returnData.forEach(([success,, result], j) => {
40
+ const formattedRes = (success && result !== '0x'
41
+ ? AbiCoder.decodeParameters(chunk[j].abiItem.outputs!, result)
42
+ : undefined);
43
+ formattedResult = [...formattedResult, formattedRes];
44
+ });
45
+ allResults.push(...formattedResult);
46
+ }
40
47
 
41
- return formattedResult as Multicall.Payload;
48
+ return allResults;
42
49
  }
43
50
 
44
51
  export async function getEventsFromContract<T extends BaseContract>(