@defisaver/automation-sdk 3.3.22-coll-switch-generic-dev → 3.3.22-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.
- package/cjs/constants/index.js +40 -60
- package/cjs/services/strategiesService.js +21 -16
- package/cjs/services/strategiesService.test.js +62 -92
- package/cjs/services/strategySubService.d.ts +1 -2
- package/cjs/services/strategySubService.js +7 -12
- package/cjs/services/strategySubService.test.js +111 -107
- package/cjs/services/subDataService.d.ts +12 -22
- package/cjs/services/subDataService.js +35 -61
- package/cjs/services/subDataService.test.js +70 -139
- package/cjs/types/enums.d.ts +18 -22
- package/cjs/types/enums.js +11 -14
- package/esm/constants/index.js +40 -60
- package/esm/services/strategiesService.js +21 -16
- package/esm/services/strategiesService.test.js +63 -93
- package/esm/services/strategySubService.d.ts +1 -2
- package/esm/services/strategySubService.js +7 -12
- package/esm/services/strategySubService.test.js +111 -107
- package/esm/services/subDataService.d.ts +12 -22
- package/esm/services/subDataService.js +33 -59
- package/esm/services/subDataService.test.js +70 -139
- package/esm/types/enums.d.ts +18 -22
- package/esm/types/enums.js +11 -14
- package/package.json +1 -1
- package/src/constants/index.ts +40 -60
- package/src/services/strategiesService.test.ts +78 -102
- package/src/services/strategiesService.ts +27 -16
- package/src/services/strategySubService.test.ts +125 -126
- package/src/services/strategySubService.ts +18 -38
- package/src/services/subDataService.test.ts +98 -149
- package/src/services/subDataService.ts +48 -88
- package/src/types/enums.ts +11 -14
|
@@ -1,113 +1,15 @@
|
|
|
1
1
|
import { expect } from 'chai';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
Bundles, CloseStrategyType, CloseToAssetType, ProtocolIdentifiers, Strategies,
|
|
5
|
+
} from '../types/enums';
|
|
4
6
|
import type { ParseData, Position } from '../types';
|
|
5
7
|
|
|
6
8
|
import '../configuration';
|
|
7
9
|
import { parseStrategiesAutomatedPosition } from './strategiesService';
|
|
10
|
+
import { aaveV3Encode } from './strategySubService';
|
|
8
11
|
|
|
9
12
|
describe('Feature: strategiesService.ts', () => {
|
|
10
|
-
describe('When parsing Aave V3 collateral switch subscriptions', () => {
|
|
11
|
-
const proxy = '0x9cB7E19861665366011899d74E75d4F2A419aEeD';
|
|
12
|
-
const user = '0x1234567890123456789012345678901234567890';
|
|
13
|
-
const fromAsset = '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2';
|
|
14
|
-
const toAsset = '0xcbB7C0000aB88B473b1f5aFd9ef808440eed33Bf';
|
|
15
|
-
const marketAddr = '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e';
|
|
16
|
-
const amountToSwitch = '115792089237316195423570985008687907853269984665640564039457584007913129639935';
|
|
17
|
-
const subHash = `0x${'ab'.repeat(32)}`;
|
|
18
|
-
const triggerData = [
|
|
19
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
|
|
20
|
-
+ '000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf'
|
|
21
|
-
+ '0000000000000000000000000000000000000000000000000000000000989680'
|
|
22
|
-
+ '0000000000000000000000000000000000000000000000000000000000000001',
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
function getParseData(strategyId: number, isGeneric: boolean, chainId = ChainId.Ethereum): ParseData {
|
|
26
|
-
const subData = [
|
|
27
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
28
|
-
isGeneric
|
|
29
|
-
? '0x0000000000000000000000000000000000000000000000000000000000000100'
|
|
30
|
-
: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
31
|
-
'0x000000000000000000000000cbb7c0000ab88b473b1f5afd9ef808440eed33bf',
|
|
32
|
-
isGeneric
|
|
33
|
-
? '0x000000000000000000000000000000000000000000000000000000000000ffff'
|
|
34
|
-
: '0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
35
|
-
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
36
|
-
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
37
|
-
isGeneric
|
|
38
|
-
? '0x0000000000000000000000001234567890123456789012345678901234567890'
|
|
39
|
-
: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
40
|
-
];
|
|
41
|
-
const subStruct = Object.assign(
|
|
42
|
-
[String(strategyId), false, triggerData, subData] as [string, boolean, string[], string[]],
|
|
43
|
-
{ strategyOrBundleId: String(strategyId), isBundle: false, triggerData, subData },
|
|
44
|
-
);
|
|
45
|
-
return {
|
|
46
|
-
chainId,
|
|
47
|
-
blockNumber: 18015756,
|
|
48
|
-
subscriptionEventData: {
|
|
49
|
-
subId: '379', proxy, subHash, subStruct,
|
|
50
|
-
0: '379', 1: proxy, 2: subHash, 3: subStruct,
|
|
51
|
-
},
|
|
52
|
-
strategiesSubsData: {
|
|
53
|
-
userProxy: proxy, isEnabled: true, strategySubHash: subHash,
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const genericStrategies: Array<[ChainId, number]> = [
|
|
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
|
-
|
|
69
|
-
expect(position).not.to.equal(null);
|
|
70
|
-
expect(position.protocol.id).to.equal(ProtocolIdentifiers.StrategiesAutomation.AaveV3);
|
|
71
|
-
expect(position.strategy.strategyId).to.equal(Strategies.Identifiers.EoaCollateralSwitch);
|
|
72
|
-
expect(position.strategy.isBundle).to.equal(false);
|
|
73
|
-
expect(position.strategyData.encoded).to.eql({
|
|
74
|
-
triggerData,
|
|
75
|
-
subData: parseData.subscriptionEventData.subStruct.subData,
|
|
76
|
-
});
|
|
77
|
-
expect(position.strategyData.decoded.triggerData).to.eql({
|
|
78
|
-
baseTokenAddress: fromAsset,
|
|
79
|
-
quoteTokenAddress: toAsset,
|
|
80
|
-
price: '0.1',
|
|
81
|
-
ratioState: RatioState.UNDER,
|
|
82
|
-
});
|
|
83
|
-
expect(position.strategyData.decoded.subData).to.eql({
|
|
84
|
-
fromAsset, fromAssetId: 256, toAsset, toAssetId: 65535, marketAddr, amountToSwitch, user,
|
|
85
|
-
});
|
|
86
|
-
expect(position.owner).to.equal(proxy.toLowerCase());
|
|
87
|
-
expect(position.positionId).to.equal(`${chainId}-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const legacyStrategies: Array<[ChainId, number]> = [
|
|
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
|
-
|
|
101
|
-
expect(position).not.to.equal(null);
|
|
102
|
-
expect(position.strategy.strategyId).to.equal(Strategies.Identifiers.CollateralSwitch);
|
|
103
|
-
expect(position.strategyData.decoded.subData).to.eql({
|
|
104
|
-
fromAsset, fromAssetId: 0, toAsset, toAssetId: 7, marketAddr, amountToSwitch,
|
|
105
|
-
});
|
|
106
|
-
expect(position.positionId).to.equal(`${chainId}-aave__v3-${proxy.toLowerCase()}-${marketAddr.toLowerCase()}`);
|
|
107
|
-
});
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
13
|
describe('When testing strategiesService.parseStrategiesAutomatedPosition', async () => {
|
|
112
14
|
// TODO: we should probably write this for every strategy?
|
|
113
15
|
const examples: Array<[Position.Automated | null, ParseData]> = [
|
|
@@ -204,4 +106,78 @@ describe('Feature: strategiesService.ts', () => {
|
|
|
204
106
|
});
|
|
205
107
|
});
|
|
206
108
|
});
|
|
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
|
+
|
|
116
|
+
const bundles: Array<[string, Bundles.MainnetIds, Strategies.Identifiers]> = [
|
|
117
|
+
['SW', Bundles.MainnetIds.AAVE_V3_SW_INSTANT_CLOSE, Strategies.Identifiers.InstantCloseOnPrice],
|
|
118
|
+
['EOA', Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE, Strategies.Identifiers.EoaInstantCloseOnPrice],
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
bundles.forEach(([walletType, expectedBundleId, expectedStrategyId]) => {
|
|
122
|
+
describe(`${walletType} bundle`, () => {
|
|
123
|
+
const [bundleId, isBundle, triggerData, subData] = aaveV3Encode.instantCloseOnPriceGeneric(
|
|
124
|
+
expectedBundleId,
|
|
125
|
+
weth, 0, usdc, 1, market, owner,
|
|
126
|
+
'1000000000000000000', '10000000000000000',
|
|
127
|
+
1500, CloseToAssetType.DEBT, 5000, CloseToAssetType.COLLATERAL,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const parseData = {
|
|
131
|
+
chainId: 1,
|
|
132
|
+
blockNumber: 1,
|
|
133
|
+
subscriptionEventData: {
|
|
134
|
+
subId: '1',
|
|
135
|
+
proxy: owner,
|
|
136
|
+
subHash: '0xhash',
|
|
137
|
+
subStruct: {
|
|
138
|
+
strategyOrBundleId: String(bundleId), isBundle, triggerData, subData,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
strategiesSubsData: { userProxy: owner, isEnabled: true, strategySubHash: '0xhash' },
|
|
142
|
+
} as unknown as ParseData;
|
|
143
|
+
|
|
144
|
+
const result = parseStrategiesAutomatedPosition(parseData) as Position.Automated;
|
|
145
|
+
|
|
146
|
+
it('should identify the strategy as instant close on price', () => {
|
|
147
|
+
expect(result.strategy.strategyOrBundleId).to.equal(expectedBundleId);
|
|
148
|
+
expect(result.strategy.strategyId).to.equal(expectedStrategyId);
|
|
149
|
+
expect(result.protocol.id).to.equal(ProtocolIdentifiers.StrategiesAutomation.AaveV3);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('should decode sub data including tsi and slippage', () => {
|
|
153
|
+
expect(result.strategyData.decoded.subData).to.eql({
|
|
154
|
+
collAsset: weth,
|
|
155
|
+
collAssetId: 0,
|
|
156
|
+
debtAsset: usdc,
|
|
157
|
+
debtAssetId: 1,
|
|
158
|
+
closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
|
|
159
|
+
marketAddr: market,
|
|
160
|
+
owner,
|
|
161
|
+
tsi: '1000000000000000000',
|
|
162
|
+
slippage: '10000000000000000',
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('should fill specific with prices and close types', () => {
|
|
167
|
+
expect(result.specific).to.eql({
|
|
168
|
+
collAsset: weth,
|
|
169
|
+
collAssetId: 0,
|
|
170
|
+
debtAsset: usdc,
|
|
171
|
+
debtAssetId: 1,
|
|
172
|
+
baseToken: weth,
|
|
173
|
+
quoteToken: usdc,
|
|
174
|
+
stopLossPrice: '1500',
|
|
175
|
+
takeProfitPrice: '5000',
|
|
176
|
+
stopLossType: CloseToAssetType.DEBT,
|
|
177
|
+
takeProfitType: CloseToAssetType.COLLATERAL,
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
});
|
|
207
183
|
});
|
|
@@ -433,32 +433,44 @@ function parseAaveV3CloseOnPrice(position: Position.Automated, parseData: ParseD
|
|
|
433
433
|
return _position;
|
|
434
434
|
}
|
|
435
435
|
|
|
436
|
-
function
|
|
436
|
+
function parseAaveV3InstantCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
437
437
|
const _position = cloneDeep(position);
|
|
438
|
+
|
|
438
439
|
const { subStruct } = parseData.subscriptionEventData;
|
|
439
|
-
|
|
440
|
-
const triggerData = triggerService.
|
|
441
|
-
const subData =
|
|
442
|
-
|
|
443
|
-
|
|
440
|
+
|
|
441
|
+
const triggerData = triggerService.aaveV3QuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
442
|
+
const subData = subDataService.aaveV3InstantCloseGenericSubData.decode(subStruct.subData);
|
|
443
|
+
|
|
444
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
445
|
+
|
|
446
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
447
|
+
|
|
444
448
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
445
449
|
_position.strategyData.decoded.subData = subData;
|
|
446
|
-
|
|
447
|
-
_position.
|
|
448
|
-
|
|
449
|
-
:
|
|
450
|
+
|
|
451
|
+
_position.specific = {
|
|
452
|
+
collAsset: subData.collAsset,
|
|
453
|
+
collAssetId: subData.collAssetId,
|
|
454
|
+
debtAsset: subData.debtAsset,
|
|
455
|
+
debtAssetId: subData.debtAssetId,
|
|
456
|
+
baseToken: triggerData.collToken,
|
|
457
|
+
quoteToken: triggerData.debtToken,
|
|
458
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
459
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
460
|
+
stopLossType,
|
|
461
|
+
takeProfitType,
|
|
462
|
+
};
|
|
450
463
|
|
|
451
464
|
return _position;
|
|
452
465
|
}
|
|
453
466
|
|
|
454
|
-
function
|
|
467
|
+
function parseAaveV3CollateralSwitch(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
455
468
|
const _position = cloneDeep(position);
|
|
456
469
|
const { subStruct } = parseData.subscriptionEventData;
|
|
457
470
|
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
458
|
-
const subData = subDataService.
|
|
471
|
+
const subData = subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
|
|
459
472
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
460
473
|
_position.strategyData.decoded.subData = subData;
|
|
461
|
-
// TODO -> This isn't enough for ID
|
|
462
474
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
463
475
|
|
|
464
476
|
return _position;
|
|
@@ -1615,10 +1627,9 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
1615
1627
|
[Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1616
1628
|
[Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1617
1629
|
[Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
1630
|
+
[Strategies.Identifiers.InstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
|
|
1631
|
+
[Strategies.Identifiers.EoaInstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
|
|
1618
1632
|
[Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1619
|
-
[Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1620
|
-
[Strategies.Identifiers.DebtSwitch]: parseAaveV3DebtSwitch,
|
|
1621
|
-
[Strategies.Identifiers.EoaDebtSwitch]: parseAaveV3DebtSwitch,
|
|
1622
1633
|
[Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
1623
1634
|
[Strategies.Identifiers.EoaLiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
1624
1635
|
},
|
|
@@ -887,165 +887,137 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
887
887
|
});
|
|
888
888
|
});
|
|
889
889
|
|
|
890
|
-
describe('
|
|
890
|
+
describe('instantCloseOnPriceGeneric()', () => {
|
|
891
891
|
const examples: Array<[
|
|
892
892
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
893
893
|
[
|
|
894
894
|
strategyOrBundleId: number,
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
895
|
+
collAsset: EthereumAddress,
|
|
896
|
+
collAssetId: number,
|
|
897
|
+
debtAsset: EthereumAddress,
|
|
898
|
+
debtAssetId: number,
|
|
899
899
|
marketAddr: EthereumAddress,
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
900
|
+
user: EthereumAddress,
|
|
901
|
+
tsi: string,
|
|
902
|
+
slippage: string,
|
|
903
|
+
stopLossPrice: number,
|
|
904
|
+
stopLossType: CloseToAssetType,
|
|
905
|
+
takeProfitPrice: number,
|
|
906
|
+
takeProfitType: CloseToAssetType
|
|
905
907
|
]
|
|
906
908
|
]> = [
|
|
907
|
-
//
|
|
909
|
+
// Stop loss only (to debt)
|
|
908
910
|
[
|
|
909
911
|
[
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
['
|
|
912
|
+
Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
|
|
913
|
+
true,
|
|
914
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000000000000000'],
|
|
913
915
|
[
|
|
914
916
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
915
917
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
916
918
|
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
917
919
|
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
918
|
-
'
|
|
919
|
-
'
|
|
920
|
-
'
|
|
920
|
+
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
921
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
922
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
923
|
+
'0x0000000000000000000000000000000000000000000000000de0b6b3a7640000',
|
|
924
|
+
'0x000000000000000000000000000000000000000000000000002386f26fc10000',
|
|
921
925
|
],
|
|
922
926
|
],
|
|
923
927
|
[
|
|
924
|
-
|
|
928
|
+
Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
|
|
925
929
|
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
926
930
|
0,
|
|
927
931
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
928
932
|
1,
|
|
929
|
-
web3Utils.toChecksumAddress('
|
|
930
|
-
'
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
933
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
934
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
935
|
+
'1000000000000000000', // tsi
|
|
936
|
+
'10000000000000000', // slippage
|
|
937
|
+
1500, // stopLossPrice
|
|
938
|
+
CloseToAssetType.DEBT, // stopLossType
|
|
939
|
+
0, // takeProfitPrice
|
|
940
|
+
CloseToAssetType.COLLATERAL, // takeProfitType (not used since price is 0)
|
|
935
941
|
]
|
|
936
942
|
],
|
|
937
|
-
//
|
|
943
|
+
// Take profit only (to collateral), zero tsi and slippage
|
|
938
944
|
[
|
|
939
945
|
[
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
['
|
|
946
|
+
Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
|
|
947
|
+
true,
|
|
948
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
943
949
|
[
|
|
950
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
951
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
944
952
|
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
945
953
|
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
946
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
947
954
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
948
|
-
'
|
|
949
|
-
'
|
|
955
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
956
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
957
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
950
958
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
951
959
|
],
|
|
952
960
|
],
|
|
953
961
|
[
|
|
954
|
-
|
|
955
|
-
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
956
|
-
1,
|
|
962
|
+
Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
|
|
957
963
|
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
958
964
|
0,
|
|
959
|
-
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
960
|
-
MAXUINT, // MaxUint256
|
|
961
965
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
966
|
+
1,
|
|
967
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
968
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
969
|
+
'0', // tsi
|
|
970
|
+
'0', // slippage
|
|
971
|
+
0, // stopLossPrice
|
|
972
|
+
CloseToAssetType.DEBT, // stopLossType (not used since price is 0)
|
|
973
|
+
5000, // takeProfitPrice
|
|
974
|
+
CloseToAssetType.COLLATERAL, // takeProfitType
|
|
965
975
|
]
|
|
966
976
|
],
|
|
967
|
-
//
|
|
977
|
+
// Take profit (to debt) and stop loss (to collateral)
|
|
968
978
|
[
|
|
969
979
|
[
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
['
|
|
980
|
+
Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
|
|
981
|
+
true,
|
|
982
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
973
983
|
[
|
|
974
984
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
975
985
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
976
|
-
'
|
|
977
|
-
'
|
|
978
|
-
'
|
|
979
|
-
'
|
|
980
|
-
'
|
|
986
|
+
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
987
|
+
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
988
|
+
'0x0000000000000000000000000000000000000000000000000000000000000007',
|
|
989
|
+
'0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e',
|
|
990
|
+
'0x0000000000000000000000001234567890123456789012345678901234567890',
|
|
991
|
+
'0x00000000000000000000000000000000000000000000000000b1a2bc2ec50000',
|
|
992
|
+
'0x0000000000000000000000000000000000000000000000000011c37937e08000',
|
|
981
993
|
],
|
|
982
994
|
],
|
|
983
995
|
[
|
|
984
|
-
|
|
996
|
+
Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
|
|
985
997
|
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
986
998
|
0,
|
|
987
|
-
web3Utils.toChecksumAddress(getAssetInfo('
|
|
988
|
-
2,
|
|
989
|
-
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
990
|
-
'5000000000000000000', // 5 WETH
|
|
991
|
-
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
992
|
-
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
999
|
+
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
993
1000
|
1,
|
|
994
|
-
|
|
1001
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1002
|
+
web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1003
|
+
'50000000000000000', // tsi
|
|
1004
|
+
'5000000000000000', // slippage
|
|
1005
|
+
1500, // stopLossPrice
|
|
1006
|
+
CloseToAssetType.COLLATERAL, // stopLossType
|
|
1007
|
+
4000, // takeProfitPrice
|
|
1008
|
+
CloseToAssetType.DEBT, // takeProfitType
|
|
995
1009
|
]
|
|
996
1010
|
],
|
|
997
1011
|
];
|
|
998
1012
|
|
|
999
1013
|
examples.forEach(([expected, actual]) => {
|
|
1000
1014
|
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1001
|
-
expect(aaveV3Encode.
|
|
1002
|
-
});
|
|
1003
|
-
});
|
|
1004
|
-
});
|
|
1005
|
-
|
|
1006
|
-
describe('collateralSwitchGeneric()', () => {
|
|
1007
|
-
const strategyId = 12345;
|
|
1008
|
-
const fromAsset = web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address);
|
|
1009
|
-
const toAsset = web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address);
|
|
1010
|
-
const marketAddr = web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39');
|
|
1011
|
-
const user = web3Utils.toChecksumAddress('0x1234567890abcdef1234567890abcdef12345678');
|
|
1012
|
-
const examples: Array<[RatioState, string, string, string]> = [
|
|
1013
|
-
[
|
|
1014
|
-
RatioState.UNDER,
|
|
1015
|
-
'10000000000000000000',
|
|
1016
|
-
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
1017
|
-
'0000000000000000000000000000000000000000000000000000000000000001',
|
|
1018
|
-
],
|
|
1019
|
-
[
|
|
1020
|
-
RatioState.OVER,
|
|
1021
|
-
MAXUINT,
|
|
1022
|
-
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
1023
|
-
'0000000000000000000000000000000000000000000000000000000000000000',
|
|
1024
|
-
],
|
|
1025
|
-
];
|
|
1026
|
-
|
|
1027
|
-
examples.forEach(([state, amountToSwitch, encodedAmount, encodedState]) => {
|
|
1028
|
-
it(`encodes a generic collateral switch with the supplied quote pair and state ${state}`, () => {
|
|
1029
|
-
const expectedTrigger = `0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000003e8${encodedState}`;
|
|
1030
|
-
const expectedSubData: SubData = [
|
|
1031
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1032
|
-
'0x0000000000000000000000000000000000000000000000000000000000000100',
|
|
1033
|
-
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1034
|
-
'0x000000000000000000000000000000000000000000000000000000000000ffff',
|
|
1035
|
-
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1036
|
-
encodedAmount,
|
|
1037
|
-
'0x0000000000000000000000001234567890abcdef1234567890abcdef12345678',
|
|
1038
|
-
];
|
|
1039
|
-
|
|
1040
|
-
expect(aaveV3Encode.collateralSwitchGeneric(
|
|
1041
|
-
strategyId, fromAsset, 256, toAsset, 65535, marketAddr, amountToSwitch, user,
|
|
1042
|
-
toAsset, fromAsset, 0.00001, state,
|
|
1043
|
-
)).to.eql([strategyId, false, [expectedTrigger], expectedSubData]);
|
|
1015
|
+
expect(aaveV3Encode.instantCloseOnPriceGeneric(...actual)).to.eql(expected);
|
|
1044
1016
|
});
|
|
1045
1017
|
});
|
|
1046
1018
|
});
|
|
1047
1019
|
|
|
1048
|
-
describe('
|
|
1020
|
+
describe('collateralSwitch()', () => {
|
|
1049
1021
|
const examples: Array<[
|
|
1050
1022
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1051
1023
|
[
|
|
@@ -1056,80 +1028,107 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1056
1028
|
toAssetId: number,
|
|
1057
1029
|
marketAddr: EthereumAddress,
|
|
1058
1030
|
amountToSwitch: string,
|
|
1059
|
-
user: EthereumAddress,
|
|
1060
1031
|
baseTokenAddress: EthereumAddress,
|
|
1061
1032
|
quoteTokenAddress: EthereumAddress,
|
|
1062
1033
|
price: number,
|
|
1063
1034
|
state: RatioState,
|
|
1064
1035
|
]
|
|
1065
1036
|
]> = [
|
|
1066
|
-
//
|
|
1037
|
+
// WETH -> USDC, price 100000, state UNDER
|
|
1067
1038
|
[
|
|
1068
1039
|
[
|
|
1069
|
-
Strategies.MainnetIds.
|
|
1040
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1070
1041
|
false,
|
|
1071
|
-
['
|
|
1042
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1072
1043
|
[
|
|
1044
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1045
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1073
1046
|
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1074
1047
|
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1075
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1076
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
1077
1048
|
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1078
1049
|
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
1079
|
-
'
|
|
1050
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1080
1051
|
],
|
|
1081
1052
|
],
|
|
1082
1053
|
[
|
|
1083
|
-
Strategies.MainnetIds.
|
|
1054
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1055
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1056
|
+
0,
|
|
1084
1057
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1085
1058
|
1,
|
|
1086
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1087
|
-
3,
|
|
1088
1059
|
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1089
|
-
'10000000000000000000', // 10
|
|
1090
|
-
web3Utils.toChecksumAddress('
|
|
1060
|
+
'10000000000000000000', // 10 WETH
|
|
1061
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1091
1062
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1092
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1093
1063
|
100000,
|
|
1094
1064
|
RatioState.UNDER,
|
|
1095
1065
|
]
|
|
1096
1066
|
],
|
|
1097
|
-
//
|
|
1067
|
+
// USDC -> WETH, price 0.00001, state OVER
|
|
1098
1068
|
[
|
|
1099
1069
|
[
|
|
1100
|
-
Strategies.MainnetIds.
|
|
1070
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1101
1071
|
false,
|
|
1102
|
-
['
|
|
1072
|
+
['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000000'],
|
|
1103
1073
|
[
|
|
1104
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1105
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
1106
1074
|
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1107
1075
|
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1076
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1077
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1108
1078
|
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1109
1079
|
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
1110
|
-
'
|
|
1080
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1111
1081
|
],
|
|
1112
1082
|
],
|
|
1113
1083
|
[
|
|
1114
|
-
Strategies.MainnetIds.
|
|
1115
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1116
|
-
3,
|
|
1084
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1117
1085
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1118
1086
|
1,
|
|
1087
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1088
|
+
0,
|
|
1119
1089
|
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1120
1090
|
MAXUINT, // MaxUint256
|
|
1121
|
-
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
1122
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1123
1091
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1124
|
-
|
|
1092
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1093
|
+
0.00001,
|
|
1125
1094
|
RatioState.OVER,
|
|
1126
1095
|
]
|
|
1127
1096
|
],
|
|
1097
|
+
// WETH -> WBTC, price 1, state UNDER
|
|
1098
|
+
[
|
|
1099
|
+
[
|
|
1100
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1101
|
+
false,
|
|
1102
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c5990000000000000000000000000000000000000000000000000000000005f5e1000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1103
|
+
[
|
|
1104
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1105
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1106
|
+
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
1107
|
+
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
1108
|
+
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1109
|
+
'0x0000000000000000000000000000000000000000000000004563918244f40000',
|
|
1110
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1111
|
+
],
|
|
1112
|
+
],
|
|
1113
|
+
[
|
|
1114
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1115
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1116
|
+
0,
|
|
1117
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1118
|
+
2,
|
|
1119
|
+
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1120
|
+
'5000000000000000000', // 5 WETH
|
|
1121
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1122
|
+
web3Utils.toChecksumAddress(getAssetInfo('WBTC', ChainId.Ethereum).address),
|
|
1123
|
+
1,
|
|
1124
|
+
RatioState.UNDER,
|
|
1125
|
+
]
|
|
1126
|
+
],
|
|
1128
1127
|
];
|
|
1129
1128
|
|
|
1130
1129
|
examples.forEach(([expected, actual]) => {
|
|
1131
1130
|
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1132
|
-
expect(aaveV3Encode.
|
|
1131
|
+
expect(aaveV3Encode.collateralSwitch(...actual)).to.eql(expected);
|
|
1133
1132
|
});
|
|
1134
1133
|
});
|
|
1135
1134
|
});
|