@curvefi/api 2.68.16 → 2.68.18
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/constants/pools/ethereum.js +0 -24
- package/lib/index.d.ts +6 -0
- package/lib/index.js +5 -2
- package/lib/router.d.ts +3 -1
- package/lib/router.js +27 -1
- package/lib/utils.d.ts +2 -1
- package/lib/utils.js +23 -0
- package/package.json +1 -1
- package/lib/constants/abis/iearn/sCurveRewards.json +0 -1
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
|
|
|
@@ -1286,30 +1286,6 @@ export const POOLS_DATA_ETHEREUM = lowerCasePoolDataAddresses({
|
|
|
1286
1286
|
swap_abi: eursusdSwapABI,
|
|
1287
1287
|
gauge_abi: gaugeV4ABI,
|
|
1288
1288
|
},
|
|
1289
|
-
crveth: {
|
|
1290
|
-
name: "crveth",
|
|
1291
|
-
full_name: "crveth",
|
|
1292
|
-
symbol: "crveth",
|
|
1293
|
-
reference_asset: 'CRYPTO',
|
|
1294
|
-
swap_address: '0x8301AE4fc9c624d1D396cbDAa1ed877821D7C511',
|
|
1295
|
-
token_address: '0xEd4064f376cB8d68F770FB1Ff088a3d0F3FF5c4d',
|
|
1296
|
-
gauge_address: '0x1cEBdB0856dd985fAe9b8fEa2262469360B8a3a6',
|
|
1297
|
-
is_crypto: true,
|
|
1298
|
-
underlying_coins: ['ETH', 'CRV'],
|
|
1299
|
-
wrapped_coins: ['WETH', 'CRV'],
|
|
1300
|
-
underlying_coin_addresses: [
|
|
1301
|
-
'0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE',
|
|
1302
|
-
'0xD533a949740bb3306d119CC777fa900bA034cd52',
|
|
1303
|
-
],
|
|
1304
|
-
wrapped_coin_addresses: [
|
|
1305
|
-
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
|
|
1306
|
-
'0xD533a949740bb3306d119CC777fa900bA034cd52',
|
|
1307
|
-
],
|
|
1308
|
-
underlying_decimals: [18, 18],
|
|
1309
|
-
wrapped_decimals: [18, 18],
|
|
1310
|
-
swap_abi: crvethSwapABI,
|
|
1311
|
-
gauge_abi: gaugeV4ABI,
|
|
1312
|
-
},
|
|
1313
1289
|
rai: {
|
|
1314
1290
|
name: "rai",
|
|
1315
1291
|
full_name: "rai",
|
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);
|
|
@@ -411,6 +416,27 @@ export function swap(inputCoin_1, outputCoin_1, amount_1) {
|
|
|
411
416
|
}
|
|
412
417
|
});
|
|
413
418
|
}
|
|
419
|
+
export function populateSwap(inputCoin_1, outputCoin_1, amount_1) {
|
|
420
|
+
return __awaiter(this, arguments, void 0, function* (inputCoin, outputCoin, amount, slippage = 0.5) {
|
|
421
|
+
console.log(inputCoin, outputCoin, amount, slippage);
|
|
422
|
+
const [inputCoinAddress, outputCoinAddress] = _getCoinAddresses.call(this, inputCoin, outputCoin);
|
|
423
|
+
const [inputCoinDecimals, outputCoinDecimals] = _getCoinDecimals.call(this, inputCoinAddress, outputCoinAddress);
|
|
424
|
+
const { route, output } = _getBestRouteAndOutput.call(this, inputCoinAddress, outputCoinAddress, amount);
|
|
425
|
+
if (route.length === 0) {
|
|
426
|
+
throw new Error("This pair can't be exchanged");
|
|
427
|
+
}
|
|
428
|
+
const { _route, _swapParams, _pools } = _getExchangeArgs.call(this, route);
|
|
429
|
+
const _amount = parseUnits(amount, inputCoinDecimals);
|
|
430
|
+
const minRecvAmountBN = BN(output).times(100 - slippage).div(100);
|
|
431
|
+
const _minRecvAmount = fromBN(minRecvAmountBN, outputCoinDecimals);
|
|
432
|
+
const contract = this.contracts[this.constants.ALIASES.router].contract;
|
|
433
|
+
return yield contract.exchange.populateTransaction(...[
|
|
434
|
+
_route, _swapParams, _amount, _minRecvAmount,
|
|
435
|
+
..._pools ? [_pools] : [],
|
|
436
|
+
{ value: isEth(inputCoinAddress) ? _amount : this.parseUnits("0") },
|
|
437
|
+
]);
|
|
438
|
+
});
|
|
439
|
+
}
|
|
414
440
|
export function getSwappedAmount(tx, outputCoin) {
|
|
415
441
|
return __awaiter(this, void 0, void 0, function* () {
|
|
416
442
|
const [outputCoinAddress] = _getCoinAddresses.call(this, 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 +0,0 @@
|
|
|
1
|
-
[{ "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "previousOwner", "type": "address" }, { "indexed": true, "internalType": "address", "name": "newOwner", "type": "address" }], "name": "OwnershipTransferred", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": false, "internalType": "uint256", "name": "reward", "type": "uint256" }], "name": "RewardAdded", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "user", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "reward", "type": "uint256" }], "name": "RewardPaid", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "user", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "Staked", "type": "event" }, { "anonymous": false, "inputs": [{ "indexed": true, "internalType": "address", "name": "user", "type": "address" }, { "indexed": false, "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "Withdrawn", "type": "event" }, { "constant": true, "inputs": [], "name": "DURATION", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], "name": "balanceOf", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [{ "internalType": "address", "name": "account", "type": "address" }], "name": "earned", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [], "name": "exit", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [], "name": "getReward", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "isOwner", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "lastTimeRewardApplicable", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "lastUpdateTime", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "internalType": "uint256", "name": "reward", "type": "uint256" }], "name": "notifyRewardAmount", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "owner", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "periodFinish", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [], "name": "renounceOwnership", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "rewardPerToken", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "rewardPerTokenStored", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "rewardRate", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [{ "internalType": "address", "name": "", "type": "address" }], "name": "rewards", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "internalType": "address", "name": "_rewardDistribution", "type": "address" }], "name": "setRewardDistribution", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": false, "inputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "stake", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "totalSupply", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "internalType": "address", "name": "newOwner", "type": "address" }], "name": "transferOwnership", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [{ "internalType": "address", "name": "", "type": "address" }], "name": "userRewardPerTokenPaid", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": false, "inputs": [{ "internalType": "uint256", "name": "amount", "type": "uint256" }], "name": "withdraw", "outputs": [], "payable": false, "stateMutability": "nonpayable", "type": "function" }, { "constant": true, "inputs": [], "name": "y", "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function" }, { "constant": true, "inputs": [], "name": "yfi", "outputs": [{ "internalType": "contract IERC20", "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function" }]
|