Skip to content

Commit

Permalink
feat: add optimism network support (#248)
Browse files Browse the repository at this point in the history
* feat: add optimism network support

* chore: use multicall3 contract for OP multicall

* chore: add OP icon

* chore: update API url

* fix: remove trailing / from explorer url
  • Loading branch information
Sekhmet authored Apr 5, 2024
1 parent ac0c902 commit ca99550
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 26 deletions.
5 changes: 5 additions & 0 deletions .changeset/lazy-oranges-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@snapshot-labs/sx": patch
---

add evmOptimism network
2 changes: 2 additions & 0 deletions apps/mana/src/eth/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
clients,
evmPolygon,
evmArbitrum,
evmOptimism,
evmMainnet,
evmGoerli,
evmSepolia,
Expand All @@ -13,6 +14,7 @@ import { createWalletProxy } from './dependencies';
import { rpcError, rpcSuccess } from '../utils';

export const NETWORKS = new Map<number, EvmNetworkConfig>([
[10, evmOptimism],
[137, evmPolygon],
[42161, evmArbitrum],
[1, evmMainnet],
Expand Down
8 changes: 4 additions & 4 deletions apps/subgraph-api/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
"startBlock": 18962278
}
},
"goerli": {
"sepolia": {
"ProxyFactory": {
"address": "0x4b4f7f64be813ccc66aefc3bfce2baa01188631c",
"startBlock": 9893638
"startBlock": 4519171
}
},
"sepolia": {
"optimism": {
"ProxyFactory": {
"address": "0x4b4f7f64be813ccc66aefc3bfce2baa01188631c",
"startBlock": 4519171
"startBlock": 118359200
}
},
"matic": {
Expand Down
2 changes: 1 addition & 1 deletion apps/subgraph-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"deploy-linea-testnet": "graph deploy --network linea-testnet --studio sx-linea-testnet",
"deploy-studio": "graph deploy --studio -l v${npm_package_version}",
"deploy-studio-mainnet": "yarn deploy-studio --network mainnet sx",
"deploy-studio-goerli": "yarn deploy-studio --network goerli sx-goerli",
"deploy-studio-sepolia": "yarn deploy-studio --network sepolia sx-sepolia",
"deploy-studio-optimism": "yarn deploy-studio --network optimism sx-optimism",
"deploy-studio-polygon": "yarn deploy-studio --network matic sx-polygon",
"deploy-studio-arbitrum": "yarn deploy-studio --network arbitrum-one sx-arbitrum"
},
Expand Down
1 change: 1 addition & 0 deletions apps/subgraph-api/src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const CHAIN_IDS = new Map<string, i32>()
CHAIN_IDS.set('mainnet', 1)
CHAIN_IDS.set('goerli', 5)
CHAIN_IDS.set('sepolia', 11155111)
CHAIN_IDS.set('optimism', 10)
CHAIN_IDS.set('matic', 137)
CHAIN_IDS.set('arbitrum-one', 42161)
CHAIN_IDS.set('linea-testnet', 59140)
Expand Down
16 changes: 8 additions & 8 deletions apps/subgraph-api/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ schema:
dataSources:
- kind: ethereum
name: ProxyFactory
network: sepolia
network: optimism
source:
abi: ProxyFactory
address: "0x4b4f7f64be813ccc66aefc3bfce2baa01188631c"
startBlock: 4519171
startBlock: 118359200
mapping:
kind: ethereum/events
apiVersion: 0.0.7
Expand All @@ -31,7 +31,7 @@ dataSources:
templates:
- kind: ethereum
name: Space
network: sepolia
network: optimism
source:
abi: Space
mapping:
Expand Down Expand Up @@ -81,7 +81,7 @@ templates:
file: ./src/mapping.ts
- kind: ethereum
name: TimelockExecutionStrategy
network: sepolia
network: optimism
source:
abi: TimelockExecutionStrategy
mapping:
Expand Down Expand Up @@ -111,7 +111,7 @@ templates:
abis:
- name: Space
file: ./abis/Space.json
network: sepolia
network: optimism
- name: ProposalMetadata
kind: file/ipfs
mapping:
Expand All @@ -124,7 +124,7 @@ templates:
abis:
- name: Space
file: ./abis/Space.json
network: sepolia
network: optimism
- name: StrategiesParsedMetadataData
kind: file/ipfs
mapping:
Expand All @@ -137,7 +137,7 @@ templates:
abis:
- name: Space
file: ./abis/Space.json
network: sepolia
network: optimism
- name: VotingPowerValidationStrategyMetadata
kind: file/ipfs
mapping:
Expand All @@ -150,4 +150,4 @@ templates:
abis:
- name: Space
file: ./abis/Space.json
network: sepolia
network: optimism
1 change: 1 addition & 0 deletions apps/ui/src/helpers/alchemy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const NETWORKS = {
1: 'eth-mainnet',
5: 'eth-goerli',
11155111: 'eth-sepolia',
10: 'opt-mainnet',
137: 'polygon-mainnet',
42161: 'arb-mainnet'
};
Expand Down
3 changes: 3 additions & 0 deletions apps/ui/src/helpers/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const ETH_CONTRACT = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee';
export const CHAIN_IDS = {
matic: 137,
arb1: 42161,
oeth: 10,
eth: 1,
gor: 5,
sep: 11155111,
Expand All @@ -13,12 +14,14 @@ export const CHAIN_IDS = {

export const COINGECKO_ASSET_PLATFORMS = {
1: 'ethereum',
10: 'optimistic-ethereum',
137: 'polygon-pos',
42161: 'arbitrum-one'
};

export const COINGECKO_BASE_ASSETS = {
1: 'ethereum',
10: 'ethereum',
137: 'matic-network',
42161: 'ethereum'
};
Expand Down
6 changes: 6 additions & 0 deletions apps/ui/src/helpers/networks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"multicall": "0xeefba1e63905ef1d7acba5a8513c70307c1ce441",
"explorer": "https://etherscan.io"
},
"10": {
"key": "10",
"chainId": 10,
"multicall": "0xcA11bde05977b3631167028862bE2a173976CA11",
"explorer": "https://optimistic.etherscan.io"
},
"137": {
"key": "137",
"chainId": 137,
Expand Down
1 change: 1 addition & 0 deletions apps/ui/src/helpers/opensea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const OPENSEA_CHAINS: Record<number, ChainItem> = {
5: { name: 'goerli', isTestnet: true },
11155111: { name: 'sepolia', isTestnet: true },
1: { name: 'ethereum', isTestnet: false },
10: { name: 'optimism', isTestnet: false },
137: { name: 'matic', isTestnet: false },
42161: { name: 'arbitrum', isTestnet: false }
};
Expand Down
2 changes: 2 additions & 0 deletions apps/ui/src/networks/evm/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Contract } from '@ethersproject/contracts';
import {
clients,
getEvmStrategy,
evmOptimism,
evmArbitrum,
evmPolygon,
evmMainnet,
Expand Down Expand Up @@ -44,6 +45,7 @@ import type {
import { getSwapLink } from '@/helpers/link';

const CONFIGS: Record<number, EvmNetworkConfig> = {
10: evmOptimism,
137: evmPolygon,
42161: evmArbitrum,
1: evmMainnet,
Expand Down
9 changes: 8 additions & 1 deletion apps/ui/src/networks/evm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ export const METADATA: Record<string, Metadata> = {
avatar: 'ipfs://bafkreic2p3zzafvz34y4tnx2kaoj6osqo66fpdo3xnagocil452y766gdq',
blockTime: ETH_MAINNET_BLOCK_TIME
},
oeth: {
name: 'Optimism',
chainId: 10,
apiUrl: 'https://api.studio.thegraph.com/query/23545/sx-optimism/version/latest',
avatar: 'ipfs://QmfF4kwhGL8QosUXvgq2KWCmavhKBvwD6kbhs7L4p5ZAWb',
blockTime: 2
},
eth: {
name: 'Ethereum',
chainId: 1,
Expand Down Expand Up @@ -118,7 +125,7 @@ export function createEvmNetwork(networkId: NetworkID): Network {
baseChainId: chainId,
currentChainId: currentChainId ?? chainId,
hasReceive: false,
supportsSimulation: ['eth', 'gor', 'sep', 'matic', 'arb1'].includes(networkId),
supportsSimulation: ['eth', 'gor', 'sep', 'oeth', 'matic', 'arb1'].includes(networkId),
managerConnectors: EVM_CONNECTORS,
actions: createActions(provider, helpers, chainId),
api,
Expand Down
14 changes: 12 additions & 2 deletions apps/ui/src/networks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,25 @@ const starknetTestnetNetwork = createStarknetNetwork('sn-tn');
const starknetSepoliaNetwork = createStarknetNetwork('sn-sep');
const polygonNetwork = createEvmNetwork('matic');
const arbitrumNetwork = createEvmNetwork('arb1');
const optimismNetwork = createEvmNetwork('oeth');
const ethereumNetwork = createEvmNetwork('eth');
const goerliNetwork = createEvmNetwork('gor');
const sepoliaNetwork = createEvmNetwork('sep');
const lineaTestnetNetwork = createEvmNetwork('linea-testnet');

export const enabledNetworks: NetworkID[] = import.meta.env.VITE_ENABLED_NETWORKS
? (import.meta.env.VITE_ENABLED_NETWORKS.split(',') as NetworkID[])
: ['s', 's-tn', 'eth', 'matic', 'arb1', 'gor', 'sep', 'sn', 'sn-sep'];
: ['s', 's-tn', 'eth', 'matic', 'arb1', 'oeth', 'gor', 'sep', 'sn', 'sn-sep'];

export const evmNetworks: NetworkID[] = ['eth', 'matic', 'arb1', 'gor', 'sep', 'linea-testnet'];
export const evmNetworks: NetworkID[] = [
'eth',
'matic',
'arb1',
'oeth',
'gor',
'sep',
'linea-testnet'
];
export const offchainNetworks: NetworkID[] = ['s', 's-tn'];

export const getNetwork = (id: NetworkID) => {
Expand All @@ -30,6 +39,7 @@ export const getNetwork = (id: NetworkID) => {
if (id === 's-tn') return snapshotTestnetNetwork;
if (id === 'matic') return polygonNetwork;
if (id === 'arb1') return arbitrumNetwork;
if (id === 'oeth') return optimismNetwork;
if (id === 'eth') return ethereumNetwork;
if (id === 'gor') return goerliNetwork;
if (id === 'sep') return sepoliaNetwork;
Expand Down
7 changes: 4 additions & 3 deletions apps/ui/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ export type NetworkID =
| 's'
| 's-tn'
| 'eth'
| 'matic'
| 'arb1'
| 'oeth'
| 'gor'
| 'sep'
| 'linea-testnet'
| 'sn'
| 'sn-tn'
| 'sn-sep'
| 'matic'
| 'arb1';
| 'sn-sep';

export type Choice = 'for' | 'against' | 'abstain' | number | number[] | Record<string, number>;

Expand Down
16 changes: 9 additions & 7 deletions packages/sx.js/src/evmNetworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function createStandardConfig(
};
}

function createStarknetConfig(networkId: keyof typeof evmNetworks): EvmNetworkConfig {
function createEvmConfig(networkId: keyof typeof evmNetworks): EvmNetworkConfig {
const network = evmNetworks[networkId];

const authenticators = {
Expand Down Expand Up @@ -94,6 +94,7 @@ function createStarknetConfig(networkId: keyof typeof evmNetworks): EvmNetworkCo
export const evmNetworks = {
eth: createStandardConfig(1),
gor: createStandardConfig(5),
oeth: createStandardConfig(10),
sep: createStandardConfig(11155111, {
strategies: {
Axiom: '0xaC6dbd42Ed254E9407fe0D2798784d0110979DC2',
Expand Down Expand Up @@ -130,9 +131,10 @@ export const evmNetworks = {
}
} as const;

export const evmMainnet = createStarknetConfig('eth');
export const evmGoerli = createStarknetConfig('gor');
export const evmSepolia = createStarknetConfig('sep');
export const evmPolygon = createStarknetConfig('matic');
export const evmArbitrum = createStarknetConfig('arb1');
export const evmLineaGoerli = createStarknetConfig('linea-testnet');
export const evmMainnet = createEvmConfig('eth');
export const evmGoerli = createEvmConfig('gor');
export const evmSepolia = createEvmConfig('sep');
export const evmOptimism = createEvmConfig('oeth');
export const evmPolygon = createEvmConfig('matic');
export const evmArbitrum = createEvmConfig('arb1');
export const evmLineaGoerli = createEvmConfig('linea-testnet');

0 comments on commit ca99550

Please sign in to comment.