Skip to content

Commit

Permalink
feat: Add configuration for optimism-mainnet and optimism-sepolia. (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunomenezes authored May 23, 2024
1 parent 8e35940 commit 4de1702
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ CHAIN_ID="11155111"
# RPC_URL_1=
# RPC_URL_11155111=
# RPC_URL_31337=
# RPC_URL_10=
# RPC_URL_11155420=
# NORMALLY FOR USE WITH LOCAL/DEV
# GENESIS_BLOCK_31337=22
# BLOCK_CONFIRMATIONS_31337=1
39 changes: 39 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import CartesiDAppFactoryMainnet from '@cartesi/rollups/deployments/mainnet/CartesiDAppFactory.json';
import InputBoxMainnet from '@cartesi/rollups/deployments/mainnet/InputBox.json';
import CartesiDAppFactoryOptimism from '@cartesi/rollups/deployments/optimism/CartesiDAppFactory.json';
import InputBoxOptimism from '@cartesi/rollups/deployments/optimism/InputBox.json';
import CartesiDAppFactoryOptimismSepolia from '@cartesi/rollups/deployments/optimism_sepolia/CartesiDAppFactory.json';
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 { lookupArchive } from '@subsquid/archive-registry';
import { DataSource } from '@subsquid/evm-processor';
import { optimism, optimismSepolia } from 'viem/chains';

// addresses are the same on all chains
export const CartesiDAppFactoryAddress =
Expand Down Expand Up @@ -65,6 +70,40 @@ export const getConfig = (chainId: number): ProcessorConfig => {
value: process.env[BLOCK_CONFIRMATIONS],
}),
};
case 10: //Optimism-Mainnet
return {
dataSource: {
archive: lookupArchive('optimism-mainnet'),
chain:
process.env[RPC_URL] ??
optimism.rpcUrls.default.http[0],
},
from: Math.min(
CartesiDAppFactoryOptimism.receipt.blockNumber,
InputBoxOptimism.receipt.blockNumber,
),
finalityConfirmation: parseIntOr({
defaultVal: FINALITY_CONFIRMATION,
value: process.env[BLOCK_CONFIRMATIONS],
}),
};
case 11155420: //Optimism-Sepolia
return {
dataSource: {
archive: lookupArchive('optimism-sepolia'),
chain:
process.env[RPC_URL] ??
optimismSepolia.rpcUrls.default.http[0],
},
from: Math.min(
CartesiDAppFactoryOptimismSepolia.receipt.blockNumber,
InputBoxOptimismSepolia.receipt.blockNumber,
),
finalityConfirmation: parseIntOr({
defaultVal: FINALITY_CONFIRMATION,
value: process.env[BLOCK_CONFIRMATIONS],
}),
};
case 31337: // anvil
return {
dataSource: {
Expand Down
94 changes: 94 additions & 0 deletions tests/processor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ vi.mock('@subsquid/evm-processor', async () => {
const sepolia = 11155111;
const mainnet = 1;
const local = 31337;
const optimism = 10;
const optimismSepolia = 11155420;

describe('Processor creation', () => {
beforeEach(() => {
Expand Down Expand Up @@ -150,6 +152,98 @@ describe('Processor creation', () => {
});
});

test('Required configs for optimism', () => {
const processor = createProcessor(optimism);

expect(processor.setDataSource).toHaveBeenCalledWith({
archive: 'https://v2.archive.subsquid.io/network/optimism-mainnet',
chain: 'https://mainnet.optimism.io',
});

expect(processor.setFinalityConfirmation).toHaveBeenCalledWith(10);
expect(processor.setFields).toHaveBeenCalledWith({
transaction: {
chainId: true,
from: true,
hash: true,
value: true,
},
});
expect(processor.setBlockRange).toHaveBeenCalledWith({
from: 107432991,
});

const addLog = processor.addLog as unknown as MockInstance;

expect(addLog).toHaveBeenCalledTimes(3);
expect(addLog.mock.calls[0][0]).toEqual({
address: ['0x7122cd1221c20892234186facfe8615e6743ab02'],
topic0: [
'0xe73165c2d277daf8713fd08b40845cb6bb7a20b2b543f3d35324a475660fcebd',
],
});
expect(addLog.mock.calls[1][0]).toEqual({
address: ['0x59b22d57d4f067708ab0c00552767405926dc768'],
topic0: [
'0x6aaa400068bf4ca337265e2a1e1e841f66b8597fd5b452fdc52a44bed28a0784',
],
transaction: true,
});

expect(addLog.mock.calls[2][0]).toEqual({
topic0: [
'0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0',
],
transaction: true,
});
});

test('Required configs for optimism-sepolia', () => {
const processor = createProcessor(optimismSepolia);

expect(processor.setDataSource).toHaveBeenCalledWith({
archive: 'https://v2.archive.subsquid.io/network/optimism-sepolia',
chain: 'https://sepolia.optimism.io',
});

expect(processor.setFinalityConfirmation).toHaveBeenCalledWith(10);
expect(processor.setFields).toHaveBeenCalledWith({
transaction: {
chainId: true,
from: true,
hash: true,
value: true,
},
});
expect(processor.setBlockRange).toHaveBeenCalledWith({
from: 5393079,
});

const addLog = processor.addLog as unknown as MockInstance;

expect(addLog).toHaveBeenCalledTimes(3);
expect(addLog.mock.calls[0][0]).toEqual({
address: ['0x7122cd1221c20892234186facfe8615e6743ab02'],
topic0: [
'0xe73165c2d277daf8713fd08b40845cb6bb7a20b2b543f3d35324a475660fcebd',
],
});
expect(addLog.mock.calls[1][0]).toEqual({
address: ['0x59b22d57d4f067708ab0c00552767405926dc768'],
topic0: [
'0x6aaa400068bf4ca337265e2a1e1e841f66b8597fd5b452fdc52a44bed28a0784',
],
transaction: true,
});

expect(addLog.mock.calls[2][0]).toEqual({
topic0: [
'0x8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0',
],
transaction: true,
});
});

test('Required configs for mainnet', () => {
const processor = createProcessor(mainnet);
const applicationMetadata = loadApplications(mainnet);
Expand Down

0 comments on commit 4de1702

Please sign in to comment.