@defisaver/automation-sdk 3.3.7 → 3.3.8
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 +15 -0
- package/cjs/services/ethereumService.test.js +1 -0
- package/cjs/services/strategiesService.js +30 -0
- package/cjs/services/strategiesService.test.js +1 -0
- package/cjs/services/strategySubService.d.ts +1 -0
- package/cjs/services/strategySubService.js +7 -0
- package/cjs/services/strategySubService.test.js +40 -2
- package/cjs/services/subDataService.d.ts +12 -0
- package/cjs/services/subDataService.js +31 -1
- package/cjs/services/subDataService.test.js +62 -10
- package/cjs/services/triggerService.d.ts +10 -0
- package/cjs/services/triggerService.js +21 -1
- package/cjs/services/triggerService.test.js +48 -0
- package/cjs/types/enums.d.ts +6 -3
- package/cjs/types/enums.js +3 -0
- package/esm/constants/index.js +15 -0
- package/esm/services/ethereumService.test.js +1 -0
- package/esm/services/strategiesService.js +30 -0
- package/esm/services/strategiesService.test.js +1 -0
- package/esm/services/strategySubService.d.ts +1 -0
- package/esm/services/strategySubService.js +7 -0
- package/esm/services/strategySubService.test.js +40 -2
- package/esm/services/subDataService.d.ts +12 -0
- package/esm/services/subDataService.js +30 -0
- package/esm/services/subDataService.test.js +62 -10
- package/esm/services/triggerService.d.ts +10 -0
- package/esm/services/triggerService.js +20 -0
- package/esm/services/triggerService.test.js +49 -1
- package/esm/types/enums.d.ts +6 -3
- package/esm/types/enums.js +3 -0
- package/package.json +2 -2
- package/src/constants/index.ts +15 -0
- package/src/services/ethereumService.test.ts +1 -0
- package/src/services/strategiesService.test.ts +1 -0
- package/src/services/strategiesService.ts +43 -0
- package/src/services/strategySubService.test.ts +57 -2
- package/src/services/strategySubService.ts +21 -0
- package/src/services/subDataService.test.ts +73 -14
- package/src/services/subDataService.ts +40 -0
- package/src/services/triggerService.test.ts +53 -0
- package/src/services/triggerService.ts +32 -0
- package/src/types/enums.ts +3 -0
|
@@ -741,6 +741,35 @@ 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
|
+
}
|
|
744
773
|
function parseLiquityV2CloseOnPrice(position, parseData) {
|
|
745
774
|
const _position = cloneDeep(position);
|
|
746
775
|
const { subStruct } = parseData.subscriptionEventData;
|
|
@@ -928,6 +957,7 @@ const parsingMethodsMapping = {
|
|
|
928
957
|
[Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
|
|
929
958
|
[Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
|
|
930
959
|
[Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
960
|
+
[Strategies.Identifiers.CloseOnPrice]: parseMorphoBlueCloseOnPrice,
|
|
931
961
|
},
|
|
932
962
|
[ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
|
|
933
963
|
[Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
|
|
@@ -94,6 +94,7 @@ 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[])[];
|
|
97
98
|
};
|
|
98
99
|
export declare const liquityV2Encode: {
|
|
99
100
|
leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
|
|
@@ -280,6 +280,13 @@ 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
|
+
},
|
|
283
290
|
};
|
|
284
291
|
export const liquityV2Encode = {
|
|
285
292
|
leverageManagement(market, troveId, collToken, boldToken, ratioState, targetRatio, triggerRatio, strategyOrBundleId) {
|
|
@@ -472,7 +472,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
472
472
|
[
|
|
473
473
|
Bundles.MainnetIds.AAVE_V3_EOA_REPAY_ON_PRICE,
|
|
474
474
|
true,
|
|
475
|
-
['
|
|
475
|
+
['0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb4800000000000000000000000000000000000000000000000000000026e1f9c6000000000000000000000000000000000000000000000000000000000000000001'],
|
|
476
476
|
[
|
|
477
477
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
478
478
|
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
@@ -500,7 +500,7 @@ describe('Feature: strategySubService.ts', () => {
|
|
|
500
500
|
[
|
|
501
501
|
Bundles.MainnetIds.AAVE_V3_EOA_BOOST_ON_PRICE,
|
|
502
502
|
true,
|
|
503
|
-
['
|
|
503
|
+
['0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599000000000000000000000000a0b86991c6218b36c1d19d4a2e9eb0ce3606eb480000000000000000000000000000000000000000000000000000000002faf0800000000000000000000000000000000000000000000000000000000000000000'],
|
|
504
504
|
[
|
|
505
505
|
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
506
506
|
'0x0000000000000000000000000000000000000000000000000000000000000002',
|
|
@@ -1336,6 +1336,44 @@ 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
|
+
});
|
|
1339
1377
|
});
|
|
1340
1378
|
describe('When testing strategySubService.compoundV3L2Encode', () => {
|
|
1341
1379
|
describe('leverageManagement()', () => {
|
|
@@ -318,3 +318,15 @@ 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,3 +852,33 @@ 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
|
+
};
|
|
@@ -1264,6 +1264,58 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1264
1264
|
});
|
|
1265
1265
|
});
|
|
1266
1266
|
});
|
|
1267
|
+
describe('When testing subDataService.morphoBlueCloseOnPriceSubData', () => {
|
|
1268
|
+
describe('encode()', () => {
|
|
1269
|
+
const examples = [
|
|
1270
|
+
[
|
|
1271
|
+
[
|
|
1272
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1273
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1274
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1275
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1276
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1277
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1278
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
1279
|
+
],
|
|
1280
|
+
[web3Utils.toChecksumAddress('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'), '945000000000000000', web3Utils.toChecksumAddress('0x1031d218133AFaB8c2B819B1366c7E434Ad91E9c'), CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT]
|
|
1281
|
+
],
|
|
1282
|
+
];
|
|
1283
|
+
examples.forEach(([expected, actual]) => {
|
|
1284
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1285
|
+
expect(subDataService.morphoBlueCloseOnPriceSubData.encode(...actual)).to.eql(expected);
|
|
1286
|
+
});
|
|
1287
|
+
});
|
|
1288
|
+
});
|
|
1289
|
+
describe('decode()', () => {
|
|
1290
|
+
const examples = [
|
|
1291
|
+
[
|
|
1292
|
+
{
|
|
1293
|
+
loanToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
1294
|
+
collToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
|
|
1295
|
+
oracle: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
1296
|
+
irm: '0x0000000000000000000000000000000000000000',
|
|
1297
|
+
lltv: '945000000000000000',
|
|
1298
|
+
user: '0x1031d218133AFaB8C2B819B1366c7e434Ad91e9c',
|
|
1299
|
+
closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
|
|
1300
|
+
},
|
|
1301
|
+
[
|
|
1302
|
+
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
1303
|
+
'0x0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0',
|
|
1304
|
+
'0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc',
|
|
1305
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
1306
|
+
'0x0000000000000000000000000000000000000000000000000d1d507e40be8000',
|
|
1307
|
+
'0x0000000000000000000000001031d218133afab8c2b819b1366c7e434ad91e9c',
|
|
1308
|
+
'0x0000000000000000000000000000000000000000000000000000000000000006',
|
|
1309
|
+
],
|
|
1310
|
+
],
|
|
1311
|
+
];
|
|
1312
|
+
examples.forEach(([expected, actual]) => {
|
|
1313
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1314
|
+
expect(subDataService.morphoBlueCloseOnPriceSubData.decode(actual)).to.eql(expected);
|
|
1315
|
+
});
|
|
1316
|
+
});
|
|
1317
|
+
});
|
|
1318
|
+
});
|
|
1267
1319
|
describe('When testing subDataService.aaveV3LeverageManagementOnPriceSubData', () => {
|
|
1268
1320
|
describe('encode()', () => {
|
|
1269
1321
|
const examples = [
|
|
@@ -1557,7 +1609,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1557
1609
|
debtAssetId: 1,
|
|
1558
1610
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1559
1611
|
targetRatio: 200,
|
|
1560
|
-
|
|
1612
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1561
1613
|
},
|
|
1562
1614
|
[
|
|
1563
1615
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -1577,7 +1629,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1577
1629
|
debtAssetId: 1,
|
|
1578
1630
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1579
1631
|
targetRatio: 200,
|
|
1580
|
-
|
|
1632
|
+
owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1581
1633
|
},
|
|
1582
1634
|
[
|
|
1583
1635
|
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
@@ -1786,7 +1838,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1786
1838
|
debtAssetId: 1,
|
|
1787
1839
|
closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL,
|
|
1788
1840
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1789
|
-
|
|
1841
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1790
1842
|
},
|
|
1791
1843
|
[
|
|
1792
1844
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -1807,7 +1859,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1807
1859
|
debtAssetId: 1,
|
|
1808
1860
|
closeType: CloseStrategyType.STOP_LOSS_IN_COLLATERAL,
|
|
1809
1861
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1810
|
-
|
|
1862
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1811
1863
|
},
|
|
1812
1864
|
[
|
|
1813
1865
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -1828,7 +1880,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1828
1880
|
debtAssetId: 1,
|
|
1829
1881
|
closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT,
|
|
1830
1882
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1831
|
-
|
|
1883
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1832
1884
|
},
|
|
1833
1885
|
[
|
|
1834
1886
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -1849,7 +1901,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1849
1901
|
debtAssetId: 1,
|
|
1850
1902
|
closeType: CloseStrategyType.STOP_LOSS_IN_DEBT,
|
|
1851
1903
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1852
|
-
|
|
1904
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1853
1905
|
},
|
|
1854
1906
|
[
|
|
1855
1907
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -1870,7 +1922,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1870
1922
|
debtAssetId: 1,
|
|
1871
1923
|
closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_COLLATERAL,
|
|
1872
1924
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1873
|
-
|
|
1925
|
+
owner: web3Utils.toChecksumAddress('0x1234567890123456789012345678901234567890'),
|
|
1874
1926
|
},
|
|
1875
1927
|
[
|
|
1876
1928
|
'0x000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
@@ -1891,7 +1943,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1891
1943
|
debtAssetId: 1,
|
|
1892
1944
|
closeType: CloseStrategyType.TAKE_PROFIT_IN_COLLATERAL_AND_STOP_LOSS_IN_DEBT,
|
|
1893
1945
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1894
|
-
|
|
1946
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1895
1947
|
},
|
|
1896
1948
|
[
|
|
1897
1949
|
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
@@ -1912,7 +1964,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1912
1964
|
debtAssetId: 1,
|
|
1913
1965
|
closeType: CloseStrategyType.TAKE_PROFIT_AND_STOP_LOSS_IN_DEBT,
|
|
1914
1966
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1915
|
-
|
|
1967
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1916
1968
|
},
|
|
1917
1969
|
[
|
|
1918
1970
|
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
@@ -1933,7 +1985,7 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1933
1985
|
debtAssetId: 1,
|
|
1934
1986
|
closeType: CloseStrategyType.TAKE_PROFIT_IN_DEBT_AND_STOP_LOSS_IN_COLLATERAL,
|
|
1935
1987
|
marketAddr: web3Utils.toChecksumAddress('0x87870Bca3F3fD6335C3F4ce8392D69d0B4161d39'),
|
|
1936
|
-
|
|
1988
|
+
owner: web3Utils.toChecksumAddress('0x0000000000000000000000000000000000000000'),
|
|
1937
1989
|
},
|
|
1938
1990
|
[
|
|
1939
1991
|
'0x0000000000000000000000002260fac5e5542a773aa44fbcfedf7c193bc2c599',
|
|
@@ -275,3 +275,13 @@ 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
|
+
};
|
|
@@ -498,3 +498,23 @@ export const sparkQuotePriceRangeTrigger = {
|
|
|
498
498
|
};
|
|
499
499
|
},
|
|
500
500
|
};
|
|
501
|
+
export const morphoBluePriceRangeTrigger = {
|
|
502
|
+
encode(oracle, collateralToken, loanToken, lowerPrice, upperPrice) {
|
|
503
|
+
// Price is scaled to 1e8
|
|
504
|
+
const lowerPriceFormatted = new Dec(lowerPrice).mul(1e8).floor().toString();
|
|
505
|
+
const upperPriceFormatted = new Dec(upperPrice).mul(1e8).floor().toString();
|
|
506
|
+
return [
|
|
507
|
+
AbiCoder.encodeParameters(['address', 'address', 'address', 'uint256', 'uint256'], [oracle, collateralToken, loanToken, lowerPriceFormatted, upperPriceFormatted]),
|
|
508
|
+
];
|
|
509
|
+
},
|
|
510
|
+
decode(triggerData) {
|
|
511
|
+
const decodedData = AbiCoder.decodeParameters(['address', 'address', 'address', 'uint256', 'uint256'], triggerData[0]);
|
|
512
|
+
return {
|
|
513
|
+
oracle: decodedData[0],
|
|
514
|
+
collateralToken: decodedData[1],
|
|
515
|
+
loanToken: decodedData[2],
|
|
516
|
+
lowerPrice: new Dec(decodedData[3]).div(1e8).toString(),
|
|
517
|
+
upperPrice: new Dec(decodedData[4]).div(1e8).toString(),
|
|
518
|
+
};
|
|
519
|
+
},
|
|
520
|
+
};
|
|
@@ -3,7 +3,7 @@ import { getAssetInfo, MAXUINT } from '@defisaver/tokens';
|
|
|
3
3
|
import * as web3Utils from 'web3-utils';
|
|
4
4
|
import { ChainId, OrderType, RatioState } from '../types/enums';
|
|
5
5
|
import '../configuration';
|
|
6
|
-
import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, } from './triggerService';
|
|
6
|
+
import { aaveV2RatioTrigger, aaveV3QuotePriceTrigger, aaveV3QuotePriceWithMaximumGasPriceTrigger, aaveV3RatioTrigger, cBondsRebondTrigger, chainlinkPriceTrigger, compoundV2RatioTrigger, compoundV3RatioTrigger, compoundV3PriceTrigger, curveUsdBorrowRateTrigger, curveUsdSoftLiquidationTrigger, exchangeOffchainPriceTrigger, exchangeTimestampTrigger, liquityDebtInFrontTrigger, makerRatioTrigger, morphoAaveV2RatioTrigger, sparkRatioTrigger, trailingStopTrigger, liquityDebtInFrontWithLimitTrigger, crvUSDRatioTrigger, morphoBlueRatioTrigger, crvUsdHealthRatioTrigger, liquityV2DebtInFrontTrigger, liquityV2AdjustTimeTrigger, compoundV3PriceRangeTrigger, aaveV3QuotePriceRangeTrigger, morphoBluePriceRangeTrigger, } from './triggerService';
|
|
7
7
|
describe('Feature: triggerService.ts', () => {
|
|
8
8
|
describe('When testing triggerService.chainlinkPriceTrigger', () => {
|
|
9
9
|
describe('encode()', () => {
|
|
@@ -1111,4 +1111,52 @@ describe('Feature: triggerService.ts', () => {
|
|
|
1111
1111
|
});
|
|
1112
1112
|
});
|
|
1113
1113
|
});
|
|
1114
|
+
describe('When testing triggerService.morphoBluePriceRangeTrigger', () => {
|
|
1115
|
+
describe('encode()', () => {
|
|
1116
|
+
const examples = [
|
|
1117
|
+
[
|
|
1118
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1119
|
+
[web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 1500, 4000]
|
|
1120
|
+
],
|
|
1121
|
+
[
|
|
1122
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1123
|
+
[web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'), web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'), web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'), 0, 5000]
|
|
1124
|
+
],
|
|
1125
|
+
];
|
|
1126
|
+
examples.forEach(([expected, actual]) => {
|
|
1127
|
+
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1128
|
+
expect(morphoBluePriceRangeTrigger.encode(...actual)).to.eql(expected);
|
|
1129
|
+
});
|
|
1130
|
+
});
|
|
1131
|
+
});
|
|
1132
|
+
describe('decode()', () => {
|
|
1133
|
+
const examples = [
|
|
1134
|
+
[
|
|
1135
|
+
{
|
|
1136
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1137
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1138
|
+
loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1139
|
+
lowerPrice: '1500',
|
|
1140
|
+
upperPrice: '4000',
|
|
1141
|
+
},
|
|
1142
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000000000000000000000000000000000022ecb25c000000000000000000000000000000000000000000000000000000005d21dba000'],
|
|
1143
|
+
],
|
|
1144
|
+
[
|
|
1145
|
+
{
|
|
1146
|
+
oracle: web3Utils.toChecksumAddress('0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC'),
|
|
1147
|
+
collateralToken: web3Utils.toChecksumAddress('0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0'),
|
|
1148
|
+
loanToken: web3Utils.toChecksumAddress('0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2'),
|
|
1149
|
+
lowerPrice: '0',
|
|
1150
|
+
upperPrice: '5000',
|
|
1151
|
+
},
|
|
1152
|
+
['0x000000000000000000000000870ac11d48b15db9a138cf899d20f13f79ba00bc0000000000000000000000007f39c581f595b53c5cb19bd0b3f8dA6c935e2ca0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc20000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000746a528800'],
|
|
1153
|
+
],
|
|
1154
|
+
];
|
|
1155
|
+
examples.forEach(([expected, actual]) => {
|
|
1156
|
+
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1157
|
+
expect(morphoBluePriceRangeTrigger.decode(actual)).to.eql(expected);
|
|
1158
|
+
});
|
|
1159
|
+
});
|
|
1160
|
+
});
|
|
1161
|
+
});
|
|
1114
1162
|
});
|
package/esm/types/enums.d.ts
CHANGED
|
@@ -206,7 +206,8 @@ 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
|
|
209
|
+
SPARK_CLOSE = 57,
|
|
210
|
+
MORPHO_BLUE_CLOSE = 58
|
|
210
211
|
}
|
|
211
212
|
enum OptimismIds {
|
|
212
213
|
AAVE_V3_REPAY = 0,
|
|
@@ -247,7 +248,8 @@ export declare namespace Bundles {
|
|
|
247
248
|
AAVE_V3_EOA_BOOST = 24,
|
|
248
249
|
AAVE_V3_EOA_REPAY_ON_PRICE = 25,
|
|
249
250
|
AAVE_V3_EOA_BOOST_ON_PRICE = 26,
|
|
250
|
-
AAVE_V3_EOA_CLOSE = 27
|
|
251
|
+
AAVE_V3_EOA_CLOSE = 27,
|
|
252
|
+
MORPHO_BLUE_CLOSE = 28
|
|
251
253
|
}
|
|
252
254
|
enum ArbitrumIds {
|
|
253
255
|
AAVE_V3_REPAY = 0,
|
|
@@ -277,6 +279,7 @@ export declare namespace Bundles {
|
|
|
277
279
|
MORPHO_BLUE_BOOST = 24,
|
|
278
280
|
MORPHO_BLUE_BOOST_ON_PRICE = 25,
|
|
279
281
|
MORPHO_BLUE_EOA_REPAY = 26,
|
|
280
|
-
MORPHO_BLUE_EOA_BOOST = 27
|
|
282
|
+
MORPHO_BLUE_EOA_BOOST = 27,
|
|
283
|
+
MORPHO_BLUE_CLOSE = 28
|
|
281
284
|
}
|
|
282
285
|
}
|
package/esm/types/enums.js
CHANGED
|
@@ -227,6 +227,7 @@ export var Bundles;
|
|
|
227
227
|
MainnetIds[MainnetIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 55] = "AAVE_V3_EOA_BOOST_ON_PRICE";
|
|
228
228
|
MainnetIds[MainnetIds["AAVE_V3_EOA_CLOSE"] = 56] = "AAVE_V3_EOA_CLOSE";
|
|
229
229
|
MainnetIds[MainnetIds["SPARK_CLOSE"] = 57] = "SPARK_CLOSE";
|
|
230
|
+
MainnetIds[MainnetIds["MORPHO_BLUE_CLOSE"] = 58] = "MORPHO_BLUE_CLOSE";
|
|
230
231
|
})(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
|
|
231
232
|
let OptimismIds;
|
|
232
233
|
(function (OptimismIds) {
|
|
@@ -270,6 +271,7 @@ export var Bundles;
|
|
|
270
271
|
BaseIds[BaseIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 25] = "AAVE_V3_EOA_REPAY_ON_PRICE";
|
|
271
272
|
BaseIds[BaseIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 26] = "AAVE_V3_EOA_BOOST_ON_PRICE";
|
|
272
273
|
BaseIds[BaseIds["AAVE_V3_EOA_CLOSE"] = 27] = "AAVE_V3_EOA_CLOSE";
|
|
274
|
+
BaseIds[BaseIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
|
|
273
275
|
})(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
|
|
274
276
|
let ArbitrumIds;
|
|
275
277
|
(function (ArbitrumIds) {
|
|
@@ -301,5 +303,6 @@ export var Bundles;
|
|
|
301
303
|
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 25] = "MORPHO_BLUE_BOOST_ON_PRICE";
|
|
302
304
|
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_REPAY"] = 26] = "MORPHO_BLUE_EOA_REPAY";
|
|
303
305
|
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_BOOST"] = 27] = "MORPHO_BLUE_EOA_BOOST";
|
|
306
|
+
ArbitrumIds[ArbitrumIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
|
|
304
307
|
})(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
|
|
305
308
|
})(Bundles || (Bundles = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defisaver/automation-sdk",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.8",
|
|
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": "^1.3.
|
|
26
|
+
"@defisaver/sdk": "^1.3.15",
|
|
27
27
|
"@defisaver/tokens": "^1.6.19",
|
|
28
28
|
"@ethersproject/address": "^5.0.10",
|
|
29
29
|
"@ethersproject/solidity": "^5.0.9",
|
package/src/constants/index.ts
CHANGED
|
@@ -491,6 +491,11 @@ export const MAINNET_BUNDLES_INFO: MainnetBundleInfo = {
|
|
|
491
491
|
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
492
492
|
protocol: PROTOCOLS.Spark,
|
|
493
493
|
},
|
|
494
|
+
[Bundles.MainnetIds.MORPHO_BLUE_CLOSE]: {
|
|
495
|
+
strategyOrBundleId: Bundles.MainnetIds.MORPHO_BLUE_CLOSE,
|
|
496
|
+
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
497
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
498
|
+
},
|
|
494
499
|
};
|
|
495
500
|
|
|
496
501
|
export const OPTIMISM_BUNDLES_INFO: OptimismBundleInfo = {
|
|
@@ -683,6 +688,11 @@ export const BASE_BUNDLES_INFO: BaseBundleInfo = {
|
|
|
683
688
|
strategyId: Strategies.Identifiers.EoaCloseOnPrice,
|
|
684
689
|
protocol: PROTOCOLS.AaveV3,
|
|
685
690
|
},
|
|
691
|
+
[Bundles.BaseIds.MORPHO_BLUE_CLOSE]: {
|
|
692
|
+
strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_CLOSE,
|
|
693
|
+
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
694
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
695
|
+
},
|
|
686
696
|
};
|
|
687
697
|
|
|
688
698
|
export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
|
|
@@ -826,6 +836,11 @@ export const ARBITRUM_BUNDLES_INFO: ArbitrumBundleInfo = {
|
|
|
826
836
|
strategyId: Strategies.Identifiers.EoaBoost,
|
|
827
837
|
protocol: PROTOCOLS.MorphoBlue,
|
|
828
838
|
},
|
|
839
|
+
[Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE]: {
|
|
840
|
+
strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE,
|
|
841
|
+
strategyId: Strategies.Identifiers.CloseOnPrice,
|
|
842
|
+
protocol: PROTOCOLS.MorphoBlue,
|
|
843
|
+
},
|
|
829
844
|
};
|
|
830
845
|
|
|
831
846
|
export const BUNDLES_INFO: BundlesInfo = {
|
|
@@ -115,6 +115,7 @@ describe('Feature: ethereumService.ts', () => {
|
|
|
115
115
|
'address': '0x5f98805A4E8be255a32880FDeC7F6728C6568bA0',
|
|
116
116
|
'blockHash': '0xb92cab2569456dbfbdb853d2c67d72c9a7580543dbcb55d483a77322b40755a4',
|
|
117
117
|
'blockNumber': 15166163,
|
|
118
|
+
'blockTimestamp': '0x62d53ad8',
|
|
118
119
|
'event': 'Transfer',
|
|
119
120
|
'id': 'log_e2258e3a',
|
|
120
121
|
'logIndex': 385,
|
|
@@ -990,6 +990,48 @@ function parseMorphoBlueLeverageManagementOnPrice(position: Position.Automated,
|
|
|
990
990
|
return _position;
|
|
991
991
|
}
|
|
992
992
|
|
|
993
|
+
function parseMorphoBlueCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
994
|
+
const _position = cloneDeep(position);
|
|
995
|
+
|
|
996
|
+
const { subStruct } = parseData.subscriptionEventData;
|
|
997
|
+
|
|
998
|
+
const triggerData = triggerService.morphoBluePriceRangeTrigger.decode(subStruct.triggerData);
|
|
999
|
+
const subData = subDataService.morphoBlueCloseOnPriceSubData.decode(subStruct.subData);
|
|
1000
|
+
|
|
1001
|
+
_position.strategyData.decoded.triggerData = triggerData;
|
|
1002
|
+
_position.strategyData.decoded.subData = subData;
|
|
1003
|
+
|
|
1004
|
+
_position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, Math.random());
|
|
1005
|
+
|
|
1006
|
+
const marketIdEncodedData = web3.eth.abi.encodeParameters(
|
|
1007
|
+
['address', 'address', 'address', 'address', 'uint256'],
|
|
1008
|
+
[
|
|
1009
|
+
subData.loanToken,
|
|
1010
|
+
subData.collToken,
|
|
1011
|
+
subData.oracle,
|
|
1012
|
+
subData.irm,
|
|
1013
|
+
subData.lltv,
|
|
1014
|
+
],
|
|
1015
|
+
);
|
|
1016
|
+
|
|
1017
|
+
const marketId = web3.utils.keccak256(marketIdEncodedData);
|
|
1018
|
+
|
|
1019
|
+
const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
|
|
1020
|
+
|
|
1021
|
+
_position.specific = {
|
|
1022
|
+
subHash: _position.subHash,
|
|
1023
|
+
marketId,
|
|
1024
|
+
collAsset: subData.collToken,
|
|
1025
|
+
debtAsset: subData.loanToken,
|
|
1026
|
+
stopLossPrice: triggerData.lowerPrice,
|
|
1027
|
+
takeProfitPrice: triggerData.upperPrice,
|
|
1028
|
+
stopLossType,
|
|
1029
|
+
takeProfitType,
|
|
1030
|
+
};
|
|
1031
|
+
|
|
1032
|
+
return _position;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
993
1035
|
function parseLiquityV2CloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
|
|
994
1036
|
const _position = cloneDeep(position);
|
|
995
1037
|
|
|
@@ -1208,6 +1250,7 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
|
|
|
1208
1250
|
[Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
|
|
1209
1251
|
[Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
|
|
1210
1252
|
[Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
|
|
1253
|
+
[Strategies.Identifiers.CloseOnPrice]: parseMorphoBlueCloseOnPrice,
|
|
1211
1254
|
},
|
|
1212
1255
|
[ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
|
|
1213
1256
|
[Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
|