Skip to content

Commit

Permalink
fix: gas estimations for gaugeDeposit/Withdraw
Browse files Browse the repository at this point in the history
  • Loading branch information
Makeev Ivan committed Sep 18, 2021
1 parent 1a83088 commit ccb4478
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@curvefi/api",
"version": "1.4.0",
"version": "1.4.1",
"description": "JavaScript library for curve.fi",
"main": "lib/index.js",
"scripts": {
Expand Down
14 changes: 14 additions & 0 deletions src/pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export class Pool {
estimateGas: {
addLiquidity: (amounts: string[]) => Promise<number>,
addLiquidityWrapped: (amounts: string[]) => Promise<number>,
gaugeDeposit: (lpTokenAmount: string) => Promise<number>,
gaugeWithdraw: (lpTokenAmount: string) => Promise<number>,
removeLiquidity: (lpTokenAmount: string) => Promise<number>,
removeLiquidityWrapped: (lpTokenAmount: string) => Promise<number>,
removeLiquidityImbalance: (amounts: string[]) => Promise<number>,
Expand Down Expand Up @@ -75,6 +77,8 @@ export class Pool {
this.estimateGas = {
addLiquidity: this.addLiquidityEstimateGas,
addLiquidityWrapped: this.addLiquidityWrappedEstimateGas,
gaugeDeposit: this.gaugeDepositEstimateGas,
gaugeWithdraw: this.gaugeWithdrawEstimateGas,
removeLiquidity: this.removeLiquidityEstimateGas,
removeLiquidityWrapped: this.removeLiquidityWrappedEstimateGas,
removeLiquidityImbalance: this.removeLiquidityImbalanceEstimateGas,
Expand Down Expand Up @@ -551,13 +555,23 @@ export class Pool {
return await this._removeLiquidityOneCoinSwap(_lpTokenAmount, i) as string;
}

private gaugeDepositEstimateGas = async (lpTokenAmount: string): Promise<number> => {
const _lpTokenAmount = ethers.utils.parseUnits(lpTokenAmount);
return (await curve.contracts[this.gauge].contract.estimateGas.deposit(_lpTokenAmount, curve.options)).toNumber();
}

public gaugeDeposit = async (lpTokenAmount: string): Promise<string> => {
const _lpTokenAmount = ethers.utils.parseUnits(lpTokenAmount);
await _ensureAllowance([this.lpToken], [_lpTokenAmount], this.gauge)

return (await curve.contracts[this.gauge].contract.deposit(_lpTokenAmount, curve.options)).hash;
}

private gaugeWithdrawEstimateGas = async (lpTokenAmount: string): Promise<number> => {
const _lpTokenAmount = ethers.utils.parseUnits(lpTokenAmount);
return (await curve.contracts[this.gauge].contract.estimateGas.withdraw(_lpTokenAmount, curve.options)).toNumber();
}

public gaugeWithdraw = async (lpTokenAmount: string): Promise<string> => {
const _lpTokenAmount = ethers.utils.parseUnits(lpTokenAmount);
return (await curve.contracts[this.gauge].contract.withdraw(_lpTokenAmount, curve.options)).hash;
Expand Down

0 comments on commit ccb4478

Please sign in to comment.