diff --git a/.env.template b/.env.template index 7957e45..e46be72 100644 --- a/.env.template +++ b/.env.template @@ -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 diff --git a/.env.test b/.env.test index 093bc5d..05d3fdd 100644 --- a/.env.test +++ b/.env.test @@ -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 diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..ae39030 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,5 @@ +src/db/migrations/ +abi/ +builds/ +lib/ +model/ \ No newline at end of file diff --git a/.prettierrc.json b/.prettierrc.json new file mode 100644 index 0000000..7197da8 --- /dev/null +++ b/.prettierrc.json @@ -0,0 +1,4 @@ +{ + "singleQuote": false, + "trailingComma": "es5" +} diff --git a/add-organisation.js b/add-organisation.js index 26bd405..4517d57 100644 --- a/add-organisation.js +++ b/add-organisation.js @@ -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 ); } diff --git a/assets/README.MD b/assets/README.MD index 23a55ab..b5e5a27 100644 --- a/assets/README.MD +++ b/assets/README.MD @@ -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. \ No newline at end of file +`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. diff --git a/db/create-organisation-add-migration.js b/db/create-organisation-add-migration.js index a9fee93..28926cb 100644 --- a/db/create-organisation-add-migration.js +++ b/db/create-organisation-add-migration.js @@ -7,7 +7,8 @@ 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`; @@ -15,12 +16,13 @@ exports.default = function createOrganisationAddMigration( // 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") @@ -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()}'\` diff --git a/db/migrations/1725254645149-AddTrace.js b/db/migrations/1725254645149-AddTrace.js index a81539b..5920b74 100644 --- a/db/migrations/1725254645149-AddTrace.js +++ b/db/migrations/1725254645149-AddTrace.js @@ -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") @@ -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'` diff --git a/db/migrations/1725344741698-AddGiveth Verification Team.js b/db/migrations/1727410589775-AddGiveth Verification Team.js similarity index 69% rename from db/migrations/1725344741698-AddGiveth Verification Team.js rename to db/migrations/1727410589775-AddGiveth Verification Team.js index 7e1148b..50c3f95 100644 --- a/db/migrations/1725344741698-AddGiveth Verification Team.js +++ b/db/migrations/1727410589775-AddGiveth Verification Team.js @@ -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") @@ -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'` diff --git a/package-lock.json b/package-lock.json index 310a5b2..46c7fe7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,10 +1,10 @@ { - "name": "squid-evm-template", + "name": "devouch-squid-backend", "lockfileVersion": 3, "requires": true, "packages": { "": { - "name": "squid-evm-template", + "name": "devouch-squid-backend", "dependencies": { "@ethereum-attestation-service/eas-sdk": "^1.5.0", "@subsquid/archive-registry": "^3.3.2", @@ -28,6 +28,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" @@ -10727,6 +10728,21 @@ "node": ">=0.10.0" } }, + "node_modules/prettier": { + "version": "3.3.0", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.0.tgz", + "integrity": "sha512-J9odKxERhCQ10OC2yb93583f6UnYutOeiV5i0zEDS7UGTdUt0u+y8erxl3lBKvwo/JHyyoEdXjwp4dke9oyZ/g==", + "dev": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", diff --git a/package.json b/package.json index 6a21468..6d3fc96 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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" diff --git a/src/constants.ts b/src/constants.ts index 9436bf9..453453f 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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 diff --git a/src/features/import-projects/rpgf/index.ts b/src/features/import-projects/rpgf/index.ts index 4e58cd1..e12bdf1 100644 --- a/src/features/import-projects/rpgf/index.ts +++ b/src/features/import-projects/rpgf/index.ts @@ -1,4 +1,3 @@ -import { getDataSource } from "../../../helpers/db"; import { updateOrCreateProject } from "../helpers"; import { rpgf3SourceConfig } from "./constants"; import { fetchRpgf3Projects } from "./service"; diff --git a/src/processor.ts b/src/processor.ts index ce29bbc..7fd0b6a 100644 --- a/src/processor.ts +++ b/src/processor.ts @@ -1,5 +1,4 @@ import { assertNotNull } from "@subsquid/util-internal"; -import { lookupArchive } from "@subsquid/archive-registry"; import { BlockHeader, DataHandlerContext, @@ -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/