Skip to content

Commit

Permalink
feat(breaking): UR address change for v4 (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
dannythedawger authored Sep 6, 2024
1 parent df6348a commit f1947c5
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 46 deletions.
2 changes: 1 addition & 1 deletion sdks/universal-router-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export * from './entities'
export * from './utils/routerTradeAdapter'
export { RoutePlanner, CommandType } from './utils/routerCommands'
export {
UNIVERSAL_ROUTER_ADDRESS,
UNIVERSAL_ROUTER_CREATION_BLOCK,
UNIVERSAL_ROUTER_ADDRESS,
PERMIT2_ADDRESS,
ROUTER_AS_RECIPIENT,
WETH_ADDRESS,
Expand Down
240 changes: 197 additions & 43 deletions sdks/universal-router-sdk/src/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,129 +1,283 @@
import { BigNumber } from 'ethers'

type ChainConfig = {
router: string
export enum RouterVersion {
V1_2,
V2_0,
}

export type RouterConfig = {
address: string
creationBlock: number
}

type ChainConfig = {
weth: string
routerConfigs: { [key in RouterVersion]: RouterConfig }
}

const WETH_NOT_SUPPORTED_ON_CHAIN = '0x0000000000000000000000000000000000000000'

const CHAIN_CONFIGS: { [key: number]: ChainConfig } = {
// Todo: Change `CHAIN_CONFIGS` to pull the UR address with v4
export const CHAIN_CONFIGS: { [key: number]: ChainConfig } = {
// mainnet
[1]: {
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
weth: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
creationBlock: 17143817,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 17143817,
},
[RouterVersion.V2_0]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 17143817,
},
},
},
// goerli
[5]: {
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
weth: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6',
creationBlock: 8940568,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 8940568,
},
[RouterVersion.V2_0]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 8940568,
},
},
},
// sepolia
[11155111]: {
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
weth: '0xfFf9976782d46CC05630D1f6eBAb18b2324d6B14',
creationBlock: 3543575,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 3543575,
},
[RouterVersion.V2_0]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 3543575,
},
},
},
// polygon
[137]: {
router: '0xec7BE89e9d109e7e3Fec59c222CF297125FEFda2',
weth: '0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270',
creationBlock: 52210153,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0xec7BE89e9d109e7e3Fec59c222CF297125FEFda2',
creationBlock: 52210153,
},
[RouterVersion.V2_0]: {
address: '0xec7BE89e9d109e7e3Fec59c222CF297125FEFda2',
creationBlock: 52210153,
},
},
},
//polygon mumbai
[80001]: {
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
weth: '0x9c3C9283D3e44854697Cd22D3Faa240Cfb032889',
creationBlock: 35176052,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 35176052,
},
[RouterVersion.V2_0]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 35176052,
},
},
},
//optimism
[10]: {
router: '0xCb1355ff08Ab38bBCE60111F1bb2B784bE25D7e8',
weth: '0x4200000000000000000000000000000000000006',
creationBlock: 114702266,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0xCb1355ff08Ab38bBCE60111F1bb2B784bE25D7e8',
creationBlock: 114702266,
},
[RouterVersion.V2_0]: {
address: '0xCb1355ff08Ab38bBCE60111F1bb2B784bE25D7e8',
creationBlock: 114702266,
},
},
},
// optimism goerli
[420]: {
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
weth: '0x4200000000000000000000000000000000000006',
creationBlock: 8887728,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 8887728,
},
[RouterVersion.V2_0]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 8887728,
},
},
},
// arbitrum
[42161]: {
router: '0x5E325eDA8064b456f4781070C0738d849c824258',
weth: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
creationBlock: 169472836,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x5E325eDA8064b456f4781070C0738d849c824258',
creationBlock: 169472836,
},
[RouterVersion.V2_0]: {
address: '0x5E325eDA8064b456f4781070C0738d849c824258',
creationBlock: 169472836,
},
},
},
// arbitrum goerli
[421613]: {
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
weth: '0xe39Ab88f8A4777030A534146A9Ca3B52bd5D43A3',
creationBlock: 18815277,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 18815277,
},
[RouterVersion.V2_0]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 18815277,
},
},
},
// celo
[42220]: {
router: '0x643770e279d5d0733f21d6dc03a8efbabf3255b4',
weth: WETH_NOT_SUPPORTED_ON_CHAIN,
creationBlock: 21407637,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x643770e279d5d0733f21d6dc03a8efbabf3255b4',
creationBlock: 21407637,
},
[RouterVersion.V2_0]: {
address: '0x643770e279d5d0733f21d6dc03a8efbabf3255b4',
creationBlock: 21407637,
},
},
},
// celo alfajores
[44787]: {
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
weth: WETH_NOT_SUPPORTED_ON_CHAIN,
creationBlock: 17566658,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 17566658,
},
[RouterVersion.V2_0]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 17566658,
},
},
},
// binance smart chain
[56]: {
router: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
weth: '0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c',
creationBlock: 35160263,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
creationBlock: 35160263,
},
[RouterVersion.V2_0]: {
address: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
creationBlock: 35160263,
},
},
},
// avalanche
[43114]: {
router: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
weth: '0xB31f66AA3C1e785363F0875A1B74E27b85FD66c7',
creationBlock: 40237257,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
creationBlock: 40237257,
},
[RouterVersion.V2_0]: {
address: '0x4Dae2f939ACf50408e13d58534Ff8c2776d45265',
creationBlock: 40237257,
},
},
},
// base goerli
[84531]: {
router: '0xd0872d928672ae2ff74bdb2f5130ac12229cafaf',
weth: '0x4200000000000000000000000000000000000006',
creationBlock: 6915289,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0xd0872d928672ae2ff74bdb2f5130ac12229cafaf',
creationBlock: 6915289,
},
[RouterVersion.V2_0]: {
address: '0xd0872d928672ae2ff74bdb2f5130ac12229cafaf',
creationBlock: 6915289,
},
},
},
// base mainnet
[8453]: {
router: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
weth: '0x4200000000000000000000000000000000000006',
creationBlock: 9107268,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 9107268,
},
[RouterVersion.V2_0]: {
address: '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD',
creationBlock: 9107268,
},
},
},
[81457]: {
router: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4',
weth: '0x4300000000000000000000000000000000000004',
creationBlock: 1116444,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4',
creationBlock: 1116444,
},
[RouterVersion.V2_0]: {
address: '0x643770E279d5D0733F21d6DC03A8efbABf3255B4',
creationBlock: 1116444,
},
},
},
[7777777]: {
router: '0x2986d9721A49838ab4297b695858aF7F17f38014',
weth: '0x4200000000000000000000000000000000000006',
creationBlock: 11832155,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x2986d9721A49838ab4297b695858aF7F17f38014',
creationBlock: 11832155,
},
[RouterVersion.V2_0]: {
address: '0x2986d9721A49838ab4297b695858aF7F17f38014',
creationBlock: 11832155,
},
},
},
[324]: {
router: '0x28731BCC616B5f51dD52CF2e4dF0E78dD1136C06',
weth: '0x5aea5775959fbc2557cc8789bc1bf90a239d9a91',
creationBlock: 12640979,
routerConfigs: {
[RouterVersion.V1_2]: {
address: '0x28731BCC616B5f51dD52CF2e4dF0E78dD1136C06',
creationBlock: 12640979,
},
[RouterVersion.V2_0]: {
address: '0x28731BCC616B5f51dD52CF2e4dF0E78dD1136C06',
creationBlock: 12640979,
},
},
},
}

export const UNIVERSAL_ROUTER_ADDRESS = (chainId: number): string => {
export const UNIVERSAL_ROUTER_ADDRESS = (version: RouterVersion, chainId: number): string => {
if (!(chainId in CHAIN_CONFIGS)) throw new Error(`Universal Router not deployed on chain ${chainId}`)
return CHAIN_CONFIGS[chainId].router
return CHAIN_CONFIGS[chainId].routerConfigs[version].address
}

export const UNIVERSAL_ROUTER_CREATION_BLOCK = (chainId: number): number => {
export const UNIVERSAL_ROUTER_CREATION_BLOCK = (version: RouterVersion, chainId: number): number => {
if (!(chainId in CHAIN_CONFIGS)) throw new Error(`Universal Router not deployed on chain ${chainId}`)
return CHAIN_CONFIGS[chainId].creationBlock
return CHAIN_CONFIGS[chainId].routerConfigs[version].creationBlock
}

export const WETH_ADDRESS = (chainId: number): string => {
Expand Down
8 changes: 6 additions & 2 deletions sdks/universal-router-sdk/test/utils/addresses.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { UNIVERSAL_ROUTER_ADDRESS, PERMIT2_ADDRESS as MAINNET_PERMIT2_ADDRESS } from '../../src/utils/constants'
import {
UNIVERSAL_ROUTER_ADDRESS,
PERMIT2_ADDRESS as MAINNET_PERMIT2_ADDRESS,
RouterVersion,
} from '../../src/utils/constants'

export const MAINNET_ROUTER_ADDRESS = UNIVERSAL_ROUTER_ADDRESS(1)
export const MAINNET_ROUTER_ADDRESS = UNIVERSAL_ROUTER_ADDRESS(RouterVersion.V1_2, 1)
export const FORGE_ROUTER_ADDRESS = '0xe808c1cfeebb6cb36b537b82fa7c9eef31415a05'
export const FORGE_PERMIT2_ADDRESS = '0x4a873bdd49f7f9cc0a5458416a12973fab208f8d'

Expand Down
Loading

0 comments on commit f1947c5

Please sign in to comment.