Skip to content

Commit

Permalink
add base sepolia and optimism sepolia chains (#1699)
Browse files Browse the repository at this point in the history
  • Loading branch information
mholtzman authored Mar 1, 2024
1 parent 60719f4 commit 110a722
Show file tree
Hide file tree
Showing 4 changed files with 239 additions and 13 deletions.
11 changes: 8 additions & 3 deletions main/store/migrate/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import legacyMigrations from './migrations/legacy'
import migration38 from './migrations/38'
import migration39 from './migrations/39'
import migration40 from './migrations/40'
import migration41 from './migrations/41'

import type { Migration } from '../state'

const migrations: Migration[] = [...legacyMigrations, migration38, migration39, migration40].sort(
(m1, m2) => m1.version - m2.version
)
const migrations: Migration[] = [
...legacyMigrations,
migration38,
migration39,
migration40,
migration41
].sort((m1, m2) => m1.version - m2.version)

// Version number of latest known migration
const latest = migrations[migrations.length - 1].version
Expand Down
161 changes: 161 additions & 0 deletions main/store/migrate/migrations/41/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import log from 'electron-log'

import { v38StateSchema } from '../38/schema'

function baseSepolia() {
const chain = {
id: 84532,
type: 'ethereum',
layer: 'testnet',
isTestnet: true,
name: 'Base Sepolia',
explorer: 'https://sepolia.basescan.org/',
gas: {
price: {
selected: 'standard',
levels: { slow: '', standard: '', fast: '', asap: '', custom: '' }
}
},
connection: {
primary: {
on: true,
current: 'pylon',
status: 'loading',
connected: false,
type: '',
network: '',
custom: ''
},
secondary: {
on: false,
current: 'custom',
status: 'loading',
connected: false,
type: '',
network: '',
custom: ''
}
},
on: false
} as const

const metadata = {
blockHeight: 0,
gas: {
fees: {},
price: {
selected: 'standard',
levels: { slow: '', standard: '', fast: '', asap: '', custom: '' }
}
},
nativeCurrency: {
symbol: 'sepETH',
usd: {
price: 0,
change24hr: 0
},
icon: '',
name: 'Base Sepolia Ether',
decimals: 18
},
icon: 'https://frame.nyc3.cdn.digitaloceanspaces.com/baseiconcolor.png',
primaryColor: 'accent2' // Testnet
} as const

return { chain, metadata }
}

function optimismSepolia() {
const chain = {
id: 11155420,
type: 'ethereum',
layer: 'testnet',
isTestnet: true,
name: 'Optimism Sepolia',
explorer: 'https://sepolia-optimism.etherscan.io/',
gas: {
price: {
selected: 'standard',
levels: { slow: '', standard: '', fast: '', asap: '', custom: '' }
}
},
connection: {
primary: {
on: true,
current: 'pylon',
status: 'loading',
connected: false,
type: '',
network: '',
custom: ''
},
secondary: {
on: false,
current: 'custom',
status: 'loading',
connected: false,
type: '',
network: '',
custom: ''
}
},
on: false
} as const

const metadata = {
blockHeight: 0,
gas: {
fees: {},
price: {
selected: 'standard',
levels: { slow: '', standard: '', fast: '', asap: '', custom: '' }
}
},
nativeCurrency: {
symbol: 'sepETH',
usd: {
price: 0,
change24hr: 0
},
icon: '',
name: 'Optimism Sepolia Ether',
decimals: 18
},
icon: '',
primaryColor: 'accent2' // Testnet
} as const

return { chain, metadata }
}

const migrate = (initial: unknown) => {
try {
const state = v38StateSchema.parse(initial)
const usingBaseSepolia = '84532' in state.main.networks.ethereum

if (!usingBaseSepolia) {
const { chain, metadata } = baseSepolia()
state.main.networks.ethereum[84532] = chain
state.main.networksMeta.ethereum[84532] = metadata
}

const usingOptimismSepolia = '11155420' in state.main.networks.ethereum

if (!usingOptimismSepolia) {
const { chain, metadata } = optimismSepolia()
state.main.networks.ethereum[11155420] = chain
state.main.networksMeta.ethereum[11155420] = metadata
}

return state
} catch (e) {
log.error('Migration 41: could not parse state', e)
}

return initial
}

export default {
version: 41,
migrate
}
73 changes: 65 additions & 8 deletions main/store/state/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ type M = Main & {
}

const mainState: M = {
_version: main('_version', 40),
_version: main('_version', 41),
instanceId: main('instanceId', generateUuid()),
colorway: main('colorway', 'dark'),
colorwayPrimary: {
Expand Down Expand Up @@ -416,13 +416,13 @@ const mainState: M = {
},
on: false
},
84531: {
id: 84531,
84532: {
id: 84532,
type: 'ethereum',
layer: 'testnet',
isTestnet: true,
name: 'Base Görli',
explorer: 'https://goerli-explorer.base.org',
name: 'Base Sepolia',
explorer: 'https://sepolia.basescan.org/',
gas: {
price: {
selected: 'standard',
Expand Down Expand Up @@ -485,6 +485,41 @@ const mainState: M = {
}
},
on: false
},
11155420: {
id: 11155420,
type: 'ethereum',
layer: 'testnet',
isTestnet: true,
name: 'Optimism Sepolia',
explorer: 'https://sepolia-optimism.etherscan.io/',
gas: {
price: {
selected: 'standard',
levels: { slow: '', standard: '', fast: '', asap: '', custom: '' }
}
},
connection: {
primary: {
on: true,
current: 'pylon',
status: 'loading',
connected: false,
type: '',
network: '',
custom: ''
},
secondary: {
on: false,
current: 'custom',
status: 'loading',
connected: false,
type: '',
network: '',
custom: ''
}
},
on: false
}
}
}),
Expand Down Expand Up @@ -644,7 +679,7 @@ const mainState: M = {
icon: 'https://frame.nyc3.cdn.digitaloceanspaces.com/icons/arbitrum.svg',
primaryColor: 'accent7' // Arbitrum
},
84531: {
84532: {
blockHeight: 0,
gas: {
fees: {},
Expand All @@ -654,13 +689,13 @@ const mainState: M = {
}
},
nativeCurrency: {
symbol: 'görETH',
symbol: 'sepETH',
usd: {
price: 0,
change24hr: 0
},
icon: '',
name: 'Görli Ether',
name: 'Base Sepolia Ether',
decimals: 18
},
icon: 'https://frame.nyc3.cdn.digitaloceanspaces.com/baseiconcolor.png',
Expand All @@ -687,6 +722,28 @@ const mainState: M = {
},
icon: '',
primaryColor: 'accent2' // Testnet
},
11155420: {
blockHeight: 0,
gas: {
fees: {},
price: {
selected: 'standard',
levels: { slow: '', standard: '', fast: '', asap: '', custom: '' }
}
},
nativeCurrency: {
symbol: 'sepETH',
usd: {
price: 0,
change24hr: 0
},
icon: '',
name: 'Optimism Sepolia Ether',
decimals: 18
},
icon: '',
primaryColor: 'accent2' // Testnet
}
}
}),
Expand Down
7 changes: 5 additions & 2 deletions resources/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ const NETWORK_PRESETS = {
42161: {
pylon: 'wss://evm.pylon.link/arbitrum'
},
84531: {
pylon: 'wss://evm.pylon.link/base-goerli'
84532: {
pylon: 'wss://evm.pylon.link/base-sepolia'
},
11155111: {
pylon: 'wss://evm.pylon.link/sepolia'
},
11155420: {
pylon: 'wss://evm.pylon.link/optimism-sepolia'
}
}
}
Expand Down

0 comments on commit 110a722

Please sign in to comment.