@curvefi/api 2.68.17 → 2.68.21
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/README.md +28 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +5 -2
- package/lib/router.d.ts +3 -1
- package/lib/router.js +35 -5
- package/lib/utils.d.ts +2 -1
- package/lib/utils.js +23 -0
- package/package.json +12 -12
package/README.md
CHANGED
|
@@ -181,6 +181,17 @@ import curve from "@curvefi/api";
|
|
|
181
181
|
// '0xb0cada2a2983dc0ed85a26916d32b9caefe45fecde47640bd7d0e214ff22aed3',
|
|
182
182
|
// '0x00ea7d827b3ad50ce933e96c579810cd7e70d66a034a86ec4e1e10005634d041'
|
|
183
183
|
// ]
|
|
184
|
+
|
|
185
|
+
// Get populated approve transactions (without executing)
|
|
186
|
+
const approveTxs = await curve.populateApprove(["DAI", "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"], ['1000', '1000'], spender);
|
|
187
|
+
// OR with custom user address (for API):
|
|
188
|
+
// await curve.populateApprove(["DAI", "USDC"], ['1000', '1000'], spender, false, '0x...userAddress');
|
|
189
|
+
// Returns array of TransactionLike objects (may include reset to 0 if needed for some tokens)
|
|
190
|
+
console.log(approveTxs);
|
|
191
|
+
// [
|
|
192
|
+
// { to: '0x6B17...', data: '0x095ea7b3...', hash: '0x...', ... },
|
|
193
|
+
// { to: '0xA0b8...', data: '0x095ea7b3...', hash: '0x...', ... }
|
|
194
|
+
// ]
|
|
184
195
|
})()
|
|
185
196
|
```
|
|
186
197
|
|
|
@@ -1191,6 +1202,13 @@ import curve from "@curvefi/api";
|
|
|
1191
1202
|
// [
|
|
1192
1203
|
// '0xc111e471715ae6f5437e12d3b94868a5b6542cd7304efca18b5782d315760ae5'
|
|
1193
1204
|
// ]
|
|
1205
|
+
|
|
1206
|
+
// Get populated transactions for approve (without executing)
|
|
1207
|
+
const approveTxs = await curve.router.populateApprove('DAI', 1000, false, userAddress);
|
|
1208
|
+
// OR const approveTxs = await curve.router.populateApprove('0x6B175474E89094C44Da98b954EedeAC495271d0F', 1000, false, userAddress);
|
|
1209
|
+
console.log(approveTxs);
|
|
1210
|
+
// [{ to: '0x6B17...', data: '0x...', ... }]
|
|
1211
|
+
// Returns array of TransactionLike objects
|
|
1194
1212
|
const swapTx = await curve.router.swap('DAI', 'CRV', '1000');
|
|
1195
1213
|
// OR const swapTx = await curve.router.swap('0x6B175474E89094C44Da98b954EedeAC495271d0F', '0xD533a949740bb3306d119CC777fa900bA034cd52', '1000');
|
|
1196
1214
|
console.log(swapTx.hash);
|
|
@@ -1200,6 +1218,16 @@ import curve from "@curvefi/api";
|
|
|
1200
1218
|
|
|
1201
1219
|
await curve.getBalances(['DAI', 'CRV']);
|
|
1202
1220
|
// [ '8900.0', '100428.626463428100672494' ]
|
|
1221
|
+
|
|
1222
|
+
// Get calldata for swap (without executing transaction)
|
|
1223
|
+
// First, you need to call getBestRouteAndOutput to cache the route
|
|
1224
|
+
await curve.router.getBestRouteAndOutput('DAI', 'CRV', '1000');
|
|
1225
|
+
|
|
1226
|
+
// Then get calldata
|
|
1227
|
+
const { data, to, from, amount } = await curve.router.populateSwap('DAI', 'CRV', '1000', 0.5);
|
|
1228
|
+
// OR const tx = await curve.router.populateSwap('0x6B175474E89094C44Da98b954EedeAC495271d0F', '0xD533a949740bb3306d119CC777fa900bA034cd52', '1000', 0.5);
|
|
1229
|
+
console.log(data);
|
|
1230
|
+
// 0x8f726f1c000000000000000000000000...
|
|
1203
1231
|
})()
|
|
1204
1232
|
```
|
|
1205
1233
|
|
package/lib/index.d.ts
CHANGED
|
@@ -51,6 +51,7 @@ export declare const createCurve: () => {
|
|
|
51
51
|
getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
|
|
52
52
|
hasAllowance: (coins: string[], amounts: (string | number)[], address: string, spender: string) => Promise<boolean>;
|
|
53
53
|
ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string, isMax?: boolean | undefined) => Promise<string[]>;
|
|
54
|
+
populateApprove: (coins: string[], amounts: (string | number)[], spender: string, isMax?: boolean | undefined, userAddress?: string | undefined) => Promise<ethers.TransactionLike<string>[]>;
|
|
54
55
|
getCoinsData: (...args: string[] | string[][]) => Promise<{
|
|
55
56
|
name: string;
|
|
56
57
|
symbol: string;
|
|
@@ -254,7 +255,9 @@ export declare const createCurve: () => {
|
|
|
254
255
|
priceImpact: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<number>;
|
|
255
256
|
isApproved: (inputCoin: string, amount: string | number) => Promise<boolean>;
|
|
256
257
|
approve: (inputCoin: string, amount: string | number) => Promise<string[]>;
|
|
258
|
+
populateApprove: (inputCoin: string, amount: string | number, isMax: boolean | undefined, userAddress: string) => Promise<ethers.TransactionLike<string>[]>;
|
|
257
259
|
swap: (inputCoin: string, outputCoin: string, amount: string | number, slippage?: number | undefined) => Promise<ethers.ContractTransactionResponse>;
|
|
260
|
+
populateSwap: (inputCoin: string, outputCoin: string, amount: string | number, slippage?: number | undefined) => Promise<ethers.TransactionLike<string>>;
|
|
258
261
|
getSwappedAmount: (tx: ethers.ContractTransactionResponse, outputCoin: string) => Promise<string>;
|
|
259
262
|
estimateGas: {
|
|
260
263
|
approve: (inputCoin: string, amount: string | number) => Promise<number | number[]>;
|
|
@@ -361,6 +364,7 @@ declare const _default: {
|
|
|
361
364
|
getAllowance: (coins: string[], address: string, spender: string) => Promise<string[]>;
|
|
362
365
|
hasAllowance: (coins: string[], amounts: (string | number)[], address: string, spender: string) => Promise<boolean>;
|
|
363
366
|
ensureAllowance: (coins: string[], amounts: (string | number)[], spender: string, isMax?: boolean | undefined) => Promise<string[]>;
|
|
367
|
+
populateApprove: (coins: string[], amounts: (string | number)[], spender: string, isMax?: boolean | undefined, userAddress?: string | undefined) => Promise<ethers.TransactionLike<string>[]>;
|
|
364
368
|
getCoinsData: (...args: string[] | string[][]) => Promise<{
|
|
365
369
|
name: string;
|
|
366
370
|
symbol: string;
|
|
@@ -564,7 +568,9 @@ declare const _default: {
|
|
|
564
568
|
priceImpact: (inputCoin: string, outputCoin: string, amount: string | number) => Promise<number>;
|
|
565
569
|
isApproved: (inputCoin: string, amount: string | number) => Promise<boolean>;
|
|
566
570
|
approve: (inputCoin: string, amount: string | number) => Promise<string[]>;
|
|
571
|
+
populateApprove: (inputCoin: string, amount: string | number, isMax: boolean | undefined, userAddress: string) => Promise<ethers.TransactionLike<string>[]>;
|
|
567
572
|
swap: (inputCoin: string, outputCoin: string, amount: string | number, slippage?: number | undefined) => Promise<ethers.ContractTransactionResponse>;
|
|
573
|
+
populateSwap: (inputCoin: string, outputCoin: string, amount: string | number, slippage?: number | undefined) => Promise<ethers.TransactionLike<string>>;
|
|
568
574
|
getSwappedAmount: (tx: ethers.ContractTransactionResponse, outputCoin: string) => Promise<string>;
|
|
569
575
|
estimateGas: {
|
|
570
576
|
approve: (inputCoin: string, amount: string | number) => Promise<number | number[]>;
|
package/lib/index.js
CHANGED
|
@@ -9,10 +9,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { PoolTemplate, getPool } from "./pools/index.js";
|
|
11
11
|
import { getUserPoolListByLiquidity, getUserPoolListByClaimable, getUserPoolList, getUserLiquidityUSD, getUserClaimable, } from "./pools/utils.js";
|
|
12
|
-
import { getBestRouteAndOutput, getArgs, swapExpected, swapRequired, swapPriceImpact, swapIsApproved, swapApproveEstimateGas, swapApprove, swapEstimateGas, swap, getSwappedAmount, } from "./router.js";
|
|
12
|
+
import { getBestRouteAndOutput, getArgs, swapExpected, swapRequired, swapPriceImpact, swapIsApproved, swapApproveEstimateGas, swapApprove, swapPopulateApprove, swapEstimateGas, swap, populateSwap, getSwappedAmount, } from "./router.js";
|
|
13
13
|
import { Curve } from "./curve.js";
|
|
14
14
|
import { getCrv, getLockedAmountAndUnlockTime, getVeCrv, getVeCrvPct, calcUnlockTime, createLockEstimateGas, createLock, isApproved, approveEstimateGas, approve, increaseAmountEstimateGas, increaseAmount, increaseUnlockTimeEstimateGas, increaseUnlockTime, withdrawLockedCrvEstimateGas, withdrawLockedCrv, claimableFees, claimFeesEstimateGas, claimFees, lastEthBlock, getAnycallBalance, topUpAnycall, topUpAnycallEstimateGas, lastBlockSent, blockToSend, sendBlockhash, sendBlockhashEstimateGas, submitProof, submitProofEstimateGas, claimFeesCrvUSDEstimateGas, claimableFeesCrvUSD, claimFeesCrvUSD, calculateVeCrv, } from "./boosting.js";
|
|
15
|
-
import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, getUsdRate, getGasPriceFromL1, getGasPriceFromL2, getGasInfoForL2, getTVL, getCoinsData, getVolume, hasDepositAndStake, hasRouter, getBasePools, getGasPrice, getCurveLiteNetworks, } from "./utils.js";
|
|
15
|
+
import { getBalances, getAllowance, hasAllowance, ensureAllowanceEstimateGas, ensureAllowance, populateApprove, getUsdRate, getGasPriceFromL1, getGasPriceFromL2, getGasInfoForL2, getTVL, getCoinsData, getVolume, hasDepositAndStake, hasRouter, getBasePools, getGasPrice, getCurveLiteNetworks, } from "./utils.js";
|
|
16
16
|
import { deployStablePlainPool, deployStablePlainPoolEstimateGas, getDeployedStablePlainPoolAddress, setOracle, setOracleEstimateGas, deployStableMetaPool, deployStableMetaPoolEstimateGas, getDeployedStableMetaPoolAddress, deployCryptoPool, deployCryptoPoolEstimateGas, getDeployedCryptoPoolAddress, deployTricryptoPool, deployTricryptoPoolEstimateGas, getDeployedTricryptoPoolAddress, deployGauge, deployGaugeEstimateGas, getDeployedGaugeAddress, deployGaugeSidechain, deployGaugeSidechainEstimateGas, deployGaugeMirror, deployGaugeMirrorEstimateGas, getDeployedGaugeMirrorAddress, getDeployedGaugeMirrorAddressByTx, deployStableNgPlainPool, deployStableNgPlainPoolEstimateGas, deployStableNgMetaPool, deployStableNgMetaPoolEstimateGas, deployTwocryptoPool, deployTwocryptoPoolEstimateGas, getDeployedTwocryptoPoolAddress, } from './factory/deploy.js';
|
|
17
17
|
import { getTwoCryptoImplementations } from './constants/twoCryptoImplementations.js';
|
|
18
18
|
import { crvSupplyStats, userCrv, userVeCrv, crvLockIsApproved, crvLockApproveEstimateGas, crvLockApprove, calcCrvUnlockTime, createCrvLockEstimateGas, createCrvLock, increaseCrvLockedAmountEstimateGas, increaseCrvLockedAmount, increaseCrvUnlockTimeEstimateGas, increaseCrvUnlockTime, withdrawLockedCrvEstimateGas as daoWithdrawLockedCrvEstimateGas, withdrawLockedCrv as daoWithdrawLockedCrv, claimableFees as daoClaimableFees, claimFeesEstimateGas as daoClaimFeesEstimateGas, claimFees as daoClaimFees, getVotingGaugeList, userGaugeVotes, voteForGaugeNextTime, voteForGaugeEstimateGas, voteForGauge, getProposalList, getProposal, userProposalVotes, voteForProposalEstimateGas, voteForProposal, executeVote, executeVoteEstimateGas, isCanVoteExecute, } from "./dao.js";
|
|
@@ -51,6 +51,7 @@ export const createCurve = () => {
|
|
|
51
51
|
getAllowance: getAllowance.bind(_curve),
|
|
52
52
|
hasAllowance: hasAllowance.bind(_curve),
|
|
53
53
|
ensureAllowance: ensureAllowance.bind(_curve),
|
|
54
|
+
populateApprove: populateApprove.bind(_curve),
|
|
54
55
|
getCoinsData: getCoinsData.bind(_curve),
|
|
55
56
|
getVolume: getVolume.bind(_curve),
|
|
56
57
|
hasDepositAndStake: hasDepositAndStake.bind(_curve),
|
|
@@ -228,7 +229,9 @@ export const createCurve = () => {
|
|
|
228
229
|
priceImpact: swapPriceImpact.bind(_curve),
|
|
229
230
|
isApproved: swapIsApproved.bind(_curve),
|
|
230
231
|
approve: swapApprove.bind(_curve),
|
|
232
|
+
populateApprove: swapPopulateApprove.bind(_curve),
|
|
231
233
|
swap: swap.bind(_curve),
|
|
234
|
+
populateSwap: populateSwap.bind(_curve),
|
|
232
235
|
getSwappedAmount: getSwappedAmount.bind(_curve),
|
|
233
236
|
estimateGas: {
|
|
234
237
|
approve: swapApproveEstimateGas.bind(_curve),
|
package/lib/router.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ethers } from "ethers";
|
|
1
|
+
import { ethers, TransactionLike } from "ethers";
|
|
2
2
|
import { type Curve } from "./curve.js";
|
|
3
3
|
import { IRoute } from "./interfaces";
|
|
4
4
|
export declare function getBestRouteAndOutput(this: Curve, inputCoin: string, outputCoin: string, amount: number | string): Promise<{
|
|
@@ -20,6 +20,8 @@ export declare function swapPriceImpact(this: Curve, inputCoin: string, outputCo
|
|
|
20
20
|
export declare function swapIsApproved(this: Curve, inputCoin: string, amount: number | string): Promise<boolean>;
|
|
21
21
|
export declare function swapApproveEstimateGas(this: Curve, inputCoin: string, amount: number | string): Promise<number | number[]>;
|
|
22
22
|
export declare function swapApprove(this: Curve, inputCoin: string, amount: number | string): Promise<string[]>;
|
|
23
|
+
export declare function swapPopulateApprove(this: Curve, inputCoin: string, amount: number | string, isMax: boolean | undefined, userAddress: string): Promise<TransactionLike[]>;
|
|
23
24
|
export declare function swapEstimateGas(this: Curve, inputCoin: string, outputCoin: string, amount: number | string): Promise<number | number[]>;
|
|
24
25
|
export declare function swap(this: Curve, inputCoin: string, outputCoin: string, amount: number | string, slippage?: number): Promise<ethers.ContractTransactionResponse>;
|
|
26
|
+
export declare function populateSwap(this: Curve, inputCoin: string, outputCoin: string, amount: number | string, slippage?: number): Promise<TransactionLike>;
|
|
25
27
|
export declare function getSwappedAmount(this: Curve, tx: ethers.ContractTransactionResponse, outputCoin: string): Promise<string>;
|
package/lib/router.js
CHANGED
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { ethers } from "ethers";
|
|
11
11
|
import { OLD_CHAINS } from "./curve.js";
|
|
12
|
-
import { _cutZeros, _get_price_impact, _get_small_x, _getCoinAddresses, _getCoinDecimals, _getUsdRate, BN, DIGas, ensureAllowance, ensureAllowanceEstimateGas, ETH_ADDRESS, fromBN, getGasPriceFromL1, getTxCostsUsd, hasAllowance, isEth, parseUnits, runWorker, smartNumber, toBN, } from "./utils.js";
|
|
12
|
+
import { _cutZeros, _get_price_impact, _get_small_x, _getCoinAddresses, _getCoinDecimals, _getUsdRate, BN, DIGas, ensureAllowance, ensureAllowanceEstimateGas, ETH_ADDRESS, fromBN, getGasPriceFromL1, getTxCostsUsd, hasAllowance, isEth, parseUnits, populateApprove, runWorker, smartNumber, toBN, } from "./utils.js";
|
|
13
13
|
import { getPool } from "./pools/index.js";
|
|
14
14
|
import { _getAmplificationCoefficientsFromApi } from "./pools/utils.js";
|
|
15
15
|
import { L2Networks } from "./constants/L2Networks.js";
|
|
@@ -373,6 +373,11 @@ export function swapApprove(inputCoin, amount) {
|
|
|
373
373
|
return yield ensureAllowance.call(this, [inputCoin], [amount], this.constants.ALIASES.router);
|
|
374
374
|
});
|
|
375
375
|
}
|
|
376
|
+
export function swapPopulateApprove(inputCoin_1, amount_1) {
|
|
377
|
+
return __awaiter(this, arguments, void 0, function* (inputCoin, amount, isMax = true, userAddress) {
|
|
378
|
+
return yield populateApprove.call(this, [inputCoin], [amount], this.constants.ALIASES.router, isMax, userAddress);
|
|
379
|
+
});
|
|
380
|
+
}
|
|
376
381
|
export function swapEstimateGas(inputCoin, outputCoin, amount) {
|
|
377
382
|
return __awaiter(this, void 0, void 0, function* () {
|
|
378
383
|
const [inputCoinAddress, outputCoinAddress] = _getCoinAddresses.call(this, inputCoin, outputCoin);
|
|
@@ -385,7 +390,7 @@ export function swapEstimateGas(inputCoin, outputCoin, amount) {
|
|
|
385
390
|
return gas;
|
|
386
391
|
});
|
|
387
392
|
}
|
|
388
|
-
|
|
393
|
+
function prepareSwap(inputCoin_1, outputCoin_1, amount_1) {
|
|
389
394
|
return __awaiter(this, arguments, void 0, function* (inputCoin, outputCoin, amount, slippage = 0.5) {
|
|
390
395
|
const [inputCoinAddress, outputCoinAddress] = _getCoinAddresses.call(this, inputCoin, outputCoin);
|
|
391
396
|
const [inputCoinDecimals, outputCoinDecimals] = _getCoinDecimals.call(this, inputCoinAddress, outputCoinAddress);
|
|
@@ -405,10 +410,35 @@ export function swap(inputCoin_1, outputCoin_1, amount_1) {
|
|
|
405
410
|
const gasLimit = (DIGas(yield contract.exchange.estimateGas(_route, _swapParams, _amount, _minRecvAmount, _pools, Object.assign(Object.assign({}, this.constantOptions), { value })))) * (this.chainId === 1 ? this.parseUnits("130", 0) : this.parseUnits("160", 0)) / this.parseUnits("100", 0);
|
|
406
411
|
return yield contract.exchange(_route, _swapParams, _amount, _minRecvAmount, _pools, Object.assign(Object.assign({}, this.options), { value, gasLimit }));
|
|
407
412
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
413
|
+
const gasLimit = (DIGas(yield contract.exchange.estimateGas(_route, _swapParams, _amount, _minRecvAmount, Object.assign(Object.assign({}, this.constantOptions), { value })))) * this.parseUnits("160", 0) / this.parseUnits("100", 0);
|
|
414
|
+
return [contract, [_route, _swapParams, _amount, _minRecvAmount], Object.assign(Object.assign({}, this.options), { value, gasLimit })];
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
export function swap(inputCoin_1, outputCoin_1, amount_1) {
|
|
418
|
+
return __awaiter(this, arguments, void 0, function* (inputCoin, outputCoin, amount, slippage = 0.5) {
|
|
419
|
+
const [contract, params, options] = yield prepareSwap.call(this, inputCoin, outputCoin, amount, slippage);
|
|
420
|
+
return yield contract.exchange(...params, options);
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
export function populateSwap(inputCoin_1, outputCoin_1, amount_1) {
|
|
424
|
+
return __awaiter(this, arguments, void 0, function* (inputCoin, outputCoin, amount, slippage = 0.5) {
|
|
425
|
+
console.log(inputCoin, outputCoin, amount, slippage);
|
|
426
|
+
const [inputCoinAddress, outputCoinAddress] = _getCoinAddresses.call(this, inputCoin, outputCoin);
|
|
427
|
+
const [inputCoinDecimals, outputCoinDecimals] = _getCoinDecimals.call(this, inputCoinAddress, outputCoinAddress);
|
|
428
|
+
const { route, output } = _getBestRouteAndOutput.call(this, inputCoinAddress, outputCoinAddress, amount);
|
|
429
|
+
if (route.length === 0) {
|
|
430
|
+
throw new Error("This pair can't be exchanged");
|
|
411
431
|
}
|
|
432
|
+
const { _route, _swapParams, _pools } = _getExchangeArgs.call(this, route);
|
|
433
|
+
const _amount = parseUnits(amount, inputCoinDecimals);
|
|
434
|
+
const minRecvAmountBN = BN(output).times(100 - slippage).div(100);
|
|
435
|
+
const _minRecvAmount = fromBN(minRecvAmountBN, outputCoinDecimals);
|
|
436
|
+
const contract = this.contracts[this.constants.ALIASES.router].contract;
|
|
437
|
+
return yield contract.exchange.populateTransaction(...[
|
|
438
|
+
_route, _swapParams, _amount, _minRecvAmount,
|
|
439
|
+
..._pools ? [_pools] : [],
|
|
440
|
+
{ value: isEth(inputCoinAddress) ? _amount : this.parseUnits("0") },
|
|
441
|
+
]);
|
|
412
442
|
});
|
|
413
443
|
}
|
|
414
444
|
export function getSwappedAmount(tx, outputCoin) {
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Contract } from 'ethers';
|
|
1
|
+
import { Contract, TransactionLike } from 'ethers';
|
|
2
2
|
import { Contract as MulticallContract } from "@curvefi/ethcall";
|
|
3
3
|
import BigNumber from 'bignumber.js';
|
|
4
4
|
import { Abi, AbiFunction, IBasePoolShortItem, IChainId, ICurveLiteNetwork, IDict, INetworkName, IRewardFromApi, IVolumeAndAPYs, REFERENCE_ASSET } from './interfaces';
|
|
@@ -33,6 +33,7 @@ export declare function hasAllowance(this: Curve, coins: string[], amounts: (num
|
|
|
33
33
|
export declare function _ensureAllowance(this: Curve, coins: string[], amounts: bigint[], spender: string, isMax?: boolean): Promise<string[]>;
|
|
34
34
|
export declare function ensureAllowanceEstimateGas(this: Curve, coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean): Promise<number | number[]>;
|
|
35
35
|
export declare function ensureAllowance(this: Curve, coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean): Promise<string[]>;
|
|
36
|
+
export declare function populateApprove(this: Curve, coins: string[], amounts: (number | string)[], spender: string, isMax?: boolean, userAddress?: string): Promise<TransactionLike[]>;
|
|
36
37
|
export declare function getPoolIdBySwapAddress(this: Curve, swapAddress: string): string;
|
|
37
38
|
export declare function _getRewardsFromApi(this: Curve): Promise<IDict<IRewardFromApi[]>>;
|
|
38
39
|
export declare function _getUsdRate(this: Curve, assetId: string): Promise<number>;
|
package/lib/utils.js
CHANGED
|
@@ -269,6 +269,29 @@ export function ensureAllowance(coins_1, amounts_1, spender_1) {
|
|
|
269
269
|
return yield _ensureAllowance.call(this, coinAddresses, _amounts, spender, isMax);
|
|
270
270
|
});
|
|
271
271
|
}
|
|
272
|
+
export function populateApprove(coins_1, amounts_1, spender_1) {
|
|
273
|
+
return __awaiter(this, arguments, void 0, function* (coins, amounts, spender, isMax = true, userAddress) {
|
|
274
|
+
const coinAddresses = _getCoinAddresses.call(this, coins);
|
|
275
|
+
const decimals = _getCoinDecimals.call(this, coinAddresses);
|
|
276
|
+
const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i]));
|
|
277
|
+
const address = userAddress || this.signerAddress;
|
|
278
|
+
if (!address)
|
|
279
|
+
throw Error("User address is not defined. Pass userAddress parameter.");
|
|
280
|
+
const allowance = yield _getAllowance.call(this, coinAddresses, address, spender);
|
|
281
|
+
const transactions = [];
|
|
282
|
+
for (let i = 0; i < allowance.length; i++) {
|
|
283
|
+
if (allowance[i] < _amounts[i]) {
|
|
284
|
+
const contract = this.contracts[coinAddresses[i]].contract;
|
|
285
|
+
const _approveAmount = isMax ? MAX_ALLOWANCE : _amounts[i];
|
|
286
|
+
if (allowance[i] > parseUnits("0")) {
|
|
287
|
+
transactions.push(yield contract.approve.populateTransaction(spender, parseUnits("0")));
|
|
288
|
+
}
|
|
289
|
+
transactions.push(yield contract.approve.populateTransaction(spender, _approveAmount));
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return transactions;
|
|
293
|
+
});
|
|
294
|
+
}
|
|
272
295
|
export function getPoolIdBySwapAddress(swapAddress) {
|
|
273
296
|
const poolsData = this.getPoolsData();
|
|
274
297
|
const poolIds = Object.entries(poolsData).filter(([, poolData]) => poolData.swap_address.toLowerCase() === swapAddress.toLowerCase());
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@curvefi/api",
|
|
3
|
-
"version": "2.68.
|
|
3
|
+
"version": "2.68.21",
|
|
4
4
|
"description": "JavaScript library for curve.finance",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"author": "Macket",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"private": false,
|
|
9
9
|
"engines": {
|
|
10
|
-
"node": "
|
|
10
|
+
"node": "24"
|
|
11
11
|
},
|
|
12
12
|
"repository": {
|
|
13
13
|
"type": "git",
|
|
@@ -25,20 +25,20 @@
|
|
|
25
25
|
},
|
|
26
26
|
"type": "module",
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@babel/eslint-parser": "^7.28.
|
|
28
|
+
"@babel/eslint-parser": "^7.28.5",
|
|
29
29
|
"@eslint/eslintrc": "^3.3.1",
|
|
30
|
-
"@eslint/js": "^9.
|
|
31
|
-
"@types/chai": "^5.2.
|
|
30
|
+
"@eslint/js": "^9.38.0",
|
|
31
|
+
"@types/chai": "^5.2.3",
|
|
32
32
|
"@types/memoizee": "^0.4.12",
|
|
33
33
|
"@types/mocha": "^10.0.10",
|
|
34
|
-
"@types/node": "^24.
|
|
35
|
-
"@typescript-eslint/eslint-plugin": "^8.
|
|
36
|
-
"@typescript-eslint/parser": "^8.
|
|
34
|
+
"@types/node": "^24.9.2",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^8.46.2",
|
|
36
|
+
"@typescript-eslint/parser": "^8.46.2",
|
|
37
37
|
"chai": "^5.3.3",
|
|
38
|
-
"eslint": "^9.
|
|
39
|
-
"globals": "^16.
|
|
40
|
-
"mocha": "^11.7.
|
|
41
|
-
"typescript": "^5.9.
|
|
38
|
+
"eslint": "^9.38.0",
|
|
39
|
+
"globals": "^16.4.0",
|
|
40
|
+
"mocha": "^11.7.4",
|
|
41
|
+
"typescript": "^5.9.3",
|
|
42
42
|
"vue-eslint-parser": "^10.2.0"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|