Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/base-watcher-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/watcher': minor
---

Add Base watcher support and switch the default Base RPC config to a production-provider placeholder.
11 changes: 10 additions & 1 deletion config/default.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
network: '' # which scanner network used in this watcher ergo/cardano/bitcoin/ethereum
network: '' # which scanner network used in this watcher ergo/cardano/bitcoin/base/ethereum
observation:
# confirmation: 60 # number of required block confirmations to create the commitment after observing an event
validThreshold: 259200 # Observations that have not been triggered will not be processed after this period (in seconds, converted to block count based on selected network block time)
Expand Down Expand Up @@ -58,6 +58,15 @@ cardano:
projectId: '' # blockfrost project Id
timeout: 10 # blockfrost request timeout
interval: 20 # blockfrost check timeout
base:
type: '' # options: rpc
initial:
height: -1 # initial height of scanning
interval: 20 # scanning interval (in seconds)
rpc:
url: '' # rpc url (use a production provider; the public Base endpoint is rate-limited)
timeout: 10 # rpc request timeout (in seconds)
# authToken: # rpc auth token
ethereum:
type: '' # options: rpc
initial:
Expand Down
3 changes: 3 additions & 0 deletions docker/custom-environment-variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ cardano:
authToken: 'KOIOS_AUTH_TOKEN'
blockfrost:
projectId: 'BLOCKFROST_PROJECT_ID'
base:
rpc:
authToken: 'BASE_RPC_AUTH_TOKEN'
ethereum:
rpc:
authToken: 'ETHEREUM_RPC_AUTH_TOKEN'
Expand Down
15 changes: 2 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
"@rosen-bridge/discord-notification": "^1.0.0",
"@rosen-bridge/ergo-observation-extractor": "^1.0.4",
"@rosen-bridge/ergo-scanner": "^1.0.3",
"@rosen-bridge/evm-observation-extractor": "^6.0.4",
"@rosen-bridge/evm-observation-extractor": "^6.1.0",
"@rosen-bridge/evm-scanner": "^1.0.3",
"@rosen-bridge/extended-typeorm": "1.0.1",
"@rosen-bridge/firo-observation-extractor": "^0.1.2",
Expand Down
35 changes: 35 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const supportedNetworks: Array<NetworkType> = [
Constants.BITCOIN_CHAIN_NAME,
Constants.BITCOIN_RUNES_CHAIN_NAME,
Constants.DOGE_CHAIN_NAME,
Constants.BASE_CHAIN_NAME,
Constants.ETHEREUM_CHAIN_NAME,
Constants.BINANCE_CHAIN_NAME,
Constants.FIRO_CHAIN_NAME,
Expand All @@ -27,6 +28,7 @@ interface ConfigType {
cardano: CardanoConfig;
bitcoin: BitcoinConfig;
bitcoinRunes: BitcoinRunesConfig;
base: BaseConfig;
ethereum: EthereumConfig;
binance: BinanceConfig;
firo: FiroConfig;
Expand Down Expand Up @@ -235,6 +237,7 @@ class Config {
[Constants.BITCOIN_CHAIN_NAME]: Constants.BITCOIN_BLOCK_TIME,
[Constants.BITCOIN_RUNES_CHAIN_NAME]: Constants.BITCOIN_BLOCK_TIME,
[Constants.CARDANO_CHAIN_NAME]: Constants.CARDANO_BLOCK_TIME,
[Constants.BASE_CHAIN_NAME]: Constants.BASE_BLOCK_TIME,
[Constants.BINANCE_CHAIN_NAME]: Constants.BINANCE_BLOCK_TIME,
[Constants.ETHEREUM_CHAIN_NAME]: Constants.ETHEREUM_BLOCK_TIME,
[Constants.DOGE_CHAIN_NAME]: Constants.DOGE_BLOCK_TIME,
Expand Down Expand Up @@ -579,6 +582,35 @@ class EthereumConfig {
}
}

class BaseConfig {
type: string;
initialHeight: number;
interval: number;
rpc?: {
url: string;
timeout: number;
authToken?: string;
};

constructor(network: string) {
this.type = config.get<string>('base.type');
if (network === Constants.BASE_CHAIN_NAME) {
this.initialHeight = getRequiredNumber('base.initial.height');
this.interval = getRequiredNumber('base.interval');
if (this.type == Constants.EVM_RPC_TYPE) {
const url = getRequiredString('base.rpc.url');
const timeout = getRequiredNumber('base.rpc.timeout');
const authToken = getOptionalString('base.rpc.authToken', undefined);
this.rpc = { url, timeout, authToken };
} else {
throw new Error(
`Improperly configured. base configuration type is invalid available choices are '${Constants.EVM_RPC_TYPE}'`
);
}
}
}
}

class BinanceConfig {
type: string;
initialHeight: number;
Expand Down Expand Up @@ -747,6 +779,7 @@ const getConfig = (): ConfigType => {
const bitcoin = new BitcoinConfig(general.networkWatcher);
const bitcoinRunes = new BitcoinRunesConfig(general.networkWatcher);
const doge = new DogeConfig(general.networkWatcher);
const base = new BaseConfig(general.networkWatcher);
const ethereum = new EthereumConfig(general.networkWatcher);
const binance = new BinanceConfig(general.networkWatcher);
const firo = new FiroConfig(general.networkWatcher);
Expand All @@ -762,6 +795,7 @@ const getConfig = (): ConfigType => {
bitcoin,
bitcoinRunes,
doge,
base,
ethereum,
binance,
firo,
Expand All @@ -783,6 +817,7 @@ export {
CardanoConfig,
BitcoinConfig,
BitcoinRunesConfig,
BaseConfig,
EthereumConfig,
BinanceConfig,
FiroConfig,
Expand Down
2 changes: 2 additions & 0 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const CARDANO_CHAIN_NAME = 'cardano';
export const BITCOIN_CHAIN_NAME = 'bitcoin';
export const BITCOIN_RUNES_CHAIN_NAME = 'bitcoin-runes';
export const DOGE_CHAIN_NAME = 'doge';
export const BASE_CHAIN_NAME = 'base';
export const ETHEREUM_CHAIN_NAME = 'ethereum';
export const BINANCE_CHAIN_NAME = 'binance';
export const FIRO_CHAIN_NAME = 'firo';
Expand All @@ -32,6 +33,7 @@ export const BINANCE_BLOCK_TIME = 0.75;
export const BITCOIN_BLOCK_TIME = 600;
export const CARDANO_BLOCK_TIME = 20;
export const ERGO_BLOCK_TIME = 120;
export const BASE_BLOCK_TIME = 2;
export const ETHEREUM_BLOCK_TIME = 12;
export const DOGE_BLOCK_TIME = 60;
export const FIRO_BLOCK_TIME = 150;
Expand Down
7 changes: 7 additions & 0 deletions src/jobs/initScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
bitcoin: bitcoinConfig,
bitcoinRunes: bitcoinRunesConfig,
doge: dogeConfig,
base: baseConfig,
ethereum: ethereumConfig,
binance: binanceConfig,
firo: firoConfig,
Expand Down Expand Up @@ -75,6 +76,12 @@ export const scannerInit = () => {
scanner.getObservationScanner() as EvmRpcScanner
).then(() => null);
break;
case Constants.BASE_CHAIN_NAME:
scanningJob(
baseConfig.interval,
scanner.getObservationScanner() as EvmRpcScanner
).then(() => null);
break;
case Constants.BINANCE_CHAIN_NAME:
scanningJob(
binanceConfig.interval,
Expand Down
1 change: 1 addition & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type NetworkType =
| typeof Constants.BITCOIN_CHAIN_NAME
| typeof Constants.BITCOIN_RUNES_CHAIN_NAME
| typeof Constants.DOGE_CHAIN_NAME
| typeof Constants.BASE_CHAIN_NAME
| typeof Constants.ETHEREUM_CHAIN_NAME
| typeof Constants.BINANCE_CHAIN_NAME
| typeof Constants.FIRO_CHAIN_NAME;
Expand Down
7 changes: 7 additions & 0 deletions src/utils/healthCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { LogLevelHealthCheck } from '@rosen-bridge/log-level-check';
import { Transaction } from '../api/Transaction';
import { getConfig } from '../config/config';
import {
BASE_BLOCK_TIME,
BASE_CHAIN_NAME,
BINANCE_BLOCK_TIME,
BINANCE_CHAIN_NAME,
BITCOIN_BLOCK_TIME,
Expand Down Expand Up @@ -238,6 +240,11 @@ class HealthCheckSingleton {
chainBlockTime = DOGE_BLOCK_TIME;
updateInterval = getConfig().doge.interval;
break;
case BASE_CHAIN_NAME:
chainName = BASE_CHAIN_NAME;
chainBlockTime = BASE_BLOCK_TIME;
updateInterval = getConfig().base.interval;
break;
case ETHEREUM_CHAIN_NAME:
chainName = ETHEREUM_CHAIN_NAME;
chainBlockTime = ETHEREUM_BLOCK_TIME;
Expand Down
12 changes: 10 additions & 2 deletions src/utils/networkConnectorManagers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export const createCardanoBlockfrostNetworkConnectorManager = () => {

/**
* Creates and configures a NetworkConnectorManager instance for EVM-based scanners (Ethereum/Binance)
* @param chainName - The name of the chain to create a connector for (ethereum/binance)
* @param chainName - The name of the chain to create a connector for (base/ethereum/binance)
*/
export const createEvmNetworkConnectorManager = (chainName: string) => {
const networkConnectorManager =
Expand All @@ -252,7 +252,15 @@ export const createEvmNetworkConnectorManager = (chainName: string) => {
evmLogger
);

if (chainName === 'ethereum' && config.ethereum.rpc) {
if (chainName === 'base' && config.base.rpc) {
networkConnectorManager.addConnector(
new EvmRpcNetwork(
config.base.rpc.url,
config.base.rpc.timeout * 1000,
config.base.rpc.authToken || undefined
)
);
} else if (chainName === 'ethereum' && config.ethereum.rpc) {
networkConnectorManager.addConnector(
new EvmRpcNetwork(
config.ethereum.rpc.url,
Expand Down
36 changes: 36 additions & 0 deletions src/utils/scanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
} from '@rosen-bridge/bitcoin-runes-observation-extractor';

import {
BaseRpcObservationExtractor,
BinanceRpcObservationExtractor,
EthereumRpcObservationExtractor,
} from '@rosen-bridge/evm-observation-extractor';
Expand All @@ -50,6 +51,7 @@ import { dataSource } from '../../config/dataSource';
import {
BinanceConfig,
BitcoinConfig,
BaseConfig,
CardanoConfig,
Config,
EthereumConfig,
Expand Down Expand Up @@ -126,6 +128,7 @@ class CreateScanner {
bitcoin: bitcoinConfig,
bitcoinRunes: bitcoinRunesConfig,
doge: dogeConfig,
base: baseConfig,
ethereum: ethereumConfig,
binance: binanceConfig,
firo: firoConfig,
Expand Down Expand Up @@ -162,6 +165,13 @@ class CreateScanner {
config.observationStoreRawData
);
break;
case Constants.BASE_CHAIN_NAME:
await CreateScanner.instance.createBaseScanner(
baseConfig,
rosenConfig,
config.observationStoreRawData
);
break;
case Constants.BINANCE_CHAIN_NAME:
await CreateScanner.instance.createBinanceScanner(
binanceConfig,
Expand Down Expand Up @@ -557,6 +567,32 @@ class CreateScanner {
}
};

private createBaseScanner = async (
baseConfig: BaseConfig,
rosenConfig: RosenConfig,
observationStoreRawData: boolean
) => {
if (!this.observationScanner) {
if (baseConfig.rpc) {
this.observationScanner = new EvmRpcScanner(Constants.BASE_CHAIN_NAME, {
dataSource,
initialHeight: baseConfig.initialHeight,
network: createEvmNetworkConnectorManager(Constants.BASE_CHAIN_NAME),
logger: loggers.observationScannerLogger,
});

const observationExtractor = new BaseRpcObservationExtractor(
rosenConfig.lockAddress,
dataSource,
TokensConfig.getInstance().getTokenMap(),
loggers.observationExtractorLogger,
observationStoreRawData
);
this.observationScanner.registerExtractor(observationExtractor);
}
}
};

private createBinanceScanner = async (
binanceConfig: BinanceConfig,
rosenConfig: RosenConfig,
Expand Down