@defisaver/automation-sdk 2.0.5 → 2.0.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.
Files changed (50) hide show
  1. package/.env.dev +5 -0
  2. package/.tests.sh +3 -0
  3. package/README.md +3 -1
  4. package/esm/automation/private/LegacyProtocol.test.d.ts +1 -0
  5. package/esm/automation/private/LegacyProtocol.test.js +25 -0
  6. package/esm/automation/private/Protocol.test.d.ts +1 -0
  7. package/esm/automation/private/Protocol.test.js +25 -0
  8. package/esm/automation/private/StrategiesAutomation.js +1 -1
  9. package/esm/constants/index.js +15 -0
  10. package/esm/services/contractService.d.ts +3 -2
  11. package/esm/services/contractService.js +7 -1
  12. package/esm/services/ethereumService.test.d.ts +1 -0
  13. package/esm/services/ethereumService.test.js +241 -0
  14. package/esm/services/strategiesService.js +40 -0
  15. package/esm/services/strategiesService.test.d.ts +1 -0
  16. package/esm/services/strategiesService.test.js +108 -0
  17. package/esm/services/strategySubService.d.ts +17 -3
  18. package/esm/services/strategySubService.js +17 -6
  19. package/esm/services/strategySubService.test.d.ts +1 -0
  20. package/esm/services/strategySubService.test.js +692 -0
  21. package/esm/services/subDataService.d.ts +8 -1
  22. package/esm/services/subDataService.js +23 -14
  23. package/esm/services/subDataService.test.d.ts +1 -0
  24. package/esm/services/subDataService.test.js +993 -0
  25. package/esm/services/triggerService.d.ts +17 -0
  26. package/esm/services/triggerService.js +42 -1
  27. package/esm/services/triggerService.test.js +119 -17
  28. package/esm/types/enums.d.ts +10 -2
  29. package/esm/types/enums.js +8 -0
  30. package/esm/types/index.d.ts +19 -2
  31. package/package.json +3 -3
  32. package/src/automation/private/LegacyProtocol.test.ts +24 -0
  33. package/src/automation/private/Protocol.test.ts +24 -0
  34. package/src/automation/private/StrategiesAutomation.ts +1 -1
  35. package/src/constants/index.ts +15 -0
  36. package/src/services/contractService.ts +17 -4
  37. package/src/services/ethereumService.test.ts +256 -0
  38. package/src/services/ethereumService.ts +2 -1
  39. package/src/services/strategiesService.test.ts +103 -0
  40. package/src/services/strategiesService.ts +66 -3
  41. package/src/services/strategySubService.test.ts +835 -0
  42. package/src/services/strategySubService.ts +50 -15
  43. package/src/services/subDataService.test.ts +1063 -0
  44. package/src/services/subDataService.ts +29 -14
  45. package/src/services/triggerService.test.ts +133 -20
  46. package/src/services/triggerService.ts +55 -0
  47. package/src/services/utils.test.ts +1 -1
  48. package/src/types/enums.ts +8 -0
  49. package/src/types/index.ts +27 -3
  50. package/umd/index.js +282 -115
@@ -0,0 +1,256 @@
1
+ import Web3 from 'web3';
2
+ import { expect } from 'chai';
3
+ import { getAssetInfo } from '@defisaver/tokens';
4
+ import { PastEventOptions } from 'web3-eth-contract';
5
+
6
+ import { ChainId } from '../types/enums';
7
+ import type { BlockNumber, Multicall } from '../types';
8
+ import { Contract } from '../types';
9
+ import type { Erc20 } from '../types/contracts/generated';
10
+
11
+ import { getEventsFromContract, multicall, } from './ethereumService';
12
+
13
+ import { makeErc20Contract } from './contractService';
14
+
15
+ require('dotenv').config({ path: '.env' });
16
+
17
+ const Web3_1 = new Web3(process.env.RPC_1!);
18
+ const Web3_10 = new Web3(process.env.RPC_10!);
19
+ const Web3_42161 = new Web3(process.env.RPC_42161!);
20
+
21
+ describe('Feature: ethereumService.ts', () => {
22
+ describe('When testing ethereumService.multicall', () => {
23
+ const examples: Array<[
24
+ Multicall.Payload,
25
+ [
26
+ web3: Web3,
27
+ chainId: ChainId,
28
+ calls: Multicall.Calls[],
29
+ block: BlockNumber,
30
+ ]
31
+ ]> = [
32
+ [
33
+ [{ 0: 'Wrapped Ether', '__length__': 1 }, { 0: '18', '__length__': 1 }],
34
+ [
35
+ Web3_1,
36
+ ChainId.Ethereum,
37
+ [
38
+ {
39
+ abiItem: {'constant':true,'inputs':[],'name':'name','outputs':[{'name':'','type':'string'}],'payable':false,'stateMutability':'view','type':'function'},
40
+ target: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
41
+ params: [],
42
+ },
43
+ {
44
+ abiItem: {'constant':true,'inputs':[],'name':'decimals','outputs':[{'name':'','type':'uint8'}],'payable':false,'stateMutability':'view','type':'function'},
45
+ target: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
46
+ params: [],
47
+ }
48
+ ],
49
+ 'latest',
50
+ ]
51
+ ],
52
+ [
53
+ [{ 0: 'Wrapped Ether', '__length__': 1 }, { 0: '18', '__length__': 1 }],
54
+ [
55
+ Web3_10,
56
+ ChainId.Optimism,
57
+ [
58
+ {
59
+ abiItem: {'constant':true,'inputs':[],'name':'name','outputs':[{'name':'','type':'string'}],'payable':false,'stateMutability':'view','type':'function'},
60
+ target: '0x4200000000000000000000000000000000000006',
61
+ params: [],
62
+ },
63
+ {
64
+ abiItem: {'constant':true,'inputs':[],'name':'decimals','outputs':[{'name':'','type':'uint8'}],'payable':false,'stateMutability':'view','type':'function'},
65
+ target: '0x4200000000000000000000000000000000000006',
66
+ params: [],
67
+ }
68
+ ],
69
+ 'latest',
70
+ ]
71
+ ],
72
+ [
73
+ [{ 0: 'Wrapped Ether', '__length__': 1 }, { 0: '18', '__length__': 1 }],
74
+ [
75
+ Web3_42161,
76
+ ChainId.Arbitrum,
77
+ [
78
+ {
79
+ abiItem: {'constant':true,'inputs':[],'name':'name','outputs':[{'name':'','type':'string'}],'payable':false,'stateMutability':'view','type':'function'},
80
+ target: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
81
+ params: [],
82
+ },
83
+ {
84
+ abiItem: {'constant':true,'inputs':[],'name':'decimals','outputs':[{'name':'','type':'uint8'}],'payable':false,'stateMutability':'view','type':'function'},
85
+ target: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1',
86
+ params: [],
87
+ }
88
+ ],
89
+ 'latest',
90
+ ]
91
+ ],
92
+ ];
93
+
94
+ examples.forEach(([expected, actual]) => {
95
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, async () => {
96
+ expect(await multicall(...actual)).to.eql(expected);
97
+ });
98
+ });
99
+ });
100
+
101
+ describe('When testing ethereumService.getEventsFromContract', () => {
102
+ const examples: Array<[
103
+ any[],
104
+ [
105
+ contractWithMeta: Contract.WithMeta<Erc20>,
106
+ contractWithMetaFork: Contract.WithMeta<Erc20> | null,
107
+ event: string,
108
+ options?: PastEventOptions,
109
+ ]
110
+ ]> = [
111
+ [
112
+ [
113
+ {
114
+ 'address': '0x5f98805A4E8be255a32880FDeC7F6728C6568bA0',
115
+ 'blockHash': '0xb92cab2569456dbfbdb853d2c67d72c9a7580543dbcb55d483a77322b40755a4',
116
+ 'blockNumber': 15166163,
117
+ 'event': 'Transfer',
118
+ 'id': 'log_e2258e3a',
119
+ 'logIndex': 385,
120
+ 'raw': {
121
+ 'data': '0x0000000000000000000000000000000000000000000001b58c2186829983fca9',
122
+ 'topics': [
123
+ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
124
+ '0x000000000000000000000000ea57dc30959eb17c506e4da095fa9181f3e0ac6d',
125
+ '0x0000000000000000000000009ccf93089cb14f94baeb8822f8ceffd91bd71649',
126
+ ],
127
+ },
128
+ 'removed': false,
129
+ 'returnValues': {
130
+ '0': '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
131
+ '1': '0x9cCf93089cb14F94BAeB8822F8CeFfd91Bd71649',
132
+ '2': '8071324659946094853289',
133
+ 'from': '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
134
+ 'to': '0x9cCf93089cb14F94BAeB8822F8CeFfd91Bd71649',
135
+ 'value': '8071324659946094853289',
136
+ },
137
+ 'signature': '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
138
+ 'transactionHash': '0x95b28d8f71719c219e09b428e6ff781d717088784fbf63681446da13de6b0c4a',
139
+ 'transactionIndex': 187,
140
+ },
141
+ ],
142
+ [
143
+ makeErc20Contract(Web3_1, getAssetInfo('LUSD').address, ChainId.Ethereum),
144
+ null,
145
+ 'Transfer',
146
+ {
147
+ fromBlock: 15166163,
148
+ toBlock: 15166163,
149
+ filter: {
150
+ from: '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
151
+ to: '0x9cCf93089cb14F94BAeB8822F8CeFfd91Bd71649',
152
+ }
153
+ },
154
+ ]
155
+ ],
156
+ [
157
+ [
158
+ {
159
+ 'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
160
+ 'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
161
+ 'blockNumber': 5353002,
162
+ 'event': 'Transfer',
163
+ 'id': 'log_f49645b8',
164
+ 'logIndex': 1,
165
+ 'raw': {
166
+ 'data': '0x000000000000000000000000000000000000000000000001158e460913d00000',
167
+ 'topics': [
168
+ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
169
+ '0x000000000000000000000000ea57dc30959eb17c506e4da095fa9181f3e0ac6d',
170
+ '0x00000000000000000000000013a22f1bba428eaaf56960530ec11118da916c11',
171
+ ],
172
+ },
173
+ 'removed': false,
174
+ 'returnValues': {
175
+ '0': '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
176
+ '1': '0x13A22f1bBa428eaAf56960530Ec11118DA916C11',
177
+ '2': '20000000000000000000',
178
+ 'from': '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
179
+ 'to': '0x13A22f1bBa428eaAf56960530Ec11118DA916C11',
180
+ 'value': '20000000000000000000',
181
+ },
182
+ 'signature': '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
183
+ 'transactionHash': '0x37c886a97c938747299c0f6b3e4591304bdd47a938df7c8146454d6fee5a6501',
184
+ 'transactionIndex': 0,
185
+ },
186
+ ],
187
+ [
188
+ makeErc20Contract(Web3_10, getAssetInfo('DAI', ChainId.Optimism).address, ChainId.Optimism),
189
+ null,
190
+ 'Transfer',
191
+ {
192
+ fromBlock: 5353002,
193
+ toBlock: 5353002,
194
+ filter: {
195
+ from: '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
196
+ to: '0x13A22f1bBa428eaAf56960530Ec11118DA916C11',
197
+ }
198
+ },
199
+ ]
200
+ ],
201
+ [
202
+ [
203
+ {
204
+ 'address': '0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1',
205
+ 'blockHash': '0xacb0213af63b4c17c436f084a96d1ac385641a59a9a4cf014ae3337cbe545aa7',
206
+ 'blockNumber': 5353002,
207
+ 'event': 'Transfer',
208
+ 'id': 'log_f49645b8',
209
+ 'logIndex': 1,
210
+ 'raw': {
211
+ 'data': '0x000000000000000000000000000000000000000000000001158e460913d00000',
212
+ 'topics': [
213
+ '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
214
+ '0x000000000000000000000000ea57dc30959eb17c506e4da095fa9181f3e0ac6d',
215
+ '0x00000000000000000000000013a22f1bba428eaaf56960530ec11118da916c11',
216
+ ],
217
+ },
218
+ 'removed': false,
219
+ 'returnValues': {
220
+ '0': '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
221
+ '1': '0x13A22f1bBa428eaAf56960530Ec11118DA916C11',
222
+ '2': '20000000000000000000',
223
+ 'from': '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
224
+ 'to': '0x13A22f1bBa428eaAf56960530Ec11118DA916C11',
225
+ 'value': '20000000000000000000',
226
+ },
227
+ 'signature': '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
228
+ 'transactionHash': '0x37c886a97c938747299c0f6b3e4591304bdd47a938df7c8146454d6fee5a6501',
229
+ 'transactionIndex': 0,
230
+ },
231
+ ],
232
+ [
233
+ makeErc20Contract(Web3_10, getAssetInfo('DAI', ChainId.Arbitrum).address, ChainId.Arbitrum),
234
+ null,
235
+ 'Transfer',
236
+ {
237
+ fromBlock: 5353002,
238
+ toBlock: 5353002,
239
+ filter: {
240
+ from: '0xEA57Dc30959eb17c506E4dA095fa9181f3E0Ac6D',
241
+ to: '0x13a22f1bba428eaaf56960530ec11118da916c11',
242
+ }
243
+ },
244
+ ]
245
+ ],
246
+ ];
247
+
248
+ examples.forEach(([expected, actual]) => {
249
+ it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, async () => {
250
+ const data = await getEventsFromContract(...actual);
251
+ console.log(data);
252
+ expect(await getEventsFromContract(...actual)).to.eql(expected);
253
+ });
254
+ });
255
+ });
256
+ });
@@ -44,7 +44,8 @@ export async function multicall(
44
44
  export async function getEventsFromContract<T extends BaseContract>(
45
45
  contractWithMeta: Contract.WithMeta<T>,
46
46
  contractWithMetaFork: Contract.WithMeta<T> | null,
47
- event: string, options?: PastEventOptions,
47
+ event: string,
48
+ options?: PastEventOptions,
48
49
  ) {
49
50
  const events = await contractWithMeta.contract.getPastEvents(
50
51
  event,
@@ -0,0 +1,103 @@
1
+ import { expect } from 'chai';
2
+
3
+ import { ProtocolIdentifiers, Strategies } from '../types/enums';
4
+ import type { ParseData, Position } from '../types';
5
+
6
+ import { parseStrategiesAutomatedPosition } from './strategiesService';
7
+
8
+ describe('Feature: strategiesService.ts', () => {
9
+ describe('When testing strategiesService.parseStrategiesAutomatedPosition', async () => {
10
+ // TODO: we should probably write this for every strategy?
11
+ const examples: Array<[Position.Automated | null, ParseData]> = [
12
+ [
13
+ {
14
+ isEnabled: true,
15
+ chainId: 1,
16
+ subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
17
+ blockNumber: 18015756,
18
+ subId: 379,
19
+ owner: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
20
+ protocol: {
21
+ id: ProtocolIdentifiers.StrategiesAutomation.AaveV3,
22
+ name: 'Aave',
23
+ slug: 'aave',
24
+ version: 'V3',
25
+ fullName: 'Aave V3'
26
+ },
27
+ strategy: {
28
+ isBundle: true,
29
+ strategyOrBundleId: 8,
30
+ strategyId: Strategies.IdOverrides.LeverageManagement,
31
+ protocol: {
32
+ id: ProtocolIdentifiers.StrategiesAutomation.AaveV3,
33
+ name: 'Aave',
34
+ slug: 'aave',
35
+ version: 'V3',
36
+ fullName: 'Aave V3'
37
+ }
38
+ },
39
+ strategyData: {
40
+ encoded: {
41
+ triggerData: [
42
+ '0x0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001',
43
+ ],
44
+ subData: [
45
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
46
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
47
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
48
+ '0x0000000000000000000000000000000000000000000000000000000000000000'
49
+ ]
50
+ },
51
+ decoded: {
52
+ triggerData: {
53
+ owner: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
54
+ market: '0x2f39d218133AFaB8F2B819B1066c7E434Ad94E9e',
55
+ ratio: 185,
56
+ ratioState: 1
57
+ },
58
+ subData: { targetRatio: 200 }
59
+ }
60
+ },
61
+ specific: {
62
+ triggerRepayRatio: 185,
63
+ targetRepayRatio: 200,
64
+ repayEnabled: true,
65
+ subId1: 379,
66
+ mergeWithSameId: true
67
+ }
68
+ },
69
+ {
70
+ chainId: 1,
71
+ blockNumber: 18015756,
72
+ subscriptionEventData: {
73
+ subId: '379',
74
+ proxy: '0x9cB7E19861665366011899d74E75d4F2A419aEeD',
75
+ subHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1',
76
+ // @ts-ignore
77
+ subStruct:
78
+ {
79
+ strategyOrBundleId: '8',
80
+ isBundle: true,
81
+ triggerData: ['0x0000000000000000000000009cb7e19861665366011899d74e75d4f2a419aeed0000000000000000000000002f39d218133afab8f2b819b1066c7e434ad94e9e00000000000000000000000000000000000000000000000019ac8532c27900000000000000000000000000000000000000000000000000000000000000000001'],
82
+ subData: [
83
+ '0x0000000000000000000000000000000000000000000000001bc16d674ec80000', '0x0000000000000000000000000000000000000000000000000000000000000001',
84
+ '0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000000000000000000000',
85
+ ],
86
+ }
87
+ },
88
+ strategiesSubsData: {
89
+ userProxy: '0x9cb7e19861665366011899d74e75d4f2a419aeed',
90
+ isEnabled: true,
91
+ strategySubHash: '0xafa4d200be62f171b57b1ae0f4e8348d1ac3f6d0812ad6da74a2adae8037dde1'
92
+ }
93
+ },
94
+ ],
95
+ ];
96
+
97
+ examples.forEach(([expected, actual]) => {
98
+ it(`Given ${JSON.stringify(actual)} should return expected value: ${JSON.stringify(expected)}`, async () => {
99
+ expect(parseStrategiesAutomatedPosition(actual)).to.eql(expected);
100
+ });
101
+ });
102
+ });
103
+ });
@@ -4,6 +4,7 @@ import { cloneDeep } from 'lodash';
4
4
  import { BUNDLES_INFO, STRATEGIES_INFO } from '../constants';
5
5
  import type {
6
6
  Position, ParseData, StrategiesToProtocolVersionMapping, BundleOrStrategy, StrategyOrBundleIds,
7
+ BundleInfoUnion, StrategyInfoUnion,
7
8
  } from '../types';
8
9
  import type { ChainId } from '../types/enums';
9
10
  import { ProtocolIdentifiers, Strategies } from '../types/enums';
@@ -77,6 +78,7 @@ function parseMakerTrailingStop(position: Position.Automated, parseData: ParseDa
77
78
 
78
79
  return _position;
79
80
  }
81
+
80
82
  function parseMakerLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
81
83
  const _position = cloneDeep(position);
82
84
 
@@ -112,6 +114,7 @@ function parseMakerLeverageManagement(position: Position.Automated, parseData: P
112
114
 
113
115
  return _position;
114
116
  }
117
+
115
118
  function parseLiquityCloseOnPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
116
119
  const _position = cloneDeep(position);
117
120
 
@@ -299,6 +302,43 @@ function parseAaveV3CloseOnPrice(position: Position.Automated, parseData: ParseD
299
302
  return _position;
300
303
  }
301
304
 
305
+ function parseAaveV3CloseOnPriceWithMaximumGasPrice(position: Position.Automated, parseData: ParseData): Position.Automated {
306
+ const _position = cloneDeep(position);
307
+
308
+ const { subStruct } = parseData.subscriptionEventData;
309
+
310
+ const triggerData = triggerService.aaveV3QuotePriceWithMaximumGasPriceTrigger.decode(subStruct.triggerData);
311
+ const subData = subDataService.aaveV3QuotePriceSubData.decode(subStruct.subData);
312
+
313
+ _position.strategyData.decoded.triggerData = triggerData;
314
+ _position.strategyData.decoded.subData = subData;
315
+
316
+ _position.specific = {
317
+ collAsset: subData.collAsset,
318
+ collAssetId: subData.collAssetId,
319
+ debtAsset: subData.debtAsset,
320
+ debtAssetId: subData.debtAssetId,
321
+ baseToken: triggerData.baseTokenAddress,
322
+ quoteToken: triggerData.quoteTokenAddress,
323
+ price: triggerData.price,
324
+ maximumGasPrice: triggerData.maximumGasPrice,
325
+ ratioState: triggerData.ratioState,
326
+ };
327
+
328
+ const { ratioState } = getRatioStateInfoForAaveCloseStrategy(
329
+ _position.specific.ratioState,
330
+ wethToEthByAddress(_position.specific.collAsset, parseData.chainId),
331
+ wethToEthByAddress(_position.specific.debtAsset, parseData.chainId),
332
+ parseData.chainId,
333
+ );
334
+
335
+ _position.strategy.strategyId = isRatioStateOver(ratioState)
336
+ ? Strategies.IdOverrides.TakeProfitWithGasPrice
337
+ : Strategies.IdOverrides.StopLossWithGasPrice;
338
+
339
+ return _position;
340
+ }
341
+
302
342
  function parseCompoundV2LeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
303
343
  const _position = cloneDeep(position);
304
344
 
@@ -412,6 +452,7 @@ function parseExchangeDca(position: Position.Automated, parseData: ParseData, ch
412
452
 
413
453
  return _position;
414
454
  }
455
+
415
456
  function parseExchangeLimitOrder(position: Position.Automated, parseData: ParseData, chainId: ChainId): Position.Automated {
416
457
  const _position = cloneDeep(position);
417
458
 
@@ -424,6 +465,7 @@ function parseExchangeLimitOrder(position: Position.Automated, parseData: ParseD
424
465
 
425
466
  return _position;
426
467
  }
468
+
427
469
  function parseLiquityLeverageManagement(position: Position.Automated, parseData: ParseData): Position.Automated {
428
470
  const _position = cloneDeep(position);
429
471
 
@@ -551,6 +593,24 @@ function parseLiquitySavingsLiqProtection(position: Position.Automated, parseDat
551
593
  return _position;
552
594
  }
553
595
 
596
+ function parseDebtInFrontRepay(position: Position.Automated, parseData: ParseData): Position.Automated {
597
+ const _position = cloneDeep(position);
598
+
599
+ const { subStruct } = parseData.subscriptionEventData;
600
+
601
+ const triggerData = triggerService.liquityDebtInFrontWithLimitTrigger.decode(subStruct.triggerData);
602
+ const subData = subDataService.liquityDebtInFrontRepaySubData.decode(subStruct.subData);
603
+
604
+ _position.strategyData.decoded.triggerData = triggerData;
605
+ _position.strategyData.decoded.subData = subData;
606
+
607
+ _position.specific = {
608
+ debtInFrontMin: triggerData.debtInFrontMin,
609
+ targetRepayRatioIncrease: subData.targetRatioIncrease,
610
+ };
611
+
612
+ return _position;
613
+ }
554
614
 
555
615
  const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
556
616
  [ProtocolIdentifiers.StrategiesAutomation.MakerDAO]: {
@@ -570,6 +630,7 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
570
630
  [Strategies.Identifiers.Boost]: parseLiquityLeverageManagement,
571
631
  [Strategies.Identifiers.SavingsDsrPayback]: parseLiquitySavingsLiqProtection,
572
632
  [Strategies.Identifiers.SavingsDsrSupply]: parseLiquitySavingsLiqProtection,
633
+ [Strategies.Identifiers.DebtInFrontRepay]: parseDebtInFrontRepay,
573
634
  },
574
635
  [ProtocolIdentifiers.StrategiesAutomation.AaveV2]: {
575
636
  [Strategies.Identifiers.Repay]: parseAaveV2LeverageManagement,
@@ -579,7 +640,9 @@ const parsingMethodsMapping: StrategiesToProtocolVersionMapping = {
579
640
  [Strategies.Identifiers.Repay]: parseAaveV3LeverageManagement,
580
641
  [Strategies.Identifiers.Boost]: parseAaveV3LeverageManagement,
581
642
  [Strategies.Identifiers.CloseToDebt]: parseAaveV3CloseOnPrice,
643
+ [Strategies.Identifiers.CloseToDebtWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
582
644
  [Strategies.Identifiers.CloseToCollateral]: parseAaveV3CloseOnPrice,
645
+ [Strategies.Identifiers.CloseToCollateralWithGasPrice]: parseAaveV3CloseOnPriceWithMaximumGasPrice,
583
646
  },
584
647
  [ProtocolIdentifiers.StrategiesAutomation.CompoundV2]: {
585
648
  [Strategies.Identifiers.Repay]: parseCompoundV2LeverageManagement,
@@ -623,12 +686,12 @@ export function parseStrategiesAutomatedPosition(parseData: ParseData): Position
623
686
  } = subscriptionEventData;
624
687
  const { isEnabled } = strategiesSubsData;
625
688
 
626
- const id = subStruct.strategyOrBundleId as StrategyOrBundleIds;
689
+ const id = subStruct.strategyOrBundleId as unknown as StrategyOrBundleIds;
627
690
 
628
691
  const strategyOrBundleInfo = (
629
692
  subStruct.isBundle
630
- ? BUNDLES_INFO[chainId][id]
631
- : STRATEGIES_INFO[chainId][id]
693
+ ? BUNDLES_INFO[chainId][id as keyof BundleInfoUnion]
694
+ : STRATEGIES_INFO[chainId][id as keyof StrategyInfoUnion]
632
695
  ) as BundleOrStrategy;
633
696
 
634
697
  if (!strategyOrBundleInfo) return null;