@defisaver/automation-sdk 3.3.11 → 3.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/automation/private/StrategiesAutomation.d.ts +2 -0
- package/cjs/automation/private/StrategiesAutomation.js +10 -1
- package/cjs/automation/private/StrategiesAutomation.test.js +25 -0
- package/cjs/constants/index.d.ts +1 -0
- package/cjs/constants/index.js +62 -1
- package/cjs/services/strategiesService.js +104 -0
- package/cjs/services/strategySubService.d.ts +6 -0
- package/cjs/services/strategySubService.js +30 -1
- package/cjs/services/strategySubService.test.js +96 -0
- package/cjs/services/subDataService.d.ts +295 -137
- package/cjs/services/subDataService.js +639 -393
- package/cjs/services/subDataService.test.js +157 -0
- package/cjs/services/triggerService.d.ts +29 -0
- package/cjs/services/triggerService.js +53 -1
- package/cjs/services/triggerService.test.js +84 -0
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +10 -2
- package/cjs/types/enums.d.ts +17 -3
- package/cjs/types/enums.js +14 -0
- package/cjs/types/index.d.ts +22 -1
- package/esm/automation/private/StrategiesAutomation.d.ts +2 -0
- package/esm/automation/private/StrategiesAutomation.js +10 -1
- package/esm/automation/private/StrategiesAutomation.test.js +25 -0
- package/esm/constants/index.d.ts +1 -0
- package/esm/constants/index.js +61 -0
- package/esm/services/strategiesService.js +105 -1
- package/esm/services/strategySubService.d.ts +6 -0
- package/esm/services/strategySubService.js +29 -0
- package/esm/services/strategySubService.test.js +97 -1
- package/esm/services/subDataService.d.ts +295 -137
- package/esm/services/subDataService.js +639 -393
- package/esm/services/subDataService.test.js +157 -0
- package/esm/services/triggerService.d.ts +29 -0
- package/esm/services/triggerService.js +52 -0
- package/esm/services/triggerService.test.js +85 -1
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +10 -2
- package/esm/types/enums.d.ts +17 -3
- package/esm/types/enums.js +14 -0
- package/esm/types/index.d.ts +22 -1
- package/package.json +2 -2
- package/src/automation/private/StrategiesAutomation.test.ts +40 -0
- package/src/automation/private/StrategiesAutomation.ts +11 -0
- package/src/constants/index.ts +62 -0
- package/src/services/strategiesService.ts +119 -1
- package/src/services/strategySubService.test.ts +124 -0
- package/src/services/strategySubService.ts +118 -0
- package/src/services/subDataService.test.ts +172 -0
- package/src/services/subDataService.ts +1031 -782
- package/src/services/triggerService.test.ts +97 -0
- package/src/services/triggerService.ts +74 -1
- package/src/services/utils.ts +15 -4
- package/src/types/enums.ts +14 -0
- package/src/types/index.ts +26 -0
|
@@ -25,6 +25,8 @@ export default class StrategiesAutomation extends Automation {
|
|
|
25
25
|
*/
|
|
26
26
|
protected removeExpiredSubscriptions(subscriptions: (Position.Automated | null)[]): (Position.Automated | null)[];
|
|
27
27
|
private _mergeCheck;
|
|
28
|
+
/** Repay/boost leverage pairs must not merge across different Aave V4 spokes. */
|
|
29
|
+
private _aaveV4MergeSpokesMatch;
|
|
28
30
|
protected mergeSubs(_subscriptions: (Position.Automated | null)[]): Position.Automated[];
|
|
29
31
|
protected _getSubscriptions(addresses?: EthereumAddress[], options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
30
32
|
getSubscriptions(options?: SubscriptionOptions): Promise<(Position.Automated | null)[]>;
|
|
@@ -104,7 +104,16 @@ class StrategiesAutomation extends Automation_1.default {
|
|
|
104
104
|
&& (s.protocol.id !== enums_1.ProtocolIdentifiers.StrategiesAutomation.CrvUSD // merge only crvUSD leverage management for the same market
|
|
105
105
|
|| s.strategyData.decoded.subData.controller.toLowerCase() === current.strategyData.decoded.triggerData.controller.toLowerCase())
|
|
106
106
|
&& (s.protocol.id !== enums_1.ProtocolIdentifiers.StrategiesAutomation.MorphoBlue // merge morpho blue with the same marketId
|
|
107
|
-
|| s.strategyData.decoded.triggerData.marketId.toLowerCase() === current.strategyData.decoded.triggerData.marketId.toLowerCase())
|
|
107
|
+
|| s.strategyData.decoded.triggerData.marketId.toLowerCase() === current.strategyData.decoded.triggerData.marketId.toLowerCase())
|
|
108
|
+
&& (s.protocol.id !== enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV4
|
|
109
|
+
|| this._aaveV4MergeSpokesMatch(s, current));
|
|
110
|
+
}
|
|
111
|
+
/** Repay/boost leverage pairs must not merge across different Aave V4 spokes. */
|
|
112
|
+
_aaveV4MergeSpokesMatch(s, current) {
|
|
113
|
+
var _a, _b, _c, _d, _e, _f;
|
|
114
|
+
const a = (_c = (_b = (_a = s.strategyData) === null || _a === void 0 ? void 0 : _a.decoded) === null || _b === void 0 ? void 0 : _b.triggerData) === null || _c === void 0 ? void 0 : _c.spoke;
|
|
115
|
+
const b = (_f = (_e = (_d = current.strategyData) === null || _d === void 0 ? void 0 : _d.decoded) === null || _e === void 0 ? void 0 : _e.triggerData) === null || _f === void 0 ? void 0 : _f.spoke;
|
|
116
|
+
return !!a && !!b && a.toLowerCase() === b.toLowerCase();
|
|
108
117
|
}
|
|
109
118
|
mergeSubs(_subscriptions) {
|
|
110
119
|
const mergeBase = _subscriptions.filter(s => (0, utils_1.isDefined)(s) && (0, utils_1.isDefined)(s.specific.mergeWithId));
|
|
@@ -667,5 +667,30 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
667
667
|
(0, chai_1.expect)(JSON.stringify(actual)).to.equal(JSON.stringify(expected));
|
|
668
668
|
}));
|
|
669
669
|
});
|
|
670
|
+
it('Aave V4: pairs repay/boost merge only when trigger spoke matches (no cross-spoke merge)', () => {
|
|
671
|
+
var _a, _b, _c;
|
|
672
|
+
const spoke1 = '0x0000000000000000000000000000000000000a01';
|
|
673
|
+
const spoke2 = '0x0000000000000000000000000000000000000a02';
|
|
674
|
+
const base = {
|
|
675
|
+
isEnabled: true,
|
|
676
|
+
chainId: 1,
|
|
677
|
+
owner: '0x0000000000000000000000000000000000000b01',
|
|
678
|
+
protocol: { id: 'Aave__V4' },
|
|
679
|
+
strategy: { strategyId: 'leverage-management' },
|
|
680
|
+
blockNumber: 0,
|
|
681
|
+
subHash: '0x1',
|
|
682
|
+
positionId: 'test',
|
|
683
|
+
};
|
|
684
|
+
const boostSpoke1 = Object.assign(Object.assign({}, base), { subId: 1, strategyData: { decoded: { triggerData: { spoke: spoke1 }, subData: {} } }, specific: { mergeId: 'boost', subId2: 1 } });
|
|
685
|
+
const repaySpoke2 = Object.assign(Object.assign({}, base), { subId: 2, strategyData: { decoded: { triggerData: { spoke: spoke2 }, subData: {} } }, specific: { mergeWithId: 'boost', subId1: 2 } });
|
|
686
|
+
const boostSpoke2 = Object.assign(Object.assign({}, base), { subId: 3, strategyData: { decoded: { triggerData: { spoke: spoke2 }, subData: {} } }, specific: { mergeId: 'boost', subId2: 3 } });
|
|
687
|
+
// @ts-ignore — mergeSubs is protected; exercised here as in examples above
|
|
688
|
+
const merged = exampleStrategiesAutomation.mergeSubs([boostSpoke1, repaySpoke2, boostSpoke2]);
|
|
689
|
+
(0, chai_1.expect)(merged).to.have.length(2);
|
|
690
|
+
const mergedPair = merged.find((m) => { var _a; return ((_a = m.subIds) === null || _a === void 0 ? void 0 : _a.length) === 2; });
|
|
691
|
+
const loneBoost = merged.find((m) => { var _a; return ((_a = m.subIds) === null || _a === void 0 ? void 0 : _a.length) === 1; });
|
|
692
|
+
(0, chai_1.expect)((_c = (_b = (_a = mergedPair === null || mergedPair === void 0 ? void 0 : mergedPair.strategyData) === null || _a === void 0 ? void 0 : _a.decoded) === null || _b === void 0 ? void 0 : _b.triggerData) === null || _c === void 0 ? void 0 : _c.spoke).to.equal(spoke2);
|
|
693
|
+
(0, chai_1.expect)(loneBoost === null || loneBoost === void 0 ? void 0 : loneBoost.subId).to.equal(1);
|
|
694
|
+
});
|
|
670
695
|
}));
|
|
671
696
|
});
|
package/cjs/constants/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ArbitrumBundleInfo, ArbitrumStrategiesInfo, BundlesInfo, EthereumAddress, Interfaces, MainnetBundleInfo, MainnetStrategiesInfo, OptimismBundleInfo, OptimismStrategiesInfo, BaseBundleInfo, BaseStrategiesInfo, StrategiesInfo } from '../types';
|
|
2
2
|
import { ProtocolIdentifiers, Strategies, Bundles } from '../types/enums';
|
|
3
3
|
export declare const ZERO_ADDRESS: EthereumAddress;
|
|
4
|
+
export declare const EMPTY_SLOT: string;
|
|
4
5
|
export declare const AAVE_V3_VARIABLE_BORROW_RATE = 2;
|
|
5
6
|
export declare const PROTOCOLS: Record<keyof typeof ProtocolIdentifiers.StrategiesAutomation, Interfaces.Protocol>;
|
|
6
7
|
export declare const LEGACY_PROTOCOLS: Record<keyof typeof ProtocolIdentifiers.LegacyAutomation, Interfaces.LegacyProtocol>;
|
package/cjs/constants/index.js
CHANGED
|
@@ -3,12 +3,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BUNDLE_IDS = exports.BUNDLES_INFO = exports.ARBITRUM_BUNDLES_INFO = exports.BASE_BUNDLES_INFO = exports.OPTIMISM_BUNDLES_INFO = exports.MAINNET_BUNDLES_INFO = exports.STRATEGY_IDS = exports.STRATEGIES_INFO = exports.ARBITRUM_STRATEGIES_INFO = exports.BASE_STRATEGIES_INFO = exports.OPTIMISM_STRATEGIES_INFO = exports.MAINNET_STRATEGIES_INFO = exports.LEGACY_PROTOCOLS = exports.PROTOCOLS = exports.AAVE_V3_VARIABLE_BORROW_RATE = exports.ZERO_ADDRESS = void 0;
|
|
6
|
+
exports.BUNDLE_IDS = exports.BUNDLES_INFO = exports.ARBITRUM_BUNDLES_INFO = exports.BASE_BUNDLES_INFO = exports.OPTIMISM_BUNDLES_INFO = exports.MAINNET_BUNDLES_INFO = exports.STRATEGY_IDS = exports.STRATEGIES_INFO = exports.ARBITRUM_STRATEGIES_INFO = exports.BASE_STRATEGIES_INFO = exports.OPTIMISM_STRATEGIES_INFO = exports.MAINNET_STRATEGIES_INFO = exports.LEGACY_PROTOCOLS = exports.PROTOCOLS = exports.AAVE_V3_VARIABLE_BORROW_RATE = exports.EMPTY_SLOT = exports.ZERO_ADDRESS = void 0;
|
|
7
7
|
const enums_1 = require("../types/enums");
|
|
8
8
|
const Protocol_1 = __importDefault(require("../automation/private/Protocol"));
|
|
9
9
|
const LegacyProtocol_1 = __importDefault(require("../automation/private/LegacyProtocol"));
|
|
10
10
|
// General
|
|
11
11
|
exports.ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
12
|
+
exports.EMPTY_SLOT = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
12
13
|
exports.AAVE_V3_VARIABLE_BORROW_RATE = 2;
|
|
13
14
|
exports.PROTOCOLS = (() => {
|
|
14
15
|
const protocolsMapping = {};
|
|
@@ -106,6 +107,16 @@ exports.MAINNET_STRATEGIES_INFO = {
|
|
|
106
107
|
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
107
108
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
108
109
|
},
|
|
110
|
+
[enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH]: {
|
|
111
|
+
strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH,
|
|
112
|
+
strategyId: enums_1.Strategies.Identifiers.CollateralSwitch,
|
|
113
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
114
|
+
},
|
|
115
|
+
[enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH_EOA]: {
|
|
116
|
+
strategyOrBundleId: enums_1.Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH_EOA,
|
|
117
|
+
strategyId: enums_1.Strategies.Identifiers.EoaCollateralSwitch,
|
|
118
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
119
|
+
},
|
|
109
120
|
};
|
|
110
121
|
exports.OPTIMISM_STRATEGIES_INFO = {
|
|
111
122
|
[enums_1.Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -483,6 +494,56 @@ exports.MAINNET_BUNDLES_INFO = {
|
|
|
483
494
|
strategyId: enums_1.Strategies.Identifiers.BoostOnPrice,
|
|
484
495
|
protocol: exports.PROTOCOLS.Spark,
|
|
485
496
|
},
|
|
497
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_REPAY]: {
|
|
498
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_REPAY,
|
|
499
|
+
strategyId: enums_1.Strategies.Identifiers.Repay,
|
|
500
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
501
|
+
},
|
|
502
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_BOOST]: {
|
|
503
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_BOOST,
|
|
504
|
+
strategyId: enums_1.Strategies.Identifiers.Boost,
|
|
505
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
506
|
+
},
|
|
507
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE]: {
|
|
508
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE,
|
|
509
|
+
strategyId: enums_1.Strategies.Identifiers.RepayOnPrice,
|
|
510
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
511
|
+
},
|
|
512
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE]: {
|
|
513
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE,
|
|
514
|
+
strategyId: enums_1.Strategies.Identifiers.BoostOnPrice,
|
|
515
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
516
|
+
},
|
|
517
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_CLOSE]: {
|
|
518
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_CLOSE,
|
|
519
|
+
strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
|
|
520
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
521
|
+
},
|
|
522
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY]: {
|
|
523
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY,
|
|
524
|
+
strategyId: enums_1.Strategies.Identifiers.EoaRepay,
|
|
525
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
526
|
+
},
|
|
527
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST]: {
|
|
528
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST,
|
|
529
|
+
strategyId: enums_1.Strategies.Identifiers.EoaBoost,
|
|
530
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
531
|
+
},
|
|
532
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE]: {
|
|
533
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE,
|
|
534
|
+
strategyId: enums_1.Strategies.Identifiers.EoaRepayOnPrice,
|
|
535
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
536
|
+
},
|
|
537
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE]: {
|
|
538
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE,
|
|
539
|
+
strategyId: enums_1.Strategies.Identifiers.EoaBoostOnPrice,
|
|
540
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
541
|
+
},
|
|
542
|
+
[enums_1.Bundles.MainnetIds.AAVE_V4_EOA_CLOSE]: {
|
|
543
|
+
strategyOrBundleId: enums_1.Bundles.MainnetIds.AAVE_V4_EOA_CLOSE,
|
|
544
|
+
strategyId: enums_1.Strategies.Identifiers.EoaCloseOnPrice,
|
|
545
|
+
protocol: exports.PROTOCOLS.AaveV4,
|
|
546
|
+
},
|
|
486
547
|
};
|
|
487
548
|
exports.OPTIMISM_BUNDLES_INFO = {
|
|
488
549
|
[enums_1.Bundles.OptimismIds.AAVE_V3_REPAY]: {
|
|
@@ -314,6 +314,96 @@ function parseAaveV3CollateralSwitch(position, parseData) {
|
|
|
314
314
|
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
315
315
|
return _position;
|
|
316
316
|
}
|
|
317
|
+
function parseAaveV4LeverageManagement(position, parseData) {
|
|
318
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
319
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
320
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
321
|
+
const triggerData = triggerService.aaveV4RatioTrigger.decode(subStruct.triggerData);
|
|
322
|
+
const subData = subDataService.aaveV4LeverageManagementSubData.decode(subStruct.subData);
|
|
323
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
324
|
+
const isRepay = [enums_1.Strategies.Identifiers.Repay, enums_1.Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId);
|
|
325
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
326
|
+
_position.strategyData.decoded.subData = subData;
|
|
327
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
328
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagement : enums_1.Strategies.IdOverrides.LeverageManagement;
|
|
329
|
+
if (isRepay) {
|
|
330
|
+
_position.specific = {
|
|
331
|
+
triggerRepayRatio: triggerData.ratio,
|
|
332
|
+
targetRepayRatio: subData.targetRatio,
|
|
333
|
+
repayEnabled: isEnabled,
|
|
334
|
+
subId1: Number(subId),
|
|
335
|
+
mergeWithId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
336
|
+
subHashRepay: subHash,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
else {
|
|
340
|
+
_position.specific = {
|
|
341
|
+
triggerBoostRatio: triggerData.ratio,
|
|
342
|
+
targetBoostRatio: subData.targetRatio,
|
|
343
|
+
boostEnabled: isEnabled,
|
|
344
|
+
subId2: Number(subId),
|
|
345
|
+
mergeId: isEOA ? enums_1.Strategies.Identifiers.EoaBoost : enums_1.Strategies.Identifiers.Boost,
|
|
346
|
+
subHashBoost: subHash,
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
return _position;
|
|
350
|
+
}
|
|
351
|
+
function parseAaveV4LeverageManagementOnPrice(position, parseData) {
|
|
352
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
353
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
354
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
|
|
355
|
+
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
356
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
357
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
358
|
+
_position.strategyData.decoded.subData = subData;
|
|
359
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
360
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.IdOverrides.EoaLeverageManagementOnPrice : enums_1.Strategies.IdOverrides.LeverageManagementOnPrice;
|
|
361
|
+
_position.specific = {
|
|
362
|
+
collAsset: subData.collAsset,
|
|
363
|
+
collAssetId: subData.collAssetId,
|
|
364
|
+
debtAsset: subData.debtAsset,
|
|
365
|
+
debtAssetId: subData.debtAssetId,
|
|
366
|
+
price: triggerData.price,
|
|
367
|
+
ratioState: triggerData.ratioState,
|
|
368
|
+
ratio: subData.targetRatio,
|
|
369
|
+
};
|
|
370
|
+
return _position;
|
|
371
|
+
}
|
|
372
|
+
function parseAaveV4CloseOnPrice(position, parseData) {
|
|
373
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
374
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
375
|
+
const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
376
|
+
const subData = subDataService.aaveV4CloseSubData.decode(subStruct.subData);
|
|
377
|
+
const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
|
|
378
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
379
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
380
|
+
_position.strategyData.decoded.subData = subData;
|
|
381
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
382
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.Identifiers.EoaCloseOnPrice : enums_1.Strategies.Identifiers.CloseOnPrice;
|
|
383
|
+
_position.specific = {
|
|
384
|
+
collAsset: subData.collAsset,
|
|
385
|
+
collAssetId: subData.collAssetId,
|
|
386
|
+
debtAsset: subData.debtAsset,
|
|
387
|
+
debtAssetId: subData.debtAssetId,
|
|
388
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
389
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
390
|
+
stopLossType,
|
|
391
|
+
takeProfitType,
|
|
392
|
+
};
|
|
393
|
+
return _position;
|
|
394
|
+
}
|
|
395
|
+
function parseAaveV4CollateralSwitch(position, parseData) {
|
|
396
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
397
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
398
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
|
|
399
|
+
const subData = subDataService.aaveV4CollateralSwitchSubData.decode(subStruct.subData);
|
|
400
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
401
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
402
|
+
_position.strategyData.decoded.subData = subData;
|
|
403
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
404
|
+
_position.strategy.strategyId = isEOA ? enums_1.Strategies.Identifiers.EoaCollateralSwitch : enums_1.Strategies.Identifiers.CollateralSwitch;
|
|
405
|
+
return _position;
|
|
406
|
+
}
|
|
317
407
|
function parseMorphoAaveV2LeverageManagement(position, parseData) {
|
|
318
408
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
319
409
|
const { subStruct, subId } = parseData.subscriptionEventData;
|
|
@@ -966,6 +1056,20 @@ const parsingMethodsMapping = {
|
|
|
966
1056
|
[enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
967
1057
|
[enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
968
1058
|
},
|
|
1059
|
+
[enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV4]: {
|
|
1060
|
+
[enums_1.Strategies.Identifiers.Repay]: parseAaveV4LeverageManagement,
|
|
1061
|
+
[enums_1.Strategies.Identifiers.Boost]: parseAaveV4LeverageManagement,
|
|
1062
|
+
[enums_1.Strategies.Identifiers.RepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1063
|
+
[enums_1.Strategies.Identifiers.BoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1064
|
+
[enums_1.Strategies.Identifiers.CloseOnPrice]: parseAaveV4CloseOnPrice,
|
|
1065
|
+
[enums_1.Strategies.Identifiers.EoaRepay]: parseAaveV4LeverageManagement,
|
|
1066
|
+
[enums_1.Strategies.Identifiers.EoaBoost]: parseAaveV4LeverageManagement,
|
|
1067
|
+
[enums_1.Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1068
|
+
[enums_1.Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1069
|
+
[enums_1.Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV4CloseOnPrice,
|
|
1070
|
+
[enums_1.Strategies.Identifiers.CollateralSwitch]: parseAaveV4CollateralSwitch,
|
|
1071
|
+
[enums_1.Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV4CollateralSwitch,
|
|
1072
|
+
},
|
|
969
1073
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
|
|
970
1074
|
[enums_1.Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
|
|
971
1075
|
[enums_1.Strategies.Identifiers.Boost]: parseCompoundV2LeverageManagement,
|
|
@@ -120,3 +120,9 @@ export declare const liquityV2Encode: {
|
|
|
120
120
|
export declare const fluidEncode: {
|
|
121
121
|
leverageManagement(nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
122
122
|
};
|
|
123
|
+
export declare const aaveV4Encode: {
|
|
124
|
+
leverageManagement(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number): (number | boolean | string[])[];
|
|
125
|
+
leverageManagementOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, targetRatio: number, price: string, priceState: RatioState, ratioState: RatioState): (number | boolean | string[])[];
|
|
126
|
+
closeOnPrice(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, stopLossPrice?: string, stopLossType?: CloseToAssetType, takeProfitPrice?: string, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
127
|
+
collateralSwitch(strategyOrBundleId: number, owner: EthereumAddress, spoke: EthereumAddress, fromAsset: EthereumAddress, fromAssetId: number, toAsset: EthereumAddress, toAssetId: number, amountToSwitch: string, price: string, ratioState: RatioState): (number | boolean | string[])[];
|
|
128
|
+
};
|
|
@@ -26,7 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.fluidEncode = exports.liquityV2Encode = exports.morphoBlueEncode = exports.crvUSDEncode = exports.sparkEncode = exports.exchangeEncode = exports.morphoAaveV2Encode = exports.compoundV3L2Encode = exports.compoundV3Encode = exports.compoundV2Encode = exports.aaveV3Encode = exports.aaveV2Encode = exports.chickenBondsEncode = exports.liquityEncode = exports.makerEncode = void 0;
|
|
29
|
+
exports.aaveV4Encode = exports.fluidEncode = exports.liquityV2Encode = exports.morphoBlueEncode = exports.crvUSDEncode = exports.sparkEncode = exports.exchangeEncode = exports.morphoAaveV2Encode = exports.compoundV3L2Encode = exports.compoundV3Encode = exports.compoundV2Encode = exports.aaveV3Encode = exports.aaveV2Encode = exports.chickenBondsEncode = exports.liquityEncode = exports.makerEncode = void 0;
|
|
30
30
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
31
31
|
const tokens_1 = require("@defisaver/tokens");
|
|
32
32
|
const enums_1 = require("../types/enums");
|
|
@@ -377,3 +377,32 @@ exports.fluidEncode = {
|
|
|
377
377
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
378
378
|
},
|
|
379
379
|
};
|
|
380
|
+
exports.aaveV4Encode = {
|
|
381
|
+
leverageManagement(strategyOrBundleId, owner, spoke, ratioState, targetRatio, triggerRatio) {
|
|
382
|
+
const isBundle = true;
|
|
383
|
+
const subData = subDataService.aaveV4LeverageManagementSubData.encode(spoke, owner, ratioState, targetRatio);
|
|
384
|
+
const triggerData = triggerService.aaveV4RatioTrigger.encode(owner, spoke, triggerRatio, ratioState);
|
|
385
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
386
|
+
},
|
|
387
|
+
leverageManagementOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, targetRatio, price, priceState, ratioState) {
|
|
388
|
+
const isBundle = true;
|
|
389
|
+
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio);
|
|
390
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(spoke, collAssetId, debtAssetId, price, priceState);
|
|
391
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
392
|
+
},
|
|
393
|
+
closeOnPrice(strategyOrBundleId, owner, spoke, collAsset, collAssetId, debtAsset, debtAssetId, stopLossPrice = '0', stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = '0', takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
|
|
394
|
+
const isBundle = true;
|
|
395
|
+
const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
396
|
+
const subData = subDataService.aaveV4CloseSubData.encode(spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, closeType);
|
|
397
|
+
const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.encode(spoke, collAssetId, debtAssetId, stopLossPrice, takeProfitPrice);
|
|
398
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
399
|
+
},
|
|
400
|
+
collateralSwitch(strategyOrBundleId, owner, spoke, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch, price, ratioState) {
|
|
401
|
+
const isBundle = false;
|
|
402
|
+
const subData = subDataService.aaveV4CollateralSwitchSubData.encode(spoke, owner, fromAsset, fromAssetId, toAsset, toAssetId, amountToSwitch);
|
|
403
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.encode(spoke, fromAssetId, // baseTokenId
|
|
404
|
+
toAssetId, // quoteTokenId
|
|
405
|
+
price, ratioState);
|
|
406
|
+
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
407
|
+
},
|
|
408
|
+
};
|
|
@@ -1614,4 +1614,100 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1614
1614
|
});
|
|
1615
1615
|
});
|
|
1616
1616
|
});
|
|
1617
|
+
describe('When testing strategySubService.aaveV4Encode', () => {
|
|
1618
|
+
describe('leverageManagement()', () => {
|
|
1619
|
+
const examples = [
|
|
1620
|
+
[
|
|
1621
|
+
[1, true, ["0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000010a741a4627800000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x0000000000000000000000000000000000000000000000000000000000000001", "0x00000000000000000000000000000000000000000000000014d1120d7b160000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1622
|
+
[
|
|
1623
|
+
1,
|
|
1624
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1625
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1626
|
+
enums_1.RatioState.UNDER,
|
|
1627
|
+
150,
|
|
1628
|
+
120,
|
|
1629
|
+
]
|
|
1630
|
+
]
|
|
1631
|
+
];
|
|
1632
|
+
examples.forEach(([expected, actual]) => {
|
|
1633
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1634
|
+
(0, chai_1.expect)(strategySubService_1.aaveV4Encode.leverageManagement(...actual)).to.eql(expected);
|
|
1635
|
+
});
|
|
1636
|
+
});
|
|
1637
|
+
});
|
|
1638
|
+
describe('leverageManagementOnPrice()', () => {
|
|
1639
|
+
const examples = [
|
|
1640
|
+
[
|
|
1641
|
+
[2, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x00000000000000000000000000000000000000000000000016345785d8a00000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1642
|
+
[
|
|
1643
|
+
2,
|
|
1644
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1645
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1646
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1647
|
+
10,
|
|
1648
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1649
|
+
20,
|
|
1650
|
+
160,
|
|
1651
|
+
'1500',
|
|
1652
|
+
enums_1.RatioState.OVER,
|
|
1653
|
+
enums_1.RatioState.OVER, // ratioState - UNDER for repay, OVER for boost
|
|
1654
|
+
]
|
|
1655
|
+
]
|
|
1656
|
+
];
|
|
1657
|
+
examples.forEach(([expected, actual]) => {
|
|
1658
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1659
|
+
(0, chai_1.expect)(strategySubService_1.aaveV4Encode.leverageManagementOnPrice(...actual)).to.eql(expected);
|
|
1660
|
+
});
|
|
1661
|
+
});
|
|
1662
|
+
});
|
|
1663
|
+
describe('closeOnPrice()', () => {
|
|
1664
|
+
const examples = [
|
|
1665
|
+
[
|
|
1666
|
+
[3, true, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000004be4e7267b6ae000000000000000000000000000000000000000000000000000000000000000000000"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000000000000000003", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1667
|
+
[
|
|
1668
|
+
3,
|
|
1669
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1670
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1671
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1672
|
+
10,
|
|
1673
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1674
|
+
20,
|
|
1675
|
+
'1400',
|
|
1676
|
+
enums_1.CloseToAssetType.DEBT,
|
|
1677
|
+
'0',
|
|
1678
|
+
enums_1.CloseToAssetType.COLLATERAL
|
|
1679
|
+
]
|
|
1680
|
+
]
|
|
1681
|
+
];
|
|
1682
|
+
examples.forEach(([expected, actual]) => {
|
|
1683
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1684
|
+
(0, chai_1.expect)(strategySubService_1.aaveV4Encode.closeOnPrice(...actual)).to.eql(expected);
|
|
1685
|
+
});
|
|
1686
|
+
});
|
|
1687
|
+
});
|
|
1688
|
+
describe('collateralSwitch()', () => {
|
|
1689
|
+
const examples = [
|
|
1690
|
+
[
|
|
1691
|
+
[4, false, ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000005150ae84a8cdf000000000000000000000000000000000000000000000000000000000000000000001"], ["0x0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e", "0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c", "0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", "0x000000000000000000000000000000000000000000000000000000000000000a", "0x000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", "0x0000000000000000000000000000000000000000000000000000000000000014", "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", "0x0000000000000000000000000000000000000000000000000000000000000000", "0x0000000000000000000000000000000000000000000000000000000000000000"]],
|
|
1692
|
+
[
|
|
1693
|
+
4,
|
|
1694
|
+
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1695
|
+
web3Utils.toChecksumAddress('0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e'),
|
|
1696
|
+
web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1697
|
+
10,
|
|
1698
|
+
web3Utils.toChecksumAddress('0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'),
|
|
1699
|
+
20,
|
|
1700
|
+
'1000000000000000000',
|
|
1701
|
+
'1500',
|
|
1702
|
+
enums_1.RatioState.UNDER,
|
|
1703
|
+
]
|
|
1704
|
+
]
|
|
1705
|
+
];
|
|
1706
|
+
examples.forEach(([expected, actual]) => {
|
|
1707
|
+
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1708
|
+
(0, chai_1.expect)(strategySubService_1.aaveV4Encode.collateralSwitch(...actual)).to.eql(expected);
|
|
1709
|
+
});
|
|
1710
|
+
});
|
|
1711
|
+
});
|
|
1712
|
+
});
|
|
1617
1713
|
});
|