@curvefi/llamalend-api 1.1.9 → 2.0.0
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/docs/MIGRATION.md +325 -0
- package/docs/SUPPORT_LLv2.md +409 -0
- package/lib/constants/abis/OneWayLendingFactoryV2ABI.json +543 -0
- package/lib/constants/aliases.d.ts +0 -11
- package/lib/constants/aliases.js +1 -86
- package/lib/constants/coins.d.ts +0 -11
- package/lib/constants/coins.js +0 -14
- package/lib/constants/utils.d.ts +2 -0
- package/lib/constants/utils.js +2 -0
- package/lib/index.d.ts +10 -4
- package/lib/interfaces.d.ts +3 -2
- package/lib/lendMarkets/LendMarketTemplate.d.ts +13 -501
- package/lib/lendMarkets/LendMarketTemplate.js +237 -2854
- package/lib/lendMarkets/fetch/fetchFactoryData.d.ts +13 -0
- package/lib/lendMarkets/fetch/fetchFactoryData.js +101 -0
- package/lib/lendMarkets/fetch/fetchLendMarkets.d.ts +3 -0
- package/lib/lendMarkets/fetch/fetchLendMarkets.js +94 -0
- package/lib/lendMarkets/interfaces/common/amm.d.ts +10 -0
- package/lib/lendMarkets/interfaces/common/amm.js +1 -0
- package/lib/lendMarkets/interfaces/common/index.d.ts +5 -0
- package/lib/lendMarkets/interfaces/common/index.js +5 -0
- package/lib/lendMarkets/interfaces/common/prices.d.ts +13 -0
- package/lib/lendMarkets/interfaces/common/prices.js +1 -0
- package/lib/lendMarkets/interfaces/common/userPosition.d.ts +39 -0
- package/lib/lendMarkets/interfaces/common/userPosition.js +1 -0
- package/lib/lendMarkets/interfaces/common/vault.d.ts +55 -0
- package/lib/lendMarkets/interfaces/common/vault.js +1 -0
- package/lib/lendMarkets/interfaces/common/wallet.d.ts +8 -0
- package/lib/lendMarkets/interfaces/common/wallet.js +1 -0
- package/lib/lendMarkets/interfaces/v1/index.d.ts +4 -0
- package/lib/lendMarkets/interfaces/v1/index.js +4 -0
- package/lib/lendMarkets/interfaces/v1/leverageV1.d.ts +90 -0
- package/lib/lendMarkets/interfaces/v1/leverageV1.js +1 -0
- package/lib/lendMarkets/interfaces/v1/loanV1.d.ts +73 -0
- package/lib/lendMarkets/interfaces/v1/loanV1.js +1 -0
- package/lib/lendMarkets/interfaces/v1/statsV1.d.ts +49 -0
- package/lib/lendMarkets/interfaces/v1/statsV1.js +1 -0
- package/lib/lendMarkets/interfaces/v2/index.d.ts +3 -0
- package/lib/lendMarkets/interfaces/v2/index.js +3 -0
- package/lib/lendMarkets/interfaces/v2/leverageV2.d.ts +90 -0
- package/lib/lendMarkets/interfaces/v2/leverageV2.js +1 -0
- package/lib/lendMarkets/interfaces/v2/loanV2.d.ts +73 -0
- package/lib/lendMarkets/interfaces/v2/loanV2.js +1 -0
- package/lib/lendMarkets/interfaces/v2/statsV2.d.ts +49 -0
- package/lib/lendMarkets/interfaces/v2/statsV2.js +1 -0
- package/lib/lendMarkets/lendMarketConstructor.js +1 -1
- package/lib/lendMarkets/modules/common/amm.d.ts +19 -0
- package/lib/lendMarkets/modules/common/amm.js +137 -0
- package/lib/lendMarkets/modules/common/index.d.ts +9 -0
- package/lib/lendMarkets/modules/common/index.js +9 -0
- package/lib/lendMarkets/modules/common/leverageZapV1Base.d.ts +118 -0
- package/lib/lendMarkets/modules/common/leverageZapV1Base.js +770 -0
- package/lib/lendMarkets/modules/{leverageZapV2.d.ts → common/leverageZapV2Base.d.ts} +10 -5
- package/lib/lendMarkets/modules/{leverageZapV2.js → common/leverageZapV2Base.js} +36 -32
- package/lib/lendMarkets/modules/common/loanBase.d.ts +115 -0
- package/lib/lendMarkets/modules/common/loanBase.js +793 -0
- package/lib/lendMarkets/modules/common/prices.d.ts +19 -0
- package/lib/lendMarkets/modules/common/prices.js +104 -0
- package/lib/lendMarkets/modules/common/statsBase.d.ts +69 -0
- package/lib/lendMarkets/modules/common/statsBase.js +291 -0
- package/lib/lendMarkets/modules/common/userPosition.d.ts +46 -0
- package/lib/lendMarkets/modules/common/userPosition.js +223 -0
- package/lib/lendMarkets/modules/common/vault.d.ts +69 -0
- package/lib/lendMarkets/modules/common/vault.js +535 -0
- package/lib/lendMarkets/modules/common/wallet.d.ts +13 -0
- package/lib/lendMarkets/modules/common/wallet.js +28 -0
- package/lib/lendMarkets/modules/index.d.ts +1 -1
- package/lib/lendMarkets/modules/index.js +1 -1
- package/lib/lendMarkets/modules/v1/index.d.ts +4 -0
- package/lib/lendMarkets/modules/v1/index.js +4 -0
- package/lib/lendMarkets/modules/v1/leverageV1ZapV1.d.ts +3 -0
- package/lib/lendMarkets/modules/v1/leverageV1ZapV1.js +3 -0
- package/lib/lendMarkets/modules/v1/leverageV1ZapV2.d.ts +3 -0
- package/lib/lendMarkets/modules/v1/leverageV1ZapV2.js +3 -0
- package/lib/lendMarkets/modules/v1/loanV1.d.ts +4 -0
- package/lib/lendMarkets/modules/v1/loanV1.js +3 -0
- package/lib/lendMarkets/modules/v1/statsV1.d.ts +3 -0
- package/lib/lendMarkets/modules/v1/statsV1.js +3 -0
- package/lib/lendMarkets/modules/v2/index.d.ts +4 -0
- package/lib/lendMarkets/modules/v2/index.js +4 -0
- package/lib/lendMarkets/modules/v2/leverageV2ZapV1.d.ts +3 -0
- package/lib/lendMarkets/modules/v2/leverageV2ZapV1.js +3 -0
- package/lib/lendMarkets/modules/v2/leverageV2ZapV2.d.ts +3 -0
- package/lib/lendMarkets/modules/v2/leverageV2ZapV2.js +3 -0
- package/lib/lendMarkets/modules/v2/loanV2.d.ts +4 -0
- package/lib/lendMarkets/modules/v2/loanV2.js +3 -0
- package/lib/lendMarkets/modules/v2/statsV2.d.ts +3 -0
- package/lib/lendMarkets/modules/v2/statsV2.js +3 -0
- package/lib/llamalend.d.ts +6 -6
- package/lib/llamalend.js +46 -210
- package/lib/utils.js +2 -33
- package/package.json +1 -1
- package/src/constants/abis/OneWayLendingFactoryV2ABI.json +543 -0
- package/src/constants/aliases.ts +1 -97
- package/src/constants/coins.ts +0 -25
- package/src/constants/utils.ts +4 -0
- package/src/interfaces.ts +3 -2
- package/src/lendMarkets/LendMarketTemplate.ts +318 -3214
- package/src/lendMarkets/fetch/fetchFactoryData.ts +113 -0
- package/src/lendMarkets/fetch/fetchLendMarkets.ts +108 -0
- package/src/lendMarkets/interfaces/common/amm.ts +11 -0
- package/src/lendMarkets/interfaces/common/index.ts +5 -0
- package/src/lendMarkets/interfaces/common/prices.ts +13 -0
- package/src/lendMarkets/interfaces/common/userPosition.ts +24 -0
- package/src/lendMarkets/interfaces/common/vault.ts +48 -0
- package/src/lendMarkets/interfaces/common/wallet.ts +3 -0
- package/src/lendMarkets/interfaces/v1/index.ts +4 -0
- package/src/lendMarkets/interfaces/v1/leverageV1.ts +84 -0
- package/src/lendMarkets/interfaces/v1/loanV1.ts +77 -0
- package/src/lendMarkets/interfaces/v1/statsV1.ts +21 -0
- package/src/lendMarkets/interfaces/v2/index.ts +3 -0
- package/src/lendMarkets/interfaces/v2/leverageV2.ts +84 -0
- package/src/lendMarkets/interfaces/v2/loanV2.ts +77 -0
- package/src/lendMarkets/interfaces/v2/statsV2.ts +21 -0
- package/src/lendMarkets/lendMarketConstructor.ts +1 -1
- package/src/lendMarkets/modules/common/amm.ts +132 -0
- package/src/lendMarkets/modules/common/index.ts +9 -0
- package/src/lendMarkets/modules/common/leverageZapV1Base.ts +912 -0
- package/src/lendMarkets/modules/{leverageZapV2.ts → common/leverageZapV2Base.ts} +41 -37
- package/src/lendMarkets/modules/common/loanBase.ts +773 -0
- package/src/lendMarkets/modules/common/prices.ts +111 -0
- package/src/lendMarkets/modules/common/statsBase.ts +313 -0
- package/src/lendMarkets/modules/common/userPosition.ts +243 -0
- package/src/lendMarkets/modules/common/vault.ts +551 -0
- package/src/lendMarkets/modules/common/wallet.ts +29 -0
- package/src/lendMarkets/modules/index.ts +1 -1
- package/src/lendMarkets/modules/v1/index.ts +4 -0
- package/src/lendMarkets/modules/v1/leverageV1ZapV1.ts +3 -0
- package/src/lendMarkets/modules/v1/leverageV1ZapV2.ts +3 -0
- package/src/lendMarkets/modules/v1/loanV1.ts +4 -0
- package/src/lendMarkets/modules/v1/statsV1.ts +3 -0
- package/src/lendMarkets/modules/v2/index.ts +4 -0
- package/src/lendMarkets/modules/v2/leverageV2ZapV1.ts +3 -0
- package/src/lendMarkets/modules/v2/leverageV2ZapV2.ts +3 -0
- package/src/lendMarkets/modules/v2/loanV2.ts +4 -0
- package/src/lendMarkets/modules/v2/statsV2.ts +3 -0
- package/src/llamalend.ts +47 -244
- package/src/utils.ts +2 -35
|
@@ -0,0 +1,535 @@
|
|
|
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
|
+
};
|
|
10
|
+
import memoize from "memoizee";
|
|
11
|
+
import { _getAddress, parseUnits, BN, toBN, ensureAllowance, hasAllowance, ensureAllowanceEstimateGas, formatUnits, smartNumber, _mulBy1_3, _getUsdRate, _ensureAllowance, DIGas, } from "../../../utils";
|
|
12
|
+
import { _getMarketsData } from "../../../external-api";
|
|
13
|
+
import ERC20Abi from '../../../constants/abis/ERC20.json' with { type: 'json' };
|
|
14
|
+
import { WEEK } from "../../../constants/utils";
|
|
15
|
+
export class VaultModule {
|
|
16
|
+
constructor(market) {
|
|
17
|
+
this._calcCrvApr = (...args_1) => __awaiter(this, [...args_1], void 0, function* (futureWorkingSupplyBN = null) {
|
|
18
|
+
const totalLiquidityUSD = yield this.vaultTotalLiquidity();
|
|
19
|
+
if (Number(totalLiquidityUSD) === 0)
|
|
20
|
+
return [0, 0];
|
|
21
|
+
let inflationRateBN, workingSupplyBN, totalSupplyBN;
|
|
22
|
+
if (this.llamalend.chainId !== 1) {
|
|
23
|
+
const gaugeContract = this.llamalend.contracts[this.market.addresses.gauge].multicallContract;
|
|
24
|
+
const lpTokenContract = this.llamalend.contracts[this.market.addresses.vault].multicallContract;
|
|
25
|
+
const crvContract = this.llamalend.contracts[this.llamalend.constants.ALIASES.crv].contract;
|
|
26
|
+
const currentWeek = Math.floor(Date.now() / 1000 / WEEK);
|
|
27
|
+
[inflationRateBN, workingSupplyBN, totalSupplyBN] = (yield this.llamalend.multicallProvider.all([
|
|
28
|
+
gaugeContract.inflation_rate(currentWeek),
|
|
29
|
+
gaugeContract.working_supply(),
|
|
30
|
+
lpTokenContract.totalSupply(),
|
|
31
|
+
])).map((value) => toBN(value));
|
|
32
|
+
if (inflationRateBN.eq(0)) {
|
|
33
|
+
inflationRateBN = toBN(yield crvContract.balanceOf(this.market.addresses.gauge, this.llamalend.constantOptions)).div(WEEK);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const gaugeContract = this.llamalend.contracts[this.market.addresses.gauge].multicallContract;
|
|
38
|
+
const lpTokenContract = this.llamalend.contracts[this.market.addresses.vault].multicallContract;
|
|
39
|
+
const gaugeControllerContract = this.llamalend.contracts[this.llamalend.constants.ALIASES.gauge_controller].multicallContract;
|
|
40
|
+
let weightBN;
|
|
41
|
+
[inflationRateBN, weightBN, workingSupplyBN, totalSupplyBN] = (yield this.llamalend.multicallProvider.all([
|
|
42
|
+
gaugeContract.inflation_rate(),
|
|
43
|
+
gaugeControllerContract.gauge_relative_weight(this.market.addresses.gauge),
|
|
44
|
+
gaugeContract.working_supply(),
|
|
45
|
+
lpTokenContract.totalSupply(),
|
|
46
|
+
])).map((value) => toBN(value));
|
|
47
|
+
inflationRateBN = inflationRateBN.times(weightBN);
|
|
48
|
+
}
|
|
49
|
+
if (inflationRateBN.eq(0))
|
|
50
|
+
return [0, 0];
|
|
51
|
+
if (futureWorkingSupplyBN !== null)
|
|
52
|
+
workingSupplyBN = futureWorkingSupplyBN;
|
|
53
|
+
// If you added 1$ value of LP it would be 0.4$ of working LP. So your annual reward per 1$ in USD is:
|
|
54
|
+
// (annual reward per working liquidity in $) * (0.4$ of working LP)
|
|
55
|
+
const rateBN = inflationRateBN.times(31536000).div(workingSupplyBN).times(totalSupplyBN).div(Number(totalLiquidityUSD)).times(0.4);
|
|
56
|
+
const crvPrice = yield _getUsdRate.call(this.llamalend, this.llamalend.constants.ALIASES.crv);
|
|
57
|
+
const baseApyBN = rateBN.times(crvPrice);
|
|
58
|
+
const boostedApyBN = baseApyBN.times(2.5);
|
|
59
|
+
return [baseApyBN.times(100).toNumber(), boostedApyBN.times(100).toNumber()];
|
|
60
|
+
});
|
|
61
|
+
this.vaultRewardTokens = memoize(() => __awaiter(this, void 0, void 0, function* () {
|
|
62
|
+
if (this.market.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS)
|
|
63
|
+
return [];
|
|
64
|
+
// if (useApi) {
|
|
65
|
+
// const rewards = await _getRewardsFromApi();
|
|
66
|
+
// if (!rewards[this.market.addresses.gauge]) return [];
|
|
67
|
+
// rewards[this.market.addresses.gauge].forEach((r) => _setContracts(r.tokenAddress, ERC20Abi));
|
|
68
|
+
// return rewards[this.market.addresses.gauge].map((r) => ({ token: r.tokenAddress, symbol: r.symbol, decimals: Number(r.decimals) }));
|
|
69
|
+
// }
|
|
70
|
+
const gaugeContract = this.llamalend.contracts[this.market.addresses.gauge].contract;
|
|
71
|
+
const gaugeMulticallContract = this.llamalend.contracts[this.market.addresses.gauge].multicallContract;
|
|
72
|
+
const rewardCount = Number(this.llamalend.formatUnits(yield gaugeContract.reward_count(this.llamalend.constantOptions), 0));
|
|
73
|
+
const tokenCalls = [];
|
|
74
|
+
for (let i = 0; i < rewardCount; i++) {
|
|
75
|
+
tokenCalls.push(gaugeMulticallContract.reward_tokens(i));
|
|
76
|
+
}
|
|
77
|
+
const tokens = (yield this.llamalend.multicallProvider.all(tokenCalls))
|
|
78
|
+
.filter((addr) => addr !== this.llamalend.constants.ZERO_ADDRESS)
|
|
79
|
+
.map((addr) => addr.toLowerCase())
|
|
80
|
+
.filter((addr) => this.llamalend.chainId === 1 || addr !== this.llamalend.constants.COINS.crv);
|
|
81
|
+
const tokenInfoCalls = [];
|
|
82
|
+
for (const token of tokens) {
|
|
83
|
+
this.llamalend.setContract(token, ERC20Abi);
|
|
84
|
+
const tokenMulticallContract = this.llamalend.contracts[token].multicallContract;
|
|
85
|
+
tokenInfoCalls.push(tokenMulticallContract.symbol(), tokenMulticallContract.decimals());
|
|
86
|
+
}
|
|
87
|
+
const tokenInfo = yield this.llamalend.multicallProvider.all(tokenInfoCalls);
|
|
88
|
+
for (let i = 0; i < tokens.length; i++) {
|
|
89
|
+
this.llamalend.constants.DECIMALS[tokens[i]] = Number(tokenInfo[(i * 2) + 1]);
|
|
90
|
+
}
|
|
91
|
+
return tokens.map((token, i) => ({ token, symbol: tokenInfo[i * 2], decimals: Number(tokenInfo[(i * 2) + 1]) }));
|
|
92
|
+
}), {
|
|
93
|
+
promise: true,
|
|
94
|
+
maxAge: 30 * 60 * 1000, // 30m
|
|
95
|
+
});
|
|
96
|
+
this.vaultRewardsApr = (...args_1) => __awaiter(this, [...args_1], void 0, function* (useApi = true) {
|
|
97
|
+
if (useApi) {
|
|
98
|
+
const response = yield _getMarketsData(this.llamalend.constants.NETWORK_NAME);
|
|
99
|
+
const market = response.lendingVaultData.find((item) => item.address.toLowerCase() === this.market.addresses.vault.toLowerCase());
|
|
100
|
+
if (market) {
|
|
101
|
+
return market.gaugeRewards;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
throw new Error('Market not found in API');
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
if (this.market.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS)
|
|
109
|
+
return [];
|
|
110
|
+
// const isDisabledChain = [1313161554].includes(this.llamalend.chainId); // Disable Aurora
|
|
111
|
+
// if (useApi && !isDisabledChain) {
|
|
112
|
+
// const rewards = await _getRewardsFromApi();
|
|
113
|
+
// if (!rewards[this.market.addresses.gauge]) return [];
|
|
114
|
+
// return rewards[this.market.addresses.gauge].map((r) => ({ gaugeAddress: r.gaugeAddress, tokenAddress: r.tokenAddress, symbol: r.symbol, apy: r.apy }));
|
|
115
|
+
// }
|
|
116
|
+
const apy = [];
|
|
117
|
+
const rewardTokens = yield this.vaultRewardTokens();
|
|
118
|
+
for (const rewardToken of rewardTokens) {
|
|
119
|
+
const gaugeContract = this.llamalend.contracts[this.market.addresses.gauge].multicallContract;
|
|
120
|
+
const lpTokenContract = this.llamalend.contracts[this.market.addresses.vault].multicallContract;
|
|
121
|
+
const rewardContract = this.llamalend.contracts[this.market.addresses.gauge].multicallContract;
|
|
122
|
+
const totalLiquidityUSD = yield this.vaultTotalLiquidity();
|
|
123
|
+
const rewardRate = yield _getUsdRate.call(this.llamalend, rewardToken.token);
|
|
124
|
+
const [rewardData, _stakedSupply, _totalSupply] = yield this.llamalend.multicallProvider.all([
|
|
125
|
+
rewardContract.reward_data(rewardToken.token),
|
|
126
|
+
gaugeContract.totalSupply(),
|
|
127
|
+
lpTokenContract.totalSupply(),
|
|
128
|
+
]);
|
|
129
|
+
const stakedSupplyBN = toBN(_stakedSupply);
|
|
130
|
+
const totalSupplyBN = toBN(_totalSupply);
|
|
131
|
+
const inflationBN = toBN(rewardData.rate, rewardToken.decimals);
|
|
132
|
+
const periodFinish = Number(this.llamalend.formatUnits(rewardData.period_finish, 0)) * 1000;
|
|
133
|
+
const baseApy = periodFinish > Date.now() ?
|
|
134
|
+
inflationBN.times(31536000).times(rewardRate).div(stakedSupplyBN).times(totalSupplyBN).div(Number(totalLiquidityUSD)) :
|
|
135
|
+
BN(0);
|
|
136
|
+
apy.push({
|
|
137
|
+
gaugeAddress: this.market.addresses.gauge,
|
|
138
|
+
tokenAddress: rewardToken.token,
|
|
139
|
+
symbol: rewardToken.symbol,
|
|
140
|
+
apy: baseApy.times(100).toNumber(),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return apy;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
this.market = market;
|
|
147
|
+
this.llamalend = market.getLlamalend();
|
|
148
|
+
}
|
|
149
|
+
vaultMaxDeposit() {
|
|
150
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
151
|
+
address = _getAddress.call(this.llamalend, address);
|
|
152
|
+
// const _amount = await this.llamalend.contracts[this.market.addresses.vault].contract.maxDeposit(address); TODO use maxDeposit
|
|
153
|
+
const _amount = yield this.llamalend.contracts[this.market.addresses.borrowed_token].contract.balanceOf(address);
|
|
154
|
+
return formatUnits(_amount, this.market.borrowed_token.decimals);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
vaultPreviewDeposit(amount) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const _amount = parseUnits(amount, this.market.borrowed_token.decimals);
|
|
160
|
+
const _shares = yield this.llamalend.contracts[this.market.addresses.vault].contract.previewDeposit(_amount);
|
|
161
|
+
return formatUnits(_shares, 18);
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
vaultDepositIsApproved(borrowed) {
|
|
165
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
166
|
+
return yield hasAllowance.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.llamalend.signerAddress, this.market.addresses.vault);
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
vaultDepositApproveEstimateGas(borrowed) {
|
|
170
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
171
|
+
return yield ensureAllowanceEstimateGas.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.market.addresses.vault);
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
vaultDepositApprove(borrowed) {
|
|
175
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
+
return yield ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.market.addresses.vault);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
_vaultDeposit(amount_1) {
|
|
180
|
+
return __awaiter(this, arguments, void 0, function* (amount, estimateGas = false) {
|
|
181
|
+
const _amount = parseUnits(amount, this.market.borrowed_token.decimals);
|
|
182
|
+
const gas = yield this.llamalend.contracts[this.market.addresses.vault].contract.deposit.estimateGas(_amount, Object.assign({}, this.llamalend.constantOptions));
|
|
183
|
+
if (estimateGas)
|
|
184
|
+
return smartNumber(gas);
|
|
185
|
+
yield this.llamalend.updateFeeData();
|
|
186
|
+
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
187
|
+
return (yield this.llamalend.contracts[this.market.addresses.vault].contract.deposit(_amount, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
vaultDepositEstimateGas(amount) {
|
|
191
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
+
if (!(yield this.vaultDepositIsApproved(amount)))
|
|
193
|
+
throw Error("Approval is needed for gas estimation");
|
|
194
|
+
return yield this._vaultDeposit(amount, true);
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
vaultDeposit(amount) {
|
|
198
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
+
yield this.vaultDepositApprove(amount);
|
|
200
|
+
return yield this._vaultDeposit(amount, false);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
vaultMaxMint() {
|
|
204
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
205
|
+
address = _getAddress.call(this.llamalend, address);
|
|
206
|
+
// const _shares = await this.llamalend.contracts[this.market.addresses.vault].contract.maxMint(address); TODO use maxMint
|
|
207
|
+
const _assetBalance = yield this.llamalend.contracts[this.market.addresses.borrowed_token].contract.balanceOf(address);
|
|
208
|
+
const _shares = yield this.llamalend.contracts[this.market.addresses.vault].contract.convertToShares(_assetBalance);
|
|
209
|
+
return formatUnits(_shares, 18);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
vaultPreviewMint(amount) {
|
|
213
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
const _amount = parseUnits(amount, 18);
|
|
215
|
+
const _assets = yield this.llamalend.contracts[this.market.addresses.vault].contract.previewMint(_amount);
|
|
216
|
+
return formatUnits(_assets, this.market.borrowed_token.decimals);
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
vaultMintIsApproved(borrowed) {
|
|
220
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
221
|
+
return yield hasAllowance.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.llamalend.signerAddress, this.market.addresses.vault);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
vaultMintApproveEstimateGas(borrowed) {
|
|
225
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
226
|
+
return yield ensureAllowanceEstimateGas.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.market.addresses.vault);
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
vaultMintApprove(borrowed) {
|
|
230
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
231
|
+
return yield ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.market.addresses.vault);
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
_vaultMint(amount_1) {
|
|
235
|
+
return __awaiter(this, arguments, void 0, function* (amount, estimateGas = false) {
|
|
236
|
+
const _amount = parseUnits(amount, 18);
|
|
237
|
+
const gas = yield this.llamalend.contracts[this.market.addresses.vault].contract.mint.estimateGas(_amount, Object.assign({}, this.llamalend.constantOptions));
|
|
238
|
+
if (estimateGas)
|
|
239
|
+
return smartNumber(gas);
|
|
240
|
+
yield this.llamalend.updateFeeData();
|
|
241
|
+
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
242
|
+
return (yield this.llamalend.contracts[this.market.addresses.vault].contract.mint(_amount, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
vaultMintEstimateGas(amount) {
|
|
246
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
247
|
+
if (!(yield this.vaultMintIsApproved(amount)))
|
|
248
|
+
throw Error("Approval is needed for gas estimation");
|
|
249
|
+
return yield this._vaultMint(amount, true);
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
vaultMint(amount) {
|
|
253
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
yield this.vaultMintApprove(amount);
|
|
255
|
+
return yield this._vaultMint(amount, false);
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
vaultMaxWithdraw() {
|
|
259
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
260
|
+
address = _getAddress.call(this.llamalend, address);
|
|
261
|
+
const _assets = yield this.llamalend.contracts[this.market.addresses.vault].contract.maxWithdraw(address);
|
|
262
|
+
return formatUnits(_assets, this.market.borrowed_token.decimals);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
vaultPreviewWithdraw(amount) {
|
|
266
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
267
|
+
const _amount = parseUnits(amount, this.market.borrowed_token.decimals);
|
|
268
|
+
const _shares = yield this.llamalend.contracts[this.market.addresses.vault].contract.previewWithdraw(_amount);
|
|
269
|
+
return formatUnits(_shares, 18);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
_vaultWithdraw(amount_1) {
|
|
273
|
+
return __awaiter(this, arguments, void 0, function* (amount, estimateGas = false) {
|
|
274
|
+
const _amount = parseUnits(amount, this.market.borrowed_token.decimals);
|
|
275
|
+
const gas = yield this.llamalend.contracts[this.market.addresses.vault].contract.withdraw.estimateGas(_amount, Object.assign({}, this.llamalend.constantOptions));
|
|
276
|
+
if (estimateGas)
|
|
277
|
+
return smartNumber(gas);
|
|
278
|
+
yield this.llamalend.updateFeeData();
|
|
279
|
+
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
280
|
+
return (yield this.llamalend.contracts[this.market.addresses.vault].contract.withdraw(_amount, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
vaultWithdrawEstimateGas(amount) {
|
|
284
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
285
|
+
return yield this._vaultWithdraw(amount, true);
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
vaultWithdraw(amount) {
|
|
289
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
+
return yield this._vaultWithdraw(amount, false);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
vaultMaxRedeem() {
|
|
294
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
295
|
+
address = _getAddress.call(this.llamalend, address);
|
|
296
|
+
const _shares = yield this.llamalend.contracts[this.market.addresses.vault].contract.maxRedeem(address);
|
|
297
|
+
return formatUnits(_shares, 18);
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
vaultPreviewRedeem(amount) {
|
|
301
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
302
|
+
const _amount = parseUnits(amount, 18);
|
|
303
|
+
const _assets = yield this.llamalend.contracts[this.market.addresses.vault].contract.previewRedeem(_amount);
|
|
304
|
+
return formatUnits(_assets, this.market.borrowed_token.decimals);
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
_vaultRedeem(amount_1) {
|
|
308
|
+
return __awaiter(this, arguments, void 0, function* (amount, estimateGas = false) {
|
|
309
|
+
const _amount = parseUnits(amount, 18);
|
|
310
|
+
const gas = yield this.llamalend.contracts[this.market.addresses.vault].contract.redeem.estimateGas(_amount, Object.assign({}, this.llamalend.constantOptions));
|
|
311
|
+
if (estimateGas)
|
|
312
|
+
return smartNumber(gas);
|
|
313
|
+
yield this.llamalend.updateFeeData();
|
|
314
|
+
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
315
|
+
return (yield this.llamalend.contracts[this.market.addresses.vault].contract.redeem(_amount, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
vaultRedeemEstimateGas(amount) {
|
|
319
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
+
return yield this._vaultRedeem(amount, true);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
vaultRedeem(amount) {
|
|
324
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
325
|
+
return yield this._vaultRedeem(amount, false);
|
|
326
|
+
});
|
|
327
|
+
}
|
|
328
|
+
// ---------------- VAULT UTILS ----------------
|
|
329
|
+
vaultConvertToShares(assets) {
|
|
330
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
331
|
+
const _assets = parseUnits(assets, this.market.borrowed_token.decimals);
|
|
332
|
+
const _shares = yield this.llamalend.contracts[this.market.addresses.vault].contract.convertToShares(_assets);
|
|
333
|
+
return this.llamalend.formatUnits(_shares);
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
vaultConvertToAssets(shares) {
|
|
337
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
338
|
+
const _shares = parseUnits(shares);
|
|
339
|
+
const _assets = yield this.llamalend.contracts[this.market.addresses.vault].contract.convertToAssets(_shares);
|
|
340
|
+
return this.llamalend.formatUnits(_assets, this.market.borrowed_token.decimals);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
// ---------------- VAULT STAKING ----------------
|
|
344
|
+
vaultStakeIsApproved(vaultShares) {
|
|
345
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
346
|
+
if (this.market.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS) {
|
|
347
|
+
throw Error(`stakeIsApproved method doesn't exist for pool ${this.market.name} (id: ${this.market.name}). There is no gauge`);
|
|
348
|
+
}
|
|
349
|
+
return yield hasAllowance.call(this.llamalend, [this.market.addresses.vault], [vaultShares], this.llamalend.signerAddress, this.market.addresses.gauge);
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
vaultStakeApproveEstimateGas(vaultShares) {
|
|
353
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
354
|
+
if (this.market.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS) {
|
|
355
|
+
throw Error(`stakeApproveEstimateGas method doesn't exist for pool ${this.market.name} (id: ${this.market.name}). There is no gauge`);
|
|
356
|
+
}
|
|
357
|
+
return yield ensureAllowanceEstimateGas.call(this.llamalend, [this.market.addresses.vault], [vaultShares], this.market.addresses.gauge);
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
vaultStakeApprove(vaultShares) {
|
|
361
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
362
|
+
if (this.market.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS) {
|
|
363
|
+
throw Error(`stakeApprove method doesn't exist for pool ${this.market.name} (id: ${this.market.name}). There is no gauge`);
|
|
364
|
+
}
|
|
365
|
+
return yield ensureAllowance.call(this.llamalend, [this.market.addresses.vault], [vaultShares], this.market.addresses.gauge);
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
vaultStakeEstimateGas(vaultShares) {
|
|
369
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
370
|
+
if (this.market.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS) {
|
|
371
|
+
throw Error(`stakeEstimateGas method doesn't exist for pool ${this.market.name} (id: ${this.market.name}). There is no gauge`);
|
|
372
|
+
}
|
|
373
|
+
const _vaultShares = parseUnits(vaultShares);
|
|
374
|
+
return smartNumber(yield this.llamalend.contracts[this.market.addresses.gauge].contract.deposit.estimateGas(_vaultShares, this.llamalend.constantOptions));
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
vaultStake(vaultShares) {
|
|
378
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
379
|
+
if (this.market.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS) {
|
|
380
|
+
throw Error(`stake method doesn't exist for pool ${this.market.name} (id: ${this.market.name}). There is no gauge`);
|
|
381
|
+
}
|
|
382
|
+
const _vaultShares = parseUnits(vaultShares);
|
|
383
|
+
yield _ensureAllowance.call(this.llamalend, [this.market.addresses.vault], [_vaultShares], this.market.addresses.gauge);
|
|
384
|
+
yield this.llamalend.updateFeeData();
|
|
385
|
+
const gasLimit = _mulBy1_3(DIGas(yield this.llamalend.contracts[this.market.addresses.gauge].contract.deposit.estimateGas(_vaultShares, this.llamalend.constantOptions)));
|
|
386
|
+
return (yield this.llamalend.contracts[this.market.addresses.gauge].contract.deposit(_vaultShares, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
387
|
+
});
|
|
388
|
+
}
|
|
389
|
+
vaultUnstakeEstimateGas(vaultShares) {
|
|
390
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
391
|
+
if (this.market.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS) {
|
|
392
|
+
throw Error(`unstakeEstimateGas method doesn't exist for pool ${this.market.name} (id: ${this.market.name}). There is no gauge`);
|
|
393
|
+
}
|
|
394
|
+
const _vaultShares = parseUnits(vaultShares);
|
|
395
|
+
return smartNumber(yield this.llamalend.contracts[this.market.addresses.gauge].contract.withdraw.estimateGas(_vaultShares, this.llamalend.constantOptions));
|
|
396
|
+
});
|
|
397
|
+
}
|
|
398
|
+
vaultUnstake(vaultShares) {
|
|
399
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
400
|
+
if (this.market.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS) {
|
|
401
|
+
throw Error(`unstake method doesn't exist for pool ${this.market.name} (id: ${this.market.name}). There is no gauge`);
|
|
402
|
+
}
|
|
403
|
+
const _vaultShares = parseUnits(vaultShares);
|
|
404
|
+
yield this.llamalend.updateFeeData();
|
|
405
|
+
const gasLimit = _mulBy1_3(DIGas((yield this.llamalend.contracts[this.market.addresses.gauge].contract.withdraw.estimateGas(_vaultShares, this.llamalend.constantOptions))));
|
|
406
|
+
return (yield this.llamalend.contracts[this.market.addresses.gauge].contract.withdraw(_vaultShares, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
// ---------------- VAULT STAKING REWARDS ----------------
|
|
410
|
+
vaultRewardsOnly() {
|
|
411
|
+
if (this.market.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS)
|
|
412
|
+
throw Error(`${this.market.name} doesn't have gauge`);
|
|
413
|
+
const gaugeContract = this.llamalend.contracts[this.market.addresses.gauge].contract;
|
|
414
|
+
return !('inflation_rate()' in gaugeContract || 'inflation_rate(uint256)' in gaugeContract);
|
|
415
|
+
}
|
|
416
|
+
vaultTotalLiquidity() {
|
|
417
|
+
return __awaiter(this, arguments, void 0, function* (useAPI = true) {
|
|
418
|
+
const { cap } = yield this.market.stats.capAndAvailable(true, useAPI);
|
|
419
|
+
const price = yield _getUsdRate.call(this.llamalend, this.market.addresses.borrowed_token);
|
|
420
|
+
return BN(cap).times(price).toFixed(6);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
vaultCrvApr() {
|
|
424
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
425
|
+
if (this.vaultRewardsOnly())
|
|
426
|
+
throw Error(`${this.market.name} has Rewards-Only Gauge. Use stats.rewardsApy instead`);
|
|
427
|
+
// const isDisabledChain = [1313161554].includes(this.llamalend.chainId); // Disable Aurora
|
|
428
|
+
// if (useApi && !isDisabledChain) {
|
|
429
|
+
// const crvAPYs = await _getCrvApyFromApi();
|
|
430
|
+
// const poolCrvApy = crvAPYs[this.market.addresses.gauge] ?? [0, 0]; // new pools might be missing
|
|
431
|
+
// return [poolCrvApy[0], poolCrvApy[1]];
|
|
432
|
+
// }
|
|
433
|
+
return yield this._calcCrvApr();
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
vaultClaimableCrv() {
|
|
437
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
438
|
+
if (this.vaultRewardsOnly())
|
|
439
|
+
throw Error(`${this.market.name} has Rewards-Only Gauge. Use claimableRewards instead`);
|
|
440
|
+
address = address || this.llamalend.signerAddress;
|
|
441
|
+
if (!address)
|
|
442
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
443
|
+
return this.llamalend.formatUnits(yield this.llamalend.contracts[this.market.addresses.gauge].contract.claimable_tokens(address, this.llamalend.constantOptions));
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
_vaultClaimCrv(estimateGas) {
|
|
447
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
448
|
+
if (this.vaultRewardsOnly())
|
|
449
|
+
throw Error(`${this.market.name} has Rewards-Only Gauge. Use claimRewards instead`);
|
|
450
|
+
let isOldFactory = false;
|
|
451
|
+
let contract;
|
|
452
|
+
if (this.llamalend.chainId !== 1) {
|
|
453
|
+
if (this.llamalend.constants.ALIASES.gauge_factory_old && this.llamalend.constants.ALIASES.gauge_factory_old !== this.llamalend.constants.ZERO_ADDRESS) {
|
|
454
|
+
const oldFactoryContract = this.llamalend.contracts[this.llamalend.constants.ALIASES.gauge_factory_old].contract;
|
|
455
|
+
const lpToken = yield this.llamalend.contracts[this.market.addresses.gauge].contract.lp_token();
|
|
456
|
+
const gaugeAddress = yield oldFactoryContract.get_gauge_from_lp_token(lpToken);
|
|
457
|
+
isOldFactory = gaugeAddress.toLowerCase() === this.market.addresses.gauge.toLowerCase();
|
|
458
|
+
if (isOldFactory) {
|
|
459
|
+
contract = oldFactoryContract;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
if (!isOldFactory) {
|
|
464
|
+
contract = this.llamalend.contracts[this.llamalend.constants.ALIASES.minter].contract;
|
|
465
|
+
}
|
|
466
|
+
if (!contract) {
|
|
467
|
+
throw Error(`${this.market.name} couldn't match gauge factory`);
|
|
468
|
+
}
|
|
469
|
+
const gas = yield contract.mint.estimateGas(this.market.addresses.gauge, this.llamalend.constantOptions);
|
|
470
|
+
if (estimateGas)
|
|
471
|
+
return smartNumber(gas);
|
|
472
|
+
yield this.llamalend.updateFeeData();
|
|
473
|
+
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
474
|
+
return (yield contract.mint(this.market.addresses.gauge, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
vaultClaimCrvEstimateGas() {
|
|
478
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
479
|
+
return yield this._vaultClaimCrv(true);
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
vaultClaimCrv() {
|
|
483
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
484
|
+
return yield this._vaultClaimCrv(false);
|
|
485
|
+
});
|
|
486
|
+
}
|
|
487
|
+
vaultClaimableRewards() {
|
|
488
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
489
|
+
if (this.market.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS) {
|
|
490
|
+
throw Error(`claimableRewards method doesn't exist for pool ${this.market.name} (id: ${this.market.name}). There is no gauge`);
|
|
491
|
+
}
|
|
492
|
+
address = address || this.llamalend.signerAddress;
|
|
493
|
+
if (!address)
|
|
494
|
+
throw Error("Need to connect wallet or pass address into args");
|
|
495
|
+
const gaugeContract = this.llamalend.contracts[this.market.addresses.gauge].contract;
|
|
496
|
+
const rewardTokens = yield this.vaultRewardTokens();
|
|
497
|
+
const rewards = [];
|
|
498
|
+
for (const rewardToken of rewardTokens) {
|
|
499
|
+
const _amount = yield gaugeContract.claimable_reward(address, rewardToken.token, this.llamalend.constantOptions);
|
|
500
|
+
rewards.push({
|
|
501
|
+
token: rewardToken.token,
|
|
502
|
+
symbol: rewardToken.symbol,
|
|
503
|
+
amount: this.llamalend.formatUnits(_amount, rewardToken.decimals),
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
return rewards;
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
_vaultClaimRewards(estimateGas) {
|
|
510
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
511
|
+
if (this.market.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS) {
|
|
512
|
+
throw Error(`claimRewards method doesn't exist for pool ${this.market.name} (id: ${this.market.name}). There is no gauge`);
|
|
513
|
+
}
|
|
514
|
+
const gaugeContract = this.llamalend.contracts[this.market.addresses.gauge].contract;
|
|
515
|
+
if (!("claim_rewards()" in gaugeContract))
|
|
516
|
+
throw Error(`${this.market.name} pool doesn't have such method`);
|
|
517
|
+
const gas = yield gaugeContract.claim_rewards.estimateGas(this.llamalend.constantOptions);
|
|
518
|
+
if (estimateGas)
|
|
519
|
+
return smartNumber(gas);
|
|
520
|
+
yield this.llamalend.updateFeeData();
|
|
521
|
+
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
522
|
+
return (yield gaugeContract.claim_rewards(Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
vaultClaimRewardsEstimateGas() {
|
|
526
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
527
|
+
return yield this._vaultClaimRewards(true);
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
vaultClaimRewards() {
|
|
531
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
532
|
+
return yield this._vaultClaimRewards(false);
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { LendMarketTemplate } from "../../LendMarketTemplate";
|
|
2
|
+
import { IWallet } from "../../interfaces/common";
|
|
3
|
+
export declare class WalletModule implements IWallet {
|
|
4
|
+
private market;
|
|
5
|
+
private llamalend;
|
|
6
|
+
constructor(market: LendMarketTemplate);
|
|
7
|
+
balances(address?: string): Promise<{
|
|
8
|
+
collateral: string;
|
|
9
|
+
borrowed: string;
|
|
10
|
+
vaultShares: string;
|
|
11
|
+
gauge: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
};
|
|
10
|
+
import { getBalances, } from "../../../utils";
|
|
11
|
+
export class WalletModule {
|
|
12
|
+
constructor(market) {
|
|
13
|
+
this.market = market;
|
|
14
|
+
this.llamalend = market.getLlamalend();
|
|
15
|
+
}
|
|
16
|
+
balances() {
|
|
17
|
+
return __awaiter(this, arguments, void 0, function* (address = "") {
|
|
18
|
+
if (this.market.addresses.gauge === this.llamalend.constants.ZERO_ADDRESS) {
|
|
19
|
+
const [collateral, borrowed, vaultShares] = yield getBalances.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address, this.market.addresses.vault], address);
|
|
20
|
+
return { collateral, borrowed, vaultShares, gauge: "0" };
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
const [collateral, borrowed, vaultShares, gauge] = yield getBalances.call(this.llamalend, [this.market.collateral_token.address, this.market.borrowed_token.address, this.market.addresses.vault, this.market.addresses.gauge], address);
|
|
24
|
+
return { collateral, borrowed, vaultShares, gauge };
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { LeverageV1ZapV2Module } from './v1/leverageV1ZapV2';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { LeverageV1ZapV2Module } from './v1/leverageV1ZapV2';
|