Initial client for Tovarish Relayer

This commit is contained in:
Tornado Contrib 2024-09-29 11:24:36 +00:00
parent be0e2419aa
commit a0f11d6ff4
Signed by: tornadocontrib
GPG Key ID: 60B4DF1A076C64B1
14 changed files with 1831 additions and 481 deletions

24
dist/events/base.d.ts vendored

@ -4,6 +4,7 @@ import { BatchEventsService, BatchBlockService, BatchTransactionService, BatchEv
import { fetchDataOptions } from '../providers'; import { fetchDataOptions } from '../providers';
import type { NetIdType, SubdomainMap } from '../networkConfig'; import type { NetIdType, SubdomainMap } from '../networkConfig';
import { RelayerParams } from '../relayerClient'; import { RelayerParams } from '../relayerClient';
import type { TovarishClient } from '../tovarishClient';
import type { BaseEvents, CachedEvents, MinimalEvents, DepositsEvents, WithdrawalsEvents, EncryptedNotesEvents, AllGovernanceEvents, RegistersEvents, EchoEvents } from './types'; import type { BaseEvents, CachedEvents, MinimalEvents, DepositsEvents, WithdrawalsEvents, EncryptedNotesEvents, AllGovernanceEvents, RegistersEvents, EchoEvents } from './types';
export declare const DEPOSIT = "deposit"; export declare const DEPOSIT = "deposit";
export declare const WITHDRAWAL = "withdrawal"; export declare const WITHDRAWAL = "withdrawal";
@ -16,6 +17,7 @@ export type BaseEventsServiceConstructor = {
type?: string; type?: string;
deployedBlock?: number; deployedBlock?: number;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarishClient?: TovarishClient;
}; };
export type BatchGraphOnProgress = ({ type, fromBlock, toBlock, count, }: { export type BatchGraphOnProgress = ({ type, fromBlock, toBlock, count, }: {
type?: ContractEventName; type?: ContractEventName;
@ -39,7 +41,8 @@ export declare class BaseEventsService<EventType extends MinimalEvents> {
deployedBlock: number; deployedBlock: number;
batchEventsService: BatchEventsService; batchEventsService: BatchEventsService;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
constructor({ netId, provider, graphApi, subgraphName, contract, type, deployedBlock, fetchDataOptions, }: BaseEventsServiceConstructor); tovarishClient?: TovarishClient;
constructor({ netId, provider, graphApi, subgraphName, contract, type, deployedBlock, fetchDataOptions, tovarishClient, }: BaseEventsServiceConstructor);
getInstanceName(): string; getInstanceName(): string;
getType(): string; getType(): string;
getTovarishType(): string; getTovarishType(): string;
@ -97,6 +100,7 @@ export type BaseTornadoServiceConstructor = {
currency: string; currency: string;
deployedBlock?: number; deployedBlock?: number;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarishClient?: TovarishClient;
}; };
export type DepositsGraphParams = BaseGraphParams & { export type DepositsGraphParams = BaseGraphParams & {
amount: string; amount: string;
@ -107,7 +111,8 @@ export declare class BaseTornadoService extends BaseEventsService<DepositsEvents
currency: string; currency: string;
batchTransactionService: BatchTransactionService; batchTransactionService: BatchTransactionService;
batchBlockService: BatchBlockService; batchBlockService: BatchBlockService;
constructor({ netId, provider, graphApi, subgraphName, Tornado, type, amount, currency, deployedBlock, fetchDataOptions, }: BaseTornadoServiceConstructor); tovarishClient?: TovarishClient;
constructor({ netId, provider, graphApi, subgraphName, Tornado, type, amount, currency, deployedBlock, fetchDataOptions, tovarishClient, }: BaseTornadoServiceConstructor);
getInstanceName(): string; getInstanceName(): string;
getGraphMethod(): string; getGraphMethod(): string;
getGraphParams(): DepositsGraphParams; getGraphParams(): DepositsGraphParams;
@ -115,6 +120,9 @@ export declare class BaseTornadoService extends BaseEventsService<DepositsEvents
validateEvents({ events }: { validateEvents({ events }: {
events: (DepositsEvents | WithdrawalsEvents)[]; events: (DepositsEvents | WithdrawalsEvents)[];
}): void; }): void;
getLatestEvents({ fromBlock }: {
fromBlock: number;
}): Promise<BaseEvents<DepositsEvents | WithdrawalsEvents>>;
} }
export type BaseEchoServiceConstructor = { export type BaseEchoServiceConstructor = {
netId: NetIdType; netId: NetIdType;
@ -124,9 +132,10 @@ export type BaseEchoServiceConstructor = {
Echoer: Echoer; Echoer: Echoer;
deployedBlock?: number; deployedBlock?: number;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarishClient?: TovarishClient;
}; };
export declare class BaseEchoService extends BaseEventsService<EchoEvents> { export declare class BaseEchoService extends BaseEventsService<EchoEvents> {
constructor({ netId, provider, graphApi, subgraphName, Echoer, deployedBlock, fetchDataOptions, }: BaseEchoServiceConstructor); constructor({ netId, provider, graphApi, subgraphName, Echoer, deployedBlock, fetchDataOptions, tovarishClient, }: BaseEchoServiceConstructor);
getInstanceName(): string; getInstanceName(): string;
getType(): string; getType(): string;
getGraphMethod(): string; getGraphMethod(): string;
@ -143,9 +152,10 @@ export type BaseEncryptedNotesServiceConstructor = {
Router: TornadoRouter | TornadoProxyLight; Router: TornadoRouter | TornadoProxyLight;
deployedBlock?: number; deployedBlock?: number;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarishClient?: TovarishClient;
}; };
export declare class BaseEncryptedNotesService extends BaseEventsService<EncryptedNotesEvents> { export declare class BaseEncryptedNotesService extends BaseEventsService<EncryptedNotesEvents> {
constructor({ netId, provider, graphApi, subgraphName, Router, deployedBlock, fetchDataOptions, }: BaseEncryptedNotesServiceConstructor); constructor({ netId, provider, graphApi, subgraphName, Router, deployedBlock, fetchDataOptions, tovarishClient, }: BaseEncryptedNotesServiceConstructor);
getInstanceName(): string; getInstanceName(): string;
getType(): string; getType(): string;
getTovarishType(): string; getTovarishType(): string;
@ -160,10 +170,11 @@ export type BaseGovernanceServiceConstructor = {
Governance: Governance; Governance: Governance;
deployedBlock?: number; deployedBlock?: number;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarishClient?: TovarishClient;
}; };
export declare class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents> { export declare class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents> {
batchTransactionService: BatchTransactionService; batchTransactionService: BatchTransactionService;
constructor({ netId, provider, graphApi, subgraphName, Governance, deployedBlock, fetchDataOptions, }: BaseGovernanceServiceConstructor); constructor({ netId, provider, graphApi, subgraphName, Governance, deployedBlock, fetchDataOptions, tovarishClient, }: BaseGovernanceServiceConstructor);
getInstanceName(): string; getInstanceName(): string;
getType(): string; getType(): string;
getTovarishType(): string; getTovarishType(): string;
@ -203,12 +214,13 @@ export type BaseRegistryServiceConstructor = {
relayerEnsSubdomains: SubdomainMap; relayerEnsSubdomains: SubdomainMap;
deployedBlock?: number; deployedBlock?: number;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarishClient?: TovarishClient;
}; };
export declare class BaseRegistryService extends BaseEventsService<RegistersEvents> { export declare class BaseRegistryService extends BaseEventsService<RegistersEvents> {
Aggregator: Aggregator; Aggregator: Aggregator;
relayerEnsSubdomains: SubdomainMap; relayerEnsSubdomains: SubdomainMap;
updateInterval: number; updateInterval: number;
constructor({ netId, provider, graphApi, subgraphName, RelayerRegistry, Aggregator, relayerEnsSubdomains, deployedBlock, fetchDataOptions, }: BaseRegistryServiceConstructor); constructor({ netId, provider, graphApi, subgraphName, RelayerRegistry, Aggregator, relayerEnsSubdomains, deployedBlock, fetchDataOptions, tovarishClient, }: BaseRegistryServiceConstructor);
getInstanceName(): string; getInstanceName(): string;
getType(): string; getType(): string;
getTovarishType(): string; getTovarishType(): string;

1
dist/index.d.ts vendored

@ -15,5 +15,6 @@ export * from './prices';
export * from './providers'; export * from './providers';
export * from './relayerClient'; export * from './relayerClient';
export * from './tokens'; export * from './tokens';
export * from './tovarishClient';
export * from './utils'; export * from './utils';
export * from './websnark'; export * from './websnark';

701
dist/index.js vendored

File diff suppressed because it is too large Load Diff

701
dist/index.mjs vendored

File diff suppressed because it is too large Load Diff

@ -1,7 +1,7 @@
import { NetIdType, Config } from './networkConfig'; import { NetIdType, Config } from './networkConfig';
import { fetchDataOptions } from './providers'; import { fetchDataOptions } from './providers';
import type { snarkProofs } from './websnark'; import type { snarkProofs } from './websnark';
import { CachedRelayerInfo } from './events/base'; import type { CachedRelayerInfo } from './events';
export declare const MIN_FEE = 0.1; export declare const MIN_FEE = 0.1;
export declare const MAX_FEE = 0.9; export declare const MAX_FEE = 0.9;
export declare const MIN_STAKE_BALANCE: bigint; export declare const MIN_STAKE_BALANCE: bigint;
@ -130,6 +130,7 @@ export declare class RelayerClient {
config: Config; config: Config;
selectedRelayer?: RelayerInfo; selectedRelayer?: RelayerInfo;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarish: boolean;
constructor({ netId, config, fetchDataOptions }: RelayerClientConstructor); constructor({ netId, config, fetchDataOptions }: RelayerClientConstructor);
askRelayerStatus({ hostname, url, relayerAddress, }: { askRelayerStatus({ hostname, url, relayerAddress, }: {
hostname?: string; hostname?: string;

@ -74,6 +74,24 @@ export type statusSchema = {
}; };
required: string[]; required: string[];
}; };
syncStatus: {
type: string;
properties: {
events: {
type: string;
};
tokenPrice: {
type: string;
};
gasPrice: {
type: string;
};
};
required: string[];
};
onSyncEvents: {
type: string;
};
currentQueue: { currentQueue: {
type: string; type: string;
}; };
@ -88,5 +106,5 @@ declare const bnType: {
type: string; type: string;
BN: boolean; BN: boolean;
}; };
export declare function getStatusSchema(netId: NetIdType, config: Config): statusSchema; export declare function getStatusSchema(netId: NetIdType, config: Config, tovarish: boolean): statusSchema;
export {}; export {};

393
dist/tornado.umd.js vendored

@ -59136,7 +59136,8 @@ class BaseEventsService {
contract, contract,
type = "", type = "",
deployedBlock = 0, deployedBlock = 0,
fetchDataOptions: fetchDataOptions2 fetchDataOptions: fetchDataOptions2,
tovarishClient
}) { }) {
this.netId = netId; this.netId = netId;
this.provider = provider; this.provider = provider;
@ -59151,6 +59152,7 @@ class BaseEventsService {
contract, contract,
onProgress: this.updateEventProgress onProgress: this.updateEventProgress
}); });
this.tovarishClient = tovarishClient;
} }
getInstanceName() { getInstanceName() {
return ""; return "";
@ -59159,7 +59161,7 @@ class BaseEventsService {
return this.type || ""; return this.type || "";
} }
getTovarishType() { getTovarishType() {
return String(this.type || "").toLowerCase(); return String(this.getType() || "").toLowerCase();
} }
getGraphMethod() { getGraphMethod() {
return ""; return "";
@ -59276,6 +59278,17 @@ class BaseEventsService {
} }
getLatestEvents(_0) { getLatestEvents(_0) {
return __async(this, arguments, function* ({ fromBlock }) { return __async(this, arguments, function* ({ fromBlock }) {
var _a;
if (((_a = this.tovarishClient) == null ? void 0 : _a.selectedRelayer) && ![DEPOSIT, WITHDRAWAL].includes(this.type.toLowerCase())) {
const { events, lastSyncBlock: lastBlock } = yield this.tovarishClient.getEvents({
type: this.getTovarishType(),
fromBlock
});
return {
events,
lastBlock
};
}
const graphEvents = yield this.getEventsFromGraph({ fromBlock }); const graphEvents = yield this.getEventsFromGraph({ fromBlock });
const lastSyncBlock = graphEvents.lastBlock && graphEvents.lastBlock >= fromBlock ? graphEvents.lastBlock : fromBlock; const lastSyncBlock = graphEvents.lastBlock && graphEvents.lastBlock >= fromBlock ? graphEvents.lastBlock : fromBlock;
const rpcEvents = yield this.getEventsFromRpc({ fromBlock: lastSyncBlock }); const rpcEvents = yield this.getEventsFromRpc({ fromBlock: lastSyncBlock });
@ -59343,9 +59356,20 @@ class BaseTornadoService extends BaseEventsService {
amount, amount,
currency, currency,
deployedBlock, deployedBlock,
fetchDataOptions: fetchDataOptions2 fetchDataOptions: fetchDataOptions2,
tovarishClient
}) { }) {
super({ netId, provider, graphApi, subgraphName, contract: Tornado, type, deployedBlock, fetchDataOptions: fetchDataOptions2 }); super({
netId,
provider,
graphApi,
subgraphName,
contract: Tornado,
type,
deployedBlock,
fetchDataOptions: fetchDataOptions2,
tovarishClient
});
this.amount = amount; this.amount = amount;
this.currency = currency; this.currency = currency;
this.batchTransactionService = new _batch__WEBPACK_IMPORTED_MODULE_1__/* .BatchTransactionService */ .AF({ this.batchTransactionService = new _batch__WEBPACK_IMPORTED_MODULE_1__/* .BatchTransactionService */ .AF({
@ -59430,6 +59454,24 @@ class BaseTornadoService extends BaseEventsService {
} }
} }
} }
getLatestEvents(_0) {
return __async(this, arguments, function* ({ fromBlock }) {
var _a;
if ((_a = this.tovarishClient) == null ? void 0 : _a.selectedRelayer) {
const { events, lastSyncBlock: lastBlock } = yield this.tovarishClient.getEvents({
type: this.getTovarishType(),
currency: this.currency,
amount: this.amount,
fromBlock
});
return {
events,
lastBlock
};
}
return __superGet(BaseTornadoService.prototype, this, "getLatestEvents").call(this, { fromBlock });
});
}
} }
class BaseEchoService extends BaseEventsService { class BaseEchoService extends BaseEventsService {
constructor({ constructor({
@ -59439,9 +59481,19 @@ class BaseEchoService extends BaseEventsService {
subgraphName, subgraphName,
Echoer, Echoer,
deployedBlock, deployedBlock,
fetchDataOptions: fetchDataOptions2 fetchDataOptions: fetchDataOptions2,
tovarishClient
}) { }) {
super({ netId, provider, graphApi, subgraphName, contract: Echoer, deployedBlock, fetchDataOptions: fetchDataOptions2 }); super({
netId,
provider,
graphApi,
subgraphName,
contract: Echoer,
deployedBlock,
fetchDataOptions: fetchDataOptions2,
tovarishClient
});
} }
getInstanceName() { getInstanceName() {
return `echo_${this.netId}`; return `echo_${this.netId}`;
@ -59490,9 +59542,19 @@ class BaseEncryptedNotesService extends BaseEventsService {
subgraphName, subgraphName,
Router, Router,
deployedBlock, deployedBlock,
fetchDataOptions: fetchDataOptions2 fetchDataOptions: fetchDataOptions2,
tovarishClient
}) { }) {
super({ netId, provider, graphApi, subgraphName, contract: Router, deployedBlock, fetchDataOptions: fetchDataOptions2 }); super({
netId,
provider,
graphApi,
subgraphName,
contract: Router,
deployedBlock,
fetchDataOptions: fetchDataOptions2,
tovarishClient
});
} }
getInstanceName() { getInstanceName() {
return `encrypted_notes_${this.netId}`; return `encrypted_notes_${this.netId}`;
@ -59532,9 +59594,19 @@ class BaseGovernanceService extends BaseEventsService {
subgraphName, subgraphName,
Governance, Governance,
deployedBlock, deployedBlock,
fetchDataOptions: fetchDataOptions2 fetchDataOptions: fetchDataOptions2,
tovarishClient
}) { }) {
super({ netId, provider, graphApi, subgraphName, contract: Governance, deployedBlock, fetchDataOptions: fetchDataOptions2 }); super({
netId,
provider,
graphApi,
subgraphName,
contract: Governance,
deployedBlock,
fetchDataOptions: fetchDataOptions2,
tovarishClient
});
this.batchTransactionService = new _batch__WEBPACK_IMPORTED_MODULE_1__/* .BatchTransactionService */ .AF({ this.batchTransactionService = new _batch__WEBPACK_IMPORTED_MODULE_1__/* .BatchTransactionService */ .AF({
provider, provider,
onProgress: this.updateTransactionProgress onProgress: this.updateTransactionProgress
@ -59661,9 +59733,19 @@ class BaseRegistryService extends BaseEventsService {
Aggregator, Aggregator,
relayerEnsSubdomains, relayerEnsSubdomains,
deployedBlock, deployedBlock,
fetchDataOptions: fetchDataOptions2 fetchDataOptions: fetchDataOptions2,
tovarishClient
}) { }) {
super({ netId, provider, graphApi, subgraphName, contract: RelayerRegistry, deployedBlock, fetchDataOptions: fetchDataOptions2 }); super({
netId,
provider,
graphApi,
subgraphName,
contract: RelayerRegistry,
deployedBlock,
fetchDataOptions: fetchDataOptions2,
tovarishClient
});
this.Aggregator = Aggregator; this.Aggregator = Aggregator;
this.relayerEnsSubdomains = relayerEnsSubdomains; this.relayerEnsSubdomains = relayerEnsSubdomains;
this.updateInterval = 86400; this.updateInterval = 86400;
@ -71549,6 +71631,7 @@ class RelayerClient {
this.netId = netId; this.netId = netId;
this.config = config; this.config = config;
this.fetchDataOptions = fetchDataOptions2; this.fetchDataOptions = fetchDataOptions2;
this.tovarish = false;
} }
askRelayerStatus(_0) { askRelayerStatus(_0) {
return __async(this, arguments, function* ({ return __async(this, arguments, function* ({
@ -71571,7 +71654,7 @@ class RelayerClient {
timeout: ((_a = this.fetchDataOptions) == null ? void 0 : _a.torPort) ? 1e4 : 3e3, timeout: ((_a = this.fetchDataOptions) == null ? void 0 : _a.torPort) ? 1e4 : 3e3,
maxRetry: ((_b = this.fetchDataOptions) == null ? void 0 : _b.torPort) ? 2 : 0 maxRetry: ((_b = this.fetchDataOptions) == null ? void 0 : _b.torPort) ? 2 : 0
})); }));
const statusValidator = _schemas__WEBPACK_IMPORTED_MODULE_3__/* .ajv */ .SS.compile((0,_schemas__WEBPACK_IMPORTED_MODULE_3__/* .getStatusSchema */ .c_)(this.netId, this.config)); const statusValidator = _schemas__WEBPACK_IMPORTED_MODULE_3__/* .ajv */ .SS.compile((0,_schemas__WEBPACK_IMPORTED_MODULE_3__/* .getStatusSchema */ .c_)(this.netId, this.config, this.tovarish));
if (!statusValidator(rawStatus)) { if (!statusValidator(rawStatus)) {
throw new Error("Invalid status schema"); throw new Error("Invalid status schema");
} }
@ -71758,11 +71841,21 @@ const statusSchema = {
}, },
required: ["status"] required: ["status"]
}, },
syncStatus: {
type: "object",
properties: {
events: { type: "boolean" },
tokenPrice: { type: "boolean" },
gasPrice: { type: "boolean" }
},
required: ["events", "tokenPrice", "gasPrice"]
},
onSyncEvents: { type: "boolean" },
currentQueue: { type: "number" } currentQueue: { type: "number" }
}, },
required: ["rewardAccount", "instances", "netId", "tornadoServiceFee", "version", "health"] required: ["rewardAccount", "instances", "netId", "tornadoServiceFee", "version", "health", "currentQueue"]
}; };
function getStatusSchema(netId, config) { function getStatusSchema(netId, config, tovarish) {
const { tokens, optionalTokens, disabledTokens, nativeCurrency } = config; const { tokens, optionalTokens, disabledTokens, nativeCurrency } = config;
const schema = JSON.parse(JSON.stringify(statusSchema)); const schema = JSON.parse(JSON.stringify(statusSchema));
const instances = Object.keys(tokens).reduce( const instances = Object.keys(tokens).reduce(
@ -71806,17 +71899,29 @@ function getStatusSchema(netId, config) {
} }
); );
schema.properties.instances = instances; schema.properties.instances = instances;
const _tokens = Object.keys(tokens).filter(
(t) => {
var _a, _b;
return t !== nativeCurrency && !((_a = config.optionalTokens) == null ? void 0 : _a.includes(t)) && !((_b = config.disabledTokens) == null ? void 0 : _b.includes(t));
}
);
if (netId === networkConfig/* NetId */.zr.MAINNET) { if (netId === networkConfig/* NetId */.zr.MAINNET) {
const _tokens = Object.keys(tokens).filter((t) => t !== nativeCurrency); _tokens.push("torn");
}
if (_tokens.length) {
const ethPrices = { const ethPrices = {
type: "object", type: "object",
properties: _tokens.reduce((acc, token) => { properties: _tokens.reduce((acc, token) => {
acc[token] = bnType; acc[token] = bnType;
return acc; return acc;
}, {}) }, {}),
// required: _tokens required: _tokens
}; };
schema.properties.ethPrices = ethPrices; schema.properties.ethPrices = ethPrices;
schema.required.push("ethPrices");
}
if (tovarish) {
schema.required.push("gasPrices", "latestBlock", "syncStatus", "onSyncEvents");
} }
return schema; return schema;
} }
@ -71967,6 +72072,204 @@ function getTokenBalances(_0) {
} }
/***/ }),
/***/ 96838:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
"use strict";
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ E: () => (/* binding */ TovarishClient),
/* harmony export */ o: () => (/* binding */ MAX_TOVARISH_EVENTS)
/* harmony export */ });
/* harmony import */ var ethers__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(30031);
/* harmony import */ var _relayerClient__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(57194);
/* harmony import */ var _providers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(68434);
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __reflectGet = Reflect.get;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
}
return a;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
const MAX_TOVARISH_EVENTS = 5e3;
class TovarishClient extends _relayerClient__WEBPACK_IMPORTED_MODULE_0__/* .RelayerClient */ .OR {
constructor({ netId, config, fetchDataOptions }) {
super({ netId, config, fetchDataOptions });
this.tovarish = true;
}
askRelayerStatus(_0) {
return __async(this, arguments, function* ({
hostname,
url,
relayerAddress
}) {
const status = yield __superGet(TovarishClient.prototype, this, "askRelayerStatus").call(this, { hostname, url, relayerAddress });
if (!status.version.includes("tovarish")) {
throw new Error("Not a tovarish relayer!");
}
return status;
});
}
filterRelayer(relayer) {
return __async(this, null, function* () {
var _a;
const { ensName, relayerAddress, tovarishHost: hostname, tovarishNetworks } = relayer;
if (!hostname || !(tovarishNetworks == null ? void 0 : tovarishNetworks.includes(this.netId))) {
return;
}
try {
const status = yield this.askRelayerStatus({ hostname, relayerAddress });
return {
netId: status.netId,
url: status.url,
hostname,
ensName,
relayerAddress,
rewardAccount: (0,ethers__WEBPACK_IMPORTED_MODULE_2__/* .getAddress */ .b)(status.rewardAccount),
instances: (0,_relayerClient__WEBPACK_IMPORTED_MODULE_0__/* .getSupportedInstances */ .XF)(status.instances),
stakeBalance: relayer.stakeBalance,
gasPrice: (_a = status.gasPrices) == null ? void 0 : _a.fast,
ethPrices: status.ethPrices,
currentQueue: status.currentQueue,
tornadoServiceFee: status.tornadoServiceFee,
// Additional fields for tovarish relayer
latestBlock: Number(status.latestBlock),
version: status.version,
events: status.events,
syncStatus: status.syncStatus
};
} catch (err) {
return {
hostname,
relayerAddress,
errorMessage: err.message,
hasError: true
};
}
});
}
getValidRelayers(relayers) {
return __async(this, null, function* () {
const invalidRelayers = [];
const validRelayers = (yield Promise.all(relayers.map((relayer) => this.filterRelayer(relayer)))).filter((r) => {
if (!r) {
return false;
}
if (r.hasError) {
invalidRelayers.push(r);
return false;
}
return true;
});
return {
validRelayers,
invalidRelayers
};
});
}
getEvents(_0) {
return __async(this, arguments, function* ({
type,
currency,
amount,
fromBlock,
recent
}) {
var _a;
const url = `${(_a = this.selectedRelayer) == null ? void 0 : _a.url}events`;
try {
const events = [];
let lastSyncBlock = fromBlock;
while (true) {
let { events: fetchedEvents, lastSyncBlock: currentBlock } = yield (0,_providers__WEBPACK_IMPORTED_MODULE_1__/* .fetchData */ .Fd)(url, __spreadProps(__spreadValues({}, this.fetchDataOptions), {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
type,
currency,
amount,
fromBlock,
recent
})
}));
lastSyncBlock = currentBlock;
if (!Array.isArray(fetchedEvents) || !fetchedEvents.length) {
break;
}
fetchedEvents = fetchedEvents.sort((a, b) => {
if (a.blockNumber === b.blockNumber) {
return a.logIndex - b.logIndex;
}
return a.blockNumber - b.blockNumber;
});
const [lastEvent] = fetchedEvents.slice(-1);
if (fetchedEvents.length < MAX_TOVARISH_EVENTS - 100) {
events.push(...fetchedEvents);
break;
}
fetchedEvents = fetchedEvents.filter((e) => e.blockNumber !== lastEvent.blockNumber);
fromBlock = Number(lastEvent.blockNumber);
events.push(...fetchedEvents);
}
return {
events,
lastSyncBlock
};
} catch (err) {
console.log("Error from TovarishClient events endpoint");
console.log(err);
return {
events: [],
lastSyncBlock: fromBlock
};
}
});
}
}
/***/ }), /***/ }),
/***/ 21278: /***/ 21278:
@ -173018,6 +173321,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ GET_WITHDRAWALS: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.GET_WITHDRAWALS), /* harmony export */ GET_WITHDRAWALS: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.GET_WITHDRAWALS),
/* harmony export */ Invoice: () => (/* reexport safe */ _deposits__WEBPACK_IMPORTED_MODULE_5__.qO), /* harmony export */ Invoice: () => (/* reexport safe */ _deposits__WEBPACK_IMPORTED_MODULE_5__.qO),
/* harmony export */ MAX_FEE: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.KN), /* harmony export */ MAX_FEE: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.KN),
/* harmony export */ MAX_TOVARISH_EVENTS: () => (/* reexport safe */ _tovarishClient__WEBPACK_IMPORTED_MODULE_17__.o),
/* harmony export */ MIN_FEE: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.Ss), /* harmony export */ MIN_FEE: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.Ss),
/* harmony export */ MIN_STAKE_BALANCE: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.pO), /* harmony export */ MIN_STAKE_BALANCE: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.pO),
/* harmony export */ MerkleTreeService: () => (/* reexport safe */ _merkleTree__WEBPACK_IMPORTED_MODULE_8__.s), /* harmony export */ MerkleTreeService: () => (/* reexport safe */ _merkleTree__WEBPACK_IMPORTED_MODULE_8__.s),
@ -173036,28 +173340,29 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ TornadoRpcSigner: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.Vr), /* harmony export */ TornadoRpcSigner: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.Vr),
/* harmony export */ TornadoVoidSigner: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.Gd), /* harmony export */ TornadoVoidSigner: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.Gd),
/* harmony export */ TornadoWallet: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.nA), /* harmony export */ TornadoWallet: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.nA),
/* harmony export */ TovarishClient: () => (/* reexport safe */ _tovarishClient__WEBPACK_IMPORTED_MODULE_17__.E),
/* harmony export */ _META: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__._META), /* harmony export */ _META: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__._META),
/* harmony export */ addNetwork: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.AE), /* harmony export */ addNetwork: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.AE),
/* harmony export */ ajv: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.SS), /* harmony export */ ajv: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.SS),
/* harmony export */ base64ToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.Kp), /* harmony export */ base64ToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.Kp),
/* harmony export */ bigIntReplacer: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.gn), /* harmony export */ bigIntReplacer: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.gn),
/* harmony export */ bnToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.jm), /* harmony export */ bnToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.jm),
/* harmony export */ buffPedersenHash: () => (/* reexport safe */ _pedersen__WEBPACK_IMPORTED_MODULE_12__.UB), /* harmony export */ buffPedersenHash: () => (/* reexport safe */ _pedersen__WEBPACK_IMPORTED_MODULE_12__.UB),
/* harmony export */ bufferToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.lY), /* harmony export */ bufferToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.lY),
/* harmony export */ bytesToBN: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.Ju), /* harmony export */ bytesToBN: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.Ju),
/* harmony export */ bytesToBase64: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__["if"]), /* harmony export */ bytesToBase64: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__["if"]),
/* harmony export */ bytesToHex: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.My), /* harmony export */ bytesToHex: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.My),
/* harmony export */ calculateScore: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.zy), /* harmony export */ calculateScore: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.zy),
/* harmony export */ calculateSnarkProof: () => (/* reexport safe */ _websnark__WEBPACK_IMPORTED_MODULE_18__.i), /* harmony export */ calculateSnarkProof: () => (/* reexport safe */ _websnark__WEBPACK_IMPORTED_MODULE_19__.i),
/* harmony export */ chunk: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.iv), /* harmony export */ chunk: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.iv),
/* harmony export */ concatBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.Id), /* harmony export */ concatBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.Id),
/* harmony export */ convertETHToTokenAmount: () => (/* reexport safe */ _fees__WEBPACK_IMPORTED_MODULE_7__.N), /* harmony export */ convertETHToTokenAmount: () => (/* reexport safe */ _fees__WEBPACK_IMPORTED_MODULE_7__.N),
/* harmony export */ createDeposit: () => (/* reexport safe */ _deposits__WEBPACK_IMPORTED_MODULE_5__.Hr), /* harmony export */ createDeposit: () => (/* reexport safe */ _deposits__WEBPACK_IMPORTED_MODULE_5__.Hr),
/* harmony export */ crypto: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.Et), /* harmony export */ crypto: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.Et),
/* harmony export */ customConfig: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.cX), /* harmony export */ customConfig: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.cX),
/* harmony export */ defaultConfig: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.sb), /* harmony export */ defaultConfig: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.sb),
/* harmony export */ defaultUserAgent: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.mJ), /* harmony export */ defaultUserAgent: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.mJ),
/* harmony export */ digest: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.br), /* harmony export */ digest: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.br),
/* harmony export */ enabledChains: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.Af), /* harmony export */ enabledChains: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.Af),
/* harmony export */ factories: () => (/* reexport safe */ _typechain__WEBPACK_IMPORTED_MODULE_3__.XB), /* harmony export */ factories: () => (/* reexport safe */ _typechain__WEBPACK_IMPORTED_MODULE_3__.XB),
/* harmony export */ fetch: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.hd), /* harmony export */ fetch: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.hd),
@ -173091,12 +173396,12 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ getTokenBalances: () => (/* reexport safe */ _tokens__WEBPACK_IMPORTED_MODULE_16__.H), /* harmony export */ getTokenBalances: () => (/* reexport safe */ _tokens__WEBPACK_IMPORTED_MODULE_16__.H),
/* harmony export */ getWeightRandom: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.c$), /* harmony export */ getWeightRandom: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.c$),
/* harmony export */ getWithdrawals: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getWithdrawals), /* harmony export */ getWithdrawals: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getWithdrawals),
/* harmony export */ hexToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.aT), /* harmony export */ hexToBytes: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.aT),
/* harmony export */ initGroth16: () => (/* reexport safe */ _websnark__WEBPACK_IMPORTED_MODULE_18__.O), /* harmony export */ initGroth16: () => (/* reexport safe */ _websnark__WEBPACK_IMPORTED_MODULE_19__.O),
/* harmony export */ isNode: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.Ll), /* harmony export */ isNode: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.Ll),
/* harmony export */ jobsSchema: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.Us), /* harmony export */ jobsSchema: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_2__.Us),
/* harmony export */ leBuff2Int: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.ae), /* harmony export */ leBuff2Int: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.ae),
/* harmony export */ leInt2Buff: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.EI), /* harmony export */ leInt2Buff: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.EI),
/* harmony export */ mimc: () => (/* reexport safe */ _mimc__WEBPACK_IMPORTED_MODULE_9__.f), /* harmony export */ mimc: () => (/* reexport safe */ _mimc__WEBPACK_IMPORTED_MODULE_9__.f),
/* harmony export */ multicall: () => (/* reexport safe */ _multicall__WEBPACK_IMPORTED_MODULE_10__.C), /* harmony export */ multicall: () => (/* reexport safe */ _multicall__WEBPACK_IMPORTED_MODULE_10__.C),
/* harmony export */ packEncryptedMessage: () => (/* reexport safe */ _encryptedNotes__WEBPACK_IMPORTED_MODULE_6__.Fr), /* harmony export */ packEncryptedMessage: () => (/* reexport safe */ _encryptedNotes__WEBPACK_IMPORTED_MODULE_6__.Fr),
@ -173104,13 +173409,13 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ pickWeightedRandomRelayer: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.sN), /* harmony export */ pickWeightedRandomRelayer: () => (/* reexport safe */ _relayerClient__WEBPACK_IMPORTED_MODULE_15__.sN),
/* harmony export */ populateTransaction: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.zr), /* harmony export */ populateTransaction: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.zr),
/* harmony export */ queryGraph: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.queryGraph), /* harmony export */ queryGraph: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.queryGraph),
/* harmony export */ rBigInt: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.ib), /* harmony export */ rBigInt: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.ib),
/* harmony export */ sleep: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.yy), /* harmony export */ sleep: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.yy),
/* harmony export */ substring: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.uU), /* harmony export */ substring: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.uU),
/* harmony export */ toFixedHex: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.$W), /* harmony export */ toFixedHex: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.$W),
/* harmony export */ toFixedLength: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.sY), /* harmony export */ toFixedLength: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.sY),
/* harmony export */ unpackEncryptedMessage: () => (/* reexport safe */ _encryptedNotes__WEBPACK_IMPORTED_MODULE_6__.ol), /* harmony export */ unpackEncryptedMessage: () => (/* reexport safe */ _encryptedNotes__WEBPACK_IMPORTED_MODULE_6__.ol),
/* harmony export */ validateUrl: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_17__.wv) /* harmony export */ validateUrl: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_18__.wv)
/* harmony export */ }); /* harmony export */ });
/* harmony import */ var _events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(94513); /* harmony import */ var _events__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(94513);
/* harmony reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {}; /* harmony reexport (unknown) */ var __WEBPACK_REEXPORT_OBJECT__ = {};
@ -173132,8 +173437,10 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var _providers__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(68434); /* harmony import */ var _providers__WEBPACK_IMPORTED_MODULE_14__ = __webpack_require__(68434);
/* harmony import */ var _relayerClient__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(57194); /* harmony import */ var _relayerClient__WEBPACK_IMPORTED_MODULE_15__ = __webpack_require__(57194);
/* harmony import */ var _tokens__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(7393); /* harmony import */ var _tokens__WEBPACK_IMPORTED_MODULE_16__ = __webpack_require__(7393);
/* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(67418); /* harmony import */ var _tovarishClient__WEBPACK_IMPORTED_MODULE_17__ = __webpack_require__(96838);
/* harmony import */ var _websnark__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(26746); /* harmony import */ var _utils__WEBPACK_IMPORTED_MODULE_18__ = __webpack_require__(67418);
/* harmony import */ var _websnark__WEBPACK_IMPORTED_MODULE_19__ = __webpack_require__(26746);

File diff suppressed because one or more lines are too long

69
dist/tovarishClient.d.ts vendored Normal file

@ -0,0 +1,69 @@
import { RelayerClient, RelayerClientConstructor, RelayerError, RelayerInfo, RelayerStatus } from './relayerClient';
import { CachedRelayerInfo, MinimalEvents } from './events';
export declare const MAX_TOVARISH_EVENTS = 5000;
export interface EventsStatus {
events: number;
lastBlock: number;
}
export interface InstanceEventsStatus {
[index: string]: {
deposits: EventsStatus;
withdrawals: EventsStatus;
};
}
export interface CurrencyEventsStatus {
[index: string]: InstanceEventsStatus;
}
export interface TovarishEventsStatus {
governance?: EventsStatus;
registered?: {
lastBlock: number;
timestamp: number;
relayers: number;
};
echo: EventsStatus;
encrypted_notes: EventsStatus;
instances: CurrencyEventsStatus;
}
export interface TovarishSyncStatus {
events: boolean;
tokenPrice: boolean;
gasPrice: boolean;
}
export interface TovarishStatus extends RelayerStatus {
events: TovarishEventsStatus;
syncStatus: TovarishSyncStatus;
onSyncEvents: boolean;
}
export interface TovarishInfo extends RelayerInfo {
latestBlock: number;
version: string;
events: TovarishEventsStatus;
syncStatus: TovarishSyncStatus;
}
export interface TovarishEventsQuery {
type: string;
currency?: string;
amount?: string;
fromBlock: number;
recent?: boolean;
}
export interface BaseTovarishEvents<T> {
events: T[];
lastSyncBlock: number;
}
export declare class TovarishClient extends RelayerClient {
selectedRelayer?: TovarishInfo;
constructor({ netId, config, fetchDataOptions }: RelayerClientConstructor);
askRelayerStatus({ hostname, url, relayerAddress, }: {
hostname?: string;
url?: string;
relayerAddress?: string;
}): Promise<TovarishStatus>;
filterRelayer(relayer: CachedRelayerInfo): Promise<TovarishInfo | RelayerError | undefined>;
getValidRelayers(relayers: CachedRelayerInfo[]): Promise<{
validRelayers: TovarishInfo[];
invalidRelayers: RelayerError[];
}>;
getEvents<T extends MinimalEvents>({ type, currency, amount, fromBlock, recent, }: TovarishEventsQuery): Promise<BaseTovarishEvents<T>>;
}

@ -33,6 +33,7 @@ import {
import { fetchData, fetchDataOptions } from '../providers'; import { fetchData, fetchDataOptions } from '../providers';
import type { NetIdType, SubdomainMap } from '../networkConfig'; import type { NetIdType, SubdomainMap } from '../networkConfig';
import { RelayerParams, MIN_STAKE_BALANCE } from '../relayerClient'; import { RelayerParams, MIN_STAKE_BALANCE } from '../relayerClient';
import type { TovarishClient } from '../tovarishClient';
import type { import type {
BaseEvents, BaseEvents,
@ -63,6 +64,7 @@ export type BaseEventsServiceConstructor = {
type?: string; type?: string;
deployedBlock?: number; deployedBlock?: number;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarishClient?: TovarishClient;
}; };
export type BatchGraphOnProgress = ({ export type BatchGraphOnProgress = ({
@ -94,6 +96,7 @@ export class BaseEventsService<EventType extends MinimalEvents> {
deployedBlock: number; deployedBlock: number;
batchEventsService: BatchEventsService; batchEventsService: BatchEventsService;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarishClient?: TovarishClient;
constructor({ constructor({
netId, netId,
@ -104,6 +107,7 @@ export class BaseEventsService<EventType extends MinimalEvents> {
type = '', type = '',
deployedBlock = 0, deployedBlock = 0,
fetchDataOptions, fetchDataOptions,
tovarishClient,
}: BaseEventsServiceConstructor) { }: BaseEventsServiceConstructor) {
this.netId = netId; this.netId = netId;
this.provider = provider; this.provider = provider;
@ -120,6 +124,8 @@ export class BaseEventsService<EventType extends MinimalEvents> {
contract, contract,
onProgress: this.updateEventProgress, onProgress: this.updateEventProgress,
}); });
this.tovarishClient = tovarishClient;
} }
getInstanceName(): string { getInstanceName(): string {
@ -131,7 +137,7 @@ export class BaseEventsService<EventType extends MinimalEvents> {
} }
getTovarishType(): string { getTovarishType(): string {
return String(this.type || '').toLowerCase(); return String(this.getType() || '').toLowerCase();
} }
getGraphMethod(): string { getGraphMethod(): string {
@ -262,6 +268,18 @@ export class BaseEventsService<EventType extends MinimalEvents> {
} }
async getLatestEvents({ fromBlock }: { fromBlock: number }): Promise<BaseEvents<EventType>> { async getLatestEvents({ fromBlock }: { fromBlock: number }): Promise<BaseEvents<EventType>> {
if (this.tovarishClient?.selectedRelayer && ![DEPOSIT, WITHDRAWAL].includes(this.type.toLowerCase())) {
const { events, lastSyncBlock: lastBlock } = await this.tovarishClient.getEvents<EventType>({
type: this.getTovarishType(),
fromBlock,
});
return {
events,
lastBlock,
};
}
const graphEvents = await this.getEventsFromGraph({ fromBlock }); const graphEvents = await this.getEventsFromGraph({ fromBlock });
const lastSyncBlock = const lastSyncBlock =
graphEvents.lastBlock && graphEvents.lastBlock >= fromBlock ? graphEvents.lastBlock : fromBlock; graphEvents.lastBlock && graphEvents.lastBlock >= fromBlock ? graphEvents.lastBlock : fromBlock;
@ -340,6 +358,7 @@ export type BaseTornadoServiceConstructor = {
currency: string; currency: string;
deployedBlock?: number; deployedBlock?: number;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarishClient?: TovarishClient;
}; };
export type DepositsGraphParams = BaseGraphParams & { export type DepositsGraphParams = BaseGraphParams & {
@ -352,6 +371,7 @@ export class BaseTornadoService extends BaseEventsService<DepositsEvents | Withd
currency: string; currency: string;
batchTransactionService: BatchTransactionService; batchTransactionService: BatchTransactionService;
batchBlockService: BatchBlockService; batchBlockService: BatchBlockService;
tovarishClient?: TovarishClient;
constructor({ constructor({
netId, netId,
@ -364,8 +384,19 @@ export class BaseTornadoService extends BaseEventsService<DepositsEvents | Withd
currency, currency,
deployedBlock, deployedBlock,
fetchDataOptions, fetchDataOptions,
tovarishClient,
}: BaseTornadoServiceConstructor) { }: BaseTornadoServiceConstructor) {
super({ netId, provider, graphApi, subgraphName, contract: Tornado, type, deployedBlock, fetchDataOptions }); super({
netId,
provider,
graphApi,
subgraphName,
contract: Tornado,
type,
deployedBlock,
fetchDataOptions,
tovarishClient,
});
this.amount = amount; this.amount = amount;
this.currency = currency; this.currency = currency;
@ -467,6 +498,26 @@ export class BaseTornadoService extends BaseEventsService<DepositsEvents | Withd
} }
} }
} }
async getLatestEvents({ fromBlock }: { fromBlock: number }): Promise<BaseEvents<DepositsEvents | WithdrawalsEvents>> {
if (this.tovarishClient?.selectedRelayer) {
const { events, lastSyncBlock: lastBlock } = await this.tovarishClient.getEvents<
DepositsEvents | WithdrawalsEvents
>({
type: this.getTovarishType(),
currency: this.currency,
amount: this.amount,
fromBlock,
});
return {
events,
lastBlock,
};
}
return super.getLatestEvents({ fromBlock });
}
} }
export type BaseEchoServiceConstructor = { export type BaseEchoServiceConstructor = {
@ -477,6 +528,7 @@ export type BaseEchoServiceConstructor = {
Echoer: Echoer; Echoer: Echoer;
deployedBlock?: number; deployedBlock?: number;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarishClient?: TovarishClient;
}; };
export class BaseEchoService extends BaseEventsService<EchoEvents> { export class BaseEchoService extends BaseEventsService<EchoEvents> {
@ -488,8 +540,18 @@ export class BaseEchoService extends BaseEventsService<EchoEvents> {
Echoer, Echoer,
deployedBlock, deployedBlock,
fetchDataOptions, fetchDataOptions,
tovarishClient,
}: BaseEchoServiceConstructor) { }: BaseEchoServiceConstructor) {
super({ netId, provider, graphApi, subgraphName, contract: Echoer, deployedBlock, fetchDataOptions }); super({
netId,
provider,
graphApi,
subgraphName,
contract: Echoer,
deployedBlock,
fetchDataOptions,
tovarishClient,
});
} }
getInstanceName(): string { getInstanceName(): string {
@ -547,6 +609,7 @@ export type BaseEncryptedNotesServiceConstructor = {
Router: TornadoRouter | TornadoProxyLight; Router: TornadoRouter | TornadoProxyLight;
deployedBlock?: number; deployedBlock?: number;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarishClient?: TovarishClient;
}; };
export class BaseEncryptedNotesService extends BaseEventsService<EncryptedNotesEvents> { export class BaseEncryptedNotesService extends BaseEventsService<EncryptedNotesEvents> {
@ -558,8 +621,18 @@ export class BaseEncryptedNotesService extends BaseEventsService<EncryptedNotesE
Router, Router,
deployedBlock, deployedBlock,
fetchDataOptions, fetchDataOptions,
tovarishClient,
}: BaseEncryptedNotesServiceConstructor) { }: BaseEncryptedNotesServiceConstructor) {
super({ netId, provider, graphApi, subgraphName, contract: Router, deployedBlock, fetchDataOptions }); super({
netId,
provider,
graphApi,
subgraphName,
contract: Router,
deployedBlock,
fetchDataOptions,
tovarishClient,
});
} }
getInstanceName(): string { getInstanceName(): string {
@ -608,6 +681,7 @@ export type BaseGovernanceServiceConstructor = {
Governance: Governance; Governance: Governance;
deployedBlock?: number; deployedBlock?: number;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarishClient?: TovarishClient;
}; };
export class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents> { export class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents> {
@ -621,8 +695,18 @@ export class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents
Governance, Governance,
deployedBlock, deployedBlock,
fetchDataOptions, fetchDataOptions,
tovarishClient,
}: BaseGovernanceServiceConstructor) { }: BaseGovernanceServiceConstructor) {
super({ netId, provider, graphApi, subgraphName, contract: Governance, deployedBlock, fetchDataOptions }); super({
netId,
provider,
graphApi,
subgraphName,
contract: Governance,
deployedBlock,
fetchDataOptions,
tovarishClient,
});
this.batchTransactionService = new BatchTransactionService({ this.batchTransactionService = new BatchTransactionService({
provider, provider,
@ -799,6 +883,7 @@ export type BaseRegistryServiceConstructor = {
relayerEnsSubdomains: SubdomainMap; relayerEnsSubdomains: SubdomainMap;
deployedBlock?: number; deployedBlock?: number;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarishClient?: TovarishClient;
}; };
export class BaseRegistryService extends BaseEventsService<RegistersEvents> { export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
@ -816,8 +901,18 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
relayerEnsSubdomains, relayerEnsSubdomains,
deployedBlock, deployedBlock,
fetchDataOptions, fetchDataOptions,
tovarishClient,
}: BaseRegistryServiceConstructor) { }: BaseRegistryServiceConstructor) {
super({ netId, provider, graphApi, subgraphName, contract: RelayerRegistry, deployedBlock, fetchDataOptions }); super({
netId,
provider,
graphApi,
subgraphName,
contract: RelayerRegistry,
deployedBlock,
fetchDataOptions,
tovarishClient,
});
this.Aggregator = Aggregator; this.Aggregator = Aggregator;
this.relayerEnsSubdomains = relayerEnsSubdomains; this.relayerEnsSubdomains = relayerEnsSubdomains;

@ -15,5 +15,6 @@ export * from './prices';
export * from './providers'; export * from './providers';
export * from './relayerClient'; export * from './relayerClient';
export * from './tokens'; export * from './tokens';
export * from './tovarishClient';
export * from './utils'; export * from './utils';
export * from './websnark'; export * from './websnark';

@ -4,7 +4,7 @@ import { NetId, NetIdType, Config } from './networkConfig';
import { fetchData, fetchDataOptions } from './providers'; import { fetchData, fetchDataOptions } from './providers';
import { ajv, jobsSchema, getStatusSchema } from './schemas'; import { ajv, jobsSchema, getStatusSchema } from './schemas';
import type { snarkProofs } from './websnark'; import type { snarkProofs } from './websnark';
import { CachedRelayerInfo } from './events/base'; import type { CachedRelayerInfo } from './events';
export const MIN_FEE = 0.1; export const MIN_FEE = 0.1;
@ -190,11 +190,13 @@ export class RelayerClient {
config: Config; config: Config;
selectedRelayer?: RelayerInfo; selectedRelayer?: RelayerInfo;
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
tovarish: boolean;
constructor({ netId, config, fetchDataOptions }: RelayerClientConstructor) { constructor({ netId, config, fetchDataOptions }: RelayerClientConstructor) {
this.netId = netId; this.netId = netId;
this.config = config; this.config = config;
this.fetchDataOptions = fetchDataOptions; this.fetchDataOptions = fetchDataOptions;
this.tovarish = false;
} }
async askRelayerStatus({ async askRelayerStatus({
@ -225,7 +227,7 @@ export class RelayerClient {
maxRetry: this.fetchDataOptions?.torPort ? 2 : 0, maxRetry: this.fetchDataOptions?.torPort ? 2 : 0,
})) as object; })) as object;
const statusValidator = ajv.compile(getStatusSchema(this.netId, this.config)); const statusValidator = ajv.compile(getStatusSchema(this.netId, this.config, this.tovarish));
if (!statusValidator(rawStatus)) { if (!statusValidator(rawStatus)) {
throw new Error('Invalid status schema'); throw new Error('Invalid status schema');

@ -70,6 +70,16 @@ export type statusSchema = {
}; };
required: string[]; required: string[];
}; };
syncStatus: {
type: string;
properties: {
events: { type: string };
tokenPrice: { type: string };
gasPrice: { type: string };
};
required: string[];
};
onSyncEvents: { type: string };
currentQueue: { currentQueue: {
type: string; type: string;
}; };
@ -105,12 +115,22 @@ const statusSchema: statusSchema = {
}, },
required: ['status'], required: ['status'],
}, },
syncStatus: {
type: 'object',
properties: {
events: { type: 'boolean' },
tokenPrice: { type: 'boolean' },
gasPrice: { type: 'boolean' },
},
required: ['events', 'tokenPrice', 'gasPrice'],
},
onSyncEvents: { type: 'boolean' },
currentQueue: { type: 'number' }, currentQueue: { type: 'number' },
}, },
required: ['rewardAccount', 'instances', 'netId', 'tornadoServiceFee', 'version', 'health'], required: ['rewardAccount', 'instances', 'netId', 'tornadoServiceFee', 'version', 'health', 'currentQueue'],
}; };
export function getStatusSchema(netId: NetIdType, config: Config) { export function getStatusSchema(netId: NetIdType, config: Config, tovarish: boolean) {
const { tokens, optionalTokens, disabledTokens, nativeCurrency } = config; const { tokens, optionalTokens, disabledTokens, nativeCurrency } = config;
// deep copy schema // deep copy schema
@ -162,19 +182,29 @@ export function getStatusSchema(netId: NetIdType, config: Config) {
schema.properties.instances = instances; schema.properties.instances = instances;
if (netId === NetId.MAINNET) { const _tokens = Object.keys(tokens).filter(
const _tokens = Object.keys(tokens).filter((t) => t !== nativeCurrency); (t) => t !== nativeCurrency && !config.optionalTokens?.includes(t) && !config.disabledTokens?.includes(t),
);
if (netId === NetId.MAINNET) {
_tokens.push('torn');
}
if (_tokens.length) {
const ethPrices: statusEthPricesType = { const ethPrices: statusEthPricesType = {
type: 'object', type: 'object',
properties: _tokens.reduce((acc: { [key in string]: typeof bnType }, token: string) => { properties: _tokens.reduce((acc: { [key in string]: typeof bnType }, token: string) => {
acc[token] = bnType; acc[token] = bnType;
return acc; return acc;
}, {}), }, {}),
// required: _tokens required: _tokens,
}; };
schema.properties.ethPrices = ethPrices; schema.properties.ethPrices = ethPrices;
// schema.required.push('ethPrices') schema.required.push('ethPrices');
}
if (tovarish) {
schema.required.push('gasPrices', 'latestBlock', 'syncStatus', 'onSyncEvents');
} }
return schema; return schema;

242
src/tovarishClient.ts Normal file

@ -0,0 +1,242 @@
import { getAddress } from 'ethers';
import {
RelayerClient,
RelayerClientConstructor,
RelayerError,
RelayerInfo,
RelayerStatus,
getSupportedInstances,
} from './relayerClient';
import { fetchData } from './providers';
import { CachedRelayerInfo, MinimalEvents } from './events';
// Return no more than 5K events per query
export const MAX_TOVARISH_EVENTS = 5000;
export interface EventsStatus {
events: number;
lastBlock: number;
}
export interface InstanceEventsStatus {
[index: string]: {
deposits: EventsStatus;
withdrawals: EventsStatus;
};
}
export interface CurrencyEventsStatus {
[index: string]: InstanceEventsStatus;
}
export interface TovarishEventsStatus {
governance?: EventsStatus;
registered?: {
lastBlock: number;
timestamp: number;
relayers: number;
};
echo: EventsStatus;
encrypted_notes: EventsStatus;
instances: CurrencyEventsStatus;
}
export interface TovarishSyncStatus {
events: boolean;
tokenPrice: boolean;
gasPrice: boolean;
}
// Expected response from /status endpoint
export interface TovarishStatus extends RelayerStatus {
events: TovarishEventsStatus;
syncStatus: TovarishSyncStatus;
onSyncEvents: boolean;
}
// Formatted TovarishStatus for Frontend usage
export interface TovarishInfo extends RelayerInfo {
latestBlock: number;
version: string;
events: TovarishEventsStatus;
syncStatus: TovarishSyncStatus;
}
// Query input for TovarishEvents
export interface TovarishEventsQuery {
type: string;
currency?: string;
amount?: string;
fromBlock: number;
recent?: boolean;
}
export interface BaseTovarishEvents<T> {
events: T[];
lastSyncBlock: number;
}
export class TovarishClient extends RelayerClient {
selectedRelayer?: TovarishInfo;
constructor({ netId, config, fetchDataOptions }: RelayerClientConstructor) {
super({ netId, config, fetchDataOptions });
this.tovarish = true;
}
async askRelayerStatus({
hostname,
url,
relayerAddress,
}: {
hostname?: string;
// optional url if entered manually
url?: string;
// relayerAddress from registry contract to prevent cheating
relayerAddress?: string;
}): Promise<TovarishStatus> {
const status = (await super.askRelayerStatus({ hostname, url, relayerAddress })) as TovarishStatus;
if (!status.version.includes('tovarish')) {
throw new Error('Not a tovarish relayer!');
}
return status;
}
async filterRelayer(relayer: CachedRelayerInfo): Promise<TovarishInfo | RelayerError | undefined> {
const { ensName, relayerAddress, tovarishHost: hostname, tovarishNetworks } = relayer;
if (!hostname || !tovarishNetworks?.includes(this.netId)) {
return;
}
try {
const status = await this.askRelayerStatus({ hostname, relayerAddress });
return {
netId: status.netId,
url: status.url,
hostname,
ensName,
relayerAddress,
rewardAccount: getAddress(status.rewardAccount),
instances: getSupportedInstances(status.instances),
stakeBalance: relayer.stakeBalance,
gasPrice: status.gasPrices?.fast,
ethPrices: status.ethPrices,
currentQueue: status.currentQueue,
tornadoServiceFee: status.tornadoServiceFee,
// Additional fields for tovarish relayer
latestBlock: Number(status.latestBlock),
version: status.version,
events: status.events,
syncStatus: status.syncStatus,
} as TovarishInfo;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
return {
hostname,
relayerAddress,
errorMessage: err.message,
hasError: true,
} as RelayerError;
}
}
async getValidRelayers(relayers: CachedRelayerInfo[]): Promise<{
validRelayers: TovarishInfo[];
invalidRelayers: RelayerError[];
}> {
const invalidRelayers: RelayerError[] = [];
const validRelayers = (await Promise.all(relayers.map((relayer) => this.filterRelayer(relayer)))).filter((r) => {
if (!r) {
return false;
}
if ((r as RelayerError).hasError) {
invalidRelayers.push(r as RelayerError);
return false;
}
return true;
}) as TovarishInfo[];
return {
validRelayers,
invalidRelayers,
};
}
async getEvents<T extends MinimalEvents>({
type,
currency,
amount,
fromBlock,
recent,
}: TovarishEventsQuery): Promise<BaseTovarishEvents<T>> {
const url = `${this.selectedRelayer?.url}events`;
try {
const events = [];
let lastSyncBlock = fromBlock;
// eslint-disable-next-line no-constant-condition
while (true) {
// eslint-disable-next-line prefer-const
let { events: fetchedEvents, lastSyncBlock: currentBlock } = (await fetchData(url, {
...this.fetchDataOptions,
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
type,
currency,
amount,
fromBlock,
recent,
}),
})) as BaseTovarishEvents<T>;
lastSyncBlock = currentBlock;
if (!Array.isArray(fetchedEvents) || !fetchedEvents.length) {
break;
}
fetchedEvents = fetchedEvents.sort((a, b) => {
if (a.blockNumber === b.blockNumber) {
return a.logIndex - b.logIndex;
}
return a.blockNumber - b.blockNumber;
});
const [lastEvent] = fetchedEvents.slice(-1);
if (fetchedEvents.length < MAX_TOVARISH_EVENTS - 100) {
events.push(...fetchedEvents);
break;
}
fetchedEvents = fetchedEvents.filter((e) => e.blockNumber !== lastEvent.blockNumber);
fromBlock = Number(lastEvent.blockNumber);
events.push(...fetchedEvents);
}
return {
events,
lastSyncBlock,
};
} catch (err) {
console.log('Error from TovarishClient events endpoint');
console.log(err);
return {
events: [],
lastSyncBlock: fromBlock,
};
}
}
}