@defisaver/automation-sdk 1.2.24 → 1.2.26
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/constants/index.js +10 -0
- package/esm/services/strategiesService.js +32 -1
- package/esm/services/strategySubService.d.ts +1 -0
- package/esm/services/strategySubService.js +9 -0
- package/esm/services/subDataService.d.ts +5 -0
- package/esm/services/subDataService.js +7 -0
- package/esm/services/triggerService.d.ts +1 -1
- package/esm/services/triggerService.js +1 -1
- package/esm/types/enums.d.ts +3 -1
- package/esm/types/enums.js +2 -0
- package/package.json +1 -1
- package/src/constants/index.ts +10 -0
- package/src/services/strategiesService.ts +39 -2
- package/src/services/strategySubService.ts +15 -0
- package/src/services/subDataService.ts +7 -0
- package/src/services/triggerService.ts +2 -2
- package/src/types/enums.ts +2 -0
- package/umd/index.js +371 -529
- package/yarn-error.log +0 -6937
package/esm/constants/index.js
CHANGED
|
@@ -192,6 +192,16 @@ export const MAINNET_BUNDLES_INFO = {
|
|
|
192
192
|
strategyId: Strategies.Identifiers.Boost,
|
|
193
193
|
protocol: PROTOCOLS.MorphoAaveV2,
|
|
194
194
|
},
|
|
195
|
+
[Bundles.MainnetIds.LIQUITY_REPAY]: {
|
|
196
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_REPAY,
|
|
197
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
198
|
+
protocol: PROTOCOLS.Liquity,
|
|
199
|
+
},
|
|
200
|
+
[Bundles.MainnetIds.LIQUITY_BOOST]: {
|
|
201
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_BOOST,
|
|
202
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
203
|
+
protocol: PROTOCOLS.Liquity,
|
|
204
|
+
},
|
|
195
205
|
};
|
|
196
206
|
export const OPTIMISM_BUNDLES_INFO = {
|
|
197
207
|
[Bundles.OptimismIds.AAVE_V3_REPAY]: {
|
|
@@ -184,7 +184,7 @@ function parseAaveV3CloseOnPrice(position, parseData) {
|
|
|
184
184
|
price: triggerData.price,
|
|
185
185
|
ratioState: triggerData.ratioState,
|
|
186
186
|
};
|
|
187
|
-
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(_position.specific.ratioState, wethToEthByAddress(_position.specific.collAsset), wethToEthByAddress(_position.specific.debtAsset), parseData.chainId);
|
|
187
|
+
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(_position.specific.ratioState, wethToEthByAddress(_position.specific.collAsset, parseData.chainId), wethToEthByAddress(_position.specific.debtAsset, parseData.chainId), parseData.chainId);
|
|
188
188
|
_position.strategy.strategyId = isRatioStateOver(ratioState) ? Strategies.IdOverrides.TakeProfit : Strategies.IdOverrides.StopLoss;
|
|
189
189
|
return _position;
|
|
190
190
|
}
|
|
@@ -255,6 +255,35 @@ function parseExchangeLimitOrder(position, parseData, chainId) {
|
|
|
255
255
|
_position.strategyData.decoded.triggerData = triggerService.exchangeOffchainPriceTrigger.decode(subStruct.triggerData, fromTokenDecimals, toTokenDecimals);
|
|
256
256
|
return _position;
|
|
257
257
|
}
|
|
258
|
+
function parseLiquityLeverageManagement(position, parseData) {
|
|
259
|
+
const _position = cloneDeep(position);
|
|
260
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
261
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
262
|
+
const triggerData = triggerService.liquityRatioTrigger.decode(subStruct.triggerData);
|
|
263
|
+
const subData = subDataService.liquityLeverageManagementSubData.decode(subStruct.subData);
|
|
264
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
265
|
+
_position.strategyData.decoded.subData = subData;
|
|
266
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
267
|
+
if (isRepay) {
|
|
268
|
+
_position.specific = {
|
|
269
|
+
minRatio: triggerData.ratio,
|
|
270
|
+
minOptimalRatio: subData.targetRatio,
|
|
271
|
+
repayEnabled: true,
|
|
272
|
+
subId1: Number(subId),
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
_position.specific = {
|
|
277
|
+
maxRatio: triggerData.ratio,
|
|
278
|
+
maxOptimalRatio: subData.targetRatio,
|
|
279
|
+
boostEnabled: isEnabled,
|
|
280
|
+
subId2: Number(subId),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
284
|
+
_position.specific.mergeWithSameId = true;
|
|
285
|
+
return _position;
|
|
286
|
+
}
|
|
258
287
|
const parsingMethodsMapping = {
|
|
259
288
|
[ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
|
|
260
289
|
[Strategies.Identifiers.SavingsLiqProtection]: parseMakerSavingsLiqProtection,
|
|
@@ -269,6 +298,8 @@ const parsingMethodsMapping = {
|
|
|
269
298
|
[Strategies.Identifiers.CloseOnPriceToColl]: parseLiquityCloseOnPrice,
|
|
270
299
|
[Strategies.Identifiers.TrailingStopToColl]: parseLiquityTrailingStop,
|
|
271
300
|
[Strategies.Identifiers.BondProtection]: parseLiquityBondProtection,
|
|
301
|
+
[Strategies.Identifiers.Repay]: parseLiquityLeverageManagement,
|
|
302
|
+
[Strategies.Identifiers.Boost]: parseLiquityLeverageManagement,
|
|
272
303
|
},
|
|
273
304
|
[ProtocolIdentifiers.StrategiesAutomation.AaveV3]: {
|
|
274
305
|
[Strategies.Identifiers.Repay]: parseAaveV3LeverageManagement,
|
|
@@ -10,6 +10,7 @@ export declare const liquityEncode: {
|
|
|
10
10
|
closeOnPrice(priceOverOrUnder: RatioState, price: string, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
11
11
|
trailingStop(triggerPercentage: number, closeToAssetAddr: EthereumAddress, chainlinkCollAddress: EthereumAddress, roundId: number, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): (boolean | string[] | Strategies.MainnetIds)[];
|
|
12
12
|
paybackFromChickenBondStrategySub(proxyAddress: EthereumAddress, ratio: number, sourceId: string, sourceType: number, ratioState?: RatioState): (boolean | string[] | Bundles.MainnetIds)[];
|
|
13
|
+
leverageManagement(minRatio: string, maxRatio: string, maxOptimalRatio: string, minOptimalRatio: string, boostEnabled: boolean): (string | boolean)[];
|
|
13
14
|
};
|
|
14
15
|
export declare const chickenBondsEncode: {
|
|
15
16
|
rebond(bondId: number): string[];
|
|
@@ -66,6 +66,15 @@ export const liquityEncode = {
|
|
|
66
66
|
const isBundle = true;
|
|
67
67
|
return [strategyId, isBundle, triggerData, subData];
|
|
68
68
|
},
|
|
69
|
+
leverageManagement(minRatio, maxRatio, maxOptimalRatio, minOptimalRatio, boostEnabled) {
|
|
70
|
+
return [
|
|
71
|
+
new Dec(minRatio).mul(1e16).toString(),
|
|
72
|
+
new Dec(maxRatio).mul(1e16).toString(),
|
|
73
|
+
new Dec(maxOptimalRatio).mul(1e16).toString(),
|
|
74
|
+
new Dec(minOptimalRatio).mul(1e16).toString(),
|
|
75
|
+
boostEnabled,
|
|
76
|
+
];
|
|
77
|
+
},
|
|
69
78
|
};
|
|
70
79
|
export const chickenBondsEncode = {
|
|
71
80
|
rebond(bondId) {
|
|
@@ -22,6 +22,11 @@ export declare const makerLeverageManagementSubData: {
|
|
|
22
22
|
targetRatio: number;
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
|
+
export declare const liquityLeverageManagementSubData: {
|
|
26
|
+
decode: (subData: string[]) => {
|
|
27
|
+
targetRatio: number;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
25
30
|
export declare const liquityCloseSubData: {
|
|
26
31
|
encode(closeToAssetAddr: EthereumAddress, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): string[];
|
|
27
32
|
decode(subData: string[]): {
|
|
@@ -70,6 +70,13 @@ export const makerLeverageManagementSubData = {
|
|
|
70
70
|
return { vaultId, targetRatio };
|
|
71
71
|
},
|
|
72
72
|
};
|
|
73
|
+
export const liquityLeverageManagementSubData = {
|
|
74
|
+
decode: (subData) => {
|
|
75
|
+
const weiRatio = mockedWeb3.eth.abi.decodeParameter('uint256', subData[1]);
|
|
76
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
77
|
+
return { targetRatio };
|
|
78
|
+
},
|
|
79
|
+
};
|
|
73
80
|
export const liquityCloseSubData = {
|
|
74
81
|
encode(closeToAssetAddr, chainId = ChainId.Ethereum, collAddr, debtAddr) {
|
|
75
82
|
const _collAddr = collAddr || getAssetInfo('WETH', chainId).address;
|
|
@@ -102,7 +102,7 @@ export const liquityRatioTrigger = {
|
|
|
102
102
|
const decodedData = mockedWeb3.eth.abi.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
103
103
|
return {
|
|
104
104
|
owner: decodedData[0],
|
|
105
|
-
ratio: new Dec(mockedWeb3.utils.fromWei(decodedData[1])).mul(100).
|
|
105
|
+
ratio: new Dec(mockedWeb3.utils.fromWei(decodedData[1])).mul(100).toNumber(),
|
|
106
106
|
ratioState: +decodedData[2],
|
|
107
107
|
};
|
|
108
108
|
},
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -98,7 +98,9 @@ export declare namespace Bundles {
|
|
|
98
98
|
AAVE_V3_CLOSE_TO_DEBT = 12,
|
|
99
99
|
AAVE_V3_CLOSE_TO_COLLATERAL = 13,
|
|
100
100
|
MORPHO_AAVE_V2_REPAY = 14,
|
|
101
|
-
MORPHO_AAVE_V2_BOOST = 15
|
|
101
|
+
MORPHO_AAVE_V2_BOOST = 15,
|
|
102
|
+
LIQUITY_REPAY = 16,
|
|
103
|
+
LIQUITY_BOOST = 17
|
|
102
104
|
}
|
|
103
105
|
enum OptimismIds {
|
|
104
106
|
AAVE_V3_REPAY = 0,
|
package/esm/types/enums.js
CHANGED
|
@@ -113,6 +113,8 @@ export var Bundles;
|
|
|
113
113
|
MainnetIds[MainnetIds["AAVE_V3_CLOSE_TO_COLLATERAL"] = 13] = "AAVE_V3_CLOSE_TO_COLLATERAL";
|
|
114
114
|
MainnetIds[MainnetIds["MORPHO_AAVE_V2_REPAY"] = 14] = "MORPHO_AAVE_V2_REPAY";
|
|
115
115
|
MainnetIds[MainnetIds["MORPHO_AAVE_V2_BOOST"] = 15] = "MORPHO_AAVE_V2_BOOST";
|
|
116
|
+
MainnetIds[MainnetIds["LIQUITY_REPAY"] = 16] = "LIQUITY_REPAY";
|
|
117
|
+
MainnetIds[MainnetIds["LIQUITY_BOOST"] = 17] = "LIQUITY_BOOST";
|
|
116
118
|
})(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
|
|
117
119
|
let OptimismIds;
|
|
118
120
|
(function (OptimismIds) {
|
package/package.json
CHANGED
package/src/constants/index.ts
CHANGED
|
@@ -208,6 +208,16 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
|
|
|
208
208
|
strategyId: Strategies.Identifiers.Boost,
|
|
209
209
|
protocol: PROTOCOLS.MorphoAaveV2,
|
|
210
210
|
},
|
|
211
|
+
[Bundles.MainnetIds.LIQUITY_REPAY]: {
|
|
212
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_REPAY,
|
|
213
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
214
|
+
protocol: PROTOCOLS.Liquity,
|
|
215
|
+
},
|
|
216
|
+
[Bundles.MainnetIds.LIQUITY_BOOST]: {
|
|
217
|
+
strategyOrBundleId: Bundles.MainnetIds.LIQUITY_BOOST,
|
|
218
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
219
|
+
protocol: PROTOCOLS.Liquity,
|
|
220
|
+
},
|
|
211
221
|
};
|
|
212
222
|
|
|
213
223
|
export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
|
|
@@ -253,8 +253,8 @@ function parseAaveV3CloseOnPrice(position: Position.Automated, parseData: ParseD
|
|
|
253
253
|
|
|
254
254
|
const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
|
|
255
255
|
_position.specific.ratioState,
|
|
256
|
-
wethToEthByAddress(_position.specific.collAsset),
|
|
257
|
-
wethToEthByAddress(_position.specific.debtAsset),
|
|
256
|
+
wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
|
|
257
|
+
wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
|
|
258
258
|
parseData.chainId,
|
|
259
259
|
);
|
|
260
260
|
|
|
@@ -352,6 +352,41 @@ function parseExchangeLimitOrder(position: Position.Automated, parseData: ParseD
|
|
|
352
352
|
|
|
353
353
|
return _position;
|
|
354
354
|
}
|
|
355
|
+
function parseLiquityLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
356
|
+
const _position = cloneDeep(position);
|
|
357
|
+
|
|
358
|
+
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
359
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
360
|
+
|
|
361
|
+
const triggerData = triggerService.liquityRatioTrigger.decode(subStruct.triggerData);
|
|
362
|
+
const subData = subDataService.liquityLeverageManagementSubData.decode(subStruct.subData);
|
|
363
|
+
|
|
364
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
365
|
+
_position.strategyData.decoded.subData = subData;
|
|
366
|
+
|
|
367
|
+
const isRepay = _position.strategy.strategyId === Strategies.Identifiers.Repay;
|
|
368
|
+
|
|
369
|
+
if (isRepay) {
|
|
370
|
+
_position.specific = {
|
|
371
|
+
minRatio: triggerData.ratio,
|
|
372
|
+
minOptimalRatio: subData.targetRatio,
|
|
373
|
+
repayEnabled: true,
|
|
374
|
+
subId1: Number(subId),
|
|
375
|
+
};
|
|
376
|
+
} else {
|
|
377
|
+
_position.specific = {
|
|
378
|
+
maxRatio: triggerData.ratio,
|
|
379
|
+
maxOptimalRatio: subData.targetRatio,
|
|
380
|
+
boostEnabled: isEnabled,
|
|
381
|
+
subId2: Number(subId),
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
_position.strategy.strategyId = Strategies.IdOverrides.LeverageManagement;
|
|
386
|
+
_position.specific.mergeWithSameId = true;
|
|
387
|
+
|
|
388
|
+
return _position;
|
|
389
|
+
}
|
|
355
390
|
|
|
356
391
|
const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
357
392
|
[ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
|
|
@@ -367,6 +402,8 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
367
402
|
[Strategies.Identifiers.CloseOnPriceToColl]: parseLiquityCloseOnPrice,
|
|
368
403
|
[Strategies.Identifiers.TrailingStopToColl]: parseLiquityTrailingStop,
|
|
369
404
|
[Strategies.Identifiers.BondProtection]: parseLiquityBondProtection,
|
|
405
|
+
[Strategies.Identifiers.Repay]: parseLiquityLeverageManagement,
|
|
406
|
+
[Strategies.Identifiers.Boost]: parseLiquityLeverageManagement,
|
|
370
407
|
},
|
|
371
408
|
[ProtocolIdentifiers.StrategiesAutomation.AaveV3]: {
|
|
372
409
|
[Strategies.Identifiers.Repay]: parseAaveV3LeverageManagement,
|
|
@@ -149,6 +149,21 @@ export const liquityEncode = {
|
|
|
149
149
|
|
|
150
150
|
return [strategyId, isBundle, triggerData, subData];
|
|
151
151
|
},
|
|
152
|
+
leverageManagement(
|
|
153
|
+
minRatio:string,
|
|
154
|
+
maxRatio:string,
|
|
155
|
+
maxOptimalRatio:string,
|
|
156
|
+
minOptimalRatio:string,
|
|
157
|
+
boostEnabled:boolean,
|
|
158
|
+
) {
|
|
159
|
+
return [
|
|
160
|
+
new Dec(minRatio).mul(1e16).toString(),
|
|
161
|
+
new Dec(maxRatio).mul(1e16).toString(),
|
|
162
|
+
new Dec(maxOptimalRatio).mul(1e16).toString(),
|
|
163
|
+
new Dec(minOptimalRatio).mul(1e16).toString(),
|
|
164
|
+
boostEnabled,
|
|
165
|
+
];
|
|
166
|
+
},
|
|
152
167
|
};
|
|
153
168
|
|
|
154
169
|
export const chickenBondsEncode = {
|
|
@@ -98,6 +98,13 @@ export const makerLeverageManagementSubData = {
|
|
|
98
98
|
return { vaultId, targetRatio };
|
|
99
99
|
},
|
|
100
100
|
};
|
|
101
|
+
export const liquityLeverageManagementSubData = {
|
|
102
|
+
decode: (subData:SubData) => {
|
|
103
|
+
const weiRatio = mockedWeb3.eth.abi.decodeParameter('uint256', subData[1]) as any as string;
|
|
104
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
105
|
+
return { targetRatio };
|
|
106
|
+
},
|
|
107
|
+
};
|
|
101
108
|
export const liquityCloseSubData = {
|
|
102
109
|
encode(
|
|
103
110
|
closeToAssetAddr: EthereumAddress,
|
|
@@ -120,11 +120,11 @@ export const liquityRatioTrigger = {
|
|
|
120
120
|
const ratioWei = ratioPercentageToWei(ratioPercentage);
|
|
121
121
|
return [mockedWeb3.eth.abi.encodeParameters(['address', 'uint256', 'uint8'], [owner, ratioWei, ratioState])];
|
|
122
122
|
},
|
|
123
|
-
decode(triggerData: TriggerData): { owner: EthereumAddress, ratioState: RatioState, ratio:
|
|
123
|
+
decode(triggerData: TriggerData): { owner: EthereumAddress, ratioState: RatioState, ratio: number } {
|
|
124
124
|
const decodedData = mockedWeb3.eth.abi.decodeParameters(['address', 'uint256', 'uint8'], triggerData[0]);
|
|
125
125
|
return {
|
|
126
126
|
owner: decodedData[0],
|
|
127
|
-
ratio: new Dec(mockedWeb3.utils.fromWei(decodedData[1])).mul(100).
|
|
127
|
+
ratio: new Dec(mockedWeb3.utils.fromWei(decodedData[1])).mul(100).toNumber(),
|
|
128
128
|
ratioState: +decodedData[2],
|
|
129
129
|
};
|
|
130
130
|
},
|