@defisaver/automation-sdk 3.2.5 → 3.3.0
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/.babelrc +3 -3
- package/.editorconfig +9 -9
- package/.env.dev +4 -4
- package/.eslintignore +6 -6
- package/.eslintrc.js +39 -39
- package/.mocharc.json +4 -4
- package/.nvmrc +1 -1
- package/README.md +46 -46
- package/cjs/abis/Erc20.json +223 -223
- package/cjs/abis/SubStorage.json +21 -21
- package/cjs/abis/UniMulticall.json +17 -17
- package/cjs/abis/index.d.ts +9 -9
- package/cjs/abis/index.js +30 -30
- package/cjs/abis/legacy_AaveV2Subscriptions.json +8 -8
- package/cjs/abis/legacy_AuthCheck.json +8 -8
- package/cjs/abis/legacy_CompoundV2Subscriptions.json +9 -9
- package/cjs/abis/legacy_MakerSubscriptions.json +9 -9
- package/cjs/automation/private/Automation.d.ts +12 -12
- package/cjs/automation/private/Automation.js +42 -42
- package/cjs/automation/private/LegacyAutomation.d.ts +25 -25
- package/cjs/automation/private/LegacyAutomation.js +118 -118
- package/cjs/automation/private/LegacyProtocol.d.ts +22 -22
- package/cjs/automation/private/LegacyProtocol.js +41 -41
- package/cjs/automation/private/LegacyProtocol.test.d.ts +1 -1
- package/cjs/automation/private/LegacyProtocol.test.js +25 -25
- package/cjs/automation/private/Protocol.d.ts +22 -22
- package/cjs/automation/private/Protocol.js +41 -41
- package/cjs/automation/private/Protocol.test.d.ts +1 -1
- package/cjs/automation/private/Protocol.test.js +25 -25
- package/cjs/automation/private/StrategiesAutomation.d.ts +33 -33
- package/cjs/automation/private/StrategiesAutomation.js +189 -189
- package/cjs/automation/private/StrategiesAutomation.test.d.ts +1 -1
- package/cjs/automation/private/StrategiesAutomation.test.js +671 -671
- package/cjs/automation/public/ArbitrumStrategies.d.ts +5 -5
- package/cjs/automation/public/ArbitrumStrategies.js +13 -13
- package/cjs/automation/public/BaseStrategies.d.ts +5 -5
- package/cjs/automation/public/BaseStrategies.js +13 -13
- package/cjs/automation/public/EthereumStrategies.d.ts +5 -5
- package/cjs/automation/public/EthereumStrategies.js +13 -13
- package/cjs/automation/public/OptimismStrategies.d.ts +5 -5
- package/cjs/automation/public/OptimismStrategies.js +13 -13
- package/cjs/automation/public/Strategies.test.d.ts +1 -1
- package/cjs/automation/public/Strategies.test.js +61 -61
- package/cjs/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
- package/cjs/automation/public/legacy/LegacyAaveAutomation.js +20 -20
- package/cjs/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
- package/cjs/automation/public/legacy/LegacyCompoundAutomation.js +20 -20
- package/cjs/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
- package/cjs/automation/public/legacy/LegacyMakerAutomation.js +20 -20
- package/cjs/configuration.d.ts +1 -1
- package/cjs/configuration.js +12 -12
- package/cjs/constants/index.d.ts +28 -28
- package/cjs/constants/index.js +674 -564
- package/cjs/index.d.ts +23 -23
- package/cjs/index.js +65 -65
- package/cjs/services/contractService.d.ts +12 -12
- package/cjs/services/contractService.js +54 -54
- package/cjs/services/ethereumService.d.ts +7 -7
- package/cjs/services/ethereumService.js +49 -49
- package/cjs/services/ethereumService.test.d.ts +1 -1
- package/cjs/services/ethereumService.test.js +242 -242
- package/cjs/services/strategiesService.d.ts +2 -2
- package/cjs/services/strategiesService.js +946 -898
- package/cjs/services/strategiesService.test.d.ts +1 -1
- package/cjs/services/strategiesService.test.js +110 -110
- package/cjs/services/strategySubService.d.ts +113 -111
- package/cjs/services/strategySubService.js +328 -314
- package/cjs/services/strategySubService.test.d.ts +1 -1
- package/cjs/services/strategySubService.test.js +1058 -936
- package/cjs/services/subDataService.d.ts +282 -261
- package/cjs/services/subDataService.js +740 -683
- package/cjs/services/subDataService.test.d.ts +1 -1
- package/cjs/services/subDataService.test.js +1458 -1282
- package/cjs/services/triggerService.d.ts +268 -249
- package/cjs/services/triggerService.js +509 -473
- package/cjs/services/triggerService.test.d.ts +1 -1
- package/cjs/services/triggerService.test.js +1139 -1045
- package/cjs/services/utils.d.ts +30 -30
- package/cjs/services/utils.js +182 -182
- package/cjs/services/utils.test.d.ts +1 -1
- package/cjs/services/utils.test.js +376 -376
- package/cjs/types/contracts/generated/Erc20.d.ts +53 -53
- package/cjs/types/contracts/generated/Erc20.js +5 -5
- package/cjs/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
- package/cjs/types/contracts/generated/Legacy_AaveV2Subscriptions.js +5 -5
- package/cjs/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
- package/cjs/types/contracts/generated/Legacy_AuthCheck.js +5 -5
- package/cjs/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
- package/cjs/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +5 -5
- package/cjs/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
- package/cjs/types/contracts/generated/Legacy_MakerSubscriptions.js +5 -5
- package/cjs/types/contracts/generated/SubStorage.d.ts +114 -114
- package/cjs/types/contracts/generated/SubStorage.js +5 -5
- package/cjs/types/contracts/generated/UniMulticall.d.ts +55 -55
- package/cjs/types/contracts/generated/UniMulticall.js +5 -5
- package/cjs/types/contracts/generated/index.d.ts +7 -7
- package/cjs/types/contracts/generated/index.js +2 -2
- package/cjs/types/contracts/generated/types.d.ts +54 -54
- package/cjs/types/contracts/generated/types.js +2 -2
- package/cjs/types/enums.d.ts +253 -226
- package/cjs/types/enums.js +279 -252
- package/cjs/types/index.d.ts +264 -248
- package/cjs/types/index.js +2 -2
- package/esm/abis/Erc20.json +223 -223
- package/esm/abis/SubStorage.json +21 -21
- package/esm/abis/UniMulticall.json +17 -17
- package/esm/abis/index.d.ts +9 -9
- package/esm/abis/index.js +18 -18
- package/esm/abis/legacy_AaveV2Subscriptions.json +8 -8
- package/esm/abis/legacy_AuthCheck.json +8 -8
- package/esm/abis/legacy_CompoundV2Subscriptions.json +9 -9
- package/esm/abis/legacy_MakerSubscriptions.json +9 -9
- package/esm/automation/private/Automation.d.ts +12 -12
- package/esm/automation/private/Automation.js +39 -39
- package/esm/automation/private/LegacyAutomation.d.ts +25 -25
- package/esm/automation/private/LegacyAutomation.js +112 -112
- package/esm/automation/private/LegacyProtocol.d.ts +22 -22
- package/esm/automation/private/LegacyProtocol.js +38 -38
- package/esm/automation/private/LegacyProtocol.test.d.ts +1 -1
- package/esm/automation/private/LegacyProtocol.test.js +20 -20
- package/esm/automation/private/Protocol.d.ts +22 -22
- package/esm/automation/private/Protocol.js +38 -38
- package/esm/automation/private/Protocol.test.d.ts +1 -1
- package/esm/automation/private/Protocol.test.js +20 -20
- package/esm/automation/private/StrategiesAutomation.d.ts +33 -33
- package/esm/automation/private/StrategiesAutomation.js +183 -183
- package/esm/automation/private/StrategiesAutomation.test.d.ts +1 -1
- package/esm/automation/private/StrategiesAutomation.test.js +666 -666
- package/esm/automation/public/ArbitrumStrategies.d.ts +5 -5
- package/esm/automation/public/ArbitrumStrategies.js +7 -7
- package/esm/automation/public/BaseStrategies.d.ts +5 -5
- package/esm/automation/public/BaseStrategies.js +7 -7
- package/esm/automation/public/EthereumStrategies.d.ts +5 -5
- package/esm/automation/public/EthereumStrategies.js +7 -7
- package/esm/automation/public/OptimismStrategies.d.ts +5 -5
- package/esm/automation/public/OptimismStrategies.js +7 -7
- package/esm/automation/public/Strategies.test.d.ts +1 -1
- package/esm/automation/public/Strategies.test.js +56 -56
- package/esm/automation/public/legacy/LegacyAaveAutomation.d.ts +6 -6
- package/esm/automation/public/legacy/LegacyAaveAutomation.js +14 -14
- package/esm/automation/public/legacy/LegacyCompoundAutomation.d.ts +6 -6
- package/esm/automation/public/legacy/LegacyCompoundAutomation.js +14 -14
- package/esm/automation/public/legacy/LegacyMakerAutomation.d.ts +6 -6
- package/esm/automation/public/legacy/LegacyMakerAutomation.js +14 -14
- package/esm/configuration.d.ts +1 -1
- package/esm/configuration.js +7 -7
- package/esm/constants/index.d.ts +28 -28
- package/esm/constants/index.js +668 -558
- package/esm/index.d.ts +23 -23
- package/esm/index.js +23 -23
- package/esm/services/contractService.d.ts +12 -12
- package/esm/services/contractService.js +45 -45
- package/esm/services/ethereumService.d.ts +7 -7
- package/esm/services/ethereumService.js +41 -41
- package/esm/services/ethereumService.test.d.ts +1 -1
- package/esm/services/ethereumService.test.js +237 -237
- package/esm/services/strategiesService.d.ts +2 -2
- package/esm/services/strategiesService.js +916 -868
- package/esm/services/strategiesService.test.d.ts +1 -1
- package/esm/services/strategiesService.test.js +108 -108
- package/esm/services/strategySubService.d.ts +113 -111
- package/esm/services/strategySubService.js +299 -285
- package/esm/services/strategySubService.test.d.ts +1 -1
- package/esm/services/strategySubService.test.js +1030 -908
- package/esm/services/subDataService.d.ts +282 -261
- package/esm/services/subDataService.js +734 -677
- package/esm/services/subDataService.test.d.ts +1 -1
- package/esm/services/subDataService.test.js +1430 -1254
- package/esm/services/triggerService.d.ts +268 -249
- package/esm/services/triggerService.js +480 -444
- package/esm/services/triggerService.test.d.ts +1 -1
- package/esm/services/triggerService.test.js +1114 -1020
- package/esm/services/utils.d.ts +30 -30
- package/esm/services/utils.js +131 -131
- package/esm/services/utils.test.d.ts +1 -1
- package/esm/services/utils.test.js +348 -348
- package/esm/types/contracts/generated/Erc20.d.ts +53 -53
- package/esm/types/contracts/generated/Erc20.js +4 -4
- package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.d.ts +129 -129
- package/esm/types/contracts/generated/Legacy_AaveV2Subscriptions.js +4 -4
- package/esm/types/contracts/generated/Legacy_AuthCheck.d.ts +20 -20
- package/esm/types/contracts/generated/Legacy_AuthCheck.js +4 -4
- package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.d.ts +128 -128
- package/esm/types/contracts/generated/Legacy_CompoundV2Subscriptions.js +4 -4
- package/esm/types/contracts/generated/Legacy_MakerSubscriptions.d.ts +246 -246
- package/esm/types/contracts/generated/Legacy_MakerSubscriptions.js +4 -4
- package/esm/types/contracts/generated/SubStorage.d.ts +114 -114
- package/esm/types/contracts/generated/SubStorage.js +4 -4
- package/esm/types/contracts/generated/UniMulticall.d.ts +55 -55
- package/esm/types/contracts/generated/UniMulticall.js +4 -4
- package/esm/types/contracts/generated/index.d.ts +7 -7
- package/esm/types/contracts/generated/index.js +1 -1
- package/esm/types/contracts/generated/types.d.ts +54 -54
- package/esm/types/contracts/generated/types.js +1 -1
- package/esm/types/enums.d.ts +253 -226
- package/esm/types/enums.js +276 -249
- package/esm/types/index.d.ts +264 -248
- package/esm/types/index.js +1 -1
- package/package.json +60 -60
- package/scripts/generateContractTypes.js +39 -39
- package/src/abis/Erc20.json +222 -222
- package/src/abis/SubStorage.json +21 -21
- package/src/abis/UniMulticall.json +17 -17
- package/src/abis/index.ts +28 -28
- package/src/abis/legacy_AaveV2Subscriptions.json +7 -7
- package/src/abis/legacy_AuthCheck.json +7 -7
- package/src/abis/legacy_CompoundV2Subscriptions.json +8 -8
- package/src/abis/legacy_MakerSubscriptions.json +8 -8
- package/src/automation/private/Automation.ts +44 -44
- package/src/automation/private/LegacyAutomation.ts +135 -135
- package/src/automation/private/LegacyProtocol.test.ts +23 -23
- package/src/automation/private/LegacyProtocol.ts +51 -51
- package/src/automation/private/Protocol.test.ts +23 -23
- package/src/automation/private/Protocol.ts +51 -51
- package/src/automation/private/StrategiesAutomation.test.ts +663 -663
- package/src/automation/private/StrategiesAutomation.ts +254 -254
- package/src/automation/public/ArbitrumStrategies.ts +10 -10
- package/src/automation/public/BaseStrategies.ts +10 -10
- package/src/automation/public/EthereumStrategies.ts +10 -10
- package/src/automation/public/OptimismStrategies.ts +10 -10
- package/src/automation/public/Strategies.test.ts +49 -49
- package/src/automation/public/legacy/LegacyAaveAutomation.ts +20 -20
- package/src/automation/public/legacy/LegacyCompoundAutomation.ts +20 -20
- package/src/automation/public/legacy/LegacyMakerAutomation.ts +20 -20
- package/src/configuration.ts +8 -8
- package/src/constants/index.ts +702 -593
- package/src/index.ts +39 -39
- package/src/services/contractService.ts +77 -77
- package/src/services/ethereumService.test.ts +257 -257
- package/src/services/ethereumService.ts +69 -69
- package/src/services/strategiesService.test.ts +105 -105
- package/src/services/strategiesService.ts +1219 -1158
- package/src/services/strategySubService.test.ts +1250 -1122
- package/src/services/strategySubService.ts +685 -648
- package/src/services/subDataService.test.ts +1546 -1387
- package/src/services/subDataService.ts +1024 -934
- package/src/services/triggerService.test.ts +1234 -1130
- package/src/services/triggerService.ts +659 -602
- package/src/services/utils.test.ts +430 -430
- package/src/services/utils.ts +162 -162
- package/src/types/enums.ts +273 -246
- package/src/types/index.ts +333 -312
- package/tsconfig.esm.json +8 -8
- package/tsconfig.json +22 -22
|
@@ -1,1158 +1,1219 @@
|
|
|
1
|
-
import { getAssetInfoByAddress } from '@defisaver/tokens';
|
|
2
|
-
import { cloneDeep } from 'lodash';
|
|
3
|
-
|
|
4
|
-
import Web3 from 'web3';
|
|
5
|
-
import { BUNDLES_INFO, STRATEGIES_INFO } from '../constants';
|
|
6
|
-
import type {
|
|
7
|
-
Position, ParseData, StrategiesToProtocolVersionMapping, BundleOrStrategy, StrategyOrBundleIds,
|
|
8
|
-
BundleInfoUnion, StrategyInfoUnion,
|
|
9
|
-
} from '../types';
|
|
10
|
-
import { ChainId, ProtocolIdentifiers, Strategies } from '../types/enums';
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
getPositionId, getRatioStateInfoForAaveCloseStrategy, getStopLossAndTakeProfitTypeByCloseStrategyType, isRatioStateOver, wethToEthByAddress,
|
|
14
|
-
} from './utils';
|
|
15
|
-
import * as subDataService from './subDataService';
|
|
16
|
-
import * as triggerService from './triggerService';
|
|
17
|
-
|
|
18
|
-
const web3 = new Web3();
|
|
19
|
-
|
|
20
|
-
const SPARK_MARKET_ADDRESSES = {
|
|
21
|
-
[ChainId.Ethereum]: '0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE',
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const AAVE_V3_MARKET_ADDRESSES = {
|
|
25
|
-
[ChainId.Ethereum]: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e',
|
|
26
|
-
[ChainId.Optimism]: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb',
|
|
27
|
-
[ChainId.Arbitrum]: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb',
|
|
28
|
-
[ChainId.Base]: '0xe20fCBdBfFC4Dd138cE8b2E6FBb6CB49777ad64D',
|
|
29
|
-
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
function parseMakerSavingsLiqProtection(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
33
|
-
const _position = cloneDeep(position);
|
|
34
|
-
|
|
35
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
36
|
-
|
|
37
|
-
const triggerData = triggerService.makerRatioTrigger.decode(subStruct.triggerData);
|
|
38
|
-
const subData = subDataService.makerRepayFromSavingsSubData.decode(subStruct.subData);
|
|
39
|
-
|
|
40
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
41
|
-
_position.strategyData.decoded.subData = subData;
|
|
42
|
-
|
|
43
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, subData.vaultId);
|
|
44
|
-
|
|
45
|
-
_position.specific = {
|
|
46
|
-
triggerRepayRatio: Number(triggerData.ratio),
|
|
47
|
-
targetRepayRatio: Number(subData.targetRatio),
|
|
48
|
-
repayEnabled: true,
|
|
49
|
-
boostEnabled: false,
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
return _position;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function parseMakerCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
56
|
-
const _position = cloneDeep(position);
|
|
57
|
-
|
|
58
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
59
|
-
|
|
60
|
-
const triggerData = triggerService.chainlinkPriceTrigger.decode(subStruct.triggerData);
|
|
61
|
-
const subData = subDataService.makerCloseSubData.decode(subStruct.subData);
|
|
62
|
-
|
|
63
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
64
|
-
_position.strategyData.decoded.subData = subData;
|
|
65
|
-
|
|
66
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, subData.vaultId);
|
|
67
|
-
|
|
68
|
-
const isTakeProfit = isRatioStateOver(Number(triggerData.state));
|
|
69
|
-
|
|
70
|
-
_position.strategy.strategyId = isTakeProfit ? Strategies.IdOverrides.TakeProfit : Strategies.IdOverrides.StopLoss;
|
|
71
|
-
|
|
72
|
-
_position.specific = {
|
|
73
|
-
price: triggerData.price,
|
|
74
|
-
closeToAssetAddr: subData.closeToAssetAddr,
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
return _position;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function parseMakerTrailingStop(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
81
|
-
const _position = cloneDeep(position);
|
|
82
|
-
|
|
83
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
84
|
-
|
|
85
|
-
const triggerData = triggerService.trailingStopTrigger.decode(subStruct.triggerData);
|
|
86
|
-
const subData = subDataService.makerCloseSubData.decode(subStruct.subData);
|
|
87
|
-
|
|
88
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
89
|
-
_position.strategyData.decoded.subData = subData;
|
|
90
|
-
|
|
91
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, subData.vaultId);
|
|
92
|
-
|
|
93
|
-
_position.strategy.strategyId = Strategies.IdOverrides.TrailingStop;
|
|
94
|
-
|
|
95
|
-
_position.specific = {
|
|
96
|
-
triggerPercentage: Number(triggerData.triggerPercentage),
|
|
97
|
-
roundId: Number(triggerData.roundId),
|
|
98
|
-
closeToAssetAddr: subData.closeToAssetAddr,
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
return _position;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
function parseMakerLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
105
|
-
const _position = cloneDeep(position);
|
|
106
|
-
|
|
107
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
108
|
-
const { isEnabled } = parseData.strategiesSubsData;
|
|
109
|
-
|
|
110
|
-
const triggerData = triggerService.makerRatioTrigger.decode(subStruct.triggerData);
|
|
111
|
-
const subData = subDataService.makerLeverageManagementSubData.decode(subStruct.subData);
|
|
112
|
-
|
|
113
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
114
|
-
_position.strategyData.decoded.subData = subData;
|
|
115
|
-
|
|
116
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, subData.vaultId);
|
|
117
|
-
|
|
118
|
-
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
119
|
-
|
|
120
|
-
if (isRepay) {
|
|
121
|
-
_position.specific = {
|
|
122
|
-
triggerRepayRatio: triggerData.ratio,
|
|
123
|
-
targetRepayRatio: subData.targetRatio,
|
|
124
|
-
repayEnabled: true,
|
|
125
|
-
subId1: Number(subId),
|
|
126
|
-
mergeWithId: Strategies.Identifiers.Boost,
|
|
127
|
-
};
|
|
128
|
-
} else {
|
|
129
|
-
_position.specific = {
|
|
130
|
-
triggerBoostRatio: triggerData.ratio,
|
|
131
|
-
targetBoostRatio: subData.targetRatio,
|
|
132
|
-
boostEnabled: isEnabled,
|
|
133
|
-
subId2: Number(subId),
|
|
134
|
-
mergeId: Strategies.Identifiers.Boost,
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
139
|
-
|
|
140
|
-
return _position;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function parseLiquityCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
144
|
-
const _position = cloneDeep(position);
|
|
145
|
-
|
|
146
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
147
|
-
|
|
148
|
-
const triggerData = triggerService.chainlinkPriceTrigger.decode(subStruct.triggerData);
|
|
149
|
-
const subData = subDataService.liquityCloseSubData.decode(subStruct.subData);
|
|
150
|
-
|
|
151
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
152
|
-
_position.strategyData.decoded.subData = subData;
|
|
153
|
-
|
|
154
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner);
|
|
155
|
-
|
|
156
|
-
const isTakeProfit = isRatioStateOver(Number(triggerData.state));
|
|
157
|
-
|
|
158
|
-
_position.strategy.strategyId = isTakeProfit ? Strategies.IdOverrides.TakeProfit : Strategies.IdOverrides.StopLoss;
|
|
159
|
-
|
|
160
|
-
_position.specific = {
|
|
161
|
-
price: triggerData.price,
|
|
162
|
-
closeToAssetAddr: subData.closeToAssetAddr,
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
return _position;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function parseLiquityTrailingStop(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
169
|
-
const _position = cloneDeep(position);
|
|
170
|
-
|
|
171
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
172
|
-
|
|
173
|
-
const triggerData = triggerService.trailingStopTrigger.decode(subStruct.triggerData);
|
|
174
|
-
const subData = subDataService.liquityCloseSubData.decode(subStruct.subData);
|
|
175
|
-
|
|
176
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
177
|
-
_position.strategyData.decoded.subData = subData;
|
|
178
|
-
|
|
179
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner);
|
|
180
|
-
|
|
181
|
-
_position.strategy.strategyId = Strategies.IdOverrides.TrailingStop;
|
|
182
|
-
|
|
183
|
-
_position.specific = {
|
|
184
|
-
triggerPercentage: Number(triggerData.triggerPercentage),
|
|
185
|
-
roundId: Number(triggerData.roundId),
|
|
186
|
-
closeToAssetAddr: subData.closeToAssetAddr,
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
return _position;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function parseAaveV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
193
|
-
const _position = cloneDeep(position);
|
|
194
|
-
|
|
195
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
196
|
-
const { isEnabled } = parseData.strategiesSubsData;
|
|
197
|
-
|
|
198
|
-
const triggerData = triggerService.aaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
199
|
-
const subData = subDataService.aaveV2LeverageManagementSubData.decode(subStruct.subData);
|
|
200
|
-
|
|
201
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
202
|
-
_position.strategyData.decoded.subData = subData;
|
|
203
|
-
|
|
204
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
|
|
205
|
-
|
|
206
|
-
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
207
|
-
|
|
208
|
-
if (isRepay) {
|
|
209
|
-
_position.specific = {
|
|
210
|
-
triggerRepayRatio: triggerData.ratio,
|
|
211
|
-
targetRepayRatio: subData.targetRatio,
|
|
212
|
-
repayEnabled: true,
|
|
213
|
-
subId1: Number(subId),
|
|
214
|
-
mergeWithId: Strategies.Identifiers.Boost,
|
|
215
|
-
};
|
|
216
|
-
} else {
|
|
217
|
-
_position.specific = {
|
|
218
|
-
triggerBoostRatio: triggerData.ratio,
|
|
219
|
-
targetBoostRatio: subData.targetRatio,
|
|
220
|
-
boostEnabled: isEnabled,
|
|
221
|
-
subId2: Number(subId),
|
|
222
|
-
mergeId: Strategies.Identifiers.Boost,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
227
|
-
|
|
228
|
-
return _position;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function parseAaveV3LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
232
|
-
const _position = cloneDeep(position);
|
|
233
|
-
|
|
234
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
235
|
-
const { isEnabled } = parseData.strategiesSubsData;
|
|
236
|
-
|
|
237
|
-
const triggerData = triggerService.aaveV3RatioTrigger.decode(subStruct.triggerData);
|
|
238
|
-
const subData = subDataService.aaveV3LeverageManagementSubData.decode(subStruct.subData);
|
|
239
|
-
|
|
240
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
241
|
-
_position.strategyData.decoded.subData = subData;
|
|
242
|
-
|
|
243
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
|
|
244
|
-
|
|
245
|
-
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
246
|
-
|
|
247
|
-
if (isRepay) {
|
|
248
|
-
_position.specific = {
|
|
249
|
-
triggerRepayRatio: triggerData.ratio,
|
|
250
|
-
targetRepayRatio: subData.targetRatio,
|
|
251
|
-
repayEnabled: true,
|
|
252
|
-
subId1: Number(subId),
|
|
253
|
-
mergeWithId: Strategies.Identifiers.Boost,
|
|
254
|
-
};
|
|
255
|
-
} else {
|
|
256
|
-
_position.specific = {
|
|
257
|
-
triggerBoostRatio: triggerData.ratio,
|
|
258
|
-
targetBoostRatio: subData.targetRatio,
|
|
259
|
-
boostEnabled: isEnabled,
|
|
260
|
-
subId2: Number(subId),
|
|
261
|
-
mergeId: Strategies.Identifiers.Boost,
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
266
|
-
|
|
267
|
-
return _position;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
271
|
-
const _position = cloneDeep(position);
|
|
272
|
-
|
|
273
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
274
|
-
const { isEnabled } = parseData.strategiesSubsData;
|
|
275
|
-
|
|
276
|
-
const triggerData = triggerService.morphoAaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
277
|
-
const subData = subDataService.morphoAaveV2LeverageManagementSubData.decode(subStruct.subData);
|
|
278
|
-
|
|
279
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
280
|
-
_position.strategyData.decoded.subData = subData;
|
|
281
|
-
|
|
282
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner);
|
|
283
|
-
|
|
284
|
-
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
285
|
-
|
|
286
|
-
if (isRepay) {
|
|
287
|
-
_position.specific = {
|
|
288
|
-
triggerRepayRatio: triggerData.ratio,
|
|
289
|
-
targetRepayRatio: subData.targetRatio,
|
|
290
|
-
repayEnabled: true,
|
|
291
|
-
subId1: Number(subId),
|
|
292
|
-
mergeWithId: Strategies.Identifiers.Boost,
|
|
293
|
-
};
|
|
294
|
-
} else {
|
|
295
|
-
_position.specific = {
|
|
296
|
-
triggerBoostRatio: triggerData.ratio,
|
|
297
|
-
targetBoostRatio: subData.targetRatio,
|
|
298
|
-
boostEnabled: isEnabled,
|
|
299
|
-
subId2: Number(subId),
|
|
300
|
-
mergeId: Strategies.Identifiers.Boost,
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
305
|
-
|
|
306
|
-
return _position;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
function parseAaveV3CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
310
|
-
const _position = cloneDeep(position);
|
|
311
|
-
|
|
312
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
313
|
-
|
|
314
|
-
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
315
|
-
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
316
|
-
|
|
317
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
318
|
-
_position.strategyData.decoded.subData = subData;
|
|
319
|
-
|
|
320
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
321
|
-
|
|
322
|
-
_position.specific = {
|
|
323
|
-
collAsset: subData.collAsset,
|
|
324
|
-
collAssetId: subData.collAssetId,
|
|
325
|
-
debtAsset: subData.debtAsset,
|
|
326
|
-
debtAssetId: subData.debtAssetId,
|
|
327
|
-
baseToken: triggerData.baseTokenAddress,
|
|
328
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
329
|
-
price: triggerData.price,
|
|
330
|
-
ratioState: triggerData.ratioState,
|
|
331
|
-
};
|
|
332
|
-
|
|
333
|
-
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
|
|
334
|
-
_position.specific.ratioState,
|
|
335
|
-
wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
|
|
336
|
-
wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
|
|
337
|
-
parseData.chainId,
|
|
338
|
-
);
|
|
339
|
-
|
|
340
|
-
_position.strategy.strategyId = isRatioStateOver(ratioState) ? Strategies.IdOverrides.TakeProfit : Strategies.IdOverrides.StopLoss;
|
|
341
|
-
|
|
342
|
-
return _position;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function parseAaveV3CloseOnPriceWithMaximumGasPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
346
|
-
const _position = cloneDeep(position);
|
|
347
|
-
|
|
348
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
349
|
-
|
|
350
|
-
const triggerData = triggerService.aaveV3QuotePriceWithMaximumGasPriceTrigger.decode(subStruct.triggerData);
|
|
351
|
-
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
352
|
-
|
|
353
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
354
|
-
_position.strategyData.decoded.subData = subData;
|
|
355
|
-
|
|
356
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
357
|
-
|
|
358
|
-
_position.specific = {
|
|
359
|
-
collAsset: subData.collAsset,
|
|
360
|
-
collAssetId: subData.collAssetId,
|
|
361
|
-
debtAsset: subData.debtAsset,
|
|
362
|
-
debtAssetId: subData.debtAssetId,
|
|
363
|
-
baseToken: triggerData.baseTokenAddress,
|
|
364
|
-
quoteToken: triggerData.quoteTokenAddress,
|
|
365
|
-
price: triggerData.price,
|
|
366
|
-
maximumGasPrice: triggerData.maximumGasPrice,
|
|
367
|
-
ratioState: triggerData.ratioState,
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
|
|
371
|
-
_position.specific.ratioState,
|
|
372
|
-
wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
|
|
373
|
-
wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
|
|
374
|
-
parseData.chainId,
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
_position.strategy.strategyId = isRatioStateOver(ratioState)
|
|
378
|
-
? Strategies.IdOverrides.TakeProfitWithGasPrice
|
|
379
|
-
: Strategies.IdOverrides.StopLossWithGasPrice;
|
|
380
|
-
|
|
381
|
-
return _position;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
function parseCompoundV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
385
|
-
const _position = cloneDeep(position);
|
|
386
|
-
|
|
387
|
-
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
388
|
-
const { isEnabled } = parseData.strategiesSubsData;
|
|
389
|
-
|
|
390
|
-
const triggerData = triggerService.compoundV2RatioTrigger.decode(subStruct.triggerData);
|
|
391
|
-
const subData = subDataService.compoundV2LeverageManagementSubData.decode(subStruct.subData);
|
|
392
|
-
|
|
393
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
394
|
-
_position.strategyData.decoded.subData = subData;
|
|
395
|
-
_position.owner = triggerData.owner.toLowerCase();
|
|
396
|
-
|
|
397
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner);
|
|
398
|
-
|
|
399
|
-
const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
|
|
400
|
-
|
|
401
|
-
if (isRepay) {
|
|
402
|
-
_position.specific = {
|
|
403
|
-
triggerRepayRatio: triggerData.ratio,
|
|
404
|
-
targetRepayRatio: subData.targetRatio,
|
|
405
|
-
repayEnabled: true,
|
|
406
|
-
subId1: Number(subId),
|
|
407
|
-
mergeWithId: Strategies.Identifiers.Boost,
|
|
408
|
-
};
|
|
409
|
-
} else {
|
|
410
|
-
_position.specific = {
|
|
411
|
-
triggerBoostRatio: triggerData.ratio,
|
|
412
|
-
targetBoostRatio: subData.targetRatio,
|
|
413
|
-
boostEnabled: isEnabled,
|
|
414
|
-
subId2: Number(subId),
|
|
415
|
-
mergeId: Strategies.Identifiers.Boost,
|
|
416
|
-
};
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
_position.strategy.strategyId
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
const {
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
const
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
_position.strategyData.decoded.
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
return _position;
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
function
|
|
470
|
-
const _position = cloneDeep(position);
|
|
471
|
-
|
|
472
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
_position.
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
_position.
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
_position
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
_position.
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
const
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
_position.strategyData.decoded.
|
|
579
|
-
_position.strategyData.decoded.
|
|
580
|
-
|
|
581
|
-
_position.positionId = getPositionId(
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
_position
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
const
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
const
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
);
|
|
681
|
-
|
|
682
|
-
_position.strategy.strategyId
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
const
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
_position.
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
_position
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
const
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
const
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
_position.
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
const {
|
|
791
|
-
const
|
|
792
|
-
const
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
_position.strategyData.decoded.
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
_position.strategy.strategyId =
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
const
|
|
832
|
-
const
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
_position.strategyData.decoded.
|
|
836
|
-
_position.
|
|
837
|
-
_position.
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
);
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
);
|
|
905
|
-
|
|
906
|
-
const
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
const
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
_position.
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
[Strategies.Identifiers.
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
[Strategies.Identifiers.
|
|
1080
|
-
[Strategies.Identifiers.
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
[Strategies.Identifiers.
|
|
1086
|
-
[Strategies.Identifiers.
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
[Strategies.Identifiers.
|
|
1090
|
-
[Strategies.Identifiers.
|
|
1091
|
-
[Strategies.Identifiers.
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
[Strategies.Identifiers.
|
|
1096
|
-
[Strategies.Identifiers.
|
|
1097
|
-
[Strategies.Identifiers.
|
|
1098
|
-
[Strategies.Identifiers.BoostOnPrice]:
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1
|
+
import { getAssetInfoByAddress } from '@defisaver/tokens';
|
|
2
|
+
import { cloneDeep } from 'lodash';
|
|
3
|
+
|
|
4
|
+
import Web3 from 'web3';
|
|
5
|
+
import { BUNDLES_INFO, STRATEGIES_INFO } from '../constants';
|
|
6
|
+
import type {
|
|
7
|
+
Position, ParseData, StrategiesToProtocolVersionMapping, BundleOrStrategy, StrategyOrBundleIds,
|
|
8
|
+
BundleInfoUnion, StrategyInfoUnion,
|
|
9
|
+
} from '../types';
|
|
10
|
+
import { ChainId, ProtocolIdentifiers, Strategies } from '../types/enums';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
getPositionId, getRatioStateInfoForAaveCloseStrategy, getStopLossAndTakeProfitTypeByCloseStrategyType, isRatioStateOver, wethToEthByAddress,
|
|
14
|
+
} from './utils';
|
|
15
|
+
import * as subDataService from './subDataService';
|
|
16
|
+
import * as triggerService from './triggerService';
|
|
17
|
+
|
|
18
|
+
const web3 = new Web3();
|
|
19
|
+
|
|
20
|
+
const SPARK_MARKET_ADDRESSES = {
|
|
21
|
+
[ChainId.Ethereum]: '0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const AAVE_V3_MARKET_ADDRESSES = {
|
|
25
|
+
[ChainId.Ethereum]: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e',
|
|
26
|
+
[ChainId.Optimism]: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb',
|
|
27
|
+
[ChainId.Arbitrum]: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb',
|
|
28
|
+
[ChainId.Base]: '0xe20fCBdBfFC4Dd138cE8b2E6FBb6CB49777ad64D',
|
|
29
|
+
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
function parseMakerSavingsLiqProtection(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
33
|
+
const _position = cloneDeep(position);
|
|
34
|
+
|
|
35
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
36
|
+
|
|
37
|
+
const triggerData = triggerService.makerRatioTrigger.decode(subStruct.triggerData);
|
|
38
|
+
const subData = subDataService.makerRepayFromSavingsSubData.decode(subStruct.subData);
|
|
39
|
+
|
|
40
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
41
|
+
_position.strategyData.decoded.subData = subData;
|
|
42
|
+
|
|
43
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, subData.vaultId);
|
|
44
|
+
|
|
45
|
+
_position.specific = {
|
|
46
|
+
triggerRepayRatio: Number(triggerData.ratio),
|
|
47
|
+
targetRepayRatio: Number(subData.targetRatio),
|
|
48
|
+
repayEnabled: true,
|
|
49
|
+
boostEnabled: false,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
return _position;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function parseMakerCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
56
|
+
const _position = cloneDeep(position);
|
|
57
|
+
|
|
58
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
59
|
+
|
|
60
|
+
const triggerData = triggerService.chainlinkPriceTrigger.decode(subStruct.triggerData);
|
|
61
|
+
const subData = subDataService.makerCloseSubData.decode(subStruct.subData);
|
|
62
|
+
|
|
63
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
64
|
+
_position.strategyData.decoded.subData = subData;
|
|
65
|
+
|
|
66
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, subData.vaultId);
|
|
67
|
+
|
|
68
|
+
const isTakeProfit = isRatioStateOver(Number(triggerData.state));
|
|
69
|
+
|
|
70
|
+
_position.strategy.strategyId = isTakeProfit ? Strategies.IdOverrides.TakeProfit : Strategies.IdOverrides.StopLoss;
|
|
71
|
+
|
|
72
|
+
_position.specific = {
|
|
73
|
+
price: triggerData.price,
|
|
74
|
+
closeToAssetAddr: subData.closeToAssetAddr,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
return _position;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function parseMakerTrailingStop(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
81
|
+
const _position = cloneDeep(position);
|
|
82
|
+
|
|
83
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
84
|
+
|
|
85
|
+
const triggerData = triggerService.trailingStopTrigger.decode(subStruct.triggerData);
|
|
86
|
+
const subData = subDataService.makerCloseSubData.decode(subStruct.subData);
|
|
87
|
+
|
|
88
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
89
|
+
_position.strategyData.decoded.subData = subData;
|
|
90
|
+
|
|
91
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, subData.vaultId);
|
|
92
|
+
|
|
93
|
+
_position.strategy.strategyId = Strategies.IdOverrides.TrailingStop;
|
|
94
|
+
|
|
95
|
+
_position.specific = {
|
|
96
|
+
triggerPercentage: Number(triggerData.triggerPercentage),
|
|
97
|
+
roundId: Number(triggerData.roundId),
|
|
98
|
+
closeToAssetAddr: subData.closeToAssetAddr,
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
return _position;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function parseMakerLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
105
|
+
const _position = cloneDeep(position);
|
|
106
|
+
|
|
107
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
108
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
109
|
+
|
|
110
|
+
const triggerData = triggerService.makerRatioTrigger.decode(subStruct.triggerData);
|
|
111
|
+
const subData = subDataService.makerLeverageManagementSubData.decode(subStruct.subData);
|
|
112
|
+
|
|
113
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
114
|
+
_position.strategyData.decoded.subData = subData;
|
|
115
|
+
|
|
116
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, subData.vaultId);
|
|
117
|
+
|
|
118
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
119
|
+
|
|
120
|
+
if (isRepay) {
|
|
121
|
+
_position.specific = {
|
|
122
|
+
triggerRepayRatio: triggerData.ratio,
|
|
123
|
+
targetRepayRatio: subData.targetRatio,
|
|
124
|
+
repayEnabled: true,
|
|
125
|
+
subId1: Number(subId),
|
|
126
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
127
|
+
};
|
|
128
|
+
} else {
|
|
129
|
+
_position.specific = {
|
|
130
|
+
triggerBoostRatio: triggerData.ratio,
|
|
131
|
+
targetBoostRatio: subData.targetRatio,
|
|
132
|
+
boostEnabled: isEnabled,
|
|
133
|
+
subId2: Number(subId),
|
|
134
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
139
|
+
|
|
140
|
+
return _position;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function parseLiquityCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
144
|
+
const _position = cloneDeep(position);
|
|
145
|
+
|
|
146
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
147
|
+
|
|
148
|
+
const triggerData = triggerService.chainlinkPriceTrigger.decode(subStruct.triggerData);
|
|
149
|
+
const subData = subDataService.liquityCloseSubData.decode(subStruct.subData);
|
|
150
|
+
|
|
151
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
152
|
+
_position.strategyData.decoded.subData = subData;
|
|
153
|
+
|
|
154
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner);
|
|
155
|
+
|
|
156
|
+
const isTakeProfit = isRatioStateOver(Number(triggerData.state));
|
|
157
|
+
|
|
158
|
+
_position.strategy.strategyId = isTakeProfit ? Strategies.IdOverrides.TakeProfit : Strategies.IdOverrides.StopLoss;
|
|
159
|
+
|
|
160
|
+
_position.specific = {
|
|
161
|
+
price: triggerData.price,
|
|
162
|
+
closeToAssetAddr: subData.closeToAssetAddr,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
return _position;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function parseLiquityTrailingStop(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
169
|
+
const _position = cloneDeep(position);
|
|
170
|
+
|
|
171
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
172
|
+
|
|
173
|
+
const triggerData = triggerService.trailingStopTrigger.decode(subStruct.triggerData);
|
|
174
|
+
const subData = subDataService.liquityCloseSubData.decode(subStruct.subData);
|
|
175
|
+
|
|
176
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
177
|
+
_position.strategyData.decoded.subData = subData;
|
|
178
|
+
|
|
179
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner);
|
|
180
|
+
|
|
181
|
+
_position.strategy.strategyId = Strategies.IdOverrides.TrailingStop;
|
|
182
|
+
|
|
183
|
+
_position.specific = {
|
|
184
|
+
triggerPercentage: Number(triggerData.triggerPercentage),
|
|
185
|
+
roundId: Number(triggerData.roundId),
|
|
186
|
+
closeToAssetAddr: subData.closeToAssetAddr,
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
return _position;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function parseAaveV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
193
|
+
const _position = cloneDeep(position);
|
|
194
|
+
|
|
195
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
196
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
197
|
+
|
|
198
|
+
const triggerData = triggerService.aaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
199
|
+
const subData = subDataService.aaveV2LeverageManagementSubData.decode(subStruct.subData);
|
|
200
|
+
|
|
201
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
202
|
+
_position.strategyData.decoded.subData = subData;
|
|
203
|
+
|
|
204
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
|
|
205
|
+
|
|
206
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
207
|
+
|
|
208
|
+
if (isRepay) {
|
|
209
|
+
_position.specific = {
|
|
210
|
+
triggerRepayRatio: triggerData.ratio,
|
|
211
|
+
targetRepayRatio: subData.targetRatio,
|
|
212
|
+
repayEnabled: true,
|
|
213
|
+
subId1: Number(subId),
|
|
214
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
215
|
+
};
|
|
216
|
+
} else {
|
|
217
|
+
_position.specific = {
|
|
218
|
+
triggerBoostRatio: triggerData.ratio,
|
|
219
|
+
targetBoostRatio: subData.targetRatio,
|
|
220
|
+
boostEnabled: isEnabled,
|
|
221
|
+
subId2: Number(subId),
|
|
222
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
227
|
+
|
|
228
|
+
return _position;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function parseAaveV3LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
232
|
+
const _position = cloneDeep(position);
|
|
233
|
+
|
|
234
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
235
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
236
|
+
|
|
237
|
+
const triggerData = triggerService.aaveV3RatioTrigger.decode(subStruct.triggerData);
|
|
238
|
+
const subData = subDataService.aaveV3LeverageManagementSubData.decode(subStruct.subData);
|
|
239
|
+
|
|
240
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
241
|
+
_position.strategyData.decoded.subData = subData;
|
|
242
|
+
|
|
243
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
|
|
244
|
+
|
|
245
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
246
|
+
|
|
247
|
+
if (isRepay) {
|
|
248
|
+
_position.specific = {
|
|
249
|
+
triggerRepayRatio: triggerData.ratio,
|
|
250
|
+
targetRepayRatio: subData.targetRatio,
|
|
251
|
+
repayEnabled: true,
|
|
252
|
+
subId1: Number(subId),
|
|
253
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
254
|
+
};
|
|
255
|
+
} else {
|
|
256
|
+
_position.specific = {
|
|
257
|
+
triggerBoostRatio: triggerData.ratio,
|
|
258
|
+
targetBoostRatio: subData.targetRatio,
|
|
259
|
+
boostEnabled: isEnabled,
|
|
260
|
+
subId2: Number(subId),
|
|
261
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
266
|
+
|
|
267
|
+
return _position;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
271
|
+
const _position = cloneDeep(position);
|
|
272
|
+
|
|
273
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
274
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
275
|
+
|
|
276
|
+
const triggerData = triggerService.morphoAaveV2RatioTrigger.decode(subStruct.triggerData);
|
|
277
|
+
const subData = subDataService.morphoAaveV2LeverageManagementSubData.decode(subStruct.subData);
|
|
278
|
+
|
|
279
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
280
|
+
_position.strategyData.decoded.subData = subData;
|
|
281
|
+
|
|
282
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner);
|
|
283
|
+
|
|
284
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
285
|
+
|
|
286
|
+
if (isRepay) {
|
|
287
|
+
_position.specific = {
|
|
288
|
+
triggerRepayRatio: triggerData.ratio,
|
|
289
|
+
targetRepayRatio: subData.targetRatio,
|
|
290
|
+
repayEnabled: true,
|
|
291
|
+
subId1: Number(subId),
|
|
292
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
293
|
+
};
|
|
294
|
+
} else {
|
|
295
|
+
_position.specific = {
|
|
296
|
+
triggerBoostRatio: triggerData.ratio,
|
|
297
|
+
targetBoostRatio: subData.targetRatio,
|
|
298
|
+
boostEnabled: isEnabled,
|
|
299
|
+
subId2: Number(subId),
|
|
300
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
305
|
+
|
|
306
|
+
return _position;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function parseAaveV3CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
310
|
+
const _position = cloneDeep(position);
|
|
311
|
+
|
|
312
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
313
|
+
|
|
314
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
315
|
+
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
316
|
+
|
|
317
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
318
|
+
_position.strategyData.decoded.subData = subData;
|
|
319
|
+
|
|
320
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
321
|
+
|
|
322
|
+
_position.specific = {
|
|
323
|
+
collAsset: subData.collAsset,
|
|
324
|
+
collAssetId: subData.collAssetId,
|
|
325
|
+
debtAsset: subData.debtAsset,
|
|
326
|
+
debtAssetId: subData.debtAssetId,
|
|
327
|
+
baseToken: triggerData.baseTokenAddress,
|
|
328
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
329
|
+
price: triggerData.price,
|
|
330
|
+
ratioState: triggerData.ratioState,
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
|
|
334
|
+
_position.specific.ratioState,
|
|
335
|
+
wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
|
|
336
|
+
wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
|
|
337
|
+
parseData.chainId,
|
|
338
|
+
);
|
|
339
|
+
|
|
340
|
+
_position.strategy.strategyId = isRatioStateOver(ratioState) ? Strategies.IdOverrides.TakeProfit : Strategies.IdOverrides.StopLoss;
|
|
341
|
+
|
|
342
|
+
return _position;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function parseAaveV3CloseOnPriceWithMaximumGasPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
346
|
+
const _position = cloneDeep(position);
|
|
347
|
+
|
|
348
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
349
|
+
|
|
350
|
+
const triggerData = triggerService.aaveV3QuotePriceWithMaximumGasPriceTrigger.decode(subStruct.triggerData);
|
|
351
|
+
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
352
|
+
|
|
353
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
354
|
+
_position.strategyData.decoded.subData = subData;
|
|
355
|
+
|
|
356
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, AAVE_V3_MARKET_ADDRESSES[_position.chainId]);
|
|
357
|
+
|
|
358
|
+
_position.specific = {
|
|
359
|
+
collAsset: subData.collAsset,
|
|
360
|
+
collAssetId: subData.collAssetId,
|
|
361
|
+
debtAsset: subData.debtAsset,
|
|
362
|
+
debtAssetId: subData.debtAssetId,
|
|
363
|
+
baseToken: triggerData.baseTokenAddress,
|
|
364
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
365
|
+
price: triggerData.price,
|
|
366
|
+
maximumGasPrice: triggerData.maximumGasPrice,
|
|
367
|
+
ratioState: triggerData.ratioState,
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
|
|
371
|
+
_position.specific.ratioState,
|
|
372
|
+
wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
|
|
373
|
+
wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
|
|
374
|
+
parseData.chainId,
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
_position.strategy.strategyId = isRatioStateOver(ratioState)
|
|
378
|
+
? Strategies.IdOverrides.TakeProfitWithGasPrice
|
|
379
|
+
: Strategies.IdOverrides.StopLossWithGasPrice;
|
|
380
|
+
|
|
381
|
+
return _position;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
function parseCompoundV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
385
|
+
const _position = cloneDeep(position);
|
|
386
|
+
|
|
387
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
388
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
389
|
+
|
|
390
|
+
const triggerData = triggerService.compoundV2RatioTrigger.decode(subStruct.triggerData);
|
|
391
|
+
const subData = subDataService.compoundV2LeverageManagementSubData.decode(subStruct.subData);
|
|
392
|
+
|
|
393
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
394
|
+
_position.strategyData.decoded.subData = subData;
|
|
395
|
+
_position.owner = triggerData.owner.toLowerCase();
|
|
396
|
+
|
|
397
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner);
|
|
398
|
+
|
|
399
|
+
const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
|
|
400
|
+
|
|
401
|
+
if (isRepay) {
|
|
402
|
+
_position.specific = {
|
|
403
|
+
triggerRepayRatio: triggerData.ratio,
|
|
404
|
+
targetRepayRatio: subData.targetRatio,
|
|
405
|
+
repayEnabled: true,
|
|
406
|
+
subId1: Number(subId),
|
|
407
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
408
|
+
};
|
|
409
|
+
} else {
|
|
410
|
+
_position.specific = {
|
|
411
|
+
triggerBoostRatio: triggerData.ratio,
|
|
412
|
+
targetBoostRatio: subData.targetRatio,
|
|
413
|
+
boostEnabled: isEnabled,
|
|
414
|
+
subId2: Number(subId),
|
|
415
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
420
|
+
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
|
|
421
|
+
|
|
422
|
+
return _position;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function parseCompoundV3LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
426
|
+
const _position = cloneDeep(position);
|
|
427
|
+
|
|
428
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
429
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
430
|
+
|
|
431
|
+
const subDataDecoder = position.chainId !== 1
|
|
432
|
+
? subDataService.compoundV3L2LeverageManagementSubData
|
|
433
|
+
: subDataService.compoundV3LeverageManagementSubData;
|
|
434
|
+
|
|
435
|
+
const triggerData = triggerService.compoundV3RatioTrigger.decode(subStruct.triggerData);
|
|
436
|
+
const subData = subDataDecoder.decode(subStruct.subData);
|
|
437
|
+
|
|
438
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
439
|
+
_position.strategyData.decoded.subData = subData;
|
|
440
|
+
|
|
441
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, triggerData.owner.toLowerCase(), triggerData.market);
|
|
442
|
+
|
|
443
|
+
const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
|
|
444
|
+
|
|
445
|
+
if (isRepay) {
|
|
446
|
+
_position.specific = {
|
|
447
|
+
triggerRepayRatio: triggerData.ratio,
|
|
448
|
+
targetRepayRatio: subData.targetRatio,
|
|
449
|
+
repayEnabled: true,
|
|
450
|
+
subId1: Number(subId),
|
|
451
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
452
|
+
};
|
|
453
|
+
} else {
|
|
454
|
+
_position.specific = {
|
|
455
|
+
triggerBoostRatio: triggerData.ratio,
|
|
456
|
+
targetBoostRatio: subData.targetRatio,
|
|
457
|
+
boostEnabled: isEnabled,
|
|
458
|
+
subId2: Number(subId),
|
|
459
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
464
|
+
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
|
|
465
|
+
|
|
466
|
+
return _position;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
function parseCompoundV3LeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
470
|
+
const _position = cloneDeep(position);
|
|
471
|
+
|
|
472
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
473
|
+
|
|
474
|
+
const triggerData = triggerService.compoundV3PriceTrigger.decode(subStruct.triggerData);
|
|
475
|
+
const subData = subDataService.compoundV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
476
|
+
|
|
477
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
478
|
+
_position.strategyData.decoded.subData = subData;
|
|
479
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, triggerData.market, triggerData.user, Math.random());
|
|
480
|
+
|
|
481
|
+
_position.specific = {
|
|
482
|
+
market: subData.market,
|
|
483
|
+
collToken: subData.collToken,
|
|
484
|
+
baseToken: subData.baseToken,
|
|
485
|
+
ratio: subData.targetRatio,
|
|
486
|
+
price: triggerData.price,
|
|
487
|
+
priceState: triggerData.priceState,
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
491
|
+
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagementOnPrice : Strategies.IdOverrides.LeverageManagementOnPrice;
|
|
492
|
+
|
|
493
|
+
return _position;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
function parseCompoundV3CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
497
|
+
const _position = cloneDeep(position);
|
|
498
|
+
|
|
499
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
500
|
+
|
|
501
|
+
const triggerData = triggerService.compoundV3PriceRangeTrigger.decode(subStruct.triggerData);
|
|
502
|
+
const subData = subDataService.compoundV3CloseSubData.decode(subStruct.subData);
|
|
503
|
+
|
|
504
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
505
|
+
_position.strategyData.decoded.subData = subData;
|
|
506
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, triggerData.market, Math.random());
|
|
507
|
+
|
|
508
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
509
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
510
|
+
_position.strategy.strategyId = isEOA ? Strategies.Identifiers.EoaCloseOnPrice : Strategies.Identifiers.CloseOnPrice;
|
|
511
|
+
|
|
512
|
+
_position.specific = {
|
|
513
|
+
market: subData.market,
|
|
514
|
+
collToken: subData.collToken,
|
|
515
|
+
baseToken: subData.baseToken,
|
|
516
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
517
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
518
|
+
takeProfitType,
|
|
519
|
+
stopLossType,
|
|
520
|
+
};
|
|
521
|
+
|
|
522
|
+
return _position;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function parseChickenBondsRebond(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
526
|
+
const _position = cloneDeep(position);
|
|
527
|
+
|
|
528
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
529
|
+
|
|
530
|
+
_position.strategyData.decoded.triggerData = triggerService.cBondsRebondTrigger.decode(subStruct.triggerData);
|
|
531
|
+
_position.strategyData.decoded.subData = subDataService.cBondsRebondSubData.decode(subStruct.subData);
|
|
532
|
+
|
|
533
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.strategyData.decoded.triggerData.bondId);
|
|
534
|
+
|
|
535
|
+
return _position;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
function parseLiquityBondProtection(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
539
|
+
const _position = cloneDeep(position);
|
|
540
|
+
|
|
541
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
542
|
+
|
|
543
|
+
const triggerData = triggerService.liquityRatioTrigger.decode(subStruct.triggerData);
|
|
544
|
+
|
|
545
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
546
|
+
_position.strategyData.decoded.subData = subDataService.liquityPaybackUsingChickenBondSubData.decode(subStruct.subData);
|
|
547
|
+
|
|
548
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner);
|
|
549
|
+
|
|
550
|
+
_position.specific = {
|
|
551
|
+
triggerRepayRatio: Number(triggerData.ratio),
|
|
552
|
+
targetRepayRatio: Infinity, // Unknown targetRepayRatio, uses all assets from chicken bond until trove min debt (2000LUSD)
|
|
553
|
+
repayEnabled: true,
|
|
554
|
+
};
|
|
555
|
+
return _position;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
function parseExchangeDca(position: Position.Automated, parseData: ParseData, chainId: ChainId): Position.Automated {
|
|
559
|
+
const _position = cloneDeep(position);
|
|
560
|
+
|
|
561
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
562
|
+
|
|
563
|
+
_position.strategyData.decoded.triggerData = triggerService.exchangeTimestampTrigger.decode(subStruct.triggerData);
|
|
564
|
+
_position.strategyData.decoded.subData = subDataService.exchangeDcaSubData.decode(subStruct.subData, chainId);
|
|
565
|
+
|
|
566
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
567
|
+
|
|
568
|
+
return _position;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
function parseExchangeLimitOrder(position: Position.Automated, parseData: ParseData, chainId: ChainId): Position.Automated {
|
|
572
|
+
const _position = cloneDeep(position);
|
|
573
|
+
|
|
574
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
575
|
+
|
|
576
|
+
_position.strategyData.decoded.subData = subDataService.exchangeLimitOrderSubData.decode(subStruct.subData, chainId);
|
|
577
|
+
const fromTokenDecimals = getAssetInfoByAddress(_position.strategyData.decoded.subData.fromToken, chainId).decimals;
|
|
578
|
+
const toTokenDecimals = getAssetInfoByAddress(_position.strategyData.decoded.subData.toToken, chainId).decimals;
|
|
579
|
+
_position.strategyData.decoded.triggerData = triggerService.exchangeOffchainPriceTrigger.decode(subStruct.triggerData, fromTokenDecimals, toTokenDecimals);
|
|
580
|
+
|
|
581
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
582
|
+
|
|
583
|
+
return _position;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
function parseLiquityLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
587
|
+
const _position = cloneDeep(position);
|
|
588
|
+
|
|
589
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
590
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
591
|
+
|
|
592
|
+
const triggerData = triggerService.liquityRatioTrigger.decode(subStruct.triggerData);
|
|
593
|
+
const subData = subDataService.liquityLeverageManagementSubData.decode(subStruct.subData);
|
|
594
|
+
|
|
595
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
596
|
+
_position.strategyData.decoded.subData = subData;
|
|
597
|
+
|
|
598
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner);
|
|
599
|
+
|
|
600
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
601
|
+
|
|
602
|
+
if (isRepay) {
|
|
603
|
+
_position.specific = {
|
|
604
|
+
triggerRepayRatio: triggerData.ratio,
|
|
605
|
+
targetRepayRatio: subData.targetRatio,
|
|
606
|
+
repayEnabled: true,
|
|
607
|
+
subId1: Number(subId),
|
|
608
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
609
|
+
};
|
|
610
|
+
} else {
|
|
611
|
+
_position.specific = {
|
|
612
|
+
triggerBoostRatio: triggerData.ratio,
|
|
613
|
+
targetBoostRatio: subData.targetRatio,
|
|
614
|
+
boostEnabled: isEnabled,
|
|
615
|
+
subId2: Number(subId),
|
|
616
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
621
|
+
|
|
622
|
+
return _position;
|
|
623
|
+
}
|
|
624
|
+
|
|
625
|
+
function parseLiquityV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
626
|
+
const _position = cloneDeep(position);
|
|
627
|
+
|
|
628
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
629
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
630
|
+
|
|
631
|
+
const triggerData = triggerService.liquityV2RatioTrigger.decode(subStruct.triggerData);
|
|
632
|
+
const subData = subDataService.liquityV2LeverageManagementSubData.decode(subStruct.subData);
|
|
633
|
+
|
|
634
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
635
|
+
_position.strategyData.decoded.subData = subData;
|
|
636
|
+
|
|
637
|
+
_position.positionId = getPositionId(
|
|
638
|
+
_position.chainId, _position.protocol.id, _position.owner, triggerData.troveId, triggerData.market,
|
|
639
|
+
);
|
|
640
|
+
|
|
641
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
642
|
+
|
|
643
|
+
if (isRepay) {
|
|
644
|
+
_position.specific = {
|
|
645
|
+
triggerRepayRatio: triggerData.ratio,
|
|
646
|
+
targetRepayRatio: subData.targetRatio,
|
|
647
|
+
repayEnabled: isEnabled,
|
|
648
|
+
subId1: Number(subId),
|
|
649
|
+
subHashRepay: subHash,
|
|
650
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
651
|
+
};
|
|
652
|
+
} else {
|
|
653
|
+
_position.specific = {
|
|
654
|
+
triggerBoostRatio: triggerData.ratio,
|
|
655
|
+
targetBoostRatio: subData.targetRatio,
|
|
656
|
+
boostEnabled: isEnabled,
|
|
657
|
+
subId2: Number(subId),
|
|
658
|
+
subHashBoost: subHash,
|
|
659
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
664
|
+
|
|
665
|
+
return _position;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
function parseSparkLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
669
|
+
const _position = cloneDeep(position);
|
|
670
|
+
|
|
671
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
672
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
673
|
+
|
|
674
|
+
const triggerData = triggerService.sparkRatioTrigger.decode(subStruct.triggerData);
|
|
675
|
+
const subData = subDataService.sparkLeverageManagementSubData.decode(subStruct.subData);
|
|
676
|
+
|
|
677
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
678
|
+
_position.strategyData.decoded.subData = subData;
|
|
679
|
+
|
|
680
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.market);
|
|
681
|
+
|
|
682
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
683
|
+
|
|
684
|
+
if (isRepay) {
|
|
685
|
+
_position.specific = {
|
|
686
|
+
triggerRepayRatio: triggerData.ratio,
|
|
687
|
+
targetRepayRatio: subData.targetRatio,
|
|
688
|
+
repayEnabled: true,
|
|
689
|
+
subId1: Number(subId),
|
|
690
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
691
|
+
};
|
|
692
|
+
} else {
|
|
693
|
+
_position.specific = {
|
|
694
|
+
triggerBoostRatio: triggerData.ratio,
|
|
695
|
+
targetBoostRatio: subData.targetRatio,
|
|
696
|
+
boostEnabled: isEnabled,
|
|
697
|
+
subId2: Number(subId),
|
|
698
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
699
|
+
};
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
703
|
+
|
|
704
|
+
return _position;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
function parseSparkCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
708
|
+
const _position = cloneDeep(position);
|
|
709
|
+
|
|
710
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
711
|
+
|
|
712
|
+
const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
|
|
713
|
+
const subData = subDataService.sparkQuotePriceSubData.decode(subStruct.subData);
|
|
714
|
+
|
|
715
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
716
|
+
_position.strategyData.decoded.subData = subData;
|
|
717
|
+
|
|
718
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, SPARK_MARKET_ADDRESSES[_position.chainId as ChainId.Ethereum]);
|
|
719
|
+
|
|
720
|
+
_position.specific = {
|
|
721
|
+
collAsset: subData.collAsset,
|
|
722
|
+
collAssetId: subData.collAssetId,
|
|
723
|
+
debtAsset: subData.debtAsset,
|
|
724
|
+
debtAssetId: subData.debtAssetId,
|
|
725
|
+
baseToken: triggerData.baseTokenAddress,
|
|
726
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
727
|
+
price: triggerData.price,
|
|
728
|
+
ratioState: triggerData.ratioState,
|
|
729
|
+
};
|
|
730
|
+
|
|
731
|
+
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
|
|
732
|
+
_position.specific.ratioState,
|
|
733
|
+
wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
|
|
734
|
+
wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
|
|
735
|
+
parseData.chainId,
|
|
736
|
+
);
|
|
737
|
+
|
|
738
|
+
_position.strategy.strategyId = isRatioStateOver(ratioState) ? Strategies.IdOverrides.TakeProfit : Strategies.IdOverrides.StopLoss;
|
|
739
|
+
|
|
740
|
+
return _position;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
function parseLiquitySavingsLiqProtection(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
744
|
+
const _position = cloneDeep(position);
|
|
745
|
+
|
|
746
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
747
|
+
|
|
748
|
+
const triggerData = triggerService.liquityRatioTrigger.decode(subStruct.triggerData);
|
|
749
|
+
const subData = subDataService.liquityRepayFromSavingsSubData.decode(subStruct.subData);
|
|
750
|
+
|
|
751
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
752
|
+
_position.strategyData.decoded.subData = subData;
|
|
753
|
+
|
|
754
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner);
|
|
755
|
+
|
|
756
|
+
_position.specific = {
|
|
757
|
+
triggerRepayRatio: triggerData.ratio,
|
|
758
|
+
targetRepayRatio: subData.targetRatio,
|
|
759
|
+
repayEnabled: true,
|
|
760
|
+
boostEnabled: false,
|
|
761
|
+
};
|
|
762
|
+
|
|
763
|
+
return _position;
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
function parseLiquityDebtInFrontRepay(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
767
|
+
const _position = cloneDeep(position);
|
|
768
|
+
|
|
769
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
770
|
+
|
|
771
|
+
const triggerData = triggerService.liquityDebtInFrontWithLimitTrigger.decode(subStruct.triggerData);
|
|
772
|
+
const subData = subDataService.liquityDebtInFrontRepaySubData.decode(subStruct.subData);
|
|
773
|
+
|
|
774
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
775
|
+
_position.strategyData.decoded.subData = subData;
|
|
776
|
+
|
|
777
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner);
|
|
778
|
+
|
|
779
|
+
_position.specific = {
|
|
780
|
+
debtInFrontMin: triggerData.debtInFrontMin,
|
|
781
|
+
targetRepayRatioIncrease: subData.targetRatioIncrease,
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
return _position;
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
function parseCrvUSDLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
788
|
+
const _position = cloneDeep(position);
|
|
789
|
+
|
|
790
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
791
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
792
|
+
const triggerData = triggerService.crvUSDRatioTrigger.decode(subStruct.triggerData);
|
|
793
|
+
const subData = subDataService.crvUSDLeverageManagementSubData.decode(subStruct.subData);
|
|
794
|
+
|
|
795
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
796
|
+
_position.strategyData.decoded.subData = subData;
|
|
797
|
+
|
|
798
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.controller);
|
|
799
|
+
|
|
800
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
801
|
+
|
|
802
|
+
if (isRepay) {
|
|
803
|
+
_position.specific = {
|
|
804
|
+
triggerRepayRatio: triggerData.ratio,
|
|
805
|
+
targetRepayRatio: subData.targetRatio,
|
|
806
|
+
repayEnabled: isEnabled,
|
|
807
|
+
subId1: Number(subId),
|
|
808
|
+
subHashRepay: subHash,
|
|
809
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
810
|
+
};
|
|
811
|
+
} else {
|
|
812
|
+
_position.specific = {
|
|
813
|
+
triggerBoostRatio: triggerData.ratio,
|
|
814
|
+
targetBoostRatio: subData.targetRatio,
|
|
815
|
+
boostEnabled: isEnabled,
|
|
816
|
+
subId2: Number(subId),
|
|
817
|
+
subHashBoost: subHash,
|
|
818
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
819
|
+
};
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
823
|
+
|
|
824
|
+
return _position;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
function parseCrvUSDPayback(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
828
|
+
const _position = cloneDeep(position);
|
|
829
|
+
|
|
830
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
831
|
+
const triggerData = triggerService.crvUsdHealthRatioTrigger.decode(subStruct.triggerData);
|
|
832
|
+
const subData = subDataService.crvUSDPaybackSubData.decode(subStruct.subData);
|
|
833
|
+
|
|
834
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
835
|
+
_position.strategyData.decoded.subData = subData;
|
|
836
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.controller, Math.random());
|
|
837
|
+
_position.strategy.strategyId = Strategies.Identifiers.Payback;
|
|
838
|
+
|
|
839
|
+
return _position;
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
function parseMorphoBlueLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
843
|
+
const _position = cloneDeep(position);
|
|
844
|
+
|
|
845
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
846
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
847
|
+
const triggerData = triggerService.morphoBlueRatioTrigger.decode(subStruct.triggerData);
|
|
848
|
+
const subData = subDataService.morphoBlueLeverageManagementSubData.decode(subStruct.subData);
|
|
849
|
+
|
|
850
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
851
|
+
_position.strategyData.decoded.subData = subData;
|
|
852
|
+
|
|
853
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, triggerData.owner.toLowerCase(), triggerData.marketId);
|
|
854
|
+
|
|
855
|
+
const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
|
|
856
|
+
|
|
857
|
+
if (isRepay) {
|
|
858
|
+
_position.specific = {
|
|
859
|
+
triggerRepayRatio: triggerData.ratio,
|
|
860
|
+
targetRepayRatio: subData.targetRatio,
|
|
861
|
+
repayEnabled: isEnabled,
|
|
862
|
+
subId1: Number(subId),
|
|
863
|
+
subHashRepay: subHash,
|
|
864
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
865
|
+
};
|
|
866
|
+
} else {
|
|
867
|
+
_position.specific = {
|
|
868
|
+
triggerBoostRatio: triggerData.ratio,
|
|
869
|
+
targetBoostRatio: subData.targetRatio,
|
|
870
|
+
boostEnabled: isEnabled,
|
|
871
|
+
subId2: Number(subId),
|
|
872
|
+
subHashBoost: subHash,
|
|
873
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
878
|
+
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
|
|
879
|
+
|
|
880
|
+
|
|
881
|
+
return _position;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
function parseMorphoBlueLeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
885
|
+
const _position = cloneDeep(position);
|
|
886
|
+
|
|
887
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
888
|
+
const triggerData = triggerService.morphoBluePriceTrigger.decode(subStruct.triggerData);
|
|
889
|
+
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
890
|
+
|
|
891
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
892
|
+
_position.strategyData.decoded.subData = subData;
|
|
893
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
894
|
+
|
|
895
|
+
const marketIdEncodedData = web3.eth.abi.encodeParameters(
|
|
896
|
+
['address', 'address', 'address', 'address', 'uint256'],
|
|
897
|
+
[
|
|
898
|
+
subData.loanToken,
|
|
899
|
+
subData.collToken,
|
|
900
|
+
subData.oracle,
|
|
901
|
+
subData.irm,
|
|
902
|
+
subData.lltv,
|
|
903
|
+
],
|
|
904
|
+
);
|
|
905
|
+
|
|
906
|
+
const marketId = web3.utils.keccak256(marketIdEncodedData);
|
|
907
|
+
|
|
908
|
+
_position.specific = {
|
|
909
|
+
subHash: _position.subHash,
|
|
910
|
+
marketId,
|
|
911
|
+
collAsset: subData.collToken,
|
|
912
|
+
debtAsset: subData.loanToken,
|
|
913
|
+
price: triggerData.price,
|
|
914
|
+
ratio: subData.targetRatio,
|
|
915
|
+
};
|
|
916
|
+
|
|
917
|
+
return _position;
|
|
918
|
+
}
|
|
919
|
+
|
|
920
|
+
function parseAaveV3LeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
921
|
+
const _position = cloneDeep(position);
|
|
922
|
+
|
|
923
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
924
|
+
|
|
925
|
+
const triggerData = triggerService.aaveV3QuotePriceTrigger.decode(subStruct.triggerData);
|
|
926
|
+
const subData = subDataService.aaveV3LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
927
|
+
|
|
928
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
929
|
+
_position.strategyData.decoded.subData = subData;
|
|
930
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
931
|
+
|
|
932
|
+
_position.specific = {
|
|
933
|
+
collAsset: subData.collAsset,
|
|
934
|
+
debtAsset: subData.debtAsset,
|
|
935
|
+
baseToken: triggerData.baseTokenAddress,
|
|
936
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
937
|
+
price: triggerData.price,
|
|
938
|
+
ratioState: triggerData.ratioState,
|
|
939
|
+
debtAssetId: subData.debtAssetId,
|
|
940
|
+
collAssetId: subData.collAssetId,
|
|
941
|
+
ratio: subData.targetRatio,
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
return _position;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
function parseLiquityV2CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
948
|
+
const _position = cloneDeep(position);
|
|
949
|
+
|
|
950
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
951
|
+
|
|
952
|
+
const triggerData = triggerService.closePriceTrigger.decode(subStruct.triggerData);
|
|
953
|
+
const subData = subDataService.liquityV2CloseSubData.decode(subStruct.subData);
|
|
954
|
+
|
|
955
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
956
|
+
_position.strategyData.decoded.subData = subData;
|
|
957
|
+
|
|
958
|
+
_position.positionId = getPositionId(
|
|
959
|
+
_position.chainId, _position.protocol.id, _position.owner, subData.troveId, subData.market,
|
|
960
|
+
);
|
|
961
|
+
|
|
962
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
963
|
+
|
|
964
|
+
// User can have:
|
|
965
|
+
// - Only TakeProfit
|
|
966
|
+
// - Only StopLoss
|
|
967
|
+
// - Both
|
|
968
|
+
_position.strategy.strategyId = Strategies.Identifiers.CloseOnPrice;
|
|
969
|
+
_position.specific = {
|
|
970
|
+
market: subData.market,
|
|
971
|
+
troveId: subData.troveId,
|
|
972
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
973
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
974
|
+
closeToAssetAddr: triggerData.tokenAddr,
|
|
975
|
+
takeProfitType,
|
|
976
|
+
stopLossType,
|
|
977
|
+
};
|
|
978
|
+
|
|
979
|
+
return _position;
|
|
980
|
+
}
|
|
981
|
+
|
|
982
|
+
function parseLiquityV2LeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
983
|
+
const _position = cloneDeep(position);
|
|
984
|
+
|
|
985
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
986
|
+
|
|
987
|
+
const triggerData = triggerService.liquityV2QuotePriceTrigger.decode(subStruct.triggerData);
|
|
988
|
+
const subData = subDataService.liquityV2LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
989
|
+
|
|
990
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
991
|
+
_position.strategyData.decoded.subData = subData;
|
|
992
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
993
|
+
|
|
994
|
+
_position.specific = {
|
|
995
|
+
subHash: _position.subHash,
|
|
996
|
+
market: subData.market,
|
|
997
|
+
troveId: subData.troveId,
|
|
998
|
+
collAsset: subData.collToken,
|
|
999
|
+
debtAsset: subData.boldToken,
|
|
1000
|
+
price: triggerData.price,
|
|
1001
|
+
ratio: subData.targetRatio,
|
|
1002
|
+
ratioState: triggerData.ratioState,
|
|
1003
|
+
};
|
|
1004
|
+
|
|
1005
|
+
return _position;
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
function parseLiquityV2Payback(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
1009
|
+
const _position = cloneDeep(position);
|
|
1010
|
+
|
|
1011
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
1012
|
+
const triggerData = triggerService.liquityV2RatioTrigger.decode(subStruct.triggerData);
|
|
1013
|
+
const subData = subDataService.liquityV2PaybackSubData.decode(subStruct.subData);
|
|
1014
|
+
|
|
1015
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
1016
|
+
_position.strategyData.decoded.subData = subData;
|
|
1017
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.troveId, triggerData.market);
|
|
1018
|
+
_position.strategy.strategyId = Strategies.Identifiers.Payback;
|
|
1019
|
+
|
|
1020
|
+
_position.specific = {
|
|
1021
|
+
subHash: _position.subHash,
|
|
1022
|
+
market: subData.market,
|
|
1023
|
+
troveId: subData.troveId,
|
|
1024
|
+
targetRatio: subData.targetRatio,
|
|
1025
|
+
triggerRatio: triggerData.ratio,
|
|
1026
|
+
};
|
|
1027
|
+
|
|
1028
|
+
return _position;
|
|
1029
|
+
}
|
|
1030
|
+
|
|
1031
|
+
function parseFluidT1LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
1032
|
+
const _position = cloneDeep(position);
|
|
1033
|
+
|
|
1034
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
1035
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
1036
|
+
|
|
1037
|
+
const triggerData = triggerService.fluidRatioTrigger.decode(subStruct.triggerData);
|
|
1038
|
+
const subData = subDataService.fluidLeverageManagementSubData.decode(subStruct.subData);
|
|
1039
|
+
|
|
1040
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
1041
|
+
_position.strategyData.decoded.subData = subData;
|
|
1042
|
+
|
|
1043
|
+
_position.positionId = getPositionId(
|
|
1044
|
+
_position.chainId, _position.protocol.id, _position.owner, triggerData.nftId, subData.vault,
|
|
1045
|
+
);
|
|
1046
|
+
|
|
1047
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
1048
|
+
|
|
1049
|
+
if (isRepay) {
|
|
1050
|
+
_position.specific = {
|
|
1051
|
+
triggerRepayRatio: triggerData.ratio,
|
|
1052
|
+
targetRepayRatio: subData.targetRatio,
|
|
1053
|
+
repayEnabled: isEnabled,
|
|
1054
|
+
subId1: Number(subId),
|
|
1055
|
+
subHashRepay: subHash,
|
|
1056
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
1057
|
+
};
|
|
1058
|
+
} else {
|
|
1059
|
+
_position.specific = {
|
|
1060
|
+
triggerBoostRatio: triggerData.ratio,
|
|
1061
|
+
targetBoostRatio: subData.targetRatio,
|
|
1062
|
+
boostEnabled: isEnabled,
|
|
1063
|
+
subId2: Number(subId),
|
|
1064
|
+
subHashBoost: subHash,
|
|
1065
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
1070
|
+
|
|
1071
|
+
return _position;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
1075
|
+
[ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
|
|
1076
|
+
[Strategies.Identifiers.SavingsLiqProtection]: parseMakerSavingsLiqProtection,
|
|
1077
|
+
[Strategies.Identifiers.CloseOnPriceToDebt]: parseMakerCloseOnPrice,
|
|
1078
|
+
[Strategies.Identifiers.CloseOnPriceToColl]: parseMakerCloseOnPrice,
|
|
1079
|
+
[Strategies.Identifiers.TrailingStopToColl]: parseMakerTrailingStop,
|
|
1080
|
+
[Strategies.Identifiers.TrailingStopToDebt]: parseMakerTrailingStop,
|
|
1081
|
+
[Strategies.Identifiers.Repay]: parseMakerLeverageManagement,
|
|
1082
|
+
[Strategies.Identifiers.Boost]: parseMakerLeverageManagement,
|
|
1083
|
+
},
|
|
1084
|
+
[ProtocolIdentifiers.StrategiesAutomation.Liquity]: {
|
|
1085
|
+
[Strategies.Identifiers.CloseOnPriceToColl]: parseLiquityCloseOnPrice,
|
|
1086
|
+
[Strategies.Identifiers.TrailingStopToColl]: parseLiquityTrailingStop,
|
|
1087
|
+
[Strategies.Identifiers.BondProtection]: parseLiquityBondProtection,
|
|
1088
|
+
[Strategies.Identifiers.Repay]: parseLiquityLeverageManagement,
|
|
1089
|
+
[Strategies.Identifiers.Boost]: parseLiquityLeverageManagement,
|
|
1090
|
+
[Strategies.Identifiers.SavingsDsrPayback]: parseLiquitySavingsLiqProtection,
|
|
1091
|
+
[Strategies.Identifiers.SavingsDsrSupply]: parseLiquitySavingsLiqProtection,
|
|
1092
|
+
[Strategies.Identifiers.DebtInFrontRepay]: parseLiquityDebtInFrontRepay,
|
|
1093
|
+
},
|
|
1094
|
+
[ProtocolIdentifiers.StrategiesAutomation.LiquityV2]: {
|
|
1095
|
+
[Strategies.Identifiers.Repay]: parseLiquityV2LeverageManagement,
|
|
1096
|
+
[Strategies.Identifiers.Boost]: parseLiquityV2LeverageManagement,
|
|
1097
|
+
[Strategies.Identifiers.CloseOnPrice]: parseLiquityV2CloseOnPrice,
|
|
1098
|
+
[Strategies.Identifiers.BoostOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
1099
|
+
[Strategies.Identifiers.RepayOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
1100
|
+
[Strategies.Identifiers.Payback]: parseLiquityV2Payback,
|
|
1101
|
+
},
|
|
1102
|
+
[ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
|
|
1103
|
+
[Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
|
|
1104
|
+
[Strategies.Identifiers.Boost]: parseAaveV2LeverageManagement,
|
|
1105
|
+
},
|
|
1106
|
+
[ProtocolIdentifiers.StrategiesAutomation.AaveV3]: {
|
|
1107
|
+
[Strategies.Identifiers.Repay]: parseAaveV3LeverageManagement,
|
|
1108
|
+
[Strategies.Identifiers.Boost]: parseAaveV3LeverageManagement,
|
|
1109
|
+
[Strategies.Identifiers.CloseToDebt]: parseAaveV3CloseOnPrice,
|
|
1110
|
+
[Strategies.Identifiers.CloseToDebtWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
|
|
1111
|
+
[Strategies.Identifiers.CloseToCollateral]: parseAaveV3CloseOnPrice,
|
|
1112
|
+
[Strategies.Identifiers.CloseToCollateralWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
|
|
1113
|
+
[Strategies.Identifiers.OpenOrderFromCollateral]: parseAaveV3LeverageManagementOnPrice,
|
|
1114
|
+
[Strategies.Identifiers.RepayOnPrice]: parseAaveV3LeverageManagementOnPrice,
|
|
1115
|
+
},
|
|
1116
|
+
[ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
|
|
1117
|
+
[Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
|
|
1118
|
+
[Strategies.Identifiers.Boost]: parseCompoundV2LeverageManagement,
|
|
1119
|
+
},
|
|
1120
|
+
[ProtocolIdentifiers.StrategiesAutomation.CompoundV3]: {
|
|
1121
|
+
[Strategies.Identifiers.Repay]: parseCompoundV3LeverageManagement,
|
|
1122
|
+
[Strategies.Identifiers.Boost]: parseCompoundV3LeverageManagement,
|
|
1123
|
+
[Strategies.Identifiers.EoaRepay]: parseCompoundV3LeverageManagement,
|
|
1124
|
+
[Strategies.Identifiers.EoaBoost]: parseCompoundV3LeverageManagement,
|
|
1125
|
+
[Strategies.Identifiers.RepayOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
1126
|
+
[Strategies.Identifiers.BoostOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
1127
|
+
[Strategies.Identifiers.EoaRepayOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
1128
|
+
[Strategies.Identifiers.EoaBoostOnPrice]: parseCompoundV3LeverageManagementOnPrice,
|
|
1129
|
+
[Strategies.Identifiers.CloseOnPrice]: parseCompoundV3CloseOnPrice,
|
|
1130
|
+
[Strategies.Identifiers.EoaCloseOnPrice]: parseCompoundV3CloseOnPrice,
|
|
1131
|
+
},
|
|
1132
|
+
[ProtocolIdentifiers.StrategiesAutomation.ChickenBonds]: {
|
|
1133
|
+
[Strategies.Identifiers.Rebond]: parseChickenBondsRebond,
|
|
1134
|
+
},
|
|
1135
|
+
[ProtocolIdentifiers.StrategiesAutomation.MorphoAaveV2]: {
|
|
1136
|
+
[Strategies.Identifiers.Repay]: parseMorphoAaveV2LeverageManagement,
|
|
1137
|
+
[Strategies.Identifiers.Boost]: parseMorphoAaveV2LeverageManagement,
|
|
1138
|
+
},
|
|
1139
|
+
[ProtocolIdentifiers.StrategiesAutomation.Exchange]: {
|
|
1140
|
+
[Strategies.Identifiers.Dca]: parseExchangeDca,
|
|
1141
|
+
[Strategies.Identifiers.LimitOrder]: parseExchangeLimitOrder,
|
|
1142
|
+
},
|
|
1143
|
+
[ProtocolIdentifiers.StrategiesAutomation.Spark]: {
|
|
1144
|
+
[Strategies.Identifiers.Repay]: parseSparkLeverageManagement,
|
|
1145
|
+
[Strategies.Identifiers.Boost]: parseSparkLeverageManagement,
|
|
1146
|
+
[Strategies.Identifiers.CloseToDebt]: parseSparkCloseOnPrice,
|
|
1147
|
+
[Strategies.Identifiers.CloseToCollateral]: parseSparkCloseOnPrice,
|
|
1148
|
+
},
|
|
1149
|
+
[ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
|
|
1150
|
+
[Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
|
|
1151
|
+
[Strategies.Identifiers.Boost]: parseCrvUSDLeverageManagement,
|
|
1152
|
+
[Strategies.Identifiers.Payback]: parseCrvUSDPayback,
|
|
1153
|
+
},
|
|
1154
|
+
[ProtocolIdentifiers.StrategiesAutomation.MorphoBlue]: {
|
|
1155
|
+
[Strategies.Identifiers.Repay]: parseMorphoBlueLeverageManagement,
|
|
1156
|
+
[Strategies.Identifiers.Boost]: parseMorphoBlueLeverageManagement,
|
|
1157
|
+
[Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
|
|
1158
|
+
[Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
|
|
1159
|
+
[Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
1160
|
+
},
|
|
1161
|
+
[ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
|
|
1162
|
+
[Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
|
|
1163
|
+
[Strategies.Identifiers.Boost]: parseFluidT1LeverageManagement,
|
|
1164
|
+
},
|
|
1165
|
+
};
|
|
1166
|
+
|
|
1167
|
+
function getParsingMethod(id: ProtocolIdentifiers.StrategiesAutomation, strategy: BundleOrStrategy) {
|
|
1168
|
+
return parsingMethodsMapping[id][strategy.strategyId];
|
|
1169
|
+
}
|
|
1170
|
+
|
|
1171
|
+
export function parseStrategiesAutomatedPosition(parseData: ParseData): Position.Automated | null {
|
|
1172
|
+
const {
|
|
1173
|
+
chainId, blockNumber, subscriptionEventData, strategiesSubsData,
|
|
1174
|
+
} = parseData;
|
|
1175
|
+
const {
|
|
1176
|
+
subStruct, proxy, subId, subHash,
|
|
1177
|
+
} = subscriptionEventData;
|
|
1178
|
+
const { isEnabled } = strategiesSubsData;
|
|
1179
|
+
|
|
1180
|
+
const id = subStruct.strategyOrBundleId as unknown as StrategyOrBundleIds;
|
|
1181
|
+
|
|
1182
|
+
const strategyOrBundleInfo = (
|
|
1183
|
+
subStruct.isBundle
|
|
1184
|
+
? BUNDLES_INFO[chainId][id as keyof BundleInfoUnion]
|
|
1185
|
+
: STRATEGIES_INFO[chainId][id as keyof StrategyInfoUnion]
|
|
1186
|
+
) as BundleOrStrategy;
|
|
1187
|
+
|
|
1188
|
+
if (!strategyOrBundleInfo) return null;
|
|
1189
|
+
|
|
1190
|
+
const position: Position.Automated = {
|
|
1191
|
+
isEnabled,
|
|
1192
|
+
chainId,
|
|
1193
|
+
subHash,
|
|
1194
|
+
blockNumber,
|
|
1195
|
+
positionId: 'positionId parsing not implemented.',
|
|
1196
|
+
subId: Number(subId),
|
|
1197
|
+
owner: proxy.toLowerCase(),
|
|
1198
|
+
protocol: {
|
|
1199
|
+
...strategyOrBundleInfo.protocol,
|
|
1200
|
+
},
|
|
1201
|
+
strategy: {
|
|
1202
|
+
isBundle: subStruct.isBundle,
|
|
1203
|
+
...strategyOrBundleInfo,
|
|
1204
|
+
},
|
|
1205
|
+
strategyData: {
|
|
1206
|
+
encoded: {
|
|
1207
|
+
triggerData: subStruct.triggerData,
|
|
1208
|
+
subData: subStruct.subData,
|
|
1209
|
+
},
|
|
1210
|
+
decoded: {
|
|
1211
|
+
triggerData: null,
|
|
1212
|
+
subData: null,
|
|
1213
|
+
},
|
|
1214
|
+
},
|
|
1215
|
+
specific: {},
|
|
1216
|
+
};
|
|
1217
|
+
|
|
1218
|
+
return getParsingMethod(position.protocol.id, position.strategy)(position, parseData, chainId);
|
|
1219
|
+
}
|