@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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@curvefi/llamalend-api",
3
- "version": "1.0.21",
3
+ "version": "1.0.22-beta.2",
4
4
  "description": "JavaScript library for Curve Lending",
5
5
  "main": "lib/index.js",
6
6
  "author": "Macket",
@@ -25,25 +25,25 @@
25
25
  "type": "module",
26
26
  "devDependencies": {
27
27
  "@eslint/eslintrc": "^3.3.1",
28
- "@eslint/js": "^9.23.0",
29
- "@types/chai": "^5.2.1",
28
+ "@eslint/js": "^9.28.0",
29
+ "@types/chai": "^5.2.2",
30
30
  "@types/memoizee": "^0.4.12",
31
31
  "@types/mocha": "^10.0.10",
32
- "@types/node": "^22.13.13",
33
- "@typescript-eslint/eslint-plugin": "^8.28.0",
34
- "@typescript-eslint/parser": "^8.28.0",
32
+ "@types/node": "^24.0.1",
33
+ "@typescript-eslint/eslint-plugin": "^8.34.0",
34
+ "@typescript-eslint/parser": "^8.34.0",
35
35
  "babel-eslint": "^10.1.0",
36
36
  "chai": "^5.2.0",
37
- "eslint": "^9.23.0",
38
- "globals": "^16.0.0",
39
- "mocha": "^11.1.0",
40
- "typescript": "^5.8.2",
41
- "vue-eslint-parser": "^10.1.1"
37
+ "eslint": "^9.28.0",
38
+ "globals": "^16.2.0",
39
+ "mocha": "^11.6.0",
40
+ "typescript": "^5.8.3",
41
+ "vue-eslint-parser": "^10.1.3"
42
42
  },
43
43
  "dependencies": {
44
- "@curvefi/ethcall": "6.0.13",
45
- "bignumber.js": "^9.1.2",
46
- "ethers": "^6.13.5",
44
+ "@curvefi/ethcall": "6.0.15",
45
+ "bignumber.js": "^9.3.0",
46
+ "ethers": "^6.14.3",
47
47
  "memoizee": "^0.4.17"
48
48
  }
49
49
  }
@@ -1,6 +1,6 @@
1
1
  import {ethers} from "ethers";
2
2
  import memoize from "memoizee";
3
- import {llamalend} from "./llamalend.js";
3
+ import type { Llamalend } from "./llamalend.js";
4
4
  import {
5
5
  IDict,
6
6
  IExtendedPoolDataFromApi,
@@ -37,8 +37,8 @@ const _getAllPoolsFromApi = async (network: INetworkName): Promise<IExtendedPool
37
37
  ]);
38
38
  }
39
39
 
40
- export const _getUsdPricesFromApi = async (): Promise<IDict<number>> => {
41
- const network = llamalend.constants.NETWORK_NAME;
40
+ export async function _getUsdPricesFromApi(this: Llamalend): Promise<IDict<number>> {
41
+ const network = this.constants.NETWORK_NAME;
42
42
  const allTypesExtendedPoolData = await _getAllPoolsFromApi(network);
43
43
  const priceDict: IDict<Record<string, number>[]> = {};
44
44
  const priceDictByMaxTvl: IDict<number> = {};
@@ -167,15 +167,15 @@ export const _getMarketsData = memoize(
167
167
 
168
168
  // --- ODOS ---
169
169
 
170
- export const _getQuoteOdos = async (fromToken: string, toToken: string, _amount: bigint, blacklist: string, pathVizImage: boolean, slippage = 0.5): Promise<IQuoteOdos> => {
170
+ export async function _getQuoteOdos(this: Llamalend, fromToken: string, toToken: string, _amount: bigint, blacklist: string, pathVizImage: boolean, slippage = 0.5): Promise<IQuoteOdos> {
171
171
  if (_amount === BigInt(0)) return { outAmounts: ["0.0"], pathId: '', pathVizImage: '', priceImpact: 0, slippage };
172
172
 
173
173
  if (ethers.getAddress(fromToken) == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") fromToken = "0x0000000000000000000000000000000000000000";
174
174
  if (ethers.getAddress(toToken) == "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE") toToken = "0x0000000000000000000000000000000000000000";
175
175
 
176
- const url = `https://prices.curve.finance/odos/quote?chain_id=${llamalend.chainId}&from_address=${ethers.getAddress(fromToken)}` +
176
+ const url = `https://prices.curve.finance/odos/quote?chain_id=${this.chainId}&from_address=${ethers.getAddress(fromToken)}` +
177
177
  `&to_address=${ethers.getAddress(toToken)}&amount=${_amount.toString()}&slippage=${slippage}&pathVizImage=${pathVizImage}` +
178
- `&caller_address=${ethers.getAddress(llamalend.constants.ALIASES.leverage_zap)}&blacklist=${ethers.getAddress(blacklist)}`;
178
+ `&caller_address=${ethers.getAddress(this.constants.ALIASES.leverage_zap)}&blacklist=${ethers.getAddress(blacklist)}`;
179
179
 
180
180
  const response = await fetch(url, { headers: {"accept": "application/json"} });
181
181
  if (response.status !== 200) {
@@ -185,13 +185,13 @@ export const _getQuoteOdos = async (fromToken: string, toToken: string, _amount:
185
185
  return { ...data, slippage };
186
186
  }
187
187
 
188
- export const _getExpectedOdos = async (fromToken: string, toToken: string, _amount: bigint, blacklist: string) => {
189
- return (await _getQuoteOdos(fromToken, toToken, _amount, blacklist, false)).outAmounts[0]
188
+ export async function _getExpectedOdos(this: Llamalend, fromToken: string, toToken: string, _amount: bigint, blacklist: string) {
189
+ return (await _getQuoteOdos.call(this, fromToken, toToken, _amount, blacklist, false)).outAmounts[0]
190
190
  }
191
191
 
192
- export const _assembleTxOdos = memoize(
193
- async (pathId: string): Promise<string> => {
194
- const url = `https://prices.curve.finance/odos/assemble?user=${ethers.getAddress(llamalend.constants.ALIASES.leverage_zap)}&path_id=${pathId}`;
192
+ const _assembleTxOdosMemoized = memoize(
193
+ async function (leverageZapAddress: string, pathId: string): Promise<string> {
194
+ const url = `https://prices.curve.finance/odos/assemble?user=${ethers.getAddress(leverageZapAddress)}&path_id=${pathId}`;
195
195
 
196
196
  const response = await fetch(url, { headers: {'Content-Type': 'application/json'} });
197
197
  if (response.status !== 200) {
@@ -204,4 +204,18 @@ export const _assembleTxOdos = memoize(
204
204
  promise: true,
205
205
  maxAge: 10 * 1000, // 10s
206
206
  }
207
+ );
208
+
209
+ export async function _assembleTxOdos(this: Llamalend, pathId: string): Promise<string> {
210
+ return _assembleTxOdosMemoized(this.constants.ALIASES.leverage_zap, pathId);
211
+ }
212
+
213
+ export const _getHiddenPools = memoize(
214
+ () => fetch(`https://api.curve.finance/api/getHiddenPools`)
215
+ .then((r) => (r.json()))
216
+ .then((json) => (json as {data: IDict<string[]>}).data),
217
+ {
218
+ promise: true,
219
+ maxAge: 5 * 60 * 1000, // 5m
220
+ }
207
221
  )
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ethers, Networkish } from "ethers";
2
2
  import { LendMarketTemplate, getLendMarket } from "./lendMarkets/index.js";
3
3
  import { MintMarketTemplate, getMintMarket} from "./mintMarkets/index.js";
4
- import { llamalend as _llamalend} from "./llamalend.js";
4
+ import { Llamalend } from "./llamalend.js";
5
5
  import {
6
6
  getBalances,
7
7
  getAllowance,
@@ -47,84 +47,96 @@ import {
47
47
  } from "./st-crvUSD.js";
48
48
 
49
49
 
50
- async function init (
51
- providerType: 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy',
52
- providerSettings: { url?: string, privateKey?: string, batchMaxCount? : number } | { externalProvider: ethers.Eip1193Provider } | { network?: Networkish, apiKey?: string },
53
- options: { gasPrice?: number, maxFeePerGas?: number, maxPriorityFeePerGas?: number, chainId?: number } = {}
54
- ): Promise<void> {
55
- await _llamalend.init(providerType, providerSettings, options);
56
- // @ts-ignore
57
- this.signerAddress = _llamalend.signerAddress;
58
- // @ts-ignore
59
- this.chainId = _llamalend.chainId;
60
- }
50
+ export function createLlamalend() {
51
+ const llamalend = new Llamalend();
52
+ return {
53
+ // Init and config
54
+ async init(
55
+ providerType: 'JsonRpc' | 'Web3' | 'Infura' | 'Alchemy',
56
+ providerSettings: { url?: string, privateKey?: string, batchMaxCount? : number } | { externalProvider: ethers.Eip1193Provider } | { network?: Networkish, apiKey?: string },
57
+ options: { gasPrice?: number, maxFeePerGas?: number, maxPriorityFeePerGas?: number, chainId?: number } = {}
58
+ ): Promise<void> {
59
+ await llamalend.init(providerType, providerSettings, options);
60
+ },
61
61
 
62
- function setCustomFeeData (customFeeData: { gasPrice?: number, maxFeePerGas?: number, maxPriorityFeePerGas?: number }): void {
63
- _llamalend.setCustomFeeData(customFeeData);
64
- }
62
+ setCustomFeeData(customFeeData: { gasPrice?: number, maxFeePerGas?: number, maxPriorityFeePerGas?: number }): void {
63
+ llamalend.setCustomFeeData(customFeeData);
64
+ },
65
65
 
66
- const llamalend = {
67
- init,
68
- chainId: 0,
69
- signerAddress: '',
70
- LendMarketTemplate,
71
- getLendMarket,
72
- MintMarketTemplate,
73
- getMintMarket,
74
- totalSupply,
75
- getLsdApy,
76
- setCustomFeeData,
77
- getBalances,
78
- getAllowance,
79
- hasAllowance,
80
- ensureAllowance,
81
- getUsdRate,
82
- getGasPriceFromL1,
83
- getGasPriceFromL2,
84
- getGasInfoForL2,
85
- fetchStats: _llamalend.fetchStats,
86
- mintMarkets: {
87
- getMarketList :_llamalend.getMintMarketList,
88
- },
89
- lendMarkets: {
90
- fetchMarkets: _llamalend.fetchLendMarkets,
91
- getMarketList: _llamalend.getLendMarketList,
92
- },
93
- estimateGas: {
94
- ensureAllowance: ensureAllowanceEstimateGas,
95
- },
96
- st_crvUSD: {
97
- convertToAssets,
98
- convertToShares,
99
- userBalances,
100
- totalSupplyAndCrvUSDLocked,
101
- maxDeposit,
102
- previewDeposit,
103
- depositIsApproved,
104
- depositAllowance,
105
- depositApprove,
106
- deposit,
107
- maxMint,
108
- previewMint,
109
- mintIsApproved,
110
- mintAllowance,
111
- mintApprove,
112
- mint,
113
- maxWithdraw,
114
- previewWithdraw,
115
- withdraw,
116
- maxRedeem,
117
- previewRedeem,
118
- redeem,
66
+ get chainId(): number { return llamalend.chainId; },
67
+ get signerAddress(): string { return llamalend.signerAddress; },
68
+
69
+ // Market templates
70
+ LendMarketTemplate,
71
+ MintMarketTemplate,
72
+
73
+ // Market constructors
74
+ getLendMarket: getLendMarket.bind(llamalend),
75
+ getMintMarket: getMintMarket.bind(llamalend),
76
+
77
+ // Utility functions
78
+ totalSupply: totalSupply.bind(llamalend),
79
+ getLsdApy: getLsdApy.bind(llamalend),
80
+ getBalances: getBalances.bind(llamalend),
81
+ getAllowance: getAllowance.bind(llamalend),
82
+ hasAllowance: hasAllowance.bind(llamalend),
83
+ ensureAllowance: ensureAllowance.bind(llamalend),
84
+ getUsdRate: getUsdRate.bind(llamalend),
85
+ getGasPriceFromL1: getGasPriceFromL1.bind(llamalend),
86
+ getGasPriceFromL2: getGasPriceFromL2.bind(llamalend),
87
+ getGasInfoForL2: getGasInfoForL2.bind(llamalend),
88
+
89
+ // Core methods
90
+ fetchStats: llamalend.fetchStats.bind(llamalend),
91
+
92
+ // Market lists
93
+ mintMarkets: {
94
+ getMarketList: llamalend.getMintMarketList.bind(llamalend),
95
+ },
96
+ lendMarkets: {
97
+ fetchMarkets: llamalend.fetchLendMarkets.bind(llamalend),
98
+ getMarketList: llamalend.getLendMarketList.bind(llamalend),
99
+ },
100
+
101
+ // Gas estimation
119
102
  estimateGas: {
120
- depositApprove: depositApproveEstimateGas,
121
- deposit: depositEstimateGas,
122
- mintApprove: mintApproveEstimateGas,
123
- mint: mintEstimateGas,
124
- withdraw: withdrawEstimateGas,
125
- redeem: redeemEstimateGas,
103
+ ensureAllowance: ensureAllowanceEstimateGas.bind(llamalend),
104
+ },
105
+
106
+ // st-crvUSD methods
107
+ st_crvUSD: {
108
+ convertToAssets: convertToAssets.bind(llamalend),
109
+ convertToShares: convertToShares.bind(llamalend),
110
+ userBalances: userBalances.bind(llamalend),
111
+ totalSupplyAndCrvUSDLocked: totalSupplyAndCrvUSDLocked.bind(llamalend),
112
+ maxDeposit: maxDeposit.bind(llamalend),
113
+ previewDeposit: previewDeposit.bind(llamalend),
114
+ depositIsApproved: depositIsApproved.bind(llamalend),
115
+ depositAllowance: depositAllowance.bind(llamalend),
116
+ depositApprove: depositApprove.bind(llamalend),
117
+ deposit: deposit.bind(llamalend),
118
+ maxMint: maxMint.bind(llamalend),
119
+ previewMint: previewMint.bind(llamalend),
120
+ mintIsApproved: mintIsApproved.bind(llamalend),
121
+ mintAllowance: mintAllowance.bind(llamalend),
122
+ mintApprove: mintApprove.bind(llamalend),
123
+ mint: mint.bind(llamalend),
124
+ maxWithdraw: maxWithdraw.bind(llamalend),
125
+ previewWithdraw: previewWithdraw.bind(llamalend),
126
+ withdraw: withdraw.bind(llamalend),
127
+ maxRedeem: maxRedeem.bind(llamalend),
128
+ previewRedeem: previewRedeem.bind(llamalend),
129
+ redeem: redeem.bind(llamalend),
130
+ estimateGas: {
131
+ depositApprove: depositApproveEstimateGas.bind(llamalend),
132
+ deposit: depositEstimateGas.bind(llamalend),
133
+ mintApprove: mintApproveEstimateGas.bind(llamalend),
134
+ mint: mintEstimateGas.bind(llamalend),
135
+ withdraw: withdrawEstimateGas.bind(llamalend),
136
+ redeem: redeemEstimateGas.bind(llamalend),
137
+ },
126
138
  },
127
- },
139
+ };
128
140
  }
129
141
 
130
- export default llamalend;
142
+ export default createLlamalend();