@defisaver/automation-sdk 3.2.0 → 3.2.2
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/.env +4 -5
- package/cjs/automation/private/StrategiesAutomation.js +5 -6
- package/cjs/constants/index.js +70 -0
- package/cjs/services/strategiesService.js +174 -0
- package/cjs/services/strategySubService.d.ts +11 -1
- package/cjs/services/strategySubService.js +42 -1
- package/cjs/services/subDataService.d.ts +63 -1
- package/cjs/services/subDataService.js +195 -1
- package/cjs/services/triggerService.d.ts +43 -0
- package/cjs/services/triggerService.js +81 -1
- package/cjs/services/utils.d.ts +6 -1
- package/cjs/services/utils.js +52 -1
- package/cjs/types/contracts/generated/SubStorage.d.ts +4 -0
- package/cjs/types/enums.d.ts +45 -5
- package/cjs/types/enums.js +45 -1
- package/cjs/types/index.d.ts +26 -2
- package/esm/automation/private/StrategiesAutomation.js +5 -6
- package/esm/constants/index.js +70 -0
- package/esm/services/strategiesService.js +172 -1
- package/esm/services/strategySubService.d.ts +11 -1
- package/esm/services/strategySubService.js +43 -2
- package/esm/services/subDataService.d.ts +63 -1
- package/esm/services/subDataService.js +195 -1
- package/esm/services/triggerService.d.ts +43 -0
- package/esm/services/triggerService.js +80 -0
- package/esm/services/utils.d.ts +6 -1
- package/esm/services/utils.js +50 -1
- package/esm/types/contracts/generated/SubStorage.d.ts +4 -0
- package/esm/types/enums.d.ts +45 -5
- package/esm/types/enums.js +44 -0
- package/esm/types/index.d.ts +26 -2
- package/package.json +3 -5
- package/src/automation/private/StrategiesAutomation.ts +5 -5
- package/src/constants/index.ts +70 -0
- package/src/services/strategiesService.ts +224 -1
- package/src/services/strategySubService.ts +111 -1
- package/src/services/subDataService.ts +271 -2
- package/src/services/triggerService.ts +125 -0
- package/src/services/utils.ts +60 -1
- package/src/types/enums.ts +44 -0
- package/src/types/index.ts +34 -1
package/esm/types/enums.js
CHANGED
|
@@ -21,6 +21,32 @@ export var BundleProtocols;
|
|
|
21
21
|
BundleProtocols["Yearn"] = "yearn";
|
|
22
22
|
BundleProtocols["Rari"] = "rari";
|
|
23
23
|
})(BundleProtocols || (BundleProtocols = {}));
|
|
24
|
+
export var CollActionType;
|
|
25
|
+
(function (CollActionType) {
|
|
26
|
+
CollActionType[CollActionType["SUPPLY"] = 0] = "SUPPLY";
|
|
27
|
+
CollActionType[CollActionType["WITHDRAW"] = 1] = "WITHDRAW";
|
|
28
|
+
})(CollActionType || (CollActionType = {}));
|
|
29
|
+
export var DebtActionType;
|
|
30
|
+
(function (DebtActionType) {
|
|
31
|
+
DebtActionType[DebtActionType["PAYBACK"] = 0] = "PAYBACK";
|
|
32
|
+
DebtActionType[DebtActionType["BORROW"] = 1] = "BORROW";
|
|
33
|
+
})(DebtActionType || (DebtActionType = {}));
|
|
34
|
+
export var CloseStrategyType;
|
|
35
|
+
(function (CloseStrategyType) {
|
|
36
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_IN_COLLATERAL"] = 0] = "TAKE_PROFIT_IN_COLLATERAL";
|
|
37
|
+
CloseStrategyType[CloseStrategyType["STOP_LOSS_IN_COLLATERAL"] = 1] = "STOP_LOSS_IN_COLLATERAL";
|
|
38
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_IN_DEBT"] = 2] = "TAKE_PROFIT_IN_DEBT";
|
|
39
|
+
CloseStrategyType[CloseStrategyType["STOP_LOSS_IN_DEBT"] = 3] = "STOP_LOSS_IN_DEBT";
|
|
40
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL"] = 4] = "TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL";
|
|
41
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT"] = 5] = "TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT";
|
|
42
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT"] = 6] = "TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT";
|
|
43
|
+
CloseStrategyType[CloseStrategyType["TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL"] = 7] = "TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL";
|
|
44
|
+
})(CloseStrategyType || (CloseStrategyType = {}));
|
|
45
|
+
export var CloseToAssetType;
|
|
46
|
+
(function (CloseToAssetType) {
|
|
47
|
+
CloseToAssetType[CloseToAssetType["COLLATERAL"] = 0] = "COLLATERAL";
|
|
48
|
+
CloseToAssetType[CloseToAssetType["DEBT"] = 1] = "DEBT";
|
|
49
|
+
})(CloseToAssetType || (CloseToAssetType = {}));
|
|
24
50
|
/**
|
|
25
51
|
* @dev Follow the naming convention:
|
|
26
52
|
* - Enum name consists of two parts, name and version
|
|
@@ -34,6 +60,7 @@ export var ProtocolIdentifiers;
|
|
|
34
60
|
(function (StrategiesAutomation) {
|
|
35
61
|
StrategiesAutomation["MakerDAO"] = "MakerDAO";
|
|
36
62
|
StrategiesAutomation["Liquity"] = "Liquity";
|
|
63
|
+
StrategiesAutomation["LiquityV2"] = "Liquity__V2";
|
|
37
64
|
StrategiesAutomation["ChickenBonds"] = "Chicken Bonds";
|
|
38
65
|
StrategiesAutomation["CompoundV2"] = "Compound__V2";
|
|
39
66
|
StrategiesAutomation["CompoundV3"] = "Compound__V3";
|
|
@@ -44,6 +71,7 @@ export var ProtocolIdentifiers;
|
|
|
44
71
|
StrategiesAutomation["Spark"] = "Spark";
|
|
45
72
|
StrategiesAutomation["CrvUSD"] = "CurveUSD";
|
|
46
73
|
StrategiesAutomation["MorphoBlue"] = "MorphoBlue";
|
|
74
|
+
StrategiesAutomation["FluidT1"] = "FluidT1";
|
|
47
75
|
})(StrategiesAutomation = ProtocolIdentifiers.StrategiesAutomation || (ProtocolIdentifiers.StrategiesAutomation = {}));
|
|
48
76
|
let LegacyAutomation;
|
|
49
77
|
(function (LegacyAutomation) {
|
|
@@ -70,6 +98,7 @@ export var Strategies;
|
|
|
70
98
|
MainnetIds[MainnetIds["LIQUITY_DSR_SUPPLY"] = 70] = "LIQUITY_DSR_SUPPLY";
|
|
71
99
|
MainnetIds[MainnetIds["LIQUITY_DEBT_IN_FRONT_REPAY"] = 75] = "LIQUITY_DEBT_IN_FRONT_REPAY";
|
|
72
100
|
MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
|
|
101
|
+
MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
|
|
73
102
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
74
103
|
let OptimismIds;
|
|
75
104
|
(function (OptimismIds) {
|
|
@@ -101,6 +130,7 @@ export var Strategies;
|
|
|
101
130
|
Identifiers["CloseToCollateralWithGasPrice"] = "close-to-collateral-with-gas-price";
|
|
102
131
|
Identifiers["CloseOnPriceToDebt"] = "close-on-price-to-debt";
|
|
103
132
|
Identifiers["CloseOnPriceToColl"] = "close-on-price-to-collateral";
|
|
133
|
+
Identifiers["CloseOnPrice"] = "close-on-price";
|
|
104
134
|
Identifiers["TrailingStopToColl"] = "trailing-stop-to-collateral";
|
|
105
135
|
Identifiers["TrailingStopToDebt"] = "trailing-stop-to-debt";
|
|
106
136
|
Identifiers["Rebond"] = "rebond";
|
|
@@ -111,6 +141,7 @@ export var Strategies;
|
|
|
111
141
|
Identifiers["DebtInFrontRepay"] = "debt-in-front-repay";
|
|
112
142
|
Identifiers["OpenOrderFromCollateral"] = "open-order-from-collateral";
|
|
113
143
|
Identifiers["OpenOrderFromDebt"] = "open-order-from-debt";
|
|
144
|
+
Identifiers["BoostOnPrice"] = "boost-on-price";
|
|
114
145
|
Identifiers["RepayOnPrice"] = "repay-on-price";
|
|
115
146
|
})(Identifiers = Strategies.Identifiers || (Strategies.Identifiers = {}));
|
|
116
147
|
let IdOverrides;
|
|
@@ -168,6 +199,14 @@ export var Bundles;
|
|
|
168
199
|
MainnetIds[MainnetIds["MORPHO_BLUE_EOA_BOOST"] = 35] = "MORPHO_BLUE_EOA_BOOST";
|
|
169
200
|
MainnetIds[MainnetIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 36] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
170
201
|
MainnetIds[MainnetIds["AAVE_V3_REPAY_ON_PRICE"] = 37] = "AAVE_V3_REPAY_ON_PRICE";
|
|
202
|
+
MainnetIds[MainnetIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 38] = "MORPHO_BLUE_BOOST_ON_PRICE";
|
|
203
|
+
MainnetIds[MainnetIds["LIQUITY_V2_REPAY"] = 39] = "LIQUITY_V2_REPAY";
|
|
204
|
+
MainnetIds[MainnetIds["LIQUITY_V2_BOOST"] = 40] = "LIQUITY_V2_BOOST";
|
|
205
|
+
MainnetIds[MainnetIds["LIQUITY_V2_CLOSE"] = 41] = "LIQUITY_V2_CLOSE";
|
|
206
|
+
MainnetIds[MainnetIds["LIQUITY_V2_REPAY_ON_PRICE"] = 42] = "LIQUITY_V2_REPAY_ON_PRICE";
|
|
207
|
+
MainnetIds[MainnetIds["LIQUITY_V2_BOOST_ON_PRICE"] = 43] = "LIQUITY_V2_BOOST_ON_PRICE";
|
|
208
|
+
MainnetIds[MainnetIds["FLUID_T1_REPAY"] = 44] = "FLUID_T1_REPAY";
|
|
209
|
+
MainnetIds[MainnetIds["FLUID_T1_BOOST"] = 45] = "FLUID_T1_BOOST";
|
|
171
210
|
})(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
|
|
172
211
|
let OptimismIds;
|
|
173
212
|
(function (OptimismIds) {
|
|
@@ -190,6 +229,9 @@ export var Bundles;
|
|
|
190
229
|
BaseIds[BaseIds["MORPHO_BLUE_BOOST"] = 9] = "MORPHO_BLUE_BOOST";
|
|
191
230
|
BaseIds[BaseIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 10] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
192
231
|
BaseIds[BaseIds["AAVE_V3_REPAY_ON_PRICE"] = 11] = "AAVE_V3_REPAY_ON_PRICE";
|
|
232
|
+
BaseIds[BaseIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 12] = "MORPHO_BLUE_BOOST_ON_PRICE";
|
|
233
|
+
BaseIds[BaseIds["FLUID_T1_REPAY"] = 13] = "FLUID_T1_REPAY";
|
|
234
|
+
BaseIds[BaseIds["FLUID_T1_BOOST"] = 14] = "FLUID_T1_BOOST";
|
|
193
235
|
})(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
|
|
194
236
|
let ArbitrumIds;
|
|
195
237
|
(function (ArbitrumIds) {
|
|
@@ -201,5 +243,7 @@ export var Bundles;
|
|
|
201
243
|
ArbitrumIds[ArbitrumIds["COMP_V3_SW_BOOST_BUNDLE"] = 5] = "COMP_V3_SW_BOOST_BUNDLE";
|
|
202
244
|
ArbitrumIds[ArbitrumIds["AAVE_V3_OPEN_ORDER_FROM_COLLATERAL"] = 6] = "AAVE_V3_OPEN_ORDER_FROM_COLLATERAL";
|
|
203
245
|
ArbitrumIds[ArbitrumIds["AAVE_V3_REPAY_ON_PRICE"] = 7] = "AAVE_V3_REPAY_ON_PRICE";
|
|
246
|
+
ArbitrumIds[ArbitrumIds["FLUID_T1_REPAY"] = 8] = "FLUID_T1_REPAY";
|
|
247
|
+
ArbitrumIds[ArbitrumIds["FLUID_T1_BOOST"] = 9] = "FLUID_T1_BOOST";
|
|
204
248
|
})(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
|
|
205
249
|
})(Bundles || (Bundles = {}));
|
package/esm/types/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type Web3 from 'web3';
|
|
|
2
2
|
import type { AbiItem } from 'web3-utils';
|
|
3
3
|
import type { BaseContract, BlockType } from './contracts/generated/types';
|
|
4
4
|
import type { Subscribe, StrategyModel } from './contracts/generated/SubStorage';
|
|
5
|
-
import type { ChainId, Strategies, Bundles, ProtocolIdentifiers, RatioState } from './enums';
|
|
5
|
+
import type { ChainId, Strategies, Bundles, ProtocolIdentifiers, RatioState, CloseToAssetType } from './enums';
|
|
6
6
|
export type PlaceholderType = any;
|
|
7
7
|
export type EthereumAddress = string;
|
|
8
8
|
export type BlockNumber = BlockType;
|
|
@@ -123,6 +123,10 @@ export declare namespace Position {
|
|
|
123
123
|
interface BoostOnPriceAave extends CloseOnPriceAave {
|
|
124
124
|
ratio: number;
|
|
125
125
|
}
|
|
126
|
+
interface BoostOnPriceMorpho extends Base {
|
|
127
|
+
marketId: string;
|
|
128
|
+
subHash: string;
|
|
129
|
+
}
|
|
126
130
|
interface CloseOnPriceWithMaximumGasPriceAave extends Base {
|
|
127
131
|
collAsset: EthereumAddress;
|
|
128
132
|
collAssetId: number;
|
|
@@ -134,6 +138,26 @@ export declare namespace Position {
|
|
|
134
138
|
maximumGasPrice: string;
|
|
135
139
|
ratioState: RatioState;
|
|
136
140
|
}
|
|
141
|
+
interface CloseOnPriceLiquityV2 extends Base {
|
|
142
|
+
market: EthereumAddress;
|
|
143
|
+
troveId: string;
|
|
144
|
+
stopLossPrice: string;
|
|
145
|
+
takeProfitPrice: string;
|
|
146
|
+
closeToAssetAddr: EthereumAddress;
|
|
147
|
+
stopLossType: CloseToAssetType | undefined;
|
|
148
|
+
takeProfitType: CloseToAssetType | undefined;
|
|
149
|
+
}
|
|
150
|
+
interface BoostOnPriceLiquityV2 extends Base {
|
|
151
|
+
market: EthereumAddress;
|
|
152
|
+
troveId: string;
|
|
153
|
+
subHash: string;
|
|
154
|
+
}
|
|
155
|
+
interface PaybackLiquityV2 extends Base {
|
|
156
|
+
market: EthereumAddress;
|
|
157
|
+
troveId: string;
|
|
158
|
+
targetRatio: number;
|
|
159
|
+
triggerRatio: number;
|
|
160
|
+
}
|
|
137
161
|
interface TrailingStop extends Base {
|
|
138
162
|
roundId: number;
|
|
139
163
|
triggerPercentage: number;
|
|
@@ -148,7 +172,7 @@ export declare namespace Position {
|
|
|
148
172
|
subHashRepay?: string;
|
|
149
173
|
}
|
|
150
174
|
}
|
|
151
|
-
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD;
|
|
175
|
+
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho | Specific.BoostOnPriceLiquityV2 | Specific.PaybackLiquityV2;
|
|
152
176
|
interface Automated {
|
|
153
177
|
chainId: ChainId;
|
|
154
178
|
positionId: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/automation-sdk",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -23,9 +23,8 @@
|
|
|
23
23
|
"repository": "https://github.com/defisaver/automation-sdk",
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@defisaver/
|
|
27
|
-
"@defisaver/
|
|
28
|
-
"@defisaver/tokens": "^1.5.50",
|
|
26
|
+
"@defisaver/sdk": "^1.2.20",
|
|
27
|
+
"@defisaver/tokens": "^1.5.56",
|
|
29
28
|
"@ethersproject/address": "^5.0.10",
|
|
30
29
|
"@ethersproject/solidity": "^5.0.9",
|
|
31
30
|
"decimal.js": "^10.4.3",
|
|
@@ -47,7 +46,6 @@
|
|
|
47
46
|
"husky": "^8.0.0",
|
|
48
47
|
"jsdoc-to-markdown": "^6.0.1",
|
|
49
48
|
"mocha": "^10.2.0",
|
|
50
|
-
"react": "^18.2.0",
|
|
51
49
|
"ts-node": "^10.9.1",
|
|
52
50
|
"typechain": "^8.1.0",
|
|
53
51
|
"typechain-target-web3-v1-3mihai3": "^6.0.1",
|
|
@@ -169,7 +169,6 @@ export default class StrategiesAutomation extends Automation {
|
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
171
|
if (mergeExtension.length > 0) {
|
|
172
|
-
console.error('Not all merge-able extensions were used', mergeExtension);
|
|
173
172
|
subscriptions = [...subscriptions, ...mergeExtension.map((s) => ({
|
|
174
173
|
...s,
|
|
175
174
|
subIds: [s.subId],
|
|
@@ -206,7 +205,7 @@ export default class StrategiesAutomation extends Automation {
|
|
|
206
205
|
|
|
207
206
|
const replaceSubWithUpdate = async (index: number) => {
|
|
208
207
|
const sub = strategiesSubs[index];
|
|
209
|
-
let latestUpdate = subscriptionEvents[index].returnValues;
|
|
208
|
+
let latestUpdate = { ...subscriptionEvents[index].returnValues };
|
|
210
209
|
|
|
211
210
|
if (latestUpdate.subHash !== sub?.strategySubHash) {
|
|
212
211
|
const updates = await this.getUpdateDataEventsFromSubStorage({
|
|
@@ -216,6 +215,7 @@ export default class StrategiesAutomation extends Automation {
|
|
|
216
215
|
latestUpdate = {
|
|
217
216
|
...latestUpdate, // Update is missing proxy, hence this
|
|
218
217
|
...updates?.[updates.length - 1]?.returnValues,
|
|
218
|
+
2: latestUpdate[2], // type issue
|
|
219
219
|
};
|
|
220
220
|
}
|
|
221
221
|
subscriptions.push(
|
|
@@ -228,12 +228,12 @@ export default class StrategiesAutomation extends Automation {
|
|
|
228
228
|
);
|
|
229
229
|
};
|
|
230
230
|
|
|
231
|
-
|
|
231
|
+
// eslint-disable-next-line func-names
|
|
232
|
+
const pool = new PromisePool(function* () {
|
|
232
233
|
for (let index = 0; index < strategiesSubs.length; index++) {
|
|
233
234
|
yield replaceSubWithUpdate(index);
|
|
234
235
|
}
|
|
235
|
-
};
|
|
236
|
-
const pool = new PromisePool(generatePromises as any, 50);
|
|
236
|
+
} as any, 50);
|
|
237
237
|
await pool.start();
|
|
238
238
|
|
|
239
239
|
if (options?.mergeSubs) {
|
package/src/constants/index.ts
CHANGED
|
@@ -113,6 +113,11 @@ export const MAINNET_STRATEGIES_INFO: MainnetStrategiesInfo = {
|
|
|
113
113
|
strategyId: Strategies.Identifiers.Payback,
|
|
114
114
|
protocol: PROTOCOLS.CrvUSD,
|
|
115
115
|
},
|
|
116
|
+
[Strategies.MainnetIds.LIQUITY_V2_PAYBACK]: {
|
|
117
|
+
strategyOrBundleId: Strategies.MainnetIds.LIQUITY_V2_PAYBACK,
|
|
118
|
+
strategyId: Strategies.Identifiers.Payback,
|
|
119
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
120
|
+
},
|
|
116
121
|
};
|
|
117
122
|
|
|
118
123
|
export const OPTIMISM_STRATEGIES_INFO: OptimismStrategiesInfo = {
|
|
@@ -376,6 +381,46 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
|
|
|
376
381
|
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
377
382
|
protocol: PROTOCOLS.AaveV3,
|
|
378
383
|
},
|
|
384
|
+
[Bundles.MainnetIds.LIQUITY_V2_REPAY]: {
|
|
385
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_REPAY,
|
|
386
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
387
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
388
|
+
},
|
|
389
|
+
[Bundles.MainnetIds.LIQUITY_V2_BOOST]: {
|
|
390
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_BOOST,
|
|
391
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
392
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
393
|
+
},
|
|
394
|
+
[Bundles.MainnetIds.LIQUITY_V2_CLOSE]: {
|
|
395
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_CLOSE,
|
|
396
|
+
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
397
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
398
|
+
},
|
|
399
|
+
[Bundles.MainnetIds.LIQUITY_V2_REPAY_ON_PRICE]: {
|
|
400
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_REPAY_ON_PRICE,
|
|
401
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
402
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
403
|
+
},
|
|
404
|
+
[Bundles.MainnetIds.LIQUITY_V2_BOOST_ON_PRICE]: {
|
|
405
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_V2_BOOST_ON_PRICE,
|
|
406
|
+
strategyId: Strategies.Identifiers.BoostOnPrice,
|
|
407
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
408
|
+
},
|
|
409
|
+
[Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE]: {
|
|
410
|
+
strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
411
|
+
strategyId: Strategies.Identifiers.BoostOnPrice,
|
|
412
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
413
|
+
},
|
|
414
|
+
[Bundles.MainnetIds.FLUID_T1_REPAY]: {
|
|
415
|
+
strategyOrBundleId: Bundles.MainnetIds.FLUID_T1_REPAY,
|
|
416
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
417
|
+
protocol: PROTOCOLS.FluidT1,
|
|
418
|
+
},
|
|
419
|
+
[Bundles.MainnetIds.FLUID_T1_BOOST]: {
|
|
420
|
+
strategyOrBundleId: Bundles.MainnetIds.FLUID_T1_BOOST,
|
|
421
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
422
|
+
protocol: PROTOCOLS.FluidT1,
|
|
423
|
+
},
|
|
379
424
|
};
|
|
380
425
|
|
|
381
426
|
export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
|
|
@@ -462,6 +507,21 @@ export const BASE_BUNDLES_INFO: BaseBundleInfo = {
|
|
|
462
507
|
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
463
508
|
protocol: PROTOCOLS.AaveV3,
|
|
464
509
|
},
|
|
510
|
+
[Bundles.BaseIds.MORPHO_BLUE_BOOST_ON_PRICE]: {
|
|
511
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_BOOST_ON_PRICE,
|
|
512
|
+
strategyId: Strategies.Identifiers.BoostOnPrice,
|
|
513
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
514
|
+
},
|
|
515
|
+
[Bundles.BaseIds.FLUID_T1_REPAY]: {
|
|
516
|
+
strategyOrBundleId: Bundles.BaseIds.FLUID_T1_REPAY,
|
|
517
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
518
|
+
protocol: PROTOCOLS.FluidT1,
|
|
519
|
+
},
|
|
520
|
+
[Bundles.BaseIds.FLUID_T1_BOOST]: {
|
|
521
|
+
strategyOrBundleId: Bundles.BaseIds.FLUID_T1_BOOST,
|
|
522
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
523
|
+
protocol: PROTOCOLS.FluidT1,
|
|
524
|
+
},
|
|
465
525
|
};
|
|
466
526
|
|
|
467
527
|
export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
|
|
@@ -505,6 +565,16 @@ export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
|
|
|
505
565
|
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
506
566
|
protocol: PROTOCOLS.AaveV3,
|
|
507
567
|
},
|
|
568
|
+
[Bundles.ArbitrumIds.FLUID_T1_REPAY]: {
|
|
569
|
+
strategyOrBundleId: Bundles.ArbitrumIds.FLUID_T1_REPAY,
|
|
570
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
571
|
+
protocol: PROTOCOLS.FluidT1,
|
|
572
|
+
},
|
|
573
|
+
[Bundles.ArbitrumIds.FLUID_T1_BOOST]: {
|
|
574
|
+
strategyOrBundleId: Bundles.ArbitrumIds.FLUID_T1_BOOST,
|
|
575
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
576
|
+
protocol: PROTOCOLS.FluidT1,
|
|
577
|
+
},
|
|
508
578
|
};
|
|
509
579
|
|
|
510
580
|
export const BUNDLES_INFO: BundlesInfo = {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getAssetInfoByAddress } from '@defisaver/tokens';
|
|
2
2
|
import { cloneDeep } from 'lodash';
|
|
3
3
|
|
|
4
|
+
import Web3 from 'web3';
|
|
4
5
|
import { BUNDLES_INFO, STRATEGIES_INFO } from '../constants';
|
|
5
6
|
import type {
|
|
6
7
|
Position, ParseData, StrategiesToProtocolVersionMapping, BundleOrStrategy, StrategyOrBundleIds,
|
|
@@ -9,11 +10,13 @@ import type {
|
|
|
9
10
|
import { ChainId, ProtocolIdentifiers, Strategies } from '../types/enums';
|
|
10
11
|
|
|
11
12
|
import {
|
|
12
|
-
getPositionId, getRatioStateInfoForAaveCloseStrategy, isRatioStateOver, wethToEthByAddress,
|
|
13
|
+
getPositionId, getRatioStateInfoForAaveCloseStrategy, getStopLossAndTakeProfitTypeByCloseStrategyType, isRatioStateOver, wethToEthByAddress,
|
|
13
14
|
} from './utils';
|
|
14
15
|
import * as subDataService from './subDataService';
|
|
15
16
|
import * as triggerService from './triggerService';
|
|
16
17
|
|
|
18
|
+
const web3 = new Web3();
|
|
19
|
+
|
|
17
20
|
const SPARK_MARKET_ADDRESSES = {
|
|
18
21
|
[ChainId.Ethereum]: '0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE',
|
|
19
22
|
};
|
|
@@ -563,6 +566,49 @@ function parseLiquityLeverageManagement(position: Position.Automated, parseData:
|
|
|
563
566
|
return _position;
|
|
564
567
|
}
|
|
565
568
|
|
|
569
|
+
function parseLiquityV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
570
|
+
const _position = cloneDeep(position);
|
|
571
|
+
|
|
572
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
573
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
574
|
+
|
|
575
|
+
const triggerData = triggerService.liquityV2RatioTrigger.decode(subStruct.triggerData);
|
|
576
|
+
const subData = subDataService.liquityV2LeverageManagementSubData.decode(subStruct.subData);
|
|
577
|
+
|
|
578
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
579
|
+
_position.strategyData.decoded.subData = subData;
|
|
580
|
+
|
|
581
|
+
_position.positionId = getPositionId(
|
|
582
|
+
_position.chainId, _position.protocol.id, _position.owner, triggerData.troveId, triggerData.market,
|
|
583
|
+
);
|
|
584
|
+
|
|
585
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
586
|
+
|
|
587
|
+
if (isRepay) {
|
|
588
|
+
_position.specific = {
|
|
589
|
+
triggerRepayRatio: triggerData.ratio,
|
|
590
|
+
targetRepayRatio: subData.targetRatio,
|
|
591
|
+
repayEnabled: isEnabled,
|
|
592
|
+
subId1: Number(subId),
|
|
593
|
+
subHashRepay: subHash,
|
|
594
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
595
|
+
};
|
|
596
|
+
} else {
|
|
597
|
+
_position.specific = {
|
|
598
|
+
triggerBoostRatio: triggerData.ratio,
|
|
599
|
+
targetBoostRatio: subData.targetRatio,
|
|
600
|
+
boostEnabled: isEnabled,
|
|
601
|
+
subId2: Number(subId),
|
|
602
|
+
subHashBoost: subHash,
|
|
603
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
604
|
+
};
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
608
|
+
|
|
609
|
+
return _position;
|
|
610
|
+
}
|
|
611
|
+
|
|
566
612
|
function parseSparkLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
567
613
|
const _position = cloneDeep(position);
|
|
568
614
|
|
|
@@ -779,6 +825,42 @@ function parseMorphoBlueLeverageManagement(position: Position.Automated, parseDa
|
|
|
779
825
|
return _position;
|
|
780
826
|
}
|
|
781
827
|
|
|
828
|
+
function parseMorphoBlueLeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
829
|
+
const _position = cloneDeep(position);
|
|
830
|
+
|
|
831
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
832
|
+
const triggerData = triggerService.morphoBluePriceTrigger.decode(subStruct.triggerData);
|
|
833
|
+
const subData = subDataService.morphoBlueLeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
834
|
+
|
|
835
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
836
|
+
_position.strategyData.decoded.subData = subData;
|
|
837
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
838
|
+
|
|
839
|
+
const marketIdEncodedData = web3.eth.abi.encodeParameters(
|
|
840
|
+
['address', 'address', 'address', 'address', 'uint256'],
|
|
841
|
+
[
|
|
842
|
+
subData.loanToken,
|
|
843
|
+
subData.collToken,
|
|
844
|
+
subData.oracle,
|
|
845
|
+
subData.irm,
|
|
846
|
+
subData.lltv,
|
|
847
|
+
],
|
|
848
|
+
);
|
|
849
|
+
|
|
850
|
+
const marketId = web3.utils.keccak256(marketIdEncodedData);
|
|
851
|
+
|
|
852
|
+
_position.specific = {
|
|
853
|
+
subHash: _position.subHash,
|
|
854
|
+
marketId,
|
|
855
|
+
collAsset: subData.collToken,
|
|
856
|
+
debtAsset: subData.loanToken,
|
|
857
|
+
price: triggerData.price,
|
|
858
|
+
ratio: subData.targetRatio,
|
|
859
|
+
};
|
|
860
|
+
|
|
861
|
+
return _position;
|
|
862
|
+
}
|
|
863
|
+
|
|
782
864
|
function parseAaveV3LeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
783
865
|
const _position = cloneDeep(position);
|
|
784
866
|
|
|
@@ -806,6 +888,134 @@ function parseAaveV3LeverageManagementOnPrice(position: Position.Automated, pars
|
|
|
806
888
|
return _position;
|
|
807
889
|
}
|
|
808
890
|
|
|
891
|
+
function parseLiquityV2CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
892
|
+
const _position = cloneDeep(position);
|
|
893
|
+
|
|
894
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
895
|
+
|
|
896
|
+
const triggerData = triggerService.closePriceTrigger.decode(subStruct.triggerData);
|
|
897
|
+
const subData = subDataService.liquityV2CloseSubData.decode(subStruct.subData);
|
|
898
|
+
|
|
899
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
900
|
+
_position.strategyData.decoded.subData = subData;
|
|
901
|
+
|
|
902
|
+
_position.positionId = getPositionId(
|
|
903
|
+
_position.chainId, _position.protocol.id, _position.owner, subData.troveId, subData.market,
|
|
904
|
+
);
|
|
905
|
+
|
|
906
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
907
|
+
|
|
908
|
+
// User can have:
|
|
909
|
+
// - Only TakeProfit
|
|
910
|
+
// - Only StopLoss
|
|
911
|
+
// - Both
|
|
912
|
+
// TODO: see on frontend what specific data we need here because stop-loss and take-profit is one bundle now
|
|
913
|
+
_position.strategy.strategyId = Strategies.Identifiers.CloseOnPrice;
|
|
914
|
+
_position.specific = {
|
|
915
|
+
market: subData.market,
|
|
916
|
+
troveId: subData.troveId,
|
|
917
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
918
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
919
|
+
closeToAssetAddr: triggerData.tokenAddr,
|
|
920
|
+
takeProfitType,
|
|
921
|
+
stopLossType,
|
|
922
|
+
};
|
|
923
|
+
|
|
924
|
+
return _position;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
function parseLiquityV2LeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
928
|
+
const _position = cloneDeep(position);
|
|
929
|
+
|
|
930
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
931
|
+
|
|
932
|
+
const triggerData = triggerService.liquityV2QuotePriceTrigger.decode(subStruct.triggerData);
|
|
933
|
+
const subData = subDataService.liquityV2LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
934
|
+
|
|
935
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
936
|
+
_position.strategyData.decoded.subData = subData;
|
|
937
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
938
|
+
|
|
939
|
+
_position.specific = {
|
|
940
|
+
subHash: _position.subHash,
|
|
941
|
+
market: subData.market,
|
|
942
|
+
troveId: subData.troveId,
|
|
943
|
+
collAsset: subData.collToken,
|
|
944
|
+
debtAsset: subData.boldToken,
|
|
945
|
+
price: triggerData.price,
|
|
946
|
+
ratio: subData.targetRatio,
|
|
947
|
+
ratioState: triggerData.ratioState,
|
|
948
|
+
};
|
|
949
|
+
|
|
950
|
+
return _position;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
function parseLiquityV2Payback(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
954
|
+
const _position = cloneDeep(position);
|
|
955
|
+
|
|
956
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
957
|
+
const triggerData = triggerService.liquityV2RatioTrigger.decode(subStruct.triggerData);
|
|
958
|
+
const subData = subDataService.liquityV2PaybackSubData.decode(subStruct.subData);
|
|
959
|
+
|
|
960
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
961
|
+
_position.strategyData.decoded.subData = subData;
|
|
962
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.troveId, triggerData.market);
|
|
963
|
+
_position.strategy.strategyId = Strategies.Identifiers.Payback;
|
|
964
|
+
|
|
965
|
+
_position.specific = {
|
|
966
|
+
subHash: _position.subHash,
|
|
967
|
+
market: subData.market,
|
|
968
|
+
troveId: subData.troveId,
|
|
969
|
+
targetRatio: subData.targetRatio,
|
|
970
|
+
triggerRatio: triggerData.ratio,
|
|
971
|
+
};
|
|
972
|
+
|
|
973
|
+
return _position;
|
|
974
|
+
}
|
|
975
|
+
|
|
976
|
+
function parseFluidT1LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
977
|
+
const _position = cloneDeep(position);
|
|
978
|
+
|
|
979
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
980
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
981
|
+
|
|
982
|
+
const triggerData = triggerService.fluidRatioTrigger.decode(subStruct.triggerData);
|
|
983
|
+
const subData = subDataService.fluidLeverageManagementSubData.decode(subStruct.subData);
|
|
984
|
+
|
|
985
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
986
|
+
_position.strategyData.decoded.subData = subData;
|
|
987
|
+
|
|
988
|
+
_position.positionId = getPositionId(
|
|
989
|
+
_position.chainId, _position.protocol.id, _position.owner, triggerData.nftId, subData.vault,
|
|
990
|
+
);
|
|
991
|
+
|
|
992
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
993
|
+
|
|
994
|
+
if (isRepay) {
|
|
995
|
+
_position.specific = {
|
|
996
|
+
triggerRepayRatio: triggerData.ratio,
|
|
997
|
+
targetRepayRatio: subData.targetRatio,
|
|
998
|
+
repayEnabled: isEnabled,
|
|
999
|
+
subId1: Number(subId),
|
|
1000
|
+
subHashRepay: subHash,
|
|
1001
|
+
mergeWithId: Strategies.Identifiers.Boost,
|
|
1002
|
+
};
|
|
1003
|
+
} else {
|
|
1004
|
+
_position.specific = {
|
|
1005
|
+
triggerBoostRatio: triggerData.ratio,
|
|
1006
|
+
targetBoostRatio: subData.targetRatio,
|
|
1007
|
+
boostEnabled: isEnabled,
|
|
1008
|
+
subId2: Number(subId),
|
|
1009
|
+
subHashBoost: subHash,
|
|
1010
|
+
mergeId: Strategies.Identifiers.Boost,
|
|
1011
|
+
};
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
1015
|
+
|
|
1016
|
+
return _position;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
809
1019
|
const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
810
1020
|
[ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
|
|
811
1021
|
[Strategies.Identifiers.SavingsLiqProtection]: parseMakerSavingsLiqProtection,
|
|
@@ -826,6 +1036,14 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
826
1036
|
[Strategies.Identifiers.SavingsDsrSupply]: parseLiquitySavingsLiqProtection,
|
|
827
1037
|
[Strategies.Identifiers.DebtInFrontRepay]: parseLiquityDebtInFrontRepay,
|
|
828
1038
|
},
|
|
1039
|
+
[ProtocolIdentifiers.StrategiesAutomation.LiquityV2]: {
|
|
1040
|
+
[Strategies.Identifiers.Repay]: parseLiquityV2LeverageManagement,
|
|
1041
|
+
[Strategies.Identifiers.Boost]: parseLiquityV2LeverageManagement,
|
|
1042
|
+
[Strategies.Identifiers.CloseOnPrice]: parseLiquityV2CloseOnPrice,
|
|
1043
|
+
[Strategies.Identifiers.BoostOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
1044
|
+
[Strategies.Identifiers.RepayOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
1045
|
+
[Strategies.Identifiers.Payback]: parseLiquityV2Payback,
|
|
1046
|
+
},
|
|
829
1047
|
[ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
|
|
830
1048
|
[Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
|
|
831
1049
|
[Strategies.Identifiers.Boost]: parseAaveV2LeverageManagement,
|
|
@@ -877,6 +1095,11 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
877
1095
|
[Strategies.Identifiers.Boost]: parseMorphoBlueLeverageManagement,
|
|
878
1096
|
[Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
|
|
879
1097
|
[Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
|
|
1098
|
+
[Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
1099
|
+
},
|
|
1100
|
+
[ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
|
|
1101
|
+
[Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
|
|
1102
|
+
[Strategies.Identifiers.Boost]: parseFluidT1LeverageManagement,
|
|
880
1103
|
},
|
|
881
1104
|
};
|
|
882
1105
|
|