diff --git a/.gitignore b/.gitignore index 27e7b7c478..11a35e86bd 100644 --- a/.gitignore +++ b/.gitignore @@ -69,6 +69,9 @@ packages/boba/gateway/public/env.js /packages/boba/subgraph/L2/build /packages/boba/subgraph/L1/generated /packages/boba/subgraph/L2/generated +/packages/boba/subgraph/L1/rollup/generated +/packages/boba/subgraph/L1/rollup/subgraph.yaml +/packages/boba/subgraph/L1/rollup/yarn.lock # api env-mainnet.yml @@ -81,3 +84,4 @@ packages/boba/contracts/coverage/ packages/boba/account-abstraction/deployments/hardhat/ packages/boba/bundler_sdk/coverage/ + diff --git a/packages/boba/subgraph/L1/rollup/config/bobaavax.json b/packages/boba/subgraph/L1/rollup/config/bobaavax.json deleted file mode 100644 index e862b5653e..0000000000 --- a/packages/boba/subgraph/L1/rollup/config/bobaavax.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "network": "avalanche", - "contracts": { - "L1CrossDomainMessenger": { - "address": "0x0fc742332ae6D447d6619D93985Aa288B81CBb0C", - "startBlock": 19286932 - }, - "L1CrossDomainMessengerFast": { - "address": "0x5b6714b7926e6D7e34154C9AC945B489978fA7E7", - "startBlock": 19286932 - }, - "StateCommitmentChain": { - "address": "0x1ef85D873Cf451C8B9a45DbE40b478E991F51210", - "startBlock": 19286932 - }, - "Lib_AddressManager": { - "address": "0x00220f8ce1c4be8436574e575fE38558d85e2E6b", - "startBlock": 19286932 - } - } -} diff --git a/packages/boba/subgraph/L1/rollup/config/bobabase.json b/packages/boba/subgraph/L1/rollup/config/bobabase.json deleted file mode 100644 index f4bbc467a7..0000000000 --- a/packages/boba/subgraph/L1/rollup/config/bobabase.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "network": "mbase", - "contracts": { - "L1CrossDomainMessenger": { - "address": "0x76DB375075F1d5Dcd1D70Fc07F69a5c7b40ab877", - "startBlock": 2798105 - }, - "L1CrossDomainMessengerFast": { - "address": "0xAE8885D3b7937af9480cd7301925a88Dfb0cE9f6", - "startBlock": 2798105 - }, - "StateCommitmentChain": { - "address": "0x5E41Eaac5319CDf336c51969E2F164A686138B28", - "startBlock": 2798105 - }, - "Lib_AddressManager": { - "address": "0xF8d0bF3a1411AC973A606f90B2d1ee0840e5979B", - "startBlock": 2103466 - } - } -} diff --git a/packages/boba/subgraph/L1/rollup/config/bobabeam.json b/packages/boba/subgraph/L1/rollup/config/bobabeam.json deleted file mode 100644 index 64d0288352..0000000000 --- a/packages/boba/subgraph/L1/rollup/config/bobabeam.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "network": "moonbeam", - "contracts": { - "L1CrossDomainMessenger": { - "address": "0x4765f8b50Bbe049045bBA1270dc7A8CDF17165cF", - "startBlock": 1687872 - }, - "L1CrossDomainMessengerFast": { - "address": "0x17d02C3e6cB69225d83d0bADEb0fC09aE735CA3b", - "startBlock": 1687872 - }, - "StateCommitmentChain": { - "address": "0xAD379B1518f50Fc737536D2Ec2c13E4640e228A8", - "startBlock": 1687872 - }, - "Lib_AddressManager": { - "address": "0x564c10A60af35a07f0EA8Be3106a4D81014b21a0", - "startBlock": 1687872 - } - } -} diff --git a/packages/boba/subgraph/L1/rollup/config/bobaopera.json b/packages/boba/subgraph/L1/rollup/config/bobaopera.json deleted file mode 100644 index bd64b421ce..0000000000 --- a/packages/boba/subgraph/L1/rollup/config/bobaopera.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "network": "fantom", - "contracts": { - "L1CrossDomainMessenger": { - "address": "0x64Fca36c52628e40de8684C4C3B5EdB22Fd2eFd9", - "startBlock": 47969835 - }, - "L1CrossDomainMessengerFast": { - "address": "0xC0597ED18446254E4dd0CA5D80eb07D3f2E462cF", - "startBlock": 47969835 - }, - "StateCommitmentChain": { - "address": "0xF764C4f8D2982432239A110Cf6B08e95631cE564", - "startBlock": 47969835 - }, - "Lib_AddressManager": { - "address": "0x4e7325bcf09e091Bb8119258B885D4ef687B7386", - "startBlock": 47969835 - } - } -} diff --git a/packages/boba/subgraph/L1/rollup/config/bobaoperatestnet.json b/packages/boba/subgraph/L1/rollup/config/bobaoperatestnet.json deleted file mode 100644 index ff079de294..0000000000 --- a/packages/boba/subgraph/L1/rollup/config/bobaoperatestnet.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "network": "fantom-testnet", - "contracts": { - "L1CrossDomainMessenger": { - "address": "0xEecAD665ca933eeA4a9a2db600E538c1391930d1", - "startBlock": 9371687 - }, - "L1CrossDomainMessengerFast": { - "address": "0xE5781E5E9CbC67E91DF93eD01E922De30125e491", - "startBlock": 9371687 - }, - "StateCommitmentChain": { - "address": "0x352d964E9aD016f122dc78Afa5164417907E0FaF", - "startBlock": 9371674 - }, - "Lib_AddressManager": { - "address": "0x12ad9f501149D3FDd703cC10c567F416B7F0af8b", - "startBlock": 9371642 - } - } -} diff --git a/packages/boba/subgraph/L1/rollup/config/fuji.json b/packages/boba/subgraph/L1/rollup/config/fuji.json deleted file mode 100644 index 4e02897730..0000000000 --- a/packages/boba/subgraph/L1/rollup/config/fuji.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "network": "fuji", - "contracts": { - "L1CrossDomainMessenger": { - "address": "0x68c19B7FbAe4F8034cf6316b2045ba6aB6978F6b", - "startBlock": 11967644 - }, - "L1CrossDomainMessengerFast": { - "address": "0xBc5249095c890F58C0b75795bd21667eFd123F5F", - "startBlock": 11967644 - }, - "StateCommitmentChain": { - "address": "0x57B9C47F2Ae857005238096486C5B107447dE221", - "startBlock": 11967644 - }, - "Lib_AddressManager": { - "address": "0xcE78de95b85212BC348452e91e0e74c17cf37c79", - "startBlock": 11967644 - } - } -} diff --git a/packages/boba/subgraph/L1/rollup/package.json b/packages/boba/subgraph/L1/rollup/package.json index 675c5cfc40..65b5532623 100644 --- a/packages/boba/subgraph/L1/rollup/package.json +++ b/packages/boba/subgraph/L1/rollup/package.json @@ -4,41 +4,13 @@ "scripts": { "codegen": "graph codegen", "build": "graph build", - "prepare:bobabase:rollup": "mustache config/bobabase.json subgraph.template.rollup.yaml > subgraph.yaml", - "prepare:bobabeam:rollup": "mustache config/bobabeam.json subgraph.template.rollup.yaml > subgraph.yaml", - "prepare:bobaoperatestnet:rollup": "mustache config/bobaoperatestnet.json subgraph.template.rollup.yaml > subgraph.yaml", - "prepare:bobaopera:rollup": "mustache config/bobaopera.json subgraph.template.rollup.yaml > subgraph.yaml", - "prepare:fuji:rollup": "mustache config/fuji.json subgraph.template.rollup.yaml > subgraph.yaml", - "prepare:bobaavax:rollup": "mustache config/bobaavax.json subgraph.template.rollup.yaml > subgraph.yaml", "prepare:bobabnbtestnet:rollup": "mustache config/bobabnbtestnet.json subgraph.template.rollup.yaml > subgraph.yaml", "prepare:bobabnb:rollup": "mustache config/bobabnb.json subgraph.template.rollup.yaml > subgraph.yaml", - "prepare:bobabase:addressManager": "mustache config/bobabase.json subgraph.template.addressManager.yaml > subgraph.yaml", - "prepare:bobabeam:addressManager": "mustache config/bobabeam.json subgraph.template.addressManager.yaml > subgraph.yaml", - "prepare:bobaoperatestnet:addressManager": "mustache config/bobaoperatestnet.json subgraph.template.addressManager.yaml > subgraph.yaml", - "prepare:bobaopera:addressManager": "mustache config/bobaopera.json subgraph.template.addressManager.yaml > subgraph.yaml", - "prepare:fuji:addressManager": "mustache config/fuji.json subgraph.template.addressManager.yaml > subgraph.yaml", - "prepare:bobaavax:addressManager": "mustache config/bobaavax.json subgraph.template.addressManager.yaml > subgraph.yaml", - "prepare:bobabnbtestnet:addressManager": "mustache config/bobabnbtestnet.json subgraph.template.addressManager.yaml > subgraph.yaml", - "prepare:bobabnb:addressManager": "mustache config/bobabnb.json subgraph.template.addressManager.yaml > subgraph.yaml", - "deploy:subgraph:bobabase:rollup": "graph deploy --product hosted-service bobanetwork/bobabase-rollup", - "deploy:subgraph:bobabeam:rollup": "graph deploy --product hosted-service bobanetwork/bobabeam-rollup", - "deploy:subgraph:bobabnbtestnet:rollup": "graph deploy --product hosted-service bobanetwork/bobabnb-tn-rollup", - "deploy:subgraph:bobabnb:rollup": "graph deploy --product hosted-service bobanetwork/bobabnb-rollup", - "deploy:subgraph:bobaoperatestnet:rollup": "graph deploy --product hosted-service bobanetwork/bobaopera-tn-rollup", - "deploy:subgraph:bobaopera:rollup": "graph deploy --product hosted-service bobanetwork/bobaopera-rollup", - "deploy:subgraph:fuji:rollup": "graph deploy --product hosted-service bobanetwork/bobafuji-rollup", - "deploy:subgraph:bobaavax:rollup": "graph deploy --product hosted-service bobanetwork/bobaavax-rollup", - "deploy:subgraph:bobabase:addressManager": "graph deploy --product hosted-service bobanetwork/bobabase-address-manager", - "deploy:subgraph:bobabeam:addressManager": "graph deploy --product hosted-service bobanetwork/bobabeam-address-manager", - "deploy:subgraph:bobaoperatestnet:addressManager": "graph deploy --product hosted-service bobanetwork/bobaopera-tn-address-manager", - "deploy:subgraph:bobaopera:addressManager": "graph deploy --product hosted-service bobanetwork/bobaopera-address-manager", - "deploy:subgraph:fuji:addressManager": "graph deploy --product hosted-service bobanetwork/bobafuji-address-manager", - "deploy:subgraph:bobaavax:addressManager": "graph deploy --product hosted-service bobanetwork/bobaavax-address-manager", - "deploy:subgraph:bobabnbtestnet:addressManager": "graph deploy --product hosted-service bobanetwork/bobabnb-tn-address-manager", - "deploy:subgraph:bobabnb:addressManager": "graph deploy --product hosted-service bobanetwork/bobabnb-address-manager" + "deploy:subgraph:bobabnbtestnet:rollup": "graph deploy --studio boba-bnb-testnet-rollup", + "deploy:subgraph:bobabnb:rollup": "graph deploy --studio boba-bnb-rollup" }, "devDependencies": { - "@graphprotocol/graph-cli": "^0.29.0", + "@graphprotocol/graph-cli": "0.71.2", "@graphprotocol/graph-ts": "^0.26.0" }, "dependencies": { diff --git a/packages/boba/subgraph/L1/rollup/subgraph.template.addressManager.yaml b/packages/boba/subgraph/L1/rollup/subgraph.template.addressManager.yaml deleted file mode 100644 index f2e49ede38..0000000000 --- a/packages/boba/subgraph/L1/rollup/subgraph.template.addressManager.yaml +++ /dev/null @@ -1,24 +0,0 @@ -specVersion: 0.0.2 -schema: - file: ./schema.graphql -dataSources: - - kind: ethereum - name: Lib_AddressManager - network: {{network}} - source: - address: '{{contracts.Lib_AddressManager.address}}' - abi: Lib_AddressManager - startBlock: {{ contracts.Lib_AddressManager.startBlock }} - mapping: - kind: ethereum/events - apiVersion: 0.0.5 - language: wasm/assemblyscript - entities: - - Lib_AddressManager - abis: - - name: Lib_AddressManager - file: ./abis/Lib_AddressManager.json - eventHandlers: - - event: AddressSet(indexed string,address,address) - handler: handleAddressSet - file: ./src/Lib_AddressManagermapping.ts diff --git a/packages/boba/subgraph/L1/rollup/subgraph.template.rollup.yaml b/packages/boba/subgraph/L1/rollup/subgraph.template.rollup.yaml index c60da2f99b..24bd51c579 100644 --- a/packages/boba/subgraph/L1/rollup/subgraph.template.rollup.yaml +++ b/packages/boba/subgraph/L1/rollup/subgraph.template.rollup.yaml @@ -2,6 +2,26 @@ specVersion: 0.0.2 schema: file: ./schema.graphql dataSources: + - kind: ethereum + name: Lib_AddressManager + network: {{network}} + source: + address: '{{contracts.Lib_AddressManager.address}}' + abi: Lib_AddressManager + startBlock: {{ contracts.Lib_AddressManager.startBlock }} + mapping: + kind: ethereum/events + apiVersion: 0.0.5 + language: wasm/assemblyscript + entities: + - Lib_AddressManager + abis: + - name: Lib_AddressManager + file: ./abis/Lib_AddressManager.json + eventHandlers: + - event: AddressSet(indexed string,address,address) + handler: handleAddressSet + file: ./src/Lib_AddressManagermapping.ts - kind: ethereum name: L1CrossDomainMessenger network: {{network}} diff --git a/packages/sdk/.env.example b/packages/sdk/.env.example new file mode 100644 index 0000000000..c986e6efa0 --- /dev/null +++ b/packages/sdk/.env.example @@ -0,0 +1,3 @@ +# optional +# This is the API key for Boba Team to access the Graph API +THE_GRAPH_API_KEY= diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 56d77d8dc9..76a898b029 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -59,6 +59,7 @@ "dependencies": { "@bobanetwork/core_contracts": "0.5.13", "@eth-optimism/core-utils": "0.8.1", + "dotenv": "8.6.0", "lodash": "^4.17.21", "merkletreejs": "^0.2.27", "node-fetch": "^2.6.7", diff --git a/packages/sdk/src/utils/graph.ts b/packages/sdk/src/utils/graph.ts index 77fd92f331..05edf744aa 100644 --- a/packages/sdk/src/utils/graph.ts +++ b/packages/sdk/src/utils/graph.ts @@ -1,74 +1,29 @@ import { ethers } from 'ethers' import fetch from 'node-fetch' +// eslint-disable-next-line @typescript-eslint/no-var-requires +require('dotenv').config() + export const WHITELIST_CHAIN_ID: Array = [ 1287, 1284, 4002, 250, 43113, 43114, 97, 56, ] +const THE_GRAPH_API_KEY = process.env.THE_GRAPH_API_KEY + export const GRAPH_API_URL: any = { - // Bobabase - 1287: { - rollup: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobabase-rollup', - // The process of syncing Lib_addressManager is super slow - addressManager: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobabase-address-manager', - }, - // Bobabeam - 1284: { - rollup: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobabeam-rollup', - // The process of syncing Lib_addressManager is super slow - addressManager: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobabeam-address-manager', - }, - // Bobaopera testnet - 4002: { - rollup: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobaopera-tn-rollup', - // The process of syncing Lib_addressManager is super slow - addressManager: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobaopera-tn-address-manager', - }, - // Bobaopera - 250: { - rollup: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobaopera-rollup', - // The process of syncing Lib_addressManager is super slow - addressManager: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobaopera-address-manager', - }, - // Avalanche Testnet (fuji) - 43113: { - rollup: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobafuji-rollup', - // The process of syncing Lib_addressManager is super slow - addressManager: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobafuji-address-manager', - }, - // Avalanche Mainnet - 43114: { - rollup: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobaavax-rollup', - // The process of syncing Lib_addressManager is super slow - addressManager: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobaavax-address-manager', - }, // BNB Testnet 97: { rollup: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobabnb-tn-rollup', - // The process of syncing Lib_addressManager is super slow - addressManager: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobabnb-tn-address-manager', + typeof THE_GRAPH_API_KEY !== 'undefined' + ? `https://gateway-arbitrum.network.thegraph.com/api/${THE_GRAPH_API_KEY}/subgraphs/id/DzAc9upeBtED6hAKBCkEUYmVTc5kSd2Cfg3Bw63fd8B4` + : 'https://api.studio.thegraph.com/query/35866/boba-bnb-testnet-rollup/version/latest', }, // BNB Mainnet 56: { rollup: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobabnb-rollup', - // The process of syncing Lib_addressManager is super slow - addressManager: - 'https://api.thegraph.com/subgraphs/name/bobanetwork/bobabnb-address-manager', + typeof THE_GRAPH_API_KEY !== 'undefined' + ? `https://gateway-arbitrum.network.thegraph.com/api/${THE_GRAPH_API_KEY}/deployments/id/QmWfzcJBxFaEJ2c5n6ZxjERhmwNpkncrZQnzEyGiKiSFpF` + : `https://api.studio.thegraph.com/query/35866/boba-bnb-rollup/version/latest`, }, } @@ -280,7 +235,7 @@ export const getAddressSetEventsFromGraph = async ( if (!GRAPH_API_URL[chainID]) { return [] } - const response = await fetch(GRAPH_API_URL[chainID].addressManager, { + const response = await fetch(GRAPH_API_URL[chainID].rollup, { method: 'POST', headers: { 'Content-Type': 'application/json', diff --git a/packages/sdk/test/utils/graph.spec.ts b/packages/sdk/test/utils/graph.spec.ts index 48f11054cd..664f0cf5dc 100644 --- a/packages/sdk/test/utils/graph.spec.ts +++ b/packages/sdk/test/utils/graph.spec.ts @@ -10,7 +10,7 @@ describe('subgraph tests', () => { let provider: ethers.providers.Provider beforeEach(async () => { provider = new ethers.providers.JsonRpcProvider( - 'https://rpc.ankr.com/fantom_testnet' + 'https://data-seed-prebsc-2-s2.bnbchain.org:8545' ) }) @@ -18,14 +18,14 @@ describe('subgraph tests', () => { // These two events are from the same block const event_1 = await getRelayedMessageEventsFromGraph( provider, - '0x1ab4456687fc99dbaf42fd88da031754fe13167fbca1922db2989e89151058e7', + '0xeb2f76016d0029df16a0ebc7abba5c4afe2b424b0c0ea3cb1bf5ead5f92bf2d0', false ) expect(event_1).to.have.lengthOf(1) const event_2 = await getRelayedMessageEventsFromGraph( provider, - '0x75cdbb1106a93a5fefb47234c253da860f0114ed64a15f629c6fabb45170b222', + '0x2d2ce68e715e0dae0fef636d67383cdbb976a1624db62ebc2ee0d892228f30f4', false ) expect(event_1).to.have.lengthOf(1) @@ -36,7 +36,7 @@ describe('subgraph tests', () => { it('should get transaction and transaction receipt from event', async () => { const event = await getRelayedMessageEventsFromGraph( provider, - '0x1ab4456687fc99dbaf42fd88da031754fe13167fbca1922db2989e89151058e7', + '0xeb2f76016d0029df16a0ebc7abba5c4afe2b424b0c0ea3cb1bf5ead5f92bf2d0', false ) const transactionReceipt = await event[0].getTransactionReceipt() @@ -48,13 +48,13 @@ describe('subgraph tests', () => { it('should get AddressSet events', async () => { provider = new ethers.providers.JsonRpcProvider( - 'https://api.avax-test.network/ext/bc/C/rpc' + 'https://data-seed-prebsc-2-s2.bnbchain.org:8545' ) const event = await getAddressSetEventsFromGraph( provider, - 'L2CrossDomainMessenger', - 11967648, - 11967648 + 'L2ERC1155Bridge', + 30863106, + 30863106 ) expect(event).to.have.lengthOf(1) diff --git a/yarn.lock b/yarn.lock index 64f69539ae..99670fa8b5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8163,6 +8163,11 @@ dotenv@8.2.0: resolved "https://registry.npmjs.org/dotenv/-/dotenv-8.2.0.tgz" integrity sha512-8sJ78ElpbDJBHNeBzUbUVLsqKdccaa/BXF1uPTw3GrvQTBgrQrtObr2mUrE38vzYd8cEv+m/JBfDLioYcfXoaw== +dotenv@8.6.0, dotenv@^8.2.0, dotenv@^8.6.0: + version "8.6.0" + resolved "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz" + integrity sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g== + dotenv@^10.0.0: version "10.0.0" resolved "https://registry.npmjs.org/dotenv/-/dotenv-10.0.0.tgz" @@ -8183,11 +8188,6 @@ dotenv@^16.0.3: resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.3.1.tgz#369034de7d7e5b120972693352a3bf112172cc3e" integrity sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ== -dotenv@^8.2.0, dotenv@^8.6.0: - version "8.6.0" - resolved "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz" - integrity sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g== - dotenv@^9.0.0: version "9.0.2" resolved "https://registry.npmjs.org/dotenv/-/dotenv-9.0.2.tgz"