Skip to content

Commit

Permalink
Merge pull request #58 from Giveth/op-mainnet
Browse files Browse the repository at this point in the history
Optimism Mainnet config
  • Loading branch information
mateodaza authored Jun 3, 2024
2 parents be98141 + fd32917 commit cfbc586
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 24 deletions.
12 changes: 8 additions & 4 deletions .env.template
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ RPC_ENDPOINT=https://eth-sepolia.g.alchemy.com/v2/XXXXXXXXXXXXXXXXXXXXXXXXXX
# More info at https://docs.subsquid.io/basics/logging/
#SQD_DEBUG=*

EAS_CONTRACT_ADDRESS=0xC2679fBD37d54388Ce493F1DB75320D236e1815e
SCHEMA_CONTRACT_ADDRESS=0x0a7E2Ff54e76B8E6659aedc9103FB21c038050D0

PROJECT_VERIFY_ATTESTATION_SCHEMA=0x3D5854AF182F27966DEA837C446A051B3509224DDC03150E55097B362D111B1B
PROJECT_GIVBACK_ELIGIBLE_ATTESTATION_SCHEMA=0x0000000000000000000000000000000000000000000000000000000000000000
SQUID_NETWORK=optimism-mainnet

# MOVED TO CONSTANTS
# EAS_CONTRACT_ADDRESS=0xC2679fBD37d54388Ce493F1DB75320D236e1815e
# SCHEMA_CONTRACT_ADDRESS=0x0a7E2Ff54e76B8E6659aedc9103FB21c038050D0

# PROJECT_VERIFY_ATTESTATION_SCHEMA=0x3D5854AF182F27966DEA837C446A051B3509224DDC03150E55097B362D111B1B
# PROJECT_GIVBACK_ELIGIBLE_ATTESTATION_SCHEMA=0x0000000000000000000000000000000000000000000000000000000000000000

#APIs
GIVETH_API_URL=https://somewhere.giveth.io/XXXXX
Expand Down
1 change: 1 addition & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ GQL_PORT=4351
# Uncommenting this line enables the debug mode
# More info at https://docs.subsquid.io/basics/logging/
#SQD_DEBUG=*
SQUID_NETWORK=optimism-mainnet

EAS_CONTRACT_ADDRESS=0xC2679fBD37d54388Ce493F1DB75320D236e1815e
SCHEMA_CONTRACT_ADDRESS=0x0a7E2Ff54e76B8E6659aedc9103FB21c038050D0
Expand Down
5 changes: 5 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
src/db/migrations/
abi/
builds/
lib/
model/
4 changes: 4 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": false,
"trailingComma": "es5"
}
6 changes: 5 additions & 1 deletion add-organisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ const SCHEMA_ID =
"0xf63f2a7159ee674aa6fce42196a8bb0605eafcf20c19e91a7eafba8d39fa0404"; // Replace with your own schema id
const AUTHORIZED_ATTESTOR = "0x826976d7C600d45FB8287CA1d7c76FC8eb732030";
const COLOR = "#7f64cb";
// staging: eth-sepolia
// production: optimism-mainnet
const network = "eth-sepolia";

function main() {
createOrganisationAddMigration(
ORGANISATION_NAME,
SCHEMA_ID,
AUTHORIZED_ATTESTOR,
COLOR
COLOR,
network
);
}

Expand Down
4 changes: 2 additions & 2 deletions assets/README.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# Assets
# Assets

`assets` is the designated folder for any additional files to be used by the squid, for example a static data file. The folder is added by default to `Dockerfile` and is kept when the squid is deployed to the Aquairum.
`assets` is the designated folder for any additional files to be used by the squid, for example a static data file. The folder is added by default to `Dockerfile` and is kept when the squid is deployed to the Aquairum.
14 changes: 9 additions & 5 deletions db/create-organisation-add-migration.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@ exports.default = function createOrganisationAddMigration(
organisationName,
schemaId,
authorizedAttestor,
color = null
color = null,
network = "eth-sepolia"
) {
const timestamp = new Date().getTime() + ADD_ORG_MIGRATION_OFFSET;
const fileName = `${timestamp}-Add${organisationName}.js`;
const className = `Add${organisationName.replace(/ /g, "")}${timestamp}`;

// create ./migrations/${fileName}
fs.writeFileSync(
__dirname + "/migrations/" + fileName,
`
module.exports = class ${className} {
`${__dirname}/migrations/${fileName}`,
`module.exports = class ${className} {
name = "${className}";
async up(db) {
const SQUID_NETWORK = process.env.SQUID_NETWORK || "eth-sepolia";
if (SQUID_NETWORK !== "${network}") return;
// add organisation with name "${organisationName}" and schema id "${schemaId}"
await db.query(
\`INSERT INTO "organisation" ("id", "name", "issuer", "color")
Expand All @@ -34,6 +36,8 @@ module.exports = class ${className} {
}
async down(db) {
const SQUID_NETWORK = process.env.SQUID_NETWORK || "eth-sepolia";
if (SQUID_NETWORK !== "${network}") return;
// remove organisation with name "${organisationName}" and schema id "${schemaId}"
await db.query(
\`DELETE FROM "organisation" WHERE "id" = '${schemaId.toLocaleLowerCase()}'\`
Expand Down
4 changes: 4 additions & 0 deletions db/migrations/1725254645149-AddTrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module.exports = class AddTrace1725254645149 {
name = "AddTrace1725254645149";

async up(db) {
const SQUID_NETWORK = process.env.SQUID_NETWORK || "eth-sepolia";
if (SQUID_NETWORK !== "eth-sepolia") return;
// add organisation with name "Trace" and schema id "0x2e22df9a11e06c306ed8f64ca45ceae02efcf8a443371395a78371bc4fb6f722"
await db.query(
`INSERT INTO "organisation" ("id", "name", "issuer", "color")
Expand All @@ -15,6 +17,8 @@ module.exports = class AddTrace1725254645149 {
}

async down(db) {
const SQUID_NETWORK = process.env.SQUID_NETWORK || "eth-sepolia";
if (SQUID_NETWORK !== "eth-sepolia") return;
// remove organisation with name "Trace" and schema id "0x2e22df9a11e06c306ed8f64ca45ceae02efcf8a443371395a78371bc4fb6f722"
await db.query(
`DELETE FROM "organisation" WHERE "id" = '0x2e22df9a11e06c306ed8f64ca45ceae02efcf8a443371395a78371bc4fb6f722'`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module.exports = class AddGivethVerificationTeam1725344741698 {
name = "AddGivethVerificationTeam1725344741698";
module.exports = class AddGivethVerificationTeam1727410589775 {
name = "AddGivethVerificationTeam1727410589775";

async up(db) {
const SQUID_NETWORK = process.env.SQUID_NETWORK || "eth-sepolia";
if (SQUID_NETWORK !== "eth-sepolia") return;
// add organisation with name "Giveth Verification Team" and schema id "0xf63f2a7159ee674aa6fce42196a8bb0605eafcf20c19e91a7eafba8d39fa0404"
await db.query(
`INSERT INTO "organisation" ("id", "name", "issuer", "color")
Expand All @@ -15,6 +17,8 @@ module.exports = class AddGivethVerificationTeam1725344741698 {
}

async down(db) {
const SQUID_NETWORK = process.env.SQUID_NETWORK || "eth-sepolia";
if (SQUID_NETWORK !== "eth-sepolia") return;
// remove organisation with name "Giveth Verification Team" and schema id "0xf63f2a7159ee674aa6fce42196a8bb0605eafcf20c19e91a7eafba8d39fa0404"
await db.query(
`DELETE FROM "organisation" WHERE "id" = '0xf63f2a7159ee674aa6fce42196a8bb0605eafcf20c19e91a7eafba8d39fa0404'`
Expand Down
20 changes: 18 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"name": "squid-evm-template",
"name": "devouch-squid-backend",
"private": true,
"scripts": {
"build": "rm -rf lib && tsc",
"prettier:write": "prettier --write **/*.ts",
"test:run-migration": "dotenvx run --env-file=.env.test -- squid-typeorm-migration apply",
"test:run-fresh-db": "docker-compose -f docker-compose-potgres-test.yml down -v; docker-compose --env-file .env.test -f docker-compose-potgres-test.yml up -d",
"test": "npm run test:run-fresh-db; dotenvx run --env-file=.env.test -- jest --runInBand",
Expand Down Expand Up @@ -33,6 +34,7 @@
"@types/node": "^20.11.17",
"@types/node-cron": "^3.0.11",
"jest": "^29.7.0",
"prettier": "^3.3.0",
"ts-jest": "^29.1.2",
"ts-node": "^10.9.2",
"typescript": "~5.3.3"
Expand Down
20 changes: 17 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import { assertNotNull } from "@subsquid/evm-processor";

const SQUID_NETWORK = process.env.SQUID_NETWORK || "eth-sepolia";

const IS_PRODUCTION = SQUID_NETWORK === "optimism-mainnet";

export const EAS_CONTRACT_ADDRESS = assertNotNull(
process.env.EAS_CONTRACT_ADDRESS
IS_PRODUCTION
? "0x4200000000000000000000000000000000000021"
: "0xC2679fBD37d54388Ce493F1DB75320D236e1815e"
);
export const SCHEMA_CONTRACT_ADDRESS = assertNotNull(
process.env.SCHEMA_CONTRACT_ADDRESS
IS_PRODUCTION
? "0x4200000000000000000000000000000000000020"
: "0x0a7E2Ff54e76B8E6659aedc9103FB21c038050D0"
);

export const PROJECT_VERIFY_SCHEMA = assertNotNull(
process.env.PROJECT_VERIFY_ATTESTATION_SCHEMA
).toLocaleLowerCase();

export const START_BLOCK = parseInt(process.env.START_BLOCK || "5815457");
export const LOOKUP_ARCHIVE = IS_PRODUCTION
? "https://v2.archive.subsquid.io/network/optimism-mainnet"
: "https://v2.archive.subsquid.io/network/ethereum-sepolia";

export const START_BLOCK = Number.parseInt(
process.env.START_BLOCK || (IS_PRODUCTION ? "119837389" : "5815457")
);

export const IMPORT_PROJECT_CRON_SCHEDULE =
process.env.IMPORT_PROJECT_CRON_SCHEDULE || "0 0 * * *"; // UTC
1 change: 0 additions & 1 deletion src/features/import-projects/rpgf/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { getDataSource } from "../../../helpers/db";
import { updateOrCreateProject } from "../helpers";
import { rpgf3SourceConfig } from "./constants";
import { fetchRpgf3Projects } from "./service";
Expand Down
5 changes: 2 additions & 3 deletions src/processor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { assertNotNull } from "@subsquid/util-internal";
import { lookupArchive } from "@subsquid/archive-registry";
import {
BlockHeader,
DataHandlerContext,
Expand All @@ -10,12 +9,12 @@ import {
} from "@subsquid/evm-processor";

import * as EASContract from "./abi/EAS";
import { EAS_CONTRACT_ADDRESS, START_BLOCK } from "./constants";
import { EAS_CONTRACT_ADDRESS, LOOKUP_ARCHIVE, START_BLOCK } from "./constants";

export const processor = new EvmBatchProcessor()
// Lookup archive by the network name in Subsquid registry
// See https://docs.subsquid.io/evm-indexing/supported-networks/
.setGateway(lookupArchive("eth-sepolia"))
.setGateway(LOOKUP_ARCHIVE)
// Chain RPC endpoint is required for
// - indexing unfinalized blocks https://docs.subsquid.io/basics/unfinalized-blocks/
// - querying the contract state https://docs.subsquid.io/evm-indexing/query-state/
Expand Down

0 comments on commit cfbc586

Please sign in to comment.