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(indexer): introduce indexer #191

Merged
merged 15 commits into from
Nov 27, 2024
Merged
4 changes: 4 additions & 0 deletions .gitignore
osipov-mit marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ out/
ethereum/broadcast

.env
.DS_Store

node_modules/
indexer/lib/
8 changes: 8 additions & 0 deletions indexer/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.git
/node_modules
/lib
/*Versions.json
npm-debug.log

# OS Files
.DS_Store
7 changes: 7 additions & 0 deletions indexer/.squidignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
builds
lib
Dockerfile
.git
.github
.idea
Empty file added indexer/Dockerfile
osipov-mit marked this conversation as resolved.
Show resolved Hide resolved
Empty file.
43 changes: 43 additions & 0 deletions indexer/README.md
osipov-mit marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Multichain transfers squid

This [squid](https://docs.subsquid.io/) captures USDC Transfer events on ETH and BSC, stores them in the same database and serves the data over a common GraphQL API.

The Ethereum processor is located in `src/eth` and similarly the Binance Chain processor can be found in `src/bsc`. The scripts file `commands.json` was updated with the commands `process:eth` and `process:bsc` to run the processors.

You can find some useful hints on developing multichain squids on the [dedicated documentation page](https://docs.subsquid.io/basics/multichain/).

Dependencies: Node.js, Docker, Git.

## Quickstart

```bash
# 0. Install @subsquid/cli a.k.a. the sqd command globally
npm i -g @subsquid/cli

# 1. Clone the repo
git clone https://github.com/subsquid-labs/multichain-transfers-example
cd multichain-transfers-example

# 2. Install dependencies
npm ci

# 3. Start a Postgres database container and detach
sqd up

# 4. Apply the migration
sqd migration:apply

# 5. Build the squid
sqd build

# 6. Run all services at once
sqd run .
```
A GraphiQL playground will be available at [localhost:4350/graphql](http://localhost:4350/graphql).

You can also run individual services separately:
```bash
sqd process:eth # Ethereum processor
sqd process:bsc # BSC processor
sqd serve # GraphQL server
```
78 changes: 78 additions & 0 deletions indexer/assets/IERC20Treasury.json
mertwole marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[
{
"type": "event",
"name": "Deposit",
"inputs": [
{
"name": "from",
"type": "address",
"indexed": true,
"internalType": "address"
},
{
"name": "to",
"type": "bytes32",
"indexed": true,
"internalType": "bytes32"
},
{
"name": "token",
"type": "address",
"indexed": true,
"internalType": "address"
},
{
"name": "amount",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
}
],
"anonymous": false
},
{
"type": "event",
"name": "Withdraw",
"inputs": [
{
"name": "to",
"type": "address",
"indexed": true,
"internalType": "address"
},
{
"name": "token",
"type": "address",
"indexed": true,
"internalType": "address"
},
{
"name": "amount",
"type": "uint256",
"indexed": false,
"internalType": "uint256"
}
],
"anonymous": false
},
{
"type": "error",
"name": "BadArguments",
"inputs": []
},
{
"type": "error",
"name": "BadEthAddress",
"inputs": []
},
{
"type": "error",
"name": "BadVaraAddress",
"inputs": []
},
{
"type": "error",
"name": "NotAuthorized",
"inputs": []
}
]
179 changes: 179 additions & 0 deletions indexer/assets/IMessageQueue.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
[
{
"type": "function",
"name": "calculateMerkleRoot",
"inputs": [
{
"name": "proof",
"type": "bytes32[]",
"internalType": "bytes32[]"
},
{
"name": "hash",
"type": "bytes32",
"internalType": "bytes32"
},
{
"name": "width",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "leaf_index",
"type": "uint256",
"internalType": "uint256"
}
],
"outputs": [
{
"name": "",
"type": "bytes32",
"internalType": "bytes32"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "processMessage",
"inputs": [
{
"name": "block_number",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "total_leaves",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "leaf_index",
"type": "uint256",
"internalType": "uint256"
},
{
"name": "message",
"type": "tuple",
"internalType": "struct VaraMessage",
"components": [
{
"name": "nonce",
"type": "bytes32",
"internalType": "bytes32"
},
{
"name": "sender",
"type": "bytes32",
"internalType": "bytes32"
},
{
"name": "receiver",
"type": "address",
"internalType": "address"
},
{
"name": "data",
"type": "bytes",
"internalType": "bytes"
}
]
},
{
"name": "proof",
"type": "bytes32[]",
"internalType": "bytes32[]"
}
],
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "event",
"name": "MessageProcessed",
"inputs": [
{
"name": "blockNumber",
"type": "uint256",
"indexed": true,
"internalType": "uint256"
},
{
"name": "messageHash",
"type": "bytes32",
"indexed": true,
"internalType": "bytes32"
},
{
"name": "messageNonce",
"type": "bytes32",
"indexed": true,
"internalType": "bytes32"
}
],
"anonymous": false
},
{
"type": "event",
"name": "ProoverAddressUpdated",
"inputs": [
{
"name": "proover",
"type": "address",
"indexed": false,
"internalType": "address"
}
],
"anonymous": false
},
{
"type": "event",
"name": "RelayerAddressUpdated",
"inputs": [
{
"name": "relayer",
"type": "address",
"indexed": false,
"internalType": "address"
}
],
"anonymous": false
},
{
"type": "error",
"name": "AlreadyInitialized",
"inputs": []
},
{
"type": "error",
"name": "BadProof",
"inputs": []
},
{
"type": "error",
"name": "MerkleRootNotSet",
"inputs": [
{
"name": "blockNumber",
"type": "uint256",
"internalType": "uint256"
}
]
},
{
"type": "error",
"name": "MessageAlreadyProcessed",
"inputs": [
{
"name": "messageNonce",
"type": "bytes32",
"internalType": "bytes32"
}
]
},
{
"type": "error",
"name": "MessageNotProcessed",
"inputs": []
}
]
Loading
Loading