fix: use NativeCurrency for polygon matic (#7567)
* fix: use NativeCurrency for polygon matic * add comment * update snapshots?? * Revert "update snapshots??" This reverts commit 280758be118610cc9e13afcd6e420985e8a200d2.
This commit is contained in:
parent
1d64d24d31
commit
c6b44bb5c9
@ -90,7 +90,13 @@ export const MATIC_MAINNET = new Token(
|
|||||||
'MATIC',
|
'MATIC',
|
||||||
'Polygon Matic'
|
'Polygon Matic'
|
||||||
)
|
)
|
||||||
const MATIC_POLYGON = new Token(ChainId.POLYGON, '0x0000000000000000000000000000000000001010', 18, 'MATIC', 'Matic')
|
export const MATIC_POLYGON = new Token(
|
||||||
|
ChainId.POLYGON,
|
||||||
|
'0x0000000000000000000000000000000000001010',
|
||||||
|
18,
|
||||||
|
'MATIC',
|
||||||
|
'Matic'
|
||||||
|
)
|
||||||
export const DAI_POLYGON = new Token(
|
export const DAI_POLYGON = new Token(
|
||||||
ChainId.POLYGON,
|
ChainId.POLYGON,
|
||||||
'0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063',
|
'0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063',
|
||||||
@ -143,13 +149,6 @@ export const WBTC_OPTIMISM = new Token(
|
|||||||
'WBTC',
|
'WBTC',
|
||||||
'Wrapped BTC'
|
'Wrapped BTC'
|
||||||
)
|
)
|
||||||
const MATIC_POLYGON_MUMBAI = new Token(
|
|
||||||
ChainId.POLYGON_MUMBAI,
|
|
||||||
'0x0000000000000000000000000000000000001010',
|
|
||||||
18,
|
|
||||||
'MATIC',
|
|
||||||
'Matic'
|
|
||||||
)
|
|
||||||
export const WETH_POLYGON_MUMBAI = new Token(
|
export const WETH_POLYGON_MUMBAI = new Token(
|
||||||
ChainId.POLYGON_MUMBAI,
|
ChainId.POLYGON_MUMBAI,
|
||||||
'0xa6fa4fb5f76172d178d61b04b0ecd319c5d1c0aa',
|
'0xa6fa4fb5f76172d178d61b04b0ecd319c5d1c0aa',
|
||||||
@ -359,14 +358,21 @@ export function isPolygon(chainId: number): chainId is ChainId.POLYGON | ChainId
|
|||||||
return chainId === ChainId.POLYGON_MUMBAI || chainId === ChainId.POLYGON
|
return chainId === ChainId.POLYGON_MUMBAI || chainId === ChainId.POLYGON
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPolygonNativeCurrency(chainId: number) {
|
class PolygonNativeCurrency extends NativeCurrency {
|
||||||
switch (chainId) {
|
equals(other: Currency): boolean {
|
||||||
case ChainId.POLYGON:
|
return other.isNative && other.chainId === this.chainId
|
||||||
return MATIC_POLYGON
|
}
|
||||||
case ChainId.POLYGON_MUMBAI:
|
|
||||||
return MATIC_POLYGON_MUMBAI
|
get wrapped(): Token {
|
||||||
default:
|
if (!isPolygon(this.chainId)) throw new Error('Not Polygon')
|
||||||
throw new Error('Not polygon')
|
const wrapped = WRAPPED_NATIVE_CURRENCY[this.chainId]
|
||||||
|
invariant(wrapped instanceof Token)
|
||||||
|
return wrapped
|
||||||
|
}
|
||||||
|
|
||||||
|
public constructor(chainId: number) {
|
||||||
|
if (!isPolygon(chainId)) throw new Error('Not Polygon')
|
||||||
|
super(chainId, 18, 'MATIC', 'Matic')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,7 +439,7 @@ export function nativeOnChain(chainId: number): NativeCurrency | Token {
|
|||||||
if (cachedNativeCurrency[chainId]) return cachedNativeCurrency[chainId]
|
if (cachedNativeCurrency[chainId]) return cachedNativeCurrency[chainId]
|
||||||
let nativeCurrency: NativeCurrency | Token
|
let nativeCurrency: NativeCurrency | Token
|
||||||
if (isPolygon(chainId)) {
|
if (isPolygon(chainId)) {
|
||||||
nativeCurrency = getPolygonNativeCurrency(chainId)
|
nativeCurrency = new PolygonNativeCurrency(chainId)
|
||||||
} else if (isCelo(chainId)) {
|
} else if (isCelo(chainId)) {
|
||||||
nativeCurrency = getCeloNativeCurrency(chainId)
|
nativeCurrency = getCeloNativeCurrency(chainId)
|
||||||
} else if (isBsc(chainId)) {
|
} else if (isBsc(chainId)) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { nativeOnChain } from 'constants/tokens'
|
import { MATIC_POLYGON, nativeOnChain } from 'constants/tokens'
|
||||||
import { Chain } from 'graphql/data/__generated__/types-and-hooks'
|
import { Chain } from 'graphql/data/__generated__/types-and-hooks'
|
||||||
import { supportedChainIdFromGQLChain } from 'graphql/data/util'
|
import { supportedChainIdFromGQLChain } from 'graphql/data/util'
|
||||||
|
|
||||||
@ -10,8 +10,11 @@ export function getNativeTokenDBAddress(chain: Chain): string | undefined {
|
|||||||
switch (chain) {
|
switch (chain) {
|
||||||
// Celo & Polygon have precompiles for their native tokens
|
// Celo & Polygon have precompiles for their native tokens
|
||||||
case Chain.Celo:
|
case Chain.Celo:
|
||||||
case Chain.Polygon:
|
|
||||||
return nativeOnChain(pageChainId).wrapped.address
|
return nativeOnChain(pageChainId).wrapped.address
|
||||||
|
case Chain.Polygon:
|
||||||
|
// Like Celo, native MATIC does have a ERC20 precompile, but we use WMATIC in routing/pools
|
||||||
|
// So instead of returning nativeOnChain().wrapped.address, should directly use the precompile address here
|
||||||
|
return MATIC_POLYGON.address
|
||||||
case Chain.Ethereum:
|
case Chain.Ethereum:
|
||||||
case Chain.Arbitrum:
|
case Chain.Arbitrum:
|
||||||
case Chain.EthereumGoerli:
|
case Chain.EthereumGoerli:
|
||||||
|
Loading…
Reference in New Issue
Block a user