Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,14 @@ function DoExitStepFast({ handleClose, token }) {

setErrorString('')

if (tooSmall || tooBig) {
setErrorString('Warning: Value out of bounds')
if (tooSmall) {
setErrorString('Value too small')
setValidValue(false)
setValue(value)
return false
}
else if (tooBig) {
setErrorString('Value too big')
setValidValue(false)
setValue(value)
return false
Expand All @@ -138,9 +144,9 @@ function DoExitStepFast({ handleClose, token }) {
//pay BOBA, exit BOBA - check BOBA amount
feeUseBoba &&
token.symbol === 'BOBA' &&
(Number(value) + feeBOBA) > balance)
(Number(value) + feeBOBA + exitFee) > balance)
{
// insufficient BOBA to cover the BOBA amount plus gas
// insufficient BOBA to cover the BOBA amount plus gas plus exitFee
setErrorString('Warning: BOBA amount + fees > balance')
setValidValue(false)
setValue(value)
Expand All @@ -163,9 +169,9 @@ function DoExitStepFast({ handleClose, token }) {
else if (
// insufficient BOBA to cover exit fees
feeUseBoba &&
feeBOBA > Number(feeBalanceBOBA))
(feeBOBA + exitFee) > Number(feeBalanceBOBA))
{
setErrorString('Warning: BOBA balance too low to cover gas')
setErrorString('Warning: BOBA balance too low to cover gas/fees')
setValidValue(false)
setValue(value)
return false
Expand Down Expand Up @@ -282,8 +288,14 @@ function DoExitStepFast({ handleClose, token }) {
setMax_Float(0.0)
}
else if (token.symbol === 'BOBA' && feeUseBoba) {
if(balance - safeCost > 0.0)
setMax_Float(balance - safeCost)
if(balance - (safeCost * feePriceRatio) - exitFee > 0.0)
setMax_Float(balance - (safeCost * feePriceRatio) - exitFee)
else
setMax_Float(0.0)
}
else if (token.symbol === 'BOBA' && !feeUseBoba) {
if(balance - exitFee > 0.0)
setMax_Float(balance - exitFee)
else
setMax_Float(0.0)
}
Expand All @@ -305,9 +317,9 @@ function DoExitStepFast({ handleClose, token }) {
let ETHstring = ''
if(feeETH && Number(feeETH) > 0) {
if(feeUseBoba) {
ETHstring = `Estimated gas (approval + exit): ${Number(feeBOBA).toFixed(4)} BOBA`
ETHstring = `Estimated gas: ${Number(feeBOBA).toFixed(4)} BOBA`
} else {
ETHstring = `Estimated gas (approval + exit): ${Number(feeETH).toFixed(4)} ETH`
ETHstring = `Estimated gas: ${Number(feeETH).toFixed(4)} ETH`
}
}

Expand All @@ -320,6 +332,8 @@ function DoExitStepFast({ handleClose, token }) {
allowExitall = false
}

const balance = Number(logAmount(token.balance, token.decimals))

return (
<>
<Box>
Expand Down Expand Up @@ -360,11 +374,23 @@ function DoExitStepFast({ handleClose, token }) {
loading={loading}
/>
}

{max_Float === 0 &&
<Typography variant="body1" sx={{mt: 2}}>
Loading...
</Typography>
}

<Typography variant="body2" sx={{mt: 2}}>
{parse(`Token balance: ${Number(balance).toFixed(6)} ${token.symbol}`)}
<br/>
{parse(`Message Relay Fee: ${exitFee} BOBA`)}
<br/>
{parse(ETHstring)}
<br/>
{parse(`Max exitable balance (balance - fees): ${Number(max_Float).toFixed(6)} ${token.symbol}`)}
</Typography>

{validValue && token && (
<Typography variant="body2" sx={{mt: 2}}>
{value &&
Expand All @@ -377,14 +403,6 @@ function DoExitStepFast({ handleClose, token }) {
</Typography>
)}

<Typography variant="body2" sx={{mt: 2}}>
{parse(ETHstring)}
</Typography>

<Typography variant="body2" sx={{mt: 2}}>
{parse(`Exit Fee: ${exitFee} BOBA`)}
</Typography>

{errorString !== '' &&
<Typography variant="body2" sx={{mt: 2, color: 'red'}}>
{errorString}
Expand All @@ -398,23 +416,16 @@ function DoExitStepFast({ handleClose, token }) {
</Typography>
)}

{(Number(LPRatio) < 0.10 && Number(value) > Number(balanceSubPending) * 0.90) && (
<Typography variant="body2" sx={{mt: 2, color: 'red'}}>
The pool's balance and balance/liquidity ratio are too low.
Please use the classic bridge.
</Typography>
)}

{(Number(LPRatio) < 0.10 && Number(value) <= Number(balanceSubPending) * 0.90) && (
<Typography variant="body2" sx={{mt: 2, color: 'red'}}>
The pool's balance/liquidity ratio (of {Number(LPRatio).toFixed(2)}) is low.
The pool's balance/liquidity ratio (of {Number(LPRatio).toFixed(2)}) is too low.
Please use the classic bridge.
</Typography>
)}

{(Number(LPRatio) >= 0.10 && Number(value) > Number(balanceSubPending) * 0.90) && (
<Typography variant="body2" sx={{mt: 2, color: 'red'}}>
The pool's balance (of {Number(balanceSubPending).toFixed(2)} including inflight bridges) is low.
The pool's balance (of {Number(balanceSubPending).toFixed(2)} including inflight bridges) is too low.
Please use the classic bridge or reduce the amount.
</Typography>
)}
Expand Down
28 changes: 21 additions & 7 deletions packages/boba/gateway/src/containers/wallet/token/Token.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import { Box, Typography, useTheme } from '@mui/material'
import { fetchLookUpPrice } from 'actions/networkAction'
import { isEqual } from 'lodash'
import React, { useCallback, useEffect } from 'react'
import React, { useCallback, useState, useEffect } from 'react'
import { useDispatch, useSelector } from 'react-redux'

import { selectlayer1Balance, selectlayer2Balance } from 'selectors/balanceSelector'
import { selectLoading } from 'selectors/loadingSelector'
import { selectAccountEnabled, selectLayer } from 'selectors/setupSelector'
import { selectTokens } from 'selectors/tokenSelector'

import { fetchLookUpPrice } from 'actions/networkAction'

import * as S from './Token.styles'
import { Box, Typography, useTheme } from '@mui/material'
import { tokenTableHeads } from './token.tableHeads'

import ListToken from 'components/listToken/listToken'
import Button from 'components/button/Button'
import Link from 'components/icons/LinkIcon'

import lightLoader from 'images/boba2/loading_light.gif'
import darkLoader from 'images/boba2/loading_dark.gif'
import Link from 'components/icons/LinkIcon'

import { isEqual } from 'lodash'

import networkService from 'services/networkService'

Expand All @@ -30,6 +35,8 @@ function TokenPage() {
const rootBalance = useSelector(selectlayer1Balance, isEqual)
const layer = useSelector(selectLayer())

const [ debug, setDebug ] = useState(false)

const depositLoading = useSelector(selectLoading([ 'DEPOSIT/CREATE' ]))
const exitLoading = useSelector(selectLoading([ 'EXIT/CREATE' ]))
const balanceLoading = useSelector(selectLoading([ 'BALANCE/GET' ]))
Expand All @@ -38,6 +45,15 @@ function TokenPage() {

const loaderImage = (theme.palette.mode === 'light') ? lightLoader : darkLoader;

useEffect(() => {
if (!accountEnabled) return
const gasEstimateAccount = networkService.gasEstimateAccount
const wAddress = networkService.account
if (wAddress.toLowerCase() === gasEstimateAccount.toLowerCase()) {
setDebug(true)
}
}, [ accountEnabled, networkService ])

const getLookupPrice = useCallback(() => {
if (!accountEnabled) return
// only run once all the tokens have been added to the tokenList
Expand Down Expand Up @@ -69,8 +85,6 @@ function TokenPage() {
console.log("GasEstimateApprove:",approval)
}

const debug = false

if (!accountEnabled) {

return (
Expand Down
58 changes: 20 additions & 38 deletions packages/boba/gateway/src/services/networkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ import { sortRawTokens } from 'util/common'
import GraphQLService from "./graphQLService"

import addresses_Rinkeby from "@boba/register/addresses/addressesRinkeby_0x93A96D6A5beb1F661cf052722A1424CDDA3e9418"
//import addresses_Local from "@boba/register/addresses/addressesLocal_0x93A96D6A5beb1F661cf052722A1424CDDA3e9418"
import addresses_Mainnet from "@boba/register/addresses/addressesMainnet_0x8376ac6C3f73a25Dd994E0b0669ca7ee0C02F089"

require('dotenv').config()
Expand Down Expand Up @@ -117,8 +116,6 @@ if (process.env.REACT_APP_CHAIN === 'rinkeby') {
}
let allTokens = {}

const benchmarkAccount = '0x4161aEf7ac9F8772B83Cda1E5F054ADe308d9049'

class NetworkService {

constructor() {
Expand Down Expand Up @@ -168,6 +165,8 @@ class NetworkService {
// "param _l1Gas Unused, but included for potential forward compatibility considerations"
this.L2GasLimit = 1300000 //use the same as the hardcoded receive

this.gasEstimateAccount = null

// Dao
this.BobaContract = null
this.xBobaContract = null
Expand Down Expand Up @@ -616,6 +615,8 @@ class NetworkService {
if (networkGateway === 'mainnet' || networkGateway === 'rinkeby') {
this.payloadForL1SecurityFee = nw[networkGateway].payloadForL1SecurityFee
this.payloadForFastDepositBatchCost = nw[networkGateway].payloadForFastDepositBatchCost
this.gasEstimateAccount = nw[networkGateway].gasEstimateAccount
console.log('gasEstimateAccount:', this.gasEstimateAccount)
}

this.L1Provider = new ethers.providers.StaticJsonRpcProvider(
Expand Down Expand Up @@ -2373,7 +2374,7 @@ class NetworkService {
utils.parseEther('1.0')
)

const approvalGas_BN = await this.L2Provider.estimateGas({...tx, from: benchmarkAccount})
const approvalGas_BN = await this.L2Provider.estimateGas({...tx, from: this.gasEstimateAccount})
approvalCost_BN = approvalGas_BN.mul(gasPrice)
console.log("Approve cost in ETH:", utils.formatEther(approvalCost_BN))
}
Expand All @@ -2392,7 +2393,7 @@ class NetworkService {
{ value: utils.parseEther('0.00001') }
)

const gas_BN = await this.L2Provider.estimateGas({...tx2, from: benchmarkAccount})
const gas_BN = await this.L2Provider.estimateGas({...tx2, from: this.gasEstimateAccount})
console.log("Classical exit gas", gas_BN.toString())

const cost_BN = gas_BN.mul(gasPrice)
Expand Down Expand Up @@ -2693,8 +2694,7 @@ class NetworkService {
let otherField = {}

if( currency === allAddresses.L1_ETH_Address || currency === allAddresses.L2_ETH_Address ) {
// console.log("Yes we have ETH")
// add value field
// add value field for ETH
otherField['value'] = value_Wei_String
}

Expand All @@ -2720,42 +2720,24 @@ class NetworkService {
async liquidityEstimate(currency) {

let otherField = {
from: benchmarkAccount
from: this.gasEstimateAccount
}

const gasPrice_BN = await this.provider.getGasPrice()
console.log("gas price", gasPrice_BN.toString())

let approvalCost_BN = BigNumber.from('0')
let stakeCost_BN = BigNumber.from('0')

try {

// first, we need the allowance of the benchmarkAccount
const BOBA = this.L2_TEST_Contract
.connect(this.provider)
.attach(this.tokenAddresses['BOBA'].L2)

let allowance_BN = await BOBA
.allowance(
benchmarkAccount,
allAddresses.L2LPAddress
)

console.log("benchmarkAllowance", allowance_BN.toString() )

if( currency === allAddresses.L2_ETH_Address ) {
otherField['value'] = allowance_BN.toString()
}

// second, we need the approval cost if non-ETH
// First, we need the approval cost
// not relevant to ETH
if( currency !== allAddresses.L2_ETH_Address ) {

const tx1 = await BOBA
const tx1 = await this.BobaContract
.populateTransaction
.approve(
allAddresses.L2LPAddress,
allowance_BN.toString(),
utils.parseEther('1.0'),
otherField
)

Expand All @@ -2764,12 +2746,13 @@ class NetworkService {
console.log("Approve cost in ETH:", utils.formatEther(approvalCost_BN))
}

// third, we need the addLiquidity cost
// Second, we need the addLiquidity cost
// all ERC20s will be the same, so use the BOBA contract
const tx2 = await this.L2LPContract
.connect(this.provider)
.populateTransaction
.addLiquidity(
allowance_BN.toString(),
utils.parseEther('1.0'),
this.tokenAddresses['BOBA'].L2,
otherField
)
Expand All @@ -2778,7 +2761,7 @@ class NetworkService {
console.log("addLiquidity cost in ETH:", utils.formatEther(stakeCost_BN))

const safety_margin_BN = BigNumber.from('1000000000000')
console.log("Stake safety margin:", utils.formatEther(safety_margin_BN))
console.log("Safety margin:", utils.formatEther(safety_margin_BN))

return approvalCost_BN.add(stakeCost_BN).add(safety_margin_BN)

Expand Down Expand Up @@ -3132,7 +3115,7 @@ class NetworkService {
utils.parseEther('1.0')
)

const approvalGas_BN = await this.L2Provider.estimateGas({...tx, from: benchmarkAccount})
const approvalGas_BN = await this.L2Provider.estimateGas({...tx, from: this.gasEstimateAccount})
approvalCost_BN = approvalGas_BN.mul(gasPrice)
console.log("Approve cost in ETH:", utils.formatEther(approvalCost_BN))
}
Expand All @@ -3147,7 +3130,7 @@ class NetworkService {
currencyAddress === allAddresses.L2_ETH_Address ? { value : '1'} : {}
)

const depositGas_BN = await this.L2Provider.estimateGas({...tx2, from: benchmarkAccount})
const depositGas_BN = await this.L2Provider.estimateGas({...tx2, from: this.gasEstimateAccount})

let l1SecurityFee = BigNumber.from('0')
if (this.networkGateway === 'mainnet') {
Expand Down Expand Up @@ -4051,10 +4034,9 @@ class NetworkService {

// used to generate gas estimates for contracts that cannot set amount === 0
// to avoid need to approve amount
const benchmarkAccount = '0x4161aEf7ac9F8772B83Cda1E5F054ADe308d9049'

let otherField = {
from: benchmarkAccount
from: this.gasEstimateAccount
}

const gasPrice_BN = await this.provider.getGasPrice()
Expand All @@ -4069,7 +4051,7 @@ class NetworkService {
let allowance_BN = await this.BobaContract
.connect(this.provider)
.allowance(
benchmarkAccount,
this.gasEstimateAccount,
allAddresses.BobaFixedSavings
)
console.log("benchmarkAllowance_BN",allowance_BN.toString())
Expand Down
Loading