Skip to content

Commit 903a866

Browse files
committed
Chore: Add new chains
1 parent 09154b7 commit 903a866

9 files changed

Lines changed: 106 additions & 1 deletion

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@mimicprotocol/lib-ts": minor
3+
"@mimicprotocol/cli": minor
4+
---
5+
6+
Add Polygon, Avalanche, and BNB chain support
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ERC20Token } from '../tokens'
2+
import { ChainId } from '../types'
3+
4+
/* eslint-disable no-secrets/no-secrets */
5+
6+
export namespace Avalanche {
7+
export const CHAIN_ID = ChainId.AVALANCHE
8+
export const AVAX = ERC20Token.native(CHAIN_ID)
9+
export const USDC = ERC20Token.fromString('0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E', CHAIN_ID, 6, 'USDC')
10+
export const USDT = ERC20Token.fromString('0x9702230A8Ea53601f5cd2dc00fDbc13d4dF4A8c7', CHAIN_ID, 6, 'USDt')
11+
export const DAI = ERC20Token.fromString('0xd586E7F844cEa2F87f50152665BCbc2C279D8d70', CHAIN_ID, 18, 'DAI.e')
12+
export const WBTC = ERC20Token.fromString('0x50b7545627a5162F82A992c33b87aDc75187B218', CHAIN_ID, 8, 'WBTC.e')
13+
export const WETH = ERC20Token.fromString('0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB', CHAIN_ID, 18, 'WETH.e')
14+
export const WAVAX = ERC20Token.fromString('0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7', CHAIN_ID, 18, 'WAVAX')
15+
}

packages/lib-ts/src/chains/BNB.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ERC20Token } from '../tokens'
2+
import { ChainId } from '../types'
3+
4+
/* eslint-disable no-secrets/no-secrets */
5+
6+
export namespace BNB {
7+
export const CHAIN_ID = ChainId.BNB
8+
export const BNB = ERC20Token.native(CHAIN_ID)
9+
export const USDC = ERC20Token.fromString('0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d', CHAIN_ID, 18, 'USDC')
10+
export const USDT = ERC20Token.fromString('0x55d398326f99059fF775485246999027B3197955', CHAIN_ID, 18, 'USDT')
11+
export const DAI = ERC20Token.fromString('0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3', CHAIN_ID, 18, 'DAI')
12+
export const WBTC = ERC20Token.fromString('0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3ead9c', CHAIN_ID, 18, 'BTCB')
13+
export const WETH = ERC20Token.fromString('0x2170Ed0880ac9A755fd29B2688956BD959F933F8', CHAIN_ID, 18, 'ETH')
14+
export const WBNB = ERC20Token.fromString('0xBB4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c', CHAIN_ID, 18, 'WBNB')
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ERC20Token } from '../tokens'
2+
import { ChainId } from '../types'
3+
4+
/* eslint-disable no-secrets/no-secrets */
5+
6+
export namespace Polygon {
7+
export const CHAIN_ID = ChainId.POLYGON
8+
export const POL = ERC20Token.native(CHAIN_ID)
9+
export const USDC = ERC20Token.fromString('0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174', CHAIN_ID, 6, 'USDC')
10+
export const USDT = ERC20Token.fromString('0xc2132D05D31c914a87C6611C10748AEb04B58e8F', CHAIN_ID, 6, 'USDT0')
11+
export const DAI = ERC20Token.fromString('0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063', CHAIN_ID, 18, 'DAI')
12+
export const WBTC = ERC20Token.fromString('0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6', CHAIN_ID, 8, 'WBTC')
13+
export const WETH = ERC20Token.fromString('0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619', CHAIN_ID, 18, 'WETH')
14+
export const WPOL = ERC20Token.fromString('0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270', CHAIN_ID, 18, 'WPOL')
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
export * from './Arbitrum'
2+
export * from './Avalanche'
23
export * from './Base'
34
export * from './BaseSepolia'
5+
export * from './BNB'
46
export * from './Ethereum'
57
export * from './Gnosis'
68
export * from './Optimism'
9+
export * from './Polygon'
710
export * from './Sonic'

packages/lib-ts/src/tokens/ERC20Token.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,14 @@ export class ERC20Token extends BlockchainToken {
2929
case ChainId.ARBITRUM:
3030
case ChainId.OPTIMISM:
3131
return ERC20Token.fromString(EVM_NATIVE_ADDRESS, chainId, 18, 'ETH')
32+
case ChainId.BNB:
33+
return ERC20Token.fromString(EVM_NATIVE_ADDRESS, chainId, 18, 'BNB')
3234
case ChainId.GNOSIS:
3335
return ERC20Token.fromString(EVM_NATIVE_ADDRESS, chainId, 18, 'xDAI')
36+
case ChainId.POLYGON:
37+
return ERC20Token.fromString('0x0000000000000000000000000000000000001010', chainId, 18, 'POL')
38+
case ChainId.AVALANCHE:
39+
return ERC20Token.fromString(EVM_NATIVE_ADDRESS, chainId, 18, 'AVAX')
3440
case ChainId.SONIC:
3541
return ERC20Token.fromString(EVM_NATIVE_ADDRESS, chainId, 18, 'SONIC')
3642
default:

packages/lib-ts/src/types/ChainId.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
export enum ChainId {
66
ETHEREUM = 1,
77
OPTIMISM = 10,
8+
BNB = 56,
9+
POLYGON = 137,
10+
SONIC = 146,
811
ARBITRUM = 42161,
12+
AVALANCHE = 43114,
913
BASE = 8453,
1014
BASE_SEPOLIA = 84532,
1115
GNOSIS = 100,
1216
SOLANA_MAINNET = 507424,
13-
SONIC = 146,
1417
}

packages/lib-ts/tests/helpers.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ export const CHAIN_IDS: ChainId[] = [
2222
ChainId.ARBITRUM,
2323
ChainId.OPTIMISM,
2424
ChainId.GNOSIS,
25+
ChainId.BNB,
26+
ChainId.POLYGON,
27+
ChainId.AVALANCHE,
2528
ChainId.SONIC,
2629
]
2730

packages/lib-ts/tests/tokens/ERC20Token.spec.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,19 @@ describe('ERC20Token', () => {
136136
})
137137
})
138138

139+
describe('when the chain id is bnb', () => {
140+
const chainId = ChainId.BNB
141+
142+
it('returns the expected token', () => {
143+
const token = ERC20Token.native(chainId)
144+
145+
expect(token.address.toHexString()).toBe(EVM_NATIVE_ADDRESS)
146+
expect(token.chainId).toBe(chainId)
147+
expect(token.symbol).toBe('BNB')
148+
expect(token.decimals).toBe(18)
149+
})
150+
})
151+
139152
describe('when the chain id is gnosis', () => {
140153
const chainId = ChainId.GNOSIS
141154

@@ -149,6 +162,32 @@ describe('ERC20Token', () => {
149162
})
150163
})
151164

165+
describe('when the chain id is polygon', () => {
166+
const chainId = ChainId.POLYGON
167+
168+
it('returns the expected token', () => {
169+
const token = ERC20Token.native(chainId)
170+
171+
expect(token.address.toHexString()).toBe('0x0000000000000000000000000000000000001010')
172+
expect(token.chainId).toBe(chainId)
173+
expect(token.symbol).toBe('POL')
174+
expect(token.decimals).toBe(18)
175+
})
176+
})
177+
178+
describe('when the chain id is avalanche', () => {
179+
const chainId = ChainId.AVALANCHE
180+
181+
it('returns the expected token', () => {
182+
const token = ERC20Token.native(chainId)
183+
184+
expect(token.address.toHexString()).toBe(EVM_NATIVE_ADDRESS)
185+
expect(token.chainId).toBe(chainId)
186+
expect(token.symbol).toBe('AVAX')
187+
expect(token.decimals).toBe(18)
188+
})
189+
})
190+
152191
describe('when the chain id is sonic', () => {
153192
const chainId = ChainId.SONIC
154193

0 commit comments

Comments
 (0)