@defisaver/automation-sdk 3.1.7 → 3.1.8-dev-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/cjs/constants/index.js +5 -0
- package/cjs/services/strategiesService.js +28 -9
- package/cjs/services/strategySubService.d.ts +1 -0
- package/cjs/services/strategySubService.js +7 -0
- package/cjs/services/subDataService.d.ts +10 -0
- package/cjs/services/subDataService.js +28 -1
- package/cjs/types/enums.d.ts +2 -1
- package/cjs/types/enums.js +1 -0
- package/cjs/types/index.d.ts +12 -1
- package/esm/constants/index.js +5 -0
- package/esm/services/strategiesService.js +28 -9
- package/esm/services/strategySubService.d.ts +1 -0
- package/esm/services/strategySubService.js +7 -0
- package/esm/services/subDataService.d.ts +10 -0
- package/esm/services/subDataService.js +27 -0
- package/esm/types/enums.d.ts +2 -1
- package/esm/types/enums.js +1 -0
- package/esm/types/index.d.ts +12 -1
- package/package.json +1 -1
- package/src/constants/index.ts +5 -0
- package/src/services/strategiesService.ts +30 -5
- package/src/services/strategySubService.ts +17 -1
- package/src/services/subDataService.ts +35 -0
- package/src/types/enums.ts +1 -0
- package/src/types/index.ts +16 -1
package/cjs/constants/index.js
CHANGED
|
@@ -96,6 +96,11 @@ exports.MAINNET_STRATEGIES_INFO = {
|
|
|
96
96
|
strategyId: enums_1.Strategies.Identifiers.Payback,
|
|
97
97
|
protocol: exports.PROTOCOLS.CrvUSD,
|
|
98
98
|
},
|
|
99
|
+
[enums_1.Strategies.MainnetIds.LIQUITY_V2_PAYBACK]: {
|
|
100
|
+
strategyOrBundleId: enums_1.Strategies.MainnetIds.LIQUITY_V2_PAYBACK,
|
|
101
|
+
strategyId: enums_1.Strategies.Identifiers.Payback,
|
|
102
|
+
protocol: exports.PROTOCOLS.LiquityV2,
|
|
103
|
+
},
|
|
99
104
|
};
|
|
100
105
|
exports.OPTIMISM_STRATEGIES_INFO = {
|
|
101
106
|
[enums_1.Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -709,16 +709,34 @@ function parseLiquityV2LeverageManagementOnPrice(position, parseData) {
|
|
|
709
709
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
710
710
|
_position.strategyData.decoded.subData = subData;
|
|
711
711
|
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
712
|
-
/// @TODO: what does even go here
|
|
713
|
-
/*
|
|
714
712
|
_position.specific = {
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
713
|
+
subHash: _position.subHash,
|
|
714
|
+
market: subData.market,
|
|
715
|
+
troveId: subData.troveId,
|
|
716
|
+
collAsset: subData.collToken,
|
|
717
|
+
debtAsset: subData.boldToken,
|
|
718
|
+
price: triggerData.price,
|
|
719
|
+
ratio: subData.targetRatio,
|
|
720
|
+
ratioState: triggerData.ratioState,
|
|
721
|
+
};
|
|
722
|
+
return _position;
|
|
723
|
+
}
|
|
724
|
+
function parseLiquityV2Payback(position, parseData) {
|
|
725
|
+
const _position = (0, lodash_1.cloneDeep)(position);
|
|
726
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
727
|
+
const triggerData = triggerService.liquityV2RatioTrigger.decode(subStruct.triggerData);
|
|
728
|
+
const subData = subDataService.liquityV2PaybackSubData.decode(subStruct.subData);
|
|
729
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
730
|
+
_position.strategyData.decoded.subData = subData;
|
|
731
|
+
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, triggerData.troveId, triggerData.market);
|
|
732
|
+
_position.strategy.strategyId = enums_1.Strategies.Identifiers.Payback;
|
|
733
|
+
_position.specific = {
|
|
734
|
+
subHash: _position.subHash,
|
|
735
|
+
market: subData.market,
|
|
736
|
+
troveId: subData.troveId,
|
|
737
|
+
targetRatio: subData.targetRatio,
|
|
738
|
+
triggerRatio: triggerData.ratio,
|
|
720
739
|
};
|
|
721
|
-
*/
|
|
722
740
|
return _position;
|
|
723
741
|
}
|
|
724
742
|
const parsingMethodsMapping = {
|
|
@@ -745,8 +763,9 @@ const parsingMethodsMapping = {
|
|
|
745
763
|
[enums_1.Strategies.Identifiers.Repay]: parseLiquityV2LeverageManagement,
|
|
746
764
|
[enums_1.Strategies.Identifiers.Boost]: parseLiquityV2LeverageManagement,
|
|
747
765
|
[enums_1.Strategies.Identifiers.CloseOnPrice]: parseLiquityV2CloseOnPrice,
|
|
748
|
-
[enums_1.Strategies.Identifiers.
|
|
766
|
+
[enums_1.Strategies.Identifiers.BoostOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
749
767
|
[enums_1.Strategies.Identifiers.RepayOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
768
|
+
[enums_1.Strategies.Identifiers.Payback]: parseLiquityV2Payback,
|
|
750
769
|
},
|
|
751
770
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
|
|
752
771
|
[enums_1.Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
|
|
@@ -103,4 +103,5 @@ export declare const liquityV2Encode: {
|
|
|
103
103
|
leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
104
104
|
closeOnPrice(strategyOrBundleId: number, market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
105
105
|
leverageManagementOnPrice(strategyOrBundleId: number, market: EthereumAddress, price: number, state: RatioState, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, targetRatio: number, isRepayOnPrice: boolean): (number | boolean | string[])[];
|
|
106
|
+
payback(market: EthereumAddress, troveId: string, boldToken: EthereumAddress, targetRatio: number, ratioState: RatioState, triggerRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
106
107
|
};
|
|
@@ -290,4 +290,11 @@ exports.liquityV2Encode = {
|
|
|
290
290
|
const isBundle = true;
|
|
291
291
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
292
292
|
},
|
|
293
|
+
payback(market, troveId, boldToken, targetRatio, ratioState, triggerRatio) {
|
|
294
|
+
const strategyId = enums_1.Strategies.MainnetIds.LIQUITY_V2_PAYBACK;
|
|
295
|
+
const isBundle = false;
|
|
296
|
+
const subData = subDataService.liquityV2PaybackSubData.encode(market, troveId, boldToken, targetRatio, ratioState);
|
|
297
|
+
const triggerData = triggerService.liquityV2RatioTrigger.encode(market, troveId, triggerRatio, ratioState);
|
|
298
|
+
return [strategyId, isBundle, triggerData, subData];
|
|
299
|
+
},
|
|
293
300
|
};
|
|
@@ -233,3 +233,13 @@ export declare const morphoBlueLeverageManagementOnPriceSubData: {
|
|
|
233
233
|
user: string;
|
|
234
234
|
};
|
|
235
235
|
};
|
|
236
|
+
export declare const liquityV2PaybackSubData: {
|
|
237
|
+
encode: (market: EthereumAddress, troveId: string, boldToken: EthereumAddress, targetRatio: number, ratioState: RatioState) => string[];
|
|
238
|
+
decode: (subData: string[]) => {
|
|
239
|
+
market: string;
|
|
240
|
+
troveId: string;
|
|
241
|
+
boldToken: string;
|
|
242
|
+
ratioState: RatioState;
|
|
243
|
+
targetRatio: number;
|
|
244
|
+
};
|
|
245
|
+
};
|
|
@@ -3,7 +3,7 @@ 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.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
|
|
6
|
+
exports.liquityV2PaybackSubData = exports.morphoBlueLeverageManagementOnPriceSubData = exports.liquityV2LeverageManagementOnPriceSubData = exports.liquityV2CloseSubData = exports.liquityV2LeverageManagementSubData = exports.aaveV3LeverageManagementOnPriceSubData = exports.morphoBlueLeverageManagementSubData = exports.crvUSDPaybackSubData = exports.crvUSDLeverageManagementSubData = exports.liquityDebtInFrontRepaySubData = exports.liquityDsrSupplySubData = exports.liquityDsrPaybackSubData = exports.sparkQuotePriceSubData = exports.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3LeverageManagementSubData = exports.aaveV2LeverageManagementSubData = exports.liquityCloseSubData = exports.liquityLeverageManagementSubData = exports.makerLeverageManagementSubData = exports.makerCloseSubData = exports.liquityRepayFromSavingsSubData = exports.makerRepayFromSavingsSubData = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
9
9
|
const web3_utils_1 = require("web3-utils");
|
|
@@ -607,3 +607,30 @@ exports.morphoBlueLeverageManagementOnPriceSubData = {
|
|
|
607
607
|
};
|
|
608
608
|
},
|
|
609
609
|
};
|
|
610
|
+
exports.liquityV2PaybackSubData = {
|
|
611
|
+
encode: (market, troveId, boldToken, targetRatio, ratioState) => {
|
|
612
|
+
const marketEncoded = web3_eth_abi_1.default.encodeParameter('address', market);
|
|
613
|
+
const troveIdEncoded = web3_eth_abi_1.default.encodeParameter('uint256', troveId);
|
|
614
|
+
const boldTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', boldToken);
|
|
615
|
+
const targetRatioEncoded = web3_eth_abi_1.default.encodeParameter('uint256', (0, utils_1.ratioPercentageToWei)(targetRatio));
|
|
616
|
+
const ratioStateEncoded = web3_eth_abi_1.default.encodeParameter('uint8', ratioState);
|
|
617
|
+
return [
|
|
618
|
+
marketEncoded,
|
|
619
|
+
troveIdEncoded,
|
|
620
|
+
boldTokenEncoded,
|
|
621
|
+
targetRatioEncoded,
|
|
622
|
+
ratioStateEncoded,
|
|
623
|
+
];
|
|
624
|
+
},
|
|
625
|
+
decode: (subData) => {
|
|
626
|
+
const market = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
627
|
+
const troveId = web3_eth_abi_1.default.decodeParameter('uint256', subData[1]);
|
|
628
|
+
const boldToken = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
629
|
+
const weiRatio = web3_eth_abi_1.default.decodeParameter('uint256', subData[3]);
|
|
630
|
+
const ratioState = web3_eth_abi_1.default.decodeParameter('uint8', subData[4]);
|
|
631
|
+
const targetRatio = (0, utils_1.weiToRatioPercentage)(weiRatio);
|
|
632
|
+
return {
|
|
633
|
+
market, troveId, boldToken, ratioState, targetRatio,
|
|
634
|
+
};
|
|
635
|
+
},
|
|
636
|
+
};
|
package/cjs/types/enums.d.ts
CHANGED
|
@@ -83,7 +83,8 @@ export declare namespace Strategies {
|
|
|
83
83
|
LIQUITY_DSR_PAYBACK = 69,
|
|
84
84
|
LIQUITY_DSR_SUPPLY = 70,
|
|
85
85
|
LIQUITY_DEBT_IN_FRONT_REPAY = 75,
|
|
86
|
-
CURVEUSD_PAYBACK = 92
|
|
86
|
+
CURVEUSD_PAYBACK = 92,
|
|
87
|
+
LIQUITY_V2_PAYBACK = 113
|
|
87
88
|
}
|
|
88
89
|
enum OptimismIds {
|
|
89
90
|
EXCHANGE_DCA = 8,
|
package/cjs/types/enums.js
CHANGED
|
@@ -100,6 +100,7 @@ var Strategies;
|
|
|
100
100
|
MainnetIds[MainnetIds["LIQUITY_DSR_SUPPLY"] = 70] = "LIQUITY_DSR_SUPPLY";
|
|
101
101
|
MainnetIds[MainnetIds["LIQUITY_DEBT_IN_FRONT_REPAY"] = 75] = "LIQUITY_DEBT_IN_FRONT_REPAY";
|
|
102
102
|
MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
|
|
103
|
+
MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
|
|
103
104
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
104
105
|
let OptimismIds;
|
|
105
106
|
(function (OptimismIds) {
|
package/cjs/types/index.d.ts
CHANGED
|
@@ -147,6 +147,17 @@ export declare namespace Position {
|
|
|
147
147
|
stopLossType: CloseToAssetType | undefined;
|
|
148
148
|
takeProfitType: CloseToAssetType | undefined;
|
|
149
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
|
+
}
|
|
150
161
|
interface TrailingStop extends Base {
|
|
151
162
|
roundId: number;
|
|
152
163
|
triggerPercentage: number;
|
|
@@ -161,7 +172,7 @@ export declare namespace Position {
|
|
|
161
172
|
subHashRepay?: string;
|
|
162
173
|
}
|
|
163
174
|
}
|
|
164
|
-
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho;
|
|
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;
|
|
165
176
|
interface Automated {
|
|
166
177
|
chainId: ChainId;
|
|
167
178
|
positionId: string;
|
package/esm/constants/index.js
CHANGED
|
@@ -90,6 +90,11 @@ export const MAINNET_STRATEGIES_INFO = {
|
|
|
90
90
|
strategyId: Strategies.Identifiers.Payback,
|
|
91
91
|
protocol: PROTOCOLS.CrvUSD,
|
|
92
92
|
},
|
|
93
|
+
[Strategies.MainnetIds.LIQUITY_V2_PAYBACK]: {
|
|
94
|
+
strategyOrBundleId: Strategies.MainnetIds.LIQUITY_V2_PAYBACK,
|
|
95
|
+
strategyId: Strategies.Identifiers.Payback,
|
|
96
|
+
protocol: PROTOCOLS.LiquityV2,
|
|
97
|
+
},
|
|
93
98
|
};
|
|
94
99
|
export const OPTIMISM_STRATEGIES_INFO = {
|
|
95
100
|
[Strategies.OptimismIds.EXCHANGE_DCA]: {
|
|
@@ -680,16 +680,34 @@ function parseLiquityV2LeverageManagementOnPrice(position, parseData) {
|
|
|
680
680
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
681
681
|
_position.strategyData.decoded.subData = subData;
|
|
682
682
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
683
|
-
/// @TODO: what does even go here
|
|
684
|
-
/*
|
|
685
683
|
_position.specific = {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
684
|
+
subHash: _position.subHash,
|
|
685
|
+
market: subData.market,
|
|
686
|
+
troveId: subData.troveId,
|
|
687
|
+
collAsset: subData.collToken,
|
|
688
|
+
debtAsset: subData.boldToken,
|
|
689
|
+
price: triggerData.price,
|
|
690
|
+
ratio: subData.targetRatio,
|
|
691
|
+
ratioState: triggerData.ratioState,
|
|
692
|
+
};
|
|
693
|
+
return _position;
|
|
694
|
+
}
|
|
695
|
+
function parseLiquityV2Payback(position, parseData) {
|
|
696
|
+
const _position = cloneDeep(position);
|
|
697
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
698
|
+
const triggerData = triggerService.liquityV2RatioTrigger.decode(subStruct.triggerData);
|
|
699
|
+
const subData = subDataService.liquityV2PaybackSubData.decode(subStruct.subData);
|
|
700
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
701
|
+
_position.strategyData.decoded.subData = subData;
|
|
702
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, triggerData.troveId, triggerData.market);
|
|
703
|
+
_position.strategy.strategyId = Strategies.Identifiers.Payback;
|
|
704
|
+
_position.specific = {
|
|
705
|
+
subHash: _position.subHash,
|
|
706
|
+
market: subData.market,
|
|
707
|
+
troveId: subData.troveId,
|
|
708
|
+
targetRatio: subData.targetRatio,
|
|
709
|
+
triggerRatio: triggerData.ratio,
|
|
691
710
|
};
|
|
692
|
-
*/
|
|
693
711
|
return _position;
|
|
694
712
|
}
|
|
695
713
|
const parsingMethodsMapping = {
|
|
@@ -716,8 +734,9 @@ const parsingMethodsMapping = {
|
|
|
716
734
|
[Strategies.Identifiers.Repay]: parseLiquityV2LeverageManagement,
|
|
717
735
|
[Strategies.Identifiers.Boost]: parseLiquityV2LeverageManagement,
|
|
718
736
|
[Strategies.Identifiers.CloseOnPrice]: parseLiquityV2CloseOnPrice,
|
|
719
|
-
[Strategies.Identifiers.
|
|
737
|
+
[Strategies.Identifiers.BoostOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
720
738
|
[Strategies.Identifiers.RepayOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
739
|
+
[Strategies.Identifiers.Payback]: parseLiquityV2Payback,
|
|
721
740
|
},
|
|
722
741
|
[ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
|
|
723
742
|
[Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
|
|
@@ -103,4 +103,5 @@ export declare const liquityV2Encode: {
|
|
|
103
103
|
leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
104
104
|
closeOnPrice(strategyOrBundleId: number, market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
105
105
|
leverageManagementOnPrice(strategyOrBundleId: number, market: EthereumAddress, price: number, state: RatioState, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, targetRatio: number, isRepayOnPrice: boolean): (number | boolean | string[])[];
|
|
106
|
+
payback(market: EthereumAddress, troveId: string, boldToken: EthereumAddress, targetRatio: number, ratioState: RatioState, triggerRatio: number): (boolean | string[] | Strategies.MainnetIds)[];
|
|
106
107
|
};
|
|
@@ -261,4 +261,11 @@ export const liquityV2Encode = {
|
|
|
261
261
|
const isBundle = true;
|
|
262
262
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
263
263
|
},
|
|
264
|
+
payback(market, troveId, boldToken, targetRatio, ratioState, triggerRatio) {
|
|
265
|
+
const strategyId = Strategies.MainnetIds.LIQUITY_V2_PAYBACK;
|
|
266
|
+
const isBundle = false;
|
|
267
|
+
const subData = subDataService.liquityV2PaybackSubData.encode(market, troveId, boldToken, targetRatio, ratioState);
|
|
268
|
+
const triggerData = triggerService.liquityV2RatioTrigger.encode(market, troveId, triggerRatio, ratioState);
|
|
269
|
+
return [strategyId, isBundle, triggerData, subData];
|
|
270
|
+
},
|
|
264
271
|
};
|
|
@@ -233,3 +233,13 @@ export declare const morphoBlueLeverageManagementOnPriceSubData: {
|
|
|
233
233
|
user: string;
|
|
234
234
|
};
|
|
235
235
|
};
|
|
236
|
+
export declare const liquityV2PaybackSubData: {
|
|
237
|
+
encode: (market: EthereumAddress, troveId: string, boldToken: EthereumAddress, targetRatio: number, ratioState: RatioState) => string[];
|
|
238
|
+
decode: (subData: string[]) => {
|
|
239
|
+
market: string;
|
|
240
|
+
troveId: string;
|
|
241
|
+
boldToken: string;
|
|
242
|
+
ratioState: RatioState;
|
|
243
|
+
targetRatio: number;
|
|
244
|
+
};
|
|
245
|
+
};
|
|
@@ -601,3 +601,30 @@ export const morphoBlueLeverageManagementOnPriceSubData = {
|
|
|
601
601
|
};
|
|
602
602
|
},
|
|
603
603
|
};
|
|
604
|
+
export const liquityV2PaybackSubData = {
|
|
605
|
+
encode: (market, troveId, boldToken, targetRatio, ratioState) => {
|
|
606
|
+
const marketEncoded = AbiCoder.encodeParameter('address', market);
|
|
607
|
+
const troveIdEncoded = AbiCoder.encodeParameter('uint256', troveId);
|
|
608
|
+
const boldTokenEncoded = AbiCoder.encodeParameter('address', boldToken);
|
|
609
|
+
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
610
|
+
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
611
|
+
return [
|
|
612
|
+
marketEncoded,
|
|
613
|
+
troveIdEncoded,
|
|
614
|
+
boldTokenEncoded,
|
|
615
|
+
targetRatioEncoded,
|
|
616
|
+
ratioStateEncoded,
|
|
617
|
+
];
|
|
618
|
+
},
|
|
619
|
+
decode: (subData) => {
|
|
620
|
+
const market = AbiCoder.decodeParameter('address', subData[0]);
|
|
621
|
+
const troveId = AbiCoder.decodeParameter('uint256', subData[1]);
|
|
622
|
+
const boldToken = AbiCoder.decodeParameter('address', subData[2]);
|
|
623
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]);
|
|
624
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[4]);
|
|
625
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
626
|
+
return {
|
|
627
|
+
market, troveId, boldToken, ratioState, targetRatio,
|
|
628
|
+
};
|
|
629
|
+
},
|
|
630
|
+
};
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -83,7 +83,8 @@ export declare namespace Strategies {
|
|
|
83
83
|
LIQUITY_DSR_PAYBACK = 69,
|
|
84
84
|
LIQUITY_DSR_SUPPLY = 70,
|
|
85
85
|
LIQUITY_DEBT_IN_FRONT_REPAY = 75,
|
|
86
|
-
CURVEUSD_PAYBACK = 92
|
|
86
|
+
CURVEUSD_PAYBACK = 92,
|
|
87
|
+
LIQUITY_V2_PAYBACK = 113
|
|
87
88
|
}
|
|
88
89
|
enum OptimismIds {
|
|
89
90
|
EXCHANGE_DCA = 8,
|
package/esm/types/enums.js
CHANGED
|
@@ -97,6 +97,7 @@ export var Strategies;
|
|
|
97
97
|
MainnetIds[MainnetIds["LIQUITY_DSR_SUPPLY"] = 70] = "LIQUITY_DSR_SUPPLY";
|
|
98
98
|
MainnetIds[MainnetIds["LIQUITY_DEBT_IN_FRONT_REPAY"] = 75] = "LIQUITY_DEBT_IN_FRONT_REPAY";
|
|
99
99
|
MainnetIds[MainnetIds["CURVEUSD_PAYBACK"] = 92] = "CURVEUSD_PAYBACK";
|
|
100
|
+
MainnetIds[MainnetIds["LIQUITY_V2_PAYBACK"] = 113] = "LIQUITY_V2_PAYBACK";
|
|
100
101
|
})(MainnetIds = Strategies.MainnetIds || (Strategies.MainnetIds = {}));
|
|
101
102
|
let OptimismIds;
|
|
102
103
|
(function (OptimismIds) {
|
package/esm/types/index.d.ts
CHANGED
|
@@ -147,6 +147,17 @@ export declare namespace Position {
|
|
|
147
147
|
stopLossType: CloseToAssetType | undefined;
|
|
148
148
|
takeProfitType: CloseToAssetType | undefined;
|
|
149
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
|
+
}
|
|
150
161
|
interface TrailingStop extends Base {
|
|
151
162
|
roundId: number;
|
|
152
163
|
triggerPercentage: number;
|
|
@@ -161,7 +172,7 @@ export declare namespace Position {
|
|
|
161
172
|
subHashRepay?: string;
|
|
162
173
|
}
|
|
163
174
|
}
|
|
164
|
-
type SpecificAny = Specific.CloseOnPrice | Specific.TrailingStop | Specific.RatioProtection | Specific.CloseOnPriceAave | Specific.BoostOnPriceAave | Specific.CloseOnPriceWithMaximumGasPriceAave | Specific.DebtInFrontRepay | Specific.LeverageManagementCrvUSD | Specific.CloseOnPriceLiquityV2 | Specific.BoostOnPriceMorpho;
|
|
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;
|
|
165
176
|
interface Automated {
|
|
166
177
|
chainId: ChainId;
|
|
167
178
|
positionId: string;
|
package/package.json
CHANGED
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 = {
|
|
@@ -935,16 +935,40 @@ function parseLiquityV2LeverageManagementOnPrice(position: Position.Automated, p
|
|
|
935
935
|
_position.strategyData.decoded.triggerData = triggerData;
|
|
936
936
|
_position.strategyData.decoded.subData = subData;
|
|
937
937
|
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
938
|
-
|
|
939
|
-
/*
|
|
938
|
+
|
|
940
939
|
_position.specific = {
|
|
940
|
+
subHash: _position.subHash,
|
|
941
941
|
market: subData.market,
|
|
942
942
|
troveId: subData.troveId,
|
|
943
|
-
|
|
943
|
+
collAsset: subData.collToken,
|
|
944
|
+
debtAsset: subData.boldToken,
|
|
944
945
|
price: triggerData.price,
|
|
946
|
+
ratio: subData.targetRatio,
|
|
945
947
|
ratioState: triggerData.ratioState,
|
|
946
948
|
};
|
|
947
|
-
|
|
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
|
+
};
|
|
948
972
|
|
|
949
973
|
return _position;
|
|
950
974
|
}
|
|
@@ -973,8 +997,9 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
973
997
|
[Strategies.Identifiers.Repay]: parseLiquityV2LeverageManagement,
|
|
974
998
|
[Strategies.Identifiers.Boost]: parseLiquityV2LeverageManagement,
|
|
975
999
|
[Strategies.Identifiers.CloseOnPrice]: parseLiquityV2CloseOnPrice,
|
|
976
|
-
[Strategies.Identifiers.
|
|
1000
|
+
[Strategies.Identifiers.BoostOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
977
1001
|
[Strategies.Identifiers.RepayOnPrice]: parseLiquityV2LeverageManagementOnPrice,
|
|
1002
|
+
[Strategies.Identifiers.Payback]: parseLiquityV2Payback,
|
|
978
1003
|
},
|
|
979
1004
|
[ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
|
|
980
1005
|
[Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
|
|
@@ -598,4 +598,20 @@ export const liquityV2Encode = {
|
|
|
598
598
|
const isBundle = true;
|
|
599
599
|
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
600
600
|
},
|
|
601
|
-
|
|
601
|
+
payback(
|
|
602
|
+
market: EthereumAddress,
|
|
603
|
+
troveId: string,
|
|
604
|
+
boldToken: EthereumAddress,
|
|
605
|
+
targetRatio: number,
|
|
606
|
+
ratioState: RatioState,
|
|
607
|
+
triggerRatio: number,
|
|
608
|
+
) {
|
|
609
|
+
const strategyId = Strategies.MainnetIds.LIQUITY_V2_PAYBACK;
|
|
610
|
+
const isBundle = false;
|
|
611
|
+
|
|
612
|
+
const subData = subDataService.liquityV2PaybackSubData.encode(market, troveId, boldToken, targetRatio, ratioState);
|
|
613
|
+
const triggerData = triggerService.liquityV2RatioTrigger.encode(market, troveId, triggerRatio, ratioState);
|
|
614
|
+
|
|
615
|
+
return [strategyId, isBundle, triggerData, subData];
|
|
616
|
+
},
|
|
617
|
+
};
|
|
@@ -833,3 +833,38 @@ export const morphoBlueLeverageManagementOnPriceSubData = {
|
|
|
833
833
|
};
|
|
834
834
|
},
|
|
835
835
|
};
|
|
836
|
+
export const liquityV2PaybackSubData = {
|
|
837
|
+
encode: (
|
|
838
|
+
market: EthereumAddress,
|
|
839
|
+
troveId: string,
|
|
840
|
+
boldToken: EthereumAddress,
|
|
841
|
+
targetRatio: number,
|
|
842
|
+
ratioState: RatioState,
|
|
843
|
+
) => {
|
|
844
|
+
const marketEncoded = AbiCoder.encodeParameter('address', market);
|
|
845
|
+
const troveIdEncoded = AbiCoder.encodeParameter('uint256', troveId);
|
|
846
|
+
const boldTokenEncoded = AbiCoder.encodeParameter('address', boldToken);
|
|
847
|
+
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
848
|
+
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
849
|
+
|
|
850
|
+
return [
|
|
851
|
+
marketEncoded,
|
|
852
|
+
troveIdEncoded,
|
|
853
|
+
boldTokenEncoded,
|
|
854
|
+
targetRatioEncoded,
|
|
855
|
+
ratioStateEncoded,
|
|
856
|
+
];
|
|
857
|
+
},
|
|
858
|
+
decode: (subData: SubData) => {
|
|
859
|
+
const market = AbiCoder.decodeParameter('address', subData[0]) as unknown as EthereumAddress;
|
|
860
|
+
const troveId = AbiCoder.decodeParameter('uint256', subData[1]) as any as string;
|
|
861
|
+
const boldToken = AbiCoder.decodeParameter('address', subData[2]) as any as EthereumAddress;
|
|
862
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]) as any as string;
|
|
863
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[4]) as any as RatioState;
|
|
864
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
865
|
+
|
|
866
|
+
return {
|
|
867
|
+
market, troveId, boldToken, ratioState, targetRatio,
|
|
868
|
+
};
|
|
869
|
+
},
|
|
870
|
+
};
|
package/src/types/enums.ts
CHANGED
package/src/types/index.ts
CHANGED
|
@@ -177,6 +177,19 @@ export declare namespace Position {
|
|
|
177
177
|
takeProfitType: CloseToAssetType | undefined,
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
interface BoostOnPriceLiquityV2 extends Base {
|
|
181
|
+
market: EthereumAddress,
|
|
182
|
+
troveId: string,
|
|
183
|
+
subHash: string;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
interface PaybackLiquityV2 extends Base {
|
|
187
|
+
market: EthereumAddress,
|
|
188
|
+
troveId: string,
|
|
189
|
+
targetRatio: number;
|
|
190
|
+
triggerRatio: number;
|
|
191
|
+
}
|
|
192
|
+
|
|
180
193
|
interface TrailingStop extends Base {
|
|
181
194
|
roundId: number,
|
|
182
195
|
triggerPercentage: number,
|
|
@@ -204,7 +217,9 @@ export declare namespace Position {
|
|
|
204
217
|
| Specific.DebtInFrontRepay
|
|
205
218
|
| Specific.LeverageManagementCrvUSD
|
|
206
219
|
| Specific.CloseOnPriceLiquityV2
|
|
207
|
-
| Specific.BoostOnPriceMorpho
|
|
220
|
+
| Specific.BoostOnPriceMorpho
|
|
221
|
+
| Specific.BoostOnPriceLiquityV2
|
|
222
|
+
| Specific.PaybackLiquityV2;
|
|
208
223
|
|
|
209
224
|
export interface Automated {
|
|
210
225
|
chainId: ChainId,
|