@defisaver/automation-sdk 3.3.21-coll-switch-generic-dev → 3.3.21-instant-twap-close-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.
@@ -317,30 +317,36 @@ function parseAaveV3CloseOnPrice(position, parseData) {
317
317
  }
318
318
  return _position;
319
319
  }
320
- function parseAaveV3CollateralSwitch(position, parseData) {
320
+ function parseAaveV3InstantCloseOnPrice(position, parseData) {
321
321
  const _position = cloneDeep(position);
322
322
  const { subStruct } = parseData.subscriptionEventData;
323
- const isEOA = _position.strategy.strategyId.includes('eoa');
324
- const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
325
- const subData = isEOA
326
- ? subDataService.aaveV3GenericFLCollateralSwitchSubData.decode(subStruct.subData)
327
- : subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
323
+ const triggerData = triggerService.aaveV3QuotePriceRangeTrigger.decode(subStruct.triggerData);
324
+ const subData = subDataService.aaveV3InstantCloseGenericSubData.decode(subStruct.subData);
325
+ const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
326
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
328
327
  _position.strategyData.decoded.triggerData = triggerData;
329
328
  _position.strategyData.decoded.subData = subData;
330
- _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
331
- _position.strategy.strategyId = isEOA
332
- ? Strategies.Identifiers.EoaCollateralSwitch
333
- : Strategies.Identifiers.CollateralSwitch;
329
+ _position.specific = {
330
+ collAsset: subData.collAsset,
331
+ collAssetId: subData.collAssetId,
332
+ debtAsset: subData.debtAsset,
333
+ debtAssetId: subData.debtAssetId,
334
+ baseToken: triggerData.collToken,
335
+ quoteToken: triggerData.debtToken,
336
+ stopLossPrice: triggerData.lowerPrice,
337
+ takeProfitPrice: triggerData.upperPrice,
338
+ stopLossType,
339
+ takeProfitType,
340
+ };
334
341
  return _position;
335
342
  }
336
- function parseAaveV3DebtSwitch(position, parseData) {
343
+ function parseAaveV3CollateralSwitch(position, parseData) {
337
344
  const _position = cloneDeep(position);
338
345
  const { subStruct } = parseData.subscriptionEventData;
339
346
  const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
340
- const subData = subDataService.aaveV3DebtSwitchSubData.decode(subStruct.subData);
347
+ const subData = subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
341
348
  _position.strategyData.decoded.triggerData = triggerData;
342
349
  _position.strategyData.decoded.subData = subData;
343
- // TODO -> This isn't enough for ID
344
350
  _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
345
351
  return _position;
346
352
  }
@@ -1233,10 +1239,9 @@ const parsingMethodsMapping = {
1233
1239
  [Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
1234
1240
  [Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
1235
1241
  [Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
1242
+ [Strategies.Identifiers.InstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
1243
+ [Strategies.Identifiers.EoaInstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
1236
1244
  [Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
1237
- [Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV3CollateralSwitch,
1238
- [Strategies.Identifiers.DebtSwitch]: parseAaveV3DebtSwitch,
1239
- [Strategies.Identifiers.EoaDebtSwitch]: parseAaveV3DebtSwitch,
1240
1245
  [Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
1241
1246
  [Strategies.Identifiers.EoaLiquidationProtection]: parseAaveV3LiquidationProtection,
1242
1247
  },
@@ -8,104 +8,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { expect } from 'chai';
11
- import { ChainId, ProtocolIdentifiers, RatioState, Strategies } from '../types/enums';
12
- import { MAINNET_STRATEGIES_INFO } from '../constants';
11
+ import { Bundles, CloseStrategyType, CloseToAssetType, ProtocolIdentifiers, Strategies, } from '../types/enums';
13
12
  import '../configuration';
14
13
  import { parseStrategiesAutomatedPosition } from './strategiesService';
14
+ import { aaveV3Encode } from './strategySubService';
15
15
  describe('Feature: strategiesService.ts', () => {
16
- describe('When parsing Aave V3 collateral switch subscriptions', () => {
17
- const proxy = '0x9cB7E19861665366011899d74E75d4F2A419aEeD';
18
- const user = '0x1234567890123456789012345678901234567890';
19
- const fromAsset = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
20
- const toAsset = '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf';
21
- const marketAddr = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e';
22
- const amountToSwitch = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
23
- const subHash = `0x${'ab'.repeat(32)}`;
24
- const triggerData = [
25
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
26
- + '000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf'
27
- + '0000000000000000000000000000000000000000000000000000000000989680'
28
- + '0000000000000000000000000000000000000000000000000000000000000001',
29
- ];
30
- function getParseData(strategyId, isGeneric, chainId = ChainId.Ethereum) {
31
- const subData = [
32
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
33
- isGeneric
34
- ? '0x0000000000000000000000000000000000000000000000000000000000000100'
35
- : '0x0000000000000000000000000000000000000000000000000000000000000000',
36
- '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
37
- isGeneric
38
- ? '0x000000000000000000000000000000000000000000000000000000000000ffff'
39
- : '0x0000000000000000000000000000000000000000000000000000000000000007',
40
- '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
41
- '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
42
- isGeneric
43
- ? '0x0000000000000000000000001234567890123456789012345678901234567890'
44
- : '0x0000000000000000000000000000000000000000000000000000000000000000',
45
- ];
46
- const subStruct = Object.assign([String(strategyId), false, triggerData, subData], { strategyOrBundleId: String(strategyId), isBundle: false, triggerData, subData });
47
- return {
48
- chainId,
49
- blockNumber: 18015756,
50
- subscriptionEventData: {
51
- subId: '379', proxy, subHash, subStruct,
52
- 0: '379', 1: proxy, 2: subHash, 3: subStruct,
53
- },
54
- strategiesSubsData: {
55
- userProxy: proxy, isEnabled: true, strategySubHash: subHash,
56
- },
57
- };
58
- }
59
- it('decodes generic collateral switches with the user and uint16 reserve IDs', () => {
60
- const strategyId = Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH;
61
- const originalInfo = MAINNET_STRATEGIES_INFO[strategyId];
62
- const parseData = getParseData(strategyId, true);
63
- let position;
64
- MAINNET_STRATEGIES_INFO[strategyId] = Object.assign(Object.assign({}, originalInfo), { strategyId: Strategies.Identifiers.EoaCollateralSwitch });
65
- try {
66
- position = parseStrategiesAutomatedPosition(parseData);
67
- }
68
- finally {
69
- MAINNET_STRATEGIES_INFO[strategyId] = originalInfo;
70
- }
71
- expect(position).not.to.equal(null);
72
- expect(position.protocol.id).to.equal(ProtocolIdentifiers.StrategiesAutomation.AaveV3);
73
- expect(position.strategy.strategyId).to.equal(Strategies.Identifiers.EoaCollateralSwitch);
74
- expect(position.strategy.isBundle).to.equal(false);
75
- expect(position.strategyData.encoded).to.eql({
76
- triggerData,
77
- subData: parseData.subscriptionEventData.subStruct.subData,
78
- });
79
- expect(position.strategyData.decoded.triggerData).to.eql({
80
- baseTokenAddress: fromAsset,
81
- quoteTokenAddress: toAsset,
82
- price: '0.1',
83
- ratioState: RatioState.UNDER,
84
- });
85
- expect(position.strategyData.decoded.subData).to.eql({
86
- fromAsset, fromAssetId: 256, toAsset, toAssetId: 65535, marketAddr, amountToSwitch, user,
87
- });
88
- expect(position.owner).to.equal(proxy.toLowerCase());
89
- expect(position.positionId).to.equal(`1-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
90
- });
91
- const legacyStrategies = [
92
- [ChainId.Ethereum, Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH],
93
- [ChainId.Optimism, Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH],
94
- [ChainId.Arbitrum, Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH],
95
- [ChainId.Base, Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH],
96
- ];
97
- legacyStrategies.forEach(([chainId, strategyId]) => {
98
- it(`continues to decode legacy collateral switches on chain ${chainId}`, () => {
99
- const position = parseStrategiesAutomatedPosition(getParseData(strategyId, false, chainId));
100
- expect(position).not.to.equal(null);
101
- expect(position.strategy.strategyId).to.equal(Strategies.Identifiers.CollateralSwitch);
102
- expect(position.strategyData.decoded.subData).to.eql({
103
- fromAsset, fromAssetId: 0, toAsset, toAssetId: 7, marketAddr, amountToSwitch,
104
- });
105
- expect(position.positionId).to.equal(`${chainId}-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
106
- });
107
- });
108
- });
109
16
  describe('When testing strategiesService.parseStrategiesAutomatedPosition', () => __awaiter(void 0, void 0, void 0, function* () {
110
17
  // TODO: we should probably write this for every strategy?
111
18
  const examples = [
@@ -200,4 +107,65 @@ describe('Feature: strategiesService.ts', () => {
200
107
  }));
201
108
  });
202
109
  }));
110
+ describe('When parsing Aave V3 instant close bundles', () => {
111
+ const owner = '0x1234567890123456789012345678901234567890';
112
+ const market = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e';
113
+ const weth = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
114
+ const usdc = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48';
115
+ const bundles = [
116
+ ['SW', Bundles.MainnetIds.AAVE_V3_SW_INSTANT_CLOSE, Strategies.Identifiers.InstantCloseOnPrice],
117
+ ['EOA', Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE, Strategies.Identifiers.EoaInstantCloseOnPrice],
118
+ ];
119
+ bundles.forEach(([walletType, expectedBundleId, expectedStrategyId]) => {
120
+ describe(`${walletType} bundle`, () => {
121
+ const [bundleId, isBundle, triggerData, subData] = aaveV3Encode.instantCloseOnPriceGeneric(expectedBundleId, weth, 0, usdc, 1, market, owner, '1000000000000000000', '10000000000000000', 1500, CloseToAssetType.DEBT, 5000, CloseToAssetType.COLLATERAL);
122
+ const parseData = {
123
+ chainId: 1,
124
+ blockNumber: 1,
125
+ subscriptionEventData: {
126
+ subId: '1',
127
+ proxy: owner,
128
+ subHash: '0xhash',
129
+ subStruct: {
130
+ strategyOrBundleId: String(bundleId), isBundle, triggerData, subData,
131
+ },
132
+ },
133
+ strategiesSubsData: { userProxy: owner, isEnabled: true, strategySubHash: '0xhash' },
134
+ };
135
+ const result = parseStrategiesAutomatedPosition(parseData);
136
+ it('should identify the strategy as instant close on price', () => {
137
+ expect(result.strategy.strategyOrBundleId).to.equal(expectedBundleId);
138
+ expect(result.strategy.strategyId).to.equal(expectedStrategyId);
139
+ expect(result.protocol.id).to.equal(ProtocolIdentifiers.StrategiesAutomation.AaveV3);
140
+ });
141
+ it('should decode sub data including tsi and slippage', () => {
142
+ expect(result.strategyData.decoded.subData).to.eql({
143
+ collAsset: weth,
144
+ collAssetId: 0,
145
+ debtAsset: usdc,
146
+ debtAssetId: 1,
147
+ closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
148
+ marketAddr: market,
149
+ owner,
150
+ tsi: '1000000000000000000',
151
+ slippage: '10000000000000000',
152
+ });
153
+ });
154
+ it('should fill specific with prices and close types', () => {
155
+ expect(result.specific).to.eql({
156
+ collAsset: weth,
157
+ collAssetId: 0,
158
+ debtAsset: usdc,
159
+ debtAssetId: 1,
160
+ baseToken: weth,
161
+ quoteToken: usdc,
162
+ stopLossPrice: '1500',
163
+ takeProfitPrice: '5000',
164
+ stopLossType: CloseToAssetType.DEBT,
165
+ takeProfitType: CloseToAssetType.COLLATERAL,
166
+ });
167
+ });
168
+ });
169
+ });
170
+ });
203
171
  });
@@ -61,9 +61,8 @@ export declare const aaveV3Encode: {
61
61
  liquidationProtection(strategyOrBundleId: number, market: EthereumAddress, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
62
62
  leverageManagementOnPriceGeneric(strategyOrBundleId: number, price: number, ratioState: RatioState, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): (number | boolean | string[])[];
63
63
  closeOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
64
+ instantCloseOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, tsi: string, slippage: string, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
64
65
  collateralSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
65
- collateralSwitchGeneric(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
66
- debtSwitch(strategyOrBundleId: number, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress, baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, state: RatioState): (number | boolean | string[])[];
67
66
  };
68
67
  export declare const compoundV2Encode: {
69
68
  leverageManagement(strategyOrBundleId: number, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
@@ -164,21 +164,16 @@ export const aaveV3Encode = {
164
164
  const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
165
165
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
166
166
  },
167
- collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
168
- const isBundle = false;
169
- const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
170
- const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
171
- return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
172
- },
173
- collateralSwitchGeneric(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
174
- const isBundle = false;
175
- const subDataEncoded = subDataService.aaveV3GenericFLCollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
176
- const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
167
+ instantCloseOnPriceGeneric(strategyOrBundleId, collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, user, tsi, slippage, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
168
+ const isBundle = true;
169
+ const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
170
+ const subDataEncoded = subDataService.aaveV3InstantCloseGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage);
171
+ const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
177
172
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
178
173
  },
179
- debtSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
174
+ collateralSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, baseTokenAddress, quoteTokenAddress, price, state) {
180
175
  const isBundle = false;
181
- const subDataEncoded = subDataService.aaveV3DebtSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
176
+ const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
182
177
  const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
183
178
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
184
179
  },
@@ -732,6 +732,117 @@ describe('Feature: strategySubService.ts', () => {
732
732
  });
733
733
  });
734
734
  });
735
+ describe('instantCloseOnPriceGeneric()', () => {
736
+ const examples = [
737
+ // Stop loss only (to debt)
738
+ [
739
+ [
740
+ Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
741
+ true,
742
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
743
+ [
744
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
745
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
746
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
747
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
748
+ '0x0000000000000000000000000000000000000000000000000000000000000003',
749
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
750
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
751
+ '0x0000000000000000000000000000000000000000000000000de0b6b3a7640000',
752
+ '0x000000000000000000000000000000000000000000000000002386f26fc10000',
753
+ ],
754
+ ],
755
+ [
756
+ Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
757
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
758
+ 0,
759
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
760
+ 1,
761
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
762
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
763
+ '1000000000000000000',
764
+ '10000000000000000',
765
+ 1500,
766
+ CloseToAssetType.DEBT,
767
+ 0,
768
+ CloseToAssetType.COLLATERAL, // takeProfitType (not used since price is 0)
769
+ ]
770
+ ],
771
+ // Take profit only (to collateral), zero tsi and slippage
772
+ [
773
+ [
774
+ Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
775
+ true,
776
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
777
+ [
778
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
779
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
780
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
781
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
782
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
783
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
784
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
785
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
786
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
787
+ ],
788
+ ],
789
+ [
790
+ Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
791
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
792
+ 0,
793
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
794
+ 1,
795
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
796
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
797
+ '0',
798
+ '0',
799
+ 0,
800
+ CloseToAssetType.DEBT,
801
+ 5000,
802
+ CloseToAssetType.COLLATERAL, // takeProfitType
803
+ ]
804
+ ],
805
+ // Take profit (to debt) and stop loss (to collateral)
806
+ [
807
+ [
808
+ Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
809
+ true,
810
+ ['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
811
+ [
812
+ '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
813
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
814
+ '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
815
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
816
+ '0x0000000000000000000000000000000000000000000000000000000000000007',
817
+ '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
818
+ '0x0000000000000000000000001234567890123456789012345678901234567890',
819
+ '0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000',
820
+ '0x0000000000000000000000000000000000000000000000000011c37937e08000',
821
+ ],
822
+ ],
823
+ [
824
+ Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
825
+ web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
826
+ 0,
827
+ web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
828
+ 1,
829
+ web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
830
+ web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
831
+ '50000000000000000',
832
+ '5000000000000000',
833
+ 1500,
834
+ CloseToAssetType.COLLATERAL,
835
+ 4000,
836
+ CloseToAssetType.DEBT, // takeProfitType
837
+ ]
838
+ ],
839
+ ];
840
+ examples.forEach(([expected, actual]) => {
841
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
842
+ expect(aaveV3Encode.instantCloseOnPriceGeneric(...actual)).to.eql(expected);
843
+ });
844
+ });
845
+ });
735
846
  describe('collateralSwitch()', () => {
736
847
  const examples = [
737
848
  // WETH -> USDC, price 100000, state UNDER
@@ -831,113 +942,6 @@ describe('Feature: strategySubService.ts', () => {
831
942
  });
832
943
  });
833
944
  });
834
- describe('collateralSwitchGeneric()', () => {
835
- const strategyId = 12345;
836
- const fromAsset = web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address);
837
- const toAsset = web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address);
838
- const marketAddr = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
839
- const user = web3Utils.toChecksumAddress('0x1234567890abcdef1234567890abcdef12345678');
840
- const examples = [
841
- [
842
- RatioState.UNDER,
843
- '10000000000000000000',
844
- '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
845
- '0000000000000000000000000000000000000000000000000000000000000001',
846
- ],
847
- [
848
- RatioState.OVER,
849
- MAXUINT,
850
- '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
851
- '0000000000000000000000000000000000000000000000000000000000000000',
852
- ],
853
- ];
854
- examples.forEach(([state, amountToSwitch, encodedAmount, encodedState]) => {
855
- it(`encodes a generic collateral switch with the supplied quote pair and state ${state}`, () => {
856
- const expectedTrigger = `0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000003e8${encodedState}`;
857
- const expectedSubData = [
858
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
859
- '0x0000000000000000000000000000000000000000000000000000000000000100',
860
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
861
- '0x000000000000000000000000000000000000000000000000000000000000ffff',
862
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
863
- encodedAmount,
864
- '0x0000000000000000000000001234567890abcdef1234567890abcdef12345678',
865
- ];
866
- expect(aaveV3Encode.collateralSwitchGeneric(strategyId, fromAsset, 256, toAsset, 65535, marketAddr, amountToSwitch, user, toAsset, fromAsset, 0.00001, state)).to.eql([strategyId, false, [expectedTrigger], expectedSubData]);
867
- });
868
- });
869
- });
870
- describe('debtSwitch()', () => {
871
- const examples = [
872
- // USDC -> DAI, price 100000, state UNDER
873
- [
874
- [
875
- Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
876
- false,
877
- ['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
878
- [
879
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
880
- '0x0000000000000000000000000000000000000000000000000000000000000001',
881
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
882
- '0x0000000000000000000000000000000000000000000000000000000000000003',
883
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
884
- '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
885
- '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
886
- ],
887
- ],
888
- [
889
- Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
890
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
891
- 1,
892
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
893
- 3,
894
- web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
895
- '10000000000000000000',
896
- web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
897
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
898
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
899
- 100000,
900
- RatioState.UNDER,
901
- ]
902
- ],
903
- // DAI -> USDC (MaxUint256), price 1, state OVER
904
- [
905
- [
906
- Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
907
- false,
908
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000000'],
909
- [
910
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
911
- '0x0000000000000000000000000000000000000000000000000000000000000003',
912
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
913
- '0x0000000000000000000000000000000000000000000000000000000000000001',
914
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
915
- '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
916
- '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
917
- ],
918
- ],
919
- [
920
- Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
921
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
922
- 3,
923
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
924
- 1,
925
- web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
926
- MAXUINT,
927
- web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
928
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
929
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
930
- 1,
931
- RatioState.OVER,
932
- ]
933
- ],
934
- ];
935
- examples.forEach(([expected, actual]) => {
936
- it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
937
- expect(aaveV3Encode.debtSwitch(...actual)).to.eql(expected);
938
- });
939
- });
940
- });
941
945
  });
942
946
  describe('When testing strategySubService.compoundV3Encode', () => {
943
947
  describe('leverageManagementOnPrice()', () => {
@@ -248,31 +248,22 @@ export declare const aaveV3CloseGenericSubData: {
248
248
  owner: EthereumAddress;
249
249
  };
250
250
  };
251
- export declare const aaveV3CollateralSwitchSubData: {
252
- encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean): string[];
253
- decode(subData: string[]): {
254
- fromAsset: EthereumAddress;
255
- fromAssetId: number;
256
- toAsset: EthereumAddress;
257
- toAssetId: number;
258
- marketAddr: EthereumAddress;
259
- amountToSwitch: string;
260
- };
261
- };
262
- export declare const aaveV3GenericFLCollateralSwitchSubData: {
263
- encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress): string[];
251
+ export declare const aaveV3InstantCloseGenericSubData: {
252
+ encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, closeType: CloseStrategyType, marketAddr: EthereumAddress, user: EthereumAddress, tsi: string, slippage: string): string[];
264
253
  decode(subData: string[]): {
265
- fromAsset: EthereumAddress;
266
- fromAssetId: number;
267
- toAsset: EthereumAddress;
268
- toAssetId: number;
254
+ collAsset: EthereumAddress;
255
+ collAssetId: number;
256
+ debtAsset: EthereumAddress;
257
+ debtAssetId: number;
258
+ closeType: CloseStrategyType;
269
259
  marketAddr: EthereumAddress;
270
- amountToSwitch: string;
271
- user: EthereumAddress;
260
+ owner: EthereumAddress;
261
+ tsi: string;
262
+ slippage: string;
272
263
  };
273
264
  };
274
- export declare const aaveV3DebtSwitchSubData: {
275
- encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress): string[];
265
+ export declare const aaveV3CollateralSwitchSubData: {
266
+ encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, useOnBehalf?: boolean): string[];
276
267
  decode(subData: string[]): {
277
268
  fromAsset: EthereumAddress;
278
269
  fromAssetId: number;
@@ -280,7 +271,6 @@ export declare const aaveV3DebtSwitchSubData: {
280
271
  toAssetId: number;
281
272
  marketAddr: EthereumAddress;
282
273
  amountToSwitch: string;
283
- user: EthereumAddress;
284
274
  };
285
275
  };
286
276
  export declare const aaveV3QuotePriceSubData: {