Skip to content

Commit

Permalink
feat(multichain): Add base and polygon (valora-inc#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
finnian0826 authored Mar 28, 2024
1 parent b9ee550 commit 0653e44
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 5 deletions.
Binary file added assets/tokens/BASE.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion config-dev.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NETWORK_IDS: 'celo-alfajores,ethereum-sepolia,arbitrum-sepolia,op-sepolia'
NETWORK_IDS: 'celo-alfajores,ethereum-sepolia,arbitrum-sepolia,op-sepolia,polygon-pos-mumbai,base-sepolia'
GCLOUD_PROJECT: 'celo-mobile-alfajores'
2 changes: 1 addition & 1 deletion config-prod.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
NETWORK_IDS: 'celo-mainnet,ethereum-mainnet,arbitrum-one,op-mainnet'
NETWORK_IDS: 'celo-mainnet,ethereum-mainnet,arbitrum-one,op-mainnet,polygon-pos-mainnet,base-mainnet'
GCLOUD_PROJECT: 'celo-mobile-mainnet'
18 changes: 18 additions & 0 deletions src/data/mainnet/base-tokens-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "Ether",
"symbol": "ETH",
"decimals": 18,
"isNative": true,
"isL2Native": true,
"imageUrl": "https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/ETH.png",
"infoUrl": "https://www.coingecko.com/en/coins/ethereum"
},
{
"name": "USD Coin",
"symbol": "USDC",
"decimals": 6,
"address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
"imageUrl": "https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/USDC.png"
}
]
19 changes: 19 additions & 0 deletions src/data/mainnet/polygon-pos-tokens-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"name": "Matic Token",
"symbol": "MATIC",
"address": "0x0000000000000000000000000000000000001010",
"decimals": 18,
"isNative": true,
"isL2Native": true,
"imageUrl": "https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/MATIC.png",
"infoUrl": "https://www.coingecko.com/en/coins/polygon"
},
{
"name": "USD Coin",
"symbol": "USDC",
"decimals": 6,
"address": "0x3c499c542cef5e3811e1192ce70d8cc03d5c3359",
"imageUrl": "https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/USDC.png"
}
]
18 changes: 18 additions & 0 deletions src/data/testnet/base-sepolia-tokens-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
{
"name": "Ether",
"symbol": "ETH",
"decimals": 18,
"isNative": true,
"isL2Native": true,
"imageUrl": "https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/ETH.png",
"infoUrl": "https://www.coingecko.com/en/coins/ethereum"
},
{
"name": "USD Coin",
"symbol": "USDC",
"decimals": 6,
"address": "0xd74cc5d436923b8ba2c179b4bca2841d8a52c5b5",
"imageUrl": "https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/USDC.png"
}
]
19 changes: 19 additions & 0 deletions src/data/testnet/polygon-pos-mumbai-tokens-info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[
{
"name": "Matic Token",
"symbol": "MATIC",
"address": "0x0000000000000000000000000000000000001010",
"decimals": 18,
"isNative": true,
"isL2Native": true,
"imageUrl": "https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/MATIC.png",
"infoUrl": "https://www.coingecko.com/en/coins/polygon"
},
{
"name": "USD Coin",
"symbol": "USDC",
"decimals": 6,
"address": "0xe6b8a5cf854791412c1f6efc7caf629f5df1c747",
"imageUrl": "https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/USDC.png"
}
]
4 changes: 4 additions & 0 deletions src/schemas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const networkIdToIsL2: Record<NetworkId, boolean> = {
[NetworkId['arbitrum-sepolia']]: true,
[NetworkId['op-mainnet']]: true,
[NetworkId['op-sepolia']]: true,
[NetworkId['polygon-pos-mainnet']]: true,
[NetworkId['polygon-pos-mumbai']]: true,
[NetworkId['base-mainnet']]: true,
[NetworkId['base-sepolia']]: true,
}

describe('Schema validation', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/schemas/tokens-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ const ProcessedTokenInfoSchema = BaseTokenInfoSchema.concat(
const getTokenInfoSchema = (base: Joi.ObjectSchema<any>) =>
Joi.alternatives().try(
Joi.object({
// native tokens don't have an address except CELO
// native tokens don't have an address except CELO and MATIC
isNative: Joi.valid(true).required(),
symbol: Joi.string().invalid('CELO').required(),
symbol: Joi.string().invalid('CELO').invalid('MATIC').required(),
address: Joi.forbidden(),
}).concat(base),
Joi.object({
// CELO is native and has an address
isNative: Joi.valid(true).required(),
symbol: Joi.valid('CELO').required(),
symbol: Joi.valid('CELO').valid('MATIC').required(),
address: AddressSchema.required(),
}).concat(base),
Joi.object({
Expand Down
16 changes: 16 additions & 0 deletions src/tokens-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import ArbitrumOneTokensInfo from './data/mainnet/arbitrum-one-tokens-info.json'
import ArbitrumSepoliaTokensInfo from './data/testnet/arbitrum-sepolia-tokens-info.json'
import OptimismMainnetTokensInfo from './data/mainnet/optimism-tokens-info.json'
import OptimismSepoliaTokensInfo from './data/testnet/optimism-sepolia-tokens-info.json'
import PolygonPoSMainnetTokensInfo from './data/mainnet/polygon-pos-tokens-info.json'
import PolygonPoSMumbaiTokensInfo from './data/testnet/polygon-pos-mumbai-tokens-info.json'
import BaseMainnetTokensInfo from './data/mainnet/base-tokens-info.json'
import BaseSepoliaTokensInfo from './data/testnet/base-sepolia-tokens-info.json'

const networkIdToTokensInfo: Record<NetworkId, TokenInfoJSON[]> = {
[NetworkId['celo-mainnet']]: CeloMainnetTokensInfo,
Expand All @@ -17,6 +21,10 @@ const networkIdToTokensInfo: Record<NetworkId, TokenInfoJSON[]> = {
[NetworkId['arbitrum-sepolia']]: ArbitrumSepoliaTokensInfo,
[NetworkId['op-mainnet']]: OptimismMainnetTokensInfo,
[NetworkId['op-sepolia']]: OptimismSepoliaTokensInfo,
[NetworkId['polygon-pos-mainnet']]: PolygonPoSMainnetTokensInfo,
[NetworkId['polygon-pos-mumbai']]: PolygonPoSMumbaiTokensInfo,
[NetworkId['base-mainnet']]: BaseMainnetTokensInfo,
[NetworkId['base-sepolia']]: BaseSepoliaTokensInfo,
}

const networkIdToNetworkIconUrl: Record<NetworkId, string> = {
Expand All @@ -36,6 +44,14 @@ const networkIdToNetworkIconUrl: Record<NetworkId, string> = {
'https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/OP.png',
[NetworkId['op-sepolia']]:
'https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/OP.png',
[NetworkId['polygon-pos-mainnet']]:
'https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/MATIC.png',
[NetworkId['polygon-pos-mumbai']]:
'https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/MATIC.png',
[NetworkId['base-mainnet']]:
'https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/BASE.png',
[NetworkId['base-sepolia']]:
'https://raw.githubusercontent.com/valora-inc/address-metadata/main/assets/tokens/BASE.png',
}

export function getTokenId(
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export enum NetworkId {
['arbitrum-sepolia'] = 'arbitrum-sepolia',
['op-mainnet'] = 'op-mainnet',
['op-sepolia'] = 'op-sepolia',
['polygon-pos-mainnet'] = 'polygon-pos-mainnet',
['polygon-pos-mumbai'] = 'polygon-pos-mumbai',
['base-mainnet'] = 'base-mainnet',
['base-sepolia'] = 'base-sepolia',
}

export type Environment = 'mainnet' | 'testnet'
Expand Down

0 comments on commit 0653e44

Please sign in to comment.