2024-11-03 05:41:14 +03:00
|
|
|
import { BaseContract, Provider, EventLog } from 'ethers';
|
|
|
|
import { Tornado, TornadoRouter, TornadoProxyLight, Governance, RelayerRegistry, Echoer, Aggregator } from '@tornado/contracts';
|
2024-11-19 08:04:13 +03:00
|
|
|
import type { MerkleTree } from '@tornado/fixed-merkle-tree';
|
2024-04-29 18:55:15 +03:00
|
|
|
import { BatchEventsService, BatchBlockService, BatchTransactionService, BatchEventOnProgress, BatchBlockOnProgress } from '../batch';
|
2024-09-26 15:23:55 +03:00
|
|
|
import { fetchDataOptions } from '../providers';
|
2024-10-02 02:27:23 +03:00
|
|
|
import { type NetIdType, type SubdomainMap } from '../networkConfig';
|
2024-09-21 04:26:50 +03:00
|
|
|
import { RelayerParams } from '../relayerClient';
|
2024-09-29 14:24:36 +03:00
|
|
|
import type { TovarishClient } from '../tovarishClient';
|
2024-10-18 05:18:06 +03:00
|
|
|
import type { ReverseRecords } from '../typechain';
|
2024-10-21 08:05:39 +03:00
|
|
|
import type { MerkleTreeService } from '../merkleTree';
|
2024-11-19 08:04:13 +03:00
|
|
|
import type { DepositType } from '../deposits';
|
|
|
|
import type { BaseEvents, CachedEvents, MinimalEvents, DepositsEvents, WithdrawalsEvents, EncryptedNotesEvents, AllGovernanceEvents, GovernanceProposalCreatedEvents, GovernanceVotedEvents, EchoEvents, AllRelayerRegistryEvents, StakeBurnedEvents, MultiDepositsEvents, MultiWithdrawalsEvents } from './types';
|
2024-10-16 17:19:49 +03:00
|
|
|
export interface BaseEventsServiceConstructor {
|
2024-04-29 18:55:15 +03:00
|
|
|
netId: NetIdType;
|
|
|
|
provider: Provider;
|
|
|
|
contract: BaseContract;
|
2024-10-16 17:19:49 +03:00
|
|
|
type: string;
|
2024-04-29 18:55:15 +03:00
|
|
|
deployedBlock?: number;
|
|
|
|
fetchDataOptions?: fetchDataOptions;
|
2024-09-29 14:24:36 +03:00
|
|
|
tovarishClient?: TovarishClient;
|
2024-10-16 17:19:49 +03:00
|
|
|
}
|
2024-04-29 18:55:15 +03:00
|
|
|
export declare class BaseEventsService<EventType extends MinimalEvents> {
|
|
|
|
netId: NetIdType;
|
|
|
|
provider: Provider;
|
|
|
|
contract: BaseContract;
|
|
|
|
type: string;
|
|
|
|
deployedBlock: number;
|
|
|
|
batchEventsService: BatchEventsService;
|
|
|
|
fetchDataOptions?: fetchDataOptions;
|
2024-09-29 14:24:36 +03:00
|
|
|
tovarishClient?: TovarishClient;
|
2024-11-03 05:41:14 +03:00
|
|
|
constructor({ netId, provider, contract, type, deployedBlock, fetchDataOptions, tovarishClient, }: BaseEventsServiceConstructor);
|
2024-04-29 18:55:15 +03:00
|
|
|
getInstanceName(): string;
|
|
|
|
getType(): string;
|
2024-09-29 06:49:00 +03:00
|
|
|
getTovarishType(): string;
|
2024-04-29 18:55:15 +03:00
|
|
|
updateEventProgress({ percentage, type, fromBlock, toBlock, count }: Parameters<BatchEventOnProgress>[0]): void;
|
|
|
|
updateBlockProgress({ percentage, currentIndex, totalIndex }: Parameters<BatchBlockOnProgress>[0]): void;
|
|
|
|
updateTransactionProgress({ percentage, currentIndex, totalIndex }: Parameters<BatchBlockOnProgress>[0]): void;
|
|
|
|
formatEvents(events: EventLog[]): Promise<EventType[]>;
|
|
|
|
/**
|
|
|
|
* Get saved or cached events
|
|
|
|
*/
|
|
|
|
getEventsFromDB(): Promise<BaseEvents<EventType>>;
|
2024-09-19 20:49:25 +03:00
|
|
|
/**
|
|
|
|
* Events from remote cache (Either from local cache, CDN, or from IPFS)
|
|
|
|
*/
|
|
|
|
getEventsFromCache(): Promise<CachedEvents<EventType>>;
|
|
|
|
getSavedEvents(): Promise<BaseEvents<EventType> | CachedEvents<EventType>>;
|
2024-04-29 18:55:15 +03:00
|
|
|
getEventsFromRpc({ fromBlock, toBlock, }: {
|
|
|
|
fromBlock: number;
|
|
|
|
toBlock?: number;
|
|
|
|
}): Promise<BaseEvents<EventType>>;
|
|
|
|
getLatestEvents({ fromBlock }: {
|
|
|
|
fromBlock: number;
|
|
|
|
}): Promise<BaseEvents<EventType>>;
|
2024-11-18 05:52:03 +03:00
|
|
|
validateEvents<S>({ events, newEvents, lastBlock, }: BaseEvents<EventType> & {
|
|
|
|
newEvents: EventType[];
|
2024-10-22 01:00:14 +03:00
|
|
|
}): Promise<S>;
|
2024-04-29 18:55:15 +03:00
|
|
|
/**
|
|
|
|
* Handle saving events
|
|
|
|
*/
|
2024-11-19 08:04:13 +03:00
|
|
|
saveEvents({ events, newEvents, lastBlock }: BaseEvents<EventType> & {
|
|
|
|
newEvents: EventType[];
|
|
|
|
}): Promise<void>;
|
2024-04-29 18:55:15 +03:00
|
|
|
/**
|
|
|
|
* Trigger saving and receiving latest events
|
|
|
|
*/
|
2024-10-21 08:05:39 +03:00
|
|
|
updateEvents<S>(): Promise<{
|
2024-04-29 18:55:15 +03:00
|
|
|
events: EventType[];
|
2024-09-22 06:16:12 +03:00
|
|
|
lastBlock: number;
|
2024-10-21 08:05:39 +03:00
|
|
|
validateResult: Awaited<S>;
|
2024-04-29 18:55:15 +03:00
|
|
|
}>;
|
|
|
|
}
|
2024-10-16 17:19:49 +03:00
|
|
|
export interface BaseTornadoServiceConstructor extends Omit<BaseEventsServiceConstructor, 'contract'> {
|
2024-04-29 18:55:15 +03:00
|
|
|
Tornado: Tornado;
|
|
|
|
amount: string;
|
|
|
|
currency: string;
|
2024-10-22 01:00:14 +03:00
|
|
|
optionalTree?: boolean;
|
2024-10-21 08:05:39 +03:00
|
|
|
merkleTreeService?: MerkleTreeService;
|
2024-10-16 17:19:49 +03:00
|
|
|
}
|
2024-05-01 12:04:01 +03:00
|
|
|
export declare class BaseTornadoService extends BaseEventsService<DepositsEvents | WithdrawalsEvents> {
|
2024-04-29 18:55:15 +03:00
|
|
|
amount: string;
|
|
|
|
currency: string;
|
2024-10-22 01:00:14 +03:00
|
|
|
optionalTree?: boolean;
|
2024-10-21 08:05:39 +03:00
|
|
|
merkleTreeService?: MerkleTreeService;
|
2024-04-29 18:55:15 +03:00
|
|
|
batchTransactionService: BatchTransactionService;
|
|
|
|
batchBlockService: BatchBlockService;
|
2024-10-16 18:19:31 +03:00
|
|
|
constructor(serviceConstructor: BaseTornadoServiceConstructor);
|
2024-04-29 18:55:15 +03:00
|
|
|
getInstanceName(): string;
|
|
|
|
formatEvents(events: EventLog[]): Promise<(DepositsEvents | WithdrawalsEvents)[]>;
|
2024-11-18 05:52:03 +03:00
|
|
|
validateEvents<S>({ events, newEvents, }: BaseEvents<DepositsEvents | WithdrawalsEvents> & {
|
|
|
|
newEvents: (DepositsEvents | WithdrawalsEvents)[];
|
2024-10-21 08:05:39 +03:00
|
|
|
}): Promise<S>;
|
2024-11-01 03:30:14 +03:00
|
|
|
getLatestEvents({ fromBlock, }: {
|
2024-09-29 14:24:36 +03:00
|
|
|
fromBlock: number;
|
|
|
|
}): Promise<BaseEvents<DepositsEvents | WithdrawalsEvents>>;
|
2024-04-29 18:55:15 +03:00
|
|
|
}
|
2024-11-19 08:04:13 +03:00
|
|
|
export interface BaseMultiTornadoServiceConstructor extends Omit<BaseEventsServiceConstructor, 'contract' | 'type'> {
|
|
|
|
instances: {
|
|
|
|
[key in string]: DepositType;
|
|
|
|
};
|
|
|
|
optionalTree?: boolean;
|
|
|
|
merkleTreeService?: MerkleTreeService;
|
|
|
|
}
|
|
|
|
export declare class BaseMultiTornadoService extends BaseEventsService<MultiDepositsEvents | MultiWithdrawalsEvents> {
|
|
|
|
instances: {
|
|
|
|
[key in string]: DepositType;
|
|
|
|
};
|
|
|
|
optionalTree?: boolean;
|
|
|
|
merkleTreeService?: MerkleTreeService;
|
|
|
|
batchTransactionService: BatchTransactionService;
|
|
|
|
batchBlockService: BatchBlockService;
|
|
|
|
constructor(serviceConstructor: BaseMultiTornadoServiceConstructor);
|
|
|
|
getInstanceName(): string;
|
|
|
|
getTovarishType(): string;
|
|
|
|
formatEvents(events: EventLog[]): Promise<(MultiDepositsEvents | MultiWithdrawalsEvents)[]>;
|
|
|
|
validateEvents<S>({ events, newEvents, }: BaseEvents<MultiDepositsEvents | MultiWithdrawalsEvents> & {
|
|
|
|
newEvents: (MultiDepositsEvents | MultiWithdrawalsEvents)[];
|
|
|
|
}): Promise<S>;
|
|
|
|
getEvents(instanceAddress: string): Promise<{
|
|
|
|
depositEvents: MultiDepositsEvents[];
|
|
|
|
withdrawalEvents: MultiWithdrawalsEvents[];
|
|
|
|
tree: MerkleTree | undefined;
|
|
|
|
lastBlock: number;
|
|
|
|
}>;
|
|
|
|
}
|
2024-10-16 17:19:49 +03:00
|
|
|
export interface BaseEchoServiceConstructor extends Omit<BaseEventsServiceConstructor, 'contract' | 'type'> {
|
2024-04-29 18:55:15 +03:00
|
|
|
Echoer: Echoer;
|
2024-10-16 17:19:49 +03:00
|
|
|
}
|
2024-04-29 18:55:15 +03:00
|
|
|
export declare class BaseEchoService extends BaseEventsService<EchoEvents> {
|
2024-10-16 18:19:31 +03:00
|
|
|
constructor(serviceConstructor: BaseEchoServiceConstructor);
|
2024-04-29 18:55:15 +03:00
|
|
|
getInstanceName(): string;
|
|
|
|
formatEvents(events: EventLog[]): Promise<EchoEvents[]>;
|
|
|
|
}
|
2024-10-16 17:19:49 +03:00
|
|
|
export interface BaseEncryptedNotesServiceConstructor extends Omit<BaseEventsServiceConstructor, 'contract' | 'type'> {
|
2024-04-29 18:55:15 +03:00
|
|
|
Router: TornadoRouter | TornadoProxyLight;
|
2024-10-16 17:19:49 +03:00
|
|
|
}
|
2024-04-29 18:55:15 +03:00
|
|
|
export declare class BaseEncryptedNotesService extends BaseEventsService<EncryptedNotesEvents> {
|
2024-10-16 18:19:31 +03:00
|
|
|
constructor(serviceConstructor: BaseEncryptedNotesServiceConstructor);
|
2024-04-29 18:55:15 +03:00
|
|
|
getInstanceName(): string;
|
2024-09-29 06:49:00 +03:00
|
|
|
getTovarishType(): string;
|
2024-04-29 18:55:15 +03:00
|
|
|
formatEvents(events: EventLog[]): Promise<EncryptedNotesEvents[]>;
|
|
|
|
}
|
2024-10-18 05:18:06 +03:00
|
|
|
export declare const proposalState: {
|
|
|
|
[key: string]: string;
|
|
|
|
};
|
|
|
|
export interface GovernanceProposals extends GovernanceProposalCreatedEvents {
|
|
|
|
title: string;
|
2024-10-18 17:17:00 +03:00
|
|
|
proposerName?: string;
|
2024-10-18 05:18:06 +03:00
|
|
|
forVotes: bigint;
|
|
|
|
againstVotes: bigint;
|
|
|
|
executed: boolean;
|
|
|
|
extended: boolean;
|
|
|
|
quorum: string;
|
|
|
|
state: string;
|
|
|
|
}
|
|
|
|
export interface GovernanceVotes extends GovernanceVotedEvents {
|
|
|
|
contact: string;
|
|
|
|
message: string;
|
2024-10-18 17:17:00 +03:00
|
|
|
fromName?: string;
|
|
|
|
voterName?: string;
|
2024-10-18 05:18:06 +03:00
|
|
|
}
|
2024-10-16 17:19:49 +03:00
|
|
|
export interface BaseGovernanceServiceConstructor extends Omit<BaseEventsServiceConstructor, 'contract' | 'type'> {
|
2024-04-29 18:55:15 +03:00
|
|
|
Governance: Governance;
|
2024-10-18 05:18:06 +03:00
|
|
|
Aggregator: Aggregator;
|
|
|
|
ReverseRecords: ReverseRecords;
|
2024-10-16 17:19:49 +03:00
|
|
|
}
|
2024-04-29 18:55:15 +03:00
|
|
|
export declare class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents> {
|
2024-10-18 05:18:06 +03:00
|
|
|
Governance: Governance;
|
|
|
|
Aggregator: Aggregator;
|
|
|
|
ReverseRecords: ReverseRecords;
|
2024-04-29 18:55:15 +03:00
|
|
|
batchTransactionService: BatchTransactionService;
|
2024-10-16 18:19:31 +03:00
|
|
|
constructor(serviceConstructor: BaseGovernanceServiceConstructor);
|
2024-04-29 18:55:15 +03:00
|
|
|
getInstanceName(): string;
|
2024-09-29 06:49:00 +03:00
|
|
|
getTovarishType(): string;
|
2024-04-29 18:55:15 +03:00
|
|
|
formatEvents(events: EventLog[]): Promise<AllGovernanceEvents[]>;
|
2024-10-18 05:18:06 +03:00
|
|
|
getAllProposals(): Promise<GovernanceProposals[]>;
|
2024-10-18 17:17:00 +03:00
|
|
|
getVotes(proposalId: number): Promise<GovernanceVotes[]>;
|
2024-10-18 05:18:06 +03:00
|
|
|
getDelegatedBalance(ethAccount: string): Promise<{
|
|
|
|
delegatedAccs: string[];
|
|
|
|
undelegatedAccs: string[];
|
|
|
|
uniq: string[];
|
2024-10-18 17:17:00 +03:00
|
|
|
uniqNames: {
|
|
|
|
[key: string]: string;
|
|
|
|
};
|
2024-10-18 05:18:06 +03:00
|
|
|
balances: bigint[];
|
|
|
|
balance: bigint;
|
|
|
|
}>;
|
2024-04-29 18:55:15 +03:00
|
|
|
}
|
2024-09-26 15:23:55 +03:00
|
|
|
export declare function getTovarishNetworks(registryService: BaseRegistryService, relayers: CachedRelayerInfo[]): Promise<void>;
|
2024-09-21 04:26:50 +03:00
|
|
|
/**
|
|
|
|
* Essential params:
|
|
|
|
* ensName, relayerAddress, hostnames
|
|
|
|
* Other data is for historic purpose from relayer registry
|
|
|
|
*/
|
|
|
|
export interface CachedRelayerInfo extends RelayerParams {
|
|
|
|
isRegistered?: boolean;
|
2024-10-19 19:25:20 +03:00
|
|
|
registeredAddress?: string;
|
2024-09-21 04:26:50 +03:00
|
|
|
stakeBalance?: string;
|
|
|
|
hostnames: SubdomainMap;
|
2024-09-29 08:56:53 +03:00
|
|
|
tovarishHost?: string;
|
2024-09-26 15:23:55 +03:00
|
|
|
tovarishNetworks?: number[];
|
2024-09-21 04:26:50 +03:00
|
|
|
}
|
|
|
|
export interface CachedRelayers {
|
2024-09-29 08:56:53 +03:00
|
|
|
lastBlock: number;
|
2024-09-21 04:26:50 +03:00
|
|
|
timestamp: number;
|
|
|
|
relayers: CachedRelayerInfo[];
|
2024-09-21 06:56:48 +03:00
|
|
|
fromCache?: boolean;
|
2024-09-21 04:26:50 +03:00
|
|
|
}
|
2024-10-16 17:19:49 +03:00
|
|
|
export interface BaseRegistryServiceConstructor extends Omit<BaseEventsServiceConstructor, 'contract' | 'type'> {
|
2024-04-29 18:55:15 +03:00
|
|
|
RelayerRegistry: RelayerRegistry;
|
2024-09-21 04:26:50 +03:00
|
|
|
Aggregator: Aggregator;
|
|
|
|
relayerEnsSubdomains: SubdomainMap;
|
2024-10-16 17:19:49 +03:00
|
|
|
}
|
2024-11-03 05:41:14 +03:00
|
|
|
export declare class BaseRegistryService extends BaseEventsService<AllRelayerRegistryEvents> {
|
2024-09-21 04:26:50 +03:00
|
|
|
Aggregator: Aggregator;
|
|
|
|
relayerEnsSubdomains: SubdomainMap;
|
|
|
|
updateInterval: number;
|
2024-10-16 18:19:31 +03:00
|
|
|
constructor(serviceConstructor: BaseRegistryServiceConstructor);
|
2024-04-29 18:55:15 +03:00
|
|
|
getInstanceName(): string;
|
2024-09-29 06:49:00 +03:00
|
|
|
getTovarishType(): string;
|
2024-11-03 05:41:14 +03:00
|
|
|
formatEvents(events: EventLog[]): Promise<AllRelayerRegistryEvents[]>;
|
2024-09-21 04:26:50 +03:00
|
|
|
/**
|
|
|
|
* Get saved or cached relayers
|
|
|
|
*/
|
|
|
|
getRelayersFromDB(): Promise<CachedRelayers>;
|
|
|
|
/**
|
|
|
|
* Relayers from remote cache (Either from local cache, CDN, or from IPFS)
|
|
|
|
*/
|
|
|
|
getRelayersFromCache(): Promise<CachedRelayers>;
|
|
|
|
getSavedRelayers(): Promise<CachedRelayers>;
|
|
|
|
getLatestRelayers(): Promise<CachedRelayers>;
|
|
|
|
/**
|
|
|
|
* Handle saving relayers
|
|
|
|
*/
|
2024-09-29 08:56:53 +03:00
|
|
|
saveRelayers({ lastBlock, timestamp, relayers }: CachedRelayers): Promise<void>;
|
2024-09-21 04:26:50 +03:00
|
|
|
/**
|
|
|
|
* Get cached or latest relayer and save to local
|
|
|
|
*/
|
|
|
|
updateRelayers(): Promise<CachedRelayers>;
|
2024-04-29 18:55:15 +03:00
|
|
|
}
|
2024-11-03 05:41:14 +03:00
|
|
|
export interface BaseRevenueServiceConstructor extends Omit<BaseEventsServiceConstructor, 'contract' | 'type'> {
|
|
|
|
RelayerRegistry: RelayerRegistry;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Tracks TORN burned events from RelayerRegistry contract
|
|
|
|
*/
|
|
|
|
export declare class BaseRevenueService extends BaseEventsService<StakeBurnedEvents> {
|
|
|
|
batchTransactionService: BatchTransactionService;
|
|
|
|
batchBlockService: BatchBlockService;
|
|
|
|
constructor(serviceConstructor: BaseRevenueServiceConstructor);
|
|
|
|
getInstanceName(): string;
|
|
|
|
getTovarishType(): string;
|
|
|
|
formatEvents(events: EventLog[]): Promise<StakeBurnedEvents[]>;
|
|
|
|
}
|