tornado-scripts/dist/relayerClient.d.ts

134 lines
4.4 KiB
TypeScript
Raw Permalink Normal View History

import type { NetIdType, TornadoConfig } from './networkConfig';
2024-04-29 15:55:15 +00:00
import { fetchDataOptions } from './providers';
import type { snarkProofs } from './websnark';
2024-09-29 11:24:36 +00:00
import type { CachedRelayerInfo } from './events';
export declare const MIN_FEE = 0.1;
export declare const MAX_FEE = 0.9;
2024-04-29 15:55:15 +00:00
export declare const MIN_STAKE_BALANCE: bigint;
export interface RelayerParams {
ensName: string;
relayerAddress: string;
2024-04-29 15:55:15 +00:00
}
/**
* Info from relayer status
*/
2024-10-16 14:19:49 +00:00
export interface RelayerInfo extends RelayerParams {
2024-04-29 15:55:15 +00:00
netId: NetIdType;
url: string;
hostname: string;
rewardAccount: string;
instances: string[];
stakeBalance?: string;
2024-04-29 15:55:15 +00:00
gasPrice?: number;
ethPrices?: Record<string, string>;
2024-04-29 15:55:15 +00:00
currentQueue: number;
tornadoServiceFee: number;
2024-10-16 14:19:49 +00:00
}
export interface RelayerError {
2024-04-29 15:55:15 +00:00
hostname: string;
relayerAddress?: string;
errorMessage?: string;
hasError: boolean;
2024-10-16 14:19:49 +00:00
}
2024-04-29 15:55:15 +00:00
export interface RelayerStatus {
url: string;
rewardAccount: string;
instances: Record<string, {
instanceAddress: Record<string, string>;
tokenAddress?: string;
symbol: string;
decimals: number;
}>;
2024-04-29 15:55:15 +00:00
gasPrices?: {
fast: number;
additionalProperties?: number;
};
netId: NetIdType;
ethPrices?: Record<string, string>;
2024-04-29 15:55:15 +00:00
tornadoServiceFee: number;
latestBlock?: number;
version: string;
health: {
status: string;
error: string;
errorsLog: any[];
};
currentQueue: number;
}
2024-10-16 14:19:49 +00:00
export interface TornadoWithdrawParams extends snarkProofs {
contract: string;
2024-10-16 14:19:49 +00:00
}
2024-04-29 15:55:15 +00:00
export interface RelayerTornadoWithdraw {
id?: string;
error?: string;
}
export interface RelayerTornadoJobs {
error?: string;
id: string;
type?: string;
status: string;
contract?: string;
proof?: string;
args?: string[];
txHash?: string;
confirmations?: number;
failedReason?: string;
}
/**
const semVerRegex =
/^(?<major>0|[1-9]\d*)\.(?<minor>0|[1-9]\d*)\.(?<patch>0|[1-9]\d*)(?:-(?<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
2024-04-29 15:55:15 +00:00
export interface semanticVersion {
major: string;
minor: string;
patch: string;
prerelease?: string;
buildmetadata?: string;
}
export function parseSemanticVersion(version: string) {
const { groups } = semVerRegex.exec(version) as RegExpExecArray;
return groups as unknown as semanticVersion;
}
export function isRelayerUpdated(relayerVersion: string, netId: NetIdType) {
const { major, patch, prerelease } = parseSemanticVersion(relayerVersion);
// Save backwards compatibility with V4 relayers for Ethereum Mainnet
const requiredMajor = netId === NetId.MAINNET ? '4' : '5';
const isUpdatedMajor = major === requiredMajor;
if (prerelease) return false;
return isUpdatedMajor && (Number(patch) >= 5 || netId !== NetId.MAINNET); // Patch checking - also backwards compatibility for Mainnet
2024-04-29 15:55:15 +00:00
}
**/
export declare function calculateScore({ stakeBalance, tornadoServiceFee }: RelayerInfo): bigint;
2024-04-29 15:55:15 +00:00
export declare function getWeightRandom(weightsScores: bigint[], random: bigint): number;
export type RelayerInstanceList = Record<string, {
instanceAddress: Record<string, string>;
}>;
2024-04-29 15:55:15 +00:00
export declare function getSupportedInstances(instanceList: RelayerInstanceList): string[];
export declare function pickWeightedRandomRelayer(relayers: RelayerInfo[]): RelayerInfo;
2024-04-29 15:55:15 +00:00
export interface RelayerClientConstructor {
tornadoConfig: TornadoConfig;
2024-04-29 15:55:15 +00:00
fetchDataOptions?: fetchDataOptions;
}
export declare class RelayerClient {
tornadoConfig: TornadoConfig;
selectedRelayer?: RelayerInfo;
2024-04-29 15:55:15 +00:00
fetchDataOptions?: fetchDataOptions;
2024-09-29 11:24:36 +00:00
tovarish: boolean;
constructor({ tornadoConfig, fetchDataOptions }: RelayerClientConstructor);
askRelayerStatus({ netId, hostname, url, }: {
netId: NetIdType;
hostname?: string;
url?: string;
2024-04-29 15:55:15 +00:00
}): Promise<RelayerStatus>;
filterRelayer(netId: NetIdType, relayer: CachedRelayerInfo): Promise<RelayerInfo | RelayerError | undefined>;
getValidRelayers(netId: NetIdType, relayers: CachedRelayerInfo[]): Promise<{
2024-04-29 15:55:15 +00:00
validRelayers: RelayerInfo[];
invalidRelayers: RelayerError[];
}>;
pickWeightedRandomRelayer(relayers: RelayerInfo[]): RelayerInfo;
2024-10-16 14:19:49 +00:00
tornadoWithdraw({ contract, proof, args }: TornadoWithdrawParams, callback?: (jobResp: RelayerTornadoWithdraw | RelayerTornadoJobs) => void): Promise<void>;
2024-04-29 15:55:15 +00:00
}