@defisaver/automation-sdk 3.3.11 → 3.3.12

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 (54) hide show
  1. package/cjs/automation/private/StrategiesAutomation.d.ts +2 -0
  2. package/cjs/automation/private/StrategiesAutomation.js +10 -1
  3. package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
  4. package/cjs/constants/index.d.ts +1 -0
  5. package/cjs/constants/index.js +62 -1
  6. package/cjs/services/strategiesService.js +104 -0
  7. package/cjs/services/strategySubService.d.ts +6 -0
  8. package/cjs/services/strategySubService.js +30 -1
  9. package/cjs/services/strategySubService.test.js +96 -0
  10. package/cjs/services/subDataService.d.ts +295 -137
  11. package/cjs/services/subDataService.js +639 -393
  12. package/cjs/services/subDataService.test.js +157 -0
  13. package/cjs/services/triggerService.d.ts +29 -0
  14. package/cjs/services/triggerService.js +53 -1
  15. package/cjs/services/triggerService.test.js +84 -0
  16. package/cjs/services/utils.d.ts +1 -1
  17. package/cjs/services/utils.js +10 -2
  18. package/cjs/types/enums.d.ts +17 -3
  19. package/cjs/types/enums.js +14 -0
  20. package/cjs/types/index.d.ts +22 -1
  21. package/esm/automation/private/StrategiesAutomation.d.ts +2 -0
  22. package/esm/automation/private/StrategiesAutomation.js +10 -1
  23. package/esm/automation/private/StrategiesAutomation.test.js +25 -0
  24. package/esm/constants/index.d.ts +1 -0
  25. package/esm/constants/index.js +61 -0
  26. package/esm/services/strategiesService.js +105 -1
  27. package/esm/services/strategySubService.d.ts +6 -0
  28. package/esm/services/strategySubService.js +29 -0
  29. package/esm/services/strategySubService.test.js +97 -1
  30. package/esm/services/subDataService.d.ts +295 -137
  31. package/esm/services/subDataService.js +639 -393
  32. package/esm/services/subDataService.test.js +157 -0
  33. package/esm/services/triggerService.d.ts +29 -0
  34. package/esm/services/triggerService.js +52 -0
  35. package/esm/services/triggerService.test.js +85 -1
  36. package/esm/services/utils.d.ts +1 -1
  37. package/esm/services/utils.js +10 -2
  38. package/esm/types/enums.d.ts +17 -3
  39. package/esm/types/enums.js +14 -0
  40. package/esm/types/index.d.ts +22 -1
  41. package/package.json +2 -2
  42. package/src/automation/private/StrategiesAutomation.test.ts +40 -0
  43. package/src/automation/private/StrategiesAutomation.ts +11 -0
  44. package/src/constants/index.ts +62 -0
  45. package/src/services/strategiesService.ts +119 -1
  46. package/src/services/strategySubService.test.ts +124 -0
  47. package/src/services/strategySubService.ts +118 -0
  48. package/src/services/subDataService.test.ts +172 -0
  49. package/src/services/subDataService.ts +1031 -782
  50. package/src/services/triggerService.test.ts +97 -0
  51. package/src/services/triggerService.ts +74 -1
  52. package/src/services/utils.ts +15 -4
  53. package/src/types/enums.ts +14 -0
  54. package/src/types/index.ts +26 -0
@@ -3,6 +3,7 @@ import Protocol from '../automation/private/Protocol';
3
3
  import LegacyProtocol from '../automation/private/LegacyProtocol';
4
4
  // General
5
5
  export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
6
+ export const EMPTY_SLOT = '0x0000000000000000000000000000000000000000000000000000000000000000';
6
7
  export const AAVE_V3_VARIABLE_BORROW_RATE = 2;
7
8
  export const PROTOCOLS = (() => {
8
9
  const protocolsMapping = {};
@@ -100,6 +101,16 @@ export const MAINNET_STRATEGIES_INFO = {
100
101
  strategyId: Strategies.Identifiers.CollateralSwitch,
101
102
  protocol: PROTOCOLS.AaveV3,
102
103
  },
104
+ [Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH]: {
105
+ strategyOrBundleId: Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH,
106
+ strategyId: Strategies.Identifiers.CollateralSwitch,
107
+ protocol: PROTOCOLS.AaveV4,
108
+ },
109
+ [Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH_EOA]: {
110
+ strategyOrBundleId: Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH_EOA,
111
+ strategyId: Strategies.Identifiers.EoaCollateralSwitch,
112
+ protocol: PROTOCOLS.AaveV4,
113
+ },
103
114
  };
104
115
  export const OPTIMISM_STRATEGIES_INFO = {
105
116
  [Strategies.OptimismIds.EXCHANGE_DCA]: {
@@ -477,6 +488,56 @@ export const MAINNET_BUNDLES_INFO = {
477
488
  strategyId: Strategies.Identifiers.BoostOnPrice,
478
489
  protocol: PROTOCOLS.Spark,
479
490
  },
491
+ [Bundles.MainnetIds.AAVE_V4_REPAY]: {
492
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_REPAY,
493
+ strategyId: Strategies.Identifiers.Repay,
494
+ protocol: PROTOCOLS.AaveV4,
495
+ },
496
+ [Bundles.MainnetIds.AAVE_V4_BOOST]: {
497
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_BOOST,
498
+ strategyId: Strategies.Identifiers.Boost,
499
+ protocol: PROTOCOLS.AaveV4,
500
+ },
501
+ [Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE]: {
502
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE,
503
+ strategyId: Strategies.Identifiers.RepayOnPrice,
504
+ protocol: PROTOCOLS.AaveV4,
505
+ },
506
+ [Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE]: {
507
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE,
508
+ strategyId: Strategies.Identifiers.BoostOnPrice,
509
+ protocol: PROTOCOLS.AaveV4,
510
+ },
511
+ [Bundles.MainnetIds.AAVE_V4_CLOSE]: {
512
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_CLOSE,
513
+ strategyId: Strategies.Identifiers.CloseOnPrice,
514
+ protocol: PROTOCOLS.AaveV4,
515
+ },
516
+ [Bundles.MainnetIds.AAVE_V4_EOA_REPAY]: {
517
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_REPAY,
518
+ strategyId: Strategies.Identifiers.EoaRepay,
519
+ protocol: PROTOCOLS.AaveV4,
520
+ },
521
+ [Bundles.MainnetIds.AAVE_V4_EOA_BOOST]: {
522
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_BOOST,
523
+ strategyId: Strategies.Identifiers.EoaBoost,
524
+ protocol: PROTOCOLS.AaveV4,
525
+ },
526
+ [Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE]: {
527
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE,
528
+ strategyId: Strategies.Identifiers.EoaRepayOnPrice,
529
+ protocol: PROTOCOLS.AaveV4,
530
+ },
531
+ [Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE]: {
532
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE,
533
+ strategyId: Strategies.Identifiers.EoaBoostOnPrice,
534
+ protocol: PROTOCOLS.AaveV4,
535
+ },
536
+ [Bundles.MainnetIds.AAVE_V4_EOA_CLOSE]: {
537
+ strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_CLOSE,
538
+ strategyId: Strategies.Identifiers.EoaCloseOnPrice,
539
+ protocol: PROTOCOLS.AaveV4,
540
+ },
480
541
  };
481
542
  export const OPTIMISM_BUNDLES_INFO = {
482
543
  [Bundles.OptimismIds.AAVE_V3_REPAY]: {
@@ -2,7 +2,7 @@ import { getAssetInfoByAddress } from '@defisaver/tokens';
2
2
  import { cloneDeep } from 'lodash';
3
3
  import Web3 from 'web3';
4
4
  import { BUNDLES_INFO, STRATEGIES_INFO } from '../constants';
5
- import { ChainId, ProtocolIdentifiers, Strategies } from '../types/enums';
5
+ import { ChainId, ProtocolIdentifiers, Strategies, } from '../types/enums';
6
6
  import { getPositionId, getRatioStateInfoForAaveCloseStrategy, getStopLossAndTakeProfitTypeByCloseStrategyType, isRatioStateOver, wethToEthByAddress, } from './utils';
7
7
  import * as subDataService from './subDataService';
8
8
  import * as triggerService from './triggerService';
@@ -285,6 +285,96 @@ function parseAaveV3CollateralSwitch(position, parseData) {
285
285
  _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
286
286
  return _position;
287
287
  }
288
+ function parseAaveV4LeverageManagement(position, parseData) {
289
+ const _position = cloneDeep(position);
290
+ const { subStruct, subId, subHash } = parseData.subscriptionEventData;
291
+ const { isEnabled } = parseData.strategiesSubsData;
292
+ const triggerData = triggerService.aaveV4RatioTrigger.decode(subStruct.triggerData);
293
+ const subData = subDataService.aaveV4LeverageManagementSubData.decode(subStruct.subData);
294
+ const isEOA = _position.strategy.strategyId.includes('eoa');
295
+ const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
296
+ _position.strategyData.decoded.triggerData = triggerData;
297
+ _position.strategyData.decoded.subData = subData;
298
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
299
+ _position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
300
+ if (isRepay) {
301
+ _position.specific = {
302
+ triggerRepayRatio: triggerData.ratio,
303
+ targetRepayRatio: subData.targetRatio,
304
+ repayEnabled: isEnabled,
305
+ subId1: Number(subId),
306
+ mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
307
+ subHashRepay: subHash,
308
+ };
309
+ }
310
+ else {
311
+ _position.specific = {
312
+ triggerBoostRatio: triggerData.ratio,
313
+ targetBoostRatio: subData.targetRatio,
314
+ boostEnabled: isEnabled,
315
+ subId2: Number(subId),
316
+ mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
317
+ subHashBoost: subHash,
318
+ };
319
+ }
320
+ return _position;
321
+ }
322
+ function parseAaveV4LeverageManagementOnPrice(position, parseData) {
323
+ const _position = cloneDeep(position);
324
+ const { subStruct } = parseData.subscriptionEventData;
325
+ const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
326
+ const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.decode(subStruct.subData);
327
+ const isEOA = _position.strategy.strategyId.includes('eoa');
328
+ _position.strategyData.decoded.triggerData = triggerData;
329
+ _position.strategyData.decoded.subData = subData;
330
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
331
+ _position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagementOnPrice : Strategies.IdOverrides.LeverageManagementOnPrice;
332
+ _position.specific = {
333
+ collAsset: subData.collAsset,
334
+ collAssetId: subData.collAssetId,
335
+ debtAsset: subData.debtAsset,
336
+ debtAssetId: subData.debtAssetId,
337
+ price: triggerData.price,
338
+ ratioState: triggerData.ratioState,
339
+ ratio: subData.targetRatio,
340
+ };
341
+ return _position;
342
+ }
343
+ function parseAaveV4CloseOnPrice(position, parseData) {
344
+ const _position = cloneDeep(position);
345
+ const { subStruct } = parseData.subscriptionEventData;
346
+ const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.decode(subStruct.triggerData);
347
+ const subData = subDataService.aaveV4CloseSubData.decode(subStruct.subData);
348
+ const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
349
+ const isEOA = _position.strategy.strategyId.includes('eoa');
350
+ _position.strategyData.decoded.triggerData = triggerData;
351
+ _position.strategyData.decoded.subData = subData;
352
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
353
+ _position.strategy.strategyId = isEOA ? Strategies.Identifiers.EoaCloseOnPrice : Strategies.Identifiers.CloseOnPrice;
354
+ _position.specific = {
355
+ collAsset: subData.collAsset,
356
+ collAssetId: subData.collAssetId,
357
+ debtAsset: subData.debtAsset,
358
+ debtAssetId: subData.debtAssetId,
359
+ stopLossPrice: triggerData.lowerPrice,
360
+ takeProfitPrice: triggerData.upperPrice,
361
+ stopLossType,
362
+ takeProfitType,
363
+ };
364
+ return _position;
365
+ }
366
+ function parseAaveV4CollateralSwitch(position, parseData) {
367
+ const _position = cloneDeep(position);
368
+ const { subStruct } = parseData.subscriptionEventData;
369
+ const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
370
+ const subData = subDataService.aaveV4CollateralSwitchSubData.decode(subStruct.subData);
371
+ const isEOA = _position.strategy.strategyId.includes('eoa');
372
+ _position.strategyData.decoded.triggerData = triggerData;
373
+ _position.strategyData.decoded.subData = subData;
374
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
375
+ _position.strategy.strategyId = isEOA ? Strategies.Identifiers.EoaCollateralSwitch : Strategies.Identifiers.CollateralSwitch;
376
+ return _position;
377
+ }
288
378
  function parseMorphoAaveV2LeverageManagement(position, parseData) {
289
379
  const _position = cloneDeep(position);
290
380
  const { subStruct, subId } = parseData.subscriptionEventData;
@@ -937,6 +1027,20 @@ const parsingMethodsMapping = {
937
1027
  [Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
938
1028
  [Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
939
1029
  },
1030
+ [ProtocolIdentifiers.StrategiesAutomation.AaveV4]: {
1031
+ [Strategies.Identifiers.Repay]: parseAaveV4LeverageManagement,
1032
+ [Strategies.Identifiers.Boost]: parseAaveV4LeverageManagement,
1033
+ [Strategies.Identifiers.RepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
1034
+ [Strategies.Identifiers.BoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
1035
+ [Strategies.Identifiers.CloseOnPrice]: parseAaveV4CloseOnPrice,
1036
+ [Strategies.Identifiers.EoaRepay]: parseAaveV4LeverageManagement,
1037
+ [Strategies.Identifiers.EoaBoost]: parseAaveV4LeverageManagement,
1038
+ [Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
1039
+ [Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
1040
+ [Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV4CloseOnPrice,
1041
+ [Strategies.Identifiers.CollateralSwitch]: parseAaveV4CollateralSwitch,
1042
+ [Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV4CollateralSwitch,
1043
+ },
940
1044
  [ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
941
1045
  [Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
942
1046
  [Strategies.Identifiers.Boost]: parseCompoundV2LeverageManagement,
@@ -120,3 +120,9 @@ export declare const liquityV2Encode: {
120
120
  export declare const fluidEncode: {
121
121
  leverageManagement(nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
122
122
  };
123
+ export declare const aaveV4Encode: {
124
+ leverageManagement(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
125
+ leverageManagementOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price: string, priceState: RatioState, ratioState: RatioState): (number | boolean | string[])[];
126
+ closeOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice?: string, stopLossType?: CloseToAssetType, takeProfitPrice?: string, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
127
+ collateralSwitch(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: string, ratioState: RatioState): (number | boolean | string[])[];
128
+ };
@@ -348,3 +348,32 @@ export const fluidEncode = {
348
348
  return [strategyOrBundleId, isBundle, triggerData, subData];
349
349
  },
350
350
  };
351
+ export const aaveV4Encode = {
352
+ leverageManagement(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
353
+ const isBundle = true;
354
+ const subData = subDataService.aaveV4LeverageManagementSubData.encode(spoke, owner, ratioState, targetRatio);
355
+ const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
356
+ return [strategyOrBundleId, isBundle, triggerData, subData];
357
+ },
358
+ leverageManagementOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, targetRatio, price, priceState, ratioState) {
359
+ const isBundle = true;
360
+ const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio);
361
+ const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(spoke, collAssetId, debtAssetId, price, priceState);
362
+ return [strategyOrBundleId, isBundle, triggerData, subData];
363
+ },
364
+ closeOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, stopLossPrice = '0', stopLossType = CloseToAssetType.DEBT, takeProfitPrice = '0', takeProfitType = CloseToAssetType.COLLATERAL) {
365
+ const isBundle = true;
366
+ const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
367
+ const subData = subDataService.aaveV4CloseSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, closeType);
368
+ const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.encode(spoke, collAssetId, debtAssetId, stopLossPrice, takeProfitPrice);
369
+ return [strategyOrBundleId, isBundle, triggerData, subData];
370
+ },
371
+ collateralSwitch(strategyOrBundleId, owner, spoke, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch, price, ratioState) {
372
+ const isBundle = false;
373
+ const subData = subDataService.aaveV4CollateralSwitchSubData.encode(spoke, owner, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch);
374
+ const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(spoke, fromAssetId, // baseTokenId
375
+ toAssetId, // quoteTokenId
376
+ price, ratioState);
377
+ return [strategyOrBundleId, isBundle, triggerData, subData];
378
+ },
379
+ };
@@ -5,7 +5,7 @@ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
5
5
  import * as web3Utils from 'web3-utils';
6
6
  import { Bundles, ChainId, CloseToAssetType, OrderType, RatioState, Strategies } from '../types/enums';
7
7
  import '../configuration';
8
- import { aaveV2Encode, chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV2Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, crvUSDEncode, compoundV3L2Encode, morphoBlueEncode, sparkEncode, } from './strategySubService';
8
+ import { aaveV2Encode, chickenBondsEncode, liquityEncode, makerEncode, aaveV3Encode, compoundV2Encode, compoundV3Encode, morphoAaveV2Encode, exchangeEncode, crvUSDEncode, compoundV3L2Encode, morphoBlueEncode, sparkEncode, aaveV4Encode, } from './strategySubService';
9
9
  describe('Feature: strategySubService.ts', () => {
10
10
  describe('When testing strategySubService.makerEncode', () => {
11
11
  // @ts-ignore // TODO - this requires change in @defisaver/tokens
@@ -1586,4 +1586,100 @@ describe('Feature: strategySubService.ts', () => {
1586
1586
  });
1587
1587
  });
1588
1588
  });
1589
+ describe('When testing strategySubService.aaveV4Encode', () => {
1590
+ describe('leverageManagement()', () => {
1591
+ const examples = [
1592
+ [
1593
+ [1, true, ["0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
1594
+ [
1595
+ 1,
1596
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1597
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
1598
+ RatioState.UNDER,
1599
+ 150,
1600
+ 120,
1601
+ ]
1602
+ ]
1603
+ ];
1604
+ examples.forEach(([expected, actual]) => {
1605
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1606
+ expect(aaveV4Encode.leverageManagement(...actual)).to.eql(expected);
1607
+ });
1608
+ });
1609
+ });
1610
+ describe('leverageManagementOnPrice()', () => {
1611
+ const examples = [
1612
+ [
1613
+ [2, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
1614
+ [
1615
+ 2,
1616
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1617
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
1618
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1619
+ 10,
1620
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1621
+ 20,
1622
+ 160,
1623
+ '1500',
1624
+ RatioState.OVER,
1625
+ RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
1626
+ ]
1627
+ ]
1628
+ ];
1629
+ examples.forEach(([expected, actual]) => {
1630
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1631
+ expect(aaveV4Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
1632
+ });
1633
+ });
1634
+ });
1635
+ describe('closeOnPrice()', () => {
1636
+ const examples = [
1637
+ [
1638
+ [3, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000003", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
1639
+ [
1640
+ 3,
1641
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1642
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
1643
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1644
+ 10,
1645
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1646
+ 20,
1647
+ '1400',
1648
+ CloseToAssetType.DEBT,
1649
+ '0',
1650
+ CloseToAssetType.COLLATERAL
1651
+ ]
1652
+ ]
1653
+ ];
1654
+ examples.forEach(([expected, actual]) => {
1655
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1656
+ expect(aaveV4Encode.closeOnPrice(...actual)).to.eql(expected);
1657
+ });
1658
+ });
1659
+ });
1660
+ describe('collateralSwitch()', () => {
1661
+ const examples = [
1662
+ [
1663
+ [4, false, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
1664
+ [
1665
+ 4,
1666
+ web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
1667
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
1668
+ web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
1669
+ 10,
1670
+ web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
1671
+ 20,
1672
+ '1000000000000000000',
1673
+ '1500',
1674
+ RatioState.UNDER,
1675
+ ]
1676
+ ]
1677
+ ];
1678
+ examples.forEach(([expected, actual]) => {
1679
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
1680
+ expect(aaveV4Encode.collateralSwitch(...actual)).to.eql(expected);
1681
+ });
1682
+ });
1683
+ });
1684
+ });
1589
1685
  });