Commit 64dd09f2 authored by Noah Zinsmeister's avatar Noah Zinsmeister Committed by GitHub

update to latest deploy (#712)

parent 6fd9808e
......@@ -32,7 +32,7 @@ import { useWeb3React, useTokenContract } from '../../hooks'
import { useAddressBalance, useAllBalances } from '../../contexts/Balances'
import { useTransactionAdder, usePendingApproval } from '../../contexts/Transactions'
import { useUserAdvanced } from '../../contexts/Application'
import { ROUTER_ADDRESSES } from '../../constants'
import { ROUTER_ADDRESS } from '../../constants'
import { getRouterContract, calculateGasMargin, getProviderOrSigner, getEtherscanLink, isWETH } from '../../utils'
import { useLocalStorageTokens } from '../../contexts/LocalStorage'
......@@ -298,7 +298,6 @@ function ExchangePage({ sendingInput = false, history, params }) {
// const { t } = useTranslation()
const { chainId, account, library } = useWeb3React()
const routerAddress: string = ROUTER_ADDRESSES[chainId]
const simplified = useUserAdvanced()
......@@ -402,7 +401,7 @@ function ExchangePage({ sendingInput = false, history, params }) {
const [allowedSlippage, setAllowedSlippage] = useState<number>(INITIAL_ALLOWED_SLIPPAGE)
// input approval
const inputApproval: TokenAmount = useAddressAllowance(account, tokens[Field.INPUT], routerAddress)
const inputApproval: TokenAmount = useAddressAllowance(account, tokens[Field.INPUT], ROUTER_ADDRESS)
// all balances for detecting a swap with send
const allBalances: TokenAmount[] = useAllBalances()
......@@ -752,16 +751,16 @@ function ExchangePage({ sendingInput = false, history, params }) {
let useUserBalance = false
const tokenContract = field === Field.INPUT ? tokenContractInput : tokenContractOutput
estimatedGas = await tokenContract.estimate.approve(routerAddress, ethers.constants.MaxUint256).catch(e => {
estimatedGas = await tokenContract.estimate.approve(ROUTER_ADDRESS, ethers.constants.MaxUint256).catch(e => {
console.log('Error setting max token approval.')
})
if (!estimatedGas) {
// general fallback for tokens who restrict approval amounts
estimatedGas = await tokenContract.estimate.approve(routerAddress, userBalances[field])
estimatedGas = await tokenContract.estimate.approve(ROUTER_ADDRESS, userBalances[field])
useUserBalance = true
}
tokenContract
.approve(routerAddress, useUserBalance ? userBalances[field] : ethers.constants.MaxUint256, {
.approve(ROUTER_ADDRESS, useUserBalance ? userBalances[field] : ethers.constants.MaxUint256, {
gasLimit: calculateGasMargin(estimatedGas, GAS_MARGIN)
})
.then(response => {
......
This diff is collapsed.
[
{
"name": "NewExchange",
"inputs": [
{ "type": "address", "name": "token", "indexed": true },
{ "type": "address", "name": "exchange", "indexed": true }
],
"anonymous": false,
"type": "event"
},
{
"name": "initializeFactory",
"outputs": [],
"inputs": [{ "type": "address", "name": "template" }],
"constant": false,
"payable": false,
"type": "function",
"gas": 35725
},
{
"name": "createExchange",
"outputs": [{ "type": "address", "name": "out" }],
"inputs": [{ "type": "address", "name": "token" }],
"constant": false,
"payable": false,
"type": "function",
"gas": 187911
},
{
"name": "getExchange",
"outputs": [{ "type": "address", "name": "out" }],
"inputs": [{ "type": "address", "name": "token" }],
"constant": true,
"payable": false,
"type": "function",
"gas": 715
},
{
"name": "getToken",
"outputs": [{ "type": "address", "name": "out" }],
"inputs": [{ "type": "address", "name": "exchange" }],
"constant": true,
"payable": false,
"type": "function",
"gas": 745
},
{
"name": "getTokenWithId",
"outputs": [{ "type": "address", "name": "out" }],
"inputs": [{ "type": "uint256", "name": "token_id" }],
"constant": true,
"payable": false,
"type": "function",
"gas": 736
},
{
"name": "exchangeTemplate",
"outputs": [{ "type": "address", "name": "out" }],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 633
},
{
"name": "tokenCount",
"outputs": [{ "type": "uint256", "name": "out" }],
"inputs": [],
"constant": true,
"payable": false,
"type": "function",
"gas": 663
}
]
This diff is collapsed.
import { injected, walletconnect, walletlink, fortmatic, portis } from '../connectors'
import { ChainId, WETH, Token } from '@uniswap/sdk'
export const FACTORY_ADDRESSES = {
1: '',
3: '0xe2f197885abe8ec7c866cFf76605FD06d4576218',
4: '0xe2f197885abe8ec7c866cFf76605FD06d4576218',
5: '0xe2f197885abe8ec7c866cFf76605FD06d4576218',
42: '0xe2f197885abe8ec7c866cFf76605FD06d4576218'
}
export const ROUTER_ADDRESSES = {
1: '',
3: '0xcDbE04934d89e97a24BCc07c3562DC8CF17d8167',
4: '0xcDbE04934d89e97a24BCc07c3562DC8CF17d8167',
5: '0xcDbE04934d89e97a24BCc07c3562DC8CF17d8167',
42: '0xcDbE04934d89e97a24BCc07c3562DC8CF17d8167'
}
export const ROUTER_ADDRESS = '0xf164fC0Ec4E93095b804a4795bBe1e041497b92a'
export const COMMON_BASES = {
1: [WETH[ChainId.MAINNET]],
......
......@@ -6,7 +6,7 @@ import copy from 'copy-to-clipboard'
import ERC20_ABI from '../constants/abis/erc20'
import { injected } from '../connectors'
import { NetworkContextName } from '../constants'
import { getContract, getFactoryContract, getExchangeContract, isAddress } from '../utils'
import { getContract, getExchangeContract, isAddress } from '../utils'
export function useWeb3React() {
const context = useWeb3ReactCore()
......@@ -197,19 +197,6 @@ export function useTokenContract(tokenAddress, withSignerIfPossible = true) {
}, [tokenAddress, library, withSignerIfPossible, account])
}
// returns null on errors
export function useFactoryContract(withSignerIfPossible = true) {
const { chainId, library, account } = useWeb3React()
return useMemo(() => {
try {
return getFactoryContract(chainId, library, withSignerIfPossible ? account : undefined)
} catch {
return null
}
}, [chainId, library, withSignerIfPossible, account])
}
export function usePairContract(pairAddress, withSignerIfPossible = true) {
const { library, account } = useWeb3React()
......
......@@ -27,7 +27,7 @@ import { useWeb3React, useTokenContract } from '../../hooks'
import { useTransactionAdder, usePendingApproval } from '../../contexts/Transactions'
import { BigNumber } from 'ethers/utils'
import { ROUTER_ADDRESSES } from '../../constants'
import { ROUTER_ADDRESS } from '../../constants'
import { getRouterContract, calculateGasMargin, isWETH } from '../../utils'
// denominated in bips
......@@ -139,8 +139,6 @@ function reducer(
function AddLiquidity({ token0, token1, step = false }) {
const { account, chainId, library } = useWeb3React()
const routerAddress: string = ROUTER_ADDRESSES[chainId]
// modal states
const [showSearch, setShowSearch] = useState<boolean>(false)
const [showConfirm, setShowConfirm] = useState<boolean>(false)
......@@ -174,8 +172,8 @@ function AddLiquidity({ token0, token1, step = false }) {
pair && JSBI.equal(pair.reserve0.raw, JSBI.BigInt(0)) && JSBI.equal(pair.reserve1.raw, JSBI.BigInt(0))
// state for amount approvals
const inputApproval: TokenAmount = useAddressAllowance(account, tokens[Field.INPUT], routerAddress)
const outputApproval: TokenAmount = useAddressAllowance(account, tokens[Field.OUTPUT], routerAddress)
const inputApproval: TokenAmount = useAddressAllowance(account, tokens[Field.INPUT], ROUTER_ADDRESS)
const outputApproval: TokenAmount = useAddressAllowance(account, tokens[Field.OUTPUT], ROUTER_ADDRESS)
const [showInputApprove, setShowInputApprove] = useState<boolean>(false)
const [showOutputApprove, setShowOutputApprove] = useState<boolean>(false)
......@@ -470,16 +468,16 @@ function AddLiquidity({ token0, token1, step = false }) {
let useUserBalance = false
const tokenContract = field === Field.INPUT ? tokenContractInput : tokenContractOutput
estimatedGas = await tokenContract.estimate.approve(routerAddress, ethers.constants.MaxUint256).catch(e => {
estimatedGas = await tokenContract.estimate.approve(ROUTER_ADDRESS, ethers.constants.MaxUint256).catch(e => {
console.log('Error setting max token approval.')
})
if (!estimatedGas) {
// general fallback for tokens who restrict approval amounts
estimatedGas = await tokenContract.estimate.approve(routerAddress, userBalances[field])
estimatedGas = await tokenContract.estimate.approve(ROUTER_ADDRESS, userBalances[field])
useUserBalance = true
}
tokenContract
.approve(routerAddress, useUserBalance ? userBalances[field] : ethers.constants.MaxUint256, {
.approve(ROUTER_ADDRESS, useUserBalance ? userBalances[field] : ethers.constants.MaxUint256, {
gasLimit: calculateGasMargin(estimatedGas, GAS_MARGIN)
})
.then(response => {
......
......@@ -27,7 +27,7 @@ import { usePair, useTotalSupply } from '../../contexts/Pairs'
import { BigNumber } from 'ethers/utils'
import { splitSignature } from '@ethersproject/bytes'
import { ROUTER_ADDRESSES } from '../../constants'
import { ROUTER_ADDRESS } from '../../constants'
import { getRouterContract, calculateGasMargin } from '../../utils'
// denominated in seconds
......@@ -151,7 +151,6 @@ const ConfirmedText = styled(Text)`
export default function RemoveLiquidity({ token0, token1 }) {
const { account, chainId, library } = useWeb3React()
const routerAddress: string = ROUTER_ADDRESSES[chainId]
const [showConfirm, setShowConfirm] = useState<boolean>(false)
const [showAdvanced, setShowAdvanced] = useState<boolean>(false)
......@@ -392,7 +391,7 @@ export default function RemoveLiquidity({ token0, token1 }) {
const message = {
owner: account,
spender: routerAddress,
spender: ROUTER_ADDRESS,
value: parsedAmounts[Field.LIQUIDITY].raw.toString(),
nonce: nonce.toHexString(),
deadline: newDeadline
......
import { ethers } from 'ethers'
import FACTORY_ABI from '../constants/abis/factory'
import EXCHANGE_ABI from '../constants/abis/exchange'
import ROUTER_ABI from '../constants/abis/router'
import IUniswapV2Pair from '@uniswap/v2-core/build/IUniswapV2Pair.json'
import IUniswapV2Router01 from '@uniswap/v2-periphery/build/IUniswapV2Router01.json'
import ERC20_ABI from '../constants/abis/erc20'
import ERC20_BYTES32_ABI from '../constants/abis/erc20_bytes32'
import { FACTORY_ADDRESSES, SUPPORTED_THEMES, ROUTER_ADDRESSES } from '../constants'
import { SUPPORTED_THEMES, ROUTER_ADDRESS } from '../constants'
import { bigNumberify, keccak256, defaultAbiCoder, toUtf8Bytes, solidityPack } from 'ethers/utils'
import UncheckedJsonRpcSigner from './signer'
......@@ -150,18 +150,13 @@ export function getContract(address, ABI, library, account) {
// account is optional
export function getRouterContract(chainId, library, account) {
const router = getContract(ROUTER_ADDRESSES[chainId], ROUTER_ABI, library, account)
const router = getContract(ROUTER_ADDRESS, IUniswapV2Router01.abi, library, account)
return router
}
// account is optional
export function getFactoryContract(networkId, library, account) {
return getContract(FACTORY_ADDRESSES[networkId], FACTORY_ABI, library, account)
}
// account is optional
export function getExchangeContract(pairAddress, library, account) {
return getContract(pairAddress, EXCHANGE_ABI, library, account)
return getContract(pairAddress, IUniswapV2Pair.abi, library, account)
}
// get token name
......@@ -215,11 +210,6 @@ export async function getTokenDecimals(tokenAddress, library) {
})
}
// get the exchange address for a token from the factory
export async function getTokenpairAddressFromFactory(tokenAddress, networkId, library) {
return getFactoryContract(networkId, library).getExchange(tokenAddress)
}
// get the ether balance of an address
export async function getEtherBalance(address, library) {
if (!isAddress(address)) {
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment