Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add arbitrum network #44

Merged
merged 3 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,21 @@ That project requires [docker](https://docker.com) to be installed so the backen

### Configuration (Environment Variables)

> Supported Chains: 1, 11155111, 10, 11155420, 8453, 84532, 31337

| Variables | Default | Description |
| :-------------------------: | :--------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| `CHAIN_IDS` | `11155111` | Comma separated supported chain ids to be indexed |
| `RPC_URL_1` | `https://rpc.ankr.com/eth` | Endpoint for Mainnet RPC node |
| `RPC_URL_11155111` | `https://rpc.ankr.com/eth_sepolia` | Endpoint for Sepolia RPC node |
| `RPC_URL_31337` | `http://127.0.0.1:8545` | Endpoint for local node |
| `RPC_URL_10` | `https://mainnet.optimism.io` | Endpoint for Optimism Mainnet RPC node |
| `RPC_URL_11155420` | `https://sepolia.optimism.io` | Endpoint for Optimism Sepolia RPC node |
| `RPC_URL_8453` | `https://mainnet.base.org` | Endpoint for Base Mainnet RPC node |
| `RPC_URL_84532` | `https://sepolia.base.org` | Endpoint for Base Sepolia RPC node |
| `RPC_RATE_LIMIT_{CHAIN_ID}` | `undefined` | Option to fine tune concurrent requests by rate limiting the requests to RPC node providers. Replace {CHAIN_ID} with a supported chain id and set a Number e.g. 15. That is good to avoid [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) status code when using free tiers. The default is Full speed |
> Supported Chains: 1, 11155111, 10, 11155420, 8453, 84532, 42161, 421614, 31337

| Variables | Default | Description |
| :-------------------------: | :--------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| `CHAIN_IDS` | `31337` | Comma separated supported chain ids to be indexed |
| `RPC_URL_1` | `https://rpc.ankr.com/eth` | Endpoint for Mainnet RPC node |
| `RPC_URL_11155111` | `https://rpc.ankr.com/eth_sepolia` | Endpoint for Sepolia RPC node |
| `RPC_URL_31337` | `http://127.0.0.1:8545` | Endpoint for local node |
| `RPC_URL_10` | `https://mainnet.optimism.io` | Endpoint for Optimism Mainnet RPC node |
| `RPC_URL_11155420` | `https://sepolia.optimism.io` | Endpoint for Optimism Sepolia RPC node |
| `RPC_URL_8453` | `https://mainnet.base.org` | Endpoint for Base Mainnet RPC node |
| `RPC_URL_84532` | `https://sepolia.base.org` | Endpoint for Base Sepolia RPC node |
| `RPC_URL_42161` | `https://arb1.arbitrum.io/rpc` | Endpoint for Arbitrum RPC node |
| `RPC_URL_421614` | `https://sepolia-rollup.arbitrum.io/rpc` | Endpoint for Arbitrum Sepolia RPC node |
| `RPC_RATE_LIMIT_{CHAIN_ID}` | `undefined` | Option to fine tune concurrent requests by rate limiting the requests to RPC node providers. Replace {CHAIN_ID} with a supported chain id and set a Number e.g. 15. That is good to avoid [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) status code when using free tiers. The default is Full speed |

For use with local devnet for fine tunning and deal with any unexpected changes e.g. Foundry nightly versions.

Expand Down
85 changes: 70 additions & 15 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import CartesiDAppFactoryArbitrum from '@cartesi/rollups/deployments/arbitrum/CartesiDAppFactory.json';
import InputBoxArbitrum from '@cartesi/rollups/deployments/arbitrum/InputBox.json';
import CartesiDAppFactoryArbitrumSepolia from '@cartesi/rollups/deployments/arbitrum_sepolia/CartesiDAppFactory.json';
import InputBoxArbitrumSepolia from '@cartesi/rollups/deployments/arbitrum_sepolia/InputBox.json';
import CartesiDAppFactoryBase from '@cartesi/rollups/deployments/base/CartesiDAppFactory.json';
import inputBoxBase from '@cartesi/rollups/deployments/base/InputBox.json';
import CartesiDAppFactoryBaseSepolia from '@cartesi/rollups/deployments/base_sepolia/CartesiDAppFactory.json';
Expand All @@ -10,24 +14,35 @@ import CartesiDAppFactoryOptimismSepolia from '@cartesi/rollups/deployments/opti
import InputBoxOptimismSepolia from '@cartesi/rollups/deployments/optimism_sepolia/InputBox.json';
import CartesiDAppFactorySepolia from '@cartesi/rollups/deployments/sepolia/CartesiDAppFactory.json';
import InputBoxSepolia from '@cartesi/rollups/deployments/sepolia/InputBox.json';
import mainnet from '@cartesi/rollups/export/abi/mainnet.json';
import rollupsMainnet from '@cartesi/rollups/export/abi/mainnet.json';
import { GatewaySettings, RpcEndpointSettings } from '@subsquid/evm-processor';
import { base, baseSepolia, optimism, optimismSepolia } from 'viem/chains';
import {
arbitrum,
arbitrumSepolia,
base,
baseSepolia,
foundry,
mainnet,
optimism,
optimismSepolia,
sepolia,
} from 'viem/chains';
import { archiveNodes } from './gateways';
import { parseIntOr } from './utils';

// addresses are the same on all chains
export const CartesiDAppFactoryAddress =
mainnet.contracts.CartesiDAppFactory.address.toLowerCase();
rollupsMainnet.contracts.CartesiDAppFactory.address.toLowerCase();
export const ERC20PortalAddress =
mainnet.contracts.ERC20Portal.address.toLowerCase();
export const InputBoxAddress = mainnet.contracts.InputBox.address.toLowerCase();
rollupsMainnet.contracts.ERC20Portal.address.toLowerCase();
export const InputBoxAddress =
rollupsMainnet.contracts.InputBox.address.toLowerCase();
export const ERC721PortalAddress =
mainnet.contracts.ERC721Portal.address.toLowerCase();
rollupsMainnet.contracts.ERC721Portal.address.toLowerCase();
export const ERC1155SinglePortalAddress =
mainnet.contracts.ERC1155SinglePortal.address.toLowerCase();
rollupsMainnet.contracts.ERC1155SinglePortal.address.toLowerCase();
export const ERC1155BatchPortalAddress =
mainnet.contracts.ERC1155BatchPortal.address.toLowerCase();
rollupsMainnet.contracts.ERC1155BatchPortal.address.toLowerCase();
interface ArchiveDataSource {
archive: string | GatewaySettings;
rpcEndpoint?: string | RpcEndpointSettings;
Expand Down Expand Up @@ -59,7 +74,7 @@ export const getConfig = (chainId: number): ProcessorConfig => {
const rateLimit = parsedRateLimit <= 0 ? undefined : parsedRateLimit;

switch (chainId) {
case 1: // mainnet
case mainnet.id:
return {
dataSource: {
archive: archiveNodes.mainnet,
Expand All @@ -77,7 +92,7 @@ export const getConfig = (chainId: number): ProcessorConfig => {
value: process.env[BLOCK_CONFIRMATIONS],
}),
};
case 11155111: // sepolia
case sepolia.id:
return {
dataSource: {
archive: archiveNodes.sepolia,
Expand All @@ -97,7 +112,7 @@ export const getConfig = (chainId: number): ProcessorConfig => {
value: process.env[BLOCK_CONFIRMATIONS],
}),
};
case 10: //Optimism-Mainnet
case optimism.id:
return {
dataSource: {
archive: archiveNodes.optimism,
Expand All @@ -117,7 +132,7 @@ export const getConfig = (chainId: number): ProcessorConfig => {
value: process.env[BLOCK_CONFIRMATIONS],
}),
};
case 11155420: //Optimism-Sepolia
case optimismSepolia.id: //Optimism-Sepolia
return {
dataSource: {
archive: archiveNodes.optimismSepolia,
Expand All @@ -137,7 +152,7 @@ export const getConfig = (chainId: number): ProcessorConfig => {
value: process.env[BLOCK_CONFIRMATIONS],
}),
};
case 8453: //Base-Mainnet
case base.id:
return {
dataSource: {
archive: archiveNodes.base,
Expand All @@ -157,7 +172,7 @@ export const getConfig = (chainId: number): ProcessorConfig => {
value: process.env[BLOCK_CONFIRMATIONS],
}),
};
case 84532: //Base-Sepolia
case baseSepolia.id:
return {
dataSource: {
archive: archiveNodes.baseSepolia,
Expand All @@ -177,7 +192,47 @@ export const getConfig = (chainId: number): ProcessorConfig => {
value: process.env[BLOCK_CONFIRMATIONS],
}),
};
case 31337: // anvil
case arbitrum.id:
return {
dataSource: {
archive: archiveNodes.arbitrum,
rpcEndpoint: {
url:
process.env[RPC_URL] ??
arbitrum.rpcUrls.default.http[0],
rateLimit: rateLimit,
},
},
from: Math.min(
CartesiDAppFactoryArbitrum.receipt.blockNumber,
InputBoxArbitrum.receipt.blockNumber,
),
finalityConfirmation: parseIntOr({
defaultVal: FINALITY_CONFIRMATION,
value: process.env[BLOCK_CONFIRMATIONS],
}),
};
case arbitrumSepolia.id:
return {
dataSource: {
archive: archiveNodes.arbitrumSepolia,
rpcEndpoint: {
url:
process.env[RPC_URL] ??
arbitrumSepolia.rpcUrls.default.http[0],
rateLimit: rateLimit,
},
},
from: Math.min(
CartesiDAppFactoryArbitrumSepolia.receipt.blockNumber,
InputBoxArbitrumSepolia.receipt.blockNumber,
),
finalityConfirmation: parseIntOr({
defaultVal: FINALITY_CONFIRMATION,
value: process.env[BLOCK_CONFIRMATIONS],
}),
};
case foundry.id:
return {
dataSource: {
rpcEndpoint:
Expand Down
2 changes: 2 additions & 0 deletions src/gateways.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ export const archiveNodes = {
optimismSepolia: 'https://v2.archive.subsquid.io/network/optimism-sepolia',
mainnet: 'https://v2.archive.subsquid.io/network/ethereum-mainnet',
sepolia: 'https://v2.archive.subsquid.io/network/ethereum-sepolia',
arbitrum: 'https://v2.archive.subsquid.io/network/arbitrum-one',
arbitrumSepolia: 'https://v2.archive.subsquid.io/network/arbitrum-sepolia',
} as const;
4 changes: 4 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { existsSync, readFileSync } from 'node:fs';
import {
arbitrum,
arbitrumSepolia,
base,
baseSepolia,
foundry,
Expand Down Expand Up @@ -37,6 +39,8 @@ export const supportedChains = new Set<number>([
baseSepolia.id,
optimism.id,
optimismSepolia.id,
arbitrum.id,
arbitrumSepolia.id,
]);

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/gateways.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ describe('Gateways (Squid Archive Nodes)', () => {
'optimismSepolia',
'mainnet',
'sepolia',
'arbitrum',
'arbitrumSepolia',
]);
});

Expand All @@ -33,5 +35,13 @@ describe('Gateways (Squid Archive Nodes)', () => {
expect(archiveNodes.sepolia).toStrictEqual(
'https://v2.archive.subsquid.io/network/ethereum-sepolia',
);

expect(archiveNodes.arbitrum).toStrictEqual(
'https://v2.archive.subsquid.io/network/arbitrum-one',
);

expect(archiveNodes.arbitrumSepolia).toStrictEqual(
'https://v2.archive.subsquid.io/network/arbitrum-sepolia',
);
});
});
Loading
Loading