@defisaver/automation-sdk 3.3.10 → 3.3.11-aave-v4-1-dev
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 +72 -1
- package/cjs/services/ethereumService.test.js +2 -0
- package/cjs/services/strategiesService.js +129 -0
- package/cjs/services/strategySubService.d.ts +19 -0
- package/cjs/services/strategySubService.js +37 -1
- package/cjs/services/strategySubService.test.js +229 -0
- package/cjs/services/subDataService.d.ts +298 -129
- package/cjs/services/subDataService.js +639 -369
- package/cjs/services/subDataService.test.js +214 -0
- package/cjs/services/triggerService.d.ts +38 -0
- package/cjs/services/triggerService.js +68 -1
- package/cjs/services/triggerService.test.js +130 -0
- package/cjs/services/utils.d.ts +1 -1
- package/cjs/services/utils.js +10 -2
- package/cjs/types/enums.d.ts +19 -3
- package/cjs/types/enums.js +16 -0
- package/cjs/types/index.d.ts +33 -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 +71 -0
- package/esm/services/ethereumService.test.js +2 -0
- package/esm/services/strategiesService.js +130 -1
- package/esm/services/strategySubService.d.ts +19 -0
- package/esm/services/strategySubService.js +36 -0
- package/esm/services/strategySubService.test.js +230 -1
- package/esm/services/subDataService.d.ts +298 -129
- package/esm/services/subDataService.js +639 -369
- package/esm/services/subDataService.test.js +214 -0
- package/esm/services/triggerService.d.ts +38 -0
- package/esm/services/triggerService.js +67 -0
- package/esm/services/triggerService.test.js +131 -1
- package/esm/services/utils.d.ts +1 -1
- package/esm/services/utils.js +10 -2
- package/esm/types/enums.d.ts +19 -3
- package/esm/types/enums.js +16 -0
- package/esm/types/index.d.ts +33 -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 +72 -0
- package/src/services/ethereumService.test.ts +2 -0
- package/src/services/strategiesService.ts +150 -2
- package/src/services/strategySubService.test.ts +286 -0
- package/src/services/strategySubService.ts +140 -0
- package/src/services/subDataService.test.ts +239 -0
- package/src/services/subDataService.ts +1072 -784
- package/src/services/triggerService.test.ts +148 -0
- package/src/services/triggerService.ts +97 -1
- package/src/services/utils.ts +15 -4
- package/src/types/enums.ts +16 -0
- package/src/types/index.ts +40 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/automation-sdk",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.11-aave-v4-1-dev",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./cjs/index.js",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"repository": "https://github.com/defisaver/automation-sdk",
|
|
24
24
|
"license": "ISC",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@defisaver/sdk": "
|
|
26
|
+
"@defisaver/sdk": "1.3.21-aave-v4-dev",
|
|
27
27
|
"@defisaver/tokens": "^1.6.19",
|
|
28
28
|
"@ethersproject/address": "^5.0.10",
|
|
29
29
|
"@ethersproject/solidity": "^5.0.9",
|
|
@@ -659,5 +659,45 @@ describe('Feature: StrategiesAutomation.ts', () => {
|
|
|
659
659
|
expect(JSON.stringify(actual)).to.equal(JSON.stringify(expected));
|
|
660
660
|
});
|
|
661
661
|
});
|
|
662
|
+
|
|
663
|
+
it('Aave V4: pairs repay/boost merge only when trigger spoke matches (no cross-spoke merge)', () => {
|
|
664
|
+
const spoke1 = '0x0000000000000000000000000000000000000a01';
|
|
665
|
+
const spoke2 = '0x0000000000000000000000000000000000000a02';
|
|
666
|
+
const base = {
|
|
667
|
+
isEnabled: true,
|
|
668
|
+
chainId: 1,
|
|
669
|
+
owner: '0x0000000000000000000000000000000000000b01',
|
|
670
|
+
protocol: { id: 'Aave__V4' },
|
|
671
|
+
strategy: { strategyId: 'leverage-management' },
|
|
672
|
+
blockNumber: 0,
|
|
673
|
+
subHash: '0x1',
|
|
674
|
+
positionId: 'test',
|
|
675
|
+
};
|
|
676
|
+
const boostSpoke1 = {
|
|
677
|
+
...base,
|
|
678
|
+
subId: 1,
|
|
679
|
+
strategyData: { decoded: { triggerData: { spoke: spoke1 }, subData: {} } },
|
|
680
|
+
specific: { mergeId: 'boost', subId2: 1 },
|
|
681
|
+
};
|
|
682
|
+
const repaySpoke2 = {
|
|
683
|
+
...base,
|
|
684
|
+
subId: 2,
|
|
685
|
+
strategyData: { decoded: { triggerData: { spoke: spoke2 }, subData: {} } },
|
|
686
|
+
specific: { mergeWithId: 'boost', subId1: 2 },
|
|
687
|
+
};
|
|
688
|
+
const boostSpoke2 = {
|
|
689
|
+
...base,
|
|
690
|
+
subId: 3,
|
|
691
|
+
strategyData: { decoded: { triggerData: { spoke: spoke2 }, subData: {} } },
|
|
692
|
+
specific: { mergeId: 'boost', subId2: 3 },
|
|
693
|
+
};
|
|
694
|
+
// @ts-ignore — mergeSubs is protected; exercised here as in examples above
|
|
695
|
+
const merged = exampleStrategiesAutomation.mergeSubs([boostSpoke1, repaySpoke2, boostSpoke2]);
|
|
696
|
+
expect(merged).to.have.length(2);
|
|
697
|
+
const mergedPair = merged.find((m: { subIds?: number[] }) => m.subIds?.length === 2);
|
|
698
|
+
const loneBoost = merged.find((m: { subIds?: number[] }) => m.subIds?.length === 1);
|
|
699
|
+
expect(mergedPair?.strategyData?.decoded?.triggerData?.spoke).to.equal(spoke2);
|
|
700
|
+
expect(loneBoost?.subId).to.equal(1);
|
|
701
|
+
});
|
|
662
702
|
});
|
|
663
703
|
});
|
|
@@ -129,9 +129,20 @@ export default class StrategiesAutomation extends Automation {
|
|
|
129
129
|
&& (
|
|
130
130
|
s.protocol.id !== ProtocolIdentifiers.StrategiesAutomation.MorphoBlue // merge morpho blue with the same marketId
|
|
131
131
|
|| s.strategyData.decoded.triggerData.marketId.toLowerCase() === current.strategyData.decoded.triggerData.marketId.toLowerCase()
|
|
132
|
+
)
|
|
133
|
+
&& (
|
|
134
|
+
s.protocol.id !== ProtocolIdentifiers.StrategiesAutomation.AaveV4
|
|
135
|
+
|| this._aaveV4MergeSpokesMatch(s, current)
|
|
132
136
|
);
|
|
133
137
|
}
|
|
134
138
|
|
|
139
|
+
/** Repay/boost leverage pairs must not merge across different Aave V4 spokes. */
|
|
140
|
+
private _aaveV4MergeSpokesMatch(s: Position.Automated, current: Position.Automated): boolean {
|
|
141
|
+
const a = s.strategyData?.decoded?.triggerData?.spoke as EthereumAddress | undefined;
|
|
142
|
+
const b = current.strategyData?.decoded?.triggerData?.spoke as EthereumAddress | undefined;
|
|
143
|
+
return !!a && !!b && a.toLowerCase() === b.toLowerCase();
|
|
144
|
+
}
|
|
145
|
+
|
|
135
146
|
protected mergeSubs(_subscriptions:(Position.Automated | null)[]) {
|
|
136
147
|
const mergeBase = _subscriptions.filter(s => isDefined(s) && isDefined(s.specific.mergeWithId)) as Position.Automated[];
|
|
137
148
|
const mergeExtension = _subscriptions.filter(s => isDefined(s) && isDefined(s.specific.mergeId)) as Position.Automated[];
|
package/src/constants/index.ts
CHANGED
|
@@ -23,6 +23,8 @@ import LegacyProtocol from '../automation/private/LegacyProtocol';
|
|
|
23
23
|
// General
|
|
24
24
|
export const ZERO_ADDRESS: EthereumAddress = '0x0000000000000000000000000000000000000000';
|
|
25
25
|
|
|
26
|
+
export const EMPTY_SLOT: string = '0x0000000000000000000000000000000000000000000000000000000000000000';
|
|
27
|
+
|
|
26
28
|
export const AAVE_V3_VARIABLE_BORROW_RATE = 2;
|
|
27
29
|
|
|
28
30
|
export const PROTOCOLS: Record<keyof typeof ProtocolIdentifiers.StrategiesAutomation, Interfaces.Protocol> = (() => {
|
|
@@ -123,6 +125,16 @@ export const MAINNET_STRATEGIES_INFO: MainnetStrategiesInfo = {
|
|
|
123
125
|
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
124
126
|
protocol: PROTOCOLS.AaveV3,
|
|
125
127
|
},
|
|
128
|
+
[Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH]: {
|
|
129
|
+
strategyOrBundleId: Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH,
|
|
130
|
+
strategyId: Strategies.Identifiers.CollateralSwitch,
|
|
131
|
+
protocol: PROTOCOLS.AaveV4,
|
|
132
|
+
},
|
|
133
|
+
[Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH_EOA]: {
|
|
134
|
+
strategyOrBundleId: Strategies.MainnetIds.AAVE_V4_COLLATERAL_SWITCH_EOA,
|
|
135
|
+
strategyId: Strategies.Identifiers.EoaCollateralSwitch,
|
|
136
|
+
protocol: PROTOCOLS.AaveV4,
|
|
137
|
+
},
|
|
126
138
|
};
|
|
127
139
|
|
|
128
140
|
export const OPTIMISM_STRATEGIES_INFO: OptimismStrategiesInfo = {
|
|
@@ -496,6 +508,66 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
|
|
|
496
508
|
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
497
509
|
protocol: PROTOCOLS.MorphoBlue,
|
|
498
510
|
},
|
|
511
|
+
[Bundles.MainnetIds.SPARK_REPAY_ON_PRICE]: {
|
|
512
|
+
strategyOrBundleId: Bundles.MainnetIds.SPARK_REPAY_ON_PRICE,
|
|
513
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
514
|
+
protocol: PROTOCOLS.Spark,
|
|
515
|
+
},
|
|
516
|
+
[Bundles.MainnetIds.SPARK_BOOST_ON_PRICE]: {
|
|
517
|
+
strategyOrBundleId: Bundles.MainnetIds.SPARK_BOOST_ON_PRICE,
|
|
518
|
+
strategyId: Strategies.Identifiers.BoostOnPrice,
|
|
519
|
+
protocol: PROTOCOLS.Spark,
|
|
520
|
+
},
|
|
521
|
+
[Bundles.MainnetIds.AAVE_V4_REPAY]: {
|
|
522
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_REPAY,
|
|
523
|
+
strategyId: Strategies.Identifiers.Repay,
|
|
524
|
+
protocol: PROTOCOLS.AaveV4,
|
|
525
|
+
},
|
|
526
|
+
[Bundles.MainnetIds.AAVE_V4_BOOST]: {
|
|
527
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_BOOST,
|
|
528
|
+
strategyId: Strategies.Identifiers.Boost,
|
|
529
|
+
protocol: PROTOCOLS.AaveV4,
|
|
530
|
+
},
|
|
531
|
+
[Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE]: {
|
|
532
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_REPAY_ON_PRICE,
|
|
533
|
+
strategyId: Strategies.Identifiers.RepayOnPrice,
|
|
534
|
+
protocol: PROTOCOLS.AaveV4,
|
|
535
|
+
},
|
|
536
|
+
[Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE]: {
|
|
537
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_BOOST_ON_PRICE,
|
|
538
|
+
strategyId: Strategies.Identifiers.BoostOnPrice,
|
|
539
|
+
protocol: PROTOCOLS.AaveV4,
|
|
540
|
+
},
|
|
541
|
+
[Bundles.MainnetIds.AAVE_V4_CLOSE]: {
|
|
542
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_CLOSE,
|
|
543
|
+
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
544
|
+
protocol: PROTOCOLS.AaveV4,
|
|
545
|
+
},
|
|
546
|
+
[Bundles.MainnetIds.AAVE_V4_EOA_REPAY]: {
|
|
547
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_REPAY,
|
|
548
|
+
strategyId: Strategies.Identifiers.EoaRepay,
|
|
549
|
+
protocol: PROTOCOLS.AaveV4,
|
|
550
|
+
},
|
|
551
|
+
[Bundles.MainnetIds.AAVE_V4_EOA_BOOST]: {
|
|
552
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_BOOST,
|
|
553
|
+
strategyId: Strategies.Identifiers.EoaBoost,
|
|
554
|
+
protocol: PROTOCOLS.AaveV4,
|
|
555
|
+
},
|
|
556
|
+
[Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE]: {
|
|
557
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_REPAY_ON_PRICE,
|
|
558
|
+
strategyId: Strategies.Identifiers.EoaRepayOnPrice,
|
|
559
|
+
protocol: PROTOCOLS.AaveV4,
|
|
560
|
+
},
|
|
561
|
+
[Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE]: {
|
|
562
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_BOOST_ON_PRICE,
|
|
563
|
+
strategyId: Strategies.Identifiers.EoaBoostOnPrice,
|
|
564
|
+
protocol: PROTOCOLS.AaveV4,
|
|
565
|
+
},
|
|
566
|
+
[Bundles.MainnetIds.AAVE_V4_EOA_CLOSE]: {
|
|
567
|
+
strategyOrBundleId: Bundles.MainnetIds.AAVE_V4_EOA_CLOSE,
|
|
568
|
+
strategyId: Strategies.Identifiers.EoaCloseOnPrice,
|
|
569
|
+
protocol: PROTOCOLS.AaveV4,
|
|
570
|
+
},
|
|
499
571
|
};
|
|
500
572
|
|
|
501
573
|
export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
|
|
@@ -161,6 +161,7 @@ describe('Feature: ethereumService.ts', () => {
|
|
|
161
161
|
'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
|
|
162
162
|
'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
|
|
163
163
|
'blockNumber': 5353002,
|
|
164
|
+
'blockTimestamp': '0x624c1a5b',
|
|
164
165
|
'event': 'Transfer',
|
|
165
166
|
'id': 'log_f49645b8',
|
|
166
167
|
'logIndex': 1,
|
|
@@ -206,6 +207,7 @@ describe('Feature: ethereumService.ts', () => {
|
|
|
206
207
|
'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
|
|
207
208
|
'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
|
|
208
209
|
'blockNumber': 5353002,
|
|
210
|
+
'blockTimestamp': '0x624c1a5b',
|
|
209
211
|
'event': 'Transfer',
|
|
210
212
|
'id': 'log_f49645b8',
|
|
211
213
|
'logIndex': 1,
|
|
@@ -7,7 +7,9 @@ import type {
|
|
|
7
7
|
Position, ParseData, StrategiesToProtocolVersionMapping, BundleOrStrategy, StrategyOrBundleIds,
|
|
8
8
|
BundleInfoUnion, StrategyInfoUnion,
|
|
9
9
|
} from '../types';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
ChainId, ProtocolIdentifiers, RatioState, Strategies,
|
|
12
|
+
} from '../types/enums';
|
|
11
13
|
|
|
12
14
|
import {
|
|
13
15
|
getPositionId, getRatioStateInfoForAaveCloseStrategy, getStopLossAndTakeProfitTypeByCloseStrategyType, isRatioStateOver, wethToEthByAddress,
|
|
@@ -383,6 +385,108 @@ function parseAaveV3CollateralSwitch(position: Position.Automated, parseData: Pa
|
|
|
383
385
|
return _position;
|
|
384
386
|
}
|
|
385
387
|
|
|
388
|
+
function parseAaveV4LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
389
|
+
const _position = cloneDeep(position);
|
|
390
|
+
const { subStruct, subId, subHash } = parseData.subscriptionEventData;
|
|
391
|
+
const { isEnabled } = parseData.strategiesSubsData;
|
|
392
|
+
const triggerData = triggerService.aaveV4RatioTrigger.decode(subStruct.triggerData);
|
|
393
|
+
const subData = subDataService.aaveV4LeverageManagementSubData.decode(subStruct.subData);
|
|
394
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
395
|
+
const isRepay = [Strategies.Identifiers.Repay, Strategies.Identifiers.EoaRepay].includes(_position.strategy.strategyId as Strategies.Identifiers);
|
|
396
|
+
|
|
397
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
398
|
+
_position.strategyData.decoded.subData = subData;
|
|
399
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
400
|
+
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagement : Strategies.IdOverrides.LeverageManagement;
|
|
401
|
+
|
|
402
|
+
if (isRepay) {
|
|
403
|
+
_position.specific = {
|
|
404
|
+
triggerRepayRatio: triggerData.ratio,
|
|
405
|
+
targetRepayRatio: subData.targetRatio,
|
|
406
|
+
repayEnabled: isEnabled,
|
|
407
|
+
subId1: Number(subId),
|
|
408
|
+
mergeWithId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
409
|
+
subHashRepay: subHash,
|
|
410
|
+
};
|
|
411
|
+
} else {
|
|
412
|
+
_position.specific = {
|
|
413
|
+
triggerBoostRatio: triggerData.ratio,
|
|
414
|
+
targetBoostRatio: subData.targetRatio,
|
|
415
|
+
boostEnabled: isEnabled,
|
|
416
|
+
subId2: Number(subId),
|
|
417
|
+
mergeId: isEOA ? Strategies.Identifiers.EoaBoost : Strategies.Identifiers.Boost,
|
|
418
|
+
subHashBoost: subHash,
|
|
419
|
+
};
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return _position;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function parseAaveV4LeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
426
|
+
const _position = cloneDeep(position);
|
|
427
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
428
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
|
|
429
|
+
const subData = subDataService.aaveV4LeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
430
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
431
|
+
|
|
432
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
433
|
+
_position.strategyData.decoded.subData = subData;
|
|
434
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
435
|
+
_position.strategy.strategyId = isEOA ? Strategies.IdOverrides.EoaLeverageManagementOnPrice : Strategies.IdOverrides.LeverageManagementOnPrice;
|
|
436
|
+
|
|
437
|
+
_position.specific = {
|
|
438
|
+
collAsset: subData.collAsset,
|
|
439
|
+
collAssetId: subData.collAssetId,
|
|
440
|
+
debtAsset: subData.debtAsset,
|
|
441
|
+
debtAssetId: subData.debtAssetId,
|
|
442
|
+
price: triggerData.price,
|
|
443
|
+
ratioState: triggerData.ratioState,
|
|
444
|
+
ratio: subData.targetRatio,
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
return _position;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
function parseAaveV4CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
451
|
+
const _position = cloneDeep(position);
|
|
452
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
453
|
+
const triggerData = triggerService.aaveV4QuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
454
|
+
const subData = subDataService.aaveV4CloseSubData.decode(subStruct.subData);
|
|
455
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
456
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
457
|
+
|
|
458
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
459
|
+
_position.strategyData.decoded.subData = subData;
|
|
460
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
461
|
+
_position.strategy.strategyId = isEOA ? Strategies.Identifiers.EoaCloseOnPrice : Strategies.Identifiers.CloseOnPrice;
|
|
462
|
+
|
|
463
|
+
_position.specific = {
|
|
464
|
+
collAsset: subData.collAsset,
|
|
465
|
+
collAssetId: subData.collAssetId,
|
|
466
|
+
debtAsset: subData.debtAsset,
|
|
467
|
+
debtAssetId: subData.debtAssetId,
|
|
468
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
469
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
470
|
+
stopLossType,
|
|
471
|
+
takeProfitType,
|
|
472
|
+
};
|
|
473
|
+
|
|
474
|
+
return _position;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
function parseAaveV4CollateralSwitch(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
478
|
+
const _position = cloneDeep(position);
|
|
479
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
480
|
+
const triggerData = triggerService.aaveV4QuotePriceTrigger.decode(subStruct.triggerData);
|
|
481
|
+
const subData = subDataService.aaveV4CollateralSwitchSubData.decode(subStruct.subData);
|
|
482
|
+
const isEOA = _position.strategy.strategyId.includes('eoa');
|
|
483
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
484
|
+
_position.strategyData.decoded.subData = subData;
|
|
485
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.spoke);
|
|
486
|
+
_position.strategy.strategyId = isEOA ? Strategies.Identifiers.EoaCollateralSwitch : Strategies.Identifiers.CollateralSwitch;
|
|
487
|
+
return _position;
|
|
488
|
+
}
|
|
489
|
+
|
|
386
490
|
function parseMorphoAaveV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
387
491
|
const _position = cloneDeep(position);
|
|
388
492
|
|
|
@@ -782,9 +886,37 @@ function parseSparkLeverageManagement(position: Position.Automated, parseData: P
|
|
|
782
886
|
return _position;
|
|
783
887
|
}
|
|
784
888
|
|
|
785
|
-
function
|
|
889
|
+
function parseSparkLeverageManagementOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
786
890
|
const _position = cloneDeep(position);
|
|
891
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
892
|
+
|
|
893
|
+
const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
|
|
894
|
+
const subData = subDataService.sparkLeverageManagementOnPriceSubData.decode(subStruct.subData);
|
|
895
|
+
|
|
896
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
897
|
+
_position.strategyData.decoded.subData = subData;
|
|
898
|
+
|
|
899
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
|
|
787
900
|
|
|
901
|
+
_position.specific = {
|
|
902
|
+
// subData
|
|
903
|
+
collAsset: subData.collAsset,
|
|
904
|
+
collAssetId: subData.collAssetId,
|
|
905
|
+
debtAsset: subData.debtAsset,
|
|
906
|
+
debtAssetId: subData.debtAssetId,
|
|
907
|
+
ratio: subData.targetRatio,
|
|
908
|
+
// triggerData
|
|
909
|
+
baseToken: triggerData.baseTokenAddr,
|
|
910
|
+
quoteToken: triggerData.quoteTokenAddr,
|
|
911
|
+
price: triggerData.price,
|
|
912
|
+
ratioState: triggerData.ratioState,
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
return _position;
|
|
916
|
+
}
|
|
917
|
+
|
|
918
|
+
function parseSparkCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
919
|
+
const _position = cloneDeep(position);
|
|
788
920
|
const { subStruct } = parseData.subscriptionEventData;
|
|
789
921
|
|
|
790
922
|
const triggerData = triggerService.sparkQuotePriceRangeTrigger.decode(subStruct.triggerData);
|
|
@@ -1207,6 +1339,20 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
1207
1339
|
[Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV3CloseOnPrice,
|
|
1208
1340
|
[Strategies.Identifiers.CollateralSwitch]: parseAaveV3CollateralSwitch,
|
|
1209
1341
|
},
|
|
1342
|
+
[ProtocolIdentifiers.StrategiesAutomation.AaveV4]: {
|
|
1343
|
+
[Strategies.Identifiers.Repay]: parseAaveV4LeverageManagement,
|
|
1344
|
+
[Strategies.Identifiers.Boost]: parseAaveV4LeverageManagement,
|
|
1345
|
+
[Strategies.Identifiers.RepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1346
|
+
[Strategies.Identifiers.BoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1347
|
+
[Strategies.Identifiers.CloseOnPrice]: parseAaveV4CloseOnPrice,
|
|
1348
|
+
[Strategies.Identifiers.EoaRepay]: parseAaveV4LeverageManagement,
|
|
1349
|
+
[Strategies.Identifiers.EoaBoost]: parseAaveV4LeverageManagement,
|
|
1350
|
+
[Strategies.Identifiers.EoaRepayOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1351
|
+
[Strategies.Identifiers.EoaBoostOnPrice]: parseAaveV4LeverageManagementOnPrice,
|
|
1352
|
+
[Strategies.Identifiers.EoaCloseOnPrice]: parseAaveV4CloseOnPrice,
|
|
1353
|
+
[Strategies.Identifiers.CollateralSwitch]: parseAaveV4CollateralSwitch,
|
|
1354
|
+
[Strategies.Identifiers.EoaCollateralSwitch]: parseAaveV4CollateralSwitch,
|
|
1355
|
+
},
|
|
1210
1356
|
[ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
|
|
1211
1357
|
[Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
|
|
1212
1358
|
[Strategies.Identifiers.Boost]: parseCompoundV2LeverageManagement,
|
|
@@ -1237,6 +1383,8 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
1237
1383
|
[ProtocolIdentifiers.StrategiesAutomation.Spark]: {
|
|
1238
1384
|
[Strategies.Identifiers.Repay]: parseSparkLeverageManagement,
|
|
1239
1385
|
[Strategies.Identifiers.Boost]: parseSparkLeverageManagement,
|
|
1386
|
+
[Strategies.Identifiers.RepayOnPrice]: parseSparkLeverageManagementOnPrice,
|
|
1387
|
+
[Strategies.Identifiers.BoostOnPrice]: parseSparkLeverageManagementOnPrice,
|
|
1240
1388
|
[Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
|
|
1241
1389
|
},
|
|
1242
1390
|
[ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
|