Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support celo #287

Merged
merged 8 commits into from
Oct 27, 2022
12 changes: 4 additions & 8 deletions src/constants/addresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ type AddressMap = { [chainId: number]: string }

export const UNI_ADDRESS: AddressMap = constructSameAddressMap('0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984')

// celo v3 addresses
const CELO_ROUTER_ADDRESS = '0x5615CDAb10dc425a742d643d949a7F474C01abc4'
const CELO_MULTICALL_ADDRESS = '0x633987602DE5C4F337e3DbF265303A1080324204'

export const MULTICALL_ADDRESS: AddressMap = {
...constructSameAddressMap('0x1F98415757620B543A52E61c46B32eB19261F984', [
SupportedChainId.OPTIMISTIC_KOVAN,
Expand All @@ -18,8 +14,8 @@ export const MULTICALL_ADDRESS: AddressMap = {
]),
[SupportedChainId.ARBITRUM_ONE]: '0xadF885960B47eA2CD9B55E6DAc6B42b7Cb2806dB',
[SupportedChainId.ARBITRUM_RINKEBY]: '0xa501c031958F579dB7676fF1CE78AD305794d579',
[SupportedChainId.CELO]: CELO_MULTICALL_ADDRESS,
[SupportedChainId.CELO_ALFAJORES]: CELO_MULTICALL_ADDRESS,
[SupportedChainId.CELO]: '0x633987602DE5C4F337e3DbF265303A1080324204',
[SupportedChainId.CELO_ALFAJORES]: '0x633987602DE5C4F337e3DbF265303A1080324204',
}

export const SWAP_ROUTER_ADDRESSES: AddressMap = {
Expand All @@ -31,8 +27,8 @@ export const SWAP_ROUTER_ADDRESSES: AddressMap = {
SupportedChainId.POLYGON,
SupportedChainId.POLYGON_MUMBAI,
]),
[SupportedChainId.CELO]: CELO_ROUTER_ADDRESS,
[SupportedChainId.CELO_ALFAJORES]: CELO_ROUTER_ADDRESS,
[SupportedChainId.CELO]: '0x5615CDAb10dc425a742d643d949a7F474C01abc4',
[SupportedChainId.CELO_ALFAJORES]: '0x5615CDAb10dc425a742d643d949a7F474C01abc4',
}

export const ARGENT_WALLET_DETECTOR_ADDRESS: AddressMap = {
Expand Down
2 changes: 1 addition & 1 deletion src/constants/chainInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ const CHAIN_INFO: ChainInfoMap = {
blockWaitMsBeforeWarning: ms`10m`,
bridge: 'https://www.portalbridge.com/#/transfer',
docs: 'https://docs.celo.org/',
explorer: 'https://alfajores-blockscout.celo-testnet.org/',
explorer: 'https://alfajores.celoscan.io/',
infoLink: 'https://info.uniswap.org/#/celo',
label: 'Celo Alfajores',
logoUrl: celoLogo,
Expand Down
124 changes: 9 additions & 115 deletions src/constants/routing.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// a list of tokens by chain
import { Currency, Token } from '@uniswap/sdk-core'
import { Token } from '@uniswap/sdk-core'

import { SupportedChainId } from './chains'
import {
Expand All @@ -15,17 +15,14 @@ import {
FEI,
FRAX,
FXS,
nativeOnChain,
PORTAL_ETH_CELO,
PORTAL_USDC_CELO,
renBTC,
rETH2,
sETH2,
SWISE,
TRIBE,
USDC_ARBITRUM,
USDC_MAINNET,
USDC_OPTIMISM,
USDC_POLYGON,
USDT,
USDT_ARBITRUM_ONE,
Expand All @@ -34,20 +31,14 @@ import {
WBTC,
WBTC_ARBITRUM_ONE,
WBTC_OPTIMISM,
WBTC_POLYGON,
WETH_POLYGON,
WETH_POLYGON_MUMBAI,
WRAPPED_NATIVE_CURRENCY,
} from './tokens'

type ChainTokenList = {
readonly [chainId: number]: Token[]
}

type ChainCurrencyList = {
readonly [chainId: number]: Currency[]
}

const WRAPPED_NATIVE_CURRENCIES_ONLY: ChainTokenList = Object.fromEntries(
Object.entries(WRAPPED_NATIVE_CURRENCY)
.map(([key, value]) => [key, [value]])
Expand Down Expand Up @@ -83,7 +74,14 @@ export const BASES_TO_CHECK_TRADES_AGAINST: ChainTokenList = {
USDT_POLYGON,
WETH_POLYGON,
],
[SupportedChainId.CELO]: [CUSD_CELO, CEUR_CELO, CMC02_CELO, PORTAL_USDC_CELO, PORTAL_ETH_CELO],
[SupportedChainId.CELO]: [
...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.CELO],
CUSD_CELO,
CEUR_CELO,
CMC02_CELO,
PORTAL_USDC_CELO,
PORTAL_ETH_CELO,
],
}
export const ADDITIONAL_BASES: { [chainId: number]: { [tokenAddress: string]: Token[] } } = {
[SupportedChainId.MAINNET]: {
Expand All @@ -107,107 +105,3 @@ export const CUSTOM_BASES: { [chainId: number]: { [tokenAddress: string]: Token[
[AMPL.address]: [DAI, WRAPPED_NATIVE_CURRENCY[SupportedChainId.MAINNET] as Token],
},
}

/**
* Shows up in the currency select for swap and add liquidity
*/
export const COMMON_BASES: ChainCurrencyList = {
[SupportedChainId.MAINNET]: [
nativeOnChain(SupportedChainId.MAINNET),
DAI,
USDC_MAINNET,
USDT,
WBTC,
WRAPPED_NATIVE_CURRENCY[SupportedChainId.MAINNET] as Token,
],
[SupportedChainId.ROPSTEN]: [
nativeOnChain(SupportedChainId.ROPSTEN),
WRAPPED_NATIVE_CURRENCY[SupportedChainId.ROPSTEN] as Token,
],
[SupportedChainId.RINKEBY]: [
nativeOnChain(SupportedChainId.RINKEBY),
WRAPPED_NATIVE_CURRENCY[SupportedChainId.RINKEBY] as Token,
],
[SupportedChainId.GOERLI]: [
nativeOnChain(SupportedChainId.GOERLI),
WRAPPED_NATIVE_CURRENCY[SupportedChainId.GOERLI] as Token,
],
[SupportedChainId.KOVAN]: [
nativeOnChain(SupportedChainId.KOVAN),
WRAPPED_NATIVE_CURRENCY[SupportedChainId.KOVAN] as Token,
],
[SupportedChainId.ARBITRUM_ONE]: [
nativeOnChain(SupportedChainId.ARBITRUM_ONE),
DAI_ARBITRUM_ONE,
USDC_ARBITRUM,
USDT_ARBITRUM_ONE,
WBTC_ARBITRUM_ONE,
WRAPPED_NATIVE_CURRENCY[SupportedChainId.ARBITRUM_ONE] as Token,
],
[SupportedChainId.ARBITRUM_RINKEBY]: [
nativeOnChain(SupportedChainId.ARBITRUM_RINKEBY),
WRAPPED_NATIVE_CURRENCY[SupportedChainId.ARBITRUM_RINKEBY] as Token,
],
[SupportedChainId.OPTIMISM]: [
nativeOnChain(SupportedChainId.OPTIMISM),
DAI_OPTIMISM,
USDC_OPTIMISM,
USDT_OPTIMISM,
WBTC_OPTIMISM,
],
[SupportedChainId.OPTIMISTIC_KOVAN]: [nativeOnChain(SupportedChainId.OPTIMISTIC_KOVAN)],
[SupportedChainId.POLYGON]: [
nativeOnChain(SupportedChainId.POLYGON),
WETH_POLYGON,
USDC_POLYGON,
DAI_POLYGON,
USDT_POLYGON,
WBTC_POLYGON,
],
[SupportedChainId.POLYGON_MUMBAI]: [
nativeOnChain(SupportedChainId.POLYGON_MUMBAI),
WRAPPED_NATIVE_CURRENCY[SupportedChainId.POLYGON_MUMBAI] as Token,
WETH_POLYGON_MUMBAI,
],
[SupportedChainId.CELO]: [
nativeOnChain(SupportedChainId.POLYGON),
WETH_POLYGON,
USDC_POLYGON,
DAI_POLYGON,
USDT_POLYGON,
WBTC_POLYGON,
],
[SupportedChainId.CELO_ALFAJORES]: [
nativeOnChain(SupportedChainId.POLYGON_MUMBAI),
WRAPPED_NATIVE_CURRENCY[SupportedChainId.POLYGON_MUMBAI] as Token,
WETH_POLYGON_MUMBAI,
],
}

// used to construct the list of all pairs we consider by default in the frontend
export const BASES_TO_TRACK_LIQUIDITY_FOR: ChainTokenList = {
...WRAPPED_NATIVE_CURRENCIES_ONLY,
[SupportedChainId.MAINNET]: [
...WRAPPED_NATIVE_CURRENCIES_ONLY[SupportedChainId.MAINNET],
DAI,
USDC_MAINNET,
USDT,
WBTC,
],
}
export const PINNED_PAIRS: { readonly [chainId: number]: [Token, Token][] } = {
[SupportedChainId.MAINNET]: [
[
new Token(SupportedChainId.MAINNET, '0x5d3a536E4D6DbD6114cc1Ead35777bAB948E3643', 8, 'cDAI', 'Compound Dai'),
new Token(
SupportedChainId.MAINNET,
'0x39AA39c021dfbaE8faC545936693aC917d5E7563',
8,
'cUSDC',
'Compound USD Coin'
),
],
[USDC_MAINNET, USDT],
[DAI, USDT],
],
}
18 changes: 3 additions & 15 deletions src/constants/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,8 @@ export const UNI: { [chainId: number]: Token } = {

export const WRAPPED_NATIVE_CURRENCY: { [chainId: number]: Token | undefined } = {
...(WETH9 as Record<SupportedChainId, Token>),
[SupportedChainId.CELO]: CELO_CELO,
[SupportedChainId.CELO_ALFAJORES]: CELO_CELO_ALFAJORES,
[SupportedChainId.OPTIMISM]: new Token(
SupportedChainId.OPTIMISM,
'0x4200000000000000000000000000000000000006',
Expand Down Expand Up @@ -388,20 +390,6 @@ export const WRAPPED_NATIVE_CURRENCY: { [chainId: number]: Token | undefined } =
'WMATIC',
'Wrapped MATIC'
),
[SupportedChainId.CELO]: new Token(
SupportedChainId.CELO,
'0x471ece3750da237f93b8e339c536989b8978a438',
18,
'CELO',
'Celo native asset'
),
[SupportedChainId.CELO_ALFAJORES]: new Token(
SupportedChainId.CELO_ALFAJORES,
'0xf194afdf50b03e69bd7d057c1aa9e10c9954e4c9',
18,
'CELO',
'Celo native asset'
),
}

export function isCelo(chainId: number): chainId is SupportedChainId.CELO | SupportedChainId.CELO_ALFAJORES {
Expand Down Expand Up @@ -483,6 +471,6 @@ export const TOKEN_SHORTHANDS: { [shorthand: string]: { [chainId in SupportedCha
[SupportedChainId.KOVAN]: USDC_KOVAN.address,
[SupportedChainId.ROPSTEN]: USDC_ROPSTEN.address,
[SupportedChainId.CELO]: PORTAL_USDC_CELO.address,
[SupportedChainId.CELO_ALFAJORES]: PORTAL_USDC_CELO.address,
[SupportedChainId.CELO_ALFAJORES]: USDC_CELO_ALFAJORES.address,
},
}
2 changes: 1 addition & 1 deletion src/hooks/useCurrencyLogoURIs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function getTokenLogoURI(address: string, chainId: SupportedChainId = SupportedC
// Celo logo is hosted elsewhere.
if (isCelo(chainId)) {
if (address === nativeOnChain(chainId).wrapped.address) {
return 'https://raw.githubusercontent.com/ubeswap/default-token-list/master/assets/asset_CELO.png'
return 'https://celo-org.github.io/celo-token-list/assets/celo_alternative_logo.png'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this the alternative logo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative logo (yellow and white) is used for erc-20 transfers and is consistent with other applications on Celo. The green and yellow icon normally represents the network itself.

For UI consistency; Celo on the celo token list (and others alike) use the alternative logo to represent $CELO. If $CELO is selected from the token list, the same logo should be displayed on the swap widget.

}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/utils/getExplorerLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ describe('#getExplorerLink', () => {
it('polygon', () => {
expect(getExplorerLink(137, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://polygonscan.com/address/abc')
})
it('mumbai', () => {
expect(getExplorerLink(80001, 'abc', ExplorerDataType.ADDRESS)).toEqual(
'https://mumbai.polygonscan.com/address/abc'
)
})
it('celo', () => {
Jesse-Sawa marked this conversation as resolved.
Show resolved Hide resolved
expect(getExplorerLink(42220, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://celoscan.io/address/abc')
})
it('alfajores', () => {
expect(getExplorerLink(44787, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://alfajores.celoscan.io/address/abc')
})
it('ropsten', () => {
expect(getExplorerLink(3, 'abc', ExplorerDataType.ADDRESS)).toEqual('https://ropsten.etherscan.io/address/abc')
})
Expand Down
2 changes: 1 addition & 1 deletion src/utils/getExplorerLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const ETHERSCAN_PREFIXES: { [chainId: number]: string } = {
[SupportedChainId.POLYGON_MUMBAI]: 'https://mumbai.polygonscan.com',
[SupportedChainId.POLYGON]: 'https://polygonscan.com',
[SupportedChainId.CELO]: 'https://celoscan.io',
[SupportedChainId.CELO_ALFAJORES]: 'https://alfajores.celoscan.io/',
[SupportedChainId.CELO_ALFAJORES]: 'https://alfajores.celoscan.io',
}

export enum ExplorerDataType {
Expand Down