@defisaver/automation-sdk 3.3.7-morpho-dev → 3.3.7
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 +0 -15
- package/cjs/services/strategiesService.js +0 -30
- package/cjs/services/strategySubService.d.ts +0 -1
- package/cjs/services/strategySubService.js +0 -7
- package/cjs/services/strategySubService.test.js +0 -38
- package/cjs/services/subDataService.d.ts +0 -12
- package/cjs/services/subDataService.js +1 -31
- package/cjs/services/subDataService.test.js +0 -52
- package/cjs/services/triggerService.d.ts +0 -10
- package/cjs/services/triggerService.js +1 -21
- package/cjs/services/triggerService.test.js +0 -48
- package/cjs/types/enums.d.ts +3 -6
- package/cjs/types/enums.js +0 -3
- package/esm/constants/index.js +0 -15
- package/esm/services/strategiesService.js +0 -30
- package/esm/services/strategySubService.d.ts +0 -1
- package/esm/services/strategySubService.js +0 -7
- package/esm/services/strategySubService.test.js +0 -38
- package/esm/services/subDataService.d.ts +0 -12
- package/esm/services/subDataService.js +0 -30
- package/esm/services/subDataService.test.js +0 -52
- package/esm/services/triggerService.d.ts +0 -10
- package/esm/services/triggerService.js +0 -20
- package/esm/services/triggerService.test.js +1 -49
- package/esm/types/enums.d.ts +3 -6
- package/esm/types/enums.js +0 -3
- package/package.json +1 -1
- package/src/constants/index.ts +0 -15
- package/src/services/strategiesService.ts +0 -43
- package/src/services/strategySubService.test.ts +0 -55
- package/src/services/strategySubService.ts +0 -21
- package/src/services/subDataService.test.ts +0 -59
- package/src/services/subDataService.ts +0 -40
- package/src/services/triggerService.test.ts +0 -53
- package/src/services/triggerService.ts +0 -32
- package/src/types/enums.ts +0 -3
package/cjs/constants/index.js
CHANGED
|
@@ -468,11 +468,6 @@ exports.MAINNET_BUNDLES_INFO = {
|
|
|
468
468
|
strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
|
|
469
469
|
protocol: exports.PROTOCOLS.Spark,
|
|
470
470
|
},
|
|
471
|
-
[enums_1.Bundles.MainnetIds.MORPHO_BLUE_CLOSE]: {
|
|
472
|
-
strategyOrBundleId: enums_1.Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
473
|
-
strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
|
|
474
|
-
protocol: exports.PROTOCOLS.MorphoBlue,
|
|
475
|
-
},
|
|
476
471
|
};
|
|
477
472
|
exports.OPTIMISM_BUNDLES_INFO = {
|
|
478
473
|
[enums_1.Bundles.OptimismIds.AAVE_V3_REPAY]: {
|
|
@@ -662,11 +657,6 @@ exports.BASE_BUNDLES_INFO = {
|
|
|
662
657
|
strategyId: enums_1.Strategies.Identifiers.EoaCloseOnPrice,
|
|
663
658
|
protocol: exports.PROTOCOLS.AaveV3,
|
|
664
659
|
},
|
|
665
|
-
[enums_1.Bundles.BaseIds.MORPHO_BLUE_CLOSE]: {
|
|
666
|
-
strategyOrBundleId: enums_1.Bundles.BaseIds.MORPHO_BLUE_CLOSE,
|
|
667
|
-
strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
|
|
668
|
-
protocol: exports.PROTOCOLS.MorphoBlue,
|
|
669
|
-
},
|
|
670
660
|
};
|
|
671
661
|
exports.ARBITRUM_BUNDLES_INFO = {
|
|
672
662
|
[enums_1.Bundles.ArbitrumIds.AAVE_V3_REPAY]: {
|
|
@@ -809,11 +799,6 @@ exports.ARBITRUM_BUNDLES_INFO = {
|
|
|
809
799
|
strategyId: enums_1.Strategies.Identifiers.EoaBoost,
|
|
810
800
|
protocol: exports.PROTOCOLS.MorphoBlue,
|
|
811
801
|
},
|
|
812
|
-
[enums_1.Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE]: {
|
|
813
|
-
strategyOrBundleId: enums_1.Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE,
|
|
814
|
-
strategyId: enums_1.Strategies.Identifiers.CloseOnPrice,
|
|
815
|
-
protocol: exports.PROTOCOLS.MorphoBlue,
|
|
816
|
-
},
|
|
817
802
|
};
|
|
818
803
|
exports.BUNDLES_INFO = {
|
|
819
804
|
[enums_1.ChainId.Ethereum]: exports.MAINNET_BUNDLES_INFO,
|
|
@@ -770,35 +770,6 @@ function parseMorphoBlueLeverageManagementOnPrice(position, parseData) {
|
|
|
770
770
|
};
|
|
771
771
|
return _position;
|
|
772
772
|
}
|
|
773
|
-
function parseMorphoBlueCloseOnPrice(position, parseData) {
|
|
774
|
-
const _position = (0, lodash_1.cloneDeep)(position);
|
|
775
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
776
|
-
const triggerData = triggerService.morphoBluePriceRangeTrigger.decode(subStruct.triggerData);
|
|
777
|
-
const subData = subDataService.morphoBlueCloseOnPriceSubData.decode(subStruct.subData);
|
|
778
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
779
|
-
_position.strategyData.decoded.subData = subData;
|
|
780
|
-
_position.positionId = (0, utils_1.getPositionId)(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
781
|
-
const marketIdEncodedData = web3.eth.abi.encodeParameters(['address', 'address', 'address', 'address', 'uint256'], [
|
|
782
|
-
subData.loanToken,
|
|
783
|
-
subData.collToken,
|
|
784
|
-
subData.oracle,
|
|
785
|
-
subData.irm,
|
|
786
|
-
subData.lltv,
|
|
787
|
-
]);
|
|
788
|
-
const marketId = web3.utils.keccak256(marketIdEncodedData);
|
|
789
|
-
const { takeProfitType, stopLossType } = (0, utils_1.getStopLossAndTakeProfitTypeByCloseStrategyType)(+subData.closeType);
|
|
790
|
-
_position.specific = {
|
|
791
|
-
subHash: _position.subHash,
|
|
792
|
-
marketId,
|
|
793
|
-
collAsset: subData.collToken,
|
|
794
|
-
debtAsset: subData.loanToken,
|
|
795
|
-
stopLossPrice: triggerData.lowerPrice,
|
|
796
|
-
takeProfitPrice: triggerData.upperPrice,
|
|
797
|
-
stopLossType,
|
|
798
|
-
takeProfitType,
|
|
799
|
-
};
|
|
800
|
-
return _position;
|
|
801
|
-
}
|
|
802
773
|
function parseLiquityV2CloseOnPrice(position, parseData) {
|
|
803
774
|
const _position = (0, lodash_1.cloneDeep)(position);
|
|
804
775
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -986,7 +957,6 @@ const parsingMethodsMapping = {
|
|
|
986
957
|
[enums_1.Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
|
|
987
958
|
[enums_1.Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
|
|
988
959
|
[enums_1.Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
989
|
-
[enums_1.Strategies.Identifiers.CloseOnPrice]: parseMorphoBlueCloseOnPrice,
|
|
990
960
|
},
|
|
991
961
|
[enums_1.ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
|
|
992
962
|
[enums_1.Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
|
|
@@ -94,7 +94,6 @@ export declare const crvUSDEncode: {
|
|
|
94
94
|
export declare const morphoBlueEncode: {
|
|
95
95
|
leverageManagement(marketId: string, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, triggerRatio: number, user: EthereumAddress, isEOA: boolean, network: ChainId): (boolean | string[] | Bundles.BaseIds)[] | (boolean | string[] | Bundles.MainnetIds | Bundles.ArbitrumIds)[];
|
|
96
96
|
leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, targetRatio: number, price: number, priceState: RatioState): (number | boolean | string[])[];
|
|
97
|
-
closeOnPrice(strategyOrBundleId: number, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
98
97
|
};
|
|
99
98
|
export declare const liquityV2Encode: {
|
|
100
99
|
leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
@@ -309,13 +309,6 @@ exports.morphoBlueEncode = {
|
|
|
309
309
|
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
310
310
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
311
311
|
},
|
|
312
|
-
closeOnPrice(strategyOrBundleId, loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = enums_1.CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = enums_1.CloseToAssetType.COLLATERAL) {
|
|
313
|
-
const isBundle = true;
|
|
314
|
-
const closeType = (0, utils_1.getCloseStrategyType)(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
315
|
-
const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
|
|
316
|
-
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
317
|
-
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
318
|
-
},
|
|
319
312
|
};
|
|
320
313
|
exports.liquityV2Encode = {
|
|
321
314
|
leverageManagement(market, troveId, collToken, boldToken, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
@@ -1364,44 +1364,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1364
1364
|
});
|
|
1365
1365
|
});
|
|
1366
1366
|
});
|
|
1367
|
-
describe('closeOnPrice()', () => {
|
|
1368
|
-
const examples = [
|
|
1369
|
-
[
|
|
1370
|
-
[
|
|
1371
|
-
enums_1.Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1372
|
-
true,
|
|
1373
|
-
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1374
|
-
[
|
|
1375
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1376
|
-
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1377
|
-
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1378
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1379
|
-
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1380
|
-
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1381
|
-
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1382
|
-
],
|
|
1383
|
-
],
|
|
1384
|
-
[
|
|
1385
|
-
enums_1.Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1386
|
-
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1387
|
-
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1388
|
-
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1389
|
-
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1390
|
-
'945000000000000000',
|
|
1391
|
-
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1392
|
-
1500,
|
|
1393
|
-
enums_1.CloseToAssetType.DEBT,
|
|
1394
|
-
4000,
|
|
1395
|
-
enums_1.CloseToAssetType.COLLATERAL
|
|
1396
|
-
]
|
|
1397
|
-
],
|
|
1398
|
-
];
|
|
1399
|
-
examples.forEach(([expected, actual]) => {
|
|
1400
|
-
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1401
|
-
(0, chai_1.expect)(strategySubService_1.morphoBlueEncode.closeOnPrice(...actual)).to.eql(expected);
|
|
1402
|
-
});
|
|
1403
|
-
});
|
|
1404
|
-
});
|
|
1405
1367
|
});
|
|
1406
1368
|
describe('When testing strategySubService.compoundV3L2Encode', () => {
|
|
1407
1369
|
describe('leverageManagement()', () => {
|
|
@@ -318,15 +318,3 @@ export declare const sparkCloseGenericSubData: {
|
|
|
318
318
|
owner: EthereumAddress;
|
|
319
319
|
};
|
|
320
320
|
};
|
|
321
|
-
export declare const morphoBlueCloseOnPriceSubData: {
|
|
322
|
-
encode(loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, closeType: CloseStrategyType): string[];
|
|
323
|
-
decode(subData: string[]): {
|
|
324
|
-
loanToken: string;
|
|
325
|
-
collToken: string;
|
|
326
|
-
oracle: string;
|
|
327
|
-
irm: string;
|
|
328
|
-
lltv: string;
|
|
329
|
-
user: string;
|
|
330
|
-
closeType: CloseStrategyType;
|
|
331
|
-
};
|
|
332
|
-
};
|
|
@@ -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.
|
|
6
|
+
exports.sparkCloseGenericSubData = exports.compoundV3CloseSubData = exports.compoundV3LeverageManagementOnPriceSubData = exports.fluidLeverageManagementSubData = 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.sparkLeverageManagementSubData = exports.exchangeLimitOrderSubData = exports.exchangeDcaSubData = exports.liquityPaybackUsingChickenBondSubData = exports.cBondsRebondSubData = exports.morphoAaveV2LeverageManagementSubData = exports.compoundV3L2LeverageManagementSubData = exports.compoundV3LeverageManagementSubData = exports.compoundV2LeverageManagementSubData = exports.aaveV3QuotePriceSubData = exports.aaveV3CollateralSwitchSubData = exports.aaveV3CloseGenericSubData = exports.aaveV3LeverageManagementOnPriceGeneric = exports.aaveV3LeverageManagementSubDataWithoutSubProxy = 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");
|
|
@@ -858,33 +858,3 @@ exports.sparkCloseGenericSubData = {
|
|
|
858
858
|
};
|
|
859
859
|
},
|
|
860
860
|
};
|
|
861
|
-
exports.morphoBlueCloseOnPriceSubData = {
|
|
862
|
-
encode(loanToken, collToken, oracle, irm, lltv, user, closeType) {
|
|
863
|
-
const loanTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', loanToken);
|
|
864
|
-
const collTokenEncoded = web3_eth_abi_1.default.encodeParameter('address', collToken);
|
|
865
|
-
const oracleEncoded = web3_eth_abi_1.default.encodeParameter('address', oracle);
|
|
866
|
-
const irmEncoded = web3_eth_abi_1.default.encodeParameter('address', irm);
|
|
867
|
-
const lltvEncoded = web3_eth_abi_1.default.encodeParameter('uint256', lltv);
|
|
868
|
-
const userEncoded = web3_eth_abi_1.default.encodeParameter('address', user);
|
|
869
|
-
const closeTypeEncoded = web3_eth_abi_1.default.encodeParameter('uint8', closeType);
|
|
870
|
-
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, userEncoded, closeTypeEncoded];
|
|
871
|
-
},
|
|
872
|
-
decode(subData) {
|
|
873
|
-
const loanToken = web3_eth_abi_1.default.decodeParameter('address', subData[0]);
|
|
874
|
-
const collToken = web3_eth_abi_1.default.decodeParameter('address', subData[1]);
|
|
875
|
-
const oracle = web3_eth_abi_1.default.decodeParameter('address', subData[2]);
|
|
876
|
-
const irm = web3_eth_abi_1.default.decodeParameter('address', subData[3]);
|
|
877
|
-
const lltv = web3_eth_abi_1.default.decodeParameter('uint256', subData[4]);
|
|
878
|
-
const user = web3_eth_abi_1.default.decodeParameter('address', subData[5]);
|
|
879
|
-
const closeType = Number(web3_eth_abi_1.default.decodeParameter('uint8', subData[6]));
|
|
880
|
-
return {
|
|
881
|
-
loanToken,
|
|
882
|
-
collToken,
|
|
883
|
-
oracle,
|
|
884
|
-
irm,
|
|
885
|
-
lltv,
|
|
886
|
-
user,
|
|
887
|
-
closeType,
|
|
888
|
-
};
|
|
889
|
-
},
|
|
890
|
-
};
|
|
@@ -1292,58 +1292,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1292
1292
|
});
|
|
1293
1293
|
});
|
|
1294
1294
|
});
|
|
1295
|
-
describe('When testing subDataService.morphoBlueCloseOnPriceSubData', () => {
|
|
1296
|
-
describe('encode()', () => {
|
|
1297
|
-
const examples = [
|
|
1298
|
-
[
|
|
1299
|
-
[
|
|
1300
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1301
|
-
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1302
|
-
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1303
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1304
|
-
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1305
|
-
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1306
|
-
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
1307
|
-
],
|
|
1308
|
-
[web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'), '945000000000000000', web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT]
|
|
1309
|
-
],
|
|
1310
|
-
];
|
|
1311
|
-
examples.forEach(([expected, actual]) => {
|
|
1312
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1313
|
-
(0, chai_1.expect)(subDataService.morphoBlueCloseOnPriceSubData.encode(...actual)).to.eql(expected);
|
|
1314
|
-
});
|
|
1315
|
-
});
|
|
1316
|
-
});
|
|
1317
|
-
describe('decode()', () => {
|
|
1318
|
-
const examples = [
|
|
1319
|
-
[
|
|
1320
|
-
{
|
|
1321
|
-
loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
1322
|
-
collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
|
|
1323
|
-
oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1324
|
-
irm: '0x0000000000000000000000000000000000000000',
|
|
1325
|
-
lltv: '945000000000000000',
|
|
1326
|
-
user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
|
|
1327
|
-
closeType: enums_1.CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
|
|
1328
|
-
},
|
|
1329
|
-
[
|
|
1330
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1331
|
-
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1332
|
-
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1333
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1334
|
-
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1335
|
-
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1336
|
-
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
1337
|
-
],
|
|
1338
|
-
],
|
|
1339
|
-
];
|
|
1340
|
-
examples.forEach(([expected, actual]) => {
|
|
1341
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1342
|
-
(0, chai_1.expect)(subDataService.morphoBlueCloseOnPriceSubData.decode(actual)).to.eql(expected);
|
|
1343
|
-
});
|
|
1344
|
-
});
|
|
1345
|
-
});
|
|
1346
|
-
});
|
|
1347
1295
|
describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
|
|
1348
1296
|
describe('encode()', () => {
|
|
1349
1297
|
const examples = [
|
|
@@ -275,13 +275,3 @@ export declare const sparkQuotePriceRangeTrigger: {
|
|
|
275
275
|
upperPrice: string;
|
|
276
276
|
};
|
|
277
277
|
};
|
|
278
|
-
export declare const morphoBluePriceRangeTrigger: {
|
|
279
|
-
encode(oracle: EthereumAddress, collateralToken: EthereumAddress, loanToken: EthereumAddress, lowerPrice: number, upperPrice: number): string[];
|
|
280
|
-
decode(triggerData: string[]): {
|
|
281
|
-
oracle: string;
|
|
282
|
-
collateralToken: string;
|
|
283
|
-
loanToken: string;
|
|
284
|
-
lowerPrice: string;
|
|
285
|
-
upperPrice: string;
|
|
286
|
-
};
|
|
287
|
-
};
|
|
@@ -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.
|
|
29
|
+
exports.sparkQuotePriceRangeTrigger = exports.aaveV3QuotePriceRangeTrigger = exports.compoundV3PriceRangeTrigger = exports.compoundV3PriceTrigger = exports.fluidRatioTrigger = exports.morphoBluePriceTrigger = exports.closePriceTrigger = exports.liquityV2QuotePriceTrigger = exports.liquityV2RatioTrigger = exports.morphoBlueRatioTrigger = exports.crvUsdHealthRatioTrigger = exports.crvUSDRatioTrigger = exports.curveUsdSoftLiquidationTrigger = exports.curveUsdBorrowRateTrigger = exports.sparkRatioTrigger = exports.exchangeOffchainPriceTrigger = exports.exchangeTimestampTrigger = exports.compoundV3RatioTrigger = exports.cBondsRebondTrigger = exports.aaveV2RatioTrigger = exports.liquityV2AdjustTimeTrigger = exports.liquityV2DebtInFrontTrigger = exports.liquityDebtInFrontWithLimitTrigger = exports.liquityDebtInFrontTrigger = exports.liquityRatioTrigger = exports.compoundV2RatioTrigger = exports.aaveV3QuotePriceWithMaximumGasPriceTrigger = exports.aaveV3QuotePriceTrigger = exports.morphoAaveV2RatioTrigger = exports.aaveV3RatioTrigger = exports.makerRatioTrigger = exports.trailingStopTrigger = exports.chainlinkPriceTrigger = void 0;
|
|
30
30
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
31
31
|
const tokens_1 = require("@defisaver/tokens");
|
|
32
32
|
const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
|
|
@@ -527,23 +527,3 @@ exports.sparkQuotePriceRangeTrigger = {
|
|
|
527
527
|
};
|
|
528
528
|
},
|
|
529
529
|
};
|
|
530
|
-
exports.morphoBluePriceRangeTrigger = {
|
|
531
|
-
encode(oracle, collateralToken, loanToken, lowerPrice, upperPrice) {
|
|
532
|
-
// Price is scaled to 1e8
|
|
533
|
-
const lowerPriceFormatted = new decimal_js_1.default(lowerPrice).mul(1e8).floor().toString();
|
|
534
|
-
const upperPriceFormatted = new decimal_js_1.default(upperPrice).mul(1e8).floor().toString();
|
|
535
|
-
return [
|
|
536
|
-
web3_eth_abi_1.default.encodeParameters(['address', 'address', 'address', 'uint256', 'uint256'], [oracle, collateralToken, loanToken, lowerPriceFormatted, upperPriceFormatted]),
|
|
537
|
-
];
|
|
538
|
-
},
|
|
539
|
-
decode(triggerData) {
|
|
540
|
-
const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'address', 'uint256', 'uint256'], triggerData[0]);
|
|
541
|
-
return {
|
|
542
|
-
oracle: decodedData[0],
|
|
543
|
-
collateralToken: decodedData[1],
|
|
544
|
-
loanToken: decodedData[2],
|
|
545
|
-
lowerPrice: new decimal_js_1.default(decodedData[3]).div(1e8).toString(),
|
|
546
|
-
upperPrice: new decimal_js_1.default(decodedData[4]).div(1e8).toString(),
|
|
547
|
-
};
|
|
548
|
-
},
|
|
549
|
-
};
|
|
@@ -1136,52 +1136,4 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1136
1136
|
});
|
|
1137
1137
|
});
|
|
1138
1138
|
});
|
|
1139
|
-
describe('When testing triggerService.morphoBluePriceRangeTrigger', () => {
|
|
1140
|
-
describe('encode()', () => {
|
|
1141
|
-
const examples = [
|
|
1142
|
-
[
|
|
1143
|
-
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1144
|
-
[web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 1500, 4000]
|
|
1145
|
-
],
|
|
1146
|
-
[
|
|
1147
|
-
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1148
|
-
[web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 0, 5000]
|
|
1149
|
-
],
|
|
1150
|
-
];
|
|
1151
|
-
examples.forEach(([expected, actual]) => {
|
|
1152
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1153
|
-
(0, chai_1.expect)(triggerService_1.morphoBluePriceRangeTrigger.encode(...actual)).to.eql(expected);
|
|
1154
|
-
});
|
|
1155
|
-
});
|
|
1156
|
-
});
|
|
1157
|
-
describe('decode()', () => {
|
|
1158
|
-
const examples = [
|
|
1159
|
-
[
|
|
1160
|
-
{
|
|
1161
|
-
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1162
|
-
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1163
|
-
loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1164
|
-
lowerPrice: '1500',
|
|
1165
|
-
upperPrice: '4000',
|
|
1166
|
-
},
|
|
1167
|
-
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1168
|
-
],
|
|
1169
|
-
[
|
|
1170
|
-
{
|
|
1171
|
-
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1172
|
-
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1173
|
-
loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1174
|
-
lowerPrice: '0',
|
|
1175
|
-
upperPrice: '5000',
|
|
1176
|
-
},
|
|
1177
|
-
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8dA6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1178
|
-
],
|
|
1179
|
-
];
|
|
1180
|
-
examples.forEach(([expected, actual]) => {
|
|
1181
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1182
|
-
(0, chai_1.expect)(triggerService_1.morphoBluePriceRangeTrigger.decode(actual)).to.eql(expected);
|
|
1183
|
-
});
|
|
1184
|
-
});
|
|
1185
|
-
});
|
|
1186
|
-
});
|
|
1187
1139
|
});
|
package/cjs/types/enums.d.ts
CHANGED
|
@@ -206,8 +206,7 @@ export declare namespace Bundles {
|
|
|
206
206
|
AAVE_V3_EOA_REPAY_ON_PRICE = 54,
|
|
207
207
|
AAVE_V3_EOA_BOOST_ON_PRICE = 55,
|
|
208
208
|
AAVE_V3_EOA_CLOSE = 56,
|
|
209
|
-
SPARK_CLOSE = 57
|
|
210
|
-
MORPHO_BLUE_CLOSE = 58
|
|
209
|
+
SPARK_CLOSE = 57
|
|
211
210
|
}
|
|
212
211
|
enum OptimismIds {
|
|
213
212
|
AAVE_V3_REPAY = 0,
|
|
@@ -248,8 +247,7 @@ export declare namespace Bundles {
|
|
|
248
247
|
AAVE_V3_EOA_BOOST = 24,
|
|
249
248
|
AAVE_V3_EOA_REPAY_ON_PRICE = 25,
|
|
250
249
|
AAVE_V3_EOA_BOOST_ON_PRICE = 26,
|
|
251
|
-
AAVE_V3_EOA_CLOSE = 27
|
|
252
|
-
MORPHO_BLUE_CLOSE = 28
|
|
250
|
+
AAVE_V3_EOA_CLOSE = 27
|
|
253
251
|
}
|
|
254
252
|
enum ArbitrumIds {
|
|
255
253
|
AAVE_V3_REPAY = 0,
|
|
@@ -279,7 +277,6 @@ export declare namespace Bundles {
|
|
|
279
277
|
MORPHO_BLUE_BOOST = 24,
|
|
280
278
|
MORPHO_BLUE_BOOST_ON_PRICE = 25,
|
|
281
279
|
MORPHO_BLUE_EOA_REPAY = 26,
|
|
282
|
-
MORPHO_BLUE_EOA_BOOST = 27
|
|
283
|
-
MORPHO_BLUE_CLOSE = 28
|
|
280
|
+
MORPHO_BLUE_EOA_BOOST = 27
|
|
284
281
|
}
|
|
285
282
|
}
|
package/cjs/types/enums.js
CHANGED
|
@@ -230,7 +230,6 @@ var Bundles;
|
|
|
230
230
|
MainnetIds[MainnetIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 55] = "AAVE_V3_EOA_BOOST_ON_PRICE";
|
|
231
231
|
MainnetIds[MainnetIds["AAVE_V3_EOA_CLOSE"] = 56] = "AAVE_V3_EOA_CLOSE";
|
|
232
232
|
MainnetIds[MainnetIds["SPARK_CLOSE"] = 57] = "SPARK_CLOSE";
|
|
233
|
-
MainnetIds[MainnetIds["MORPHO_BLUE_CLOSE"] = 58] = "MORPHO_BLUE_CLOSE";
|
|
234
233
|
})(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
|
|
235
234
|
let OptimismIds;
|
|
236
235
|
(function (OptimismIds) {
|
|
@@ -274,7 +273,6 @@ var Bundles;
|
|
|
274
273
|
BaseIds[BaseIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 25] = "AAVE_V3_EOA_REPAY_ON_PRICE";
|
|
275
274
|
BaseIds[BaseIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 26] = "AAVE_V3_EOA_BOOST_ON_PRICE";
|
|
276
275
|
BaseIds[BaseIds["AAVE_V3_EOA_CLOSE"] = 27] = "AAVE_V3_EOA_CLOSE";
|
|
277
|
-
BaseIds[BaseIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
|
|
278
276
|
})(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
|
|
279
277
|
let ArbitrumIds;
|
|
280
278
|
(function (ArbitrumIds) {
|
|
@@ -306,6 +304,5 @@ var Bundles;
|
|
|
306
304
|
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 25] = "MORPHO_BLUE_BOOST_ON_PRICE";
|
|
307
305
|
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_REPAY"] = 26] = "MORPHO_BLUE_EOA_REPAY";
|
|
308
306
|
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_BOOST"] = 27] = "MORPHO_BLUE_EOA_BOOST";
|
|
309
|
-
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
|
|
310
307
|
})(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
|
|
311
308
|
})(Bundles = exports.Bundles || (exports.Bundles = {}));
|
package/esm/constants/index.js
CHANGED
|
@@ -462,11 +462,6 @@ export const MAINNET_BUNDLES_INFO = {
|
|
|
462
462
|
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
463
463
|
protocol: PROTOCOLS.Spark,
|
|
464
464
|
},
|
|
465
|
-
[Bundles.MainnetIds.MORPHO_BLUE_CLOSE]: {
|
|
466
|
-
strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
467
|
-
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
468
|
-
protocol: PROTOCOLS.MorphoBlue,
|
|
469
|
-
},
|
|
470
465
|
};
|
|
471
466
|
export const OPTIMISM_BUNDLES_INFO = {
|
|
472
467
|
[Bundles.OptimismIds.AAVE_V3_REPAY]: {
|
|
@@ -656,11 +651,6 @@ export const BASE_BUNDLES_INFO = {
|
|
|
656
651
|
strategyId: Strategies.Identifiers.EoaCloseOnPrice,
|
|
657
652
|
protocol: PROTOCOLS.AaveV3,
|
|
658
653
|
},
|
|
659
|
-
[Bundles.BaseIds.MORPHO_BLUE_CLOSE]: {
|
|
660
|
-
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_CLOSE,
|
|
661
|
-
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
662
|
-
protocol: PROTOCOLS.MorphoBlue,
|
|
663
|
-
},
|
|
664
654
|
};
|
|
665
655
|
export const ARBITRUM_BUNDLES_INFO = {
|
|
666
656
|
[Bundles.ArbitrumIds.AAVE_V3_REPAY]: {
|
|
@@ -803,11 +793,6 @@ export const ARBITRUM_BUNDLES_INFO = {
|
|
|
803
793
|
strategyId: Strategies.Identifiers.EoaBoost,
|
|
804
794
|
protocol: PROTOCOLS.MorphoBlue,
|
|
805
795
|
},
|
|
806
|
-
[Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE]: {
|
|
807
|
-
strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE,
|
|
808
|
-
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
809
|
-
protocol: PROTOCOLS.MorphoBlue,
|
|
810
|
-
},
|
|
811
796
|
};
|
|
812
797
|
export const BUNDLES_INFO = {
|
|
813
798
|
[ChainId.Ethereum]: MAINNET_BUNDLES_INFO,
|
|
@@ -741,35 +741,6 @@ function parseMorphoBlueLeverageManagementOnPrice(position, parseData) {
|
|
|
741
741
|
};
|
|
742
742
|
return _position;
|
|
743
743
|
}
|
|
744
|
-
function parseMorphoBlueCloseOnPrice(position, parseData) {
|
|
745
|
-
const _position = cloneDeep(position);
|
|
746
|
-
const { subStruct } = parseData.subscriptionEventData;
|
|
747
|
-
const triggerData = triggerService.morphoBluePriceRangeTrigger.decode(subStruct.triggerData);
|
|
748
|
-
const subData = subDataService.morphoBlueCloseOnPriceSubData.decode(subStruct.subData);
|
|
749
|
-
_position.strategyData.decoded.triggerData = triggerData;
|
|
750
|
-
_position.strategyData.decoded.subData = subData;
|
|
751
|
-
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
752
|
-
const marketIdEncodedData = web3.eth.abi.encodeParameters(['address', 'address', 'address', 'address', 'uint256'], [
|
|
753
|
-
subData.loanToken,
|
|
754
|
-
subData.collToken,
|
|
755
|
-
subData.oracle,
|
|
756
|
-
subData.irm,
|
|
757
|
-
subData.lltv,
|
|
758
|
-
]);
|
|
759
|
-
const marketId = web3.utils.keccak256(marketIdEncodedData);
|
|
760
|
-
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
761
|
-
_position.specific = {
|
|
762
|
-
subHash: _position.subHash,
|
|
763
|
-
marketId,
|
|
764
|
-
collAsset: subData.collToken,
|
|
765
|
-
debtAsset: subData.loanToken,
|
|
766
|
-
stopLossPrice: triggerData.lowerPrice,
|
|
767
|
-
takeProfitPrice: triggerData.upperPrice,
|
|
768
|
-
stopLossType,
|
|
769
|
-
takeProfitType,
|
|
770
|
-
};
|
|
771
|
-
return _position;
|
|
772
|
-
}
|
|
773
744
|
function parseLiquityV2CloseOnPrice(position, parseData) {
|
|
774
745
|
const _position = cloneDeep(position);
|
|
775
746
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -957,7 +928,6 @@ const parsingMethodsMapping = {
|
|
|
957
928
|
[Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
|
|
958
929
|
[Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
|
|
959
930
|
[Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
960
|
-
[Strategies.Identifiers.CloseOnPrice]: parseMorphoBlueCloseOnPrice,
|
|
961
931
|
},
|
|
962
932
|
[ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
|
|
963
933
|
[Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
|
|
@@ -94,7 +94,6 @@ export declare const crvUSDEncode: {
|
|
|
94
94
|
export declare const morphoBlueEncode: {
|
|
95
95
|
leverageManagement(marketId: string, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, triggerRatio: number, user: EthereumAddress, isEOA: boolean, network: ChainId): (boolean | string[] | Bundles.BaseIds)[] | (boolean | string[] | Bundles.MainnetIds | Bundles.ArbitrumIds)[];
|
|
96
96
|
leverageManagementOnPrice(strategyOrBundleId: number, isBundle: boolean | undefined, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, targetRatio: number, price: number, priceState: RatioState): (number | boolean | string[])[];
|
|
97
|
-
closeOnPrice(strategyOrBundleId: number, loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
|
|
98
97
|
};
|
|
99
98
|
export declare const liquityV2Encode: {
|
|
100
99
|
leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
@@ -280,13 +280,6 @@ export const morphoBlueEncode = {
|
|
|
280
280
|
const triggerData = triggerService.morphoBluePriceTrigger.encode(oracle, collToken, loanToken, price, priceState);
|
|
281
281
|
return [strategyOrBundleId, isBundle, triggerData, subData];
|
|
282
282
|
},
|
|
283
|
-
closeOnPrice(strategyOrBundleId, loanToken, collToken, oracle, irm, lltv, user, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
|
|
284
|
-
const isBundle = true;
|
|
285
|
-
const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
|
|
286
|
-
const subDataEncoded = subDataService.morphoBlueCloseOnPriceSubData.encode(loanToken, collToken, oracle, irm, lltv, user, closeType);
|
|
287
|
-
const triggerDataEncoded = triggerService.morphoBluePriceRangeTrigger.encode(oracle, collToken, loanToken, stopLossPrice, takeProfitPrice);
|
|
288
|
-
return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
|
|
289
|
-
},
|
|
290
283
|
};
|
|
291
284
|
export const liquityV2Encode = {
|
|
292
285
|
leverageManagement(market, troveId, collToken, boldToken, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
@@ -1336,44 +1336,6 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
1336
1336
|
});
|
|
1337
1337
|
});
|
|
1338
1338
|
});
|
|
1339
|
-
describe('closeOnPrice()', () => {
|
|
1340
|
-
const examples = [
|
|
1341
|
-
[
|
|
1342
|
-
[
|
|
1343
|
-
Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1344
|
-
true,
|
|
1345
|
-
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1346
|
-
[
|
|
1347
|
-
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1348
|
-
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1349
|
-
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1350
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1351
|
-
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1352
|
-
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1353
|
-
'0x0000000000000000000000000000000000000000000000000000000000000005',
|
|
1354
|
-
],
|
|
1355
|
-
],
|
|
1356
|
-
[
|
|
1357
|
-
Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
1358
|
-
web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'),
|
|
1359
|
-
web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1360
|
-
web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1361
|
-
web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1362
|
-
'945000000000000000',
|
|
1363
|
-
web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'),
|
|
1364
|
-
1500,
|
|
1365
|
-
CloseToAssetType.DEBT,
|
|
1366
|
-
4000,
|
|
1367
|
-
CloseToAssetType.COLLATERAL
|
|
1368
|
-
]
|
|
1369
|
-
],
|
|
1370
|
-
];
|
|
1371
|
-
examples.forEach(([expected, actual]) => {
|
|
1372
|
-
it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1373
|
-
expect(morphoBlueEncode.closeOnPrice(...actual)).to.eql(expected);
|
|
1374
|
-
});
|
|
1375
|
-
});
|
|
1376
|
-
});
|
|
1377
1339
|
});
|
|
1378
1340
|
describe('When testing strategySubService.compoundV3L2Encode', () => {
|
|
1379
1341
|
describe('leverageManagement()', () => {
|
|
@@ -318,15 +318,3 @@ export declare const sparkCloseGenericSubData: {
|
|
|
318
318
|
owner: EthereumAddress;
|
|
319
319
|
};
|
|
320
320
|
};
|
|
321
|
-
export declare const morphoBlueCloseOnPriceSubData: {
|
|
322
|
-
encode(loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, user: EthereumAddress, closeType: CloseStrategyType): string[];
|
|
323
|
-
decode(subData: string[]): {
|
|
324
|
-
loanToken: string;
|
|
325
|
-
collToken: string;
|
|
326
|
-
oracle: string;
|
|
327
|
-
irm: string;
|
|
328
|
-
lltv: string;
|
|
329
|
-
user: string;
|
|
330
|
-
closeType: CloseStrategyType;
|
|
331
|
-
};
|
|
332
|
-
};
|
|
@@ -852,33 +852,3 @@ export const sparkCloseGenericSubData = {
|
|
|
852
852
|
};
|
|
853
853
|
},
|
|
854
854
|
};
|
|
855
|
-
export const morphoBlueCloseOnPriceSubData = {
|
|
856
|
-
encode(loanToken, collToken, oracle, irm, lltv, user, closeType) {
|
|
857
|
-
const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
|
|
858
|
-
const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
|
|
859
|
-
const oracleEncoded = AbiCoder.encodeParameter('address', oracle);
|
|
860
|
-
const irmEncoded = AbiCoder.encodeParameter('address', irm);
|
|
861
|
-
const lltvEncoded = AbiCoder.encodeParameter('uint256', lltv);
|
|
862
|
-
const userEncoded = AbiCoder.encodeParameter('address', user);
|
|
863
|
-
const closeTypeEncoded = AbiCoder.encodeParameter('uint8', closeType);
|
|
864
|
-
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, userEncoded, closeTypeEncoded];
|
|
865
|
-
},
|
|
866
|
-
decode(subData) {
|
|
867
|
-
const loanToken = AbiCoder.decodeParameter('address', subData[0]);
|
|
868
|
-
const collToken = AbiCoder.decodeParameter('address', subData[1]);
|
|
869
|
-
const oracle = AbiCoder.decodeParameter('address', subData[2]);
|
|
870
|
-
const irm = AbiCoder.decodeParameter('address', subData[3]);
|
|
871
|
-
const lltv = AbiCoder.decodeParameter('uint256', subData[4]);
|
|
872
|
-
const user = AbiCoder.decodeParameter('address', subData[5]);
|
|
873
|
-
const closeType = Number(AbiCoder.decodeParameter('uint8', subData[6]));
|
|
874
|
-
return {
|
|
875
|
-
loanToken,
|
|
876
|
-
collToken,
|
|
877
|
-
oracle,
|
|
878
|
-
irm,
|
|
879
|
-
lltv,
|
|
880
|
-
user,
|
|
881
|
-
closeType,
|
|
882
|
-
};
|
|
883
|
-
},
|
|
884
|
-
};
|