@defisaver/automation-sdk 3.3.6 → 3.3.7-morpho-dev

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/cjs/constants/index.js +20 -10
  2. package/cjs/services/strategiesService.js +41 -14
  3. package/cjs/services/strategySubService.d.ts +2 -11
  4. package/cjs/services/strategySubService.js +12 -5
  5. package/cjs/services/strategySubService.test.js +38 -72
  6. package/cjs/services/subDataService.d.ts +24 -9
  7. package/cjs/services/subDataService.js +63 -20
  8. package/cjs/services/subDataService.test.js +52 -72
  9. package/cjs/services/triggerService.d.ts +19 -9
  10. package/cjs/services/triggerService.js +40 -19
  11. package/cjs/services/triggerService.test.js +48 -46
  12. package/cjs/services/utils.test.js +0 -77
  13. package/cjs/types/enums.d.ts +7 -5
  14. package/cjs/types/enums.js +4 -2
  15. package/esm/constants/index.js +20 -10
  16. package/esm/services/strategiesService.js +41 -14
  17. package/esm/services/strategySubService.d.ts +2 -11
  18. package/esm/services/strategySubService.js +12 -5
  19. package/esm/services/strategySubService.test.js +39 -73
  20. package/esm/services/subDataService.d.ts +24 -9
  21. package/esm/services/subDataService.js +62 -19
  22. package/esm/services/subDataService.test.js +52 -72
  23. package/esm/services/triggerService.d.ts +19 -9
  24. package/esm/services/triggerService.js +39 -18
  25. package/esm/services/triggerService.test.js +49 -47
  26. package/esm/services/utils.test.js +1 -52
  27. package/esm/types/enums.d.ts +7 -5
  28. package/esm/types/enums.js +4 -2
  29. package/package.json +1 -1
  30. package/src/constants/index.ts +20 -12
  31. package/src/services/strategiesService.ts +55 -22
  32. package/src/services/strategySubService.test.ts +59 -94
  33. package/src/services/strategySubService.ts +36 -16
  34. package/src/services/subDataService.test.ts +60 -78
  35. package/src/services/subDataService.ts +92 -31
  36. package/src/services/triggerService.test.ts +53 -51
  37. package/src/services/triggerService.ts +61 -26
  38. package/src/services/utils.test.ts +0 -59
  39. package/src/types/enums.ts +4 -2
@@ -153,15 +153,6 @@ export declare const sparkRatioTrigger: {
153
153
  ratioState: number;
154
154
  };
155
155
  };
156
- export declare const sparkQuotePriceTrigger: {
157
- encode(baseTokenAddress: EthereumAddress, quoteTokenAddress: EthereumAddress, price: number, ratioState: RatioState): string[];
158
- decode(triggerData: string[]): {
159
- baseTokenAddress: EthereumAddress;
160
- quoteTokenAddress: EthereumAddress;
161
- price: string;
162
- ratioState: RatioState;
163
- };
164
- };
165
156
  export declare const curveUsdBorrowRateTrigger: {
166
157
  encode(market: EthereumAddress, targetRate: string, rateState: RatioState): string[];
167
158
  decode(triggerData: string[]): {
@@ -275,3 +266,22 @@ export declare const aaveV3QuotePriceRangeTrigger: {
275
266
  upperPrice: string;
276
267
  };
277
268
  };
269
+ export declare const sparkQuotePriceRangeTrigger: {
270
+ encode(collToken: EthereumAddress, debtToken: EthereumAddress, lowerPrice: number, upperPrice: number): string[];
271
+ decode(triggerData: string[]): {
272
+ collToken: string;
273
+ debtToken: string;
274
+ lowerPrice: string;
275
+ upperPrice: string;
276
+ };
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.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.sparkQuotePriceTrigger = 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;
29
+ exports.morphoBluePriceRangeTrigger = 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"));
@@ -290,24 +290,6 @@ exports.sparkRatioTrigger = {
290
290
  };
291
291
  },
292
292
  };
293
- exports.sparkQuotePriceTrigger = {
294
- encode(baseTokenAddress, quoteTokenAddress, price, ratioState) {
295
- // Price is always in 8 decimals
296
- const _price = new decimal_js_1.default(price.toString()).mul(Math.pow(10, 8)).floor().toString();
297
- return [web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint8'], [baseTokenAddress, quoteTokenAddress, _price, ratioState])];
298
- },
299
- decode(triggerData) {
300
- const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint8'], triggerData[0]);
301
- // Price is always in 8 decimals
302
- const price = new decimal_js_1.default(decodedData[2]).div(Math.pow(10, 8)).toDP(8).toString();
303
- return {
304
- price,
305
- baseTokenAddress: decodedData[0],
306
- quoteTokenAddress: decodedData[1],
307
- ratioState: +decodedData[3],
308
- };
309
- },
310
- };
311
293
  exports.curveUsdBorrowRateTrigger = {
312
294
  encode(market, targetRate, rateState) {
313
295
  // the form is x = (e**(rate*365*86400))-1 where x*100 is number in %
@@ -526,3 +508,42 @@ exports.aaveV3QuotePriceRangeTrigger = {
526
508
  };
527
509
  },
528
510
  };
511
+ exports.sparkQuotePriceRangeTrigger = {
512
+ encode(collToken, debtToken, lowerPrice, upperPrice) {
513
+ // Price is scaled to 1e8
514
+ const lowerPriceFormatted = new decimal_js_1.default(lowerPrice).mul(1e8).floor().toString();
515
+ const upperPriceFormatted = new decimal_js_1.default(upperPrice).mul(1e8).floor().toString();
516
+ return [
517
+ web3_eth_abi_1.default.encodeParameters(['address', 'address', 'uint256', 'uint256'], [collToken, debtToken, lowerPriceFormatted, upperPriceFormatted]),
518
+ ];
519
+ },
520
+ decode(triggerData) {
521
+ const decodedData = web3_eth_abi_1.default.decodeParameters(['address', 'address', 'uint256', 'uint256'], triggerData[0]);
522
+ return {
523
+ collToken: decodedData[0],
524
+ debtToken: decodedData[1],
525
+ lowerPrice: new decimal_js_1.default(decodedData[2]).div(1e8).toString(),
526
+ upperPrice: new decimal_js_1.default(decodedData[3]).div(1e8).toString(),
527
+ };
528
+ },
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
+ };
@@ -806,52 +806,6 @@ describe('Feature: triggerService.ts', () => {
806
806
  });
807
807
  });
808
808
  });
809
- describe('When testing triggerService.sparkQuotePriceTrigger', () => {
810
- describe('encode()', () => {
811
- const examples = [
812
- [
813
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
814
- [(0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address, (0, tokens_1.getAssetInfo)('wstETH', enums_1.ChainId.Ethereum).address, 0.0004321, enums_1.RatioState.UNDER]
815
- ],
816
- [
817
- ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
818
- [(0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Arbitrum).address, (0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address, 0.00100023, enums_1.RatioState.OVER]
819
- ],
820
- ];
821
- examples.forEach(([expected, actual]) => {
822
- it(`Given ${actual} should return expected value: ${expected}`, () => {
823
- (0, chai_1.expect)(triggerService_1.sparkQuotePriceTrigger.encode(...actual)).to.eql(expected);
824
- });
825
- });
826
- });
827
- describe('decode()', () => {
828
- const examples = [
829
- [
830
- {
831
- baseTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('DAI', enums_1.ChainId.Ethereum).address),
832
- quoteTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('wstETH', enums_1.ChainId.Ethereum).address),
833
- price: '0.0004321',
834
- ratioState: enums_1.RatioState.UNDER,
835
- },
836
- ['0x0000000000000000000000006b175474e89094c44da98b954eedeac495271d0f0000000000000000000000007f39c581f595b53c5cb19bd0b3f8da6c935e2ca0000000000000000000000000000000000000000000000000000000000000a8ca0000000000000000000000000000000000000000000000000000000000000001'],
837
- ],
838
- [
839
- {
840
- baseTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('WBTC', enums_1.ChainId.Arbitrum).address),
841
- quoteTokenAddress: web3Utils.toChecksumAddress((0, tokens_1.getAssetInfo)('USDC', enums_1.ChainId.Arbitrum).address),
842
- price: '0.00100023',
843
- ratioState: enums_1.RatioState.OVER,
844
- },
845
- ['0x0000000000000000000000002f2a2543b76a4166549f7aab2e75bef0aefc5b0f000000000000000000000000af88d065e77c8cc2239327c5edb3a432268e583100000000000000000000000000000000000000000000000000000000000186b70000000000000000000000000000000000000000000000000000000000000000'],
846
- ]
847
- ];
848
- examples.forEach(([expected, actual]) => {
849
- it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
850
- (0, chai_1.expect)(triggerService_1.sparkQuotePriceTrigger.decode(actual)).to.eql(expected);
851
- });
852
- });
853
- });
854
- });
855
809
  describe('When testing triggerService.curveUsdBorrowRateTrigger', () => {
856
810
  describe('encode()', () => {
857
811
  const examples = [
@@ -1182,4 +1136,52 @@ describe('Feature: triggerService.ts', () => {
1182
1136
  });
1183
1137
  });
1184
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
+ });
1185
1187
  });
@@ -1,37 +1,8 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
2
  Object.defineProperty(exports, "__esModule", { value: true });
29
3
  const chai_1 = require("chai");
30
- const web3Utils = __importStar(require("web3-utils"));
31
- const web3_eth_abi_1 = __importDefault(require("web3-eth-abi"));
32
4
  const tokens_1 = require("@defisaver/tokens");
33
5
  const enums_1 = require("../types/enums");
34
- const strategySubService_1 = require("./strategySubService");
35
6
  require("../configuration");
36
7
  const utils_1 = require("./utils");
37
8
  describe('Feature: utils.ts', () => {
@@ -167,54 +138,6 @@ describe('Feature: utils.ts', () => {
167
138
  });
168
139
  });
169
140
  });
170
- describe('When testing utils.compareSubHashes()', () => {
171
- const subDataToEncodeOne = [
172
- 12,
173
- false,
174
- {
175
- baseTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
176
- quoteTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
177
- price: 100,
178
- ratioState: 1,
179
- },
180
- {
181
- collAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
182
- collAssetId: 2,
183
- debtAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
184
- debtAssetId: 3,
185
- },
186
- ];
187
- const subDataToEncodeTwo = [
188
- 13,
189
- true,
190
- {
191
- baseTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
192
- quoteTokenAddress: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
193
- price: 100,
194
- ratioState: 2,
195
- },
196
- {
197
- collAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
198
- collAssetId: 2,
199
- debtAsset: '0xaf88d065e77c8cC2239327C5EDb3A432268e5831',
200
- debtAssetId: 3,
201
- },
202
- ];
203
- // @ts-ignore
204
- const encodedSubDataOne = strategySubService_1.sparkEncode.closeToAsset(...subDataToEncodeOne);
205
- // @ts-ignore
206
- const encodedSubDataTwo = strategySubService_1.sparkEncode.closeToAsset(...subDataToEncodeTwo);
207
- const encodedParams = web3Utils.keccak256(web3_eth_abi_1.default.encodeParameter('(uint64,bool,bytes[],bytes32[])', encodedSubDataOne));
208
- const examples = [
209
- [true, [encodedParams, encodedSubDataOne]],
210
- [false, [encodedParams, encodedSubDataTwo]],
211
- ];
212
- examples.forEach(([expected, actual]) => {
213
- it(`Given ${actual} should return expected value: ${expected}`, () => {
214
- (0, chai_1.expect)((0, utils_1.compareSubHashes)(...actual)).to.equal(expected);
215
- });
216
- });
217
- });
218
141
  describe('When testing utils.encodeSubId()', () => {
219
142
  const examples = [
220
143
  ['00000001', '1'],
@@ -171,8 +171,6 @@ export declare namespace Bundles {
171
171
  LIQUITY_BOOST = 17,
172
172
  SPARK_REPAY = 18,
173
173
  SPARK_BOOST = 19,
174
- SPARK_CLOSE_TO_DEBT = -21231230,
175
- SPARK_CLOSE_TO_COLLATERAL = -21231231,
176
174
  AAVE_V2_REPAY = 22,
177
175
  AAVE_V2_BOOST = 23,
178
176
  COMP_V2_REPAY = 20,
@@ -207,7 +205,9 @@ export declare namespace Bundles {
207
205
  AAVE_V3_EOA_BOOST = 53,
208
206
  AAVE_V3_EOA_REPAY_ON_PRICE = 54,
209
207
  AAVE_V3_EOA_BOOST_ON_PRICE = 55,
210
- AAVE_V3_EOA_CLOSE = 56
208
+ AAVE_V3_EOA_CLOSE = 56,
209
+ SPARK_CLOSE = 57,
210
+ MORPHO_BLUE_CLOSE = 58
211
211
  }
212
212
  enum OptimismIds {
213
213
  AAVE_V3_REPAY = 0,
@@ -248,7 +248,8 @@ export declare namespace Bundles {
248
248
  AAVE_V3_EOA_BOOST = 24,
249
249
  AAVE_V3_EOA_REPAY_ON_PRICE = 25,
250
250
  AAVE_V3_EOA_BOOST_ON_PRICE = 26,
251
- AAVE_V3_EOA_CLOSE = 27
251
+ AAVE_V3_EOA_CLOSE = 27,
252
+ MORPHO_BLUE_CLOSE = 28
252
253
  }
253
254
  enum ArbitrumIds {
254
255
  AAVE_V3_REPAY = 0,
@@ -278,6 +279,7 @@ export declare namespace Bundles {
278
279
  MORPHO_BLUE_BOOST = 24,
279
280
  MORPHO_BLUE_BOOST_ON_PRICE = 25,
280
281
  MORPHO_BLUE_EOA_REPAY = 26,
281
- MORPHO_BLUE_EOA_BOOST = 27
282
+ MORPHO_BLUE_EOA_BOOST = 27,
283
+ MORPHO_BLUE_CLOSE = 28
282
284
  }
283
285
  }
@@ -194,8 +194,6 @@ var Bundles;
194
194
  MainnetIds[MainnetIds["LIQUITY_BOOST"] = 17] = "LIQUITY_BOOST";
195
195
  MainnetIds[MainnetIds["SPARK_REPAY"] = 18] = "SPARK_REPAY";
196
196
  MainnetIds[MainnetIds["SPARK_BOOST"] = 19] = "SPARK_BOOST";
197
- MainnetIds[MainnetIds["SPARK_CLOSE_TO_DEBT"] = -21231230] = "SPARK_CLOSE_TO_DEBT";
198
- MainnetIds[MainnetIds["SPARK_CLOSE_TO_COLLATERAL"] = -21231231] = "SPARK_CLOSE_TO_COLLATERAL";
199
197
  MainnetIds[MainnetIds["AAVE_V2_REPAY"] = 22] = "AAVE_V2_REPAY";
200
198
  MainnetIds[MainnetIds["AAVE_V2_BOOST"] = 23] = "AAVE_V2_BOOST";
201
199
  MainnetIds[MainnetIds["COMP_V2_REPAY"] = 20] = "COMP_V2_REPAY";
@@ -231,6 +229,8 @@ var Bundles;
231
229
  MainnetIds[MainnetIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 54] = "AAVE_V3_EOA_REPAY_ON_PRICE";
232
230
  MainnetIds[MainnetIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 55] = "AAVE_V3_EOA_BOOST_ON_PRICE";
233
231
  MainnetIds[MainnetIds["AAVE_V3_EOA_CLOSE"] = 56] = "AAVE_V3_EOA_CLOSE";
232
+ MainnetIds[MainnetIds["SPARK_CLOSE"] = 57] = "SPARK_CLOSE";
233
+ MainnetIds[MainnetIds["MORPHO_BLUE_CLOSE"] = 58] = "MORPHO_BLUE_CLOSE";
234
234
  })(MainnetIds = Bundles.MainnetIds || (Bundles.MainnetIds = {}));
235
235
  let OptimismIds;
236
236
  (function (OptimismIds) {
@@ -274,6 +274,7 @@ var Bundles;
274
274
  BaseIds[BaseIds["AAVE_V3_EOA_REPAY_ON_PRICE"] = 25] = "AAVE_V3_EOA_REPAY_ON_PRICE";
275
275
  BaseIds[BaseIds["AAVE_V3_EOA_BOOST_ON_PRICE"] = 26] = "AAVE_V3_EOA_BOOST_ON_PRICE";
276
276
  BaseIds[BaseIds["AAVE_V3_EOA_CLOSE"] = 27] = "AAVE_V3_EOA_CLOSE";
277
+ BaseIds[BaseIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
277
278
  })(BaseIds = Bundles.BaseIds || (Bundles.BaseIds = {}));
278
279
  let ArbitrumIds;
279
280
  (function (ArbitrumIds) {
@@ -305,5 +306,6 @@ var Bundles;
305
306
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_BOOST_ON_PRICE"] = 25] = "MORPHO_BLUE_BOOST_ON_PRICE";
306
307
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_REPAY"] = 26] = "MORPHO_BLUE_EOA_REPAY";
307
308
  ArbitrumIds[ArbitrumIds["MORPHO_BLUE_EOA_BOOST"] = 27] = "MORPHO_BLUE_EOA_BOOST";
309
+ ArbitrumIds[ArbitrumIds["MORPHO_BLUE_CLOSE"] = 28] = "MORPHO_BLUE_CLOSE";
308
310
  })(ArbitrumIds = Bundles.ArbitrumIds || (Bundles.ArbitrumIds = {}));
309
311
  })(Bundles = exports.Bundles || (exports.Bundles = {}));
@@ -302,16 +302,6 @@ export const MAINNET_BUNDLES_INFO = {
302
302
  strategyId: Strategies.Identifiers.Boost,
303
303
  protocol: PROTOCOLS.Spark,
304
304
  },
305
- [Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT]: {
306
- strategyOrBundleId: Bundles.MainnetIds.SPARK_CLOSE_TO_DEBT,
307
- strategyId: Strategies.Identifiers.CloseToDebt,
308
- protocol: PROTOCOLS.Spark,
309
- },
310
- [Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL]: {
311
- strategyOrBundleId: Bundles.MainnetIds.SPARK_CLOSE_TO_COLLATERAL,
312
- strategyId: Strategies.Identifiers.CloseToCollateral,
313
- protocol: PROTOCOLS.Spark,
314
- },
315
305
  [Bundles.MainnetIds.AAVE_V2_REPAY]: {
316
306
  strategyOrBundleId: Bundles.MainnetIds.AAVE_V2_REPAY,
317
307
  strategyId: Strategies.Identifiers.Repay,
@@ -467,6 +457,16 @@ export const MAINNET_BUNDLES_INFO = {
467
457
  strategyId: Strategies.Identifiers.EoaCloseOnPrice,
468
458
  protocol: PROTOCOLS.AaveV3,
469
459
  },
460
+ [Bundles.MainnetIds.SPARK_CLOSE]: {
461
+ strategyOrBundleId: Bundles.MainnetIds.SPARK_CLOSE,
462
+ strategyId: Strategies.Identifiers.CloseOnPrice,
463
+ protocol: PROTOCOLS.Spark,
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
470
  };
471
471
  export const OPTIMISM_BUNDLES_INFO = {
472
472
  [Bundles.OptimismIds.AAVE_V3_REPAY]: {
@@ -656,6 +656,11 @@ export const BASE_BUNDLES_INFO = {
656
656
  strategyId: Strategies.Identifiers.EoaCloseOnPrice,
657
657
  protocol: PROTOCOLS.AaveV3,
658
658
  },
659
+ [Bundles.BaseIds.MORPHO_BLUE_CLOSE]: {
660
+ strategyOrBundleId: Bundles.BaseIds.MORPHO_BLUE_CLOSE,
661
+ strategyId: Strategies.Identifiers.CloseOnPrice,
662
+ protocol: PROTOCOLS.MorphoBlue,
663
+ },
659
664
  };
660
665
  export const ARBITRUM_BUNDLES_INFO = {
661
666
  [Bundles.ArbitrumIds.AAVE_V3_REPAY]: {
@@ -798,6 +803,11 @@ export const ARBITRUM_BUNDLES_INFO = {
798
803
  strategyId: Strategies.Identifiers.EoaBoost,
799
804
  protocol: PROTOCOLS.MorphoBlue,
800
805
  },
806
+ [Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE]: {
807
+ strategyOrBundleId: Bundles.ArbitrumIds.MORPHO_BLUE_CLOSE,
808
+ strategyId: Strategies.Identifiers.CloseOnPrice,
809
+ protocol: PROTOCOLS.MorphoBlue,
810
+ },
801
811
  };
802
812
  export const BUNDLES_INFO = {
803
813
  [ChainId.Ethereum]: MAINNET_BUNDLES_INFO,
@@ -7,9 +7,6 @@ import { getPositionId, getRatioStateInfoForAaveCloseStrategy, getStopLossAndTak
7
7
  import * as subDataService from './subDataService';
8
8
  import * as triggerService from './triggerService';
9
9
  const web3 = new Web3();
10
- const SPARK_MARKET_ADDRESSES = {
11
- [ChainId.Ethereum]: '0x02C3eA4e34C0cBd694D2adFa2c690EECbC1793eE',
12
- };
13
10
  const AAVE_V3_MARKET_ADDRESSES = {
14
11
  [ChainId.Ethereum]: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e',
15
12
  [ChainId.Optimism]: '0xa97684ead0e402dC232d5A977953DF7ECBaB3CDb',
@@ -590,23 +587,24 @@ function parseSparkLeverageManagement(position, parseData) {
590
587
  function parseSparkCloseOnPrice(position, parseData) {
591
588
  const _position = cloneDeep(position);
592
589
  const { subStruct } = parseData.subscriptionEventData;
593
- const triggerData = triggerService.sparkQuotePriceTrigger.decode(subStruct.triggerData);
594
- const subData = subDataService.sparkQuotePriceSubData.decode(subStruct.subData);
590
+ const triggerData = triggerService.sparkQuotePriceRangeTrigger.decode(subStruct.triggerData);
591
+ const subData = subDataService.sparkCloseGenericSubData.decode(subStruct.subData);
595
592
  _position.strategyData.decoded.triggerData = triggerData;
596
593
  _position.strategyData.decoded.subData = subData;
597
- _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, SPARK_MARKET_ADDRESSES[_position.chainId]);
594
+ _position.positionId = getPositionId(_position.chainId, _position.protocol.id, _position.owner, subData.marketAddr);
595
+ const { takeProfitType, stopLossType } = getStopLossAndTakeProfitTypeByCloseStrategyType(+subData.closeType);
598
596
  _position.specific = {
599
597
  collAsset: subData.collAsset,
600
598
  collAssetId: subData.collAssetId,
601
599
  debtAsset: subData.debtAsset,
602
600
  debtAssetId: subData.debtAssetId,
603
- baseToken: triggerData.baseTokenAddress,
604
- quoteToken: triggerData.quoteTokenAddress,
605
- price: triggerData.price,
606
- ratioState: triggerData.ratioState,
601
+ baseToken: triggerData.collToken,
602
+ quoteToken: triggerData.debtToken,
603
+ stopLossPrice: triggerData.lowerPrice,
604
+ takeProfitPrice: triggerData.upperPrice,
605
+ stopLossType,
606
+ takeProfitType,
607
607
  };
608
- const { ratioState } = getRatioStateInfoForAaveCloseStrategy(_position.specific.ratioState, wethToEthByAddress(_position.specific.collAsset, parseData.chainId), wethToEthByAddress(_position.specific.debtAsset, parseData.chainId), parseData.chainId);
609
- _position.strategy.strategyId = isRatioStateOver(ratioState) ? Strategies.IdOverrides.TakeProfit : Strategies.IdOverrides.StopLoss;
610
608
  return _position;
611
609
  }
612
610
  function parseLiquitySavingsLiqProtection(position, parseData) {
@@ -743,6 +741,35 @@ function parseMorphoBlueLeverageManagementOnPrice(position, parseData) {
743
741
  };
744
742
  return _position;
745
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
+ }
746
773
  function parseLiquityV2CloseOnPrice(position, parseData) {
747
774
  const _position = cloneDeep(position);
748
775
  const { subStruct } = parseData.subscriptionEventData;
@@ -917,8 +944,7 @@ const parsingMethodsMapping = {
917
944
  [ProtocolIdentifiers.StrategiesAutomation.Spark]: {
918
945
  [Strategies.Identifiers.Repay]: parseSparkLeverageManagement,
919
946
  [Strategies.Identifiers.Boost]: parseSparkLeverageManagement,
920
- [Strategies.Identifiers.CloseToDebt]: parseSparkCloseOnPrice,
921
- [Strategies.Identifiers.CloseToCollateral]: parseSparkCloseOnPrice,
947
+ [Strategies.Identifiers.CloseOnPrice]: parseSparkCloseOnPrice,
922
948
  },
923
949
  [ProtocolIdentifiers.StrategiesAutomation.CrvUSD]: {
924
950
  [Strategies.Identifiers.Repay]: parseCrvUSDLeverageManagement,
@@ -931,6 +957,7 @@ const parsingMethodsMapping = {
931
957
  [Strategies.Identifiers.EoaRepay]: parseMorphoBlueLeverageManagement,
932
958
  [Strategies.Identifiers.EoaBoost]: parseMorphoBlueLeverageManagement,
933
959
  [Strategies.Identifiers.BoostOnPrice]: parseMorphoBlueLeverageManagementOnPrice,
960
+ [Strategies.Identifiers.CloseOnPrice]: parseMorphoBlueCloseOnPrice,
934
961
  },
935
962
  [ProtocolIdentifiers.StrategiesAutomation.FluidT1]: {
936
963
  [Strategies.Identifiers.Repay]: parseFluidT1LeverageManagement,
@@ -85,17 +85,7 @@ export declare const exchangeEncode: {
85
85
  };
86
86
  export declare const sparkEncode: {
87
87
  leverageManagement(triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean): string;
88
- closeToAsset(strategyOrBundleId: number, isBundle: boolean | undefined, triggerData: {
89
- baseTokenAddress: EthereumAddress;
90
- quoteTokenAddress: EthereumAddress;
91
- price: number;
92
- ratioState: RatioState;
93
- }, subData: {
94
- collAsset: EthereumAddress;
95
- collAssetId: number;
96
- debtAsset: EthereumAddress;
97
- debtAssetId: number;
98
- }): (number | boolean | string[])[];
88
+ closeOnPriceGeneric(strategyOrBundleId: number, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, user: EthereumAddress, stopLossPrice?: number, stopLossType?: CloseToAssetType, takeProfitPrice?: number, takeProfitType?: CloseToAssetType): (number | boolean | string[])[];
99
89
  };
100
90
  export declare const crvUSDEncode: {
101
91
  leverageManagement(owner: EthereumAddress, controllerAddr: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, collTokenAddr: EthereumAddress, crvUSDAddr: EthereumAddress): (boolean | string[] | Bundles.MainnetIds)[];
@@ -104,6 +94,7 @@ export declare const crvUSDEncode: {
104
94
  export declare const morphoBlueEncode: {
105
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)[];
106
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[])[];
107
98
  };
108
99
  export declare const liquityV2Encode: {
109
100
  leverageManagement(market: EthereumAddress, troveId: string, collToken: EthereumAddress, boldToken: EthereumAddress, ratioState: RatioState, targetRatio: number, triggerRatio: number, strategyOrBundleId: number): (number | boolean | string[])[];
@@ -232,11 +232,11 @@ export const sparkEncode = {
232
232
  subInput = subInput.concat(boostEnabled ? '01' : '00');
233
233
  return subInput;
234
234
  },
235
- closeToAsset(strategyOrBundleId, isBundle = true, triggerData, subData) {
236
- const { collAsset, collAssetId, debtAsset, debtAssetId, } = subData;
237
- const subDataEncoded = subDataService.sparkQuotePriceSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId);
238
- const { baseTokenAddress, quoteTokenAddress, price, ratioState, } = triggerData;
239
- const triggerDataEncoded = triggerService.sparkQuotePriceTrigger.encode(baseTokenAddress, quoteTokenAddress, price, ratioState);
235
+ closeOnPriceGeneric(strategyOrBundleId, collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, user, stopLossPrice = 0, stopLossType = CloseToAssetType.DEBT, takeProfitPrice = 0, takeProfitType = CloseToAssetType.COLLATERAL) {
236
+ const isBundle = true;
237
+ const closeType = getCloseStrategyType(stopLossPrice, stopLossType, takeProfitPrice, takeProfitType);
238
+ const subDataEncoded = subDataService.sparkCloseGenericSubData.encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user);
239
+ const triggerDataEncoded = triggerService.sparkQuotePriceRangeTrigger.encode(collAsset, debtAsset, stopLossPrice, takeProfitPrice);
240
240
  return [strategyOrBundleId, isBundle, triggerDataEncoded, subDataEncoded];
241
241
  },
242
242
  };
@@ -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) {