@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
@@ -164,6 +164,62 @@ describe('Feature: subDataService.ts', () => {
164
164
  });
165
165
  });
166
166
  });
167
+ describe('When testing subDataService.makerLeverageManagementWithoutSubProxy', () => {
168
+ describe('encode()', () => {
169
+ const examples = [
170
+ [
171
+ [
172
+ '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
173
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
174
+ ],
175
+ [222, 180], // Uses default DAI address
176
+ ],
177
+ [
178
+ [
179
+ '0x000000000000000000000000000000000000000000000000000000000000014d', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
180
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
181
+ ],
182
+ [333, 200, web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address)], // Custom address
183
+ ],
184
+ ];
185
+ examples.forEach(([expected, actual]) => {
186
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
187
+ (0, chai_1.expect)(subDataService.makerLeverageManagementWithoutSubProxy.encode(...actual)).to.eql(expected);
188
+ });
189
+ });
190
+ });
191
+ describe('decode()', () => {
192
+ const examples = [
193
+ [
194
+ {
195
+ vaultId: 222,
196
+ targetRatio: 180,
197
+ daiAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
198
+ },
199
+ [
200
+ '0x00000000000000000000000000000000000000000000000000000000000000de', '0x00000000000000000000000000000000000000000000000018fae27693b40000',
201
+ '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
202
+ ],
203
+ ],
204
+ [
205
+ {
206
+ vaultId: 333,
207
+ targetRatio: 200,
208
+ daiAddr: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WETH', enums_1.ChainId.Ethereum).address),
209
+ },
210
+ [
211
+ '0x000000000000000000000000000000000000000000000000000000000000014d', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
212
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
213
+ ],
214
+ ],
215
+ ];
216
+ examples.forEach(([expected, actual]) => {
217
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
218
+ (0, chai_1.expect)(subDataService.makerLeverageManagementWithoutSubProxy.decode(actual)).to.eql(expected);
219
+ });
220
+ });
221
+ });
222
+ });
167
223
  describe('When testing subDataService.liquityLeverageManagementSubData', () => {
168
224
  describe('decode()', () => {
169
225
  const examples = [
@@ -2033,4 +2089,161 @@ describe('Feature: subDataService.ts', () => {
2033
2089
  });
2034
2090
  });
2035
2091
  });
2092
+ describe('When testing subDataService.aaveV4LeverageManagementSubData', () => {
2093
+ describe('encode()', () => {
2094
+ const examples = [
2095
+ [
2096
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000"],
2097
+ [web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), enums_1.RatioState.UNDER, 150]
2098
+ ],
2099
+ ];
2100
+ examples.forEach(([expected, actual]) => {
2101
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2102
+ (0, chai_1.expect)(subDataService.aaveV4LeverageManagementSubData.encode(...actual)).to.eql(expected);
2103
+ });
2104
+ });
2105
+ });
2106
+ describe('decode()', () => {
2107
+ const examples = [
2108
+ [
2109
+ {
2110
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2111
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2112
+ ratioState: enums_1.RatioState.UNDER,
2113
+ targetRatio: 150,
2114
+ },
2115
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000"],
2116
+ ],
2117
+ ];
2118
+ examples.forEach(([expected, actual]) => {
2119
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2120
+ (0, chai_1.expect)(subDataService.aaveV4LeverageManagementSubData.decode(actual)).to.eql(expected);
2121
+ });
2122
+ });
2123
+ });
2124
+ });
2125
+ describe('When testing subDataService.aaveV4LeverageManagementOnPriceSubData', () => {
2126
+ describe('encode()', () => {
2127
+ const examples = [
2128
+ [
2129
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000"],
2130
+ [
2131
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2132
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
2133
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
2134
+ enums_1.RatioState.OVER, 160
2135
+ ]
2136
+ ],
2137
+ ];
2138
+ examples.forEach(([expected, actual]) => {
2139
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2140
+ (0, chai_1.expect)(subDataService.aaveV4LeverageManagementOnPriceSubData.encode(...actual)).to.eql(expected);
2141
+ });
2142
+ });
2143
+ });
2144
+ describe('decode()', () => {
2145
+ const examples = [
2146
+ [
2147
+ {
2148
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2149
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2150
+ collAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2151
+ collAssetId: 10,
2152
+ debtAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2153
+ debtAssetId: 20,
2154
+ ratioState: enums_1.RatioState.OVER,
2155
+ targetRatio: 160,
2156
+ },
2157
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000"],
2158
+ ],
2159
+ ];
2160
+ examples.forEach(([expected, actual]) => {
2161
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2162
+ (0, chai_1.expect)(subDataService.aaveV4LeverageManagementOnPriceSubData.decode(actual)).to.eql(expected);
2163
+ });
2164
+ });
2165
+ });
2166
+ });
2167
+ describe('When testing subDataService.aaveV4CloseSubData', () => {
2168
+ describe('encode()', () => {
2169
+ const examples = [
2170
+ [
2171
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000001"],
2172
+ [
2173
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2174
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
2175
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
2176
+ enums_1.CloseStrategyType.STOP_LOSS_IN_COLLATERAL
2177
+ ]
2178
+ ],
2179
+ ];
2180
+ examples.forEach(([expected, actual]) => {
2181
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2182
+ (0, chai_1.expect)(subDataService.aaveV4CloseSubData.encode(...actual)).to.eql(expected);
2183
+ });
2184
+ });
2185
+ });
2186
+ describe('decode()', () => {
2187
+ const examples = [
2188
+ [
2189
+ {
2190
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2191
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2192
+ collAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2193
+ collAssetId: 10,
2194
+ debtAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2195
+ debtAssetId: 20,
2196
+ closeType: enums_1.CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
2197
+ },
2198
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000001"],
2199
+ ],
2200
+ ];
2201
+ examples.forEach(([expected, actual]) => {
2202
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2203
+ (0, chai_1.expect)(subDataService.aaveV4CloseSubData.decode(actual)).to.eql(expected);
2204
+ });
2205
+ });
2206
+ });
2207
+ });
2208
+ describe('When testing subDataService.aaveV4CollateralSwitchSubData', () => {
2209
+ describe('encode()', () => {
2210
+ const examples = [
2211
+ [
2212
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000"],
2213
+ [
2214
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2215
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 10,
2216
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'), 20,
2217
+ '1000000000000000000'
2218
+ ]
2219
+ ],
2220
+ ];
2221
+ examples.forEach(([expected, actual]) => {
2222
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
2223
+ (0, chai_1.expect)(subDataService.aaveV4CollateralSwitchSubData.encode(...actual)).to.eql(expected);
2224
+ });
2225
+ });
2226
+ });
2227
+ describe('decode()', () => {
2228
+ const examples = [
2229
+ [
2230
+ {
2231
+ spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
2232
+ owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
2233
+ fromAsset: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
2234
+ fromAssetId: 10,
2235
+ toAsset: web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
2236
+ toAssetId: 20,
2237
+ amountToSwitch: '1000000000000000000'
2238
+ },
2239
+ ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000"],
2240
+ ],
2241
+ ];
2242
+ examples.forEach(([expected, actual]) => {
2243
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
2244
+ (0, chai_1.expect)(subDataService.aaveV4CollateralSwitchSubData.decode(actual)).to.eql(expected);
2245
+ });
2246
+ });
2247
+ });
2248
+ });
2036
2249
  });
@@ -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
+ };
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
26
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.morphoBluePriceRangeTrigger = exports.sparkQuotePriceRangeTrigger = exports.aaveV3QuotePriceRangeTrigger = exports.compoundV3PriceRangeTrigger = exports.compoundV3PriceTrigger = exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityV2AdjustTimeTrigger = exports.liquityV2DebtInFrontTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
29
+ exports.aaveV4QuotePriceRangeTrigger = exports.aaveV4QuotePriceTrigger = exports.aaveV4RatioTrigger = exports.morphoBluePriceRangeTrigger = exports.sparkQuotePriceRangeTrigger = exports.aaveV3QuotePriceRangeTrigger = exports.compoundV3PriceRangeTrigger = exports.compoundV3PriceTrigger = exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityV2AdjustTimeTrigger = exports.liquityV2DebtInFrontTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
30
30
  const decimal_js_1 = __importDefault(require("decimal.js"));
31
31
  const tokens_1 = require("@defisaver/tokens");
32
32
  const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
@@ -547,3 +547,57 @@ exports.morphoBluePriceRangeTrigger = {
547
547
  };
548
548
  },
549
549
  };
550
+ exports.aaveV4RatioTrigger = {
551
+ encode(owner, spoke, ratioPercentage, ratioState) {
552
+ const ratioWei = (0, utils_1.ratioPercentageToWei)(ratioPercentage);
553
+ return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [owner, spoke, ratioWei, ratioState])];
554
+ },
555
+ decode(triggerData) {
556
+ const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
557
+ return {
558
+ owner: decodedData[0],
559
+ spoke: decodedData[1],
560
+ ratio: (0, utils_1.weiToRatioPercentage)(decodedData[2]),
561
+ ratioState: Number(decodedData[3]),
562
+ };
563
+ },
564
+ };
565
+ exports.aaveV4QuotePriceTrigger = {
566
+ encode(spoke, baseTokenId, quoteTokenId, price, ratioState) {
567
+ // Price is always in 8 decimals
568
+ const _price = new decimal_js_1.default(price.toString()).mul(Math.pow(10, 8)).floor().toString();
569
+ return [web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], [spoke, baseTokenId, quoteTokenId, _price, ratioState])];
570
+ },
571
+ decode(triggerData) {
572
+ const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint8'], triggerData[0]);
573
+ // Price is always in 8 decimals
574
+ const price = new decimal_js_1.default(decodedData[3]).div(Math.pow(10, 8)).toDP(8).toString();
575
+ return {
576
+ spoke: decodedData[0],
577
+ baseTokenId: Number(decodedData[1]),
578
+ quoteTokenId: Number(decodedData[2]),
579
+ price,
580
+ ratioState: Number(decodedData[4]),
581
+ };
582
+ },
583
+ };
584
+ exports.aaveV4QuotePriceRangeTrigger = {
585
+ encode(spoke, baseTokenId, quoteTokenId, lowerPrice, upperPrice) {
586
+ // Price is scaled to 1e8
587
+ const lowerPriceFormatted = new decimal_js_1.default(lowerPrice).mul(1e8).floor().toString();
588
+ const upperPriceFormatted = new decimal_js_1.default(upperPrice).mul(1e8).floor().toString();
589
+ return [
590
+ web3_eth_abi_1.default.encodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint256'], [spoke, baseTokenId, quoteTokenId, lowerPriceFormatted, upperPriceFormatted]),
591
+ ];
592
+ },
593
+ decode(triggerData) {
594
+ const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'uint256', 'uint256', 'uint256', 'uint256'], triggerData[0]);
595
+ return {
596
+ spoke: decodedData[0],
597
+ baseTokenId: Number(decodedData[1]),
598
+ quoteTokenId: Number(decodedData[2]),
599
+ lowerPrice: new decimal_js_1.default(decodedData[3]).div(1e8).toString(),
600
+ upperPrice: new decimal_js_1.default(decodedData[4]).div(1e8).toString(),
601
+ };
602
+ },
603
+ };
@@ -1184,4 +1184,88 @@ describe('Feature: triggerService.ts', () => {
1184
1184
  });
1185
1185
  });
1186
1186
  });
1187
+ describe('When testing triggerService.aaveV4RatioTrigger', () => {
1188
+ describe('encode()', () => {
1189
+ const examples = [
1190
+ [
1191
+ ['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
1192
+ [web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 120, enums_1.RatioState.UNDER]
1193
+ ],
1194
+ ];
1195
+ examples.forEach(([expected, actual]) => {
1196
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1197
+ (0, chai_1.expect)(triggerService_1.aaveV4RatioTrigger.encode(...actual)).to.eql(expected);
1198
+ });
1199
+ });
1200
+ });
1201
+ describe('decode()', () => {
1202
+ const examples = [
1203
+ [
1204
+ { owner: web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), ratio: 120, ratioState: enums_1.RatioState.UNDER },
1205
+ ['0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001'],
1206
+ ],
1207
+ ];
1208
+ examples.forEach(([expected, actual]) => {
1209
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1210
+ (0, chai_1.expect)(triggerService_1.aaveV4RatioTrigger.decode(actual)).to.eql(expected);
1211
+ });
1212
+ });
1213
+ });
1214
+ });
1215
+ describe('When testing triggerService.aaveV4QuotePriceTrigger', () => {
1216
+ describe('encode()', () => {
1217
+ const examples = [
1218
+ [
1219
+ ['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
1220
+ [web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, 1500, enums_1.RatioState.OVER]
1221
+ ],
1222
+ ];
1223
+ examples.forEach(([expected, actual]) => {
1224
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1225
+ (0, chai_1.expect)(triggerService_1.aaveV4QuotePriceTrigger.encode(...actual)).to.eql(expected);
1226
+ });
1227
+ });
1228
+ });
1229
+ describe('decode()', () => {
1230
+ const examples = [
1231
+ [
1232
+ { spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, price: '1500', ratioState: enums_1.RatioState.OVER },
1233
+ ['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
1234
+ ],
1235
+ ];
1236
+ examples.forEach(([expected, actual]) => {
1237
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1238
+ (0, chai_1.expect)(triggerService_1.aaveV4QuotePriceTrigger.decode(actual)).to.eql(expected);
1239
+ });
1240
+ });
1241
+ });
1242
+ });
1243
+ describe('When testing triggerService.aaveV4QuotePriceRangeTrigger', () => {
1244
+ describe('encode()', () => {
1245
+ const examples = [
1246
+ [
1247
+ ['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000002098a678000000000000000000000000000000000000000000000000000000002540be4000'],
1248
+ [web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), 10, 20, 1400, 1600]
1249
+ ],
1250
+ ];
1251
+ examples.forEach(([expected, actual]) => {
1252
+ it(`Given ${actual} should return expected value: ${expected}`, () => {
1253
+ (0, chai_1.expect)(triggerService_1.aaveV4QuotePriceRangeTrigger.encode(...actual)).to.eql(expected);
1254
+ });
1255
+ });
1256
+ });
1257
+ describe('decode()', () => {
1258
+ const examples = [
1259
+ [
1260
+ { spoke: web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'), baseTokenId: 10, quoteTokenId: 20, lowerPrice: '1400', upperPrice: '1600' },
1261
+ ['0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000002098a678000000000000000000000000000000000000000000000000000000002540be4000'],
1262
+ ],
1263
+ ];
1264
+ examples.forEach(([expected, actual]) => {
1265
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
1266
+ (0, chai_1.expect)(triggerService_1.aaveV4QuotePriceRangeTrigger.decode(actual)).to.eql(expected);
1267
+ });
1268
+ });
1269
+ });
1270
+ });
1187
1271
  });
@@ -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,
@@ -69,6 +69,7 @@ var ProtocolIdentifiers;
69
69
  StrategiesAutomation["CompoundV3"] = "Compound__V3";
70
70
  StrategiesAutomation["AaveV2"] = "Aave__V2";
71
71
  StrategiesAutomation["AaveV3"] = "Aave__V3";
72
+ StrategiesAutomation["AaveV4"] = "Aave__V4";
72
73
  StrategiesAutomation["MorphoAaveV2"] = "Morpho-Aave__V2";
73
74
  StrategiesAutomation["Exchange"] = "Exchange";
74
75
  StrategiesAutomation["Spark"] = "Spark";
@@ -103,6 +104,7 @@ var Strategies;
103
104
  MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
104
105
  MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
105
106
  MainnetIds[MainnetIds["AAVE_V3_COLLATERAL_SWITCH"] = 135] = "AAVE_V3_COLLATERAL_SWITCH";
107
+ MainnetIds[MainnetIds["AAVE_V4_COLLATERAL_SWITCH"] = 151] = "AAVE_V4_COLLATERAL_SWITCH";
106
108
  })(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
107
109
  let OptimismIds;
108
110
  (function (OptimismIds) {
@@ -231,6 +233,16 @@ var Bundles;
231
233
  MainnetIds[MainnetIds["AAVE_V3_EOA_CLOSE"] = 56] = "AAVE_V3_EOA_CLOSE";
232
234
  MainnetIds[MainnetIds["SPARK_CLOSE"] = 57] = "SPARK_CLOSE";
233
235
  MainnetIds[MainnetIds["MORPHO_BLUE_CLOSE"] = 58] = "MORPHO_BLUE_CLOSE";
236
+ MainnetIds[MainnetIds["AAVE_V4_REPAY"] = 59] = "AAVE_V4_REPAY";
237
+ MainnetIds[MainnetIds["AAVE_V4_BOOST"] = 60] = "AAVE_V4_BOOST";
238
+ MainnetIds[MainnetIds["AAVE_V4_REPAY_ON_PRICE"] = 61] = "AAVE_V4_REPAY_ON_PRICE";
239
+ MainnetIds[MainnetIds["AAVE_V4_BOOST_ON_PRICE"] = 62] = "AAVE_V4_BOOST_ON_PRICE";
240
+ MainnetIds[MainnetIds["AAVE_V4_CLOSE"] = 63] = "AAVE_V4_CLOSE";
241
+ MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY"] = 64] = "AAVE_V4_EOA_REPAY";
242
+ MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST"] = 65] = "AAVE_V4_EOA_BOOST";
243
+ MainnetIds[MainnetIds["AAVE_V4_EOA_REPAY_ON_PRICE"] = 66] = "AAVE_V4_EOA_REPAY_ON_PRICE";
244
+ MainnetIds[MainnetIds["AAVE_V4_EOA_BOOST_ON_PRICE"] = 67] = "AAVE_V4_EOA_BOOST_ON_PRICE";
245
+ MainnetIds[MainnetIds["AAVE_V4_EOA_CLOSE"] = 68] = "AAVE_V4_EOA_CLOSE";
234
246
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
235
247
  let OptimismIds;
236
248
  (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;
@@ -100,6 +100,11 @@ export const MAINNET_STRATEGIES_INFO = {
100
100
  strategyId: Strategies.Identifiers.CollateralSwitch,
101
101
  protocol: PROTOCOLS.AaveV3,
102
102
  },
103
+ [Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH]: {
104
+ strategyOrBundleId: Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH,
105
+ strategyId: Strategies.Identifiers.CollateralSwitch,
106
+ protocol: PROTOCOLS.AaveV4,
107
+ },
103
108
  };
104
109
  export const OPTIMISM_STRATEGIES_INFO = {
105
110
  [Strategies.OptimismIds.EXCHANGE_DCA]: {
@@ -467,6 +472,56 @@ export const MAINNET_BUNDLES_INFO = {
467
472
  strategyId: Strategies.Identifiers.CloseOnPrice,
468
473
  protocol: PROTOCOLS.MorphoBlue,
469
474
  },
475
+ [Bundles.MainnetIds.AAVE_V4_REPAY]: {
476
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_REPAY,
477
+ strategyId: Strategies.Identifiers.Repay,
478
+ protocol: PROTOCOLS.AaveV4,
479
+ },
480
+ [Bundles.MainnetIds.AAVE_V4_BOOST]: {
481
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_BOOST,
482
+ strategyId: Strategies.Identifiers.Boost,
483
+ protocol: PROTOCOLS.AaveV4,
484
+ },
485
+ [Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE]: {
486
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE,
487
+ strategyId: Strategies.Identifiers.RepayOnPrice,
488
+ protocol: PROTOCOLS.AaveV4,
489
+ },
490
+ [Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE]: {
491
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE,
492
+ strategyId: Strategies.Identifiers.BoostOnPrice,
493
+ protocol: PROTOCOLS.AaveV4,
494
+ },
495
+ [Bundles.MainnetIds.AAVE_V4_CLOSE]: {
496
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_CLOSE,
497
+ strategyId: Strategies.Identifiers.CloseOnPrice,
498
+ protocol: PROTOCOLS.AaveV4,
499
+ },
500
+ [Bundles.MainnetIds.AAVE_V4_EOA_REPAY]: {
501
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_REPAY,
502
+ strategyId: Strategies.Identifiers.EoaRepay,
503
+ protocol: PROTOCOLS.AaveV4,
504
+ },
505
+ [Bundles.MainnetIds.AAVE_V4_EOA_BOOST]: {
506
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_BOOST,
507
+ strategyId: Strategies.Identifiers.EoaBoost,
508
+ protocol: PROTOCOLS.AaveV4,
509
+ },
510
+ [Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE]: {
511
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE,
512
+ strategyId: Strategies.Identifiers.EoaRepayOnPrice,
513
+ protocol: PROTOCOLS.AaveV4,
514
+ },
515
+ [Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE]: {
516
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE,
517
+ strategyId: Strategies.Identifiers.EoaBoostOnPrice,
518
+ protocol: PROTOCOLS.AaveV4,
519
+ },
520
+ [Bundles.MainnetIds.AAVE_V4_EOA_CLOSE]: {
521
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_CLOSE,
522
+ strategyId: Strategies.Identifiers.EoaCloseOnPrice,
523
+ protocol: PROTOCOLS.AaveV4,
524
+ },
470
525
  };
471
526
  export const OPTIMISM_BUNDLES_INFO = {
472
527
  [Bundles.OptimismIds.AAVE_V3_REPAY]: {
@@ -13,20 +13,27 @@ import { addToObjectIf, isDefined } from './utils';
13
13
  export function multicall(web3, chainId, calls, block = 'latest') {
14
14
  return __awaiter(this, void 0, void 0, function* () {
15
15
  const multicallContract = makeUniMulticallContract(web3, chainId).contract;
16
- const formattedCalls = calls.map((call) => ({
17
- callData: AbiCoder.encodeFunctionCall(call.abiItem, call.params),
18
- target: call.target || '0x0',
19
- gasLimit: call.gasLimit || 1e6,
20
- }));
21
- const callResult = yield multicallContract.methods.multicall(formattedCalls.filter(item => item.target !== '0x0')).call({}, block);
22
- let formattedResult = [];
23
- callResult.returnData.forEach(([success, gasUsed, result], i) => {
24
- const formattedRes = (result !== '0x'
25
- ? AbiCoder.decodeParameters(calls[i].abiItem.outputs, result)
26
- : undefined);
27
- formattedResult = [...formattedResult, formattedRes];
28
- });
29
- return formattedResult;
16
+ const MAX_CALLS_PER_BATCH = 1000;
17
+ const allResults = [];
18
+ // Process each chunk
19
+ for (let i = 0; i < calls.length; i += MAX_CALLS_PER_BATCH) {
20
+ const chunk = calls.slice(i, i + MAX_CALLS_PER_BATCH);
21
+ const formattedCalls = chunk.map((call) => ({
22
+ callData: AbiCoder.encodeFunctionCall(call.abiItem, call.params),
23
+ target: call.target || '0x0',
24
+ gasLimit: call.gasLimit || 1e6,
25
+ }));
26
+ const callResult = yield multicallContract.methods.multicall(formattedCalls).call({}, block);
27
+ let formattedResult = [];
28
+ callResult.returnData.forEach(([success, , result], j) => {
29
+ const formattedRes = (success && result !== '0x'
30
+ ? AbiCoder.decodeParameters(chunk[j].abiItem.outputs, result)
31
+ : undefined);
32
+ formattedResult = [...formattedResult, formattedRes];
33
+ });
34
+ allResults.push(...formattedResult);
35
+ }
36
+ return allResults;
30
37
  });
31
38
  }
32
39
  export function getEventsFromContract(contractWithMeta, contractWithMetaFork, event, options) {