diff --git a/package.json b/package.json index bc09d99..6a40961 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@curvefi/llamalend-api", - "version": "1.0.26", + "version": "1.0.27", "description": "JavaScript library for Curve Lending", "main": "lib/index.js", "author": "Macket", diff --git a/src/utils.ts b/src/utils.ts index 94de240..1321653 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -246,8 +246,18 @@ export const _ensureAllowance = async function (this: Llamalend, coins: string[] const contract = this.contracts[coins[i]].contract; const _approveAmount = isMax ? MAX_ALLOWANCE : _amounts[i]; await this.updateFeeData(); + + if (_allowance[i] > parseUnits("0")) { + const gasLimit = _mulBy1_3(DIGas(await contract.approve.estimateGas(spender, parseUnits("0"), this.constantOptions))); + const resetTx = await contract.approve(spender, parseUnits("0"), { ...this.options, gasLimit }); + txHashes.push(resetTx.hash); + await resetTx.wait(); + } + const gasLimit = _mulBy1_3(DIGas(await contract.approve.estimateGas(spender, _approveAmount, this.constantOptions))); - txHashes.push((await contract.approve(spender, _approveAmount, { ...this.options, gasLimit })).hash); + const approveTx = await contract.approve(spender, _approveAmount, { ...this.options, gasLimit }); + txHashes.push(approveTx.hash); + await approveTx.wait(); } }