@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
|
@@ -1,3 +1,115 @@
|
|
|
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 { _getAddress, smartNumber, _mulBy1_3, DIGas, MAX_ACTIVE_BAND, buildCalldataForLeverageZapV2Llv2, } from "../../../utils";
|
|
2
12
|
export class LeverageV2ZapV2Module extends LeverageZapV2BaseModule {
|
|
13
|
+
_getLeverageZapAddress() {
|
|
14
|
+
return this.llamalend.constants.ALIASES.leverage_zap_v2_llv2;
|
|
15
|
+
}
|
|
16
|
+
_getMaxAdditionalBorrowable(_stateCollateral, _dCollateral, _N, _stateDebt, address) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
return yield this.llamalend.contracts[this.market.addresses.controller].contract.max_borrowable(_dCollateral, _N, address, this.llamalend.constantOptions);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
_calcDebtN1Call(_collateral, _debt, N) {
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const address = _getAddress.call(this.llamalend, '');
|
|
24
|
+
return yield this.llamalend.contracts[this.market.addresses.controller].contract.calculate_debt_n1(_collateral, _debt, N, address, this.llamalend.constantOptions);
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
_calcDebtN1MulticallCall(_collateral, _debt, N) {
|
|
28
|
+
const address = _getAddress.call(this.llamalend, '');
|
|
29
|
+
return this.llamalend.contracts[this.market.addresses.controller].multicallContract.calculate_debt_n1(_collateral, _debt, N, address);
|
|
30
|
+
}
|
|
31
|
+
_calcCreateLoanHealthCall(_collateral, _dDebt, N, full) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
const _for = _getAddress.call(this.llamalend, '');
|
|
34
|
+
return yield this.llamalend.contracts[this.market.addresses.controller].contract.create_loan_health_preview(_collateral, _dDebt, N, _for, full, this.llamalend.constantOptions);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
_calcBorrowMoreHealthCall(_collateral, _dDebt, _N, user, full) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
return yield this.llamalend.contracts[this.market.addresses.controller].contract.borrow_more_health_preview(_collateral, _dDebt, user, full, this.llamalend.constantOptions);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
_calcRepayHealthCall(_dCollateral, _dDebt, _N, user, full) {
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
const _dCollateralAbs = _dCollateral < BigInt(0) ? -_dCollateral : _dCollateral;
|
|
45
|
+
const _dDebtAbs = _dDebt < BigInt(0) ? -_dDebt : _dDebt;
|
|
46
|
+
const _shrink = false;
|
|
47
|
+
return yield this.llamalend.contracts[this.market.addresses.controller].contract.repay_health_preview(_dCollateralAbs, _dDebtAbs, user, _shrink, full, this.llamalend.constantOptions);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
_createLoanContractCall(_userCollateral, _userBorrowed, _debt, _minRecv, range, router, exchangeCalldata, estimateGas) {
|
|
51
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
52
|
+
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
53
|
+
const _for = _getAddress.call(this.llamalend, '');
|
|
54
|
+
const _callbacker = this._getLeverageZapAddress();
|
|
55
|
+
const zapCalldata = buildCalldataForLeverageZapV2Llv2({
|
|
56
|
+
op: 'create_loan',
|
|
57
|
+
controllerId: this._getMarketId(),
|
|
58
|
+
userBorrowed: _userBorrowed,
|
|
59
|
+
minRecv: _minRecv,
|
|
60
|
+
router,
|
|
61
|
+
exchangeCalldata,
|
|
62
|
+
});
|
|
63
|
+
const gas = yield contract.create_loan.estimateGas(_userCollateral, _debt, range, _for, _callbacker, zapCalldata, Object.assign({}, this.llamalend.constantOptions));
|
|
64
|
+
if (estimateGas)
|
|
65
|
+
return smartNumber(gas);
|
|
66
|
+
yield this.llamalend.updateFeeData();
|
|
67
|
+
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
68
|
+
return (yield contract.create_loan(_userCollateral, _debt, range, _for, _callbacker, zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
_borrowMoreContractCall(_userCollateral, _userBorrowed, _debt, _minRecv, router, exchangeCalldata, estimateGas) {
|
|
72
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
74
|
+
const _for = _getAddress.call(this.llamalend, '');
|
|
75
|
+
const _callbacker = this._getLeverageZapAddress();
|
|
76
|
+
const zapCalldata = buildCalldataForLeverageZapV2Llv2({
|
|
77
|
+
op: 'borrow_more',
|
|
78
|
+
controllerId: this._getMarketId(),
|
|
79
|
+
userBorrowed: _userBorrowed,
|
|
80
|
+
minRecv: _minRecv,
|
|
81
|
+
router,
|
|
82
|
+
exchangeCalldata,
|
|
83
|
+
});
|
|
84
|
+
const gas = yield contract.borrow_more.estimateGas(_userCollateral, _debt, _for, _callbacker, zapCalldata, Object.assign({}, this.llamalend.constantOptions));
|
|
85
|
+
if (estimateGas)
|
|
86
|
+
return smartNumber(gas);
|
|
87
|
+
yield this.llamalend.updateFeeData();
|
|
88
|
+
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
89
|
+
return (yield contract.borrow_more(_userCollateral, _debt, _for, _callbacker, zapCalldata, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
_repayContractCall(_userCollateral, _userBorrowed, _minRecv, router, exchangeCalldata, estimateGas) {
|
|
93
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
95
|
+
const _for = _getAddress.call(this.llamalend, '');
|
|
96
|
+
const _callbacker = this._getLeverageZapAddress();
|
|
97
|
+
const zapCalldata = buildCalldataForLeverageZapV2Llv2({
|
|
98
|
+
op: 'repay',
|
|
99
|
+
controllerId: this._getMarketId(),
|
|
100
|
+
userCollateral: _userCollateral,
|
|
101
|
+
userBorrowed: _userBorrowed,
|
|
102
|
+
minRecv: _minRecv,
|
|
103
|
+
router,
|
|
104
|
+
exchangeCalldata,
|
|
105
|
+
});
|
|
106
|
+
const _walletDDebt = BigInt(0);
|
|
107
|
+
const gas = yield contract.repay.estimateGas(_walletDDebt, _for, MAX_ACTIVE_BAND, _callbacker, zapCalldata, false, Object.assign({}, this.llamalend.constantOptions));
|
|
108
|
+
if (estimateGas)
|
|
109
|
+
return smartNumber(gas);
|
|
110
|
+
yield this.llamalend.updateFeeData();
|
|
111
|
+
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
112
|
+
return (yield contract.repay(_walletDDebt, _for, MAX_ACTIVE_BAND, _callbacker, zapCalldata, false, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
3
115
|
}
|
package/lib/llamalend.js
CHANGED
|
@@ -293,8 +293,9 @@ class Llamalend {
|
|
|
293
293
|
this.setContract(this.constants.ALIASES['one_way_factory_v2'], OneWayLendingFactoryV2ABI);
|
|
294
294
|
}
|
|
295
295
|
this.setContract(this.constants.ALIASES['gauge_controller'], GaugeControllerABI);
|
|
296
|
-
this.setContract(this.constants.ALIASES['
|
|
296
|
+
this.setContract(this.constants.ALIASES['leverage_zap_deprecated'], LeverageZapABI);
|
|
297
297
|
this.setContract(this.constants.ALIASES['leverage_zap_v2'], LeverageZapABI);
|
|
298
|
+
this.setContract(this.constants.ALIASES['leverage_zap_v2_llv2'], LeverageZapABI);
|
|
298
299
|
if (this.chainId === 1) {
|
|
299
300
|
this.setContract(this.constants.ALIASES.minter, MinterABI);
|
|
300
301
|
this.setContract(this.constants.ALIASES.gauge_factory, GaugeFactoryMainnetABI);
|
|
@@ -1094,6 +1094,7 @@ export class MintMarketTemplate {
|
|
|
1094
1094
|
// ---------------- REPAY ----------------
|
|
1095
1095
|
_repayBands(debt, address) {
|
|
1096
1096
|
return __awaiter(this, void 0, void 0, function* () {
|
|
1097
|
+
address = _getAddress.call(this.llamalend, address);
|
|
1097
1098
|
const { _collateral: _currentCollateral, _debt: _currentDebt, _stablecoin: _currentStablecoin } = yield this._userState(address);
|
|
1098
1099
|
if (_currentDebt === BigInt(0))
|
|
1099
1100
|
throw Error(`Loan for ${address} does not exist`);
|
|
@@ -11,7 +11,7 @@ import { _getCrvUsdMarketsData } from "../../external-api.js";
|
|
|
11
11
|
import ERC20ABI from '../../constants/abis/ERC20.json' with { type: 'json' };
|
|
12
12
|
import llammaABI from "../../constants/abis/crvUSD/llamma.json" with { type: 'json' };
|
|
13
13
|
import controllerABI from "../../constants/abis/crvUSD/controller.json" with { type: 'json' };
|
|
14
|
-
import controllerV2ABI from "../../constants/abis/crvUSD/controller_v2.json";
|
|
14
|
+
import controllerV2ABI from "../../constants/abis/crvUSD/controller_v2.json" with { type: 'json' };
|
|
15
15
|
import FactoryABI from "../../constants/abis/crvUSD/Factory.json" with { type: 'json' };
|
|
16
16
|
import { extractDecimals } from "../../constants/utils.js";
|
|
17
17
|
import { handleMultiCallResponse } from "../../utils.js";
|
package/lib/utils.d.ts
CHANGED
|
@@ -59,3 +59,17 @@ export declare const getLsdApy: ((name: "wstETH" | "sfrxETH") => Promise<{
|
|
|
59
59
|
}>>;
|
|
60
60
|
export declare const calculateFutureLeverage: (currentCollateral: number | string, totalDepositFromUser: number | string, collateral: number | string, operation: "add" | "remove") => string;
|
|
61
61
|
export declare const buildCalldataForLeverageZapV2: (routerAddress: string, exchangeCalldata: string) => string;
|
|
62
|
+
export type LeverageZapV2LLv2CalldataParams = {
|
|
63
|
+
controllerId: number | string | bigint;
|
|
64
|
+
minRecv: bigint;
|
|
65
|
+
router: string;
|
|
66
|
+
exchangeCalldata: string;
|
|
67
|
+
} & ({
|
|
68
|
+
op: 'create_loan' | 'borrow_more';
|
|
69
|
+
userBorrowed: bigint;
|
|
70
|
+
} | {
|
|
71
|
+
op: 'repay';
|
|
72
|
+
userCollateral: bigint;
|
|
73
|
+
userBorrowed: bigint;
|
|
74
|
+
});
|
|
75
|
+
export declare const buildCalldataForLeverageZapV2Llv2: (params: LeverageZapV2LLv2CalldataParams) => string;
|
package/lib/utils.js
CHANGED
|
@@ -448,3 +448,12 @@ export const buildCalldataForLeverageZapV2 = (routerAddress, exchangeCalldata) =
|
|
|
448
448
|
const abiCoder = ethers.AbiCoder.defaultAbiCoder();
|
|
449
449
|
return abiCoder.encode(['address', 'bytes'], [routerAddress, '0x' + cleanCalldata]);
|
|
450
450
|
};
|
|
451
|
+
export const buildCalldataForLeverageZapV2Llv2 = (params) => {
|
|
452
|
+
const cleanCalldata = params.exchangeCalldata.startsWith('0x') ? params.exchangeCalldata.slice(2) : params.exchangeCalldata;
|
|
453
|
+
const exchangeBytes = '0x' + cleanCalldata;
|
|
454
|
+
const abiCoder = ethers.AbiCoder.defaultAbiCoder();
|
|
455
|
+
if (params.op === 'repay') {
|
|
456
|
+
return abiCoder.encode(['uint256', 'uint256', 'uint256', 'uint256', 'address', 'bytes'], [BigInt(params.controllerId), params.userCollateral, params.userBorrowed, params.minRecv, params.router, exchangeBytes]);
|
|
457
|
+
}
|
|
458
|
+
return abiCoder.encode(['uint256', 'uint256', 'uint256', 'address', 'bytes'], [BigInt(params.controllerId), params.userBorrowed, params.minRecv, params.router, exchangeBytes]);
|
|
459
|
+
};
|
package/package.json
CHANGED
package/src/constants/aliases.ts
CHANGED
|
@@ -7,9 +7,9 @@ export const ALIASES_ETHEREUM = lowerCaseValues({
|
|
|
7
7
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
8
8
|
"minter": '0xd061D61a4d941c39E5453435B6345Dc261C2fcE0',
|
|
9
9
|
"gauge_factory": "0xabC000d88f23Bb45525E447528DBF656A9D55bf5",
|
|
10
|
-
|
|
11
|
-
"leverage_zap": "0xC8E8430dc7Cb23C32543329acCC68c9055C23e18", // odos v3
|
|
10
|
+
"leverage_zap_deprecated": "0xC8E8430dc7Cb23C32543329acCC68c9055C23e18", // odos v3
|
|
12
11
|
"leverage_zap_v2": "0x324c5f9F7A3015D91860aC6870dcE25d410Df3Dc",
|
|
12
|
+
"leverage_zap_v2_llv2": "0x0F7C08E209ef1C3bE725c2584BCed4877095D680",
|
|
13
13
|
"leverage_markets_start_id": "9",
|
|
14
14
|
"crvUSD": "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E",
|
|
15
15
|
"st_crvUSD": "0x0655977FEb2f289A4aB78af67BAB0d17aAb84367",
|
|
@@ -20,9 +20,9 @@ export const ALIASES_ARBITRUM = lowerCaseValues({
|
|
|
20
20
|
"one_way_factory": "0xcaEC110C784c9DF37240a8Ce096D352A75922DeA",
|
|
21
21
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
22
22
|
"gauge_factory": "0xabC000d88f23Bb45525E447528DBF656A9D55bf5",
|
|
23
|
-
|
|
24
|
-
"leverage_zap": "0xFE02553d3Ba4c3f39F36a4632F91404DF94b9AE2", // odos v3
|
|
23
|
+
"leverage_zap_deprecated": "0xFE02553d3Ba4c3f39F36a4632F91404DF94b9AE2", // odos v3
|
|
25
24
|
"leverage_zap_v2": "0x9577086c6E38d38359872F903Da201f1bdCc0323",
|
|
25
|
+
"leverage_zap_v2_llv2": "0x0F7C08E209ef1C3bE725c2584BCed4877095D680",
|
|
26
26
|
"leverage_markets_start_id": "9",
|
|
27
27
|
});
|
|
28
28
|
|
|
@@ -34,8 +34,9 @@ export const ALIASES_OPTIMISM = lowerCaseValues({
|
|
|
34
34
|
"gauge_factory_old": "0xabC000d88f23Bb45525E447528DBF656A9D55bf5",
|
|
35
35
|
"gauge_factory": "0x871fBD4E01012e2E8457346059e8C189d664DbA4",
|
|
36
36
|
"old_gauge_end_index": "4",
|
|
37
|
-
"
|
|
37
|
+
"leverage_zap_deprecated": "0xBFab8ebc836E1c4D81837798FC076D219C9a1855", // odos v3
|
|
38
38
|
"leverage_zap_v2": "0xE94d1fBF399c27CCBf0185b2Dd11Bf0FA0f0D95C",
|
|
39
|
+
"leverage_zap_v2_llv2": "0xcfd71a5BC9c2215ca8878C1083EC9a3CE1F0fdEb",
|
|
39
40
|
"leverage_markets_start_id": "0",
|
|
40
41
|
"gas_oracle": '0xc0d3C0d3C0d3c0D3C0D3C0d3C0d3C0D3C0D3000f',
|
|
41
42
|
"gas_oracle_blob": '0x420000000000000000000000000000000000000f',
|
|
@@ -48,8 +49,9 @@ export const ALIASES_FRAXTAL = lowerCaseValues({
|
|
|
48
49
|
"gauge_factory_old": "0xeF672bD94913CB6f1d2812a6e18c1fFdEd8eFf5c",
|
|
49
50
|
"gauge_factory": "0x0b8d6b6cefc7aa1c2852442e518443b1b22e1c52",
|
|
50
51
|
"old_gauge_end_index": "3",
|
|
51
|
-
"
|
|
52
|
+
"leverage_zap_deprecated": "0x3294514B78Df4Bb90132567fcf8E5e99f390B687", // odos v3
|
|
52
53
|
"leverage_zap_v2": "0x16C6521Dff6baB339122a0FE25a9116693265353",
|
|
54
|
+
"leverage_zap_v2_llv2": "0x0F7C08E209ef1C3bE725c2584BCed4877095D680",
|
|
53
55
|
"leverage_markets_start_id": "0",
|
|
54
56
|
});
|
|
55
57
|
|
|
@@ -58,7 +60,8 @@ export const ALIASES_SONIC = lowerCaseValues({
|
|
|
58
60
|
"one_way_factory": "0x30d1859dad5a52ae03b6e259d1b48c4b12933993",
|
|
59
61
|
"gauge_controller": "0x2F50D538606Fa9EDD2B11E2446BEb18C9D5846bB",
|
|
60
62
|
"gauge_factory": "0xf3A431008396df8A8b2DF492C913706BDB0874ef",
|
|
61
|
-
"
|
|
63
|
+
"leverage_zap_deprecated": "0x0fE38dCC905eC14F6099a83Ac5C93BF2601300CF", // odos v3
|
|
62
64
|
"leverage_zap_v2": "0xCA8d0747B5573D69653C3aC22242e6341C36e4b4",
|
|
65
|
+
"leverage_zap_v2_llv2": "0x0F7C08E209ef1C3bE725c2584BCed4877095D680",
|
|
63
66
|
"leverage_markets_start_id": "0",
|
|
64
67
|
});
|
|
@@ -37,7 +37,7 @@ export class LeverageZapV1BaseModule {
|
|
|
37
37
|
// ============ CREATE LOAN METHODS ============
|
|
38
38
|
|
|
39
39
|
public hasLeverage = (): boolean => {
|
|
40
|
-
return this.llamalend.constants.ALIASES.
|
|
40
|
+
return this.llamalend.constants.ALIASES.leverage_zap_deprecated !== this.llamalend.constants.ZERO_ADDRESS &&
|
|
41
41
|
this._getMarketId() >= Number(this.llamalend.constants.ALIASES["leverage_markets_start_id"]);
|
|
42
42
|
}
|
|
43
43
|
|
|
@@ -93,7 +93,7 @@ export class LeverageZapV1BaseModule {
|
|
|
93
93
|
let _userEffectiveCollateral = BigInt(0);
|
|
94
94
|
let _maxLeverageCollateral = BigInt(0);
|
|
95
95
|
|
|
96
|
-
const contract = this.llamalend.contracts[this.llamalend.constants.ALIASES.
|
|
96
|
+
const contract = this.llamalend.contracts[this.llamalend.constants.ALIASES.leverage_zap_deprecated].contract;
|
|
97
97
|
for (let i = 0; i < 5; i++) {
|
|
98
98
|
maxBorrowablePrevBN = maxBorrowableBN;
|
|
99
99
|
_userEffectiveCollateral = _userCollateral + fromBN(BN(userBorrowed).div(pAvgBN), this.market.collateral_token.decimals);
|
|
@@ -141,7 +141,7 @@ export class LeverageZapV1BaseModule {
|
|
|
141
141
|
}>> => {
|
|
142
142
|
this._checkLeverageZap();
|
|
143
143
|
const _userCollateral = parseUnits(userCollateral, this.market.collateral_token.decimals);
|
|
144
|
-
const contract = this.llamalend.contracts[this.llamalend.constants.ALIASES.
|
|
144
|
+
const contract = this.llamalend.contracts[this.llamalend.constants.ALIASES.leverage_zap_deprecated].multicallContract;
|
|
145
145
|
|
|
146
146
|
const oraclePriceBand = await this.market.prices.oraclePriceBand();
|
|
147
147
|
const pAvgApproxBN = BN(await this.market.prices.calcTickPrice(oraclePriceBand)); // upper tick of oracle price band
|
|
@@ -427,7 +427,7 @@ export class LeverageZapV1BaseModule {
|
|
|
427
427
|
const collateralAllowance = await hasAllowance.call(this.llamalend,
|
|
428
428
|
[this.market.collateral_token.address], [userCollateral], this.llamalend.signerAddress, this.market.addresses.controller);
|
|
429
429
|
const borrowedAllowance = await hasAllowance.call(this.llamalend,
|
|
430
|
-
[this.market.borrowed_token.address], [userBorrowed], this.llamalend.signerAddress, this.llamalend.constants.ALIASES.
|
|
430
|
+
[this.market.borrowed_token.address], [userBorrowed], this.llamalend.signerAddress, this.llamalend.constants.ALIASES.leverage_zap_deprecated);
|
|
431
431
|
|
|
432
432
|
return collateralAllowance && borrowedAllowance
|
|
433
433
|
}
|
|
@@ -437,7 +437,7 @@ export class LeverageZapV1BaseModule {
|
|
|
437
437
|
const collateralGas = await ensureAllowanceEstimateGas.call(this.llamalend,
|
|
438
438
|
[this.market.collateral_token.address], [userCollateral], this.market.addresses.controller);
|
|
439
439
|
const borrowedGas = await ensureAllowanceEstimateGas.call(this.llamalend,
|
|
440
|
-
[this.market.borrowed_token.address], [userBorrowed], this.llamalend.constants.ALIASES.
|
|
440
|
+
[this.market.borrowed_token.address], [userBorrowed], this.llamalend.constants.ALIASES.leverage_zap_deprecated);
|
|
441
441
|
|
|
442
442
|
if(Array.isArray(collateralGas) && Array.isArray(borrowedGas)) {
|
|
443
443
|
return [collateralGas[0] + borrowedGas[0], collateralGas[1] + borrowedGas[1]]
|
|
@@ -451,7 +451,7 @@ export class LeverageZapV1BaseModule {
|
|
|
451
451
|
const collateralApproveTx = await ensureAllowance.call(this.llamalend,
|
|
452
452
|
[this.market.collateral_token.address], [userCollateral], this.market.addresses.controller);
|
|
453
453
|
const borrowedApproveTx = await ensureAllowance.call(this.llamalend,
|
|
454
|
-
[this.market.borrowed_token.address], [userBorrowed], this.llamalend.constants.ALIASES.
|
|
454
|
+
[this.market.borrowed_token.address], [userBorrowed], this.llamalend.constants.ALIASES.leverage_zap_deprecated);
|
|
455
455
|
|
|
456
456
|
return [...collateralApproveTx, ...borrowedApproveTx]
|
|
457
457
|
}
|
|
@@ -486,7 +486,7 @@ export class LeverageZapV1BaseModule {
|
|
|
486
486
|
_userCollateral,
|
|
487
487
|
_debt,
|
|
488
488
|
range,
|
|
489
|
-
this.llamalend.constants.ALIASES.
|
|
489
|
+
this.llamalend.constants.ALIASES.leverage_zap_deprecated,
|
|
490
490
|
[0, parseUnits(this._getMarketId(), 0), _userBorrowed],
|
|
491
491
|
calldata,
|
|
492
492
|
{ ...this.llamalend.constantOptions }
|
|
@@ -499,7 +499,7 @@ export class LeverageZapV1BaseModule {
|
|
|
499
499
|
_userCollateral,
|
|
500
500
|
_debt,
|
|
501
501
|
range,
|
|
502
|
-
this.llamalend.constants.ALIASES.
|
|
502
|
+
this.llamalend.constants.ALIASES.leverage_zap_deprecated,
|
|
503
503
|
[0, parseUnits(this._getMarketId(), 0), _userBorrowed],
|
|
504
504
|
calldata,
|
|
505
505
|
{ ...this.llamalend.options, gasLimit }
|
|
@@ -547,7 +547,7 @@ export class LeverageZapV1BaseModule {
|
|
|
547
547
|
let _userEffectiveCollateral = BigInt(0);
|
|
548
548
|
let _maxLeverageCollateral = BigInt(0);
|
|
549
549
|
|
|
550
|
-
const contract = this.llamalend.contracts[this.llamalend.constants.ALIASES.
|
|
550
|
+
const contract = this.llamalend.contracts[this.llamalend.constants.ALIASES.leverage_zap_deprecated].contract;
|
|
551
551
|
for (let i = 0; i < 5; i++) {
|
|
552
552
|
maxBorrowablePrevBN = maxBorrowableBN;
|
|
553
553
|
_userEffectiveCollateral = _userCollateral + fromBN(BN(userBorrowed).div(pAvgBN), this.market.collateral_token.decimals);
|
|
@@ -656,7 +656,7 @@ export class LeverageZapV1BaseModule {
|
|
|
656
656
|
const gas = await contract.borrow_more_extended.estimateGas(
|
|
657
657
|
_userCollateral,
|
|
658
658
|
_debt,
|
|
659
|
-
this.llamalend.constants.ALIASES.
|
|
659
|
+
this.llamalend.constants.ALIASES.leverage_zap_deprecated,
|
|
660
660
|
[0, parseUnits(this._getMarketId(), 0), _userBorrowed],
|
|
661
661
|
calldata,
|
|
662
662
|
{ ...this.llamalend.constantOptions }
|
|
@@ -669,7 +669,7 @@ export class LeverageZapV1BaseModule {
|
|
|
669
669
|
return (await contract.borrow_more_extended(
|
|
670
670
|
_userCollateral,
|
|
671
671
|
_debt,
|
|
672
|
-
this.llamalend.constants.ALIASES.
|
|
672
|
+
this.llamalend.constants.ALIASES.leverage_zap_deprecated,
|
|
673
673
|
[0, parseUnits(this._getMarketId(), 0), _userBorrowed],
|
|
674
674
|
calldata,
|
|
675
675
|
{ ...this.llamalend.options, gasLimit }
|
|
@@ -846,7 +846,7 @@ export class LeverageZapV1BaseModule {
|
|
|
846
846
|
[this.market.collateral_token.address, this.market.borrowed_token.address],
|
|
847
847
|
[userCollateral, userBorrowed],
|
|
848
848
|
this.llamalend.signerAddress,
|
|
849
|
-
this.llamalend.constants.ALIASES.
|
|
849
|
+
this.llamalend.constants.ALIASES.leverage_zap_deprecated
|
|
850
850
|
);
|
|
851
851
|
}
|
|
852
852
|
|
|
@@ -855,7 +855,7 @@ export class LeverageZapV1BaseModule {
|
|
|
855
855
|
return await ensureAllowanceEstimateGas.call(this.llamalend,
|
|
856
856
|
[this.market.collateral_token.address, this.market.borrowed_token.address],
|
|
857
857
|
[userCollateral, userBorrowed],
|
|
858
|
-
this.llamalend.constants.ALIASES.
|
|
858
|
+
this.llamalend.constants.ALIASES.leverage_zap_deprecated
|
|
859
859
|
);
|
|
860
860
|
}
|
|
861
861
|
|
|
@@ -864,7 +864,7 @@ export class LeverageZapV1BaseModule {
|
|
|
864
864
|
return await ensureAllowance.call(this.llamalend,
|
|
865
865
|
[this.market.collateral_token.address, this.market.borrowed_token.address],
|
|
866
866
|
[userCollateral, userBorrowed],
|
|
867
|
-
this.llamalend.constants.ALIASES.
|
|
867
|
+
this.llamalend.constants.ALIASES.leverage_zap_deprecated
|
|
868
868
|
);
|
|
869
869
|
}
|
|
870
870
|
|
|
@@ -896,7 +896,7 @@ export class LeverageZapV1BaseModule {
|
|
|
896
896
|
|
|
897
897
|
const contract = this.llamalend.contracts[this.market.addresses.controller].contract;
|
|
898
898
|
const gas = await contract.repay_extended.estimateGas(
|
|
899
|
-
this.llamalend.constants.ALIASES.
|
|
899
|
+
this.llamalend.constants.ALIASES.leverage_zap_deprecated,
|
|
900
900
|
[0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed],
|
|
901
901
|
calldata
|
|
902
902
|
);
|
|
@@ -906,7 +906,7 @@ export class LeverageZapV1BaseModule {
|
|
|
906
906
|
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
907
907
|
|
|
908
908
|
return (await contract.repay_extended(
|
|
909
|
-
this.llamalend.constants.ALIASES.
|
|
909
|
+
this.llamalend.constants.ALIASES.leverage_zap_deprecated,
|
|
910
910
|
[0, parseUnits(this._getMarketId(), 0), _userCollateral, _userBorrowed],
|
|
911
911
|
calldata,
|
|
912
912
|
{ ...this.llamalend.options, gasLimit }
|