diff --git a/deploy/event-watcher/configmap.yaml b/deploy/event-watcher/configmap.yaml index fcabb3aa..f8ced148 100644 --- a/deploy/event-watcher/configmap.yaml +++ b/deploy/event-watcher/configmap.yaml @@ -30,4 +30,28 @@ data: sui-rpc: {{ .SUI_RPC }} terra-rpc: {{ .TERRA_RPC }} terra2-rpc: {{ .TERRA2_RPC }} - xpla-rpc: {{ .XPLA_RPC }} \ No newline at end of file + xpla-rpc: {{ .XPLA_RPC }} + acala-rps: {{ .ACALA_RPS }} + algorand-rps: {{ .ALGORAND_RPS }} + aptos-rps: {{ .APTOS_RPS }} + arbitrum-rps: {{ .ARBITRUM_RPS }} + avalanche-rps: {{ .AVALANCHE_RPS }} + base-rps: {{ .BASE_RPS }} + bsc-rps: {{ .BSC_RPS }} + celo-rps: {{ .CELO_RPS }} + ethereum-rps: {{ .ETHEREUM_RPS }} + fantom-rps: {{ .FANTOM_RPS }} + injective-rps: {{ .INJECTIVE_RPS }} + karura-rps: {{ .KARURA_RPS }} + klaytn-rps: {{ .KLAYTN_RPS }} + moonbeam-rps: {{ .MOONBEAM_RPS }} + near-rps: {{ .NEAR_RPS }} + oasis-rps: {{ .OASIS_RPS }} + optimism-rps: {{ .OPTIMISM_RPS }} + polygon-rps: {{ .POLYGON_RPS }} + sei-rps: {{ .SEI_RPS }} + solana-rps: {{ .SOLANA_RPS }} + sui-rps: {{ .SUI_RPS }} + terra-rps: {{ .TERRA_RPS }} + terra2-rps: {{ .TERRA2_RPS }} + xpla-rps: {{ .XPLA_RPS }} \ No newline at end of file diff --git a/deploy/event-watcher/env/staging-mainnet.env b/deploy/event-watcher/env/staging-mainnet.env index 1cd97133..a5eb298b 100644 --- a/deploy/event-watcher/env/staging-mainnet.env +++ b/deploy/event-watcher/env/staging-mainnet.env @@ -41,3 +41,27 @@ SUI_RPC=https://rpc.mainnet.sui.io TERRA_RPC=https://terra-classic-fcd.publicnode.com TERRA2_RPC=https://phoenix-lcd.terra.dev XPLA_RPC=https://dimension-lcd.xpla.dev +ACALA_RPS=30 +ALGORAND_RPS=30 +APTOS_RPS=30 +ARBITRUM_RPS=30 +AVALANCHE_RPS=30 +BASE_RPS=30 +BSC_RPS=30 +CELO_RPS=30 +ETHEREUM_RPS=30 +FANTOM_RPS=30 +INJECTIVE_RPS=30 +KARURA_RPS=30 +KLAYTN_RPS=30 +MOONBEAM_RPS=30 +NEAR_RPS=30 +OASIS_RPS=30 +OPTIMISM_RPS=30 +POLYGON_RPS=30 +SEI_RPS=30 +SOLANA_RPS=30 +SUI_RPS=30 +TERRA_RPS=30 +TERRA2_RPS=30 +XPLA_RPS=30 diff --git a/deploy/event-watcher/env/staging-testnet.env b/deploy/event-watcher/env/staging-testnet.env index 93c91c9c..98ac64e2 100644 --- a/deploy/event-watcher/env/staging-testnet.env +++ b/deploy/event-watcher/env/staging-testnet.env @@ -40,4 +40,28 @@ SOLANA_RPC=https://api.devnet.solana.com SUI_RPC=https://sui-testnet-rpc.allthatnode.com TERRA_RPC=https://bombay.stakesystems.io:2053 TERRA2_RPC=https://pisco-lcd.terra.dev -XPLA_RPC=https://dimension-rpc.xpla.dev \ No newline at end of file +XPLA_RPC=https://dimension-rpc.xpla.dev +ACALA_RPS=30 +ALGORAND_RPS=30 +APTOS_RPS=30 +ARBITRUM_RPS=30 +AVALANCHE_RPS=30 +BASE_RPS=30 +BSC_RPS=30 +CELO_RPS=30 +ETHEREUM_RPS=30 +FANTOM_RPS=30 +INJECTIVE_RPS=30 +KARURA_RPS=30 +KLAYTN_RPS=30 +MOONBEAM_RPS=30 +NEAR_RPS=30 +OASIS_RPS=30 +OPTIMISM_RPS=30 +POLYGON_RPS=30 +SEI_RPS=30 +SOLANA_RPS=30 +SUI_RPS=30 +TERRA_RPS=30 +TERRA2_RPS=30 +XPLA_RPS=30 \ No newline at end of file diff --git a/deploy/event-watcher/event-watcher-service.yaml b/deploy/event-watcher/event-watcher-service.yaml index 8fa38c81..e8b300f9 100644 --- a/deploy/event-watcher/event-watcher-service.yaml +++ b/deploy/event-watcher/event-watcher-service.yaml @@ -194,6 +194,127 @@ spec: name: event-watcher key: xpla-rpc + + - name: ACALA_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: acala-rps + - name: ALGORAND_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: algorand-rps + - name: APTOS_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: aptos-rps + - name: ARBITRUM_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: arbitrum-rps + - name: AVALANCHE_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: avalanche-rps + - name: BASE_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: base-rps + - name: BSC_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: bsc-rps + - name: CELO_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: celo-rps + - name: ETHEREUM_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: ethereum-rps + - name: FANTOM_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: fantom-rps + - name: INJECTIVE_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: injective-rps + - name: KARURA_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: karura-rps + - name: KLAYTN_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: klaytn-rps + - name: MOONBEAM_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: moonbeam-rps + - name: NEAR_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: near-rps + - name: OASIS_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: oasis-rps + - name: OPTIMISM_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: optimism-rps + - name: POLYGON_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: polygon-rps + - name: SEI_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: sei-rps + - name: SOLANA_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: solana-rps + - name: SUI_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: sui-rps + - name: TERRA_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: terra-rps + - name: TERRA2_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: terra2-rps + - name: XPLA_RPS + valueFrom: + configMapKeyRef: + name: event-watcher + key: xpla-rps resources: limits: memory: {{ .RESOURCES_LIMITS_MEMORY }} diff --git a/event-watcher/.env.sample b/event-watcher/.env.sample index 32140dab..4421a1b0 100644 --- a/event-watcher/.env.sample +++ b/event-watcher/.env.sample @@ -57,4 +57,30 @@ SOLANA_RPC= SUI_RPC= TERRA_RPC= TERRA2_RPC= -XPLA_RPC= \ No newline at end of file +XPLA_RPC= + +#RPS +ACALA_RPS=10 +ALGORAND_RPS=10 +APTOS_RPS=10 +ARBITRUM_RPS=10 +AVALANCHE_RPS=10 +BASE_RPS=10 +BSC_RPS=10 +CELO_RPS=10 +ETHEREUM_RPS=10 +FANTOM_RPS=10 +INJECTIVE_RPS=10 +KARURA_RPS=10 +KLAYTN_RPS=10 +MOONBEAM_RPS=10 +NEAR_RPS=10 +OASIS_RPS=10 +OPTIMISM_RPS=10 +POLYGON_RPS=10 +SEI_RPS=10 +SOLANA_RPS=10 +SUI_RPS=10 +TERRA_RPS=10 +TERRA2_RPS=10 +XPLA_RPS=10 \ No newline at end of file diff --git a/event-watcher/package-lock.json b/event-watcher/package-lock.json index c55647c8..d07b59a6 100644 --- a/event-watcher/package-lock.json +++ b/event-watcher/package-lock.json @@ -19,6 +19,7 @@ "algosdk": "^2.4.0", "aptos": "^1.4.0", "axios": "^1.2.1", + "axios-rate-limit": "1.3.0", "bs58": "^5.0.0", "dotenv": "^16.0.3", "fastify": "^4.21.0", @@ -5757,6 +5758,14 @@ "proxy-from-env": "^1.1.0" } }, + "node_modules/axios-rate-limit": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/axios-rate-limit/-/axios-rate-limit-1.3.0.tgz", + "integrity": "sha512-cKR5wTbU/CeeyF1xVl5hl6FlYsmzDVqxlN4rGtfO5x7J83UxKDckudsW0yW21/ZJRcO0Qrfm3fUFbhEbWTLayw==", + "peerDependencies": { + "axios": "*" + } + }, "node_modules/babel-jest": { "version": "29.6.2", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.6.2.tgz", diff --git a/event-watcher/package.json b/event-watcher/package.json index dcf72137..eb7f4877 100644 --- a/event-watcher/package.json +++ b/event-watcher/package.json @@ -13,36 +13,37 @@ }, "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", - "@google-cloud/bigtable": "^4.1.0", - "@google-cloud/pubsub": "^3.4.1", - "@mysten/sui.js": "^0.33.0", - "@solana/web3.js": "^1.73.0", - "algosdk": "^2.4.0", - "aptos": "^1.4.0", - "axios": "^1.2.1", - "bs58": "^5.0.0", - "dotenv": "^16.0.3", - "fastify": "^4.21.0", - "firebase-admin": "^11.4.0", - "js-sha512": "^0.8.0", - "mongodb": "^5.7.0", - "near-api-js": "^1.1.0", - "ora": "^5.4.1", - "winston": "^3.8.2", - "zod": "^3.20.2" + "@celo-tools/celo-ethers-wrapper": "0.3.0", + "@certusone/wormhole-sdk": "0.9.22", + "@fastify/swagger": "8.8.0", + "@google-cloud/bigtable": "4.1.0", + "@google-cloud/pubsub": "3.4.1", + "@mysten/sui.js": "0.33.0", + "@solana/web3.js": "1.73.0", + "algosdk": "2.4.0", + "aptos": "1.4.0", + "axios": "1.2.1", + "axios-rate-limit": "1.3.0", + "bs58": "5.0.0", + "dotenv": "16.0.3", + "fastify": "4.21.0", + "firebase-admin": "11.4.0", + "js-sha512": "0.8.0", + "mongodb": "5.7.0", + "near-api-js": "1.1.0", + "ora": "5.4.1", + "winston": "3.8.2", + "zod": "3.20.2" }, "devDependencies": { - "@jest/globals": "^29.3.1", - "@typescript-eslint/eslint-plugin": "^6.7.2", - "@typescript-eslint/parser": "^6.7.2", - "add": "^2.0.6", - "jest": "^29.3.1", + "@jest/globals": "29.3.1", + "@typescript-eslint/eslint-plugin": "6.7.2", + "@typescript-eslint/parser": "6.7.2", + "add": "2.0.6", + "jest": "29.3.1", "prettier": "2.8.1", - "ts-jest": "^29.0.3", - "ts-node": "^10.9.1", - "typescript": "^4.9.4" + "ts-jest": "29.0.3", + "ts-node": "10.9.1", + "typescript": "4.9.4" } } diff --git a/event-watcher/src/config/index.ts b/event-watcher/src/config/index.ts index 1338fa16..71e13e8e 100644 --- a/event-watcher/src/config/index.ts +++ b/event-watcher/src/config/index.ts @@ -52,6 +52,32 @@ export const env = { TERRA2_RPC: process.env.TERRA2_RPC, WORMCHAIN_RPC: process.env.WORMCHAIN_RPC, XPLA_RPC: process.env.XPLA_RPC, + + ACALA_RPS: process.env.ACALA_RPS, + ALGORAND_RPS: process.env.ALGORAND_RPS, + APTOS_RPS: process.env.APTOS_RPS, + ARBITRUM_RPS: process.env.ARBITRUM_RPS, + AVALANCHE_RPS: process.env.AVALANCHE_RPS, + BASE_RPS: process.env.BASE_RPS, + BSC_RPS: process.env.BSC_RPS, + CELO_RPS: process.env.CELO_RPS, + ETHEREUM_RPS: process.env.ETHEREUM_RPS, + FANTOM_RPS: process.env.FANTOM_RPS, + INJECTIVE_RPS: process.env.INJECTIVE_RPS, + KARURA_RPS: process.env.KARURA_RPS, + KLAYTN_RPS: process.env.KLAYTN_RPS, + MOONBEAM_RPS: process.env.MOONBEAM_RPS, + NEAR_RPS: process.env.NEAR_RPS, + OASIS_RPS: process.env.OASIS_RPS, + OPTIMISM_RPS: process.env.OPTIMISM_RPS, + POLYGON_RPS: process.env.POLYGON_RPS, + SEI_RPS: process.env.SEI_RPS, + SOLANA_RPS: process.env.SOLANA_RPS, + SUI_RPS: process.env.SUI_RPS, + TERRA_RPS: process.env.TERRA_RPS, + TERRA2_RPS: process.env.TERRA2_RPS, + WORMCHAIN_RPS: process.env.WORMCHAIN_RPS, + XPLA_RPS: process.env.XPLA_RPS, } as const; // EVM Chains not supported diff --git a/event-watcher/src/consts.ts b/event-watcher/src/consts.ts index 5e350dbf..57600646 100644 --- a/event-watcher/src/consts.ts +++ b/event-watcher/src/consts.ts @@ -29,10 +29,10 @@ export const TIMEOUT = 0.5 * 1000; export const RPCS_BY_CHAIN_MAINNET: { [key in ChainName]?: string } = { acala: env.ACALA_RPC || 'https://eth-rpc-acala.aca-api.network', algorand: env.ALGORAND_RPC || 'https://mainnet-api.algonode.cloud', - aptos: env.APTOS_RPC || 'https://fullnode.mainnet.aptoslabs.com', - arbitrum: env.ARBITRUM_RPC || 'https://arb1.arbitrum.io/rpc', + aptos: env.APTOS_RPC || 'https://rpc.ankr.com/aptos', + arbitrum: env.ARBITRUM_RPC || 'https://rpc.ankr.com/arbitrum', avalanche: env.AVALANCHE_RPC || 'https://rpc.ankr.com/avalanche', - base: env.BASE_RPC || 'https://rpc.ankr.com/base', + base: env.BASE_RPC || 'https://mainnet.base.org', bsc: env.BSC_RPC || 'https://rpc.ankr.com/bsc_testnet_chapel', celo: env.CELO_RPC || 'https://forno.celo.org', ethereum: env.ETHEREUM_RPC || 'https://eth.llamarpc.com', // 'https://svc.blockdaemon.com/ethereum/mainnet/native', @@ -45,9 +45,9 @@ export const RPCS_BY_CHAIN_MAINNET: { [key in ChainName]?: string } = { oasis: env.OASIS_RPC || 'https://emerald.oasis.dev', optimism: env.OPTIMISM_RPC || 'https://rpc.ankr.com/optimism', polygon: env.POLYGON_RPC || 'https://rpc.ankr.com/polygon', - sei: env.SEI_RPC || 'https://sei-rest.brocha.in', // https://docs.sei.io/develop/resources + sei: env.SEI_RPC || 'https://rpc.ankr.com/sei', // https://docs.sei.io/develop/resources solana: env.SOLANA_RPC || 'https://api.mainnet-beta.solana.com', - sui: env.SUI_RPC || 'https://rpc.mainnet.sui.io', + sui: env.SUI_RPC || 'https://rpc.ankr.com/sui', terra: env.TERRA_RPC || 'https://terra-classic-fcd.publicnode.com', // 'https://columbus-fcd.terra.dev', terra2: env.TERRA2_RPC || 'https://phoenix-lcd.terra.dev', wormchain: env.WORMCHAIN_RPC || 'https://wormchain-rpc.quickapi.com', @@ -120,3 +120,58 @@ export const GUARDIAN_RPC_HOSTS = [ 'https://wormhole-v2-mainnet-api.chainlayer.network', 'https://wormhole-v2-mainnet-api.staking.fund', ]; + +export const DEFAULT_RPS = 30; + +export const RPS_BY_CHAIN_MAINNET: { [key in ChainName]?: number } = { + acala: Number(env.ACALA_RPS) || DEFAULT_RPS, + algorand: Number(env.ALGORAND_RPS) || DEFAULT_RPS, + aptos: Number(env.APTOS_RPS) || DEFAULT_RPS, + arbitrum: Number(env.ARBITRUM_RPS) || DEFAULT_RPS, + avalanche: Number(env.AVALANCHE_RPS) || DEFAULT_RPS, + base: Number(env.BASE_RPS) || DEFAULT_RPS, + celo: Number(env.CELO_RPS) || DEFAULT_RPS, + ethereum: Number(env.CELO_RPS) || DEFAULT_RPS, + fantom: Number(env.FANTOM_RPS) || DEFAULT_RPS, + injective: Number(env.INJECTIVE_RPS) || DEFAULT_RPS, + klaytn: Number(env.KLAYTN_RPS) || DEFAULT_RPS, + moonbeam: Number(env.MOONBEAM_RPS) || DEFAULT_RPS, + near: Number(env.NEAR_RPS) || DEFAULT_RPS, + oasis: Number(env.OASIS_RPS) || DEFAULT_RPS, + polygon: Number(env.POLYGON_RPS) || DEFAULT_RPS, + sei: Number(env.SEI_RPS) || DEFAULT_RPS, + solana: Number(env.SOLANA_RPS) || DEFAULT_RPS, + sui: Number(env.SUI_RPS) || DEFAULT_RPS, + terra: Number(env.TERRA_RPS) || DEFAULT_RPS, + terra2: Number(env.TERRA2_RPS) || DEFAULT_RPS, + wormchain: Number(env.WORMCHAIN_RPS) || DEFAULT_RPS, + xpla: Number(env.XPLA_RPS) || DEFAULT_RPS, +} as const; + +export const RPS_BY_CHAIN_TESTNET: { [key in ChainName]?: number } = { + acala: Number(env.ACALA_RPS) || DEFAULT_RPS, + algorand: Number(env.ALGORAND_RPS) || DEFAULT_RPS, + aptos: Number(env.APTOS_RPS) || DEFAULT_RPS, + arbitrum: Number(env.ARBITRUM_RPS) || DEFAULT_RPS, + avalanche: Number(env.AVALANCHE_RPS) || DEFAULT_RPS, + base: Number(env.BASE_RPS) || DEFAULT_RPS, + celo: Number(env.CELO_RPS) || DEFAULT_RPS, + ethereum: Number(env.CELO_RPS) || DEFAULT_RPS, + fantom: Number(env.FANTOM_RPS) || DEFAULT_RPS, + injective: Number(env.INJECTIVE_RPS) || DEFAULT_RPS, + klaytn: Number(env.KLAYTN_RPS) || DEFAULT_RPS, + moonbeam: Number(env.MOONBEAM_RPS) || DEFAULT_RPS, + near: Number(env.NEAR_RPS) || DEFAULT_RPS, + oasis: Number(env.OASIS_RPS) || DEFAULT_RPS, + polygon: Number(env.POLYGON_RPS) || DEFAULT_RPS, + sei: Number(env.SEI_RPS) || DEFAULT_RPS, + solana: Number(env.SOLANA_RPS) || DEFAULT_RPS, + sui: Number(env.SUI_RPS) || DEFAULT_RPS, + terra: Number(env.TERRA_RPS) || DEFAULT_RPS, + terra2: Number(env.TERRA2_RPS) || DEFAULT_RPS, + wormchain: Number(env.WORMCHAIN_RPS) || DEFAULT_RPS, + xpla: Number(env.XPLA_RPS) || DEFAULT_RPS, +} as const; + +export const NETWORK_RPS_BY_CHAIN = + NETWORK === 'testnet' ? RPS_BY_CHAIN_TESTNET : RPS_BY_CHAIN_MAINNET; diff --git a/event-watcher/src/watchers/ArbitrumWatcher.ts b/event-watcher/src/watchers/ArbitrumWatcher.ts index 86af6c26..2148ee04 100644 --- a/event-watcher/src/watchers/ArbitrumWatcher.ts +++ b/event-watcher/src/watchers/ArbitrumWatcher.ts @@ -1,4 +1,3 @@ -import axios from 'axios'; import { AXIOS_CONFIG_JSON, NETWORK_RPCS_BY_CHAIN } from '../consts'; import { EVMWatcher } from './EVMWatcher'; @@ -30,7 +29,7 @@ export class ArbitrumWatcher extends EVMWatcher { // This gets the latest L2 block so we can get the associated L1 block number const l1Result: BlockByNumberResult = ( - await axios.post( + await this.http.post( this.rpc, [ { diff --git a/event-watcher/src/watchers/BaseWatcher.ts b/event-watcher/src/watchers/BaseWatcher.ts index e429baa5..1f99d639 100644 --- a/event-watcher/src/watchers/BaseWatcher.ts +++ b/event-watcher/src/watchers/BaseWatcher.ts @@ -1,23 +1,27 @@ import { ChainName } from '@certusone/wormhole-sdk/lib/cjs/utils/consts'; import { INITIAL_DEPLOYMENT_BLOCK_BY_CHAIN, sleep } from '../common'; import { z } from 'zod'; -import { TIMEOUT } from '../consts'; +import { DEFAULT_RPS, NETWORK_RPS_BY_CHAIN, TIMEOUT } from '../consts'; import { DBOptionTypes, WHTransaction, VaasByBlock, WHTransferRedeemed } from '../databases/types'; import { getLogger, WormholeLogger } from '../utils/logger'; import { SNSOptionTypes } from '../services/SNS/types'; import { WatcherImplementation } from './types'; -import { env } from '../config'; +import axios from 'axios'; +import rateLimit, { type RateLimitedAxiosInstance } from 'axios-rate-limit'; -const isDev = env.NODE_ENV !== 'production'; abstract class BaseWatcher implements WatcherImplementation { public logger: WormholeLogger; maximumBatchSize: number = 100; sns?: SNSOptionTypes; db?: DBOptionTypes; stopWatcher: boolean = false; + http: RateLimitedAxiosInstance; constructor(public chain: ChainName) { this.logger = getLogger(chain); + + const rps = NETWORK_RPS_BY_CHAIN[this.chain] || DEFAULT_RPS; + this.http = rateLimit(axios.create(), { maxRPS: rps }); } abstract getFinalizedBlockNumber(): Promise; @@ -88,11 +92,6 @@ abstract class BaseWatcher implements WatcherImplementation { break; } - if (isDev) { - // Delay for 1 second in dev mode to avoid rate limiting - await new Promise((resolve) => setTimeout(resolve, 1000)); - } - try { if (fromBlock !== null && toBlock !== null && fromBlock <= toBlock) { // fetch logs for the block range, inclusive of toBlock diff --git a/event-watcher/src/watchers/CosmwasmWatcher.ts b/event-watcher/src/watchers/CosmwasmWatcher.ts index 3b533251..ade1fe5f 100644 --- a/event-watcher/src/watchers/CosmwasmWatcher.ts +++ b/event-watcher/src/watchers/CosmwasmWatcher.ts @@ -1,5 +1,4 @@ import { CosmWasmChainName } from '@certusone/wormhole-sdk/lib/cjs/utils/consts'; -import axios from 'axios'; import { AXIOS_CONFIG_JSON, NETWORK_CONTRACTS, NETWORK_RPCS_BY_CHAIN } from '../consts'; import { makeBlockKey, makeVaaKey, makeWHTransaction } from '../databases/utils'; import BaseWatcher from './BaseWatcher'; @@ -40,7 +39,7 @@ export class CosmwasmWatcher extends BaseWatcher { } override async getFinalizedBlockNumber(): Promise { - const result = (await axios.get(`${this.rpc}/${this.latestBlockTag}`)).data; + const result = (await this.http.get(`${this.rpc}/${this.latestBlockTag}`)).data; if (result && result.block.header.height) { const blockHeight: number = parseInt(result.block.header.height); if (blockHeight !== this.latestBlockHeight) { @@ -69,7 +68,7 @@ export class CosmwasmWatcher extends BaseWatcher { for (let blockNumber = fromBlock; blockNumber <= toBlock; blockNumber++) { this.logger.debug('Getting block number ' + blockNumber); const blockResult: CosmwasmBlockResult = ( - await axios.get(`${this.rpc}/${this.getBlockTag}${blockNumber}`) + await this.http.get(`${this.rpc}/${this.getBlockTag}${blockNumber}`) ).data; if (!blockResult || !blockResult.block.data) { throw new Error('bad result for block ${blockNumber}'); @@ -95,7 +94,7 @@ export class CosmwasmWatcher extends BaseWatcher { // console.log('Attempting to get hash', `${this.rpc}/${this.hashTag}${hash}`); try { const hashResult: CosmwasmHashResult = ( - await axios.get(`${this.rpc}/${this.hashTag}${hash}`, AXIOS_CONFIG_JSON) + await this.http.get(`${this.rpc}/${this.hashTag}${hash}`, AXIOS_CONFIG_JSON) ).data; if (hashResult && hashResult.tx_response.events) { const numEvents = hashResult.tx_response.events.length; @@ -173,7 +172,7 @@ export class CosmwasmWatcher extends BaseWatcher { this.logger.debug('Getting block number ' + blockNumber); const blockResult: CosmwasmBlockResult = ( - await axios.get(`${this.rpc}/${this.getBlockTag}${blockNumber}`) + await this.http.get(`${this.rpc}/${this.getBlockTag}${blockNumber}`) ).data; if (!blockResult || !blockResult.block.data) { @@ -197,7 +196,7 @@ export class CosmwasmWatcher extends BaseWatcher { // console.log('Attempting to get hash', `${this.rpc}/${this.hashTag}${hash}`); try { const hashResult: CosmwasmHashResult = ( - await axios.get(`${this.rpc}/${this.hashTag}${hash}`, AXIOS_CONFIG_JSON) + await this.http.get(`${this.rpc}/${this.hashTag}${hash}`, AXIOS_CONFIG_JSON) ).data; if (hashResult && hashResult.tx_response.events) { diff --git a/event-watcher/src/watchers/EVMWatcher.ts b/event-watcher/src/watchers/EVMWatcher.ts index 15a965be..ef0d54c3 100644 --- a/event-watcher/src/watchers/EVMWatcher.ts +++ b/event-watcher/src/watchers/EVMWatcher.ts @@ -1,7 +1,7 @@ import { Implementation__factory } from '@certusone/wormhole-sdk/lib/cjs/ethers-contracts/factories/Implementation__factory'; import { EVMChainName, coalesceChainId } from '@certusone/wormhole-sdk/lib/cjs/utils/consts'; import { Log } from '@ethersproject/abstract-provider'; -import axios from 'axios'; + import { BigNumber } from 'ethers'; import { AXIOS_CONFIG_JSON, NETWORK_CONTRACTS, NETWORK_RPCS_BY_CHAIN } from '../consts'; import { WHTransaction, VaasByBlock, WHTransferRedeemed } from '../databases/types'; @@ -56,7 +56,7 @@ export class EVMWatcher extends BaseWatcher { throw new Error(`${this.chain} RPC is not defined!`); } let result = ( - await axios.post( + await this.http.post( rpc, [ { @@ -121,7 +121,7 @@ export class EVMWatcher extends BaseWatcher { params: [`0x${blockNumber.toString(16)}`, false], }); } - const results = (await axios.post(rpc, reqs, AXIOS_CONFIG_JSON))?.data; + const results = (await this.http.post(rpc, reqs, AXIOS_CONFIG_JSON))?.data; if (results && results.length) { // Convert to Ethers compatible type return results.map( @@ -175,7 +175,7 @@ export class EVMWatcher extends BaseWatcher { throw new Error(`${this.chain} RPC is not defined!`); } const result = ( - await axios.post( + await this.http.post( rpc, [ { diff --git a/event-watcher/src/watchers/InjectiveExplorerWatcher.ts b/event-watcher/src/watchers/InjectiveExplorerWatcher.ts index 7a93d96d..3b924fd7 100644 --- a/event-watcher/src/watchers/InjectiveExplorerWatcher.ts +++ b/event-watcher/src/watchers/InjectiveExplorerWatcher.ts @@ -1,4 +1,3 @@ -import axios from 'axios'; import { NETWORK_CONTRACTS, NETWORK_RPCS_BY_CHAIN } from '../consts'; import { WHTransaction, VaasByBlock, WHTransferRedeemed } from '../databases/types'; import { makeBlockKey, makeVaaKey, makeWHTransaction } from '../databases/utils'; @@ -31,7 +30,7 @@ export class InjectiveExplorerWatcher extends BaseWatcher { } override async getFinalizedBlockNumber(): Promise { - const result: ExplorerBlocks = (await axios.get(`${this.rpc}/${this.latestBlockTag}`)).data; + const result: ExplorerBlocks = (await this.http.get(`${this.rpc}/${this.latestBlockTag}`)).data; if (result && result.paging.total) { const blockHeight: number = result.paging.total; if (blockHeight !== this.latestBlockHeight) { @@ -66,7 +65,7 @@ export class InjectiveExplorerWatcher extends BaseWatcher { const url: string = `${this.rpc}/${this.contractTag}${address}?skip=${skip}&limit=${limit}`; // this.logger.debug(`Query string = ${url}`); const bulkTxnResult = ( - await axios.get(url, { + await this.http.get(url, { headers: { 'User-Agent': 'Mozilla/5.0', }, @@ -159,7 +158,7 @@ export class InjectiveExplorerWatcher extends BaseWatcher { this.logger.debug(`Adding filler for block ${toBlock}`); const blkUrl = `${this.rpc}/${this.getBlockTag}${toBlock}`; this.logger.debug(`Query string for block = ${blkUrl}`); - const result = (await axios.get(blkUrl)).data; + const result = (await this.http.get(blkUrl)).data; if (!result) { throw new Error(`Unable to get block information for block ${toBlock}`); } @@ -192,7 +191,7 @@ export class InjectiveExplorerWatcher extends BaseWatcher { const url: string = `${this.rpc}/${this.contractTag}${address}?skip=${skip}&limit=${limit}`; // this.logger.debug(`Query string = ${url}`); const bulkTxnResult = ( - await axios.get(url, { + await this.http.get(url, { headers: { 'User-Agent': 'Mozilla/5.0', }, diff --git a/event-watcher/src/watchers/MoonbeamWatcher.ts b/event-watcher/src/watchers/MoonbeamWatcher.ts index 3aee114b..a7c076d0 100644 --- a/event-watcher/src/watchers/MoonbeamWatcher.ts +++ b/event-watcher/src/watchers/MoonbeamWatcher.ts @@ -1,5 +1,4 @@ import { sleep } from '../common'; -import axios from 'axios'; import { AXIOS_CONFIG_JSON, NETWORK_RPCS_BY_CHAIN } from '../consts'; import { EVMWatcher } from './EVMWatcher'; @@ -21,7 +20,7 @@ export class MoonbeamWatcher extends EVMWatcher { const blockFromNumber = await this.getBlock(latestBlock); isBlockFinalized = ( - await axios.post( + await this.http.post( NETWORK_RPCS_BY_CHAIN.moonbeam!, [ { diff --git a/event-watcher/src/watchers/PolygonWatcher.ts b/event-watcher/src/watchers/PolygonWatcher.ts index d7565554..e05fb6d0 100644 --- a/event-watcher/src/watchers/PolygonWatcher.ts +++ b/event-watcher/src/watchers/PolygonWatcher.ts @@ -12,7 +12,7 @@ export class PolygonWatcher extends EVMWatcher { // ]); // const callData = rootChain.encodeFunctionData('getLastChildBlock'); // const callResult = ( - // await axios.post( + // await this.http.post( // POLYGON_ROOT_CHAIN_RPC, // [ // { diff --git a/event-watcher/src/watchers/SeiExplorerWatcher.ts b/event-watcher/src/watchers/SeiExplorerWatcher.ts index c7ca53be..d953ded5 100644 --- a/event-watcher/src/watchers/SeiExplorerWatcher.ts +++ b/event-watcher/src/watchers/SeiExplorerWatcher.ts @@ -1,4 +1,3 @@ -import axios from 'axios'; import { sleep } from '../common'; import { AXIOS_CONFIG_JSON, @@ -55,7 +54,7 @@ export class SeiExplorerWatcher extends CosmwasmWatcher { const query = this.makeGraphQLQuery(0, 1); // this.logger.debug(`Query string = ${JSON.stringify(query)}`); const bulkTxnResult = ( - await axios.post( + await this.http.post( SEI_EXPLORER_GRAPHQL, query, AXIOS_CONFIG_JSON, @@ -90,7 +89,7 @@ export class SeiExplorerWatcher extends CosmwasmWatcher { const query = this.makeGraphQLQuery(skip, limit); // this.logger.debug(`Query string = ${JSON.stringify(query)}`); const bulkTxnResult = ( - await axios.post( + await this.http.post( SEI_EXPLORER_GRAPHQL, query, AXIOS_CONFIG_JSON, @@ -130,12 +129,12 @@ export class SeiExplorerWatcher extends CosmwasmWatcher { try { // try hitting the node first hashResult = ( - await axios.get(`${this.rpc}/${this.hashTag}${hash}`, AXIOS_CONFIG_JSON) + await this.http.get(`${this.rpc}/${this.hashTag}${hash}`, AXIOS_CONFIG_JSON) ).data; } catch (e: any) { if (e?.response?.status === 404) { // the node is mysteriously missing some transactions, but so is this ='( - hashResult = (await axios.get(`${SEI_EXPLORER_TXS}${hash}`, AXIOS_CONFIG_JSON)) + hashResult = (await this.http.get(`${SEI_EXPLORER_TXS}${hash}`, AXIOS_CONFIG_JSON)) .data; } } @@ -225,7 +224,7 @@ export class SeiExplorerWatcher extends CosmwasmWatcher { const query = this.makeGraphQLQuery(skip, limit); // this.logger.debug(`Query string = ${JSON.stringify(query)}`); const bulkTxnResult = ( - await axios.post( + await this.http.post( SEI_EXPLORER_GRAPHQL, query, AXIOS_CONFIG_JSON, @@ -262,12 +261,12 @@ export class SeiExplorerWatcher extends CosmwasmWatcher { try { // try hitting the node first hashResult = ( - await axios.get(`${this.rpc}/${this.hashTag}${hash}`, AXIOS_CONFIG_JSON) + await this.http.get(`${this.rpc}/${this.hashTag}${hash}`, AXIOS_CONFIG_JSON) ).data; } catch (e: any) { if (e?.response?.status === 404) { // the node is mysteriously missing some transactions, but so is this ='( - hashResult = (await axios.get(`${SEI_EXPLORER_TXS}${hash}`, AXIOS_CONFIG_JSON)) + hashResult = (await this.http.get(`${SEI_EXPLORER_TXS}${hash}`, AXIOS_CONFIG_JSON)) .data; } } diff --git a/event-watcher/src/watchers/TerraExplorerWatcher.ts b/event-watcher/src/watchers/TerraExplorerWatcher.ts index f4bd74db..9ddef20a 100644 --- a/event-watcher/src/watchers/TerraExplorerWatcher.ts +++ b/event-watcher/src/watchers/TerraExplorerWatcher.ts @@ -1,5 +1,4 @@ import { CosmWasmChainName } from '@certusone/wormhole-sdk/lib/cjs/utils/consts'; -import axios from 'axios'; import { AXIOS_CONFIG_JSON, NETWORK_CONTRACTS, NETWORK_RPCS_BY_CHAIN } from '../consts'; import { WHTransaction, VaasByBlock, WHTransferRedeemed } from '../databases/types'; import { makeBlockKey, makeVaaKey, makeWHTransaction } from '../databases/utils'; @@ -29,7 +28,8 @@ export class TerraExplorerWatcher extends BaseWatcher { } override async getFinalizedBlockNumber(): Promise { - const result = (await axios.get(`${this.rpc}/${this.latestBlockTag}`, AXIOS_CONFIG_JSON)).data; + const result = (await this.http.get(`${this.rpc}/${this.latestBlockTag}`, AXIOS_CONFIG_JSON)) + .data; if (result && result.block.header.height) { const blockHeight: number = parseInt(result.block.header.height); if (blockHeight !== this.latestBlockHeight) { @@ -62,7 +62,7 @@ export class TerraExplorerWatcher extends BaseWatcher { const url: string = `${this.rpc}/${this.allTxsTag}offset=${offset}&limit=${limit}&account=${address}`; // this.logger.debug(`Query string = ${url}`); const bulkTxnResult: BulkTxnResult = ( - await axios.get(url, { + await this.http.get(url, { headers: { 'User-Agent': 'Mozilla/5.0', 'Accept-Encoding': 'application/json', @@ -150,7 +150,7 @@ export class TerraExplorerWatcher extends BaseWatcher { // become the new starting point for subsequent calls. this.logger.debug(`Adding filler for block ${toBlock}`); const blkUrl = `${this.rpc}/${this.getBlockTag}${toBlock}`; - const result: CosmwasmBlockResult = (await axios.get(blkUrl, AXIOS_CONFIG_JSON)).data; + const result: CosmwasmBlockResult = (await this.http.get(blkUrl, AXIOS_CONFIG_JSON)).data; if (!result) { throw new Error(`Unable to get block information for block ${toBlock}`); } @@ -182,7 +182,7 @@ export class TerraExplorerWatcher extends BaseWatcher { const url: string = `${this.rpc}/${this.allTxsTag}offset=${offset}&limit=${limit}&account=${address}`; // this.logger.debug(`Query string = ${url}`); const bulkTxnResult: BulkTxnResult = ( - await axios.get(url, { + await this.http.get(url, { headers: { 'User-Agent': 'Mozilla/5.0', 'Accept-Encoding': 'application/json',