@curvefi/llamalend-api 1.0.21 → 1.0.22-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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 { llamalend } from "./llamalend.js";
13
+ import type { Llamalend } from "./llamalend.js";
14
14
  import { TAmount, TGas } from "./interfaces.js";
15
15
 
16
16
  // ---------------- UTILS ----------------
17
17
 
18
- export const convertToShares = async (assets: TAmount): Promise<string> => {
18
+ export async function convertToShares(this: Llamalend, assets: TAmount): Promise<string> {
19
19
  const _assets = parseUnits(assets);
20
- const _shares = await llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].contract.convertToShares(_assets);
20
+ const _shares = await this.contracts[this.constants.ALIASES.st_crvUSD].contract.convertToShares(_assets);
21
21
 
22
- return llamalend.formatUnits(_shares);
22
+ return this.formatUnits(_shares);
23
23
  }
24
24
 
25
- export const convertToAssets = async (shares: TAmount): Promise<string> => {
25
+ export async function convertToAssets(this: Llamalend, shares: TAmount): Promise<string> {
26
26
  const _shares = parseUnits(shares);
27
- const _assets = await llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].contract.convertToAssets(_shares);
27
+ const _assets = await this.contracts[this.constants.ALIASES.st_crvUSD].contract.convertToAssets(_shares);
28
28
 
29
- return llamalend.formatUnits(_assets);
29
+ return this.formatUnits(_assets);
30
30
  }
31
31
 
32
32
  // ---------------- BALANCES ----------------
33
33
 
34
- export const userBalances = async (address = llamalend.signerAddress): Promise<{ "crvUSD": string, "st_crvUSD": string }> => {
35
- const rawBalances = await getBalances([llamalend.constants.ALIASES.crvUSD, llamalend.constants.ALIASES.st_crvUSD], address);
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 const totalSupplyAndCrvUSDLocked = async (): Promise<{ "crvUSD": string, "st_crvUSD": string }> => {
43
- const contract = llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].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": llamalend.formatUnits(_crvUSDLocked),
48
- "st_crvUSD": llamalend.formatUnits(_totalSupply),
48
+ "crvUSD": this.formatUnits(_crvUSDLocked),
49
+ "st_crvUSD": this.formatUnits(_totalSupply),
49
50
  }
50
51
  }
51
52
 
52
53
  // ---------------- DEPOSIT ----------------
53
54
 
54
- export const maxDeposit = async (address = ""): Promise<string> => {
55
- address = _getAddress(address);
56
- const _assets = await llamalend.contracts[llamalend.constants.ALIASES.crvUSD].contract.balanceOf(address);
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 const previewDeposit = async (assets: TAmount): Promise<string> => {
62
+ export async function previewDeposit(this: Llamalend, assets: TAmount): Promise<string> {
62
63
  const _assets = parseUnits(assets);
63
- const _shares = await llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].contract.previewDeposit(_assets);
64
+ const _shares = await this.contracts[this.constants.ALIASES.st_crvUSD].contract.previewDeposit(_assets);
64
65
 
65
- return llamalend.formatUnits(_shares);
66
+ return this.formatUnits(_shares);
66
67
  }
67
68
 
68
- export const depositIsApproved = async(assets: TAmount): Promise<boolean> => {
69
- return await hasAllowance([llamalend.constants.ALIASES.crvUSD], [assets], llamalend.signerAddress, llamalend.constants.ALIASES.st_crvUSD);
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 const depositAllowance = async(): Promise<string[]> => {
73
- return await getAllowance([llamalend.constants.ALIASES.crvUSD], llamalend.signerAddress, llamalend.constants.ALIASES.st_crvUSD);
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 const depositApproveEstimateGas = async (assets: TAmount): Promise<TGas> => {
77
- return await ensureAllowanceEstimateGas([llamalend.constants.ALIASES.crvUSD], [assets], llamalend.constants.ALIASES.st_crvUSD);
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 const depositApprove = async (assets: TAmount, isMax = true): Promise<string[]> => {
81
- return await ensureAllowance([llamalend.constants.ALIASES.crvUSD], [assets], llamalend.constants.ALIASES.st_crvUSD, isMax);
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
- const _deposit = async (assets: TAmount, estimateGas = false): Promise<string | TGas> => {
85
+ async function _deposit(this: Llamalend, assets: TAmount, estimateGas = false): Promise<string | TGas> {
85
86
  const _assets = parseUnits(assets);
86
- const contract = llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].contract;
87
- const gas = await contract.deposit.estimateGas(_assets, llamalend.signerAddress, { ...llamalend.constantOptions });
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 llamalend.updateFeeData();
91
+ await this.updateFeeData();
91
92
 
92
93
  const gasLimit = _mulBy1_3(DIGas(gas));
93
94
 
94
- return (await contract.deposit(_assets, llamalend.signerAddress, { ...llamalend.options, gasLimit })).hash;
95
+ return (await contract.deposit(_assets, this.signerAddress, { ...this.options, gasLimit })).hash;
95
96
  }
96
97
 
97
- export const depositEstimateGas = async (assets: TAmount): Promise<TGas> => {
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 const deposit = async (assets: TAmount): Promise<string> => {
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 const maxMint = async (address = ""): Promise<string> => {
110
- address = _getAddress(address);
111
- const _assetBalance = await llamalend.contracts[llamalend.constants.ALIASES.crvUSD].contract.balanceOf(address);
112
- const _shares = await llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].contract.convertToShares(_assetBalance);
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 const previewMint = async (shares: TAmount): Promise<string> => {
118
+ export async function previewMint(this: Llamalend, shares: TAmount): Promise<string> {
118
119
  const _shares = parseUnits(shares);
119
- const _assets = await llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].contract.previewMint(_shares);
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 const mintIsApproved = async (shares: TAmount): Promise<boolean> => {
125
- const assets = await previewMint(shares);
126
- return await hasAllowance([llamalend.constants.ALIASES.crvUSD], [assets], llamalend.signerAddress, llamalend.constants.ALIASES.st_crvUSD);
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 const mintAllowance = async (): Promise<string[]> => {
130
- const assets = await getAllowance([llamalend.constants.ALIASES.crvUSD], llamalend.signerAddress, llamalend.constants.ALIASES.st_crvUSD);
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 [llamalend.formatUnits(MAX_ALLOWANCE)];
135
+ if (parseUnits(assets[0]) === MAX_ALLOWANCE) return [this.formatUnits(MAX_ALLOWANCE)];
135
136
  throw e;
136
137
  }
137
138
  }
138
139
 
139
- export const mintApproveEstimateGas = async (shares: TAmount): Promise<TGas> => {
140
- const assets = await previewMint(shares);
141
- return await ensureAllowanceEstimateGas([llamalend.constants.ALIASES.crvUSD], [assets], llamalend.constants.ALIASES.st_crvUSD);
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 const mintApprove = async (shares: TAmount, isMax = true): Promise<string[]> => {
145
- const assets = await previewMint(shares);
146
- return await ensureAllowance([llamalend.constants.ALIASES.crvUSD], [assets], llamalend.constants.ALIASES.st_crvUSD, isMax);
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
- const _mint = async (shares: TAmount, estimateGas = false): Promise<string | TGas> => {
150
+ async function _mint(this: Llamalend, shares: TAmount, estimateGas = false): Promise<string | TGas> {
150
151
  const _shares = parseUnits(shares);
151
- const contract = llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].contract;
152
- const gas = await contract.mint.estimateGas(_shares, llamalend.signerAddress, { ...llamalend.constantOptions });
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 llamalend.updateFeeData();
156
+ await this.updateFeeData();
156
157
 
157
158
  const gasLimit = _mulBy1_3(DIGas(gas));
158
159
 
159
- return (await contract.mint(_shares, llamalend.signerAddress, { ...llamalend.options, gasLimit })).hash;
160
+ return (await contract.mint(_shares, this.signerAddress, { ...this.options, gasLimit })).hash;
160
161
  }
161
162
 
162
- export const mintEstimateGas = async (shares: TAmount): Promise<TGas> => {
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 const mint = async (shares: TAmount): Promise<string> => {
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 const maxWithdraw = async (address = ""): Promise<string> => {
175
- address = _getAddress(address);
176
- const _assets = await llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].contract.maxWithdraw(address);
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 const previewWithdraw = async (assets: TAmount): Promise<string> => {
182
+ export async function previewWithdraw(this: Llamalend, assets: TAmount): Promise<string> {
182
183
  const _assets = parseUnits(assets);
183
- const _shares = await llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].contract.previewWithdraw(_assets);
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
- const _withdraw = async (assets: TAmount, estimateGas = false): Promise<string | TGas> => {
189
+ async function _withdraw(this: Llamalend, assets: TAmount, estimateGas = false): Promise<string | TGas> {
189
190
  const _assets = parseUnits(assets);
190
- const contract = llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].contract;
191
- const gas = await contract.withdraw.estimateGas(_assets, llamalend.signerAddress, llamalend.signerAddress, { ...llamalend.constantOptions });
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 llamalend.updateFeeData();
195
+ await this.updateFeeData();
195
196
 
196
197
  const gasLimit = _mulBy1_3(DIGas(gas));
197
198
 
198
- return (await contract.withdraw(_assets, llamalend.signerAddress, llamalend.signerAddress, { ...llamalend.options, gasLimit })).hash;
199
+ return (await contract.withdraw(_assets, this.signerAddress, this.signerAddress, { ...this.options, gasLimit })).hash;
199
200
  }
200
201
 
201
- export const withdrawEstimateGas = async (assets: TAmount): Promise<TGas> => {
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 const withdraw = async (assets: TAmount): Promise<string> => {
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 const maxRedeem = async (address = ""): Promise<string> => {
212
- address = _getAddress(address);
213
- const _shares = await llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].contract.maxRedeem(address)
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 const previewRedeem = async (shares: TAmount): Promise<string> => {
219
+ export async function previewRedeem(this: Llamalend, shares: TAmount): Promise<string> {
219
220
  const _shares = parseUnits(shares, 18);
220
- const _assets = await llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].contract.previewRedeem(_shares);
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
- const _redeem = async (shares: TAmount, estimateGas = false): Promise<string | TGas> => {
226
+ async function _redeem(this: Llamalend, shares: TAmount, estimateGas = false): Promise<string | TGas> {
226
227
  const _shares = parseUnits(shares, 18);
227
- const contract = llamalend.contracts[llamalend.constants.ALIASES.st_crvUSD].contract;
228
- const gas = await contract.redeem.estimateGas(_shares, llamalend.signerAddress, llamalend.signerAddress, { ...llamalend.constantOptions });
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 llamalend.updateFeeData();
232
+ await this.updateFeeData();
232
233
 
233
234
  const gasLimit = _mulBy1_3(DIGas(gas));
234
235
 
235
- return (await contract.redeem(_shares, llamalend.signerAddress, llamalend.signerAddress, { ...llamalend.options, gasLimit })).hash;
236
+ return (await contract.redeem(_shares, this.signerAddress, this.signerAddress, { ...this.options, gasLimit })).hash;
236
237
  }
237
238
 
238
- export const redeemEstimateGas = async (shares: TAmount): Promise<TGas> => {
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 const redeem = async (shares: TAmount): Promise<string> => {
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
  }