2024-04-29 18:55:15 +03:00
|
|
|
import { NetIdType, Config } from './networkConfig';
|
|
|
|
import { fetchDataOptions } from './providers';
|
|
|
|
import type { snarkProofs } from './websnark';
|
2024-09-21 04:26:50 +03:00
|
|
|
import { CachedRelayerInfo } from './events/base';
|
|
|
|
export declare const MIN_FEE = 0.1;
|
2024-09-26 15:23:55 +03:00
|
|
|
export declare const MAX_FEE = 0.9;
|
2024-04-29 18:55:15 +03:00
|
|
|
export declare const MIN_STAKE_BALANCE: bigint;
|
|
|
|
export interface RelayerParams {
|
|
|
|
ensName: string;
|
2024-09-21 04:26:50 +03:00
|
|
|
relayerAddress: string;
|
2024-04-29 18:55:15 +03:00
|
|
|
}
|
2024-09-21 04:26:50 +03:00
|
|
|
/**
|
|
|
|
* Info from relayer status
|
|
|
|
*/
|
|
|
|
export type RelayerInfo = RelayerParams & {
|
2024-04-29 18:55:15 +03:00
|
|
|
netId: NetIdType;
|
|
|
|
url: string;
|
|
|
|
hostname: string;
|
|
|
|
rewardAccount: string;
|
|
|
|
instances: string[];
|
2024-09-21 04:26:50 +03:00
|
|
|
stakeBalance?: string;
|
2024-04-29 18:55:15 +03:00
|
|
|
gasPrice?: number;
|
|
|
|
ethPrices?: {
|
|
|
|
[key in string]: string;
|
|
|
|
};
|
|
|
|
currentQueue: number;
|
|
|
|
tornadoServiceFee: number;
|
|
|
|
};
|
|
|
|
export type RelayerError = {
|
|
|
|
hostname: string;
|
|
|
|
relayerAddress?: string;
|
|
|
|
errorMessage?: string;
|
2024-09-21 04:26:50 +03:00
|
|
|
hasError: boolean;
|
2024-04-29 18:55:15 +03:00
|
|
|
};
|
|
|
|
export interface RelayerStatus {
|
|
|
|
url: string;
|
|
|
|
rewardAccount: string;
|
|
|
|
instances: {
|
|
|
|
[key in string]: {
|
|
|
|
instanceAddress: {
|
|
|
|
[key in string]: string;
|
|
|
|
};
|
|
|
|
tokenAddress?: string;
|
|
|
|
symbol: string;
|
|
|
|
decimals: number;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
gasPrices?: {
|
|
|
|
fast: number;
|
|
|
|
additionalProperties?: number;
|
|
|
|
};
|
|
|
|
netId: NetIdType;
|
|
|
|
ethPrices?: {
|
|
|
|
[key in string]: string;
|
|
|
|
};
|
|
|
|
tornadoServiceFee: number;
|
|
|
|
latestBlock?: number;
|
|
|
|
version: string;
|
|
|
|
health: {
|
|
|
|
status: string;
|
|
|
|
error: string;
|
|
|
|
errorsLog: any[];
|
|
|
|
};
|
|
|
|
currentQueue: number;
|
|
|
|
}
|
2024-09-26 15:23:55 +03:00
|
|
|
export type TornadoWithdrawParams = snarkProofs & {
|
|
|
|
contract: string;
|
|
|
|
};
|
2024-04-29 18:55:15 +03: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;
|
|
|
|
}
|
2024-09-25 10:31:00 +03:00
|
|
|
/**
|
|
|
|
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 18:55:15 +03:00
|
|
|
export interface semanticVersion {
|
2024-09-25 10:31:00 +03:00
|
|
|
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 18:55:15 +03:00
|
|
|
}
|
2024-09-25 10:31:00 +03:00
|
|
|
**/
|
2024-09-21 04:26:50 +03:00
|
|
|
export declare function calculateScore({ stakeBalance, tornadoServiceFee }: RelayerInfo): bigint;
|
2024-04-29 18:55:15 +03:00
|
|
|
export declare function getWeightRandom(weightsScores: bigint[], random: bigint): number;
|
|
|
|
export type RelayerInstanceList = {
|
|
|
|
[key in string]: {
|
|
|
|
instanceAddress: {
|
|
|
|
[key in string]: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
export declare function getSupportedInstances(instanceList: RelayerInstanceList): string[];
|
2024-09-21 04:26:50 +03:00
|
|
|
export declare function pickWeightedRandomRelayer(relayers: RelayerInfo[]): RelayerInfo;
|
2024-04-29 18:55:15 +03:00
|
|
|
export interface RelayerClientConstructor {
|
|
|
|
netId: NetIdType;
|
|
|
|
config: Config;
|
|
|
|
fetchDataOptions?: fetchDataOptions;
|
|
|
|
}
|
|
|
|
export declare class RelayerClient {
|
|
|
|
netId: NetIdType;
|
|
|
|
config: Config;
|
2024-09-21 04:26:50 +03:00
|
|
|
selectedRelayer?: RelayerInfo;
|
2024-04-29 18:55:15 +03:00
|
|
|
fetchDataOptions?: fetchDataOptions;
|
2024-09-21 04:26:50 +03:00
|
|
|
constructor({ netId, config, fetchDataOptions }: RelayerClientConstructor);
|
2024-09-27 07:56:19 +03:00
|
|
|
askRelayerStatus({ hostname, url, relayerAddress, }: {
|
2024-09-28 05:42:27 +03:00
|
|
|
hostname?: string;
|
2024-09-27 07:56:19 +03:00
|
|
|
url?: string;
|
2024-04-29 18:55:15 +03:00
|
|
|
relayerAddress?: string;
|
|
|
|
}): Promise<RelayerStatus>;
|
2024-09-21 04:26:50 +03:00
|
|
|
filterRelayer(relayer: CachedRelayerInfo): Promise<RelayerInfo | RelayerError | undefined>;
|
|
|
|
getValidRelayers(relayers: CachedRelayerInfo[]): Promise<{
|
2024-04-29 18:55:15 +03:00
|
|
|
validRelayers: RelayerInfo[];
|
|
|
|
invalidRelayers: RelayerError[];
|
|
|
|
}>;
|
|
|
|
pickWeightedRandomRelayer(relayers: RelayerInfo[]): RelayerInfo;
|
2024-09-26 15:23:55 +03:00
|
|
|
tornadoWithdraw({ contract, proof, args }: TornadoWithdrawParams): Promise<void>;
|
2024-04-29 18:55:15 +03:00
|
|
|
}
|