Skip to content

Commit

Permalink
estimate gas in migrate v2
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahZinsmeister committed May 6, 2021
1 parent d3898cf commit 81af31e
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions src/pages/MigrateV2/MigrateV2Pair.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { usePairContract, useV2MigratorContract } from '../../hooks/useContract'
import { NEVER_RELOAD, useSingleCallResult } from '../../state/multicall/hooks'
import { useTokenBalance } from '../../state/wallet/hooks'
import { BackArrow, ExternalLink, TYPE } from '../../theme'
import { getEtherscanLink, isAddress } from '../../utils'
import { calculateGasMargin, getEtherscanLink, isAddress } from '../../utils'
import { BodyWrapper } from '../AppBody'
import { V3_MIGRATOR_ADDRESSES } from 'constants/v3'
import { PoolState, usePool } from 'hooks/usePools'
Expand Down Expand Up @@ -274,7 +274,7 @@ function V2PairMigration({

const deadlineToUse = signatureData?.deadline ?? deadline

const data = []
const data: string[] = []

// permit if necessary
if (signatureData) {
Expand Down Expand Up @@ -324,19 +324,24 @@ function V2PairMigration({
)

setConfirmingMigration(true)
migrator
.multicall(data)
.then((response: TransactionResponse) => {
ReactGA.event({
category: 'Migrate',
action: `${isNotUniswap ? 'SushiSwap' : 'V2'}->V3`,
label: `${currency0.symbol}/${currency1.symbol}`,
})

addTransaction(response, {
summary: `Migrate ${currency0.symbol}/${currency1.symbol} liquidity to V3`,
})
setPendingMigrationHash(response.hash)
migrator.estimateGas
.multicall(data)
.then((gasEstimate) => {
return migrator
.multicall(data, { gasLimit: calculateGasMargin(gasEstimate) })
.then((response: TransactionResponse) => {
ReactGA.event({
category: 'Migrate',
action: `${isNotUniswap ? 'SushiSwap' : 'V2'}->V3`,
label: `${currency0.symbol}/${currency1.symbol}`,
})

addTransaction(response, {
summary: `Migrate ${currency0.symbol}/${currency1.symbol} liquidity to V3`,
})
setPendingMigrationHash(response.hash)
})
})
.catch(() => {
setConfirmingMigration(false)
Expand Down

1 comment on commit 81af31e

@vercel
Copy link

@vercel vercel bot commented on 81af31e May 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.