@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.
- package/.github/workflows/publish.yml +1 -0
- package/lib/external-api.d.ts +5 -4
- package/lib/external-api.js +110 -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 +1 -2
- package/lib/llamalend.js +4 -18
- 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 +16 -12
- package/src/index.ts +88 -76
- package/src/lendMarkets/LendMarketTemplate.ts +348 -346
- package/src/lendMarkets/lendMarketConstructor.ts +4 -4
- package/src/llamalend.ts +35 -56
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curvefi/llamalend-api",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.22-beta.1",
|
|
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.
|
|
29
|
-
"@types/chai": "^5.2.
|
|
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": "^
|
|
33
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
34
|
-
"@typescript-eslint/parser": "^8.
|
|
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.
|
|
38
|
-
"globals": "^16.
|
|
39
|
-
"mocha": "^11.
|
|
40
|
-
"typescript": "^5.8.
|
|
41
|
-
"vue-eslint-parser": "^10.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.
|
|
45
|
-
"bignumber.js": "^9.
|
|
46
|
-
"ethers": "^6.
|
|
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
|
}
|
package/src/external-api.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {ethers} from "ethers";
|
|
2
2
|
import memoize from "memoizee";
|
|
3
|
-
import {
|
|
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
|
|
41
|
-
const network =
|
|
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
|
|
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=${
|
|
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(
|
|
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
|
|
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
|
-
|
|
193
|
-
async (pathId: string): Promise<string>
|
|
194
|
-
const url = `https://prices.curve.finance/odos/assemble?user=${ethers.getAddress(
|
|
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,8 @@ export const _assembleTxOdos = memoize(
|
|
|
204
204
|
promise: true,
|
|
205
205
|
maxAge: 10 * 1000, // 10s
|
|
206
206
|
}
|
|
207
|
-
)
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
export async function _assembleTxOdos(this: Llamalend, pathId: string): Promise<string> {
|
|
210
|
+
return _assembleTxOdosMemoized(this.constants.ALIASES.leverage_zap, pathId);
|
|
211
|
+
}
|
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 {
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
62
|
+
setCustomFeeData(customFeeData: { gasPrice?: number, maxFeePerGas?: number, maxPriorityFeePerGas?: number }): void {
|
|
63
|
+
llamalend.setCustomFeeData(customFeeData);
|
|
64
|
+
},
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
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
|
|
142
|
+
export default createLlamalend();
|