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
25 changes: 20 additions & 5 deletions packages/boba/gateway/src/actions/tokenAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,26 @@ export async function addToken ( tokenContractAddressL1 ) {
)
}

const [ _symbolL1, _decimals, _name ] = await Promise.all([
tokenContract.symbol(),
tokenContract.decimals(),
tokenContract.name()
]).catch(e => [ null, null, null ])
let _symbolL1
let _decimals
let _name

if (ethers.utils.isAddress(_tokenContractAddressL1)) {
const tokenInfo = networkService.tokenInfo.L1[ethers.utils.getAddress(_tokenContractAddressL1)]
if (tokenInfo) {
_symbolL1 = tokenInfo.symbol
_decimals = tokenInfo.decimals
_name = tokenInfo.name
}
}

if (!_symbolL1 || !_decimals || !_name) {
[ _symbolL1, _decimals, _name ] = await Promise.all([
tokenContract.symbol(),
tokenContract.decimals(),
tokenContract.name()
]).catch(e => [ null, null, null ])
}

const decimals = _decimals ? Number(_decimals.toString()) : 'NOT ON ETHEREUM'
const symbolL1 = _symbolL1 || 'NOT ON ETHEREUM'
Expand Down
34 changes: 28 additions & 6 deletions packages/boba/gateway/src/services/networkService.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ import addresses_Mainnet from "@boba/register/addresses/addressesMainnet_0x8376a
import layerZeroTestnet from "@boba/register/addresses/layerZeroTestnet"
import layerZeroMainnet from "@boba/register/addresses/layerZeroMainnet"

import tokenInfo from "@boba/register/addresses/tokenInfo"

import { bobaBridges } from 'util/bobaBridges'
import { APP_AIRDROP, APP_CHAIN, SPEED_CHECK } from 'util/constant'
import { getPoolDetail } from 'util/poolDetails'
Expand Down Expand Up @@ -225,6 +227,9 @@ class NetworkService {

// support alt l1 tokens
this.supportedAltL1Chains = supportedAltL1Chains

// token info
this.tokenInfo = {}
}

bindProviderListeners() {
Expand Down Expand Up @@ -731,6 +736,9 @@ class NetworkService {
nw[networkGateway]['L2']['rpcUrl']
)

const chainId = (await this.L1Provider.getNetwork()).chainId
this.tokenInfo = tokenInfo[chainId]

if (networkGateway === 'rinkeby') {
addresses = addresses_Rinkeby
} else if (networkGateway === 'mainnet') {
Expand Down Expand Up @@ -2861,9 +2869,16 @@ class NetworkService {
//getting eth balance
//console.log("Getting balance for:", tokenAddress)
tokenBalance = await this.L1_TEST_Contract.attach(tokenAddress).connect(this.L1Provider).balanceOf(allAddresses.L1LPAddress)
tokenSymbol = await this.L1_TEST_Contract.attach(tokenAddress).connect(this.L1Provider).symbol()
tokenName = await this.L1_TEST_Contract.attach(tokenAddress).connect(this.L1Provider).name()
decimals = await this.L1_TEST_Contract.attach(tokenAddress).connect(this.L1Provider).decimals()
const tokenInfoFiltered = this.tokenInfo.L1[utils.getAddress(tokenAddress)]
if (tokenInfo) {
tokenSymbol = tokenInfoFiltered.symbol
tokenName = tokenInfoFiltered.name
decimals = tokenInfoFiltered.decimals
} else {
tokenSymbol = await this.L1_TEST_Contract.attach(tokenAddress).connect(this.L1Provider).symbol()
tokenName = await this.L1_TEST_Contract.attach(tokenAddress).connect(this.L1Provider).name()
decimals = await this.L1_TEST_Contract.attach(tokenAddress).connect(this.L1Provider).decimals()
}
}

const poolTokenInfo = await L1LPContract.poolInfo(tokenAddress)
Expand Down Expand Up @@ -2956,9 +2971,16 @@ class NetworkService {
decimals = 18
} else {
tokenBalance = await this.L2_TEST_Contract.attach(tokenAddress).connect(this.L2Provider).balanceOf(allAddresses.L2LPAddress)
tokenSymbol = await this.L2_TEST_Contract.attach(tokenAddress).connect(this.L2Provider).symbol()
tokenName = await this.L2_TEST_Contract.attach(tokenAddress).connect(this.L2Provider).name()
decimals = await this.L1_TEST_Contract.attach(tokenAddressL1).connect(this.L1Provider).decimals()
const tokenInfoFiltered = this.tokenInfo.L2[utils.getAddress(tokenAddress)]
if (tokenInfo) {
tokenSymbol = tokenInfoFiltered.symbol
tokenName = tokenInfoFiltered.name
decimals = tokenInfoFiltered.decimals
} else {
tokenSymbol = await this.L2_TEST_Contract.attach(tokenAddress).connect(this.L2Provider).symbol()
tokenName = await this.L2_TEST_Contract.attach(tokenAddress).connect(this.L2Provider).name()
decimals = await this.L1_TEST_Contract.attach(tokenAddressL1).connect(this.L1Provider).decimals()
}
}
const poolTokenInfo = await L2LPContract.poolInfo(tokenAddress)
let userTokenInfo = {}
Expand Down
Loading