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: add EVM event-watcher support with mongodb / sns #638

Merged
merged 5 commits into from
Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 9 additions & 8 deletions event-watcher/.env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ LOG_LEVEL=info
ETH_RPC=
DB_SOURCE=
JSON_DB_FILE=db.json
FIRESTORE_ACCOUNT_KEY_PATH=
FIRESTORE_COLLECTION=
FIRESTORE_LATEST_COLLECTION=
GOOGLE_APPLICATION_CREDENTIALS=
BIGTABLE_TABLE_ID=
BIGTABLE_INSTANCE_ID=
BIGTABLE_SIGNED_VAAS_TABLE_ID=
BIGTABLE_VAAS_BY_TX_HASH_TABLE_ID=
raop155 marked this conversation as resolved.
Show resolved Hide resolved

MONGODB_URI=mongodb://localhost:27017
MONGODB_DATABASE=wormhole

AWS_SNS_REGION=
AWS_TOPIC_ARN=
AWS_SNS_SUBJECT=EventWatcher
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
1,709 changes: 1,703 additions & 6 deletions event-watcher/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions event-watcher/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"read-firestore": "ts-node scripts/readFirestore.ts"
},
"dependencies": {
"@aws-sdk/client-sns": "3.391.0",
"@celo-tools/celo-ethers-wrapper": "^0.3.0",
"@certusone/wormhole-sdk": "^0.9.22",
"@fastify/swagger": "^8.8.0",
Expand Down
7 changes: 7 additions & 0 deletions event-watcher/src/common/arrays.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function chunkArray<T>(arr: T[], size: number): T[][] {
const chunks = [];
for (let i = 0; i < arr.length; i += size) {
chunks.push(arr.slice(i, i + size));
}
return chunks;
}
86 changes: 86 additions & 0 deletions event-watcher/src/common/consts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import {
ChainId,
ChainName,
coalesceChainName,
} from '@certusone/wormhole-sdk/lib/cjs/utils/consts';

export const INITIAL_DEPLOYMENT_BLOCK_BY_CHAIN: {
[key in ChainName]?: string;
} = {
ethereum: '12959638',
terra: '4810000', // not sure exactly but this should be before the first known message
bsc: '9745450',
polygon: '20629146',
avalanche: '8237163',
oasis: '1757',
algorand: '22931277',
fantom: '31817467',
karura: '1824665',
acala: '1144161',
klaytn: '90563824',
celo: '12947144',
moonbeam: '1486591',
terra2: '399813',
injective: '20908376',
arbitrum: '18128584',
optimism: '69401779',
aptos: '0', // block is 1094390 but AptosWatcher uses sequence number instead
near: '72767136',
xpla: '777549',
solana: '94401321', // https://explorer.solana.com/tx/KhLy688yDxbP7xbXVXK7TGpZU5DAFHbYiaoX16zZArxvVySz8i8g7N7Ss2noQYoq9XRbg6HDzrQBjUfmNcSWwhe
sui: '1485552', // https://explorer.sui.io/txblock/671SoTvVUvBZQWKXeameDvAwzHQvnr8Nj7dR9MUwm3CV?network=https%3A%2F%2Frpc.mainnet.sui.io
base: '1422314',
};

export const TOKEN_BRIDGE_EMITTERS: { [key in ChainName]?: string } = {
solana: 'ec7372995d5cc8732397fb0ad35c0121e0eaa90d26f828a534cab54391b3a4f5',
ethereum: '0000000000000000000000003ee18b2214aff97000d974cf647e7c347e8fa585',
terra: '0000000000000000000000007cf7b764e38a0a5e967972c1df77d432510564e2',
terra2: 'a463ad028fb79679cfc8ce1efba35ac0e77b35080a1abe9bebe83461f176b0a3',
bsc: '000000000000000000000000b6f6d86a8f9879a9c87f643768d9efc38c1da6e7',
polygon: '0000000000000000000000005a58505a96d1dbf8df91cb21b54419fc36e93fde',
avalanche: '0000000000000000000000000e082f06ff657d94310cb8ce8b0d9a04541d8052',
oasis: '0000000000000000000000005848c791e09901b40a9ef749f2a6735b418d7564',
algorand: '67e93fa6c8ac5c819990aa7340c0c16b508abb1178be9b30d024b8ac25193d45',
aptos: '0000000000000000000000000000000000000000000000000000000000000001',
aurora: '00000000000000000000000051b5123a7b0f9b2ba265f9c4c8de7d78d52f510f',
fantom: '0000000000000000000000007c9fc5741288cdfdd83ceb07f3ea7e22618d79d2',
karura: '000000000000000000000000ae9d7fe007b3327aa64a32824aaac52c42a6e624',
acala: '000000000000000000000000ae9d7fe007b3327aa64a32824aaac52c42a6e624',
klaytn: '0000000000000000000000005b08ac39eaed75c0439fc750d9fe7e1f9dd0193f',
celo: '000000000000000000000000796dff6d74f3e27060b71255fe517bfb23c93eed',
near: '148410499d3fcda4dcfd68a1ebfcdddda16ab28326448d4aae4d2f0465cdfcb7',
moonbeam: '000000000000000000000000b1731c586ca89a23809861c6103f0b96b3f57d92',
arbitrum: '0000000000000000000000000b2402144bb366a632d14b83f244d2e0e21bd39c',
optimism: '0000000000000000000000001d68124e65fafc907325e3edbf8c4d84499daa8b',
xpla: '8f9cf727175353b17a5f574270e370776123d90fd74956ae4277962b4fdee24c',
injective: '00000000000000000000000045dbea4617971d93188eda21530bc6503d153313',
sui: 'ccceeb29348f71bdd22ffef43a2a19c1f5b5e17c5cca5411529120182672ade5',
base: '0000000000000000000000008d2de8d2f73F1F4cAB472AC9A881C9b123C79627',
};

export const isTokenBridgeEmitter = (chain: ChainId | ChainName, emitter: string) =>
TOKEN_BRIDGE_EMITTERS[coalesceChainName(chain)] === emitter;

export const NFT_BRIDGE_EMITTERS: { [key in ChainName]?: string } = {
solana: '0def15a24423e1edd1a5ab16f557b9060303ddbab8c803d2ee48f4b78a1cfd6b',
ethereum: '0000000000000000000000006ffd7ede62328b3af38fcd61461bbfc52f5651fe',
bsc: '0000000000000000000000005a58505a96d1dbf8df91cb21b54419fc36e93fde',
polygon: '00000000000000000000000090bbd86a6fe93d3bc3ed6335935447e75fab7fcf',
avalanche: '000000000000000000000000f7b6737ca9c4e08ae573f75a97b73d7a813f5de5',
oasis: '00000000000000000000000004952d522ff217f40b5ef3cbf659eca7b952a6c1',
aurora: '0000000000000000000000006dcc0484472523ed9cdc017f711bcbf909789284',
fantom: '000000000000000000000000a9c7119abda80d4a4e0c06c8f4d8cf5893234535',
karura: '000000000000000000000000b91e3638f82a1facb28690b37e3aae45d2c33808',
acala: '000000000000000000000000b91e3638f82a1facb28690b37e3aae45d2c33808',
klaytn: '0000000000000000000000003c3c561757baa0b78c5c025cdeaa4ee24c1dffef',
celo: '000000000000000000000000a6a377d75ca5c9052c9a77ed1e865cc25bd97bf3',
moonbeam: '000000000000000000000000453cfbe096c0f8d763e8c5f24b441097d577bde2',
arbitrum: '0000000000000000000000003dd14d553cfd986eac8e3bddf629d82073e188c8',
optimism: '000000000000000000000000fe8cd454b4a1ca468b57d79c0cc77ef5b6f64585',
aptos: '0000000000000000000000000000000000000000000000000000000000000005',
base: '000000000000000000000000DA3adC6621B2677BEf9aD26598e6939CF0D92f88',
};

export const isNFTBridgeEmitter = (chain: ChainId | ChainName, emitter: string) =>
NFT_BRIDGE_EMITTERS[coalesceChainName(chain)] === emitter;
3 changes: 3 additions & 0 deletions event-watcher/src/common/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './arrays';
export * from './consts';
export * from './utils';
7 changes: 0 additions & 7 deletions event-watcher/src/common/package.json

This file was deleted.

8 changes: 0 additions & 8 deletions event-watcher/src/common/tsconfig.json

This file was deleted.

1 change: 0 additions & 1 deletion event-watcher/src/common/tsconfig.tsbuildinfo

This file was deleted.

15 changes: 15 additions & 0 deletions event-watcher/src/common/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export async function sleep(timeout: number) {
return new Promise((resolve) => setTimeout(resolve, timeout));
}
export const assertEnvironmentVariable = (varName: string) => {
if (varName in process.env) return process.env[varName]!;
throw new Error(`Missing required environment variable: ${varName}`);
};
export const MAX_UINT_16 = '65535';
export const padUint16 = (s: string): string => s.padStart(MAX_UINT_16.length, '0');
export const MAX_UINT_64 = '18446744073709551615';
export const padUint64 = (s: string): string => s.padStart(MAX_UINT_64.length, '0');

// make a bigtable row key for the `signedVAAs` table
export const makeSignedVAAsRowKey = (chain: number, emitter: string, sequence: string): string =>
`${padUint16(chain.toString())}/${emitter}/${padUint64(sequence)}`;
9 changes: 5 additions & 4 deletions event-watcher/src/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const TIMEOUT = 0.5 * 1000;

export const RPCS_BY_CHAIN: { [key in ChainName]?: string } = {
ethereum: process.env.ETH_RPC || 'https://svc.blockdaemon.com/ethereum/mainnet/native',
bsc: process.env.BSC_RPC || 'https://bsc-dataseed2.defibit.io',
bsc: 'https://bsc-dataseed2.defibit.io',
polygon: 'https://rpc.ankr.com/polygon',
avalanche: 'https://rpc.ankr.com/avalanche',
oasis: 'https://emerald.oasis.dev',
Expand Down Expand Up @@ -75,9 +75,10 @@ export const DB_LAST_BLOCK_FILE = process.env.DB_LAST_BLOCK_FILE || './lastBlock

// without this, axios request will error `Z_BUF_ERROR`: https://github.com/axios/axios/issues/5346
export const AXIOS_CONFIG_JSON: AxiosRequestConfig = {
headers: { 'Accept-Encoding': 'application/json',
'Authorization': 'Bearer zpka_213d294a9a5a44619cd6a02e55a20417_5f43e4d0'
},
headers: {
'Accept-Encoding': 'application/json',
Authorization: 'Bearer zpka_213d294a9a5a44619cd6a02e55a20417_5f43e4d0',
},
};

export const GUARDIAN_RPC_HOSTS = [
Expand Down
Loading
Loading