@curvefi/llamalend-api 1.0.21 → 1.0.22-beta.2
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/.github/workflows/publish.yml +1 -0
- package/lib/external-api.d.ts +6 -4
- package/lib/external-api.js +116 -98
- package/lib/index.d.ts +138 -41
- package/lib/index.js +80 -75
- package/lib/lendMarkets/LendMarketTemplate.d.ts +3 -1
- package/lib/lendMarkets/LendMarketTemplate.js +333 -333
- package/lib/lendMarkets/lendMarketConstructor.d.ts +2 -1
- package/lib/lendMarkets/lendMarketConstructor.js +3 -4
- package/lib/llamalend.d.ts +2 -2
- package/lib/llamalend.js +12 -20
- package/lib/mintMarkets/MintMarketTemplate.d.ts +3 -1
- package/lib/mintMarkets/MintMarketTemplate.js +204 -204
- package/lib/mintMarkets/mintMarketConstructor.d.ts +2 -1
- package/lib/mintMarkets/mintMarketConstructor.js +2 -2
- package/lib/st-crvUSD.d.ts +29 -28
- package/lib/st-crvUSD.js +237 -173
- package/lib/utils.d.ts +20 -19
- package/lib/utils.js +290 -256
- package/package.json +14 -14
- package/src/external-api.ts +25 -11
- package/src/index.ts +88 -76
- package/src/lendMarkets/LendMarketTemplate.ts +348 -346
- package/src/lendMarkets/lendMarketConstructor.ts +4 -4
- package/src/llamalend.ts +42 -58
- package/src/mintMarkets/MintMarketTemplate.ts +206 -204
- package/src/mintMarkets/mintMarketConstructor.ts +3 -2
- package/src/st-crvUSD.ts +97 -96
- package/src/utils.ts +85 -82
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { MintMarketTemplate} from "./MintMarketTemplate";
|
|
2
|
+
import type { Llamalend } from "../llamalend.js";
|
|
2
3
|
|
|
3
|
-
export const getMintMarket = (mintMarketId: string): MintMarketTemplate
|
|
4
|
-
return new MintMarketTemplate(mintMarketId)
|
|
4
|
+
export const getMintMarket = function (this: Llamalend, mintMarketId: string): MintMarketTemplate {
|
|
5
|
+
return new MintMarketTemplate(mintMarketId, this)
|
|
5
6
|
}
|
package/src/st-crvUSD.ts
CHANGED
|
@@ -10,235 +10,236 @@ import {
|
|
|
10
10
|
getBalances,
|
|
11
11
|
MAX_ALLOWANCE,
|
|
12
12
|
} from "./utils.js";
|
|
13
|
-
import {
|
|
13
|
+
import type { Llamalend } from "./llamalend.js";
|
|
14
14
|
import { TAmount, TGas } from "./interfaces.js";
|
|
15
15
|
|
|
16
16
|
// ---------------- UTILS ----------------
|
|
17
17
|
|
|
18
|
-
export
|
|
18
|
+
export async function convertToShares(this: Llamalend, assets: TAmount): Promise<string> {
|
|
19
19
|
const _assets = parseUnits(assets);
|
|
20
|
-
const _shares = await
|
|
20
|
+
const _shares = await this.contracts[this.constants.ALIASES.st_crvUSD].contract.convertToShares(_assets);
|
|
21
21
|
|
|
22
|
-
return
|
|
22
|
+
return this.formatUnits(_shares);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export
|
|
25
|
+
export async function convertToAssets(this: Llamalend, shares: TAmount): Promise<string> {
|
|
26
26
|
const _shares = parseUnits(shares);
|
|
27
|
-
const _assets = await
|
|
27
|
+
const _assets = await this.contracts[this.constants.ALIASES.st_crvUSD].contract.convertToAssets(_shares);
|
|
28
28
|
|
|
29
|
-
return
|
|
29
|
+
return this.formatUnits(_assets);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
// ---------------- BALANCES ----------------
|
|
33
33
|
|
|
34
|
-
export
|
|
35
|
-
|
|
34
|
+
export async function userBalances(this: Llamalend, address = ""): Promise<{ "crvUSD": string, "st_crvUSD": string }> {
|
|
35
|
+
address = address || this.signerAddress;
|
|
36
|
+
const rawBalances = await getBalances.call(this, [this.constants.ALIASES.crvUSD, this.constants.ALIASES.st_crvUSD], address);
|
|
36
37
|
return {
|
|
37
38
|
"crvUSD": rawBalances[0],
|
|
38
39
|
"st_crvUSD": rawBalances[1],
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|
|
42
|
-
export
|
|
43
|
-
const contract =
|
|
43
|
+
export async function totalSupplyAndCrvUSDLocked(this: Llamalend): Promise<{ "crvUSD": string, "st_crvUSD": string }> {
|
|
44
|
+
const contract = this.contracts[this.constants.ALIASES.st_crvUSD].contract;
|
|
44
45
|
const _totalSupply = await contract.totalSupply();
|
|
45
46
|
const _crvUSDLocked = await contract.convertToAssets(_totalSupply)
|
|
46
47
|
return {
|
|
47
|
-
"crvUSD":
|
|
48
|
-
"st_crvUSD":
|
|
48
|
+
"crvUSD": this.formatUnits(_crvUSDLocked),
|
|
49
|
+
"st_crvUSD": this.formatUnits(_totalSupply),
|
|
49
50
|
}
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
// ---------------- DEPOSIT ----------------
|
|
53
54
|
|
|
54
|
-
export
|
|
55
|
-
address = _getAddress(address);
|
|
56
|
-
const _assets = await
|
|
55
|
+
export async function maxDeposit(this: Llamalend, address = ""): Promise<string> {
|
|
56
|
+
address = _getAddress.call(this, address);
|
|
57
|
+
const _assets = await this.contracts[this.constants.ALIASES.crvUSD].contract.balanceOf(address);
|
|
57
58
|
|
|
58
59
|
return formatUnits(_assets);
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
export
|
|
62
|
+
export async function previewDeposit(this: Llamalend, assets: TAmount): Promise<string> {
|
|
62
63
|
const _assets = parseUnits(assets);
|
|
63
|
-
const _shares = await
|
|
64
|
+
const _shares = await this.contracts[this.constants.ALIASES.st_crvUSD].contract.previewDeposit(_assets);
|
|
64
65
|
|
|
65
|
-
return
|
|
66
|
+
return this.formatUnits(_shares);
|
|
66
67
|
}
|
|
67
68
|
|
|
68
|
-
export
|
|
69
|
-
return await hasAllowance([
|
|
69
|
+
export async function depositIsApproved(this: Llamalend, assets: TAmount): Promise<boolean> {
|
|
70
|
+
return await hasAllowance.call(this, [this.constants.ALIASES.crvUSD], [assets], this.signerAddress, this.constants.ALIASES.st_crvUSD);
|
|
70
71
|
}
|
|
71
72
|
|
|
72
|
-
export
|
|
73
|
-
return await getAllowance([
|
|
73
|
+
export async function depositAllowance(this: Llamalend): Promise<string[]> {
|
|
74
|
+
return await getAllowance.call(this, [this.constants.ALIASES.crvUSD], this.signerAddress, this.constants.ALIASES.st_crvUSD);
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
export
|
|
77
|
-
return await ensureAllowanceEstimateGas([
|
|
77
|
+
export async function depositApproveEstimateGas(this: Llamalend, assets: TAmount): Promise<TGas> {
|
|
78
|
+
return await ensureAllowanceEstimateGas.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD);
|
|
78
79
|
}
|
|
79
80
|
|
|
80
|
-
export
|
|
81
|
-
return await ensureAllowance([
|
|
81
|
+
export async function depositApprove(this: Llamalend, assets: TAmount, isMax = true): Promise<string[]> {
|
|
82
|
+
return await ensureAllowance.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD, isMax);
|
|
82
83
|
}
|
|
83
84
|
|
|
84
|
-
|
|
85
|
+
async function _deposit(this: Llamalend, assets: TAmount, estimateGas = false): Promise<string | TGas> {
|
|
85
86
|
const _assets = parseUnits(assets);
|
|
86
|
-
const contract =
|
|
87
|
-
const gas = await contract.deposit.estimateGas(_assets,
|
|
87
|
+
const contract = this.contracts[this.constants.ALIASES.st_crvUSD].contract;
|
|
88
|
+
const gas = await contract.deposit.estimateGas(_assets, this.signerAddress, { ...this.constantOptions });
|
|
88
89
|
if (estimateGas) return smartNumber(gas);
|
|
89
90
|
|
|
90
|
-
await
|
|
91
|
+
await this.updateFeeData();
|
|
91
92
|
|
|
92
93
|
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
93
94
|
|
|
94
|
-
return (await contract.deposit(_assets,
|
|
95
|
+
return (await contract.deposit(_assets, this.signerAddress, { ...this.options, gasLimit })).hash;
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
export
|
|
98
|
-
if (!(await depositIsApproved(assets))) throw Error("Approval is needed for gas estimation");
|
|
99
|
-
return await _deposit(assets, true) as number;
|
|
98
|
+
export async function depositEstimateGas(this: Llamalend, assets: TAmount): Promise<TGas> {
|
|
99
|
+
if (!(await depositIsApproved.call(this, assets))) throw Error("Approval is needed for gas estimation");
|
|
100
|
+
return await _deposit.call(this, assets, true) as number;
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
export
|
|
103
|
-
await depositApprove(assets);
|
|
104
|
-
return await _deposit(assets, false) as string;
|
|
103
|
+
export async function deposit(this: Llamalend, assets: TAmount): Promise<string> {
|
|
104
|
+
await depositApprove.call(this, assets);
|
|
105
|
+
return await _deposit.call(this, assets, false) as string;
|
|
105
106
|
}
|
|
106
107
|
|
|
107
108
|
// ---------------- MINT ----------------
|
|
108
109
|
|
|
109
|
-
export
|
|
110
|
-
address = _getAddress(address);
|
|
111
|
-
const _assetBalance = await
|
|
112
|
-
const _shares = await
|
|
110
|
+
export async function maxMint(this: Llamalend, address = ""): Promise<string> {
|
|
111
|
+
address = _getAddress.call(this, address);
|
|
112
|
+
const _assetBalance = await this.contracts[this.constants.ALIASES.crvUSD].contract.balanceOf(address);
|
|
113
|
+
const _shares = await this.contracts[this.constants.ALIASES.st_crvUSD].contract.convertToShares(_assetBalance);
|
|
113
114
|
|
|
114
115
|
return formatUnits(_shares);
|
|
115
116
|
}
|
|
116
117
|
|
|
117
|
-
export
|
|
118
|
+
export async function previewMint(this: Llamalend, shares: TAmount): Promise<string> {
|
|
118
119
|
const _shares = parseUnits(shares);
|
|
119
|
-
const _assets = await
|
|
120
|
+
const _assets = await this.contracts[this.constants.ALIASES.st_crvUSD].contract.previewMint(_shares);
|
|
120
121
|
|
|
121
122
|
return formatUnits(_assets);
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
export
|
|
125
|
-
const assets = await previewMint(shares);
|
|
126
|
-
return await hasAllowance([
|
|
125
|
+
export async function mintIsApproved(this: Llamalend, shares: TAmount): Promise<boolean> {
|
|
126
|
+
const assets = await previewMint.call(this, shares);
|
|
127
|
+
return await hasAllowance.call(this, [this.constants.ALIASES.crvUSD], [assets], this.signerAddress, this.constants.ALIASES.st_crvUSD);
|
|
127
128
|
}
|
|
128
129
|
|
|
129
|
-
export
|
|
130
|
-
const assets = await getAllowance([
|
|
130
|
+
export async function mintAllowance(this: Llamalend): Promise<string[]> {
|
|
131
|
+
const assets = await getAllowance.call(this, [this.constants.ALIASES.crvUSD], this.signerAddress, this.constants.ALIASES.st_crvUSD);
|
|
131
132
|
try {
|
|
132
|
-
return [await convertToShares(assets[0])]
|
|
133
|
+
return [await convertToShares.call(this, assets[0])]
|
|
133
134
|
} catch (e) {
|
|
134
|
-
if (parseUnits(assets[0]) === MAX_ALLOWANCE) return [
|
|
135
|
+
if (parseUnits(assets[0]) === MAX_ALLOWANCE) return [this.formatUnits(MAX_ALLOWANCE)];
|
|
135
136
|
throw e;
|
|
136
137
|
}
|
|
137
138
|
}
|
|
138
139
|
|
|
139
|
-
export
|
|
140
|
-
const assets = await previewMint(shares);
|
|
141
|
-
return await ensureAllowanceEstimateGas([
|
|
140
|
+
export async function mintApproveEstimateGas(this: Llamalend, shares: TAmount): Promise<TGas> {
|
|
141
|
+
const assets = await previewMint.call(this, shares);
|
|
142
|
+
return await ensureAllowanceEstimateGas.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD);
|
|
142
143
|
}
|
|
143
144
|
|
|
144
|
-
export
|
|
145
|
-
const assets = await previewMint(shares);
|
|
146
|
-
return await ensureAllowance([
|
|
145
|
+
export async function mintApprove(this: Llamalend, shares: TAmount, isMax = true): Promise<string[]> {
|
|
146
|
+
const assets = await previewMint.call(this, shares);
|
|
147
|
+
return await ensureAllowance.call(this, [this.constants.ALIASES.crvUSD], [assets], this.constants.ALIASES.st_crvUSD, isMax);
|
|
147
148
|
}
|
|
148
149
|
|
|
149
|
-
|
|
150
|
+
async function _mint(this: Llamalend, shares: TAmount, estimateGas = false): Promise<string | TGas> {
|
|
150
151
|
const _shares = parseUnits(shares);
|
|
151
|
-
const contract =
|
|
152
|
-
const gas = await contract.mint.estimateGas(_shares,
|
|
152
|
+
const contract = this.contracts[this.constants.ALIASES.st_crvUSD].contract;
|
|
153
|
+
const gas = await contract.mint.estimateGas(_shares, this.signerAddress, { ...this.constantOptions });
|
|
153
154
|
if (estimateGas) return smartNumber(gas);
|
|
154
155
|
|
|
155
|
-
await
|
|
156
|
+
await this.updateFeeData();
|
|
156
157
|
|
|
157
158
|
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
158
159
|
|
|
159
|
-
return (await contract.mint(_shares,
|
|
160
|
+
return (await contract.mint(_shares, this.signerAddress, { ...this.options, gasLimit })).hash;
|
|
160
161
|
}
|
|
161
162
|
|
|
162
|
-
export
|
|
163
|
-
if (!(await mintIsApproved(shares))) throw Error("Approval is needed for gas estimation");
|
|
164
|
-
return await _mint(shares, true) as number;
|
|
163
|
+
export async function mintEstimateGas(this: Llamalend, shares: TAmount): Promise<TGas> {
|
|
164
|
+
if (!(await mintIsApproved.call(this, shares))) throw Error("Approval is needed for gas estimation");
|
|
165
|
+
return await _mint.call(this, shares, true) as number;
|
|
165
166
|
}
|
|
166
167
|
|
|
167
|
-
export
|
|
168
|
-
await mintApprove(shares);
|
|
169
|
-
return await _mint(shares, false) as string;
|
|
168
|
+
export async function mint(this: Llamalend, shares: TAmount): Promise<string> {
|
|
169
|
+
await mintApprove.call(this, shares);
|
|
170
|
+
return await _mint.call(this, shares, false) as string;
|
|
170
171
|
}
|
|
171
172
|
|
|
172
173
|
// ---------------- WITHDRAW ----------------
|
|
173
174
|
|
|
174
|
-
export
|
|
175
|
-
address = _getAddress(address);
|
|
176
|
-
const _assets = await
|
|
175
|
+
export async function maxWithdraw(this: Llamalend, address = ""): Promise<string> {
|
|
176
|
+
address = _getAddress.call(this, address);
|
|
177
|
+
const _assets = await this.contracts[this.constants.ALIASES.st_crvUSD].contract.maxWithdraw(address);
|
|
177
178
|
|
|
178
179
|
return formatUnits(_assets);
|
|
179
180
|
}
|
|
180
181
|
|
|
181
|
-
export
|
|
182
|
+
export async function previewWithdraw(this: Llamalend, assets: TAmount): Promise<string> {
|
|
182
183
|
const _assets = parseUnits(assets);
|
|
183
|
-
const _shares = await
|
|
184
|
+
const _shares = await this.contracts[this.constants.ALIASES.st_crvUSD].contract.previewWithdraw(_assets);
|
|
184
185
|
|
|
185
186
|
return formatUnits(_shares);
|
|
186
187
|
}
|
|
187
188
|
|
|
188
|
-
|
|
189
|
+
async function _withdraw(this: Llamalend, assets: TAmount, estimateGas = false): Promise<string | TGas> {
|
|
189
190
|
const _assets = parseUnits(assets);
|
|
190
|
-
const contract =
|
|
191
|
-
const gas = await contract.withdraw.estimateGas(_assets,
|
|
191
|
+
const contract = this.contracts[this.constants.ALIASES.st_crvUSD].contract;
|
|
192
|
+
const gas = await contract.withdraw.estimateGas(_assets, this.signerAddress, this.signerAddress, { ...this.constantOptions });
|
|
192
193
|
if (estimateGas) return smartNumber(gas);
|
|
193
194
|
|
|
194
|
-
await
|
|
195
|
+
await this.updateFeeData();
|
|
195
196
|
|
|
196
197
|
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
197
198
|
|
|
198
|
-
return (await contract.withdraw(_assets,
|
|
199
|
+
return (await contract.withdraw(_assets, this.signerAddress, this.signerAddress, { ...this.options, gasLimit })).hash;
|
|
199
200
|
}
|
|
200
201
|
|
|
201
|
-
export
|
|
202
|
-
return await _withdraw(assets, true) as number;
|
|
202
|
+
export async function withdrawEstimateGas(this: Llamalend, assets: TAmount): Promise<TGas> {
|
|
203
|
+
return await _withdraw.call(this, assets, true) as number;
|
|
203
204
|
}
|
|
204
205
|
|
|
205
|
-
export
|
|
206
|
-
return await _withdraw(assets, false) as string;
|
|
206
|
+
export async function withdraw(this: Llamalend, assets: TAmount): Promise<string> {
|
|
207
|
+
return await _withdraw.call(this, assets, false) as string;
|
|
207
208
|
}
|
|
208
209
|
|
|
209
210
|
// ---------------- REDEEM ----------------
|
|
210
211
|
|
|
211
|
-
export
|
|
212
|
-
address = _getAddress(address);
|
|
213
|
-
const _shares = await
|
|
212
|
+
export async function maxRedeem(this: Llamalend, address = ""): Promise<string> {
|
|
213
|
+
address = _getAddress.call(this, address);
|
|
214
|
+
const _shares = await this.contracts[this.constants.ALIASES.st_crvUSD].contract.maxRedeem(address)
|
|
214
215
|
|
|
215
216
|
return formatUnits(_shares);
|
|
216
217
|
}
|
|
217
218
|
|
|
218
|
-
export
|
|
219
|
+
export async function previewRedeem(this: Llamalend, shares: TAmount): Promise<string> {
|
|
219
220
|
const _shares = parseUnits(shares, 18);
|
|
220
|
-
const _assets = await
|
|
221
|
+
const _assets = await this.contracts[this.constants.ALIASES.st_crvUSD].contract.previewRedeem(_shares);
|
|
221
222
|
|
|
222
223
|
return formatUnits(_assets);
|
|
223
224
|
}
|
|
224
225
|
|
|
225
|
-
|
|
226
|
+
async function _redeem(this: Llamalend, shares: TAmount, estimateGas = false): Promise<string | TGas> {
|
|
226
227
|
const _shares = parseUnits(shares, 18);
|
|
227
|
-
const contract =
|
|
228
|
-
const gas = await contract.redeem.estimateGas(_shares,
|
|
228
|
+
const contract = this.contracts[this.constants.ALIASES.st_crvUSD].contract;
|
|
229
|
+
const gas = await contract.redeem.estimateGas(_shares, this.signerAddress, this.signerAddress, { ...this.constantOptions });
|
|
229
230
|
if (estimateGas) return smartNumber(gas);
|
|
230
231
|
|
|
231
|
-
await
|
|
232
|
+
await this.updateFeeData();
|
|
232
233
|
|
|
233
234
|
const gasLimit = _mulBy1_3(DIGas(gas));
|
|
234
235
|
|
|
235
|
-
return (await contract.redeem(_shares,
|
|
236
|
+
return (await contract.redeem(_shares, this.signerAddress, this.signerAddress, { ...this.options, gasLimit })).hash;
|
|
236
237
|
}
|
|
237
238
|
|
|
238
|
-
export
|
|
239
|
-
return await _redeem(shares, true) as number;
|
|
239
|
+
export async function redeemEstimateGas(this: Llamalend, shares: TAmount): Promise<TGas> {
|
|
240
|
+
return await _redeem.call(this, shares, true) as number;
|
|
240
241
|
}
|
|
241
242
|
|
|
242
|
-
export
|
|
243
|
-
return await _redeem(shares, false) as string;
|
|
243
|
+
export async function redeem(this: Llamalend, shares: TAmount): Promise<string> {
|
|
244
|
+
return await _redeem.call(this, shares, false) as string;
|
|
244
245
|
}
|