@defisaver/automation-sdk 3.3.22-coll-switch-generic-dev → 3.3.22

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 (52) hide show
  1. package/cjs/automation/private/StrategiesAutomation.d.ts +5 -1
  2. package/cjs/automation/private/StrategiesAutomation.js +12 -0
  3. package/cjs/automation/private/StrategiesAutomation.test.js +51 -0
  4. package/cjs/constants/index.js +0 -60
  5. package/cjs/services/apiSubscriptionsService.d.ts +7 -0
  6. package/cjs/services/apiSubscriptionsService.js +33 -0
  7. package/cjs/services/apiSubscriptionsService.test.d.ts +1 -0
  8. package/cjs/services/apiSubscriptionsService.test.js +67 -0
  9. package/cjs/services/strategiesService.js +1 -21
  10. package/cjs/services/strategiesService.test.js +0 -93
  11. package/cjs/services/strategySubService.d.ts +0 -2
  12. package/cjs/services/strategySubService.js +0 -12
  13. package/cjs/services/strategySubService.test.js +0 -107
  14. package/cjs/services/subDataService.d.ts +0 -24
  15. package/cjs/services/subDataService.js +2 -66
  16. package/cjs/services/subDataService.test.js +0 -139
  17. package/cjs/types/enums.d.ts +4 -18
  18. package/cjs/types/enums.js +0 -14
  19. package/cjs/types/index.d.ts +24 -2
  20. package/esm/automation/private/StrategiesAutomation.d.ts +5 -1
  21. package/esm/automation/private/StrategiesAutomation.js +12 -0
  22. package/esm/automation/private/StrategiesAutomation.test.js +51 -0
  23. package/esm/constants/index.js +0 -60
  24. package/esm/services/apiSubscriptionsService.d.ts +7 -0
  25. package/esm/services/apiSubscriptionsService.js +29 -0
  26. package/esm/services/apiSubscriptionsService.test.d.ts +1 -0
  27. package/esm/services/apiSubscriptionsService.test.js +65 -0
  28. package/esm/services/strategiesService.js +1 -21
  29. package/esm/services/strategiesService.test.js +1 -94
  30. package/esm/services/strategySubService.d.ts +0 -2
  31. package/esm/services/strategySubService.js +0 -12
  32. package/esm/services/strategySubService.test.js +0 -107
  33. package/esm/services/subDataService.d.ts +0 -24
  34. package/esm/services/subDataService.js +0 -64
  35. package/esm/services/subDataService.test.js +0 -139
  36. package/esm/types/enums.d.ts +4 -18
  37. package/esm/types/enums.js +0 -14
  38. package/esm/types/index.d.ts +24 -2
  39. package/package.json +1 -1
  40. package/src/automation/private/StrategiesAutomation.test.ts +65 -1
  41. package/src/automation/private/StrategiesAutomation.ts +17 -0
  42. package/src/constants/index.ts +0 -60
  43. package/src/services/apiSubscriptionsService.test.ts +73 -0
  44. package/src/services/apiSubscriptionsService.ts +33 -0
  45. package/src/services/strategiesService.test.ts +1 -103
  46. package/src/services/strategiesService.ts +1 -23
  47. package/src/services/strategySubService.test.ts +0 -131
  48. package/src/services/strategySubService.ts +0 -46
  49. package/src/services/subDataService.test.ts +0 -149
  50. package/src/services/subDataService.ts +0 -101
  51. package/src/types/enums.ts +0 -14
  52. package/src/types/index.ts +26 -2
@@ -0,0 +1,65 @@
1
+ import { expect } from 'chai';
2
+ import { ChainId } from '../types/enums';
3
+ import '../configuration';
4
+ import { parseDataFromApiSubscription } from './apiSubscriptionsService';
5
+ import { parseStrategiesAutomatedPosition } from './strategiesService';
6
+ describe('Feature: apiSubscriptionsService.ts', () => {
7
+ describe('When testing apiSubscriptionsService.parseDataFromApiSubscription', () => {
8
+ // same subscription as in strategiesService.test.ts, in the shape the automation API returns it
9
+ const record = {
10
+ id: 379,
11
+ wallet: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
12
+ wallet_type: 'safe',
13
+ is_enabled: true,
14
+ is_bundle: true,
15
+ strategy_or_bundle_id: 8,
16
+ strategy_ids: [34, 35],
17
+ sub_data_hash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
18
+ trigger_data: [
19
+ '0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001',
20
+ ],
21
+ sub_data: [
22
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
23
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
24
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
25
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
26
+ ],
27
+ block_number: 18015756,
28
+ additional_triggers: null,
29
+ };
30
+ const fromEvents = {
31
+ chainId: ChainId.Ethereum,
32
+ blockNumber: 18015756,
33
+ subscriptionEventData: {
34
+ subId: '379',
35
+ proxy: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
36
+ subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
37
+ subStruct: {
38
+ strategyOrBundleId: '8',
39
+ isBundle: true,
40
+ triggerData: [
41
+ '0x0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001',
42
+ ],
43
+ subData: record.sub_data,
44
+ },
45
+ },
46
+ strategiesSubsData: {
47
+ userProxy: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
48
+ isEnabled: true,
49
+ strategySubHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
50
+ },
51
+ };
52
+ it('Given an API record should return the same parse data as Subscribe event and SubStorage would', () => {
53
+ expect(parseDataFromApiSubscription(record, ChainId.Ethereum)).to.eql(fromEvents);
54
+ });
55
+ it('Given an API record the parsed position should match the one parsed from events', () => {
56
+ const fromApi = parseStrategiesAutomatedPosition(parseDataFromApiSubscription(record, ChainId.Ethereum));
57
+ expect(fromApi).to.not.equal(null);
58
+ expect(fromApi).to.eql(parseStrategiesAutomatedPosition(fromEvents));
59
+ });
60
+ it('Given a disabled record should keep it disabled', () => {
61
+ const parseData = parseDataFromApiSubscription(Object.assign(Object.assign({}, record), { is_enabled: false }), ChainId.Ethereum);
62
+ expect(parseData.strategiesSubsData.isEnabled).to.equal(false);
63
+ });
64
+ });
65
+ });
@@ -318,29 +318,12 @@ function parseAaveV3CloseOnPrice(position, parseData) {
318
318
  return _position;
319
319
  }
320
320
  function parseAaveV3CollateralSwitch(position, parseData) {
321
- const _position = cloneDeep(position);
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);
328
- _position.strategyData.decoded.triggerData = triggerData;
329
- _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;
334
- return _position;
335
- }
336
- function parseAaveV3DebtSwitch(position, parseData) {
337
321
  const _position = cloneDeep(position);
338
322
  const { subStruct } = parseData.subscriptionEventData;
339
323
  const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
340
- const subData = subDataService.aaveV3DebtSwitchSubData.decode(subStruct.subData);
324
+ const subData = subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
341
325
  _position.strategyData.decoded.triggerData = triggerData;
342
326
  _position.strategyData.decoded.subData = subData;
343
- // TODO -> This isn't enough for ID
344
327
  _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
345
328
  return _position;
346
329
  }
@@ -1234,9 +1217,6 @@ const parsingMethodsMapping = {
1234
1217
  [Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
1235
1218
  [Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
1236
1219
  [Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
1237
- [Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV3CollateralSwitch,
1238
- [Strategies.Identifiers.DebtSwitch]: parseAaveV3DebtSwitch,
1239
- [Strategies.Identifiers.EoaDebtSwitch]: parseAaveV3DebtSwitch,
1240
1220
  [Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
1241
1221
  [Strategies.Identifiers.EoaLiquidationProtection]: parseAaveV3LiquidationProtection,
1242
1222
  },
@@ -8,102 +8,10 @@ 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';
11
+ import { ProtocolIdentifiers, Strategies } from '../types/enums';
12
12
  import '../configuration';
13
13
  import { parseStrategiesAutomatedPosition } from './strategiesService';
14
14
  describe('Feature: strategiesService.ts', () => {
15
- describe('When parsing Aave V3 collateral switch subscriptions', () => {
16
- const proxy = '0x9cB7E19861665366011899d74E75d4F2A419aEeD';
17
- const user = '0x1234567890123456789012345678901234567890';
18
- const fromAsset = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
19
- const toAsset = '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf';
20
- const marketAddr = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e';
21
- const amountToSwitch = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
22
- const subHash = `0x${'ab'.repeat(32)}`;
23
- const triggerData = [
24
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
25
- + '000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf'
26
- + '0000000000000000000000000000000000000000000000000000000000989680'
27
- + '0000000000000000000000000000000000000000000000000000000000000001',
28
- ];
29
- function getParseData(strategyId, isGeneric, chainId = ChainId.Ethereum) {
30
- const subData = [
31
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
32
- isGeneric
33
- ? '0x0000000000000000000000000000000000000000000000000000000000000100'
34
- : '0x0000000000000000000000000000000000000000000000000000000000000000',
35
- '0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
36
- isGeneric
37
- ? '0x000000000000000000000000000000000000000000000000000000000000ffff'
38
- : '0x0000000000000000000000000000000000000000000000000000000000000007',
39
- '0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
40
- '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
41
- isGeneric
42
- ? '0x0000000000000000000000001234567890123456789012345678901234567890'
43
- : '0x0000000000000000000000000000000000000000000000000000000000000000',
44
- ];
45
- const subStruct = Object.assign([String(strategyId), false, triggerData, subData], { strategyOrBundleId: String(strategyId), isBundle: false, triggerData, subData });
46
- return {
47
- chainId,
48
- blockNumber: 18015756,
49
- subscriptionEventData: {
50
- subId: '379', proxy, subHash, subStruct,
51
- 0: '379', 1: proxy, 2: subHash, 3: subStruct,
52
- },
53
- strategiesSubsData: {
54
- userProxy: proxy, isEnabled: true, strategySubHash: subHash,
55
- },
56
- };
57
- }
58
- const genericStrategies = [
59
- [ChainId.Ethereum, Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
60
- [ChainId.Optimism, Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
61
- [ChainId.Arbitrum, Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
62
- [ChainId.Base, Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH_EOA],
63
- ];
64
- genericStrategies.forEach(([chainId, strategyId]) => {
65
- it(`decodes generic collateral switches with the user and uint16 reserve IDs on chain ${chainId}`, () => {
66
- const parseData = getParseData(strategyId, true, chainId);
67
- const position = parseStrategiesAutomatedPosition(parseData);
68
- expect(position).not.to.equal(null);
69
- expect(position.protocol.id).to.equal(ProtocolIdentifiers.StrategiesAutomation.AaveV3);
70
- expect(position.strategy.strategyId).to.equal(Strategies.Identifiers.EoaCollateralSwitch);
71
- expect(position.strategy.isBundle).to.equal(false);
72
- expect(position.strategyData.encoded).to.eql({
73
- triggerData,
74
- subData: parseData.subscriptionEventData.subStruct.subData,
75
- });
76
- expect(position.strategyData.decoded.triggerData).to.eql({
77
- baseTokenAddress: fromAsset,
78
- quoteTokenAddress: toAsset,
79
- price: '0.1',
80
- ratioState: RatioState.UNDER,
81
- });
82
- expect(position.strategyData.decoded.subData).to.eql({
83
- fromAsset, fromAssetId: 256, toAsset, toAssetId: 65535, marketAddr, amountToSwitch, user,
84
- });
85
- expect(position.owner).to.equal(proxy.toLowerCase());
86
- expect(position.positionId).to.equal(`${chainId}-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
87
- });
88
- });
89
- const legacyStrategies = [
90
- [ChainId.Ethereum, Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH],
91
- [ChainId.Optimism, Strategies.OptimismIds.AAVE_V3_COLLATERAL_SWITCH],
92
- [ChainId.Arbitrum, Strategies.ArbitrumIds.AAVE_V3_COLLATERAL_SWITCH],
93
- [ChainId.Base, Strategies.BaseIds.AAVE_V3_COLLATERAL_SWITCH],
94
- ];
95
- legacyStrategies.forEach(([chainId, strategyId]) => {
96
- it(`continues to decode legacy collateral switches on chain ${chainId}`, () => {
97
- const position = parseStrategiesAutomatedPosition(getParseData(strategyId, false, chainId));
98
- expect(position).not.to.equal(null);
99
- expect(position.strategy.strategyId).to.equal(Strategies.Identifiers.CollateralSwitch);
100
- expect(position.strategyData.decoded.subData).to.eql({
101
- fromAsset, fromAssetId: 0, toAsset, toAssetId: 7, marketAddr, amountToSwitch,
102
- });
103
- expect(position.positionId).to.equal(`${chainId}-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
104
- });
105
- });
106
- });
107
15
  describe('When testing strategiesService.parseStrategiesAutomatedPosition', () => __awaiter(void 0, void 0, void 0, function* () {
108
16
  // TODO: we should probably write this for every strategy?
109
17
  const examples = [
@@ -173,7 +81,6 @@ describe('Feature: strategiesService.ts', () => {
173
81
  subId: '379',
174
82
  proxy: '0x9cb7e19861665366011899d74e75d4f2a419aeed',
175
83
  subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
176
- // @ts-ignore
177
84
  subStruct: {
178
85
  strategyOrBundleId: '8',
179
86
  isBundle: true,
@@ -62,8 +62,6 @@ export declare const aaveV3Encode: {
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
64
  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
65
  };
68
66
  export declare const compoundV2Encode: {
69
67
  leverageManagement(strategyOrBundleId: number, user: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
@@ -170,18 +170,6 @@ export const aaveV3Encode = {
170
170
  const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
171
171
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
172
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);
177
- return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
178
- },
179
- debtSwitch(strategyOrBundleId, fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user, baseTokenAddress, quoteTokenAddress, price, state) {
180
- const isBundle = false;
181
- const subDataEncoded = subDataService.aaveV3DebtSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user);
182
- const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
183
- return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
184
- },
185
173
  };
186
174
  export const compoundV2Encode = {
187
175
  leverageManagement(strategyOrBundleId, user, ratioState, targetRatio, triggerRatio) {
@@ -831,113 +831,6 @@ describe('Feature: strategySubService.ts', () => {
831
831
  });
832
832
  });
833
833
  });
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
834
  });
942
835
  describe('When testing strategySubService.compoundV3Encode', () => {
943
836
  describe('leverageManagementOnPrice()', () => {
@@ -259,30 +259,6 @@ export declare const aaveV3CollateralSwitchSubData: {
259
259
  amountToSwitch: string;
260
260
  };
261
261
  };
262
- export declare const aaveV3GenericFLCollateralSwitchSubData: {
263
- encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress): string[];
264
- decode(subData: string[]): {
265
- fromAsset: EthereumAddress;
266
- fromAssetId: number;
267
- toAsset: EthereumAddress;
268
- toAssetId: number;
269
- marketAddr: EthereumAddress;
270
- amountToSwitch: string;
271
- user: EthereumAddress;
272
- };
273
- };
274
- export declare const aaveV3DebtSwitchSubData: {
275
- encode(fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, marketAddr: EthereumAddress, amountToSwitch: string, user: EthereumAddress): string[];
276
- decode(subData: string[]): {
277
- fromAsset: EthereumAddress;
278
- fromAssetId: number;
279
- toAsset: EthereumAddress;
280
- toAssetId: number;
281
- marketAddr: EthereumAddress;
282
- amountToSwitch: string;
283
- user: EthereumAddress;
284
- };
285
- };
286
262
  export declare const aaveV3QuotePriceSubData: {
287
263
  encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, nullAddress?: EthereumAddress): string[];
288
264
  decode(subData: string[]): {
@@ -542,70 +542,6 @@ export const aaveV3CollateralSwitchSubData = {
542
542
  };
543
543
  },
544
544
  };
545
- export const aaveV3GenericFLCollateralSwitchSubData = {
546
- encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user) {
547
- const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
548
- const encodedFromAssetId = AbiCoder.encodeParameter('uint16', fromAssetId);
549
- const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
550
- const encodedToAssetId = AbiCoder.encodeParameter('uint16', toAssetId);
551
- const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
552
- const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
553
- const encodedUser = AbiCoder.encodeParameter('address', user);
554
- return [
555
- encodedFromAsset,
556
- encodedFromAssetId,
557
- encodedToAsset,
558
- encodedToAssetId,
559
- encodedMarketAddr,
560
- encodedAmountToSwitch,
561
- encodedUser,
562
- ];
563
- },
564
- decode(subData) {
565
- const fromAsset = AbiCoder.decodeParameter('address', subData[0]);
566
- const fromAssetId = Number(AbiCoder.decodeParameter('uint16', subData[1]));
567
- const toAsset = AbiCoder.decodeParameter('address', subData[2]);
568
- const toAssetId = Number(AbiCoder.decodeParameter('uint16', subData[3]));
569
- const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
570
- const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]);
571
- const user = AbiCoder.decodeParameter('address', subData[6]);
572
- return {
573
- fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
574
- };
575
- },
576
- };
577
- export const aaveV3DebtSwitchSubData = {
578
- encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user) {
579
- const encodedFromAsset = AbiCoder.encodeParameter('address', fromAsset);
580
- const encodedFromAssetId = AbiCoder.encodeParameter('uint8', fromAssetId);
581
- const encodedToAsset = AbiCoder.encodeParameter('address', toAsset);
582
- const encodedToAssetId = AbiCoder.encodeParameter('uint8', toAssetId);
583
- const encodedMarketAddr = AbiCoder.encodeParameter('address', marketAddr);
584
- const encodedAmountToSwitch = AbiCoder.encodeParameter('uint256', amountToSwitch);
585
- const encodedUser = AbiCoder.encodeParameter('address', user);
586
- return [
587
- encodedFromAsset,
588
- encodedFromAssetId,
589
- encodedToAsset,
590
- encodedToAssetId,
591
- encodedMarketAddr,
592
- encodedAmountToSwitch,
593
- encodedUser,
594
- ];
595
- },
596
- decode(subData) {
597
- const fromAsset = AbiCoder.decodeParameter('address', subData[0]);
598
- const fromAssetId = Number(AbiCoder.decodeParameter('uint8', subData[1]));
599
- const toAsset = AbiCoder.decodeParameter('address', subData[2]);
600
- const toAssetId = Number(AbiCoder.decodeParameter('uint8', subData[3]));
601
- const marketAddr = AbiCoder.decodeParameter('address', subData[4]);
602
- const amountToSwitch = AbiCoder.decodeParameter('uint256', subData[5]);
603
- const user = AbiCoder.decodeParameter('address', subData[6]);
604
- return {
605
- fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch, user,
606
- };
607
- },
608
- };
609
545
  export const aaveV3QuotePriceSubData = {
610
546
  encode(collAsset, collAssetId, debtAsset, debtAssetId, nullAddress = ZERO_ADDRESS) {
611
547
  const encodedColl = AbiCoder.encodeParameter('address', collAsset);
@@ -510,145 +510,6 @@ describe('Feature: subDataService.ts', () => {
510
510
  });
511
511
  });
512
512
  });
513
- describe('When testing subDataService.aaveV3DebtSwitchSubData', () => {
514
- describe('encode()', () => {
515
- const examples = [
516
- // USDC -> DAI
517
- [
518
- [
519
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
520
- '0x0000000000000000000000000000000000000000000000000000000000000001',
521
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
522
- '0x0000000000000000000000000000000000000000000000000000000000000003',
523
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
524
- '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
525
- '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
526
- ],
527
- [
528
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
529
- 1,
530
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
531
- 3,
532
- web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
533
- '10000000000000000000',
534
- web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
535
- ]
536
- ],
537
- // DAI -> USDC (MaxUint256)
538
- [
539
- [
540
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
541
- '0x0000000000000000000000000000000000000000000000000000000000000003',
542
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
543
- '0x0000000000000000000000000000000000000000000000000000000000000001',
544
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
545
- '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
546
- '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
547
- ],
548
- [
549
- web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
550
- 3,
551
- web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
552
- 1,
553
- web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
554
- MAXUINT,
555
- web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
556
- ]
557
- ],
558
- ];
559
- examples.forEach(([expected, actual]) => {
560
- it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
561
- expect(subDataService.aaveV3DebtSwitchSubData.encode(...actual)).to.eql(expected);
562
- });
563
- });
564
- });
565
- describe('decode()', () => {
566
- const examples = [
567
- // USDC -> DAI
568
- [
569
- {
570
- fromAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
571
- fromAssetId: 1,
572
- toAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
573
- toAssetId: 3,
574
- marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
575
- amountToSwitch: '10000000000000000000',
576
- user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
577
- },
578
- [
579
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
580
- '0x0000000000000000000000000000000000000000000000000000000000000001',
581
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
582
- '0x0000000000000000000000000000000000000000000000000000000000000003',
583
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
584
- '0x0000000000000000000000000000000000000000000000008ac7230489e80000',
585
- '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
586
- ],
587
- ],
588
- // DAI -> USDC (MaxUint256)
589
- [
590
- {
591
- fromAsset: web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
592
- fromAssetId: 3,
593
- toAsset: web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
594
- toAssetId: 1,
595
- marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
596
- amountToSwitch: MAXUINT,
597
- user: web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
598
- },
599
- [
600
- '0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
601
- '0x0000000000000000000000000000000000000000000000000000000000000003',
602
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
603
- '0x0000000000000000000000000000000000000000000000000000000000000001',
604
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
605
- '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
606
- '0x000000000000000000000000dd6ecd6c9b9f7e29e0f14bb9d5f0d0a3c6cb6c6a',
607
- ],
608
- ],
609
- ];
610
- examples.forEach(([expected, actual]) => {
611
- it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
612
- expect(subDataService.aaveV3DebtSwitchSubData.decode(actual)).to.eql(expected);
613
- });
614
- });
615
- });
616
- });
617
- describe('When testing subDataService.aaveV3GenericFLCollateralSwitchSubData', () => {
618
- const fromAsset = web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address);
619
- const toAsset = web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address);
620
- const marketAddr = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
621
- const user = web3Utils.toChecksumAddress('0x1234567890abcdef1234567890abcdef12345678');
622
- const examples = [
623
- ['10000000000000000000', '0x0000000000000000000000000000000000000000000000008ac7230489e80000'],
624
- [MAXUINT, '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'],
625
- ];
626
- examples.forEach(([amountToSwitch, encodedAmount]) => {
627
- const subData = [
628
- '0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
629
- '0x0000000000000000000000000000000000000000000000000000000000000100',
630
- '0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
631
- '0x000000000000000000000000000000000000000000000000000000000000ffff',
632
- '0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
633
- encodedAmount,
634
- '0x0000000000000000000000001234567890abcdef1234567890abcdef12345678',
635
- ];
636
- it(`encode() preserves uint16 asset IDs and user when switching ${amountToSwitch}`, () => {
637
- expect(subDataService.aaveV3GenericFLCollateralSwitchSubData.encode(fromAsset, 256, toAsset, 65535, marketAddr, amountToSwitch, user)).to.eql(subData);
638
- });
639
- it(`decode() preserves uint16 asset IDs and user when switching ${amountToSwitch}`, () => {
640
- expect(subDataService.aaveV3GenericFLCollateralSwitchSubData.decode(subData)).to.eql({
641
- fromAsset,
642
- fromAssetId: 256,
643
- toAsset,
644
- toAssetId: 65535,
645
- marketAddr,
646
- amountToSwitch,
647
- user,
648
- });
649
- });
650
- });
651
- });
652
513
  describe('When testing subDataService.sparkCollateralSwitchSubData', () => {
653
514
  describe('encode()', () => {
654
515
  const examples = [