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

feat: index both mainnet and sepolia #1092

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
94 changes: 0 additions & 94 deletions apps/api/src/config.json

This file was deleted.

164 changes: 164 additions & 0 deletions apps/api/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
import { CheckpointConfig } from '@snapshot-labs/checkpoint';
import { starknetNetworks } from '@snapshot-labs/sx';
import { validateAndParseAddress } from 'starknet';
import spaceAbi from './abis/space.json';
import spaceFactoryAbi from './abis/spaceFactory.json';

export type FullConfig = {
indexerName: 'sn' | 'sn-sep';
overrides: ReturnType<typeof createOverrides>;
} & CheckpointConfig;

const CONFIG = {
sn: {
indexerName: 'sn',
networkNodeUrl:
'https://starknet-mainnet.infura.io/v3/46a5dd9727bf48d4a132672d3f376146',
l1NetworkNodeUrl: 'https://rpc.brovider.xyz/1',
contract: starknetNetworks['sn'].Meta.spaceFactory,
start: 445498,
verifiedSpaces: [
'0x009fedaf0d7a480d21a27683b0965c0f8ded35b3f1cac39827a25a06a8a682a4',
'0x05ea5ef0c54c84dc7382629684c6e536c0b06246b3b0981c426b42372e3ef263',
'0x07c251045154318a2376a3bb65be47d3c90df1740d8e35c9b9d943aa3f240e50',
'0x07bd3419669f9f0cc8f19e9e2457089cdd4804a4c41a5729ee9c7fd02ab8ab62'
]
},
'sn-sep': {
indexerName: 'sn-sep',
networkNodeUrl:
'https://starknet-sepolia.infura.io/v3/46a5dd9727bf48d4a132672d3f376146',
l1NetworkNodeUrl: 'https://rpc.brovider.xyz/11155111',
contract: starknetNetworks['sn-sep'].Meta.spaceFactory,
start: 17960,
verifiedSpaces: [
'0x0141464688e48ae5b7c83045edb10ecc242ce0e1ad4ff44aca3402f7f47c1ab9'
]
}
};

const manaRpcUrl = process.env.VITE_MANA_URL || 'https://mana.box';

function createOverrides(networkId: keyof typeof CONFIG) {
const config = starknetNetworks[networkId];

return {
networkNodeUrl: CONFIG[networkId].networkNodeUrl,
l1NetworkNodeUrl: CONFIG[networkId].l1NetworkNodeUrl,
manaRpcUrl: `${manaRpcUrl}/stark_rpc/${config.Meta.eip712ChainId}`,
baseChainId: config.Meta.herodotusAccumulatesChainId,
erc20VotesStrategy: config.Strategies.ERC20Votes,
propositionPowerValidationStrategyAddress:
config.ProposalValidations.VotingPower,
spaceClassHash: config.Meta.masterSpace,
verifiedSpaces: CONFIG[networkId].verifiedSpaces,
herodotusStrategies: [
config.Strategies.OZVotesStorageProof,
config.Strategies.OZVotesTrace208StorageProof,
config.Strategies.EVMSlotValue
]
.filter(address => !!address)
.map(strategy => validateAndParseAddress(strategy))
};
}

export function createConfig(indexerName: keyof typeof CONFIG): FullConfig {
const { networkNodeUrl, contract, start } = CONFIG[indexerName];

const overrides = createOverrides(indexerName);

return {
indexerName,
overrides,
network_node_url: networkNodeUrl,
optimistic_indexing: true,
sources: [
{
contract,
start,
abi: 'SpaceFactory',
events: [
{
name: 'NewContractDeployed',
fn: 'handleContractDeployed'
}
]
}
],
templates: {
Space: {
abi: 'Space',
events: [
{
name: 'SpaceCreated',
fn: 'handleSpaceCreated'
},
{
name: 'ProposalCreated',
fn: 'handlePropose'
},
{
name: 'ProposalCancelled',
fn: 'handleCancel'
},
{
name: 'ProposalUpdated',
fn: 'handleUpdate'
},
{
name: 'ProposalExecuted',
fn: 'handleExecute'
},
{
name: 'VoteCast',
fn: 'handleVote'
},
{
name: 'MetadataUriUpdated',
fn: 'handleMetadataUriUpdated'
},
{
name: 'MinVotingDurationUpdated',
fn: 'handleMinVotingDurationUpdated'
},
{
name: 'MaxVotingDurationUpdated',
fn: 'handleMaxVotingDurationUpdated'
},
{
name: 'VotingDelayUpdated',
fn: 'handleVotingDelayUpdated'
},
{
name: 'OwnershipTransferred',
fn: 'handleOwnershipTransferred'
},
{
name: 'AuthenticatorsAdded',
fn: 'handleAuthenticatorsAdded'
},
{
name: 'AuthenticatorsRemoved',
fn: 'handleAuthenticatorsRemoved'
},
{
name: 'VotingStrategiesAdded',
fn: 'handleVotingStrategiesAdded'
},
{
name: 'VotingStrategiesRemoved',
fn: 'handleVotingStrategiesRemoved'
},
{
name: 'ProposalValidationStrategyUpdated',
fn: 'handleProposalValidationStrategyUpdated'
}
]
}
},
abis: {
SpaceFactory: spaceFactoryAbi,
Space: spaceAbi
}
};
}
16 changes: 0 additions & 16 deletions apps/api/src/currentConfig.ts

This file was deleted.

27 changes: 16 additions & 11 deletions apps/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ import Checkpoint, {
LogLevel,
starknet
} from '@snapshot-labs/checkpoint';
import spaceAbi from './abis/space.json';
import spaceFactoryAbi from './abis/spaceFactory.json';
import config from './currentConfig';
import * as writer from './writer';
import { createConfig } from './config';
import overrides from './overrides.json';
import { createWriters } from './writer';

const dir = __dirname.endsWith('dist/src') ? '../' : '';
const schemaFile = path.join(__dirname, `${dir}../src/schema.gql`);
Expand All @@ -25,17 +24,22 @@ if (process.env.CA_CERT) {
process.env.CA_CERT = process.env.CA_CERT.replace(/\\n/g, '\n');
}

const indexer = new starknet.StarknetIndexer(writer);
const checkpoint = new Checkpoint(config, indexer, schema, {
const snConfig = createConfig('sn');
const snSepConfig = createConfig('sn-sep');

const snIndexer = new starknet.StarknetIndexer(createWriters(snConfig));
const snSepIndexer = new starknet.StarknetIndexer(createWriters(snSepConfig));

const checkpoint = new Checkpoint(schema, {
logLevel: LogLevel.Info,
resetOnConfigChange: true,
prettifyLogs: process.env.NODE_ENV !== 'production',
abis: {
SpaceFactory: spaceFactoryAbi,
Space: spaceAbi
}
overridesConfig: overrides
});

checkpoint.addIndexer(snConfig.indexerName, snConfig, snIndexer);
checkpoint.addIndexer(snSepConfig.indexerName, snSepConfig, snSepIndexer);

const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

async function run() {
Expand Down Expand Up @@ -65,7 +69,8 @@ async function run() {
await sleep(PRODUCTION_INDEXER_DELAY);
}

// await checkpoint.reset();
await checkpoint.resetMetadata();
await checkpoint.reset();
checkpoint.start();
}

Expand Down
Loading
Loading