Skip to content

Commit

Permalink
fix: untrack erc-20 interface of the base token (#1584)
Browse files Browse the repository at this point in the history
* fix: untrack erc20 shimmer

* add constant

* fix: type

* fix: types and circular dependencies
  • Loading branch information
nicole-obrien authored Dec 7, 2023
1 parent 4c66035 commit e0ae0cc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { IAccountState } from '@core/account/interfaces'
import { EvmExplorerApi } from '@core/network'
import { EvmExplorerApi, EvmNetworkId } from '@core/network'
import { getNetwork } from '@core/network/stores'
import { TokenStandard, TokenTrackingStatus } from '@core/token'
import { addNewTrackedTokenToActiveProfile, hasTokenBeenUntracked } from '@core/wallet/actions'
import { BASE_TOKEN_CONTRACT_ADDRESS } from '../constants'

export function checkForUntrackedTokens(account: IAccountState, addPreviouslyUntracked?: boolean): void {
const chains = getNetwork()?.getChains()
Expand All @@ -21,12 +22,14 @@ export function checkForUntrackedTokens(account: IAccountState, addPreviouslyUnt
)
untrackedTokensToTrack.forEach(({ token }) => {
const { address, type, name, symbol, decimals } = token
addNewTrackedTokenToActiveProfile(
networkId,
address.toLowerCase(),
{ standard: type as TokenStandard.Erc20, name, symbol, decimals },
TokenTrackingStatus.AutomaticallyTracked
)
if (address !== BASE_TOKEN_CONTRACT_ADDRESS?.[networkId as EvmNetworkId]) {
addNewTrackedTokenToActiveProfile(
networkId,
address.toLowerCase(),
{ standard: type as TokenStandard.Erc20, name, symbol, decimals },
TokenTrackingStatus.AutomaticallyTracked
)
}
})
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { EvmNetworkId } from '@core/network/enums'

export const BASE_TOKEN_CONTRACT_ADDRESS: Readonly<{ [id in EvmNetworkId]?: string }> = {
[EvmNetworkId.ShimmerEvm]: '0x1074010000000000000000000000000000000000',
[EvmNetworkId.TestnetEvm]: '0x1074010000000000000000000000000000000000',
}
1 change: 1 addition & 0 deletions packages/shared/src/lib/core/layer-2/constants/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './accounts-contract.constant'
export * from './base-token-contract-address.constant'
export * from './contract-functions.constant'
export * from './empty-buffer.constants'
export * from './erc20-tokens-poll-interval.constant'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getLayer2AccountBalance } from '@core/layer-2/stores'
import { MarketCoinPrices, MarketCurrency } from '@core/market'
import { shimmerEvmAddressToCoinGeckoIdMap } from '@core/market/stores'
import { calculateFiatValueFromTokenValueAndMarketPrice } from '@core/market/utils'
import { NetworkId, getNetwork } from '@core/network'
import { NetworkId, EvmNetworkId, getNetwork } from '@core/network'
import { getActiveNetworkId } from '@core/network/actions/getActiveNetworkId'
import { sortTokens } from '@core/token/utils/sortTokens'
import { get } from 'svelte/store'
Expand All @@ -12,6 +12,7 @@ import { ITokenWithBalance } from '../interfaces'
import { AccountTokens, IAccountTokensPerNetwork } from '../interfaces/account-tokens.interface'
import { getPersistedToken } from '../stores'
import { isValidIrc30Token, isValidToken } from '../utils'
import { BASE_TOKEN_CONTRACT_ADDRESS } from '@core/layer-2'

export function getAccountTokensForAccount(
account: IAccountState,
Expand Down Expand Up @@ -110,7 +111,10 @@ function getAccountAssetForChain(
const tokens = Object.entries(balanceForNetworkId) ?? []

for (const [tokenId, balance] of tokens) {
if (tokenId === BASE_TOKEN_ID) {
if (tokenId === BASE_TOKEN_CONTRACT_ADDRESS?.[networkId as EvmNetworkId]) {
// ignore erc20 interface of the base coin of the chain
continue
} else if (tokenId === BASE_TOKEN_ID) {
const persistedBaseCoin = getPersistedToken(BASE_TOKEN_ID) // we use the L1 coin type for now because we assume that the basecoin for L2 is SMR
const baseCoinMarketPrices = marketCoinPrices?.[persistedBaseCoin.metadata?.name?.toLowerCase() ?? '']
const baseCoinMarketPrice = baseCoinMarketPrices?.[marketCurrency]
Expand Down

0 comments on commit e0ae0cc

Please sign in to comment.