@defisaver/automation-sdk 2.0.4 → 2.0.6
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/esm/automation/private/StrategiesAutomation.js +1 -1
- package/esm/constants/index.js +10 -0
- package/esm/services/strategiesService.js +26 -0
- package/esm/services/strategySubService.d.ts +12 -0
- package/esm/services/strategySubService.js +7 -0
- package/esm/services/triggerService.d.ts +11 -1
- package/esm/services/triggerService.js +37 -9
- package/esm/services/triggerService.test.d.ts +1 -0
- package/esm/services/triggerService.test.js +719 -0
- package/esm/types/enums.d.ts +6 -0
- package/esm/types/enums.js +6 -0
- package/esm/types/index.d.ts +12 -1
- package/package.json +2 -2
- package/src/automation/private/StrategiesAutomation.ts +1 -1
- package/src/constants/index.ts +10 -0
- package/src/services/strategiesService.ts +39 -0
- package/src/services/strategySubService.ts +22 -0
- package/src/services/triggerService.test.ts +785 -0
- package/src/services/triggerService.ts +50 -7
- package/src/types/enums.ts +6 -0
- package/src/types/index.ts +14 -1
- package/umd/index.js +172 -79
package/esm/types/enums.d.ts
CHANGED
|
@@ -74,7 +74,9 @@ export declare namespace Strategies {
|
|
|
74
74
|
Boost = "boost",
|
|
75
75
|
EoaBoost = "eoa-boost",
|
|
76
76
|
CloseToDebt = "close-to-debt",
|
|
77
|
+
CloseToDebtWithGasPrice = "close-to-debt-with-gas-price",
|
|
77
78
|
CloseToCollateral = "close-to-collateral",
|
|
79
|
+
CloseToCollateralWithGasPrice = "close-to-collateral-with-gas-price",
|
|
78
80
|
CloseOnPriceToDebt = "close-on-price-to-debt",
|
|
79
81
|
CloseOnPriceToColl = "close-on-price-to-collateral",
|
|
80
82
|
TrailingStopToColl = "trailing-stop-to-collateral",
|
|
@@ -87,6 +89,8 @@ export declare namespace Strategies {
|
|
|
87
89
|
enum IdOverrides {
|
|
88
90
|
TakeProfit = "take-profit",
|
|
89
91
|
StopLoss = "stop-loss",
|
|
92
|
+
TakeProfitWithGasPrice = "take-profit-with-gas-price",
|
|
93
|
+
StopLossWithGasPrice = "stop-loss-with-gas-price",
|
|
90
94
|
TrailingStop = "trailing-stop",
|
|
91
95
|
LeverageManagement = "leverage-management",
|
|
92
96
|
EoaLeverageManagement = "leverage-management-eoa"
|
|
@@ -107,7 +111,9 @@ export declare namespace Bundles {
|
|
|
107
111
|
MAKER_REPAY = 10,
|
|
108
112
|
MAKER_BOOST = 11,
|
|
109
113
|
AAVE_V3_CLOSE_TO_DEBT = 12,
|
|
114
|
+
AAVE_V3_CLOSE_TO_DEBT_WITH_GAS_PRICE = 24,
|
|
110
115
|
AAVE_V3_CLOSE_TO_COLLATERAL = 13,
|
|
116
|
+
AAVE_V3_CLOSE_TO_COLLATERAL_WITH_GAS_PRICE = 25,
|
|
111
117
|
MORPHO_AAVE_V2_REPAY = 14,
|
|
112
118
|
MORPHO_AAVE_V2_BOOST = 15,
|
|
113
119
|
LIQUITY_REPAY = 16,
|
package/esm/types/enums.js
CHANGED
|
@@ -89,7 +89,9 @@ var Strategies;
|
|
|
89
89
|
Identifiers["Boost"] = "boost";
|
|
90
90
|
Identifiers["EoaBoost"] = "eoa-boost";
|
|
91
91
|
Identifiers["CloseToDebt"] = "close-to-debt";
|
|
92
|
+
Identifiers["CloseToDebtWithGasPrice"] = "close-to-debt-with-gas-price";
|
|
92
93
|
Identifiers["CloseToCollateral"] = "close-to-collateral";
|
|
94
|
+
Identifiers["CloseToCollateralWithGasPrice"] = "close-to-collateral-with-gas-price";
|
|
93
95
|
Identifiers["CloseOnPriceToDebt"] = "close-on-price-to-debt";
|
|
94
96
|
Identifiers["CloseOnPriceToColl"] = "close-on-price-to-collateral";
|
|
95
97
|
Identifiers["TrailingStopToColl"] = "trailing-stop-to-collateral";
|
|
@@ -103,6 +105,8 @@ var Strategies;
|
|
|
103
105
|
(function (IdOverrides) {
|
|
104
106
|
IdOverrides["TakeProfit"] = "take-profit";
|
|
105
107
|
IdOverrides["StopLoss"] = "stop-loss";
|
|
108
|
+
IdOverrides["TakeProfitWithGasPrice"] = "take-profit-with-gas-price";
|
|
109
|
+
IdOverrides["StopLossWithGasPrice"] = "stop-loss-with-gas-price";
|
|
106
110
|
IdOverrides["TrailingStop"] = "trailing-stop";
|
|
107
111
|
IdOverrides["LeverageManagement"] = "leverage-management";
|
|
108
112
|
IdOverrides["EoaLeverageManagement"] = "leverage-management-eoa";
|
|
@@ -125,7 +129,9 @@ var Bundles;
|
|
|
125
129
|
MainnetIds[MainnetIds["MAKER_REPAY"] = 10] = "MAKER_REPAY";
|
|
126
130
|
MainnetIds[MainnetIds["MAKER_BOOST"] = 11] = "MAKER_BOOST";
|
|
127
131
|
MainnetIds[MainnetIds["AAVE_V3_CLOSE_TO_DEBT"] = 12] = "AAVE_V3_CLOSE_TO_DEBT";
|
|
132
|
+
MainnetIds[MainnetIds["AAVE_V3_CLOSE_TO_DEBT_WITH_GAS_PRICE"] = 24] = "AAVE_V3_CLOSE_TO_DEBT_WITH_GAS_PRICE";
|
|
128
133
|
MainnetIds[MainnetIds["AAVE_V3_CLOSE_TO_COLLATERAL"] = 13] = "AAVE_V3_CLOSE_TO_COLLATERAL";
|
|
134
|
+
MainnetIds[MainnetIds["AAVE_V3_CLOSE_TO_COLLATERAL_WITH_GAS_PRICE"] = 25] = "AAVE_V3_CLOSE_TO_COLLATERAL_WITH_GAS_PRICE";
|
|
129
135
|
MainnetIds[MainnetIds["MORPHO_AAVE_V2_REPAY"] = 14] = "MORPHO_AAVE_V2_REPAY";
|
|
130
136
|
MainnetIds[MainnetIds["MORPHO_AAVE_V2_BOOST"] = 15] = "MORPHO_AAVE_V2_BOOST";
|
|
131
137
|
MainnetIds[MainnetIds["LIQUITY_REPAY"] = 16] = "LIQUITY_REPAY";
|
package/esm/types/index.d.ts
CHANGED
|
@@ -116,13 +116,24 @@ export declare namespace Position {
|
|
|
116
116
|
price: string;
|
|
117
117
|
ratioState: RatioState;
|
|
118
118
|
}
|
|
119
|
+
interface CloseOnPriceWithMaximumGasPriceAave extends Base {
|
|
120
|
+
collAsset: EthereumAddress;
|
|
121
|
+
collAssetId: number;
|
|
122
|
+
debtAsset: EthereumAddress;
|
|
123
|
+
debtAssetId: number;
|
|
124
|
+
baseToken: EthereumAddress;
|
|
125
|
+
quoteToken: EthereumAddress;
|
|
126
|
+
price: string;
|
|
127
|
+
maximumGasPrice: string;
|
|
128
|
+
ratioState: RatioState;
|
|
129
|
+
}
|
|
119
130
|
interface TrailingStop extends Base {
|
|
120
131
|
roundId: number;
|
|
121
132
|
triggerPercentage: number;
|
|
122
133
|
closeToAssetAddr: EthereumAddress;
|
|
123
134
|
}
|
|
124
135
|
}
|
|
125
|
-
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave;
|
|
136
|
+
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave;
|
|
126
137
|
interface Automated {
|
|
127
138
|
chainId: ChainId;
|
|
128
139
|
owner: EthereumAddress;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/automation-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./umd/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"lint": "node_modules/.bin/eslint ./src",
|
|
16
16
|
"gtc": "node scripts/generateContractTypes.js",
|
|
17
17
|
"prepare": "husky install && npm run gtc",
|
|
18
|
-
"test": "mocha \"./src/**/*.test.ts\" --
|
|
18
|
+
"test": "mocha \"./src/**/*.test.ts\" --require ts-node/register --extension ts"
|
|
19
19
|
},
|
|
20
20
|
"author": "DeFi Saver",
|
|
21
21
|
"repository": "https://github.com/defisaver/automation-sdk",
|
|
@@ -97,7 +97,7 @@ export default class StrategiesAutomation extends Automation {
|
|
|
97
97
|
|
|
98
98
|
if (subscriptionEvents) {
|
|
99
99
|
// @ts-ignore
|
|
100
|
-
const strategiesSubs = await this.getStrategiesSubs(subscriptionEvents.map((e) => e.returnValues.subId), _options.
|
|
100
|
+
const strategiesSubs = await this.getStrategiesSubs(subscriptionEvents.map((e) => e.returnValues.subId), _options.toBlock);
|
|
101
101
|
|
|
102
102
|
subscriptions = await Promise.all(strategiesSubs.map(async (sub, index: number) => {
|
|
103
103
|
let latestUpdate = subscriptionEvents[index].returnValues;
|
package/src/constants/index.ts
CHANGED
|
@@ -203,11 +203,21 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
|
|
|
203
203
|
strategyId: Strategies.Identifiers.CloseToDebt,
|
|
204
204
|
protocol: PROTOCOLS.AaveV3,
|
|
205
205
|
},
|
|
206
|
+
[Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT_WITH_GAS_PRICE]: {
|
|
207
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_CLOSE_TO_DEBT_WITH_GAS_PRICE,
|
|
208
|
+
strategyId: Strategies.Identifiers.CloseToDebtWithGasPrice,
|
|
209
|
+
protocol: PROTOCOLS.AaveV3,
|
|
210
|
+
},
|
|
206
211
|
[Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL]: {
|
|
207
212
|
strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL,
|
|
208
213
|
strategyId: Strategies.Identifiers.CloseToCollateral,
|
|
209
214
|
protocol: PROTOCOLS.AaveV3,
|
|
210
215
|
},
|
|
216
|
+
[Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL_WITH_GAS_PRICE]: {
|
|
217
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V3_CLOSE_TO_COLLATERAL_WITH_GAS_PRICE,
|
|
218
|
+
strategyId: Strategies.Identifiers.CloseToCollateralWithGasPrice,
|
|
219
|
+
protocol: PROTOCOLS.AaveV3,
|
|
220
|
+
},
|
|
211
221
|
[Bundles.MainnetIds.MORPHO_AAVE_V2_REPAY]: {
|
|
212
222
|
strategyOrBundleId: Bundles.MainnetIds.MORPHO_AAVE_V2_REPAY,
|
|
213
223
|
strategyId: Strategies.Identifiers.Repay,
|
|
@@ -299,6 +299,43 @@ function parseAaveV3CloseOnPrice(position: Position.Automated, parseData: ParseD
|
|
|
299
299
|
return _position;
|
|
300
300
|
}
|
|
301
301
|
|
|
302
|
+
function parseAaveV3CloseOnPriceWithMaximumGasPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
303
|
+
const _position = cloneDeep(position);
|
|
304
|
+
|
|
305
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
306
|
+
|
|
307
|
+
const triggerData = triggerService.aaveV3QuotePriceWithMaximumGasPriceTrigger.decode(subStruct.triggerData);
|
|
308
|
+
const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
|
|
309
|
+
|
|
310
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
311
|
+
_position.strategyData.decoded.subData = subData;
|
|
312
|
+
|
|
313
|
+
_position.specific = {
|
|
314
|
+
collAsset: subData.collAsset,
|
|
315
|
+
collAssetId: subData.collAssetId,
|
|
316
|
+
debtAsset: subData.debtAsset,
|
|
317
|
+
debtAssetId: subData.debtAssetId,
|
|
318
|
+
baseToken: triggerData.baseTokenAddress,
|
|
319
|
+
quoteToken: triggerData.quoteTokenAddress,
|
|
320
|
+
price: triggerData.price,
|
|
321
|
+
maximumGasPrice: triggerData.maximumGasPrice,
|
|
322
|
+
ratioState: triggerData.ratioState,
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
|
|
326
|
+
_position.specific.ratioState,
|
|
327
|
+
wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
|
|
328
|
+
wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
|
|
329
|
+
parseData.chainId,
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
_position.strategy.strategyId = isRatioStateOver(ratioState)
|
|
333
|
+
? Strategies.IdOverrides.TakeProfitWithGasPrice
|
|
334
|
+
: Strategies.IdOverrides.StopLossWithGasPrice;
|
|
335
|
+
|
|
336
|
+
return _position;
|
|
337
|
+
}
|
|
338
|
+
|
|
302
339
|
function parseCompoundV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
303
340
|
const _position = cloneDeep(position);
|
|
304
341
|
|
|
@@ -579,7 +616,9 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
579
616
|
[Strategies.Identifiers.Repay]: parseAaveV3LeverageManagement,
|
|
580
617
|
[Strategies.Identifiers.Boost]: parseAaveV3LeverageManagement,
|
|
581
618
|
[Strategies.Identifiers.CloseToDebt]: parseAaveV3CloseOnPrice,
|
|
619
|
+
[Strategies.Identifiers.CloseToDebtWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
|
|
582
620
|
[Strategies.Identifiers.CloseToCollateral]: parseAaveV3CloseOnPrice,
|
|
621
|
+
[Strategies.Identifiers.CloseToCollateralWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
|
|
583
622
|
},
|
|
584
623
|
[ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
|
|
585
624
|
[Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
|
|
@@ -256,6 +256,28 @@ export const aaveV3Encode = {
|
|
|
256
256
|
} = triggerData;
|
|
257
257
|
const triggerDataEncoded = triggerService.aaveV3QuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, ratioState);
|
|
258
258
|
|
|
259
|
+
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
260
|
+
},
|
|
261
|
+
closeToAssetWithMaximumGasPrice(
|
|
262
|
+
strategyOrBundleId: number,
|
|
263
|
+
isBundle: boolean = true,
|
|
264
|
+
triggerData: {
|
|
265
|
+
baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState, maximumGasPrice: number
|
|
266
|
+
},
|
|
267
|
+
subData: {
|
|
268
|
+
collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number,
|
|
269
|
+
},
|
|
270
|
+
) {
|
|
271
|
+
const {
|
|
272
|
+
collAsset, collAssetId, debtAsset, debtAssetId,
|
|
273
|
+
} = subData;
|
|
274
|
+
const subDataEncoded = subDataService.aaveV3QuotePriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId);
|
|
275
|
+
|
|
276
|
+
const {
|
|
277
|
+
baseTokenAddress, quoteTokenAddress, price, maximumGasPrice, ratioState,
|
|
278
|
+
} = triggerData;
|
|
279
|
+
const triggerDataEncoded = triggerService.aaveV3QuotePriceWithMaximumGasPriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, ratioState, maximumGasPrice);
|
|
280
|
+
|
|
259
281
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
260
282
|
},
|
|
261
283
|
};
|