@defisaver/automation-sdk 3.3.21-debt-switch-dev-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.
- package/cjs/constants/index.js +10 -40
- package/cjs/services/strategiesService.js +21 -9
- package/cjs/services/strategiesService.test.js +62 -0
- package/cjs/services/strategySubService.d.ts +1 -1
- package/cjs/services/strategySubService.js +7 -6
- package/cjs/services/strategySubService.test.js +111 -71
- package/cjs/services/subDataService.d.ts +12 -10
- package/cjs/services/subDataService.js +36 -30
- package/cjs/services/subDataService.test.js +70 -104
- package/cjs/types/enums.d.ts +9 -15
- package/cjs/types/enums.js +4 -10
- package/esm/constants/index.js +10 -40
- package/esm/services/strategiesService.js +21 -9
- package/esm/services/strategiesService.test.js +63 -1
- package/esm/services/strategySubService.d.ts +1 -1
- package/esm/services/strategySubService.js +7 -6
- package/esm/services/strategySubService.test.js +111 -71
- package/esm/services/subDataService.d.ts +12 -10
- package/esm/services/subDataService.js +35 -29
- package/esm/services/subDataService.test.js +70 -104
- package/esm/types/enums.d.ts +9 -15
- package/esm/types/enums.js +4 -10
- package/package.json +1 -1
- package/src/constants/index.ts +10 -40
- package/src/services/strategiesService.test.ts +78 -1
- package/src/services/strategiesService.ts +27 -9
- package/src/services/strategySubService.test.ts +125 -84
- package/src/services/strategySubService.ts +20 -16
- package/src/services/subDataService.test.ts +98 -108
- package/src/services/subDataService.ts +51 -40
- package/src/types/enums.ts +4 -10
package/package.json
CHANGED
package/src/constants/index.ts
CHANGED
|
@@ -145,16 +145,6 @@ export const MAINNET_STRATEGIES_INFO: MainnetStrategiesInfo = {
|
|
|
145
145
|
strategyId: Strategies.Identifiers.EoaCollateralSwitch,
|
|
146
146
|
protocol: PROTOCOLS.Spark,
|
|
147
147
|
},
|
|
148
|
-
[Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH]: {
|
|
149
|
-
strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH,
|
|
150
|
-
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
151
|
-
protocol: PROTOCOLS.AaveV3,
|
|
152
|
-
},
|
|
153
|
-
[Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
154
|
-
strategyOrBundleId: Strategies.MainnetIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
155
|
-
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
156
|
-
protocol: PROTOCOLS.AaveV3,
|
|
157
|
-
},
|
|
158
148
|
};
|
|
159
149
|
|
|
160
150
|
export const OPTIMISM_STRATEGIES_INFO: OptimismStrategiesInfo = {
|
|
@@ -173,16 +163,6 @@ export const OPTIMISM_STRATEGIES_INFO: OptimismStrategiesInfo = {
|
|
|
173
163
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
174
164
|
protocol: PROTOCOLS.AaveV3,
|
|
175
165
|
},
|
|
176
|
-
[Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH]: {
|
|
177
|
-
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH,
|
|
178
|
-
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
179
|
-
protocol: PROTOCOLS.AaveV3,
|
|
180
|
-
},
|
|
181
|
-
[Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
182
|
-
strategyOrBundleId: Strategies.OptimismIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
183
|
-
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
184
|
-
protocol: PROTOCOLS.AaveV3,
|
|
185
|
-
},
|
|
186
166
|
};
|
|
187
167
|
|
|
188
168
|
export const BASE_STRATEGIES_INFO: BaseStrategiesInfo = {
|
|
@@ -201,16 +181,6 @@ export const BASE_STRATEGIES_INFO: BaseStrategiesInfo = {
|
|
|
201
181
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
202
182
|
protocol: PROTOCOLS.AaveV3,
|
|
203
183
|
},
|
|
204
|
-
[Strategies.BaseIds.AAVE_V3_DEBT_SWITCH]: {
|
|
205
|
-
strategyOrBundleId: Strategies.BaseIds.AAVE_V3_DEBT_SWITCH,
|
|
206
|
-
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
207
|
-
protocol: PROTOCOLS.AaveV3,
|
|
208
|
-
},
|
|
209
|
-
[Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
210
|
-
strategyOrBundleId: Strategies.BaseIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
211
|
-
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
212
|
-
protocol: PROTOCOLS.AaveV3,
|
|
213
|
-
},
|
|
214
184
|
};
|
|
215
185
|
|
|
216
186
|
export const ARBITRUM_STRATEGIES_INFO: ArbitrumStrategiesInfo = {
|
|
@@ -229,16 +199,6 @@ export const ARBITRUM_STRATEGIES_INFO: ArbitrumStrategiesInfo = {
|
|
|
229
199
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
230
200
|
protocol: PROTOCOLS.AaveV3,
|
|
231
201
|
},
|
|
232
|
-
[Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH]: {
|
|
233
|
-
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH,
|
|
234
|
-
strategyId: Strategies.Identifiers.DebtSwitch,
|
|
235
|
-
protocol: PROTOCOLS.AaveV3,
|
|
236
|
-
},
|
|
237
|
-
[Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA]: {
|
|
238
|
-
strategyOrBundleId: Strategies.ArbitrumIds.AAVE_V3_DEBT_SWITCH_EOA,
|
|
239
|
-
strategyId: Strategies.Identifiers.EoaDebtSwitch,
|
|
240
|
-
protocol: PROTOCOLS.AaveV3,
|
|
241
|
-
},
|
|
242
202
|
};
|
|
243
203
|
|
|
244
204
|
export const STRATEGIES_INFO: StrategiesInfo = {
|
|
@@ -724,6 +684,16 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
|
|
|
724
684
|
strategyId: Strategies.Identifiers.EoaLiquidationProtection,
|
|
725
685
|
protocol: PROTOCOLS.Spark,
|
|
726
686
|
},
|
|
687
|
+
[Bundles.MainnetIds.AAVE_V3_SW_INSTANT_CLOSE]: {
|
|
688
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_SW_INSTANT_CLOSE,
|
|
689
|
+
strategyId: Strategies.Identifiers.InstantCloseOnPrice,
|
|
690
|
+
protocol: PROTOCOLS.AaveV3,
|
|
691
|
+
},
|
|
692
|
+
[Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE]: {
|
|
693
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_EOA_INSTANT_CLOSE,
|
|
694
|
+
strategyId: Strategies.Identifiers.EoaInstantCloseOnPrice,
|
|
695
|
+
protocol: PROTOCOLS.AaveV3,
|
|
696
|
+
},
|
|
727
697
|
};
|
|
728
698
|
|
|
729
699
|
export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
|
|
@@ -1,10 +1,13 @@
|
|
|
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
13
|
describe('When testing strategiesService.parseStrategiesAutomatedPosition', async () => {
|
|
@@ -103,4 +106,78 @@ describe('Feature: strategiesService.ts', () => {
|
|
|
103
106
|
});
|
|
104
107
|
});
|
|
105
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
|
+
});
|
|
106
183
|
});
|
|
@@ -433,26 +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
|
|
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
|
+
|
|
441
448
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
442
449
|
_position.strategyData.decoded.subData = subData;
|
|
443
|
-
|
|
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
|
+
};
|
|
444
463
|
|
|
445
464
|
return _position;
|
|
446
465
|
}
|
|
447
466
|
|
|
448
|
-
function
|
|
467
|
+
function parseAaveV3CollateralSwitch(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
449
468
|
const _position = cloneDeep(position);
|
|
450
469
|
const { subStruct } = parseData.subscriptionEventData;
|
|
451
470
|
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
452
|
-
const subData = subDataService.
|
|
471
|
+
const subData = subDataService.aaveV3CollateralSwitchSubData.decode(subStruct.subData);
|
|
453
472
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
454
473
|
_position.strategyData.decoded.subData = subData;
|
|
455
|
-
// TODO -> This isn't enough for ID
|
|
456
474
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
457
475
|
|
|
458
476
|
return _position;
|
|
@@ -1609,9 +1627,9 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
1609
1627
|
[Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1610
1628
|
[Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1611
1629
|
[Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
1630
|
+
[Strategies.Identifiers.InstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
|
|
1631
|
+
[Strategies.Identifiers.EoaInstantCloseOnPrice]: parseAaveV3InstantCloseOnPrice,
|
|
1612
1632
|
[Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1613
|
-
[Strategies.Identifiers.DebtSwitch]: parseAaveV3DebtSwitch,
|
|
1614
|
-
[Strategies.Identifiers.EoaDebtSwitch]: parseAaveV3DebtSwitch,
|
|
1615
1633
|
[Strategies.Identifiers.LiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
1616
1634
|
[Strategies.Identifiers.EoaLiquidationProtection]: parseAaveV3LiquidationProtection,
|
|
1617
1635
|
},
|
|
@@ -887,123 +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.
|
|
1015
|
+
expect(aaveV3Encode.instantCloseOnPriceGeneric(...actual)).to.eql(expected);
|
|
1002
1016
|
});
|
|
1003
1017
|
});
|
|
1004
1018
|
});
|
|
1005
1019
|
|
|
1006
|
-
describe('
|
|
1020
|
+
describe('collateralSwitch()', () => {
|
|
1007
1021
|
const examples: Array<[
|
|
1008
1022
|
[StrategyOrBundleIds, boolean, TriggerData, SubData],
|
|
1009
1023
|
[
|
|
@@ -1014,80 +1028,107 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1014
1028
|
toAssetId: number,
|
|
1015
1029
|
marketAddr: EthereumAddress,
|
|
1016
1030
|
amountToSwitch: string,
|
|
1017
|
-
user: EthereumAddress,
|
|
1018
1031
|
baseTokenAddress: EthereumAddress,
|
|
1019
1032
|
quoteTokenAddress: EthereumAddress,
|
|
1020
1033
|
price: number,
|
|
1021
1034
|
state: RatioState,
|
|
1022
1035
|
]
|
|
1023
1036
|
]> = [
|
|
1024
|
-
//
|
|
1037
|
+
// WETH -> USDC, price 100000, state UNDER
|
|
1025
1038
|
[
|
|
1026
1039
|
[
|
|
1027
|
-
Strategies.MainnetIds.
|
|
1040
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1028
1041
|
false,
|
|
1029
|
-
['
|
|
1042
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000000000000000000000000000000009184e72a0000000000000000000000000000000000000000000000000000000000000000001'],
|
|
1030
1043
|
[
|
|
1044
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1045
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1031
1046
|
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1032
1047
|
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1033
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1034
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
1035
1048
|
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1036
1049
|
'0x0000000000000000000000000000000000000000000000008ac7230489e80000',
|
|
1037
|
-
'
|
|
1050
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1038
1051
|
],
|
|
1039
1052
|
],
|
|
1040
1053
|
[
|
|
1041
|
-
Strategies.MainnetIds.
|
|
1054
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1055
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1056
|
+
0,
|
|
1042
1057
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1043
1058
|
1,
|
|
1044
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1045
|
-
3,
|
|
1046
1059
|
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1047
|
-
'10000000000000000000', // 10
|
|
1048
|
-
web3Utils.toChecksumAddress('
|
|
1060
|
+
'10000000000000000000', // 10 WETH
|
|
1061
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1049
1062
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1050
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1051
1063
|
100000,
|
|
1052
1064
|
RatioState.UNDER,
|
|
1053
1065
|
]
|
|
1054
1066
|
],
|
|
1055
|
-
//
|
|
1067
|
+
// USDC -> WETH, price 0.00001, state OVER
|
|
1056
1068
|
[
|
|
1057
1069
|
[
|
|
1058
|
-
Strategies.MainnetIds.
|
|
1070
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1059
1071
|
false,
|
|
1060
|
-
['
|
|
1072
|
+
['0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000000000003e80000000000000000000000000000000000000000000000000000000000000000'],
|
|
1061
1073
|
[
|
|
1062
|
-
'0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f',
|
|
1063
|
-
'0x0000000000000000000000000000000000000000000000000000000000000003',
|
|
1064
1074
|
'0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48',
|
|
1065
1075
|
'0x0000000000000000000000000000000000000000000000000000000000000001',
|
|
1076
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1077
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1066
1078
|
'0x00000000000000000000000087870bca3f3fd6335c3f4ce8392d69d0b4161d39',
|
|
1067
1079
|
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
|
|
1068
|
-
'
|
|
1080
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1069
1081
|
],
|
|
1070
1082
|
],
|
|
1071
1083
|
[
|
|
1072
|
-
Strategies.MainnetIds.
|
|
1073
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1074
|
-
3,
|
|
1084
|
+
Strategies.MainnetIds.AAVE_V3_COLLATERAL_SWITCH,
|
|
1075
1085
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1076
1086
|
1,
|
|
1087
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1088
|
+
0,
|
|
1077
1089
|
web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1078
1090
|
MAXUINT, // MaxUint256
|
|
1079
|
-
web3Utils.toChecksumAddress('0xDd6ecD6c9b9F7e29E0f14bb9D5F0D0A3C6cB6c6A'),
|
|
1080
|
-
web3Utils.toChecksumAddress(getAssetInfo('DAI', ChainId.Ethereum).address),
|
|
1081
1091
|
web3Utils.toChecksumAddress(getAssetInfo('USDC', ChainId.Ethereum).address),
|
|
1082
|
-
|
|
1092
|
+
web3Utils.toChecksumAddress(getAssetInfo('WETH', ChainId.Ethereum).address),
|
|
1093
|
+
0.00001,
|
|
1083
1094
|
RatioState.OVER,
|
|
1084
1095
|
]
|
|
1085
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
|
+
],
|
|
1086
1127
|
];
|
|
1087
1128
|
|
|
1088
1129
|
examples.forEach(([expected, actual]) => {
|
|
1089
1130
|
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1090
|
-
expect(aaveV3Encode.
|
|
1131
|
+
expect(aaveV3Encode.collateralSwitch(...actual)).to.eql(expected);
|
|
1091
1132
|
});
|
|
1092
1133
|
});
|
|
1093
1134
|
});
|
|
@@ -424,28 +424,33 @@ export const aaveV3Encode = {
|
|
|
424
424
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
425
425
|
},
|
|
426
426
|
|
|
427
|
-
|
|
427
|
+
instantCloseOnPriceGeneric(
|
|
428
428
|
strategyOrBundleId: number,
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
429
|
+
collAsset: EthereumAddress,
|
|
430
|
+
collAssetId: number,
|
|
431
|
+
debtAsset: EthereumAddress,
|
|
432
|
+
debtAssetId: number,
|
|
433
433
|
marketAddr: EthereumAddress,
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
434
|
+
user: EthereumAddress,
|
|
435
|
+
tsi: string,
|
|
436
|
+
slippage: string,
|
|
437
|
+
stopLossPrice: number = 0,
|
|
438
|
+
stopLossType: CloseToAssetType = CloseToAssetType.DEBT,
|
|
439
|
+
takeProfitPrice: number = 0,
|
|
440
|
+
takeProfitType: CloseToAssetType = CloseToAssetType.COLLATERAL,
|
|
439
441
|
) {
|
|
440
|
-
const isBundle =
|
|
442
|
+
const isBundle = true;
|
|
443
|
+
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
441
444
|
|
|
442
|
-
const subDataEncoded = subDataService.
|
|
443
|
-
|
|
445
|
+
const subDataEncoded = subDataService.aaveV3InstantCloseGenericSubData.encode(
|
|
446
|
+
collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user, tsi, slippage,
|
|
447
|
+
);
|
|
448
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
|
|
444
449
|
|
|
445
450
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
446
451
|
},
|
|
447
452
|
|
|
448
|
-
|
|
453
|
+
collateralSwitch(
|
|
449
454
|
strategyOrBundleId: number,
|
|
450
455
|
fromAsset: EthereumAddress,
|
|
451
456
|
fromAssetId: number,
|
|
@@ -453,7 +458,6 @@ export const aaveV3Encode = {
|
|
|
453
458
|
toAssetId: number,
|
|
454
459
|
marketAddr: EthereumAddress,
|
|
455
460
|
amountToSwitch: string,
|
|
456
|
-
user: EthereumAddress,
|
|
457
461
|
baseTokenAddress: EthereumAddress,
|
|
458
462
|
quoteTokenAddress: EthereumAddress,
|
|
459
463
|
price: number,
|
|
@@ -461,7 +465,7 @@ export const aaveV3Encode = {
|
|
|
461
465
|
) {
|
|
462
466
|
const isBundle = false;
|
|
463
467
|
|
|
464
|
-
const subDataEncoded = subDataService.
|
|
468
|
+
const subDataEncoded = subDataService.aaveV3CollateralSwitchSubData.encode(fromAsset, fromAssetId, toAsset, toAssetId, marketAddr, amountToSwitch);
|
|
465
469
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, state);
|
|
466
470
|
|
|
467
471
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|