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

Support PNA and multi hops transfer #2

Merged
merged 33 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
792b629
Deploy to cloud
yrong Dec 22, 2024
5381c8a
Generate types for parachain Moonbeam
yrong Dec 22, 2024
64c03d2
Change code layout
yrong Dec 23, 2024
33369ed
Index ethereum transfer on Moonbeam
yrong Dec 23, 2024
fe10d0b
Update metadata to v3100
yrong Dec 23, 2024
36eb486
Limit call to transfer_assets_using_type_and_then
yrong Dec 23, 2024
4cd4d35
Fix typegen.json
yrong Dec 24, 2024
6a04d1e
Add hydration
yrong Dec 24, 2024
1142710
Move filter logic ahead
yrong Dec 25, 2024
3417e71
Seperate process logic into inbound&outbound
yrong Dec 25, 2024
b8b6fee
Update assethub metadata
yrong Dec 25, 2024
3499da2
Index forwarded xcm on AH for the multi hop
yrong Dec 25, 2024
6b7c669
Refactor for multi-hops
yrong Dec 27, 2024
425a361
Refactor for multi-hops
yrong Dec 27, 2024
d7d8bd5
Fix update logic
yrong Dec 27, 2024
3801d7e
Update process logic
yrong Dec 28, 2024
98a0cf5
Deploy to squid cloud
yrong Dec 29, 2024
dc382a8
Add pm2 script for hydration
yrong Dec 29, 2024
771518b
Update to V2
yrong Dec 29, 2024
fa7bed3
Add script for reindex
yrong Dec 30, 2024
c419bc6
Fix process logic on AH
yrong Dec 30, 2024
1804c51
Update metadata & fix process logic for moonbeam
yrong Dec 30, 2024
b15f788
Post process to update the blocks
yrong Dec 30, 2024
11dd770
Enable production profiles
yrong Dec 30, 2024
fc8f782
Update command
yrong Dec 30, 2024
162e606
Update schema
yrong Jan 10, 2025
2030fca
Update bridgehub meta types
yrong Jan 10, 2025
81b2a73
Index for PNA
yrong Jan 10, 2025
5e3fa41
Remove moonbeam
yrong Jan 11, 2025
a53ff77
Index PNA - hydration
yrong Jan 11, 2025
4335b94
Add processingFailed event
yrong Jan 11, 2025
536cc9a
Index PNA transfer on ethereum
yrong Jan 11, 2025
3e40c37
Fix with status nullable
yrong Jan 11, 2025
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
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ GQL_PORT=4350
# JSON-RPC node endpoints (wss or https)
RPC_BRIDGEHUB_POLKADOT=wss://bridgehub-polkadot.api.onfinality.io/public-ws
RPC_ASSETHUB_POLKADOT=wss://statemint.api.onfinality.io/public-ws
RPC_MOONBEAM=wss://moonbeam.ibp.network
RPC_HYDRATION=wss://hydration.dotters.network

# Ankr endpoint is only for test, for production to decrease the latency
# better to use rpc endpoint more robust/realtime like Alchemy
Expand Down
3 changes: 3 additions & 0 deletions .squidignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ Dockerfile
.git
.github
.idea
data
db
.env
20 changes: 19 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,32 @@
"args": ["src/assethub/main.ts"],
"env": { "SQD_DEBUG": "*" }
},
{
"type": "node",
"request": "launch",
"name": "Launch process moonbeam",
"runtimeArgs": ["-r", "ts-node/register", "-r", "dotenv/config"],
"cwd": "${workspaceRoot}",
"args": ["src/parachains/moonbeam/main.ts"],
"env": { "SQD_DEBUG": "*" }
},
{
"type": "node",
"request": "launch",
"name": "Launch process hydration",
"runtimeArgs": ["-r", "ts-node/register", "-r", "dotenv/config"],
"cwd": "${workspaceRoot}",
"args": ["src/parachains/hydration/main.ts"],
"env": { "SQD_DEBUG": "*" }
},
{
"type": "node",
"request": "launch",
"name": "post process status",
"runtimeArgs": ["-r", "ts-node/register", "-r", "dotenv/config"],
"cwd": "${workspaceRoot}",
// "args": ["src/postprocess/index.ts", "toPolkadot"],
"args": ["src/postprocess/index.ts", "toEthereum"],
"args": ["src/postprocess/start.ts"],
"env": { "SQD_DEBUG": "*" }
}
]
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,22 @@ Basically transfer status should be resolved by these two queries.
It is possible to extend `squid-graphql-server(1)` with custom
[type-graphql](https://typegraphql.com) resolvers and to add request validation.
For more details, consult [docs](https://docs.subsquid.io/graphql-api/).

## Deploy to subsquid cloud

Follow the guides in:

- https://docs.sqd.dev/cloud/overview/

- https://app.subsquid.io/squids/deploy


Deploy to cloud with `sqd`

```
sqd deploy --org snowfork /home/ubuntu/projects/snowbridge-subsquid
```

### API endpoint

https://data.snowbridge.network/graphql
694 changes: 694 additions & 0 deletions abi/Token.json

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions assethub-versions.jsonl

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions bridgehub-versions.jsonl

Large diffs are not rendered by default.

56 changes: 47 additions & 9 deletions commands.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"migration:apply": {
"description": "Apply the DB migrations",
"deps": ["migration"],
"cmd": ["squid-typeorm-migration", "apply"]
},
"migration:generate": {
Expand All @@ -36,7 +37,7 @@
"cmd": ["npx", "--yes", "rimraf", "./db/migrations"]
},
"migration": {
"deps": ["build"],
"deps": ["clean", "codegen", "build", "migration:clean"],
"cmd": ["squid-typeorm-migration", "generate"],
"hidden": true
},
Expand All @@ -50,7 +51,7 @@
},
"process:ethereum": {
"description": "Load .env and start the squid processor",
"deps": ["build", "migration:apply"],
"deps": ["build"],
"cmd": ["node", "--require=dotenv/config", "lib/ethereum/main.js"]
},
"generateMeta:bridgehub": {
Expand All @@ -68,7 +69,7 @@
},
"process:bridgehub": {
"description": "Load .env and start the squid processor",
"deps": ["build", "migration:apply"],
"deps": ["build"],
"cmd": ["node", "--require=dotenv/config", "lib/bridgehub/main.js"]
},
"generateMeta:assethub": {
Expand All @@ -86,15 +87,56 @@
},
"process:assethub": {
"description": "Load .env and start the squid processor",
"deps": ["build", "migration:apply"],
"deps": ["build"],
"cmd": ["node", "--require=dotenv/config", "lib/assethub/main.js"]
},
"postprocess": {
"description": "Update status based on stored data",
"deps": ["build"],
"cmd": ["node", "--require=dotenv/config", "lib/postprocess/cron.js"]
},
"generateMeta:parachain:moonbeam": {
"description": "Generate metadata for moonbeam",
"cmd": [
"npx",
"squid-substrate-metadata-explorer",
"--rpc=wss://moonbeam.ibp.network",
"--out=moonbeam-versions.jsonl"
]
},
"typegen:parachain:moonbeam": {
"description": "Generate data access classes for an moombeam metadata",
"cmd": ["squid-substrate-typegen", "./typegen-moonbeam.json"]
},
"process:parachain:moonbeam": {
"description": "Load .env and start the squid processor",
"deps": ["build"],
"cmd": [
"node",
"--require=dotenv/config",
"lib/postprocess/start.js"
"lib/parachains/moonbeam/main.js"
]
},
"generateMeta:parachain:hydration": {
"description": "Generate metadata for hydration",
"cmd": [
"npx",
"squid-substrate-metadata-explorer",
"--rpc=wss://hydration.dotters.network",
"--out=hydration-versions.jsonl"
]
},
"typegen:parachain:hydration": {
"description": "Generate data access classes for hydration metadata",
"cmd": ["squid-substrate-typegen", "./typegen-hydration.json"]
},
"process:parachain:hydration": {
"description": "Load .env and start the squid processor",
"deps": ["build"],
"cmd": [
"node",
"--require=dotenv/config",
"lib/parachains/hydration/main.js"
]
},
"serve": {
Expand Down Expand Up @@ -130,10 +172,6 @@
"deps": ["check-updates"],
"cmd": ["npm", "i", "-f"]
},
"open": {
"description": "Open a local browser window",
"cmd": ["npx", "--yes", "opener"]
},
"prettier": {
"cmd": ["npx", "prettier", ".", "--write"]
}
Expand Down
9 changes: 7 additions & 2 deletions ecosystem.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ module.exports = {
node_args: "--require=dotenv/config",
script: "./lib/assethub/main.js",
},
{
name: "hydration",
node_args: "--require=dotenv/config",
script: "./lib/parachains/hydration/main.js",
},
{
name: "graphql",
script: "./node_modules/.bin/squid-graphql-server",
},
{
name: "postprocess",
node_args: "--require=dotenv/config",
script: "./lib/postprocess/cron.js"
}
script: "./lib/postprocess/cron.js",
},
],
};
35 changes: 35 additions & 0 deletions hydration-versions.jsonl

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions moonbeam-versions.jsonl

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"enabled": false
}
],
// "automerge": true,
"automergeType": "pr",
"automergeStrategy": "squash",
"ignoreTests": true
Expand Down
97 changes: 51 additions & 46 deletions schema.graphql
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
type TokenSentOnEthereum @entity {
id: ID!
txHash: String! @index
blockNumber: Int! @index
timestamp: DateTime! @index
tokenAddress: String! @index
senderAddress: String! @index
destinationParaId: Int! @index
destinationAddress: String! @index
amount: BigInt!
}

"""
Outbound message sent on Ethereum
"""
type OutboundMessageAcceptedOnEthereum @entity {
id: ID!
txHash: String! @index
Expand All @@ -20,6 +11,9 @@ type OutboundMessageAcceptedOnEthereum @entity {
nonce: Int! @index
}

"""
Inbound message received on BridgeHub
"""
type InboundMessageReceivedOnBridgeHub @entity {
id: ID!
blockNumber: Int! @index
Expand All @@ -29,75 +23,86 @@ type InboundMessageReceivedOnBridgeHub @entity {
nonce: Int! @index
}

"""
Message processed on polkadot chains
"""
type MessageProcessedOnPolkadot @entity {
id: ID!
blockNumber: Int! @index
timestamp: DateTime! @index
messageId: String! @index
success: Boolean! @index
paraId: Int
success: Boolean
}

type TransferStatusToPolkadot @entity {
"""
Outbound message sent on BridgeHub
"""
type OutboundMessageAcceptedOnBridgeHub @entity {
id: ID!
messageId: String! @index
txHash: String! @index
blockNumber: Int! @index
timestamp: DateTime! @index
tokenAddress: String! @index
senderAddress: String! @index
destinationParaId: Int! @index
destinationAddress: String! @index
amount: BigInt!
messageId: String! @index
channelId: String @index
nonce: Int! @index
status: String! @index
}

type TokenSentOnPolkadot @entity {
"""
Inbound message dispatched on Ethereum
"""
type InboundMessageDispatchedOnEthereum @entity {
id: ID!
messageId: String! @index
txHash: String! @index
blockNumber: Int! @index
timestamp: DateTime! @index
tokenAddress: String! @index
senderAddress: String! @index
sourceParaId: Int! @index
destinationAddress: String! @index
amount: BigInt!
}

type OutboundMessageAcceptedOnBridgeHub @entity {
id: ID!
blockNumber: Int! @index
timestamp: DateTime! @index
messageId: String! @index
channelId: String @index
nonce: Int! @index
success: Boolean @index
}

type InboundMessageDispatchedOnEthereum @entity {
"""
Transfers from Ethereum to Polkadot
"""
type TransferStatusToPolkadot @entity {
id: ID!
messageId: String! @index
txHash: String! @index
blockNumber: Int! @index
timestamp: DateTime! @index
messageId: String! @index
channelId: String @index
nonce: Int! @index
success: Boolean! @index
nonce: Int @index
status: String! @index
tokenAddress: String
tokenLocation: String
senderAddress: String
destinationParaId: Int
destinationAddress: String
amount: BigInt
channelId: String
forwardedBlockNumber: Int
bridgedBlockNumber: Int
destinationBlockNumber: Int
}

"""
Transfers from Polkadot to Ethereum
"""
type TransferStatusToEthereum @entity {
id: ID!
messageId: String! @index
txHash: String! @index
blockNumber: Int! @index
timestamp: DateTime! @index
tokenAddress: String! @index
senderAddress: String! @index
sourceParaId: Int! @index
destinationAddress: String! @index
amount: BigInt!
channelId: String @index
nonce: Int @index
status: String! @index
tokenAddress: String
tokenLocation: String
senderAddress: String
sourceParaId: Int
destinationAddress: String
amount: BigInt
channelId: String
forwardedBlockNumber: Int
bridgedBlockNumber: Int
destinationBlockNumber: Int
}
Empty file modified scripts/docker-run.sh
100644 → 100755
Empty file.
11 changes: 11 additions & 0 deletions scripts/re-index-all.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
set -e

pm2 stop ecosystem.config.js

docker exec snowbridge-subsquid-db-1 /bin/sh -c 'psql -h localhost -U postgres -c "drop database squid_v2 WITH (FORCE);" -c "create database squid_v2;"'

sqd clean && sqd codegen && sqd build && sqd migration:apply

pm2 start ecosystem.config.js


9 changes: 9 additions & 0 deletions scripts/re-index-assethub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set -e

pm2 stop assethub

docker exec snowbridge-subsquid-db-1 /bin/sh -c 'psql -h localhost -U postgres -d squid_v2 -c "drop schema assethub_processor cascade;"'

pm2 start assethub


9 changes: 9 additions & 0 deletions scripts/re-index-bridgehub.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set -e

pm2 stop bridgehub

docker exec snowbridge-subsquid-db-1 /bin/sh -c 'psql -h localhost -U postgres -d squid_v2 -c "drop schema bridgehub_processor cascade;"'

pm2 start bridgehub


9 changes: 9 additions & 0 deletions scripts/re-index-ethereum.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set -e

pm2 stop ethereum

docker exec snowbridge-subsquid-db-1 /bin/sh -c 'psql -h localhost -U postgres -d squid_v2 -c "drop schema eth_processor cascade;"'

pm2 start ethereum


Loading