@curvefi/llamalend-api 2.3.2 → 2.3.3
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/lendMarkets/interfaces/common/vault.d.ts +14 -14
- package/lib/lendMarkets/modules/common/vault.d.ts +12 -12
- package/lib/lendMarkets/modules/common/vault.js +40 -40
- package/lib/st-crvUSD.js +2 -2
- package/lib/utils.js +3 -3
- package/package.json +4 -5
- package/src/lendMarkets/interfaces/common/vault.ts +14 -14
- package/src/lendMarkets/modules/common/vault.ts +36 -36
- package/src/st-crvUSD.ts +2 -2
- package/src/utils.ts +3 -3
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { IReward, TAmount, TGas } from "../../../interfaces";
|
|
2
2
|
export interface IVault {
|
|
3
3
|
maxDeposit: (address?: string) => Promise<string>;
|
|
4
|
-
previewDeposit: (
|
|
4
|
+
previewDeposit: (borrowed: TAmount) => Promise<string>;
|
|
5
5
|
depositIsApproved: (borrowed: TAmount) => Promise<boolean>;
|
|
6
6
|
depositApprove: (borrowed: TAmount) => Promise<string[]>;
|
|
7
|
-
deposit: (
|
|
7
|
+
deposit: (borrowed: TAmount) => Promise<string>;
|
|
8
8
|
maxMint: (address?: string) => Promise<string>;
|
|
9
|
-
previewMint: (
|
|
9
|
+
previewMint: (shares: TAmount) => Promise<string>;
|
|
10
10
|
mintIsApproved: (borrowed: TAmount) => Promise<boolean>;
|
|
11
11
|
mintApprove: (borrowed: TAmount) => Promise<string[]>;
|
|
12
|
-
mint: (
|
|
12
|
+
mint: (shares: TAmount) => Promise<string>;
|
|
13
13
|
maxWithdraw: (address?: string) => Promise<string>;
|
|
14
|
-
previewWithdraw: (
|
|
15
|
-
withdraw: (
|
|
14
|
+
previewWithdraw: (borrowed: TAmount) => Promise<string>;
|
|
15
|
+
withdraw: (borrowed: TAmount) => Promise<string>;
|
|
16
16
|
maxRedeem: (address?: string) => Promise<string>;
|
|
17
|
-
previewRedeem: (
|
|
18
|
-
redeem: (
|
|
17
|
+
previewRedeem: (shares: TAmount) => Promise<string>;
|
|
18
|
+
redeem: (shares: TAmount) => Promise<string>;
|
|
19
19
|
convertToShares: (assets: TAmount) => Promise<string>;
|
|
20
20
|
convertToAssets: (shares: TAmount) => Promise<string>;
|
|
21
21
|
stakeIsApproved: (vaultShares: number | string) => Promise<boolean>;
|
|
@@ -40,12 +40,12 @@ export interface IVault {
|
|
|
40
40
|
}[]>;
|
|
41
41
|
claimRewards: () => Promise<string>;
|
|
42
42
|
estimateGas: {
|
|
43
|
-
depositApprove: (
|
|
44
|
-
deposit: (
|
|
45
|
-
mintApprove: (
|
|
46
|
-
mint: (
|
|
47
|
-
withdraw: (
|
|
48
|
-
redeem: (
|
|
43
|
+
depositApprove: (borrowed: TAmount) => Promise<TGas>;
|
|
44
|
+
deposit: (borrowed: TAmount) => Promise<TGas>;
|
|
45
|
+
mintApprove: (borrowed: TAmount) => Promise<TGas>;
|
|
46
|
+
mint: (shares: TAmount) => Promise<TGas>;
|
|
47
|
+
withdraw: (borrowed: TAmount) => Promise<TGas>;
|
|
48
|
+
redeem: (shares: TAmount) => Promise<TGas>;
|
|
49
49
|
stakeApprove: (vaultShares: number | string) => Promise<TGas>;
|
|
50
50
|
stake: (vaultShares: number | string) => Promise<TGas>;
|
|
51
51
|
unstake: (vaultShares: number | string) => Promise<TGas>;
|
|
@@ -6,31 +6,31 @@ export declare class VaultModule {
|
|
|
6
6
|
private llamalend;
|
|
7
7
|
constructor(market: LendMarketTemplate);
|
|
8
8
|
vaultMaxDeposit(address?: string): Promise<string>;
|
|
9
|
-
vaultPreviewDeposit(
|
|
9
|
+
vaultPreviewDeposit(borrowed: TAmount): Promise<string>;
|
|
10
10
|
vaultDepositIsApproved(borrowed: TAmount): Promise<boolean>;
|
|
11
11
|
vaultDepositApproveEstimateGas(borrowed: TAmount): Promise<TGas>;
|
|
12
12
|
vaultDepositApprove(borrowed: TAmount): Promise<string[]>;
|
|
13
13
|
private _vaultDeposit;
|
|
14
|
-
vaultDepositEstimateGas(
|
|
15
|
-
vaultDeposit(
|
|
14
|
+
vaultDepositEstimateGas(borrowed: TAmount): Promise<TGas>;
|
|
15
|
+
vaultDeposit(borrowed: TAmount): Promise<string>;
|
|
16
16
|
vaultMaxMint(address?: string): Promise<string>;
|
|
17
|
-
vaultPreviewMint(
|
|
17
|
+
vaultPreviewMint(shares: TAmount): Promise<string>;
|
|
18
18
|
vaultMintIsApproved(borrowed: TAmount): Promise<boolean>;
|
|
19
19
|
vaultMintApproveEstimateGas(borrowed: TAmount): Promise<TGas>;
|
|
20
20
|
vaultMintApprove(borrowed: TAmount): Promise<string[]>;
|
|
21
21
|
private _vaultMint;
|
|
22
|
-
vaultMintEstimateGas(
|
|
23
|
-
vaultMint(
|
|
22
|
+
vaultMintEstimateGas(shares: TAmount): Promise<TGas>;
|
|
23
|
+
vaultMint(shares: TAmount): Promise<string>;
|
|
24
24
|
vaultMaxWithdraw(address?: string): Promise<string>;
|
|
25
|
-
vaultPreviewWithdraw(
|
|
25
|
+
vaultPreviewWithdraw(borrowed: TAmount): Promise<string>;
|
|
26
26
|
private _vaultWithdraw;
|
|
27
|
-
vaultWithdrawEstimateGas(
|
|
28
|
-
vaultWithdraw(
|
|
27
|
+
vaultWithdrawEstimateGas(borrowed: TAmount): Promise<TGas>;
|
|
28
|
+
vaultWithdraw(borrowed: TAmount): Promise<string>;
|
|
29
29
|
vaultMaxRedeem(address?: string): Promise<string>;
|
|
30
|
-
vaultPreviewRedeem(
|
|
30
|
+
vaultPreviewRedeem(shares: TAmount): Promise<string>;
|
|
31
31
|
private _vaultRedeem;
|
|
32
|
-
vaultRedeemEstimateGas(
|
|
33
|
-
vaultRedeem(
|
|
32
|
+
vaultRedeemEstimateGas(shares: TAmount): Promise<TGas>;
|
|
33
|
+
vaultRedeem(shares: TAmount): Promise<string>;
|
|
34
34
|
vaultConvertToShares(assets: TAmount): Promise<string>;
|
|
35
35
|
vaultConvertToAssets(shares: TAmount): Promise<string>;
|
|
36
36
|
vaultStakeIsApproved(vaultShares: number | string): Promise<boolean>;
|
|
@@ -154,9 +154,9 @@ export class VaultModule {
|
|
|
154
154
|
return formatUnits(_amount, this.market.borrowed_token.decimals);
|
|
155
155
|
});
|
|
156
156
|
}
|
|
157
|
-
vaultPreviewDeposit(
|
|
157
|
+
vaultPreviewDeposit(borrowed) {
|
|
158
158
|
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
const _amount = parseUnits(
|
|
159
|
+
const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
|
|
160
160
|
const _shares = yield this.llamalend.contracts[this.market.addresses.vault].contract.previewDeposit(_amount);
|
|
161
161
|
return formatUnits(_shares, 18);
|
|
162
162
|
});
|
|
@@ -176,9 +176,9 @@ export class VaultModule {
|
|
|
176
176
|
return yield ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.market.addresses.vault);
|
|
177
177
|
});
|
|
178
178
|
}
|
|
179
|
-
_vaultDeposit(
|
|
180
|
-
return __awaiter(this, arguments, void 0, function* (
|
|
181
|
-
const _amount = parseUnits(
|
|
179
|
+
_vaultDeposit(borrowed_1) {
|
|
180
|
+
return __awaiter(this, arguments, void 0, function* (borrowed, estimateGas = false) {
|
|
181
|
+
const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
|
|
182
182
|
const gas = yield this.llamalend.contracts[this.market.addresses.vault].contract.deposit.estimateGas(_amount, Object.assign({}, this.llamalend.constantOptions));
|
|
183
183
|
if (estimateGas)
|
|
184
184
|
return smartNumber(gas);
|
|
@@ -187,17 +187,17 @@ export class VaultModule {
|
|
|
187
187
|
return (yield this.llamalend.contracts[this.market.addresses.vault].contract.deposit(_amount, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
188
188
|
});
|
|
189
189
|
}
|
|
190
|
-
vaultDepositEstimateGas(
|
|
190
|
+
vaultDepositEstimateGas(borrowed) {
|
|
191
191
|
return __awaiter(this, void 0, void 0, function* () {
|
|
192
|
-
if (!(yield this.vaultDepositIsApproved(
|
|
192
|
+
if (!(yield this.vaultDepositIsApproved(borrowed)))
|
|
193
193
|
throw Error("Approval is needed for gas estimation");
|
|
194
|
-
return yield this._vaultDeposit(
|
|
194
|
+
return yield this._vaultDeposit(borrowed, true);
|
|
195
195
|
});
|
|
196
196
|
}
|
|
197
|
-
vaultDeposit(
|
|
197
|
+
vaultDeposit(borrowed) {
|
|
198
198
|
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
yield this.vaultDepositApprove(
|
|
200
|
-
return yield this._vaultDeposit(
|
|
199
|
+
yield this.vaultDepositApprove(borrowed);
|
|
200
|
+
return yield this._vaultDeposit(borrowed, false);
|
|
201
201
|
});
|
|
202
202
|
}
|
|
203
203
|
vaultMaxMint() {
|
|
@@ -209,9 +209,9 @@ export class VaultModule {
|
|
|
209
209
|
return formatUnits(_shares, 18);
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
|
-
vaultPreviewMint(
|
|
212
|
+
vaultPreviewMint(shares) {
|
|
213
213
|
return __awaiter(this, void 0, void 0, function* () {
|
|
214
|
-
const _amount = parseUnits(
|
|
214
|
+
const _amount = parseUnits(shares, 18);
|
|
215
215
|
const _assets = yield this.llamalend.contracts[this.market.addresses.vault].contract.previewMint(_amount);
|
|
216
216
|
return formatUnits(_assets, this.market.borrowed_token.decimals);
|
|
217
217
|
});
|
|
@@ -231,9 +231,9 @@ export class VaultModule {
|
|
|
231
231
|
return yield ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.market.addresses.vault);
|
|
232
232
|
});
|
|
233
233
|
}
|
|
234
|
-
_vaultMint(
|
|
235
|
-
return __awaiter(this, arguments, void 0, function* (
|
|
236
|
-
const _amount = parseUnits(
|
|
234
|
+
_vaultMint(shares_1) {
|
|
235
|
+
return __awaiter(this, arguments, void 0, function* (shares, estimateGas = false) {
|
|
236
|
+
const _amount = parseUnits(shares, 18);
|
|
237
237
|
const gas = yield this.llamalend.contracts[this.market.addresses.vault].contract.mint.estimateGas(_amount, Object.assign({}, this.llamalend.constantOptions));
|
|
238
238
|
if (estimateGas)
|
|
239
239
|
return smartNumber(gas);
|
|
@@ -242,17 +242,17 @@ export class VaultModule {
|
|
|
242
242
|
return (yield this.llamalend.contracts[this.market.addresses.vault].contract.mint(_amount, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
243
243
|
});
|
|
244
244
|
}
|
|
245
|
-
vaultMintEstimateGas(
|
|
245
|
+
vaultMintEstimateGas(shares) {
|
|
246
246
|
return __awaiter(this, void 0, void 0, function* () {
|
|
247
|
-
if (!(yield this.vaultMintIsApproved(
|
|
247
|
+
if (!(yield this.vaultMintIsApproved(shares)))
|
|
248
248
|
throw Error("Approval is needed for gas estimation");
|
|
249
|
-
return yield this._vaultMint(
|
|
249
|
+
return yield this._vaultMint(shares, true);
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
|
-
vaultMint(
|
|
252
|
+
vaultMint(shares) {
|
|
253
253
|
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
-
yield this.vaultMintApprove(
|
|
255
|
-
return yield this._vaultMint(
|
|
254
|
+
yield this.vaultMintApprove(shares);
|
|
255
|
+
return yield this._vaultMint(shares, false);
|
|
256
256
|
});
|
|
257
257
|
}
|
|
258
258
|
vaultMaxWithdraw() {
|
|
@@ -262,16 +262,16 @@ export class VaultModule {
|
|
|
262
262
|
return formatUnits(_assets, this.market.borrowed_token.decimals);
|
|
263
263
|
});
|
|
264
264
|
}
|
|
265
|
-
vaultPreviewWithdraw(
|
|
265
|
+
vaultPreviewWithdraw(borrowed) {
|
|
266
266
|
return __awaiter(this, void 0, void 0, function* () {
|
|
267
|
-
const _amount = parseUnits(
|
|
267
|
+
const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
|
|
268
268
|
const _shares = yield this.llamalend.contracts[this.market.addresses.vault].contract.previewWithdraw(_amount);
|
|
269
269
|
return formatUnits(_shares, 18);
|
|
270
270
|
});
|
|
271
271
|
}
|
|
272
|
-
_vaultWithdraw(
|
|
273
|
-
return __awaiter(this, arguments, void 0, function* (
|
|
274
|
-
const _amount = parseUnits(
|
|
272
|
+
_vaultWithdraw(borrowed_1) {
|
|
273
|
+
return __awaiter(this, arguments, void 0, function* (borrowed, estimateGas = false) {
|
|
274
|
+
const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
|
|
275
275
|
const gas = yield this.llamalend.contracts[this.market.addresses.vault].contract.withdraw.estimateGas(_amount, Object.assign({}, this.llamalend.constantOptions));
|
|
276
276
|
if (estimateGas)
|
|
277
277
|
return smartNumber(gas);
|
|
@@ -280,14 +280,14 @@ export class VaultModule {
|
|
|
280
280
|
return (yield this.llamalend.contracts[this.market.addresses.vault].contract.withdraw(_amount, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
281
281
|
});
|
|
282
282
|
}
|
|
283
|
-
vaultWithdrawEstimateGas(
|
|
283
|
+
vaultWithdrawEstimateGas(borrowed) {
|
|
284
284
|
return __awaiter(this, void 0, void 0, function* () {
|
|
285
|
-
return yield this._vaultWithdraw(
|
|
285
|
+
return yield this._vaultWithdraw(borrowed, true);
|
|
286
286
|
});
|
|
287
287
|
}
|
|
288
|
-
vaultWithdraw(
|
|
288
|
+
vaultWithdraw(borrowed) {
|
|
289
289
|
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
-
return yield this._vaultWithdraw(
|
|
290
|
+
return yield this._vaultWithdraw(borrowed, false);
|
|
291
291
|
});
|
|
292
292
|
}
|
|
293
293
|
vaultMaxRedeem() {
|
|
@@ -297,16 +297,16 @@ export class VaultModule {
|
|
|
297
297
|
return formatUnits(_shares, 18);
|
|
298
298
|
});
|
|
299
299
|
}
|
|
300
|
-
vaultPreviewRedeem(
|
|
300
|
+
vaultPreviewRedeem(shares) {
|
|
301
301
|
return __awaiter(this, void 0, void 0, function* () {
|
|
302
|
-
const _amount = parseUnits(
|
|
302
|
+
const _amount = parseUnits(shares, 18);
|
|
303
303
|
const _assets = yield this.llamalend.contracts[this.market.addresses.vault].contract.previewRedeem(_amount);
|
|
304
304
|
return formatUnits(_assets, this.market.borrowed_token.decimals);
|
|
305
305
|
});
|
|
306
306
|
}
|
|
307
|
-
_vaultRedeem(
|
|
308
|
-
return __awaiter(this, arguments, void 0, function* (
|
|
309
|
-
const _amount = parseUnits(
|
|
307
|
+
_vaultRedeem(shares_1) {
|
|
308
|
+
return __awaiter(this, arguments, void 0, function* (shares, estimateGas = false) {
|
|
309
|
+
const _amount = parseUnits(shares, 18);
|
|
310
310
|
const gas = yield this.llamalend.contracts[this.market.addresses.vault].contract.redeem.estimateGas(_amount, Object.assign({}, this.llamalend.constantOptions));
|
|
311
311
|
if (estimateGas)
|
|
312
312
|
return smartNumber(gas);
|
|
@@ -315,14 +315,14 @@ export class VaultModule {
|
|
|
315
315
|
return (yield this.llamalend.contracts[this.market.addresses.vault].contract.redeem(_amount, Object.assign(Object.assign({}, this.llamalend.options), { gasLimit }))).hash;
|
|
316
316
|
});
|
|
317
317
|
}
|
|
318
|
-
vaultRedeemEstimateGas(
|
|
318
|
+
vaultRedeemEstimateGas(shares) {
|
|
319
319
|
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
-
return yield this._vaultRedeem(
|
|
320
|
+
return yield this._vaultRedeem(shares, true);
|
|
321
321
|
});
|
|
322
322
|
}
|
|
323
|
-
vaultRedeem(
|
|
323
|
+
vaultRedeem(shares) {
|
|
324
324
|
return __awaiter(this, void 0, void 0, function* () {
|
|
325
|
-
return yield this._vaultRedeem(
|
|
325
|
+
return yield this._vaultRedeem(shares, false);
|
|
326
326
|
});
|
|
327
327
|
}
|
|
328
328
|
// ---------------- VAULT UTILS ----------------
|
package/lib/st-crvUSD.js
CHANGED
|
@@ -76,7 +76,7 @@ export function depositApproveEstimateGas(assets) {
|
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
export function depositApprove(assets_1) {
|
|
79
|
-
return __awaiter(this, arguments, void 0, function* (assets, isMax =
|
|
79
|
+
return __awaiter(this, arguments, void 0, function* (assets, isMax = false) {
|
|
80
80
|
return yield ensureAllowance.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD, isMax);
|
|
81
81
|
});
|
|
82
82
|
}
|
|
@@ -147,7 +147,7 @@ export function mintApproveEstimateGas(shares) {
|
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
149
|
export function mintApprove(shares_1) {
|
|
150
|
-
return __awaiter(this, arguments, void 0, function* (shares, isMax =
|
|
150
|
+
return __awaiter(this, arguments, void 0, function* (shares, isMax = false) {
|
|
151
151
|
const assets = yield previewMint.call(this, shares);
|
|
152
152
|
return yield ensureAllowance.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD, isMax);
|
|
153
153
|
});
|
package/lib/utils.js
CHANGED
|
@@ -214,7 +214,7 @@ export const hasAllowance = function (coins, amounts, address, spender) {
|
|
|
214
214
|
});
|
|
215
215
|
};
|
|
216
216
|
export const _ensureAllowance = function (coins_1, _amounts_1, spender_1) {
|
|
217
|
-
return __awaiter(this, arguments, void 0, function* (coins, _amounts, spender, isMax =
|
|
217
|
+
return __awaiter(this, arguments, void 0, function* (coins, _amounts, spender, isMax = false) {
|
|
218
218
|
const address = this.signerAddress;
|
|
219
219
|
const _allowance = yield _getAllowance.call(this, coins, address, spender);
|
|
220
220
|
const txHashes = [];
|
|
@@ -232,7 +232,7 @@ export const _ensureAllowance = function (coins_1, _amounts_1, spender_1) {
|
|
|
232
232
|
};
|
|
233
233
|
// coins can be either addresses or symbols
|
|
234
234
|
export const ensureAllowanceEstimateGas = function (coins_1, amounts_1, spender_1) {
|
|
235
|
-
return __awaiter(this, arguments, void 0, function* (coins, amounts, spender, isMax =
|
|
235
|
+
return __awaiter(this, arguments, void 0, function* (coins, amounts, spender, isMax = false) {
|
|
236
236
|
const coinAddresses = _getCoinAddresses.call(this, coins);
|
|
237
237
|
const decimals = _getCoinDecimals.call(this, coinAddresses).map((item) => Number(item));
|
|
238
238
|
const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
|
|
@@ -251,7 +251,7 @@ export const ensureAllowanceEstimateGas = function (coins_1, amounts_1, spender_
|
|
|
251
251
|
};
|
|
252
252
|
// coins can be either addresses or symbols
|
|
253
253
|
export const ensureAllowance = function (coins_1, amounts_1, spender_1) {
|
|
254
|
-
return __awaiter(this, arguments, void 0, function* (coins, amounts, spender, isMax =
|
|
254
|
+
return __awaiter(this, arguments, void 0, function* (coins, amounts, spender, isMax = false) {
|
|
255
255
|
const coinAddresses = _getCoinAddresses.call(this, coins);
|
|
256
256
|
const decimals = _getCoinDecimals.call(this, coinAddresses).map((item) => Number(item));
|
|
257
257
|
const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curvefi/llamalend-api",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.3",
|
|
4
4
|
"description": "JavaScript library for Curve Lending",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Macket",
|
|
@@ -37,16 +37,15 @@
|
|
|
37
37
|
"chai": "^5.3.3",
|
|
38
38
|
"eslint": "^9.38.0",
|
|
39
39
|
"globals": "^16.4.0",
|
|
40
|
-
"mocha": "^11.7.
|
|
40
|
+
"mocha": "^11.7.6",
|
|
41
41
|
"typescript": "^5.9.3",
|
|
42
42
|
"vue-eslint-parser": "^10.2.0"
|
|
43
43
|
},
|
|
44
44
|
"overrides": {
|
|
45
|
-
"serialize-javascript": "^7.0.4"
|
|
46
|
-
"diff": "^8.0.3"
|
|
45
|
+
"serialize-javascript": "^7.0.4"
|
|
47
46
|
},
|
|
48
47
|
"dependencies": {
|
|
49
|
-
"@curvefi/ethcall": "6.0.
|
|
48
|
+
"@curvefi/ethcall": "6.0.20",
|
|
50
49
|
"bignumber.js": "9.3.1",
|
|
51
50
|
"ethers": "6.17.0",
|
|
52
51
|
"memoizee": "0.4.17"
|
|
@@ -2,21 +2,21 @@ import {IReward, TAmount, TGas} from "../../../interfaces";
|
|
|
2
2
|
|
|
3
3
|
export interface IVault {
|
|
4
4
|
maxDeposit: (address?: string) => Promise<string>,
|
|
5
|
-
previewDeposit: (
|
|
5
|
+
previewDeposit: (borrowed: TAmount) => Promise<string>,
|
|
6
6
|
depositIsApproved: (borrowed: TAmount) => Promise<boolean>
|
|
7
7
|
depositApprove: (borrowed: TAmount) => Promise<string[]>
|
|
8
|
-
deposit: (
|
|
8
|
+
deposit: (borrowed: TAmount) => Promise<string>,
|
|
9
9
|
maxMint: (address?: string) => Promise<string>,
|
|
10
|
-
previewMint: (
|
|
10
|
+
previewMint: (shares: TAmount) => Promise<string>,
|
|
11
11
|
mintIsApproved: (borrowed: TAmount) => Promise<boolean>
|
|
12
12
|
mintApprove: (borrowed: TAmount) => Promise<string[]>
|
|
13
|
-
mint: (
|
|
13
|
+
mint: (shares: TAmount) => Promise<string>,
|
|
14
14
|
maxWithdraw: (address?: string) => Promise<string>,
|
|
15
|
-
previewWithdraw: (
|
|
16
|
-
withdraw: (
|
|
15
|
+
previewWithdraw: (borrowed: TAmount) => Promise<string>,
|
|
16
|
+
withdraw: (borrowed: TAmount) => Promise<string>,
|
|
17
17
|
maxRedeem: (address?: string) => Promise<string>,
|
|
18
|
-
previewRedeem: (
|
|
19
|
-
redeem: (
|
|
18
|
+
previewRedeem: (shares: TAmount) => Promise<string>,
|
|
19
|
+
redeem: (shares: TAmount) => Promise<string>,
|
|
20
20
|
convertToShares: (assets: TAmount) => Promise<string>,
|
|
21
21
|
convertToAssets: (shares: TAmount) => Promise<string>,
|
|
22
22
|
stakeIsApproved: (vaultShares: number | string) => Promise<boolean>,
|
|
@@ -33,12 +33,12 @@ export interface IVault {
|
|
|
33
33
|
claimableRewards: (address?: string) => Promise<{token: string, symbol: string, amount: string}[]>,
|
|
34
34
|
claimRewards: () => Promise<string>,
|
|
35
35
|
estimateGas: {
|
|
36
|
-
depositApprove: (
|
|
37
|
-
deposit: (
|
|
38
|
-
mintApprove: (
|
|
39
|
-
mint: (
|
|
40
|
-
withdraw: (
|
|
41
|
-
redeem: (
|
|
36
|
+
depositApprove: (borrowed: TAmount) => Promise<TGas>,
|
|
37
|
+
deposit: (borrowed: TAmount) => Promise<TGas>,
|
|
38
|
+
mintApprove: (borrowed: TAmount) => Promise<TGas>,
|
|
39
|
+
mint: (shares: TAmount) => Promise<TGas>,
|
|
40
|
+
withdraw: (borrowed: TAmount) => Promise<TGas>,
|
|
41
|
+
redeem: (shares: TAmount) => Promise<TGas>,
|
|
42
42
|
stakeApprove: (vaultShares: number | string) => Promise<TGas>,
|
|
43
43
|
stake: (vaultShares: number | string) => Promise<TGas>,
|
|
44
44
|
unstake: (vaultShares: number | string) => Promise<TGas>,
|
|
@@ -39,8 +39,8 @@ export class VaultModule {
|
|
|
39
39
|
return formatUnits(_amount, this.market.borrowed_token.decimals);
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
public async vaultPreviewDeposit(
|
|
43
|
-
const _amount = parseUnits(
|
|
42
|
+
public async vaultPreviewDeposit(borrowed: TAmount): Promise<string> {
|
|
43
|
+
const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
|
|
44
44
|
const _shares = await this.llamalend.contracts[this.market.addresses.vault].contract.previewDeposit(_amount);
|
|
45
45
|
|
|
46
46
|
return formatUnits(_shares, 18);
|
|
@@ -58,8 +58,8 @@ export class VaultModule {
|
|
|
58
58
|
return await ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.market.addresses.vault);
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
private async _vaultDeposit(
|
|
62
|
-
const _amount = parseUnits(
|
|
61
|
+
private async _vaultDeposit(borrowed: TAmount, estimateGas = false): Promise<string | TGas> {
|
|
62
|
+
const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
|
|
63
63
|
const gas = await this.llamalend.contracts[this.market.addresses.vault].contract.deposit.estimateGas(_amount, { ...this.llamalend.constantOptions });
|
|
64
64
|
if (estimateGas) return smartNumber(gas);
|
|
65
65
|
|
|
@@ -70,14 +70,14 @@ export class VaultModule {
|
|
|
70
70
|
return (await this.llamalend.contracts[this.market.addresses.vault].contract.deposit(_amount, { ...this.llamalend.options, gasLimit })).hash;
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
public async vaultDepositEstimateGas(
|
|
74
|
-
if (!(await this.vaultDepositIsApproved(
|
|
75
|
-
return await this._vaultDeposit(
|
|
73
|
+
public async vaultDepositEstimateGas(borrowed: TAmount): Promise<TGas> {
|
|
74
|
+
if (!(await this.vaultDepositIsApproved(borrowed))) throw Error("Approval is needed for gas estimation");
|
|
75
|
+
return await this._vaultDeposit(borrowed, true) as number;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
public async vaultDeposit(
|
|
79
|
-
await this.vaultDepositApprove(
|
|
80
|
-
return await this._vaultDeposit(
|
|
78
|
+
public async vaultDeposit(borrowed: TAmount): Promise<string> {
|
|
79
|
+
await this.vaultDepositApprove(borrowed);
|
|
80
|
+
return await this._vaultDeposit(borrowed, false) as string;
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
|
|
@@ -90,8 +90,8 @@ export class VaultModule {
|
|
|
90
90
|
return formatUnits(_shares, 18);
|
|
91
91
|
}
|
|
92
92
|
|
|
93
|
-
public async vaultPreviewMint(
|
|
94
|
-
const _amount = parseUnits(
|
|
93
|
+
public async vaultPreviewMint(shares: TAmount): Promise<string> {
|
|
94
|
+
const _amount = parseUnits(shares, 18);
|
|
95
95
|
const _assets = await this.llamalend.contracts[this.market.addresses.vault].contract.previewMint(_amount);
|
|
96
96
|
|
|
97
97
|
return formatUnits(_assets, this.market.borrowed_token.decimals);
|
|
@@ -109,8 +109,8 @@ export class VaultModule {
|
|
|
109
109
|
return await ensureAllowance.call(this.llamalend, [this.market.borrowed_token.address], [borrowed], this.market.addresses.vault);
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
private async _vaultMint(
|
|
113
|
-
const _amount = parseUnits(
|
|
112
|
+
private async _vaultMint(shares: TAmount, estimateGas = false): Promise<string | TGas> {
|
|
113
|
+
const _amount = parseUnits(shares, 18);
|
|
114
114
|
const gas = await this.llamalend.contracts[this.market.addresses.vault].contract.mint.estimateGas(_amount, { ...this.llamalend.constantOptions });
|
|
115
115
|
if (estimateGas) return smartNumber(gas);
|
|
116
116
|
|
|
@@ -121,14 +121,14 @@ export class VaultModule {
|
|
|
121
121
|
return (await this.llamalend.contracts[this.market.addresses.vault].contract.mint(_amount, { ...this.llamalend.options, gasLimit })).hash;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
public async vaultMintEstimateGas(
|
|
125
|
-
if (!(await this.vaultMintIsApproved(
|
|
126
|
-
return await this._vaultMint(
|
|
124
|
+
public async vaultMintEstimateGas(shares: TAmount): Promise<TGas> {
|
|
125
|
+
if (!(await this.vaultMintIsApproved(shares))) throw Error("Approval is needed for gas estimation");
|
|
126
|
+
return await this._vaultMint(shares, true) as number;
|
|
127
127
|
}
|
|
128
128
|
|
|
129
|
-
public async vaultMint(
|
|
130
|
-
await this.vaultMintApprove(
|
|
131
|
-
return await this._vaultMint(
|
|
129
|
+
public async vaultMint(shares: TAmount): Promise<string> {
|
|
130
|
+
await this.vaultMintApprove(shares);
|
|
131
|
+
return await this._vaultMint(shares, false) as string;
|
|
132
132
|
}
|
|
133
133
|
|
|
134
134
|
|
|
@@ -139,15 +139,15 @@ export class VaultModule {
|
|
|
139
139
|
return formatUnits(_assets, this.market.borrowed_token.decimals);
|
|
140
140
|
}
|
|
141
141
|
|
|
142
|
-
public async vaultPreviewWithdraw(
|
|
143
|
-
const _amount = parseUnits(
|
|
142
|
+
public async vaultPreviewWithdraw(borrowed: TAmount): Promise<string> {
|
|
143
|
+
const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
|
|
144
144
|
const _shares = await this.llamalend.contracts[this.market.addresses.vault].contract.previewWithdraw(_amount);
|
|
145
145
|
|
|
146
146
|
return formatUnits(_shares, 18);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
private async _vaultWithdraw(
|
|
150
|
-
const _amount = parseUnits(
|
|
149
|
+
private async _vaultWithdraw(borrowed: TAmount, estimateGas = false): Promise<string | TGas> {
|
|
150
|
+
const _amount = parseUnits(borrowed, this.market.borrowed_token.decimals);
|
|
151
151
|
const gas = await this.llamalend.contracts[this.market.addresses.vault].contract.withdraw.estimateGas(_amount, { ...this.llamalend.constantOptions });
|
|
152
152
|
if (estimateGas) return smartNumber(gas);
|
|
153
153
|
|
|
@@ -158,12 +158,12 @@ export class VaultModule {
|
|
|
158
158
|
return (await this.llamalend.contracts[this.market.addresses.vault].contract.withdraw(_amount, { ...this.llamalend.options, gasLimit })).hash;
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
public async vaultWithdrawEstimateGas(
|
|
162
|
-
return await this._vaultWithdraw(
|
|
161
|
+
public async vaultWithdrawEstimateGas(borrowed: TAmount): Promise<TGas> {
|
|
162
|
+
return await this._vaultWithdraw(borrowed, true) as number;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
public async vaultWithdraw(
|
|
166
|
-
return await this._vaultWithdraw(
|
|
165
|
+
public async vaultWithdraw(borrowed: TAmount): Promise<string> {
|
|
166
|
+
return await this._vaultWithdraw(borrowed, false) as string;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
|
|
@@ -174,15 +174,15 @@ export class VaultModule {
|
|
|
174
174
|
return formatUnits(_shares, 18);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
public async vaultPreviewRedeem(
|
|
178
|
-
const _amount = parseUnits(
|
|
177
|
+
public async vaultPreviewRedeem(shares: TAmount): Promise<string> {
|
|
178
|
+
const _amount = parseUnits(shares, 18);
|
|
179
179
|
const _assets = await this.llamalend.contracts[this.market.addresses.vault].contract.previewRedeem(_amount);
|
|
180
180
|
|
|
181
181
|
return formatUnits(_assets, this.market.borrowed_token.decimals);
|
|
182
182
|
}
|
|
183
183
|
|
|
184
|
-
private async _vaultRedeem(
|
|
185
|
-
const _amount = parseUnits(
|
|
184
|
+
private async _vaultRedeem(shares: TAmount, estimateGas = false): Promise<string | TGas> {
|
|
185
|
+
const _amount = parseUnits(shares, 18);
|
|
186
186
|
const gas = await this.llamalend.contracts[this.market.addresses.vault].contract.redeem.estimateGas(_amount, { ...this.llamalend.constantOptions });
|
|
187
187
|
if (estimateGas) return smartNumber(gas);
|
|
188
188
|
|
|
@@ -193,12 +193,12 @@ export class VaultModule {
|
|
|
193
193
|
return (await this.llamalend.contracts[this.market.addresses.vault].contract.redeem(_amount, { ...this.llamalend.options, gasLimit })).hash;
|
|
194
194
|
}
|
|
195
195
|
|
|
196
|
-
public async vaultRedeemEstimateGas(
|
|
197
|
-
return await this._vaultRedeem(
|
|
196
|
+
public async vaultRedeemEstimateGas(shares: TAmount): Promise<TGas> {
|
|
197
|
+
return await this._vaultRedeem(shares, true) as number;
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
public async vaultRedeem(
|
|
201
|
-
return await this._vaultRedeem(
|
|
200
|
+
public async vaultRedeem(shares: TAmount): Promise<string> {
|
|
201
|
+
return await this._vaultRedeem(shares, false) as string;
|
|
202
202
|
}
|
|
203
203
|
|
|
204
204
|
// ---------------- VAULT UTILS ----------------
|
package/src/st-crvUSD.ts
CHANGED
|
@@ -78,7 +78,7 @@ export async function depositApproveEstimateGas(this: Llamalend, assets: TAmount
|
|
|
78
78
|
return await ensureAllowanceEstimateGas.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
export async function depositApprove(this: Llamalend, assets: TAmount, isMax =
|
|
81
|
+
export async function depositApprove(this: Llamalend, assets: TAmount, isMax = false): Promise<string[]> {
|
|
82
82
|
return await ensureAllowance.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD, isMax);
|
|
83
83
|
}
|
|
84
84
|
|
|
@@ -142,7 +142,7 @@ export async function mintApproveEstimateGas(this: Llamalend, shares: TAmount):
|
|
|
142
142
|
return await ensureAllowanceEstimateGas.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD);
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
export async function mintApprove(this: Llamalend, shares: TAmount, isMax =
|
|
145
|
+
export async function mintApprove(this: Llamalend, shares: TAmount, isMax = false): Promise<string[]> {
|
|
146
146
|
const assets = await previewMint.call(this, shares);
|
|
147
147
|
return await ensureAllowance.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD, isMax);
|
|
148
148
|
}
|
package/src/utils.ts
CHANGED
|
@@ -235,7 +235,7 @@ export const hasAllowance = async function (this: Llamalend, coins: string[], am
|
|
|
235
235
|
return _allowance.map((a, i) => a >= _amounts[i]).reduce((a, b) => a && b);
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
export const _ensureAllowance = async function (this: Llamalend, coins: string[], _amounts: bigint[], spender: string, isMax =
|
|
238
|
+
export const _ensureAllowance = async function (this: Llamalend, coins: string[], _amounts: bigint[], spender: string, isMax = false): Promise<string[]> {
|
|
239
239
|
const address = this.signerAddress;
|
|
240
240
|
const _allowance: bigint[] = await _getAllowance.call(this, coins, address, spender);
|
|
241
241
|
|
|
@@ -254,7 +254,7 @@ export const _ensureAllowance = async function (this: Llamalend, coins: string[]
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
// coins can be either addresses or symbols
|
|
257
|
-
export const ensureAllowanceEstimateGas = async function (this: Llamalend, coins: string[], amounts: (number | string)[], spender: string, isMax =
|
|
257
|
+
export const ensureAllowanceEstimateGas = async function (this: Llamalend, coins: string[], amounts: (number | string)[], spender: string, isMax = false): Promise<TGas> {
|
|
258
258
|
const coinAddresses = _getCoinAddresses.call(this, coins);
|
|
259
259
|
const decimals = _getCoinDecimals.call(this, coinAddresses).map((item) => Number(item));
|
|
260
260
|
const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
|
|
@@ -274,7 +274,7 @@ export const ensureAllowanceEstimateGas = async function (this: Llamalend, coins
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
// coins can be either addresses or symbols
|
|
277
|
-
export const ensureAllowance = async function (this: Llamalend, coins: string[], amounts: (number | string)[], spender: string, isMax =
|
|
277
|
+
export const ensureAllowance = async function (this: Llamalend, coins: string[], amounts: (number | string)[], spender: string, isMax = false): Promise<string[]> {
|
|
278
278
|
const coinAddresses = _getCoinAddresses.call(this, coins);
|
|
279
279
|
const decimals = _getCoinDecimals.call(this, coinAddresses).map((item) => Number(item));
|
|
280
280
|
const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
|