@curvefi/llamalend-api 2.0.28 → 2.1.1
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/lib/constants/aliases.js +10 -7
- package/lib/lendMarkets/modules/common/leverageZapV1Base.js +16 -16
- package/lib/lendMarkets/modules/common/leverageZapV2Base.d.ts +12 -2
- package/lib/lendMarkets/modules/common/leverageZapV2Base.js +25 -48
- package/lib/lendMarkets/modules/v1/leverageV1ZapV2.d.ts +11 -0
- package/lib/lendMarkets/modules/v1/leverageV1ZapV2.js +78 -0
- package/lib/lendMarkets/modules/v2/leverageV2ZapV2.d.ts +11 -0
- package/lib/lendMarkets/modules/v2/leverageV2ZapV2.js +112 -0
- package/lib/llamalend.js +2 -1
- package/lib/mintMarkets/MintMarketTemplate.js +1 -0
- package/lib/mintMarkets/fetch/fetchMintMarkets.js +1 -1
- package/lib/utils.d.ts +14 -0
- package/lib/utils.js +9 -0
- package/package.json +1 -1
- package/src/constants/aliases.ts +10 -7
- package/src/lendMarkets/modules/common/leverageZapV1Base.ts +16 -16
- package/src/lendMarkets/modules/common/leverageZapV2Base.ts +81 -95
- package/src/lendMarkets/modules/v1/leverageV1ZapV2.ts +154 -1
- package/src/lendMarkets/modules/v2/leverageV2ZapV2.ts +200 -1
- package/src/llamalend.ts +3 -1
- package/src/mintMarkets/MintMarketTemplate.ts +1 -0
- package/src/mintMarkets/fetch/fetchMintMarkets.ts +1 -1
- package/src/utils.ts +31 -1
package/lib/constants/aliases.js
CHANGED
|
@@ -5,9 +5,9 @@ export const ALIASES_ETHEREUM = lowerCaseValues({
|
|
|
5
5
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
6
6
|
"minter": '0xd061D61a4d941c39E5453435B6345Dc261C2fcE0',
|
|
7
7
|
"gauge_factory": "0xabC000d88f23Bb45525E447528DBF656A9D55bf5",
|
|
8
|
-
|
|
9
|
-
"leverage_zap": "0xC8E8430dc7Cb23C32543329acCC68c9055C23e18", // odos v3
|
|
8
|
+
"leverage_zap_deprecated": "0xC8E8430dc7Cb23C32543329acCC68c9055C23e18", // odos v3
|
|
10
9
|
"leverage_zap_v2": "0x324c5f9F7A3015D91860aC6870dcE25d410Df3Dc",
|
|
10
|
+
"leverage_zap_v2_llv2": "0x0F7C08E209ef1C3bE725c2584BCed4877095D680",
|
|
11
11
|
"leverage_markets_start_id": "9",
|
|
12
12
|
"crvUSD": "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
|
|
13
13
|
"st_crvUSD": "0x0655977FEb2f289A4aB78af67BAB0d17aAb84367",
|
|
@@ -17,9 +17,9 @@ export const ALIASES_ARBITRUM = lowerCaseValues({
|
|
|
17
17
|
"one_way_factory": "0xcaEC110C784c9DF37240a8Ce096D352A75922DeA",
|
|
18
18
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
19
19
|
"gauge_factory": "0xabC000d88f23Bb45525E447528DBF656A9D55bf5",
|
|
20
|
-
|
|
21
|
-
"leverage_zap": "0xFE02553d3Ba4c3f39F36a4632F91404DF94b9AE2", // odos v3
|
|
20
|
+
"leverage_zap_deprecated": "0xFE02553d3Ba4c3f39F36a4632F91404DF94b9AE2", // odos v3
|
|
22
21
|
"leverage_zap_v2": "0x9577086c6E38d38359872F903Da201f1bdCc0323",
|
|
22
|
+
"leverage_zap_v2_llv2": "0x0F7C08E209ef1C3bE725c2584BCed4877095D680",
|
|
23
23
|
"leverage_markets_start_id": "9",
|
|
24
24
|
});
|
|
25
25
|
export const ALIASES_OPTIMISM = lowerCaseValues({
|
|
@@ -30,8 +30,9 @@ export const ALIASES_OPTIMISM = lowerCaseValues({
|
|
|
30
30
|
"gauge_factory_old": "0xabC000d88f23Bb45525E447528DBF656A9D55bf5",
|
|
31
31
|
"gauge_factory": "0x871fBD4E01012e2E8457346059e8C189d664DbA4",
|
|
32
32
|
"old_gauge_end_index": "4",
|
|
33
|
-
"
|
|
33
|
+
"leverage_zap_deprecated": "0xBFab8ebc836E1c4D81837798FC076D219C9a1855", // odos v3
|
|
34
34
|
"leverage_zap_v2": "0xE94d1fBF399c27CCBf0185b2Dd11Bf0FA0f0D95C",
|
|
35
|
+
"leverage_zap_v2_llv2": "0xcfd71a5BC9c2215ca8878C1083EC9a3CE1F0fdEb",
|
|
35
36
|
"leverage_markets_start_id": "0",
|
|
36
37
|
"gas_oracle": '0xc0d3C0d3C0d3c0D3C0D3C0d3C0d3C0D3C0D3000f',
|
|
37
38
|
"gas_oracle_blob": '0x420000000000000000000000000000000000000f',
|
|
@@ -43,8 +44,9 @@ export const ALIASES_FRAXTAL = lowerCaseValues({
|
|
|
43
44
|
"gauge_factory_old": "0xeF672bD94913CB6f1d2812a6e18c1fFdEd8eFf5c",
|
|
44
45
|
"gauge_factory": "0x0b8d6b6cefc7aa1c2852442e518443b1b22e1c52",
|
|
45
46
|
"old_gauge_end_index": "3",
|
|
46
|
-
"
|
|
47
|
+
"leverage_zap_deprecated": "0x3294514B78Df4Bb90132567fcf8E5e99f390B687", // odos v3
|
|
47
48
|
"leverage_zap_v2": "0x16C6521Dff6baB339122a0FE25a9116693265353",
|
|
49
|
+
"leverage_zap_v2_llv2": "0x0F7C08E209ef1C3bE725c2584BCed4877095D680",
|
|
48
50
|
"leverage_markets_start_id": "0",
|
|
49
51
|
});
|
|
50
52
|
export const ALIASES_SONIC = lowerCaseValues({
|
|
@@ -52,7 +54,8 @@ export const ALIASES_SONIC = lowerCaseValues({
|
|
|
52
54
|
"one_way_factory": "0x30d1859dad5a52ae03b6e259d1b48c4b12933993",
|
|
53
55
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
54
56
|
"gauge_factory": "0xf3A431008396df8A8b2DF492C913706BDB0874ef",
|
|
55
|
-
"
|
|
57
|
+
"leverage_zap_deprecated": "0x0fE38dCC905eC14F6099a83Ac5C93BF2601300CF", // odos v3
|
|
56
58
|
"leverage_zap_v2": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4",
|
|
59
|
+
"leverage_zap_v2_llv2": "0x0F7C08E209ef1C3bE725c2584BCed4877095D680",
|
|
57
60
|
"leverage_markets_start_id": "0",
|
|
58
61
|
});
|
|
@@ -19,13 +19,13 @@ export class LeverageZapV1BaseModule {
|
|
|
19
19
|
this._getMarketId = () => Number(this.market.id.split("-").slice(-1)[0]);
|
|
20
20
|
// ============ CREATE LOAN METHODS ============
|
|
21
21
|
this.hasLeverage = () => {
|
|
22
|
-
return this.llamalend.constants.ALIASES.
|
|
22
|
+
return this.llamalend.constants.ALIASES.leverage_zap_deprecated !== this.llamalend.constants.ZERO_ADDRESS &&
|
|
23
23
|
this._getMarketId() >= Number(this.llamalend.constants.ALIASES["leverage_markets_start_id"]);
|
|
24
24
|
};
|
|
25
25
|
this.leverageCreateLoanMaxRecvAllRanges = memoize((userCollateral, userBorrowed) => __awaiter(this, void 0, void 0, function* () {
|
|
26
26
|
this._checkLeverageZap();
|
|
27
27
|
const _userCollateral = parseUnits(userCollateral, this.market.collateral_token.decimals);
|
|
28
|
-
const contract = this.llamalend.contracts[this.llamalend.constants.ALIASES.
|
|
28
|
+
const contract = this.llamalend.contracts[this.llamalend.constants.ALIASES.leverage_zap_deprecated].multicallContract;
|
|
29
29
|
const oraclePriceBand = yield this.market.prices.oraclePriceBand();
|
|
30
30
|
const pAvgApproxBN = BN(yield this.market.prices.calcTickPrice(oraclePriceBand)); // upper tick of oracle price band
|
|
31
31
|
let pAvgBN = null;
|
|
@@ -246,7 +246,7 @@ export class LeverageZapV1BaseModule {
|
|
|
246
246
|
let maxBorrowableBN = BN(0);
|
|
247
247
|
let _userEffectiveCollateral = BigInt(0);
|
|
248
248
|
let _maxLeverageCollateral = BigInt(0);
|
|
249
|
-
const contract = this.llamalend.contracts[this.llamalend.constants.ALIASES.
|
|
249
|
+
const contract = this.llamalend.contracts[this.llamalend.constants.ALIASES.leverage_zap_deprecated].contract;
|
|
250
250
|
for (let i = 0; i < 5; i++) {
|
|
251
251
|
maxBorrowablePrevBN = maxBorrowableBN;
|
|
252
252
|
_userEffectiveCollateral = _userCollateral + fromBN(BN(userBorrowed).div(pAvgBN), this.market.collateral_token.decimals);
|
|
@@ -414,7 +414,7 @@ export class LeverageZapV1BaseModule {
|
|
|
414
414
|
return __awaiter(this, void 0, void 0, function* () {
|
|
415
415
|
this._checkLeverageZap();
|
|
416
416
|
const collateralAllowance = yield hasAllowance.call(this.llamalend, [this.market.collateral_token.address], [userCollateral], this.llamalend.signerAddress, this.market.addresses.controller);
|
|
417
|
-
const borrowedAllowance = yield hasAllowance.call(this.llamalend, [this.market.borrowed_token.address], [userBorrowed], this.llamalend.signerAddress, this.llamalend.constants.ALIASES.
|
|
417
|
+
const borrowedAllowance = yield hasAllowance.call(this.llamalend, [this.market.borrowed_token.address], [userBorrowed], this.llamalend.signerAddress, this.llamalend.constants.ALIASES.leverage_zap_deprecated);
|
|
418
418
|
return collateralAllowance && borrowedAllowance;
|
|
419
419
|
});
|
|
420
420
|
}
|
|
@@ -422,7 +422,7 @@ export class LeverageZapV1BaseModule {
|
|
|
422
422
|
return __awaiter(this, void 0, void 0, function* () {
|
|
423
423
|
this._checkLeverageZap();
|
|
424
424
|
const collateralGas = yield ensureAllowanceEstimateGas.call(this.llamalend, [this.market.collateral_token.address], [userCollateral], this.market.addresses.controller);
|
|
425
|
-
const borrowedGas = yield ensureAllowanceEstimateGas.call(this.llamalend, [this.market.borrowed_token.address], [userBorrowed], this.llamalend.constants.ALIASES.
|
|
425
|
+
const borrowedGas = yield ensureAllowanceEstimateGas.call(this.llamalend, [this.market.borrowed_token.address], [userBorrowed], this.llamalend.constants.ALIASES.leverage_zap_deprecated);
|
|
426
426
|
if (Array.isArray(collateralGas) && Array.isArray(borrowedGas)) {
|
|
427
427
|
return [collateralGas[0] + borrowedGas[0], collateralGas[1] + borrowedGas[1]];
|
|
428
428
|
}
|
|
@@ -435,7 +435,7 @@ export class LeverageZapV1BaseModule {
|
|
|
435
435
|
return __awaiter(this, void 0, void 0, function* () {
|
|
436
436
|
this._checkLeverageZap();
|
|
437
437
|
const collateralApproveTx = yield ensureAllowance.call(this.llamalend, [this.market.collateral_token.address], [userCollateral], this.market.addresses.controller);
|
|
438
|
-
const borrowedApproveTx = yield ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [userBorrowed], this.llamalend.constants.ALIASES.
|
|
438
|
+
const borrowedApproveTx = yield ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [userBorrowed], this.llamalend.constants.ALIASES.leverage_zap_deprecated);
|
|
439
439
|
return [...collateralApproveTx, ...borrowedApproveTx];
|
|
440
440
|
});
|
|
441
441
|
}
|
|
@@ -460,12 +460,12 @@ export class LeverageZapV1BaseModule {
|
|
|
460
460
|
throw Error(`You must call leverage.createLoanExpectedCollateral() with slippage=${slippage} first`);
|
|
461
461
|
const calldata = yield _assembleTxOdos.call(this.llamalend, swapData.pathId);
|
|
462
462
|
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
463
|
-
const gas = yield contract.create_loan_extended.estimateGas(_userCollateral, _debt, range, this.llamalend.constants.ALIASES.
|
|
463
|
+
const gas = yield contract.create_loan_extended.estimateGas(_userCollateral, _debt, range, this.llamalend.constants.ALIASES.leverage_zap_deprecated, [0, parseUnits(this._getMarketId(), 0), _userBorrowed], calldata, Object.assign({}, this.llamalend.constantOptions));
|
|
464
464
|
if (estimateGas)
|
|
465
465
|
return smartNumber(gas);
|
|
466
466
|
yield this.llamalend.updateFeeData();
|
|
467
467
|
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
468
|
-
return (yield contract.create_loan_extended(_userCollateral, _debt, range, this.llamalend.constants.ALIASES.
|
|
468
|
+
return (yield contract.create_loan_extended(_userCollateral, _debt, range, this.llamalend.constants.ALIASES.leverage_zap_deprecated, [0, parseUnits(this._getMarketId(), 0), _userBorrowed], calldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
469
469
|
});
|
|
470
470
|
}
|
|
471
471
|
leverageCreateLoanEstimateGas(userCollateral_1, userBorrowed_1, debt_1, range_1) {
|
|
@@ -503,7 +503,7 @@ export class LeverageZapV1BaseModule {
|
|
|
503
503
|
let maxBorrowableBN = BN(0);
|
|
504
504
|
let _userEffectiveCollateral = BigInt(0);
|
|
505
505
|
let _maxLeverageCollateral = BigInt(0);
|
|
506
|
-
const contract = this.llamalend.contracts[this.llamalend.constants.ALIASES.
|
|
506
|
+
const contract = this.llamalend.contracts[this.llamalend.constants.ALIASES.leverage_zap_deprecated].contract;
|
|
507
507
|
for (let i = 0; i < 5; i++) {
|
|
508
508
|
maxBorrowablePrevBN = maxBorrowableBN;
|
|
509
509
|
_userEffectiveCollateral = _userCollateral + fromBN(BN(userBorrowed).div(pAvgBN), this.market.collateral_token.decimals);
|
|
@@ -604,12 +604,12 @@ export class LeverageZapV1BaseModule {
|
|
|
604
604
|
throw Error(`You must call leverage.borrowMoreExpectedCollateral() with slippage=${slippage} first`);
|
|
605
605
|
const calldata = yield _assembleTxOdos.call(this.llamalend, swapData.pathId);
|
|
606
606
|
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
607
|
-
const gas = yield contract.borrow_more_extended.estimateGas(_userCollateral, _debt, this.llamalend.constants.ALIASES.
|
|
607
|
+
const gas = yield contract.borrow_more_extended.estimateGas(_userCollateral, _debt, this.llamalend.constants.ALIASES.leverage_zap_deprecated, [0, parseUnits(this._getMarketId(), 0), _userBorrowed], calldata, Object.assign({}, this.llamalend.constantOptions));
|
|
608
608
|
if (estimateGas)
|
|
609
609
|
return smartNumber(gas);
|
|
610
610
|
yield this.llamalend.updateFeeData();
|
|
611
611
|
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
612
|
-
return (yield contract.borrow_more_extended(_userCollateral, _debt, this.llamalend.constants.ALIASES.
|
|
612
|
+
return (yield contract.borrow_more_extended(_userCollateral, _debt, this.llamalend.constants.ALIASES.leverage_zap_deprecated, [0, parseUnits(this._getMarketId(), 0), _userBorrowed], calldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
613
613
|
});
|
|
614
614
|
}
|
|
615
615
|
leverageBorrowMoreEstimateGas(userCollateral_1, userBorrowed_1, debt_1) {
|
|
@@ -718,19 +718,19 @@ export class LeverageZapV1BaseModule {
|
|
|
718
718
|
leverageRepayIsApproved(userCollateral, userBorrowed) {
|
|
719
719
|
return __awaiter(this, void 0, void 0, function* () {
|
|
720
720
|
this._checkLeverageZap();
|
|
721
|
-
return yield hasAllowance.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address], [userCollateral, userBorrowed], this.llamalend.signerAddress, this.llamalend.constants.ALIASES.
|
|
721
|
+
return yield hasAllowance.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address], [userCollateral, userBorrowed], this.llamalend.signerAddress, this.llamalend.constants.ALIASES.leverage_zap_deprecated);
|
|
722
722
|
});
|
|
723
723
|
}
|
|
724
724
|
leverageRepayApproveEstimateGas(userCollateral, userBorrowed) {
|
|
725
725
|
return __awaiter(this, void 0, void 0, function* () {
|
|
726
726
|
this._checkLeverageZap();
|
|
727
|
-
return yield ensureAllowanceEstimateGas.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address], [userCollateral, userBorrowed], this.llamalend.constants.ALIASES.
|
|
727
|
+
return yield ensureAllowanceEstimateGas.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address], [userCollateral, userBorrowed], this.llamalend.constants.ALIASES.leverage_zap_deprecated);
|
|
728
728
|
});
|
|
729
729
|
}
|
|
730
730
|
leverageRepayApprove(userCollateral, userBorrowed) {
|
|
731
731
|
return __awaiter(this, void 0, void 0, function* () {
|
|
732
732
|
this._checkLeverageZap();
|
|
733
|
-
return yield ensureAllowance.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address], [userCollateral, userBorrowed], this.llamalend.constants.ALIASES.
|
|
733
|
+
return yield ensureAllowance.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address], [userCollateral, userBorrowed], this.llamalend.constants.ALIASES.leverage_zap_deprecated);
|
|
734
734
|
});
|
|
735
735
|
}
|
|
736
736
|
leverageRepayRouteImage(stateCollateral, userCollateral) {
|
|
@@ -756,12 +756,12 @@ export class LeverageZapV1BaseModule {
|
|
|
756
756
|
calldata = yield _assembleTxOdos.call(this.llamalend, swapData.pathId);
|
|
757
757
|
}
|
|
758
758
|
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
759
|
-
const gas = yield contract.repay_extended.estimateGas(this.llamalend.constants.ALIASES.
|
|
759
|
+
const gas = yield contract.repay_extended.estimateGas(this.llamalend.constants.ALIASES.leverage_zap_deprecated, [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed], calldata);
|
|
760
760
|
if (estimateGas)
|
|
761
761
|
return smartNumber(gas);
|
|
762
762
|
yield this.llamalend.updateFeeData();
|
|
763
763
|
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
764
|
-
return (yield contract.repay_extended(this.llamalend.constants.ALIASES.
|
|
764
|
+
return (yield contract.repay_extended(this.llamalend.constants.ALIASES.leverage_zap_deprecated, [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed], calldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
765
765
|
});
|
|
766
766
|
}
|
|
767
767
|
leverageRepayEstimateGas(stateCollateral_1, userCollateral_1, userBorrowed_1) {
|
|
@@ -10,11 +10,21 @@ import BigNumber from "bignumber.js";
|
|
|
10
10
|
* - prices
|
|
11
11
|
* - userPosition
|
|
12
12
|
*/
|
|
13
|
-
export declare class LeverageZapV2BaseModule {
|
|
13
|
+
export declare abstract class LeverageZapV2BaseModule {
|
|
14
14
|
protected market: LendMarketTemplate;
|
|
15
15
|
protected llamalend: Llamalend;
|
|
16
16
|
constructor(market: LendMarketTemplate);
|
|
17
|
-
|
|
17
|
+
protected abstract _getLeverageZapAddress(): string;
|
|
18
|
+
protected abstract _calcCreateLoanHealthCall(_collateral: bigint, _dDebt: bigint, N: number | bigint, full: boolean): Promise<bigint>;
|
|
19
|
+
protected abstract _calcBorrowMoreHealthCall(_collateral: bigint, _dDebt: bigint, N: number | bigint, user: string, full: boolean): Promise<bigint>;
|
|
20
|
+
protected abstract _calcRepayHealthCall(_dCollateral: bigint, _dDebt: bigint, N: number | bigint, user: string, full: boolean): Promise<bigint>;
|
|
21
|
+
protected abstract _calcDebtN1Call(_collateral: bigint, _debt: bigint, N: number | bigint): Promise<bigint>;
|
|
22
|
+
protected abstract _calcDebtN1MulticallCall(_collateral: bigint, _debt: bigint, N: number | bigint): any;
|
|
23
|
+
protected abstract _createLoanContractCall(_userCollateral: bigint, _userBorrowed: bigint, _debt: bigint, _minRecv: bigint, range: number, router: string, exchangeCalldata: string, estimateGas: boolean): Promise<string | TGas>;
|
|
24
|
+
protected abstract _borrowMoreContractCall(_userCollateral: bigint, _userBorrowed: bigint, _debt: bigint, _minRecv: bigint, router: string, exchangeCalldata: string, estimateGas: boolean): Promise<string | TGas>;
|
|
25
|
+
protected abstract _repayContractCall(_userCollateral: bigint, _userBorrowed: bigint, _minRecv: bigint, router: string, exchangeCalldata: string, estimateGas: boolean): Promise<string | TGas>;
|
|
26
|
+
protected abstract _getMaxAdditionalBorrowable(_stateCollateral: bigint, _dCollateral: bigint, _N: bigint, _stateDebt: bigint, address: string): Promise<bigint>;
|
|
27
|
+
protected _getMarketId: () => number;
|
|
18
28
|
hasLeverage: () => boolean;
|
|
19
29
|
_checkLeverageZap(): void;
|
|
20
30
|
_get_k_effective_BN(N: number): Promise<BigNumber>;
|
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import memoize from "memoizee";
|
|
11
|
-
import { _getAddress, parseUnits, BN, toBN, fromBN, ensureAllowance, hasAllowance, ensureAllowanceEstimateGas, formatUnits,
|
|
11
|
+
import { _getAddress, parseUnits, BN, toBN, fromBN, ensureAllowance, hasAllowance, ensureAllowanceEstimateGas, formatUnits, formatNumber, } from "../../../utils";
|
|
12
12
|
import BigNumber from "bignumber.js";
|
|
13
13
|
/**
|
|
14
14
|
* LeverageZapV2 module for LendMarketTemplate
|
|
@@ -22,13 +22,13 @@ export class LeverageZapV2BaseModule {
|
|
|
22
22
|
this._getMarketId = () => Number(this.market.id.split("-").slice(-1)[0]);
|
|
23
23
|
// ============ CREATE LOAN METHODS ============
|
|
24
24
|
this.hasLeverage = () => {
|
|
25
|
-
return this.
|
|
25
|
+
return this._getLeverageZapAddress() !== this.llamalend.constants.ZERO_ADDRESS &&
|
|
26
26
|
this._getMarketId() >= Number(this.llamalend.constants.ALIASES["leverage_markets_start_id"]);
|
|
27
27
|
};
|
|
28
28
|
this.leverageCreateLoanMaxRecvAllRanges = memoize((_a) => __awaiter(this, [_a], void 0, function* ({ userCollateral, userBorrowed, getExpected }) {
|
|
29
29
|
this._checkLeverageZap();
|
|
30
30
|
const _userCollateral = parseUnits(userCollateral, this.market.collateral_token.decimals);
|
|
31
|
-
const contract = this.llamalend.contracts[this.
|
|
31
|
+
const contract = this.llamalend.contracts[this._getLeverageZapAddress()].multicallContract;
|
|
32
32
|
const oraclePriceBand = yield this.market.prices.oraclePriceBand();
|
|
33
33
|
const pAvgApproxBN = BN(yield this.market.prices.calcTickPrice(oraclePriceBand)); // upper tick of oracle price band
|
|
34
34
|
let pAvgBN = null;
|
|
@@ -115,7 +115,7 @@ export class LeverageZapV2BaseModule {
|
|
|
115
115
|
}
|
|
116
116
|
const { _futureStateCollateral } = yield this._leverageExpectedCollateral(userCollateral, userBorrowed, debt, quote, user);
|
|
117
117
|
const _debt = _stateDebt + parseUnits(debt, this.market.borrowed_token.decimals);
|
|
118
|
-
return yield this.
|
|
118
|
+
return yield this._calcDebtN1Call(_futureStateCollateral, _debt, range);
|
|
119
119
|
}), {
|
|
120
120
|
promise: true,
|
|
121
121
|
maxAge: 60 * 1000, // 1m
|
|
@@ -125,7 +125,7 @@ export class LeverageZapV2BaseModule {
|
|
|
125
125
|
const _debt = parseUnits(debt, this.market.borrowed_token.decimals);
|
|
126
126
|
const calls = [];
|
|
127
127
|
for (let N = this.market.minBands; N <= maxN; N++) {
|
|
128
|
-
calls.push(this.
|
|
128
|
+
calls.push(this._calcDebtN1MulticallCall(_futureStateCollateral, _debt, N));
|
|
129
129
|
}
|
|
130
130
|
return yield this.llamalend.multicallProvider.all(calls);
|
|
131
131
|
}), {
|
|
@@ -174,7 +174,7 @@ export class LeverageZapV2BaseModule {
|
|
|
174
174
|
let _n2 = parseUnits(0, 0);
|
|
175
175
|
const { _totalBorrowed: _repayExpected } = this._leverageRepayExpectedBorrowed(stateCollateral, userCollateral, userBorrowed, quote);
|
|
176
176
|
try {
|
|
177
|
-
_n1 = yield this.
|
|
177
|
+
_n1 = yield this._calcDebtN1Call(_stateCollateral - _stateRepayCollateral, _stateDebt - _repayExpected, _N);
|
|
178
178
|
_n2 = _n1 + (_N - BigInt(1));
|
|
179
179
|
return [_n2, _n1];
|
|
180
180
|
}
|
|
@@ -234,7 +234,7 @@ export class LeverageZapV2BaseModule {
|
|
|
234
234
|
let maxBorrowableBN = BN(0);
|
|
235
235
|
let _userEffectiveCollateral = BigInt(0);
|
|
236
236
|
let _maxLeverageCollateral = BigInt(0);
|
|
237
|
-
const contract = this.llamalend.contracts[this.
|
|
237
|
+
const contract = this.llamalend.contracts[this._getLeverageZapAddress()].contract;
|
|
238
238
|
for (let i = 0; i < 5; i++) {
|
|
239
239
|
maxBorrowablePrevBN = maxBorrowableBN;
|
|
240
240
|
_userEffectiveCollateral = _userCollateral + fromBN(BN(userBorrowed).div(pAvgBN), this.market.collateral_token.decimals);
|
|
@@ -375,8 +375,10 @@ export class LeverageZapV2BaseModule {
|
|
|
375
375
|
if (range < 0)
|
|
376
376
|
range = Number(this.llamalend.formatUnits(_N, 0));
|
|
377
377
|
const _dDebt = parseUnits(dDebt, this.market.borrowed_token.decimals);
|
|
378
|
-
const
|
|
379
|
-
let _health =
|
|
378
|
+
const isCreateLoan = user === this.llamalend.constants.ZERO_ADDRESS;
|
|
379
|
+
let _health = isCreateLoan
|
|
380
|
+
? yield this._calcCreateLoanHealthCall(_totalCollateral, _dDebt, range, full)
|
|
381
|
+
: yield this._calcBorrowMoreHealthCall(_totalCollateral, _dDebt, range, user, full);
|
|
380
382
|
_health = _health * BigInt(100);
|
|
381
383
|
return formatUnits(_health);
|
|
382
384
|
});
|
|
@@ -385,7 +387,7 @@ export class LeverageZapV2BaseModule {
|
|
|
385
387
|
return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed }) {
|
|
386
388
|
this._checkLeverageZap();
|
|
387
389
|
const collateralAllowance = yield hasAllowance.call(this.llamalend, [this.market.collateral_token.address], [userCollateral], this.llamalend.signerAddress, this.market.addresses.controller);
|
|
388
|
-
const borrowedAllowance = yield hasAllowance.call(this.llamalend, [this.market.borrowed_token.address], [userBorrowed], this.llamalend.signerAddress, this.
|
|
390
|
+
const borrowedAllowance = yield hasAllowance.call(this.llamalend, [this.market.borrowed_token.address], [userBorrowed], this.llamalend.signerAddress, this._getLeverageZapAddress());
|
|
389
391
|
return collateralAllowance && borrowedAllowance;
|
|
390
392
|
});
|
|
391
393
|
}
|
|
@@ -393,7 +395,7 @@ export class LeverageZapV2BaseModule {
|
|
|
393
395
|
return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed }) {
|
|
394
396
|
this._checkLeverageZap();
|
|
395
397
|
const collateralGas = yield ensureAllowanceEstimateGas.call(this.llamalend, [this.market.collateral_token.address], [userCollateral], this.market.addresses.controller);
|
|
396
|
-
const borrowedGas = yield ensureAllowanceEstimateGas.call(this.llamalend, [this.market.borrowed_token.address], [userBorrowed], this.
|
|
398
|
+
const borrowedGas = yield ensureAllowanceEstimateGas.call(this.llamalend, [this.market.borrowed_token.address], [userBorrowed], this._getLeverageZapAddress());
|
|
397
399
|
if (Array.isArray(collateralGas) && Array.isArray(borrowedGas)) {
|
|
398
400
|
return [collateralGas[0] + borrowedGas[0], collateralGas[1] + borrowedGas[1]];
|
|
399
401
|
}
|
|
@@ -406,7 +408,7 @@ export class LeverageZapV2BaseModule {
|
|
|
406
408
|
return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed }) {
|
|
407
409
|
this._checkLeverageZap();
|
|
408
410
|
const collateralApproveTx = yield ensureAllowance.call(this.llamalend, [this.market.collateral_token.address], [userCollateral], this.market.addresses.controller);
|
|
409
|
-
const borrowedApproveTx = yield ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [userBorrowed], this.
|
|
411
|
+
const borrowedApproveTx = yield ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [userBorrowed], this._getLeverageZapAddress());
|
|
410
412
|
return [...collateralApproveTx, ...borrowedApproveTx];
|
|
411
413
|
});
|
|
412
414
|
}
|
|
@@ -419,14 +421,7 @@ export class LeverageZapV2BaseModule {
|
|
|
419
421
|
const _userBorrowed = parseUnits(userBorrowed, this.market.borrowed_token.decimals);
|
|
420
422
|
const _debt = parseUnits(debt, this.market.borrowed_token.decimals);
|
|
421
423
|
const _minRecv = parseUnits(minRecv, this.market.collateral_token.decimals);
|
|
422
|
-
|
|
423
|
-
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
424
|
-
const gas = yield contract.create_loan_extended.estimateGas(_userCollateral, _debt, range, this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv], zapCalldata, Object.assign({}, this.llamalend.constantOptions));
|
|
425
|
-
if (estimateGas)
|
|
426
|
-
return smartNumber(gas);
|
|
427
|
-
yield this.llamalend.updateFeeData();
|
|
428
|
-
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
429
|
-
return (yield contract.create_loan_extended(_userCollateral, _debt, range, this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv], zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
424
|
+
return yield this._createLoanContractCall(_userCollateral, _userBorrowed, _debt, _minRecv, range, router, calldata, estimateGas);
|
|
430
425
|
});
|
|
431
426
|
}
|
|
432
427
|
leverageCreateLoanEstimateGas(_a) {
|
|
@@ -454,8 +449,7 @@ export class LeverageZapV2BaseModule {
|
|
|
454
449
|
if (_stateBorrowed > BigInt(0))
|
|
455
450
|
throw Error(`User ${address} is already in liquidation mode`);
|
|
456
451
|
const _userCollateral = parseUnits(userCollateral, this.market.collateral_token.decimals);
|
|
457
|
-
const
|
|
458
|
-
const _borrowedFromStateCollateral = (yield controllerContract.max_borrowable(_stateCollateral, _N, _stateDebt, this.llamalend.constantOptions)) - _stateDebt;
|
|
452
|
+
const _borrowedFromStateCollateral = yield this._getMaxAdditionalBorrowable(_stateCollateral, BigInt(0), _N, _stateDebt, address);
|
|
459
453
|
const _userBorrowed = _borrowedFromStateCollateral + parseUnits(userBorrowed, this.market.borrowed_token.decimals);
|
|
460
454
|
userBorrowed = formatUnits(_userBorrowed, this.market.borrowed_token.decimals);
|
|
461
455
|
const oraclePriceBand = yield this.market.prices.oraclePriceBand();
|
|
@@ -464,7 +458,7 @@ export class LeverageZapV2BaseModule {
|
|
|
464
458
|
let maxBorrowableBN = BN(0);
|
|
465
459
|
let _userEffectiveCollateral = BigInt(0);
|
|
466
460
|
let _maxLeverageCollateral = BigInt(0);
|
|
467
|
-
const contract = this.llamalend.contracts[this.
|
|
461
|
+
const contract = this.llamalend.contracts[this._getLeverageZapAddress()].contract;
|
|
468
462
|
for (let i = 0; i < 5; i++) {
|
|
469
463
|
maxBorrowablePrevBN = maxBorrowableBN;
|
|
470
464
|
_userEffectiveCollateral = _userCollateral + fromBN(BN(userBorrowed).div(pAvgBN), this.market.collateral_token.decimals);
|
|
@@ -485,7 +479,7 @@ export class LeverageZapV2BaseModule {
|
|
|
485
479
|
if (maxBorrowableBN.eq(0))
|
|
486
480
|
_userEffectiveCollateral = BigInt(0);
|
|
487
481
|
const _maxTotalCollateral = _userEffectiveCollateral + _maxLeverageCollateral;
|
|
488
|
-
let _maxBorrowable =
|
|
482
|
+
let _maxBorrowable = yield this._getMaxAdditionalBorrowable(_stateCollateral, _maxTotalCollateral, _N, _stateDebt, address);
|
|
489
483
|
_maxBorrowable = _maxBorrowable * BigInt(970) / BigInt(1000);
|
|
490
484
|
return {
|
|
491
485
|
maxDebt: formatUnits(_maxBorrowable, this.market.borrowed_token.decimals),
|
|
@@ -534,14 +528,7 @@ export class LeverageZapV2BaseModule {
|
|
|
534
528
|
const _userBorrowed = parseUnits(userBorrowed, this.market.borrowed_token.decimals);
|
|
535
529
|
const _debt = parseUnits(debt, this.market.borrowed_token.decimals);
|
|
536
530
|
const _minRecv = parseUnits(minRecv, this.market.collateral_token.decimals);
|
|
537
|
-
|
|
538
|
-
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
539
|
-
const gas = yield contract.borrow_more_extended.estimateGas(_userCollateral, _debt, this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv], zapCalldata, Object.assign({}, this.llamalend.constantOptions));
|
|
540
|
-
if (estimateGas)
|
|
541
|
-
return smartNumber(gas);
|
|
542
|
-
yield this.llamalend.updateFeeData();
|
|
543
|
-
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
544
|
-
return (yield contract.borrow_more_extended(_userCollateral, _debt, this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv], zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
531
|
+
return yield this._borrowMoreContractCall(_userCollateral, _userBorrowed, _debt, _minRecv, router, calldata, estimateGas);
|
|
545
532
|
});
|
|
546
533
|
}
|
|
547
534
|
leverageBorrowMoreIsApproved(_a) {
|
|
@@ -648,8 +635,7 @@ export class LeverageZapV2BaseModule {
|
|
|
648
635
|
const _dDebt = _totalBorrowed * BigInt(-1);
|
|
649
636
|
if (_debt + _dDebt <= BigInt(0))
|
|
650
637
|
return "0.0";
|
|
651
|
-
|
|
652
|
-
let _health = yield contract.health_calculator(address, _dCollateral, _dDebt, full, _N, this.llamalend.constantOptions);
|
|
638
|
+
let _health = yield this._calcRepayHealthCall(_dCollateral, _dDebt, _N, address, full);
|
|
653
639
|
_health = _health * BigInt(100);
|
|
654
640
|
return this.llamalend.formatUnits(_health);
|
|
655
641
|
});
|
|
@@ -657,19 +643,19 @@ export class LeverageZapV2BaseModule {
|
|
|
657
643
|
leverageRepayIsApproved(_a) {
|
|
658
644
|
return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed }) {
|
|
659
645
|
this._checkLeverageZap();
|
|
660
|
-
return yield hasAllowance.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address], [userCollateral, userBorrowed], this.llamalend.signerAddress, this.
|
|
646
|
+
return yield hasAllowance.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address], [userCollateral, userBorrowed], this.llamalend.signerAddress, this._getLeverageZapAddress());
|
|
661
647
|
});
|
|
662
648
|
}
|
|
663
649
|
leverageRepayApproveEstimateGas(_a) {
|
|
664
650
|
return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed }) {
|
|
665
651
|
this._checkLeverageZap();
|
|
666
|
-
return yield ensureAllowanceEstimateGas.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address], [userCollateral, userBorrowed], this.
|
|
652
|
+
return yield ensureAllowanceEstimateGas.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address], [userCollateral, userBorrowed], this._getLeverageZapAddress());
|
|
667
653
|
});
|
|
668
654
|
}
|
|
669
655
|
leverageRepayApprove(_a) {
|
|
670
656
|
return __awaiter(this, arguments, void 0, function* ({ userCollateral, userBorrowed }) {
|
|
671
657
|
this._checkLeverageZap();
|
|
672
|
-
return yield ensureAllowance.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address], [userCollateral, userBorrowed], this.
|
|
658
|
+
return yield ensureAllowance.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address], [userCollateral, userBorrowed], this._getLeverageZapAddress());
|
|
673
659
|
});
|
|
674
660
|
}
|
|
675
661
|
_leverageRepay(stateCollateral, userCollateral, userBorrowed, minRecv, router, calldata, estimateGas) {
|
|
@@ -680,17 +666,8 @@ export class LeverageZapV2BaseModule {
|
|
|
680
666
|
const _userCollateral = parseUnits(userCollateral, this.market.collateral_token.decimals);
|
|
681
667
|
const _userBorrowed = parseUnits(userBorrowed, this.market.borrowed_token.decimals);
|
|
682
668
|
const _minRecv = parseUnits(minRecv, this.market.borrowed_token.decimals);
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
zapCalldata = buildCalldataForLeverageZapV2(router, calldata);
|
|
686
|
-
}
|
|
687
|
-
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
688
|
-
const gas = yield contract.repay_extended.estimateGas(this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed, _minRecv], zapCalldata);
|
|
689
|
-
if (estimateGas)
|
|
690
|
-
return smartNumber(gas);
|
|
691
|
-
yield this.llamalend.updateFeeData();
|
|
692
|
-
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
693
|
-
return (yield contract.repay_extended(this.llamalend.constants.ALIASES.leverage_zap_v2, [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed, _minRecv], zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
669
|
+
const exchangeCalldata = _stateCollateral + _userCollateral > BigInt(0) ? calldata : "0x";
|
|
670
|
+
return yield this._repayContractCall(_userCollateral, _userBorrowed, _minRecv, router, exchangeCalldata, estimateGas);
|
|
694
671
|
});
|
|
695
672
|
}
|
|
696
673
|
leverageRepayEstimateGas(_a) {
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
import { LeverageZapV2BaseModule } from "../common/leverageZapV2Base.js";
|
|
2
|
+
import type { TGas } from "../../../interfaces";
|
|
2
3
|
export declare class LeverageV1ZapV2Module extends LeverageZapV2BaseModule {
|
|
4
|
+
protected _getLeverageZapAddress(): string;
|
|
5
|
+
protected _getMaxAdditionalBorrowable(_stateCollateral: bigint, _dCollateral: bigint, _N: bigint, _stateDebt: bigint): Promise<bigint>;
|
|
6
|
+
protected _calcDebtN1Call(_collateral: bigint, _debt: bigint, N: number | bigint): Promise<bigint>;
|
|
7
|
+
protected _calcDebtN1MulticallCall(_collateral: bigint, _debt: bigint, N: number | bigint): any;
|
|
8
|
+
protected _calcCreateLoanHealthCall(_collateral: bigint, _dDebt: bigint, N: number | bigint, full: boolean): Promise<bigint>;
|
|
9
|
+
protected _calcBorrowMoreHealthCall(_collateral: bigint, _dDebt: bigint, N: number | bigint, user: string, full: boolean): Promise<bigint>;
|
|
10
|
+
protected _calcRepayHealthCall(_dCollateral: bigint, _dDebt: bigint, N: number | bigint, user: string, full: boolean): Promise<bigint>;
|
|
11
|
+
protected _createLoanContractCall(_userCollateral: bigint, _userBorrowed: bigint, _debt: bigint, _minRecv: bigint, range: number, router: string, exchangeCalldata: string, estimateGas: boolean): Promise<string | TGas>;
|
|
12
|
+
protected _borrowMoreContractCall(_userCollateral: bigint, _userBorrowed: bigint, _debt: bigint, _minRecv: bigint, router: string, exchangeCalldata: string, estimateGas: boolean): Promise<string | TGas>;
|
|
13
|
+
protected _repayContractCall(_userCollateral: bigint, _userBorrowed: bigint, _minRecv: bigint, router: string, exchangeCalldata: string, estimateGas: boolean): Promise<string | TGas>;
|
|
3
14
|
}
|
|
@@ -1,3 +1,81 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import { LeverageZapV2BaseModule } from "../common/leverageZapV2Base.js";
|
|
11
|
+
import { parseUnits, smartNumber, _mulBy1_3, DIGas, buildCalldataForLeverageZapV2, } from "../../../utils";
|
|
2
12
|
export class LeverageV1ZapV2Module extends LeverageZapV2BaseModule {
|
|
13
|
+
_getLeverageZapAddress() {
|
|
14
|
+
return this.llamalend.constants.ALIASES.leverage_zap_v2;
|
|
15
|
+
}
|
|
16
|
+
_getMaxAdditionalBorrowable(_stateCollateral, _dCollateral, _N, _stateDebt) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const result = yield this.llamalend.contracts[this.market.addresses.controller].contract.max_borrowable(_stateCollateral + _dCollateral, _N, _stateDebt, this.llamalend.constantOptions);
|
|
19
|
+
return result - _stateDebt;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
_calcDebtN1Call(_collateral, _debt, N) {
|
|
23
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
return yield this.llamalend.contracts[this.market.addresses.controller].contract.calculate_debt_n1(_collateral, _debt, N, this.llamalend.constantOptions);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
_calcDebtN1MulticallCall(_collateral, _debt, N) {
|
|
28
|
+
return this.llamalend.contracts[this.market.addresses.controller].multicallContract.calculate_debt_n1(_collateral, _debt, N);
|
|
29
|
+
}
|
|
30
|
+
_calcCreateLoanHealthCall(_collateral, _dDebt, N, full) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
return yield this.llamalend.contracts[this.market.addresses.controller].contract.health_calculator(this.llamalend.constants.ZERO_ADDRESS, _collateral, _dDebt, full, N, this.llamalend.constantOptions);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
_calcBorrowMoreHealthCall(_collateral, _dDebt, N, user, full) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
return yield this.llamalend.contracts[this.market.addresses.controller].contract.health_calculator(user, _collateral, _dDebt, full, N, this.llamalend.constantOptions);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
_calcRepayHealthCall(_dCollateral, _dDebt, N, user, full) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
return yield this.llamalend.contracts[this.market.addresses.controller].contract.health_calculator(user, _dCollateral, _dDebt, full, N, this.llamalend.constantOptions);
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
_createLoanContractCall(_userCollateral, _userBorrowed, _debt, _minRecv, range, router, exchangeCalldata, estimateGas) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
const zapCalldata = buildCalldataForLeverageZapV2(router, exchangeCalldata);
|
|
48
|
+
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
49
|
+
const gas = yield contract.create_loan_extended.estimateGas(_userCollateral, _debt, range, this._getLeverageZapAddress(), [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv], zapCalldata, Object.assign({}, this.llamalend.constantOptions));
|
|
50
|
+
if (estimateGas)
|
|
51
|
+
return smartNumber(gas);
|
|
52
|
+
yield this.llamalend.updateFeeData();
|
|
53
|
+
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
54
|
+
return (yield contract.create_loan_extended(_userCollateral, _debt, range, this._getLeverageZapAddress(), [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv], zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
_borrowMoreContractCall(_userCollateral, _userBorrowed, _debt, _minRecv, router, exchangeCalldata, estimateGas) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
const zapCalldata = buildCalldataForLeverageZapV2(router, exchangeCalldata);
|
|
60
|
+
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
61
|
+
const gas = yield contract.borrow_more_extended.estimateGas(_userCollateral, _debt, this._getLeverageZapAddress(), [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv], zapCalldata, Object.assign({}, this.llamalend.constantOptions));
|
|
62
|
+
if (estimateGas)
|
|
63
|
+
return smartNumber(gas);
|
|
64
|
+
yield this.llamalend.updateFeeData();
|
|
65
|
+
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
66
|
+
return (yield contract.borrow_more_extended(_userCollateral, _debt, this._getLeverageZapAddress(), [0, parseUnits(this._getMarketId(), 0), _userBorrowed, _minRecv], zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
_repayContractCall(_userCollateral, _userBorrowed, _minRecv, router, exchangeCalldata, estimateGas) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
const zapCalldata = buildCalldataForLeverageZapV2(router, exchangeCalldata);
|
|
72
|
+
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
73
|
+
const gas = yield contract.repay_extended.estimateGas(this._getLeverageZapAddress(), [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed, _minRecv], zapCalldata);
|
|
74
|
+
if (estimateGas)
|
|
75
|
+
return smartNumber(gas);
|
|
76
|
+
yield this.llamalend.updateFeeData();
|
|
77
|
+
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
78
|
+
return (yield contract.repay_extended(this._getLeverageZapAddress(), [0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed, _minRecv], zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
79
|
+
});
|
|
80
|
+
}
|
|
3
81
|
}
|
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
import { LeverageZapV2BaseModule } from "../common/leverageZapV2Base.js";
|
|
2
|
+
import type { TGas } from "../../../interfaces";
|
|
2
3
|
export declare class LeverageV2ZapV2Module extends LeverageZapV2BaseModule {
|
|
4
|
+
protected _getLeverageZapAddress(): string;
|
|
5
|
+
protected _getMaxAdditionalBorrowable(_stateCollateral: bigint, _dCollateral: bigint, _N: bigint, _stateDebt: bigint, address: string): Promise<bigint>;
|
|
6
|
+
protected _calcDebtN1Call(_collateral: bigint, _debt: bigint, N: number | bigint): Promise<bigint>;
|
|
7
|
+
protected _calcDebtN1MulticallCall(_collateral: bigint, _debt: bigint, N: number | bigint): any;
|
|
8
|
+
protected _calcCreateLoanHealthCall(_collateral: bigint, _dDebt: bigint, N: number | bigint, full: boolean): Promise<bigint>;
|
|
9
|
+
protected _calcBorrowMoreHealthCall(_collateral: bigint, _dDebt: bigint, _N: number | bigint, user: string, full: boolean): Promise<bigint>;
|
|
10
|
+
protected _calcRepayHealthCall(_dCollateral: bigint, _dDebt: bigint, _N: number | bigint, user: string, full: boolean): Promise<bigint>;
|
|
11
|
+
protected _createLoanContractCall(_userCollateral: bigint, _userBorrowed: bigint, _debt: bigint, _minRecv: bigint, range: number, router: string, exchangeCalldata: string, estimateGas: boolean): Promise<string | TGas>;
|
|
12
|
+
protected _borrowMoreContractCall(_userCollateral: bigint, _userBorrowed: bigint, _debt: bigint, _minRecv: bigint, router: string, exchangeCalldata: string, estimateGas: boolean): Promise<string | TGas>;
|
|
13
|
+
protected _repayContractCall(_userCollateral: bigint, _userBorrowed: bigint, _minRecv: bigint, router: string, exchangeCalldata: string, estimateGas: boolean): Promise<string | TGas>;
|
|
3
14
|
}
|