Skip to content

Commit 0138d57

Browse files
committed
watcher: add sei testnet watcher
1 parent 5a979b1 commit 0138d57

File tree

2 files changed

+61
-13
lines changed

2 files changed

+61
-13
lines changed

watcher/src/consts.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,12 @@ export const ALGORAND_INFO: { [key in Environment]: AlgorandInfo } = {
136136
},
137137
};
138138

139-
export const SEI_EXPLORER_GRAPHQL = 'https://pacific-1-graphql.alleslabs.dev/v1/graphql';
140-
export const SEI_EXPLORER_TXS = 'https://celatone-api-prod.alleslabs.dev/v1/sei/pacific-1/txs/';
139+
export const SEI_EXPLORER_GRAPHQL_MAINNET = 'https://pacific-1-graphql.alleslabs.dev/v1/graphql';
140+
export const SEI_EXPLORER_TXS_MAINNET =
141+
'https://celatone-api-prod.alleslabs.dev/v1/sei/pacific-1/txs/';
142+
export const SEI_EXPLORER_GRAPHQL_TESTNET = 'https://atlantic-2-graphql.alleslabs.dev/v1/graphql';
143+
export const SEI_EXPLORER_TXS_TESTNET =
144+
'https://celatone-api-prod.alleslabs.dev/v1/sei/atlantic-2/txs/';
141145

142146
export const DB_SOURCE =
143147
process.env.NODE_ENV === 'test' ? 'local' : process.env.DB_SOURCE || 'local';

watcher/src/watchers/SeiExplorerWatcher.ts

+55-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
import { CONTRACTS } from '@certusone/wormhole-sdk/lib/cjs/utils/consts';
1+
import { CONTRACTS, Contracts } from '@certusone/wormhole-sdk/lib/cjs/utils/consts';
22
import axios from 'axios';
3-
import { AXIOS_CONFIG_JSON, SEI_EXPLORER_GRAPHQL, SEI_EXPLORER_TXS } from '../consts';
3+
import {
4+
AXIOS_CONFIG_JSON,
5+
SEI_EXPLORER_GRAPHQL_MAINNET,
6+
SEI_EXPLORER_GRAPHQL_TESTNET,
7+
SEI_EXPLORER_TXS_MAINNET,
8+
SEI_EXPLORER_TXS_TESTNET,
9+
} from '../consts';
410
import { VaasByBlock } from '../databases/types';
511
import { makeBlockKey, makeVaaKey } from '../databases/utils';
612
import { CosmwasmHashResult, CosmwasmWatcher } from './CosmwasmWatcher';
@@ -29,33 +35,65 @@ type SeiExplorerAccountTransactionsResponse = {
2935
};
3036

3137
export class SeiExplorerWatcher extends CosmwasmWatcher {
38+
explorerGraphql: string;
39+
explorerTxs: string;
40+
accountId: number;
41+
3242
constructor(network: Environment) {
3343
super(network, 'sei');
3444
// arbitrarily large since the code here is capable of pulling all logs from all via indexer pagination
3545
this.maximumBatchSize = 1_000_000;
46+
this.explorerGraphql =
47+
network === 'mainnet'
48+
? SEI_EXPLORER_GRAPHQL_MAINNET
49+
: network === 'testnet'
50+
? SEI_EXPLORER_GRAPHQL_TESTNET
51+
: '';
52+
this.explorerTxs =
53+
network === 'mainnet'
54+
? SEI_EXPLORER_TXS_MAINNET
55+
: network === 'testnet'
56+
? SEI_EXPLORER_TXS_TESTNET
57+
: '';
58+
this.accountId = network === 'mainnet' ? 42 : network === 'testnet' ? 3254150 : 0;
59+
// 42 is the account id of sei1gjrrme22cyha4ht2xapn3f08zzw6z3d4uxx6fyy9zd5dyr3yxgzqqncdqn <-- mainnet
60+
// MAINNET:
61+
// curl https://pacific-1-graphql.alleslabs.dev/v1/graphql \
62+
// -X POST \
63+
// -H "Content-Type: application/json" \
64+
// --data '{"query":"query getAccountIdByAddressQueryDocument($address: String!) {accounts_by_pk(address: $address) {id}}", "variables":{"address":"sei1gjrrme22cyha4ht2xapn3f08zzw6z3d4uxx6fyy9zd5dyr3yxgzqqncdqn"}, "operationName":"getAccountIdByAddressQueryDocument"}'
65+
// {"data":{"accounts_by_pk":{"id":42}}}
66+
//
67+
// 3254150 is the account number of sei1nna9mzp274djrgzhzkac2gvm3j27l402s4xzr08chq57pjsupqnqaj0d5s <-- testnet
68+
// TESTNET:
69+
// curl https://atlantic-2-graphql.alleslabs.dev/v1/graphql \
70+
// -X POST \
71+
// -H "Content-Type: application/json" \
72+
// --data '{"query":"query getAccountIdByAddressQueryDocument($address: String!) {accounts_by_pk(address: $address) {id}}", "variables":{"address":"sei1nna9mzp274djrgzhzkac2gvm3j27l402s4xzr08chq57pjsupqnqaj0d5s"}, "operationName":"getAccountIdByAddressQueryDocument"}'
73+
// {"data":{"accounts_by_pk":{"id":3254150}}}
74+
// returned by getAccountIdByAddressQueryDocument
3675
}
3776

3877
makeGraphQLQuery(offset: number, pageSize: number) {
3978
return {
4079
query:
4180
'query getTxsByAddressPagination($expression: account_transactions_bool_exp, $offset: Int!, $pageSize: Int!) {\n account_transactions(\n where: $expression\n order_by: {block_height: desc}\n offset: $offset\n limit: $pageSize\n ) {\n block {\n height\n timestamp\n }\n transaction {\n account {\n address\n }\n hash\n success\n messages\n is_clear_admin\n is_execute\n is_ibc\n is_instantiate\n is_migrate\n is_send\n is_store_code\n is_update_admin\n }\n is_signer\n }\n}',
42-
variables: { expression: { account_id: { _eq: 42 } }, offset, pageSize },
43-
// 42 is the account id of sei1gjrrme22cyha4ht2xapn3f08zzw6z3d4uxx6fyy9zd5dyr3yxgzqqncdqn
44-
// returned by getAccountIdByAddressQueryDocument
81+
variables: { expression: { account_id: { _eq: this.accountId } }, offset, pageSize },
4582
operationName: 'getTxsByAddressPagination',
4683
};
4784
}
4885

4986
async getFinalizedBlockNumber(): Promise<number> {
5087
const query = this.makeGraphQLQuery(0, 1);
51-
this.logger.debug(`Query string = ${JSON.stringify(query)}`);
88+
// this.logger.debug(`Query string = ${JSON.stringify(query)}`);
5289
const bulkTxnResult = (
5390
await axios.post<SeiExplorerAccountTransactionsResponse>(
54-
SEI_EXPLORER_GRAPHQL,
91+
this.explorerGraphql,
5592
query,
5693
AXIOS_CONFIG_JSON
5794
)
5895
).data;
96+
this.logger.debug(`bulkTxnResult = ${JSON.stringify(bulkTxnResult)}`);
5997
const blockHeight = bulkTxnResult?.data?.account_transactions?.[0]?.block?.height;
6098
if (blockHeight) {
6199
if (blockHeight !== this.latestBlockHeight) {
@@ -70,7 +108,13 @@ export class SeiExplorerWatcher extends CosmwasmWatcher {
70108
// retrieve blocks for core contract
71109
// compare block height with what is passed in
72110
async getMessagesForBlocks(fromBlock: number, toBlock: number): Promise<VaasByBlock> {
73-
const address = CONTRACTS.MAINNET[this.chain].core;
111+
const contracts: Contracts =
112+
this.network === 'mainnet'
113+
? CONTRACTS.MAINNET[this.chain]
114+
: this.network === 'testnet'
115+
? CONTRACTS.TESTNET[this.chain]
116+
: CONTRACTS.DEVNET[this.chain];
117+
const address = contracts.core;
74118
if (!address) {
75119
throw new Error(`Core contract not defined for ${this.chain}`);
76120
}
@@ -83,10 +127,10 @@ export class SeiExplorerWatcher extends CosmwasmWatcher {
83127
let skip: number = 0;
84128
while (!done) {
85129
const query = this.makeGraphQLQuery(skip, limit);
86-
this.logger.debug(`Query string = ${JSON.stringify(query)}`);
130+
// this.logger.debug(`Query string = ${JSON.stringify(query)}`);
87131
const bulkTxnResult = (
88132
await axios.post<SeiExplorerAccountTransactionsResponse>(
89-
SEI_EXPLORER_GRAPHQL,
133+
this.explorerGraphql,
90134
query,
91135
AXIOS_CONFIG_JSON
92136
)
@@ -130,7 +174,7 @@ export class SeiExplorerWatcher extends CosmwasmWatcher {
130174
} catch (e: any) {
131175
if (e?.response?.status === 404) {
132176
// the node is mysteriously missing some transactions, but so is this ='(
133-
hashResult = (await axios.get(`${SEI_EXPLORER_TXS}${hash}`, AXIOS_CONFIG_JSON))
177+
hashResult = (await axios.get(`${this.explorerTxs}${hash}`, AXIOS_CONFIG_JSON))
134178
.data;
135179
}
136180
}

0 commit comments

Comments
 (0)