@defisaver/automation-sdk 3.3.14 → 3.3.15-liq-prot-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.
- package/cjs/constants/index.js +95 -0
- package/cjs/index.d.ts +4 -3
- package/cjs/index.js +6 -2
- package/cjs/services/strategiesService.js +181 -17
- package/cjs/services/strategySubService.d.ts +14 -13
- package/cjs/services/strategySubService.js +74 -63
- package/cjs/services/strategySubService.test.js +0 -234
- package/cjs/services/subDataService.d.ts +98 -1
- package/cjs/services/subDataService.js +264 -6
- package/cjs/services/subDataService.test.js +0 -42
- package/cjs/services/utils.d.ts +3 -1
- package/cjs/services/utils.js +34 -1
- package/cjs/services/utils.test.js +25 -0
- package/cjs/types/enums.d.ts +29 -6
- package/cjs/types/enums.js +23 -0
- package/esm/constants/index.js +95 -0
- package/esm/index.d.ts +4 -3
- package/esm/index.js +7 -3
- package/esm/services/strategiesService.js +181 -17
- package/esm/services/strategySubService.d.ts +14 -13
- package/esm/services/strategySubService.js +74 -60
- package/esm/services/strategySubService.test.js +2 -236
- package/esm/services/subDataService.d.ts +98 -1
- package/esm/services/subDataService.js +262 -5
- package/esm/services/subDataService.test.js +0 -42
- package/esm/services/utils.d.ts +3 -1
- package/esm/services/utils.js +32 -1
- package/esm/services/utils.test.js +27 -2
- package/esm/types/enums.d.ts +29 -6
- package/esm/types/enums.js +23 -0
- package/package.json +1 -1
- package/src/constants/index.ts +96 -0
- package/src/index.ts +24 -6
- package/src/services/strategiesService.ts +246 -17
- package/src/services/strategySubService.test.ts +0 -279
- package/src/services/strategySubService.ts +196 -110
- package/src/services/subDataService.test.ts +0 -48
- package/src/services/subDataService.ts +363 -4
- package/src/services/utils.test.ts +32 -1
- package/src/services/utils.ts +32 -1
- package/src/types/enums.ts +23 -0
|
@@ -71,6 +71,14 @@ export declare const makerLeverageManagementWithoutSubProxy: {
|
|
|
71
71
|
daiAddr: string;
|
|
72
72
|
};
|
|
73
73
|
};
|
|
74
|
+
export declare const makerLiquidationProtectionSubData: {
|
|
75
|
+
encode(vaultId: number, targetRatio: number, daiAddr?: EthereumAddress): string[];
|
|
76
|
+
decode(subData: string[]): {
|
|
77
|
+
vaultId: number;
|
|
78
|
+
targetRatio: number;
|
|
79
|
+
daiAddr: string;
|
|
80
|
+
};
|
|
81
|
+
};
|
|
74
82
|
/**
|
|
75
83
|
__ __ ______ __ __ __ .___________.____ ____ ____ ____ __
|
|
76
84
|
| | | | / __ \ | | | | | | | |\ \ / / \ \ / / /_ |
|
|
@@ -89,6 +97,13 @@ export declare const liquityLeverageManagementSubData: {
|
|
|
89
97
|
targetRatio: number;
|
|
90
98
|
};
|
|
91
99
|
};
|
|
100
|
+
export declare const liquityLeverageManagementSubDataWithoutSubProxy: {
|
|
101
|
+
encode(targetRatio: number, ratioState: RatioState): string[];
|
|
102
|
+
decode(subData: string[]): {
|
|
103
|
+
targetRatio: number;
|
|
104
|
+
ratioState: RatioState;
|
|
105
|
+
};
|
|
106
|
+
};
|
|
92
107
|
export declare const liquityCloseSubData: {
|
|
93
108
|
encode(closeToAssetAddr: EthereumAddress, chainId?: ChainId, collAddr?: EthereumAddress, debtAddr?: EthereumAddress): string[];
|
|
94
109
|
decode(subData: string[]): {
|
|
@@ -177,6 +192,14 @@ export declare const aaveV2LeverageManagementSubData: {
|
|
|
177
192
|
targetRatio: number;
|
|
178
193
|
};
|
|
179
194
|
};
|
|
195
|
+
export declare const aaveV2LeverageManagementSubDataWithoutSubProxy: {
|
|
196
|
+
encode(market: EthereumAddress, targetRatio: number, ratioState: RatioState): string[];
|
|
197
|
+
decode(subData: string[]): {
|
|
198
|
+
market: EthereumAddress;
|
|
199
|
+
targetRatio: number;
|
|
200
|
+
ratioState: RatioState;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
180
203
|
/**
|
|
181
204
|
___ ___ ____ ____ _______ ____ ____ ____
|
|
182
205
|
/ \ / \ \ \ / / | ____| \ \ / / |___ \
|
|
@@ -197,6 +220,13 @@ export declare const aaveV3LeverageManagementSubDataWithoutSubProxy: {
|
|
|
197
220
|
ratioState: RatioState;
|
|
198
221
|
};
|
|
199
222
|
};
|
|
223
|
+
export declare const aaveV3LiquidationProtectionSubData: {
|
|
224
|
+
encode(targetRatio: number, ratioState: RatioState, market: EthereumAddress, user: EthereumAddress): string[];
|
|
225
|
+
decode(subData: string[]): {
|
|
226
|
+
targetRatio: number;
|
|
227
|
+
ratioState: RatioState;
|
|
228
|
+
};
|
|
229
|
+
};
|
|
200
230
|
export declare const aaveV3LeverageManagementOnPriceGeneric: {
|
|
201
231
|
encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, marketAddr: EthereumAddress, targetRatio: number, user: EthereumAddress): string[];
|
|
202
232
|
decode(subData: string[]): {
|
|
@@ -269,6 +299,15 @@ export declare const aaveV4LeverageManagementSubData: {
|
|
|
269
299
|
targetRatio: number;
|
|
270
300
|
};
|
|
271
301
|
};
|
|
302
|
+
export declare const aaveV4LiquidationProtectionSubData: {
|
|
303
|
+
encode: (spoke: EthereumAddress, owner: EthereumAddress, ratioState: RatioState, targetRatio: number) => string[];
|
|
304
|
+
decode: (subData: string[]) => {
|
|
305
|
+
spoke: string;
|
|
306
|
+
owner: string;
|
|
307
|
+
ratioState: RatioState;
|
|
308
|
+
targetRatio: number;
|
|
309
|
+
};
|
|
310
|
+
};
|
|
272
311
|
export declare const aaveV4LeverageManagementOnPriceSubData: {
|
|
273
312
|
encode: (spoke: EthereumAddress, owner: EthereumAddress, collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, ratioState: RatioState, targetRatio: number) => string[];
|
|
274
313
|
decode: (subData: string[]) => {
|
|
@@ -320,6 +359,13 @@ export declare const compoundV2LeverageManagementSubData: {
|
|
|
320
359
|
targetRatio: number;
|
|
321
360
|
};
|
|
322
361
|
};
|
|
362
|
+
export declare const compoundV2LeverageManagementSubDataWithoutSubProxy: {
|
|
363
|
+
encode(targetRatio: number, ratioState: RatioState): string[];
|
|
364
|
+
decode(subData: string[]): {
|
|
365
|
+
targetRatio: number;
|
|
366
|
+
ratioState: RatioState;
|
|
367
|
+
};
|
|
368
|
+
};
|
|
323
369
|
/**
|
|
324
370
|
______ ______ .___ ___. .______ ____ ____ ____
|
|
325
371
|
/ | / __ \ | \/ | | _ \ \ \ / / |___ \
|
|
@@ -334,7 +380,22 @@ export declare const compoundV3LeverageManagementSubData: {
|
|
|
334
380
|
targetRatio: number;
|
|
335
381
|
};
|
|
336
382
|
};
|
|
337
|
-
export declare const
|
|
383
|
+
export declare const compoundV3LeverageManagementSubDataWithoutSubProxy: {
|
|
384
|
+
encode(market: EthereumAddress, baseToken: EthereumAddress, targetRatio: number, ratioState: RatioState): string[];
|
|
385
|
+
decode(subData: string[]): {
|
|
386
|
+
market: EthereumAddress;
|
|
387
|
+
baseToken: EthereumAddress;
|
|
388
|
+
targetRatio: number;
|
|
389
|
+
ratioState: RatioState;
|
|
390
|
+
};
|
|
391
|
+
};
|
|
392
|
+
export declare const compoundV3LiquidationProtectionSubData: {
|
|
393
|
+
encode(market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean): string[];
|
|
394
|
+
decode(subData: string[]): {
|
|
395
|
+
targetRatio: number;
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
export declare const compoundV3L2LiquidationProtectionSubData: {
|
|
338
399
|
encode(market: EthereumAddress, baseToken: EthereumAddress, triggerRepayRatio: number, triggerBoostRatio: number, targetBoostRatio: number, targetRepayRatio: number, boostEnabled: boolean, isEOA: boolean): string;
|
|
339
400
|
decode(subData: string[]): {
|
|
340
401
|
targetRatio: number;
|
|
@@ -386,6 +447,14 @@ export declare const exchangeLimitOrderSubData: {
|
|
|
386
447
|
amount: string;
|
|
387
448
|
};
|
|
388
449
|
};
|
|
450
|
+
export declare const exchangeLimitOrderSubDataWithoutSubProxy: {
|
|
451
|
+
encode(fromToken: EthereumAddress, toToken: EthereumAddress, amount: string): string[];
|
|
452
|
+
decode: (subData: string[], chainId: ChainId) => {
|
|
453
|
+
fromToken: string;
|
|
454
|
+
toToken: string;
|
|
455
|
+
amount: string;
|
|
456
|
+
};
|
|
457
|
+
};
|
|
389
458
|
/**
|
|
390
459
|
_______..______ ___ .______ __ ___
|
|
391
460
|
/ || _ \ / \ | _ \ | |/ /
|
|
@@ -406,6 +475,13 @@ export declare const sparkLeverageManagementSubDataWithoutSubProxy: {
|
|
|
406
475
|
ratioState: RatioState;
|
|
407
476
|
};
|
|
408
477
|
};
|
|
478
|
+
export declare const sparkLiquidationProtectionSubData: {
|
|
479
|
+
encode(targetRatio: number, ratioState: RatioState): string[];
|
|
480
|
+
decode(subData: string[]): {
|
|
481
|
+
targetRatio: number;
|
|
482
|
+
ratioState: RatioState;
|
|
483
|
+
};
|
|
484
|
+
};
|
|
409
485
|
export declare const sparkCloseGenericSubData: {
|
|
410
486
|
encode(collAsset: EthereumAddress, collAssetId: number, debtAsset: EthereumAddress, debtAssetId: number, closeType: CloseStrategyType, marketAddr: EthereumAddress, user: EthereumAddress): string[];
|
|
411
487
|
decode(subData: string[]): {
|
|
@@ -484,6 +560,18 @@ export declare const morphoBlueLeverageManagementSubData: {
|
|
|
484
560
|
targetRatio: number;
|
|
485
561
|
};
|
|
486
562
|
};
|
|
563
|
+
export declare const morphoBlueLiquidationProtectionSubData: {
|
|
564
|
+
encode: (loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, ratioState: RatioState, targetRatio: number, user: EthereumAddress, isEOA: boolean) => string[];
|
|
565
|
+
decode: (subData: string[]) => {
|
|
566
|
+
loanToken: string;
|
|
567
|
+
collToken: string;
|
|
568
|
+
oracle: string;
|
|
569
|
+
irm: string;
|
|
570
|
+
lltv: string;
|
|
571
|
+
user: string;
|
|
572
|
+
targetRatio: number;
|
|
573
|
+
};
|
|
574
|
+
};
|
|
487
575
|
export declare const morphoBlueLeverageManagementOnPriceSubData: {
|
|
488
576
|
encode(loanToken: EthereumAddress, collToken: EthereumAddress, oracle: EthereumAddress, irm: EthereumAddress, lltv: string, targetRatio: number, user: EthereumAddress): string[];
|
|
489
577
|
decode(subData: string[]): {
|
|
@@ -525,3 +613,12 @@ export declare const fluidLeverageManagementSubData: {
|
|
|
525
613
|
targetRatio: number;
|
|
526
614
|
};
|
|
527
615
|
};
|
|
616
|
+
export declare const fluidLiquidationProtectionSubData: {
|
|
617
|
+
encode: (nftId: string, vault: EthereumAddress, ratioState: RatioState, targetRatio: number) => string[];
|
|
618
|
+
decode: (subData: string[]) => {
|
|
619
|
+
nftId: string;
|
|
620
|
+
vault: string;
|
|
621
|
+
ratioState: RatioState;
|
|
622
|
+
targetRatio: number;
|
|
623
|
+
};
|
|
624
|
+
};
|
|
@@ -125,6 +125,8 @@ export const makerLeverageManagementSubData = {
|
|
|
125
125
|
return { vaultId, targetRatio };
|
|
126
126
|
},
|
|
127
127
|
};
|
|
128
|
+
// ! Any change here will PROBABLY require a change in makerLiquidationProtectionSubData as well, since it is copy paste
|
|
129
|
+
// ! Double check before changing
|
|
128
130
|
export const makerLeverageManagementWithoutSubProxy = {
|
|
129
131
|
encode(vaultId, targetRatio, daiAddr) {
|
|
130
132
|
const encodedVaultId = AbiCoder.encodeParameter('uint256', vaultId);
|
|
@@ -139,6 +141,20 @@ export const makerLeverageManagementWithoutSubProxy = {
|
|
|
139
141
|
return { vaultId, targetRatio, daiAddr };
|
|
140
142
|
},
|
|
141
143
|
};
|
|
144
|
+
export const makerLiquidationProtectionSubData = {
|
|
145
|
+
encode(vaultId, targetRatio, daiAddr) {
|
|
146
|
+
const encodedVaultId = AbiCoder.encodeParameter('uint256', vaultId);
|
|
147
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
148
|
+
const encodedDaiAddr = AbiCoder.encodeParameter('address', daiAddr || getAssetInfo('DAI', 1).address);
|
|
149
|
+
return [encodedVaultId, encodedTargetRatio, encodedDaiAddr];
|
|
150
|
+
},
|
|
151
|
+
decode(subData) {
|
|
152
|
+
const vaultId = +AbiCoder.decodeParameter('uint256', subData[0]).toString();
|
|
153
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]));
|
|
154
|
+
const daiAddr = AbiCoder.decodeParameter('address', subData[2]).toString();
|
|
155
|
+
return { vaultId, targetRatio, daiAddr };
|
|
156
|
+
},
|
|
157
|
+
};
|
|
142
158
|
/**
|
|
143
159
|
__ __ ______ __ __ __ .___________.____ ____ ____ ____ __
|
|
144
160
|
| | | | / __ \ | | | | | | | |\ \ / / \ \ / / /_ |
|
|
@@ -161,6 +177,23 @@ export const liquityLeverageManagementSubData = {
|
|
|
161
177
|
return { targetRatio };
|
|
162
178
|
},
|
|
163
179
|
};
|
|
180
|
+
export const liquityLeverageManagementSubDataWithoutSubProxy = {
|
|
181
|
+
encode(targetRatio, ratioState) {
|
|
182
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
183
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
184
|
+
const isRepay = ratioState === RatioState.UNDER;
|
|
185
|
+
const collActionType = isRepay ? CollActionType.WITHDRAW : CollActionType.SUPPLY;
|
|
186
|
+
const debtActionType = isRepay ? DebtActionType.PAYBACK : DebtActionType.BORROW;
|
|
187
|
+
const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
|
|
188
|
+
const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
|
|
189
|
+
return [encodedRatioState, encodedTargetRatio, collActionTypeEncoded, debtActionTypeEncoded];
|
|
190
|
+
},
|
|
191
|
+
decode(subData) {
|
|
192
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[0]);
|
|
193
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]));
|
|
194
|
+
return { targetRatio, ratioState };
|
|
195
|
+
},
|
|
196
|
+
};
|
|
164
197
|
export const liquityCloseSubData = {
|
|
165
198
|
encode(closeToAssetAddr, chainId = ChainId.Ethereum, collAddr, debtAddr) {
|
|
166
199
|
const _collAddr = collAddr || getAssetInfo('WETH', chainId).address;
|
|
@@ -392,6 +425,25 @@ export const aaveV2LeverageManagementSubData = {
|
|
|
392
425
|
return { targetRatio };
|
|
393
426
|
},
|
|
394
427
|
};
|
|
428
|
+
export const aaveV2LeverageManagementSubDataWithoutSubProxy = {
|
|
429
|
+
encode(market, targetRatio, ratioState) {
|
|
430
|
+
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
431
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
432
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
433
|
+
const isBoost = ratioState === RatioState.OVER;
|
|
434
|
+
if (isBoost) {
|
|
435
|
+
const enableAsCollEncoded = AbiCoder.encodeParameter('uint256', 1);
|
|
436
|
+
return [encodedMarket, encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
|
|
437
|
+
}
|
|
438
|
+
return [encodedMarket, encodedTargetRatio, encodedRatioState];
|
|
439
|
+
},
|
|
440
|
+
decode(subData) {
|
|
441
|
+
const market = AbiCoder.decodeParameter('address', subData[0]);
|
|
442
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[1]));
|
|
443
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[2]);
|
|
444
|
+
return { market, targetRatio, ratioState };
|
|
445
|
+
},
|
|
446
|
+
};
|
|
395
447
|
/**
|
|
396
448
|
___ ___ ____ ____ _______ ____ ____ ____
|
|
397
449
|
/ \ / \ \ \ / / | ____| \ \ / / |___ \
|
|
@@ -407,6 +459,8 @@ export const aaveV3LeverageManagementSubData = {
|
|
|
407
459
|
return { targetRatio };
|
|
408
460
|
},
|
|
409
461
|
};
|
|
462
|
+
// ! Any change here will PROBABLY require a change in aaveV3LiquidationProtectionSubData as well
|
|
463
|
+
// ! Double check before changing. Liquidation protection is using Generic encoding for both - EOA and SW
|
|
410
464
|
export const aaveV3LeverageManagementSubDataWithoutSubProxy = {
|
|
411
465
|
encode(targetRatio, ratioState, market, user, isGeneric) {
|
|
412
466
|
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
@@ -426,6 +480,20 @@ export const aaveV3LeverageManagementSubDataWithoutSubProxy = {
|
|
|
426
480
|
return { targetRatio, ratioState };
|
|
427
481
|
},
|
|
428
482
|
};
|
|
483
|
+
export const aaveV3LiquidationProtectionSubData = {
|
|
484
|
+
encode(targetRatio, ratioState, market, user) {
|
|
485
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
486
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
487
|
+
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
488
|
+
const encodedUser = AbiCoder.encodeParameter('address', user);
|
|
489
|
+
return [encodedTargetRatio, encodedRatioState, encodedMarket, encodedUser];
|
|
490
|
+
},
|
|
491
|
+
decode(subData) {
|
|
492
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]));
|
|
493
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[1]);
|
|
494
|
+
return { targetRatio, ratioState };
|
|
495
|
+
},
|
|
496
|
+
};
|
|
429
497
|
export const aaveV3LeverageManagementOnPriceGeneric = {
|
|
430
498
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, marketAddr, targetRatio, user) {
|
|
431
499
|
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|
|
@@ -587,6 +655,8 @@ export const aaveV3LeverageManagementOnPriceSubData = {
|
|
|
587
655
|
/ _____ \ / _____ \ \ / | |____ \ / | |
|
|
588
656
|
/__/ \__\ /__/ \__\ \__/ |_______| \__/ |_|
|
|
589
657
|
*/
|
|
658
|
+
// ! Any change here will PROBABLY require a change in aaveV4LiquidationProtectionSubData as well, since it is copy paste
|
|
659
|
+
// ! Double check before changing
|
|
590
660
|
export const aaveV4LeverageManagementSubData = {
|
|
591
661
|
encode: (spoke, owner, ratioState, targetRatio) => {
|
|
592
662
|
const spokeEncoded = AbiCoder.encodeParameter('address', spoke);
|
|
@@ -613,6 +683,32 @@ export const aaveV4LeverageManagementSubData = {
|
|
|
613
683
|
};
|
|
614
684
|
},
|
|
615
685
|
};
|
|
686
|
+
export const aaveV4LiquidationProtectionSubData = {
|
|
687
|
+
encode: (spoke, owner, ratioState, targetRatio) => {
|
|
688
|
+
const spokeEncoded = AbiCoder.encodeParameter('address', spoke);
|
|
689
|
+
const ownerEncoded = AbiCoder.encodeParameter('address', owner);
|
|
690
|
+
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
691
|
+
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
692
|
+
// Add two empty slots for future addons (e.g tsi or slippage settings)
|
|
693
|
+
return [
|
|
694
|
+
spokeEncoded,
|
|
695
|
+
ownerEncoded,
|
|
696
|
+
ratioStateEncoded,
|
|
697
|
+
targetRatioEncoded,
|
|
698
|
+
EMPTY_SLOT,
|
|
699
|
+
EMPTY_SLOT,
|
|
700
|
+
];
|
|
701
|
+
},
|
|
702
|
+
decode: (subData) => {
|
|
703
|
+
const spoke = AbiCoder.decodeParameter('address', subData[0]);
|
|
704
|
+
const owner = AbiCoder.decodeParameter('address', subData[1]);
|
|
705
|
+
const ratioState = Number(AbiCoder.decodeParameter('uint8', subData[2]));
|
|
706
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[3]));
|
|
707
|
+
return {
|
|
708
|
+
spoke, owner, ratioState, targetRatio,
|
|
709
|
+
};
|
|
710
|
+
},
|
|
711
|
+
};
|
|
616
712
|
export const aaveV4LeverageManagementOnPriceSubData = {
|
|
617
713
|
encode: (spoke, owner, collAsset, collAssetId, debtAsset, debtAssetId, ratioState, targetRatio) => {
|
|
618
714
|
const spokeEncoded = AbiCoder.encodeParameter('address', spoke);
|
|
@@ -746,6 +842,23 @@ export const compoundV2LeverageManagementSubData = {
|
|
|
746
842
|
return { targetRatio };
|
|
747
843
|
},
|
|
748
844
|
};
|
|
845
|
+
export const compoundV2LeverageManagementSubDataWithoutSubProxy = {
|
|
846
|
+
encode(targetRatio, ratioState) {
|
|
847
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
848
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
849
|
+
const isBoost = ratioState === RatioState.OVER;
|
|
850
|
+
if (isBoost) {
|
|
851
|
+
const enableAsCollEncoded = AbiCoder.encodeParameter('uint256', 1);
|
|
852
|
+
return [encodedTargetRatio, encodedRatioState, enableAsCollEncoded];
|
|
853
|
+
}
|
|
854
|
+
return [encodedTargetRatio, encodedRatioState];
|
|
855
|
+
},
|
|
856
|
+
decode(subData) {
|
|
857
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]));
|
|
858
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[1]);
|
|
859
|
+
return { targetRatio, ratioState };
|
|
860
|
+
},
|
|
861
|
+
};
|
|
749
862
|
/**
|
|
750
863
|
______ ______ .___ ___. .______ ____ ____ ____
|
|
751
864
|
/ | / __ \ | \/ | | _ \ \ \ / / |___ \
|
|
@@ -754,6 +867,8 @@ export const compoundV2LeverageManagementSubData = {
|
|
|
754
867
|
| `----.| `--' | | | | | | | \ / ___) |
|
|
755
868
|
\______| \______/ |__| |__| | _| \__/ |____/
|
|
756
869
|
*/
|
|
870
|
+
// ! Any change here will PROBABLY require a change in compoundV3LiquidationProtectionSubData as well, since it is copy paste
|
|
871
|
+
// ! Double check before changing
|
|
757
872
|
export const compoundV3LeverageManagementSubData = {
|
|
758
873
|
encode(market, baseToken, triggerRepayRatio, triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
759
874
|
return [
|
|
@@ -773,8 +888,51 @@ export const compoundV3LeverageManagementSubData = {
|
|
|
773
888
|
return { targetRatio };
|
|
774
889
|
},
|
|
775
890
|
};
|
|
776
|
-
|
|
777
|
-
|
|
891
|
+
// ! Any change here will PROBABLY require a change in compoundV3L2LiquidationProtectionSubData as well, since it is copy paste
|
|
892
|
+
// ! Double check before changing
|
|
893
|
+
export const compoundV3LeverageManagementSubDataWithoutSubProxy = {
|
|
894
|
+
encode(market, baseToken, targetRatio, ratioState) {
|
|
895
|
+
const encodedMarket = AbiCoder.encodeParameter('address', market);
|
|
896
|
+
const encodedBaseToken = AbiCoder.encodeParameter('address', baseToken);
|
|
897
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
898
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
899
|
+
return [encodedMarket, encodedBaseToken, encodedRatioState, encodedTargetRatio];
|
|
900
|
+
},
|
|
901
|
+
decode(subData) {
|
|
902
|
+
const market = AbiCoder.decodeParameter('address', subData[0]);
|
|
903
|
+
const baseToken = AbiCoder.decodeParameter('address', subData[1]);
|
|
904
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[2]);
|
|
905
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[3]));
|
|
906
|
+
return {
|
|
907
|
+
market, baseToken, targetRatio, ratioState,
|
|
908
|
+
};
|
|
909
|
+
},
|
|
910
|
+
};
|
|
911
|
+
export const compoundV3LiquidationProtectionSubData = {
|
|
912
|
+
encode(market, baseToken, triggerRepayRatio,
|
|
913
|
+
// TODO -> can remove boost stuff ? Not sure if want it to be compatible or not.
|
|
914
|
+
triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
915
|
+
return [
|
|
916
|
+
market,
|
|
917
|
+
baseToken,
|
|
918
|
+
new Dec(triggerRepayRatio).mul(1e16).toString(),
|
|
919
|
+
new Dec(triggerBoostRatio).mul(1e16).toString(),
|
|
920
|
+
new Dec(targetBoostRatio).mul(1e16).toString(),
|
|
921
|
+
new Dec(targetRepayRatio).mul(1e16).toString(),
|
|
922
|
+
// @ts-ignore // TODO
|
|
923
|
+
boostEnabled, isEOA,
|
|
924
|
+
];
|
|
925
|
+
},
|
|
926
|
+
decode(subData) {
|
|
927
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]);
|
|
928
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
929
|
+
return { targetRatio };
|
|
930
|
+
},
|
|
931
|
+
};
|
|
932
|
+
export const compoundV3L2LiquidationProtectionSubData = {
|
|
933
|
+
encode(market, baseToken, triggerRepayRatio,
|
|
934
|
+
// TODO -> can remove boost stuff ? Not sure if want it to be compatible or not.
|
|
935
|
+
triggerBoostRatio, targetBoostRatio, targetRepayRatio, boostEnabled, isEOA) {
|
|
778
936
|
let subInput = '0x';
|
|
779
937
|
subInput = subInput.concat(market.slice(2));
|
|
780
938
|
subInput = subInput.concat(baseToken.slice(2));
|
|
@@ -899,6 +1057,21 @@ export const exchangeLimitOrderSubData = {
|
|
|
899
1057
|
return { fromToken, toToken, amount };
|
|
900
1058
|
},
|
|
901
1059
|
};
|
|
1060
|
+
export const exchangeLimitOrderSubDataWithoutSubProxy = {
|
|
1061
|
+
encode(fromToken, toToken, amount) {
|
|
1062
|
+
return [
|
|
1063
|
+
AbiCoder.encodeParameter('address', fromToken),
|
|
1064
|
+
AbiCoder.encodeParameter('address', toToken),
|
|
1065
|
+
AbiCoder.encodeParameter('uint256', amount),
|
|
1066
|
+
];
|
|
1067
|
+
},
|
|
1068
|
+
decode: (subData, chainId) => {
|
|
1069
|
+
const fromToken = AbiCoder.decodeParameter('address', subData[0]).toString();
|
|
1070
|
+
const toToken = AbiCoder.decodeParameter('address', subData[1]).toString();
|
|
1071
|
+
const amount = assetAmountInEth(AbiCoder.decodeParameter('uint256', subData[2]).toString(), getAssetInfoByAddress(fromToken, chainId).symbol);
|
|
1072
|
+
return { fromToken, toToken, amount };
|
|
1073
|
+
},
|
|
1074
|
+
};
|
|
902
1075
|
/**
|
|
903
1076
|
_______..______ ___ .______ __ ___
|
|
904
1077
|
/ || _ \ / \ | _ \ | |/ /
|
|
@@ -914,6 +1087,8 @@ export const sparkLeverageManagementSubData = {
|
|
|
914
1087
|
return { targetRatio };
|
|
915
1088
|
},
|
|
916
1089
|
};
|
|
1090
|
+
// ! Any change here will PROBABLY require a change in sparkLiquidationProtectionSubData as well, since it is copy paste
|
|
1091
|
+
// ! Double check before changing
|
|
917
1092
|
export const sparkLeverageManagementSubDataWithoutSubProxy = {
|
|
918
1093
|
encode(targetRatio, ratioState) {
|
|
919
1094
|
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
@@ -928,6 +1103,20 @@ export const sparkLeverageManagementSubDataWithoutSubProxy = {
|
|
|
928
1103
|
return { targetRatio, ratioState };
|
|
929
1104
|
},
|
|
930
1105
|
};
|
|
1106
|
+
export const sparkLiquidationProtectionSubData = {
|
|
1107
|
+
encode(targetRatio, ratioState) {
|
|
1108
|
+
const encodedTargetRatio = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1109
|
+
const encodedRatioState = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1110
|
+
const encodedUseDefaultMarket = AbiCoder.encodeParameter('bool', true);
|
|
1111
|
+
const encodedUseOnBehalf = AbiCoder.encodeParameter('bool', false);
|
|
1112
|
+
return [encodedTargetRatio, encodedRatioState, encodedUseDefaultMarket, encodedUseOnBehalf];
|
|
1113
|
+
},
|
|
1114
|
+
decode(subData) {
|
|
1115
|
+
const targetRatio = weiToRatioPercentage(AbiCoder.decodeParameter('uint256', subData[0]));
|
|
1116
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[1]);
|
|
1117
|
+
return { targetRatio, ratioState };
|
|
1118
|
+
},
|
|
1119
|
+
};
|
|
931
1120
|
export const sparkCloseGenericSubData = {
|
|
932
1121
|
encode(collAsset, collAssetId, debtAsset, debtAssetId, closeType, marketAddr, user) {
|
|
933
1122
|
const encodedColl = AbiCoder.encodeParameter('address', collAsset);
|
|
@@ -1076,6 +1265,8 @@ export const crvUSDPaybackSubData = {
|
|
|
1076
1265
|
| | | | | `--' | | |\ \----.| | | | | | | `--' |
|
|
1077
1266
|
|__| |__| \______/ | _| `._____|| _| |__| |__| \______/
|
|
1078
1267
|
*/
|
|
1268
|
+
// ! Any change here will PROBABLY require a change in morphoBlueLiquidationProtectionSubData as well, since it is copy paste
|
|
1269
|
+
// ! Double check before changing
|
|
1079
1270
|
export const morphoBlueLeverageManagementSubData = {
|
|
1080
1271
|
encode: (loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA) => {
|
|
1081
1272
|
const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
|
|
@@ -1109,6 +1300,39 @@ export const morphoBlueLeverageManagementSubData = {
|
|
|
1109
1300
|
};
|
|
1110
1301
|
},
|
|
1111
1302
|
};
|
|
1303
|
+
export const morphoBlueLiquidationProtectionSubData = {
|
|
1304
|
+
encode: (loanToken, collToken, oracle, irm, lltv, ratioState, targetRatio, user, isEOA) => {
|
|
1305
|
+
const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
|
|
1306
|
+
const collTokenEncoded = AbiCoder.encodeParameter('address', collToken);
|
|
1307
|
+
const oracleEncoded = AbiCoder.encodeParameter('address', oracle);
|
|
1308
|
+
const irmEncoded = AbiCoder.encodeParameter('address', irm);
|
|
1309
|
+
const lltvEncoded = AbiCoder.encodeParameter('uint256', lltv);
|
|
1310
|
+
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1311
|
+
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1312
|
+
const userEncoded = AbiCoder.encodeParameter('address', user);
|
|
1313
|
+
const isEOAEncoded = AbiCoder.encodeParameter('bool', isEOA);
|
|
1314
|
+
return [loanTokenEncoded, collTokenEncoded, oracleEncoded, irmEncoded, lltvEncoded, ratioStateEncoded, targetRatioEncoded, userEncoded, isEOAEncoded];
|
|
1315
|
+
},
|
|
1316
|
+
decode: (subData) => {
|
|
1317
|
+
const loanToken = AbiCoder.decodeParameter('address', subData[0]);
|
|
1318
|
+
const collToken = AbiCoder.decodeParameter('address', subData[1]);
|
|
1319
|
+
const oracle = AbiCoder.decodeParameter('address', subData[2]);
|
|
1320
|
+
const irm = AbiCoder.decodeParameter('address', subData[3]);
|
|
1321
|
+
const lltv = AbiCoder.decodeParameter('uint256', subData[4]);
|
|
1322
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[6]);
|
|
1323
|
+
const user = AbiCoder.decodeParameter('address', subData[7]);
|
|
1324
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
1325
|
+
return {
|
|
1326
|
+
loanToken,
|
|
1327
|
+
collToken,
|
|
1328
|
+
oracle,
|
|
1329
|
+
irm,
|
|
1330
|
+
lltv,
|
|
1331
|
+
user,
|
|
1332
|
+
targetRatio,
|
|
1333
|
+
};
|
|
1334
|
+
},
|
|
1335
|
+
};
|
|
1112
1336
|
export const morphoBlueLeverageManagementOnPriceSubData = {
|
|
1113
1337
|
encode(loanToken, collToken, oracle, irm, lltv, targetRatio, user) {
|
|
1114
1338
|
const loanTokenEncoded = AbiCoder.encodeParameter('address', loanToken);
|
|
@@ -1178,6 +1402,8 @@ _______ __ __ __ __ _______
|
|
|
1178
1402
|
| | | `----.| `--' | | | | '--' |
|
|
1179
1403
|
|__| |_______| \______/ |__| |_______/
|
|
1180
1404
|
*/
|
|
1405
|
+
// ! Any change here will PROBABLY require a change in fluidLeverageManagementSubData as well, since it is copy paste
|
|
1406
|
+
// ! Double check before changing
|
|
1181
1407
|
export const fluidLeverageManagementSubData = {
|
|
1182
1408
|
encode: (nftId, vault, ratioState, targetRatio) => {
|
|
1183
1409
|
const nftIdEncoded = AbiCoder.encodeParameter('uint256', nftId);
|
|
@@ -1185,9 +1411,40 @@ export const fluidLeverageManagementSubData = {
|
|
|
1185
1411
|
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1186
1412
|
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1187
1413
|
const wrapEthEncoded = AbiCoder.encodeParameter('bool', true);
|
|
1188
|
-
const
|
|
1189
|
-
const
|
|
1190
|
-
const
|
|
1414
|
+
const collActionType = CollActionType.WITHDRAW;
|
|
1415
|
+
const debtActionType = DebtActionType.PAYBACK;
|
|
1416
|
+
const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
|
|
1417
|
+
const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
|
|
1418
|
+
return [
|
|
1419
|
+
nftIdEncoded,
|
|
1420
|
+
vaultEncoded,
|
|
1421
|
+
ratioStateEncoded,
|
|
1422
|
+
targetRatioEncoded,
|
|
1423
|
+
wrapEthEncoded,
|
|
1424
|
+
collActionTypeEncoded,
|
|
1425
|
+
debtActionTypeEncoded,
|
|
1426
|
+
];
|
|
1427
|
+
},
|
|
1428
|
+
decode: (subData) => {
|
|
1429
|
+
const nftId = AbiCoder.decodeParameter('uint256', subData[0]);
|
|
1430
|
+
const vault = AbiCoder.decodeParameter('address', subData[1]);
|
|
1431
|
+
const ratioState = AbiCoder.decodeParameter('uint8', subData[2]);
|
|
1432
|
+
const weiRatio = AbiCoder.decodeParameter('uint256', subData[3]);
|
|
1433
|
+
const targetRatio = weiToRatioPercentage(weiRatio);
|
|
1434
|
+
return {
|
|
1435
|
+
nftId, vault, ratioState, targetRatio,
|
|
1436
|
+
};
|
|
1437
|
+
},
|
|
1438
|
+
};
|
|
1439
|
+
export const fluidLiquidationProtectionSubData = {
|
|
1440
|
+
encode: (nftId, vault, ratioState, targetRatio) => {
|
|
1441
|
+
const nftIdEncoded = AbiCoder.encodeParameter('uint256', nftId);
|
|
1442
|
+
const vaultEncoded = AbiCoder.encodeParameter('address', vault);
|
|
1443
|
+
const ratioStateEncoded = AbiCoder.encodeParameter('uint8', ratioState);
|
|
1444
|
+
const targetRatioEncoded = AbiCoder.encodeParameter('uint256', ratioPercentageToWei(targetRatio));
|
|
1445
|
+
const wrapEthEncoded = AbiCoder.encodeParameter('bool', true);
|
|
1446
|
+
const collActionType = CollActionType.WITHDRAW;
|
|
1447
|
+
const debtActionType = DebtActionType.PAYBACK;
|
|
1191
1448
|
const collActionTypeEncoded = AbiCoder.encodeParameter('uint8', collActionType);
|
|
1192
1449
|
const debtActionTypeEncoded = AbiCoder.encodeParameter('uint8', debtActionType);
|
|
1193
1450
|
return [
|
|
@@ -1309,48 +1309,6 @@ describe('Feature: subDataService.ts', () => {
|
|
|
1309
1309
|
});
|
|
1310
1310
|
});
|
|
1311
1311
|
});
|
|
1312
|
-
describe('When testing subDataService.compoundV3L2LeverageManagementSubData', () => {
|
|
1313
|
-
describe('encode()', () => {
|
|
1314
|
-
const examples = [
|
|
1315
|
-
[
|
|
1316
|
-
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0213D212133AfaB8F2b829B1066C7E43cAD94E2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000001a5e27eef13e00000100',
|
|
1317
|
-
[web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0213d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 190, true, false]
|
|
1318
|
-
],
|
|
1319
|
-
[
|
|
1320
|
-
'0x0313D212133AFab8F2b829B1066c7e43caD94e2c0413d212133afAb8F2B829b1066C7e43cAd94e2c000000000000000016345785d8a0000000000000000000001e87f85809dc0000000000000000000018fae27693b4000000000000000000000f43fc2c04ee00000000',
|
|
1321
|
-
[web3Utils.toChecksumAddress('0x0313d212133AFaB8F2B829B1066c7E43cAd94E2c'), web3Utils.toChecksumAddress('0x0413d212133AFaB8F2B829B1066c7E43cAd94E2c'), 160, 220, 180, 110, false, false]
|
|
1322
|
-
],
|
|
1323
|
-
];
|
|
1324
|
-
examples.forEach(([expected, actual]) => {
|
|
1325
|
-
it(`Given ${actual} should return expected value: ${expected}`, () => {
|
|
1326
|
-
expect(subDataService.compoundV3L2LeverageManagementSubData.encode(...actual)).to.eql(expected);
|
|
1327
|
-
});
|
|
1328
|
-
});
|
|
1329
|
-
});
|
|
1330
|
-
describe('decode()', () => {
|
|
1331
|
-
const examples = [
|
|
1332
|
-
[
|
|
1333
|
-
{ targetRatio: 200 },
|
|
1334
|
-
[
|
|
1335
|
-
'0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000213d212133AFaB8F2B829B1066c7E43cAd94E2c',
|
|
1336
|
-
'0x0000000000000000000000000000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000000000000001bc16d674ec80000',
|
|
1337
|
-
],
|
|
1338
|
-
],
|
|
1339
|
-
[
|
|
1340
|
-
{ targetRatio: 123 },
|
|
1341
|
-
[
|
|
1342
|
-
'0x0000000000000000000000000313d212133AFaB8F2B829B1066c7E43cAd94E2c', '0x0000000000000000000000000413d212133AFaB8F2B829B1066c7E43cAd94E2c',
|
|
1343
|
-
'0x0000000000000000000000000000000000000000000000000000000000000000', '0x0000000000000000000000000000000000000000000000001111d67bb1bb0000',
|
|
1344
|
-
],
|
|
1345
|
-
],
|
|
1346
|
-
];
|
|
1347
|
-
examples.forEach(([expected, actual]) => {
|
|
1348
|
-
it(`Given ${actual} should return expected value: ${JSON.stringify(expected)}`, () => {
|
|
1349
|
-
expect(subDataService.compoundV3L2LeverageManagementSubData.decode(actual)).to.eql(expected);
|
|
1350
|
-
});
|
|
1351
|
-
});
|
|
1352
|
-
});
|
|
1353
|
-
});
|
|
1354
1312
|
describe('When testing subDataService.morphoBlueLeverageManagementSubData', () => {
|
|
1355
1313
|
describe('encode()', () => {
|
|
1356
1314
|
const examples = [
|
package/esm/services/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EthereumAddress } from '../types';
|
|
2
|
-
import { ChainId, CloseStrategyType, CloseToAssetType, RatioState } from '../types/enums';
|
|
2
|
+
import { Bundles, ChainId, CloseStrategyType, CloseToAssetType, RatioState } from '../types/enums';
|
|
3
3
|
export declare function isDefined<T>(value: T): value is NonNullable<T>;
|
|
4
4
|
export declare function isUndefined(value: unknown): boolean;
|
|
5
5
|
export declare function compareAddresses(firstAddress: EthereumAddress, secondAddress: EthereumAddress): boolean;
|
|
@@ -28,3 +28,5 @@ export declare function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStr
|
|
|
28
28
|
stopLossType: CloseToAssetType | undefined;
|
|
29
29
|
takeProfitType: CloseToAssetType | undefined;
|
|
30
30
|
};
|
|
31
|
+
export declare function getBundleIdsByNetwork(network: ChainId): typeof Bundles.MainnetIds | typeof Bundles.OptimismIds | typeof Bundles.ArbitrumIds | typeof Bundles.BaseIds;
|
|
32
|
+
export declare function getCompoundV3LeverageManagementBundleId(network: ChainId, isEOA: boolean, isBoost: boolean): number;
|
package/esm/services/utils.js
CHANGED
|
@@ -2,7 +2,7 @@ import Dec from 'decimal.js';
|
|
|
2
2
|
import * as web3Utils from 'web3-utils';
|
|
3
3
|
import AbiCoder from 'web3-eth-abi';
|
|
4
4
|
import { getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
|
|
5
|
-
import { ChainId, CloseStrategyType, CloseToAssetType, RatioState, } from '../types/enums';
|
|
5
|
+
import { Bundles, ChainId, CloseStrategyType, CloseToAssetType, RatioState, } from '../types/enums';
|
|
6
6
|
export function isDefined(value) {
|
|
7
7
|
return value !== undefined && value !== null;
|
|
8
8
|
}
|
|
@@ -137,3 +137,34 @@ export function getStopLossAndTakeProfitTypeByCloseStrategyType(closeStrategyTyp
|
|
|
137
137
|
throw new Error('CloseStrategyType not supported');
|
|
138
138
|
}
|
|
139
139
|
}
|
|
140
|
+
export function getBundleIdsByNetwork(network) {
|
|
141
|
+
switch (network) {
|
|
142
|
+
case ChainId.Arbitrum:
|
|
143
|
+
return Bundles.ArbitrumIds;
|
|
144
|
+
case ChainId.Base:
|
|
145
|
+
return Bundles.BaseIds;
|
|
146
|
+
case ChainId.Optimism:
|
|
147
|
+
return Bundles.OptimismIds;
|
|
148
|
+
default:
|
|
149
|
+
return Bundles.MainnetIds;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
// Mainnet uses the V2 bundle ids; L2s use the original bundle ids.
|
|
153
|
+
export function getCompoundV3LeverageManagementBundleId(network, isEOA, isBoost) {
|
|
154
|
+
switch (Number(network)) {
|
|
155
|
+
case ChainId.Ethereum:
|
|
156
|
+
if (isEOA)
|
|
157
|
+
return isBoost ? Bundles.MainnetIds.COMP_V3_EOA_BOOST_V2_BUNDLE : Bundles.MainnetIds.COMP_V3_EOA_REPAY_V2_BUNDLE;
|
|
158
|
+
return isBoost ? Bundles.MainnetIds.COMP_V3_SW_BOOST_V2_BUNDLE : Bundles.MainnetIds.COMP_V3_SW_REPAY_V2_BUNDLE;
|
|
159
|
+
case ChainId.Base:
|
|
160
|
+
if (isEOA)
|
|
161
|
+
return isBoost ? Bundles.BaseIds.COMP_V3_EOA_BOOST : Bundles.BaseIds.COMP_V3_EOA_REPAY;
|
|
162
|
+
return isBoost ? Bundles.BaseIds.COMP_V3_SW_BOOST_BUNDLE : Bundles.BaseIds.COMP_V3_SW_REPAY_BUNDLE;
|
|
163
|
+
case ChainId.Arbitrum:
|
|
164
|
+
if (isEOA)
|
|
165
|
+
return isBoost ? Bundles.ArbitrumIds.COMP_V3_EOA_BOOST : Bundles.ArbitrumIds.COMP_V3_EOA_REPAY;
|
|
166
|
+
return isBoost ? Bundles.ArbitrumIds.COMP_V3_SW_BOOST_BUNDLE : Bundles.ArbitrumIds.COMP_V3_SW_REPAY_BUNDLE;
|
|
167
|
+
default:
|
|
168
|
+
throw new Error(`Compound V3 leverage management is not supported on network ${network}`);
|
|
169
|
+
}
|
|
170
|
+
}
|