From 627f0fc77b145d8f78dfafed785437bb4167cbb1 Mon Sep 17 00:00:00 2001 From: macket Date: Tue, 5 Nov 2024 20:52:07 +0400 Subject: [PATCH 1/3] chore: remove revoke step from reapprove --- src/utils.ts | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/utils.ts b/src/utils.ts index 0f9d761..db38214 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -234,20 +234,16 @@ export const hasAllowance = async (coins: string[], amounts: (number | string)[] return _allowance.map((a, i) => a >= _amounts[i]).reduce((a, b) => a && b); } -export const _ensureAllowance = async (coins: string[], amounts: bigint[], spender: string, isMax = true): Promise => { +export const _ensureAllowance = async (coins: string[], _amounts: bigint[], spender: string, isMax = true): Promise => { const address = lending.signerAddress; - const allowance: bigint[] = await _getAllowance(coins, address, spender); + const _allowance: bigint[] = await _getAllowance(coins, address, spender); const txHashes: string[] = [] - for (let i = 0; i < allowance.length; i++) { - if (allowance[i] < amounts[i]) { + for (let i = 0; i < _allowance.length; i++) { + if (_allowance[i] < _amounts[i]) { const contract = lending.contracts[coins[i]].contract; - const _approveAmount = isMax ? MAX_ALLOWANCE : amounts[i]; + const _approveAmount = isMax ? MAX_ALLOWANCE : _amounts[i]; await lending.updateFeeData(); - if (allowance[i] > lending.parseUnits("0")) { - const gasLimit = _mulBy1_3(DIGas(await contract.approve.estimateGas(spender, lending.parseUnits("0"), lending.constantOptions))); - txHashes.push((await contract.approve(spender, lending.parseUnits("0"), { ...lending.options, gasLimit })).hash); - } const gasLimit = _mulBy1_3(DIGas(await contract.approve.estimateGas(spender, _approveAmount, lending.constantOptions))); txHashes.push((await contract.approve(spender, _approveAmount, { ...lending.options, gasLimit })).hash); } @@ -261,27 +257,15 @@ export const ensureAllowanceEstimateGas = async (coins: string[], amounts: (numb const coinAddresses = _getCoinAddresses(coins); const decimals = _getCoinDecimals(coinAddresses); const _amounts = amounts.map((a, i) => parseUnits(a, decimals[i])); - const address = lending.signerAddress; - const _allowance: bigint[] = await _getAllowance(coinAddresses, address, spender); + const _allowance: bigint[] = await _getAllowance(coinAddresses, lending.signerAddress, spender); let gas = [0,0]; for (let i = 0; i < _allowance.length; i++) { if (_allowance[i] < _amounts[i]) { const contract = lending.contracts[coinAddresses[i]].contract; const _approveAmount = isMax ? MAX_ALLOWANCE : _amounts[i]; - if (_allowance[i] > lending.parseUnits("0")) { - let currentGas = smartNumber(await contract.approve.estimateGas(spender, lending.parseUnits("0"), lending.constantOptions)); - // For some coins (crv for example ) we can't estimate the second tx gas (approve: 0 --> amount), so we assume it will cost the same amount of gas - if (typeof currentGas === "number") { - currentGas = currentGas * 2; - } else { - currentGas = currentGas.map((g) => g * 2) - } - gas = gasSum(gas, currentGas); - } else { - const currentGas = smartNumber(await contract.approve.estimateGas(spender, _approveAmount, lending.constantOptions)); - gas = gasSum(gas, currentGas); - } + const currentGas = smartNumber(await contract.approve.estimateGas(spender, _approveAmount, lending.constantOptions)); + gas = gasSum(gas, currentGas); } } From e67086ee9d782f0309606fcb5a90c055e3a14847 Mon Sep 17 00:00:00 2001 From: macket Date: Tue, 5 Nov 2024 20:56:09 +0400 Subject: [PATCH 2/3] chore: real scrvUSD address --- src/constants/aliases.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/constants/aliases.ts b/src/constants/aliases.ts index 8c73bfe..5b27941 100644 --- a/src/constants/aliases.ts +++ b/src/constants/aliases.ts @@ -10,7 +10,7 @@ export const ALIASES_ETHEREUM = lowerCaseValues({ "leverage_zap": "0x3294514B78Df4Bb90132567fcf8E5e99f390B687", "leverage_markets_start_id": "9", "crvUSD": "0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E", - "st_crvUSD": "0xcea18a8752bb7e7817f9ae7565328fe415c0f2ca", // TODO It's Yearn vault for tests, change to real + "st_crvUSD": "0x0655977FEb2f289A4aB78af67BAB0d17aAb84367", }); export const ALIASES_POLYGON = lowerCaseValues({ From 79675aed70e7baf1acd8bc0887e2b627eb001173 Mon Sep 17 00:00:00 2001 From: macket Date: Tue, 5 Nov 2024 20:56:36 +0400 Subject: [PATCH 3/3] build: v2.3.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index dfcc028..ec03bff 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@curvefi/lending-api", - "version": "2.3.5", + "version": "2.3.6", "description": "JavaScript library for Curve Lending", "main": "lib/index.js", "author": "Macket",