Minor updates #1

Closed
tornadocontrib wants to merge 67 commits from tornadocontrib/tornado-core:main into main
13 changed files with 252 additions and 105 deletions
Showing only changes of commit 69faa7a974 - Show all commits

View File

@ -1,7 +1,7 @@
import { BaseContract, Provider, EventLog, ContractEventName } from 'ethers';
import type { Tornado, TornadoRouter, TornadoProxyLight, Governance, RelayerRegistry, Echoer, Aggregator } from '@tornado/contracts';
import { BatchEventsService, BatchBlockService, BatchTransactionService, BatchEventOnProgress, BatchBlockOnProgress } from '../batch';
import type { fetchDataOptions } from '../providers';
import { fetchDataOptions } from '../providers';
import type { NetIdType, SubdomainMap } from '../networkConfig';
import { RelayerParams } from '../relayerClient';
import type { BaseEvents, CachedEvents, MinimalEvents, DepositsEvents, WithdrawalsEvents, EncryptedNotesEvents, AllGovernanceEvents, RegistersEvents, EchoEvents } from './types';
@ -170,6 +170,7 @@ export declare class BaseGovernanceService extends BaseEventsService<AllGovernan
fromBlock: number;
}): Promise<BaseEvents<AllGovernanceEvents>>;
}
export declare function getTovarishNetworks(registryService: BaseRegistryService, relayers: CachedRelayerInfo[]): Promise<void>;
/**
* Essential params:
* ensName, relayerAddress, hostnames
@ -180,6 +181,8 @@ export interface CachedRelayerInfo extends RelayerParams {
owner?: string;
stakeBalance?: string;
hostnames: SubdomainMap;
tovarishUrl?: string;
tovarishNetworks?: number[];
}
export interface CachedRelayers {
timestamp: number;

68
dist/index.js vendored
View File

@ -2368,6 +2368,15 @@ function getActiveTokens(config) {
const { tokens, disabledTokens } = config;
return Object.keys(tokens).filter((t) => !(disabledTokens == null ? void 0 : disabledTokens.includes(t)));
}
function getActiveTokenInstances(config) {
const { tokens, disabledTokens } = config;
return Object.entries(tokens).reduce((acc, [token, instances]) => {
if (!(disabledTokens == null ? void 0 : disabledTokens.includes(token))) {
acc[token] = instances;
}
return acc;
}, {});
}
function getInstanceByAddress(config, address) {
const { tokens, disabledTokens } = config;
for (const [currency, { instanceAddress }] of Object.entries(tokens)) {
@ -2556,7 +2565,7 @@ var __async$9 = (__this, __arguments, generator) => {
});
};
const MIN_FEE = 0.1;
const MAX_FEE = 0.6;
const MAX_FEE = 0.9;
const MIN_STAKE_BALANCE = ethers.parseEther("500");
function calculateScore({ stakeBalance, tornadoServiceFee }) {
if (tornadoServiceFee < MIN_FEE) {
@ -2804,13 +2813,13 @@ class BaseEventsService {
contract,
type = "",
deployedBlock = 0,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
this.netId = netId;
this.provider = provider;
this.graphApi = graphApi;
this.subgraphName = subgraphName;
this.fetchDataOptions = fetchDataOptions;
this.fetchDataOptions = fetchDataOptions2;
this.contract = contract;
this.type = type;
this.deployedBlock = deployedBlock;
@ -3008,9 +3017,9 @@ class BaseTornadoService extends BaseEventsService {
amount,
currency,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: Tornado, type, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: Tornado, type, deployedBlock, fetchDataOptions: fetchDataOptions2 });
this.amount = amount;
this.currency = currency;
this.batchTransactionService = new BatchTransactionService({
@ -3104,9 +3113,9 @@ class BaseEchoService extends BaseEventsService {
subgraphName,
Echoer,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: Echoer, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: Echoer, deployedBlock, fetchDataOptions: fetchDataOptions2 });
}
getInstanceName() {
return `echo_${this.netId}`;
@ -3155,9 +3164,9 @@ class BaseEncryptedNotesService extends BaseEventsService {
subgraphName,
Router,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: Router, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: Router, deployedBlock, fetchDataOptions: fetchDataOptions2 });
}
getInstanceName() {
return `encrypted_notes_${this.netId}`;
@ -3194,9 +3203,9 @@ class BaseGovernanceService extends BaseEventsService {
subgraphName,
Governance,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: Governance, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: Governance, deployedBlock, fetchDataOptions: fetchDataOptions2 });
this.batchTransactionService = new BatchTransactionService({
provider,
onProgress: this.updateTransactionProgress
@ -3290,6 +3299,26 @@ class BaseGovernanceService extends BaseEventsService {
});
}
}
function getTovarishNetworks(registryService, relayers) {
return __async$8(this, null, function* () {
yield Promise.all(
relayers.filter((r) => r.tovarishUrl).map((relayer) => __async$8(this, null, function* () {
var _a, _b;
try {
relayer.tovarishNetworks = yield fetchData(relayer.tovarishUrl, __spreadProps(__spreadValues({}, registryService.fetchDataOptions), {
headers: {
"Content-Type": "application/json"
},
timeout: ((_a = registryService.fetchDataOptions) == null ? void 0 : _a.torPort) ? 1e4 : 3e3,
maxRetry: ((_b = registryService.fetchDataOptions) == null ? void 0 : _b.torPort) ? 2 : 0
}));
} catch (e) {
relayer.tovarishNetworks = [];
}
}))
);
});
}
class BaseRegistryService extends BaseEventsService {
constructor({
netId,
@ -3300,9 +3329,9 @@ class BaseRegistryService extends BaseEventsService {
Aggregator,
relayerEnsSubdomains,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: RelayerRegistry, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: RelayerRegistry, deployedBlock, fetchDataOptions: fetchDataOptions2 });
this.Aggregator = Aggregator;
this.relayerEnsSubdomains = relayerEnsSubdomains;
this.updateInterval = 86400;
@ -3379,13 +3408,18 @@ class BaseRegistryService extends BaseEventsService {
});
const relayerNameHashes = uniqueRegisters.map((r) => ethers.namehash(r.ensName));
const [relayersData, timestamp] = yield Promise.all([
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains),
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains.concat("tovarish-relayer")),
this.provider.getBlock("latest").then((b) => Number(b == null ? void 0 : b.timestamp))
]);
const relayers = relayersData.map(({ owner, balance: stakeBalance, records, isRegistered }, index) => {
const { ensName, relayerAddress } = uniqueRegisters[index];
let tovarishUrl = void 0;
const hostnames = records.reduce((acc, record, recordIndex) => {
if (record) {
if (recordIndex === records.length - 1) {
tovarishUrl = record;
return acc;
}
acc[Number(Object.keys(this.relayerEnsSubdomains)[recordIndex])] = record;
}
return acc;
@ -3400,10 +3434,12 @@ class BaseRegistryService extends BaseEventsService {
isRegistered,
owner,
stakeBalance: ethers.formatEther(stakeBalance),
hostnames
hostnames,
tovarishUrl
};
}
}).filter((r) => r);
yield getTovarishNetworks(this, relayers);
return {
timestamp,
relayers
@ -6711,6 +6747,7 @@ exports.factories = index;
exports.fetch = fetch;
exports.fetchData = fetchData;
exports.fetchGetUrlFunc = fetchGetUrlFunc;
exports.getActiveTokenInstances = getActiveTokenInstances;
exports.getActiveTokens = getActiveTokens;
exports.getAllDeposits = getAllDeposits;
exports.getAllEncryptedNotes = getAllEncryptedNotes;
@ -6736,6 +6773,7 @@ exports.getStatistic = getStatistic;
exports.getStatusSchema = getStatusSchema;
exports.getSupportedInstances = getSupportedInstances;
exports.getTokenBalances = getTokenBalances;
exports.getTovarishNetworks = getTovarishNetworks;
exports.getWeightRandom = getWeightRandom;
exports.getWithdrawals = getWithdrawals;
exports.hexToBytes = hexToBytes;

68
dist/index.mjs vendored
View File

@ -2347,6 +2347,15 @@ function getActiveTokens(config) {
const { tokens, disabledTokens } = config;
return Object.keys(tokens).filter((t) => !(disabledTokens == null ? void 0 : disabledTokens.includes(t)));
}
function getActiveTokenInstances(config) {
const { tokens, disabledTokens } = config;
return Object.entries(tokens).reduce((acc, [token, instances]) => {
if (!(disabledTokens == null ? void 0 : disabledTokens.includes(token))) {
acc[token] = instances;
}
return acc;
}, {});
}
function getInstanceByAddress(config, address) {
const { tokens, disabledTokens } = config;
for (const [currency, { instanceAddress }] of Object.entries(tokens)) {
@ -2535,7 +2544,7 @@ var __async$9 = (__this, __arguments, generator) => {
});
};
const MIN_FEE = 0.1;
const MAX_FEE = 0.6;
const MAX_FEE = 0.9;
const MIN_STAKE_BALANCE = parseEther("500");
function calculateScore({ stakeBalance, tornadoServiceFee }) {
if (tornadoServiceFee < MIN_FEE) {
@ -2783,13 +2792,13 @@ class BaseEventsService {
contract,
type = "",
deployedBlock = 0,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
this.netId = netId;
this.provider = provider;
this.graphApi = graphApi;
this.subgraphName = subgraphName;
this.fetchDataOptions = fetchDataOptions;
this.fetchDataOptions = fetchDataOptions2;
this.contract = contract;
this.type = type;
this.deployedBlock = deployedBlock;
@ -2987,9 +2996,9 @@ class BaseTornadoService extends BaseEventsService {
amount,
currency,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: Tornado, type, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: Tornado, type, deployedBlock, fetchDataOptions: fetchDataOptions2 });
this.amount = amount;
this.currency = currency;
this.batchTransactionService = new BatchTransactionService({
@ -3083,9 +3092,9 @@ class BaseEchoService extends BaseEventsService {
subgraphName,
Echoer,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: Echoer, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: Echoer, deployedBlock, fetchDataOptions: fetchDataOptions2 });
}
getInstanceName() {
return `echo_${this.netId}`;
@ -3134,9 +3143,9 @@ class BaseEncryptedNotesService extends BaseEventsService {
subgraphName,
Router,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: Router, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: Router, deployedBlock, fetchDataOptions: fetchDataOptions2 });
}
getInstanceName() {
return `encrypted_notes_${this.netId}`;
@ -3173,9 +3182,9 @@ class BaseGovernanceService extends BaseEventsService {
subgraphName,
Governance,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: Governance, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: Governance, deployedBlock, fetchDataOptions: fetchDataOptions2 });
this.batchTransactionService = new BatchTransactionService({
provider,
onProgress: this.updateTransactionProgress
@ -3269,6 +3278,26 @@ class BaseGovernanceService extends BaseEventsService {
});
}
}
function getTovarishNetworks(registryService, relayers) {
return __async$8(this, null, function* () {
yield Promise.all(
relayers.filter((r) => r.tovarishUrl).map((relayer) => __async$8(this, null, function* () {
var _a, _b;
try {
relayer.tovarishNetworks = yield fetchData(relayer.tovarishUrl, __spreadProps(__spreadValues({}, registryService.fetchDataOptions), {
headers: {
"Content-Type": "application/json"
},
timeout: ((_a = registryService.fetchDataOptions) == null ? void 0 : _a.torPort) ? 1e4 : 3e3,
maxRetry: ((_b = registryService.fetchDataOptions) == null ? void 0 : _b.torPort) ? 2 : 0
}));
} catch (e) {
relayer.tovarishNetworks = [];
}
}))
);
});
}
class BaseRegistryService extends BaseEventsService {
constructor({
netId,
@ -3279,9 +3308,9 @@ class BaseRegistryService extends BaseEventsService {
Aggregator,
relayerEnsSubdomains,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: RelayerRegistry, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: RelayerRegistry, deployedBlock, fetchDataOptions: fetchDataOptions2 });
this.Aggregator = Aggregator;
this.relayerEnsSubdomains = relayerEnsSubdomains;
this.updateInterval = 86400;
@ -3358,13 +3387,18 @@ class BaseRegistryService extends BaseEventsService {
});
const relayerNameHashes = uniqueRegisters.map((r) => namehash(r.ensName));
const [relayersData, timestamp] = yield Promise.all([
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains),
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains.concat("tovarish-relayer")),
this.provider.getBlock("latest").then((b) => Number(b == null ? void 0 : b.timestamp))
]);
const relayers = relayersData.map(({ owner, balance: stakeBalance, records, isRegistered }, index) => {
const { ensName, relayerAddress } = uniqueRegisters[index];
let tovarishUrl = void 0;
const hostnames = records.reduce((acc, record, recordIndex) => {
if (record) {
if (recordIndex === records.length - 1) {
tovarishUrl = record;
return acc;
}
acc[Number(Object.keys(this.relayerEnsSubdomains)[recordIndex])] = record;
}
return acc;
@ -3379,10 +3413,12 @@ class BaseRegistryService extends BaseEventsService {
isRegistered,
owner,
stakeBalance: formatEther(stakeBalance),
hostnames
hostnames,
tovarishUrl
};
}
}).filter((r) => r);
yield getTovarishNetworks(this, relayers);
return {
timestamp,
relayers
@ -6621,4 +6657,4 @@ function calculateSnarkProof(input, circuit, provingKey) {
});
}
export { BaseEchoService, BaseEncryptedNotesService, BaseEventsService, BaseGovernanceService, BaseRegistryService, BaseTornadoService, BatchBlockService, BatchEventsService, BatchTransactionService, DEPOSIT, Deposit, ENS__factory, ERC20__factory, GET_DEPOSITS, GET_ECHO_EVENTS, GET_ENCRYPTED_NOTES, GET_GOVERNANCE_APY, GET_GOVERNANCE_EVENTS, GET_NOTE_ACCOUNTS, GET_REGISTERED, GET_STATISTIC, GET_WITHDRAWALS, Invoice, MAX_FEE, MIN_FEE, MIN_STAKE_BALANCE, MerkleTreeService, Mimc, Multicall__factory, NetId, NoteAccount, OffchainOracle__factory, OvmGasPriceOracle__factory, Pedersen, RelayerClient, ReverseRecords__factory, TokenPriceOracle, TornadoBrowserProvider, TornadoFeeOracle, TornadoRpcSigner, TornadoVoidSigner, TornadoWallet, WITHDRAWAL, _META, addNetwork, ajv, base64ToBytes, bigIntReplacer, bnToBytes, buffPedersenHash, bufferToBytes, bytesToBN, bytesToBase64, bytesToHex, calculateScore, calculateSnarkProof, chunk, concatBytes, convertETHToTokenAmount, createDeposit, crypto, customConfig, defaultConfig, defaultUserAgent, digest, enabledChains, index as factories, fetch, fetchData, fetchGetUrlFunc, getActiveTokens, getAllDeposits, getAllEncryptedNotes, getAllGovernanceEvents, getAllGraphEchoEvents, getAllRegisters, getAllWithdrawals, getConfig, getDeposits, getEncryptedNotes, getGovernanceEvents, getGraphEchoEvents, getHttpAgent, getInstanceByAddress, getMeta, getNetworkConfig, getNoteAccounts, getProvider, getProviderWithNetId, getRegisters, getRelayerEnsSubdomains, getStatistic, getStatusSchema, getSupportedInstances, getTokenBalances, getWeightRandom, getWithdrawals, hexToBytes, initGroth16, isNode, jobsSchema, leBuff2Int, leInt2Buff, mimc, multicall, packEncryptedMessage, pedersen, pickWeightedRandomRelayer, populateTransaction, queryGraph, rBigInt, sleep, substring, toFixedHex, toFixedLength, unpackEncryptedMessage, validateUrl };
export { BaseEchoService, BaseEncryptedNotesService, BaseEventsService, BaseGovernanceService, BaseRegistryService, BaseTornadoService, BatchBlockService, BatchEventsService, BatchTransactionService, DEPOSIT, Deposit, ENS__factory, ERC20__factory, GET_DEPOSITS, GET_ECHO_EVENTS, GET_ENCRYPTED_NOTES, GET_GOVERNANCE_APY, GET_GOVERNANCE_EVENTS, GET_NOTE_ACCOUNTS, GET_REGISTERED, GET_STATISTIC, GET_WITHDRAWALS, Invoice, MAX_FEE, MIN_FEE, MIN_STAKE_BALANCE, MerkleTreeService, Mimc, Multicall__factory, NetId, NoteAccount, OffchainOracle__factory, OvmGasPriceOracle__factory, Pedersen, RelayerClient, ReverseRecords__factory, TokenPriceOracle, TornadoBrowserProvider, TornadoFeeOracle, TornadoRpcSigner, TornadoVoidSigner, TornadoWallet, WITHDRAWAL, _META, addNetwork, ajv, base64ToBytes, bigIntReplacer, bnToBytes, buffPedersenHash, bufferToBytes, bytesToBN, bytesToBase64, bytesToHex, calculateScore, calculateSnarkProof, chunk, concatBytes, convertETHToTokenAmount, createDeposit, crypto, customConfig, defaultConfig, defaultUserAgent, digest, enabledChains, index as factories, fetch, fetchData, fetchGetUrlFunc, getActiveTokenInstances, getActiveTokens, getAllDeposits, getAllEncryptedNotes, getAllGovernanceEvents, getAllGraphEchoEvents, getAllRegisters, getAllWithdrawals, getConfig, getDeposits, getEncryptedNotes, getGovernanceEvents, getGraphEchoEvents, getHttpAgent, getInstanceByAddress, getMeta, getNetworkConfig, getNoteAccounts, getProvider, getProviderWithNetId, getRegisters, getRelayerEnsSubdomains, getStatistic, getStatusSchema, getSupportedInstances, getTokenBalances, getTovarishNetworks, getWeightRandom, getWithdrawals, hexToBytes, initGroth16, isNode, jobsSchema, leBuff2Int, leInt2Buff, mimc, multicall, packEncryptedMessage, pedersen, pickWeightedRandomRelayer, populateTransaction, queryGraph, rBigInt, sleep, substring, toFixedHex, toFixedLength, unpackEncryptedMessage, validateUrl };

View File

@ -109,6 +109,7 @@ export declare function addNetwork(newConfig: networkConfig): void;
export declare function getNetworkConfig(): networkConfig;
export declare function getConfig(netId: NetIdType): Config;
export declare function getActiveTokens(config: Config): string[];
export declare function getActiveTokenInstances(config: Config): TokenInstances;
export declare function getInstanceByAddress(config: Config, address: string): {
amount: string;
currency: string;

View File

@ -3,7 +3,7 @@ import { fetchDataOptions } from './providers';
import type { snarkProofs } from './websnark';
import { CachedRelayerInfo } from './events/base';
export declare const MIN_FEE = 0.1;
export declare const MAX_FEE = 0.6;
export declare const MAX_FEE = 0.9;
export declare const MIN_STAKE_BALANCE: bigint;
export interface RelayerParams {
ensName: string;
@ -63,6 +63,9 @@ export interface RelayerStatus {
};
currentQueue: number;
}
export type TornadoWithdrawParams = snarkProofs & {
contract: string;
};
export interface RelayerTornadoWithdraw {
id?: string;
error?: string;
@ -122,9 +125,6 @@ export interface RelayerClientConstructor {
config: Config;
fetchDataOptions?: fetchDataOptions;
}
export type RelayerClientWithdraw = snarkProofs & {
contract: string;
};
export declare class RelayerClient {
netId: NetIdType;
config: Config;
@ -141,5 +141,5 @@ export declare class RelayerClient {
invalidRelayers: RelayerError[];
}>;
pickWeightedRandomRelayer(relayers: RelayerInfo[]): RelayerInfo;
tornadoWithdraw({ contract, proof, args }: RelayerClientWithdraw): Promise<void>;
tornadoWithdraw({ contract, proof, args }: TornadoWithdrawParams): Promise<void>;
}

90
dist/tornado.umd.js vendored
View File

@ -59060,6 +59060,7 @@ class NoteAccount {
"use strict";
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ EU: () => (/* binding */ getTovarishNetworks),
/* harmony export */ GS: () => (/* binding */ BaseEchoService),
/* harmony export */ JJ: () => (/* binding */ BaseGovernanceService),
/* harmony export */ Lx: () => (/* binding */ DEPOSIT),
@ -59069,12 +59070,13 @@ class NoteAccount {
/* harmony export */ oW: () => (/* binding */ WITHDRAWAL),
/* harmony export */ uw: () => (/* binding */ BaseEventsService)
/* harmony export */ });
/* harmony import */ var ethers__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(30031);
/* harmony import */ var ethers__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(64563);
/* harmony import */ var ethers__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(99770);
/* harmony import */ var ethers__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(30031);
/* harmony import */ var ethers__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(64563);
/* harmony import */ var ethers__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(99770);
/* harmony import */ var _graphql__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(52049);
/* harmony import */ var _batch__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9723);
/* harmony import */ var _relayerClient__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(57194);
/* harmony import */ var _providers__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(68434);
/* harmony import */ var _relayerClient__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(57194);
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
@ -59122,6 +59124,7 @@ var __async = (__this, __arguments, generator) => {
const DEPOSIT = "deposit";
const WITHDRAWAL = "withdrawal";
class BaseEventsService {
@ -59133,13 +59136,13 @@ class BaseEventsService {
contract,
type = "",
deployedBlock = 0,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
this.netId = netId;
this.provider = provider;
this.graphApi = graphApi;
this.subgraphName = subgraphName;
this.fetchDataOptions = fetchDataOptions;
this.fetchDataOptions = fetchDataOptions2;
this.contract = contract;
this.type = type;
this.deployedBlock = deployedBlock;
@ -59337,9 +59340,9 @@ class BaseTornadoService extends BaseEventsService {
amount,
currency,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: Tornado, type, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: Tornado, type, deployedBlock, fetchDataOptions: fetchDataOptions2 });
this.amount = amount;
this.currency = currency;
this.batchTransactionService = new _batch__WEBPACK_IMPORTED_MODULE_1__/* .BatchTransactionService */ .AF({
@ -59399,7 +59402,7 @@ class BaseTornadoService extends BaseEventsService {
logIndex,
transactionHash,
nullifierHash: String(nullifierHash),
to: (0,ethers__WEBPACK_IMPORTED_MODULE_3__/* .getAddress */ .b)(to),
to: (0,ethers__WEBPACK_IMPORTED_MODULE_4__/* .getAddress */ .b)(to),
fee: String(fee)
};
});
@ -59433,9 +59436,9 @@ class BaseEchoService extends BaseEventsService {
subgraphName,
Echoer,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: Echoer, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: Echoer, deployedBlock, fetchDataOptions: fetchDataOptions2 });
}
getInstanceName() {
return `echo_${this.netId}`;
@ -59484,9 +59487,9 @@ class BaseEncryptedNotesService extends BaseEventsService {
subgraphName,
Router,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: Router, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: Router, deployedBlock, fetchDataOptions: fetchDataOptions2 });
}
getInstanceName() {
return `encrypted_notes_${this.netId}`;
@ -59523,9 +59526,9 @@ class BaseGovernanceService extends BaseEventsService {
subgraphName,
Governance,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: Governance, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: Governance, deployedBlock, fetchDataOptions: fetchDataOptions2 });
this.batchTransactionService = new _batch__WEBPACK_IMPORTED_MODULE_1__/* .BatchTransactionService */ .AF({
provider,
onProgress: this.updateTransactionProgress
@ -59619,6 +59622,26 @@ class BaseGovernanceService extends BaseEventsService {
});
}
}
function getTovarishNetworks(registryService, relayers) {
return __async(this, null, function* () {
yield Promise.all(
relayers.filter((r) => r.tovarishUrl).map((relayer) => __async(this, null, function* () {
var _a, _b;
try {
relayer.tovarishNetworks = yield (0,_providers__WEBPACK_IMPORTED_MODULE_2__/* .fetchData */ .Fd)(relayer.tovarishUrl, __spreadProps(__spreadValues({}, registryService.fetchDataOptions), {
headers: {
"Content-Type": "application/json"
},
timeout: ((_a = registryService.fetchDataOptions) == null ? void 0 : _a.torPort) ? 1e4 : 3e3,
maxRetry: ((_b = registryService.fetchDataOptions) == null ? void 0 : _b.torPort) ? 2 : 0
}));
} catch (e) {
relayer.tovarishNetworks = [];
}
}))
);
});
}
class BaseRegistryService extends BaseEventsService {
constructor({
netId,
@ -59629,9 +59652,9 @@ class BaseRegistryService extends BaseEventsService {
Aggregator,
relayerEnsSubdomains,
deployedBlock,
fetchDataOptions
fetchDataOptions: fetchDataOptions2
}) {
super({ netId, provider, graphApi, subgraphName, contract: RelayerRegistry, deployedBlock, fetchDataOptions });
super({ netId, provider, graphApi, subgraphName, contract: RelayerRegistry, deployedBlock, fetchDataOptions: fetchDataOptions2 });
this.Aggregator = Aggregator;
this.relayerEnsSubdomains = relayerEnsSubdomains;
this.updateInterval = 86400;
@ -59706,21 +59729,26 @@ class BaseRegistryService extends BaseEventsService {
}
return false;
});
const relayerNameHashes = uniqueRegisters.map((r) => (0,ethers__WEBPACK_IMPORTED_MODULE_4__/* .namehash */ .kM)(r.ensName));
const relayerNameHashes = uniqueRegisters.map((r) => (0,ethers__WEBPACK_IMPORTED_MODULE_5__/* .namehash */ .kM)(r.ensName));
const [relayersData, timestamp] = yield Promise.all([
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains),
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains.concat("tovarish-relayer")),
this.provider.getBlock("latest").then((b) => Number(b == null ? void 0 : b.timestamp))
]);
const relayers = relayersData.map(({ owner, balance: stakeBalance, records, isRegistered }, index) => {
const { ensName, relayerAddress } = uniqueRegisters[index];
let tovarishUrl = void 0;
const hostnames = records.reduce((acc, record, recordIndex) => {
if (record) {
if (recordIndex === records.length - 1) {
tovarishUrl = record;
return acc;
}
acc[Number(Object.keys(this.relayerEnsSubdomains)[recordIndex])] = record;
}
return acc;
}, {});
const isOwner = !relayerAddress || relayerAddress === owner;
const hasMinBalance = stakeBalance >= _relayerClient__WEBPACK_IMPORTED_MODULE_2__/* .MIN_STAKE_BALANCE */ .pO;
const hasMinBalance = stakeBalance >= _relayerClient__WEBPACK_IMPORTED_MODULE_3__/* .MIN_STAKE_BALANCE */ .pO;
const preCondition = Object.keys(hostnames).length && isOwner && isRegistered && hasMinBalance;
if (preCondition) {
return {
@ -59728,11 +59756,13 @@ class BaseRegistryService extends BaseEventsService {
relayerAddress,
isRegistered,
owner,
stakeBalance: (0,ethers__WEBPACK_IMPORTED_MODULE_5__/* .formatEther */ .ck)(stakeBalance),
hostnames
stakeBalance: (0,ethers__WEBPACK_IMPORTED_MODULE_6__/* .formatEther */ .ck)(stakeBalance),
hostnames,
tovarishUrl
};
}
}).filter((r) => r);
yield getTovarishNetworks(this, relayers);
return {
timestamp,
relayers
@ -59783,7 +59813,8 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ BaseRegistryService: () => (/* reexport safe */ _base__WEBPACK_IMPORTED_MODULE_1__.cE),
/* harmony export */ BaseTornadoService: () => (/* reexport safe */ _base__WEBPACK_IMPORTED_MODULE_1__.e0),
/* harmony export */ DEPOSIT: () => (/* reexport safe */ _base__WEBPACK_IMPORTED_MODULE_1__.Lx),
/* harmony export */ WITHDRAWAL: () => (/* reexport safe */ _base__WEBPACK_IMPORTED_MODULE_1__.oW)
/* harmony export */ WITHDRAWAL: () => (/* reexport safe */ _base__WEBPACK_IMPORTED_MODULE_1__.oW),
/* harmony export */ getTovarishNetworks: () => (/* reexport safe */ _base__WEBPACK_IMPORTED_MODULE_1__.EU)
/* harmony export */ });
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(61060);
/* harmony import */ var _types__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_types__WEBPACK_IMPORTED_MODULE_0__);
@ -61234,6 +61265,7 @@ function multicall(Multicall2, calls) {
/* harmony export */ cX: () => (/* binding */ customConfig),
/* harmony export */ h9: () => (/* binding */ getActiveTokens),
/* harmony export */ o2: () => (/* binding */ getRelayerEnsSubdomains),
/* harmony export */ oY: () => (/* binding */ getActiveTokenInstances),
/* harmony export */ sb: () => (/* binding */ defaultConfig),
/* harmony export */ zj: () => (/* binding */ getConfig),
/* harmony export */ zr: () => (/* binding */ NetId)
@ -61857,6 +61889,15 @@ function getActiveTokens(config) {
const { tokens, disabledTokens } = config;
return Object.keys(tokens).filter((t) => !(disabledTokens == null ? void 0 : disabledTokens.includes(t)));
}
function getActiveTokenInstances(config) {
const { tokens, disabledTokens } = config;
return Object.entries(tokens).reduce((acc, [token, instances]) => {
if (!(disabledTokens == null ? void 0 : disabledTokens.includes(token))) {
acc[token] = instances;
}
return acc;
}, {});
}
function getInstanceByAddress(config, address) {
const { tokens, disabledTokens } = config;
for (const [currency, { instanceAddress }] of Object.entries(tokens)) {
@ -71479,7 +71520,7 @@ var __async = (__this, __arguments, generator) => {
const MIN_FEE = 0.1;
const MAX_FEE = 0.6;
const MAX_FEE = 0.9;
const MIN_STAKE_BALANCE = (0,ethers__WEBPACK_IMPORTED_MODULE_4__/* .parseEther */ .g5)("500");
function calculateScore({ stakeBalance, tornadoServiceFee }) {
if (tornadoServiceFee < MIN_FEE) {
@ -173028,6 +173069,7 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ fetch: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.hd),
/* harmony export */ fetchData: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.Fd),
/* harmony export */ fetchGetUrlFunc: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_14__.uY),
/* harmony export */ getActiveTokenInstances: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.oY),
/* harmony export */ getActiveTokens: () => (/* reexport safe */ _networkConfig__WEBPACK_IMPORTED_MODULE_11__.h9),
/* harmony export */ getAllDeposits: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getAllDeposits),
/* harmony export */ getAllEncryptedNotes: () => (/* reexport safe */ _graphql__WEBPACK_IMPORTED_MODULE_1__.getAllEncryptedNotes),

File diff suppressed because one or more lines are too long

17
dist/websnark.d.ts vendored
View File

@ -1,10 +1,9 @@
import type { Element } from '@tornado/fixed-merkle-tree';
import type { AddressLike, BytesLike, BigNumberish } from 'ethers';
export type snarkInputs = {
root: Element;
nullifierHex: string;
recipient: AddressLike;
relayer: AddressLike;
recipient: string;
relayer: string;
fee: bigint;
refund: bigint;
nullifier: bigint;
@ -12,17 +11,9 @@ export type snarkInputs = {
pathElements: Element[];
pathIndices: Element[];
};
export type snarkArgs = [
_root: BytesLike,
_nullifierHash: BytesLike,
_recipient: AddressLike,
_relayer: AddressLike,
_fee: BigNumberish,
_refund: BigNumberish
];
export type snarkProofs = {
proof: BytesLike;
args: snarkArgs;
proof: string;
args: string[];
};
export declare function initGroth16(): Promise<void>;
export declare function calculateSnarkProof(input: snarkInputs, circuit: object, provingKey: ArrayBuffer): Promise<snarkProofs>;

View File

@ -1,6 +1,6 @@
{
"name": "@tornado/core",
"version": "1.0.14",
"version": "1.0.15",
"description": "An SDK for building applications on top of Privacy Pools",
"main": "./dist/index.js",
"module": "./dist/index.mjs",

View File

@ -30,7 +30,7 @@ import {
BatchBlockOnProgress,
} from '../batch';
import type { fetchDataOptions } from '../providers';
import { fetchData, fetchDataOptions } from '../providers';
import type { NetIdType, SubdomainMap } from '../networkConfig';
import { RelayerParams, MIN_STAKE_BALANCE } from '../relayerClient';
@ -734,6 +734,28 @@ export class BaseGovernanceService extends BaseEventsService<AllGovernanceEvents
}
}
export async function getTovarishNetworks(registryService: BaseRegistryService, relayers: CachedRelayerInfo[]) {
await Promise.all(
relayers
.filter((r) => r.tovarishUrl)
.map(async (relayer) => {
try {
relayer.tovarishNetworks = await fetchData(relayer.tovarishUrl as string, {
...registryService.fetchDataOptions,
headers: {
'Content-Type': 'application/json',
},
timeout: registryService.fetchDataOptions?.torPort ? 10000 : 3000,
maxRetry: registryService.fetchDataOptions?.torPort ? 2 : 0,
});
} catch {
// Ignore error and disable relayer
relayer.tovarishNetworks = [];
}
}),
);
}
/**
* Essential params:
* ensName, relayerAddress, hostnames
@ -744,6 +766,8 @@ export interface CachedRelayerInfo extends RelayerParams {
owner?: string;
stakeBalance?: string;
hostnames: SubdomainMap;
tovarishUrl?: string;
tovarishNetworks?: number[];
}
export interface CachedRelayers {
@ -867,7 +891,7 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
const relayerNameHashes = uniqueRegisters.map((r) => namehash(r.ensName));
const [relayersData, timestamp] = await Promise.all([
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains),
this.Aggregator.relayersData.staticCall(relayerNameHashes, subdomains.concat('tovarish-relayer')),
this.provider.getBlock('latest').then((b) => Number(b?.timestamp)),
]);
@ -875,8 +899,16 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
.map(({ owner, balance: stakeBalance, records, isRegistered }, index) => {
const { ensName, relayerAddress } = uniqueRegisters[index];
let tovarishUrl = undefined;
const hostnames = records.reduce((acc, record, recordIndex) => {
if (record) {
// tovarish-relayer.relayer.eth
if (recordIndex === records.length - 1) {
tovarishUrl = record;
return acc;
}
acc[Number(Object.keys(this.relayerEnsSubdomains)[recordIndex])] = record;
}
return acc;
@ -895,11 +927,14 @@ export class BaseRegistryService extends BaseEventsService<RegistersEvents> {
owner,
stakeBalance: formatEther(stakeBalance),
hostnames,
tovarishUrl,
} as CachedRelayerInfo;
}
})
.filter((r) => r) as CachedRelayerInfo[];
await getTovarishNetworks(this, relayers);
return {
timestamp,
relayers,

View File

@ -725,12 +725,23 @@ export function getConfig(netId: NetIdType) {
return chainConfig;
}
export function getActiveTokens(config: Config) {
export function getActiveTokens(config: Config): string[] {
const { tokens, disabledTokens } = config;
return Object.keys(tokens).filter((t) => !disabledTokens?.includes(t));
}
export function getActiveTokenInstances(config: Config): TokenInstances {
const { tokens, disabledTokens } = config;
return Object.entries(tokens).reduce((acc, [token, instances]) => {
if (!disabledTokens?.includes(token)) {
acc[token] = instances;
}
return acc;
}, {} as TokenInstances);
}
export function getInstanceByAddress(config: Config, address: string) {
const { tokens, disabledTokens } = config;

View File

@ -8,7 +8,7 @@ import { CachedRelayerInfo } from './events/base';
export const MIN_FEE = 0.1;
export const MAX_FEE = 0.6;
export const MAX_FEE = 0.9;
export const MIN_STAKE_BALANCE = parseEther('500');
@ -75,6 +75,10 @@ export interface RelayerStatus {
currentQueue: number;
}
export type TornadoWithdrawParams = snarkProofs & {
contract: string;
};
export interface RelayerTornadoWithdraw {
id?: string;
error?: string;
@ -181,10 +185,6 @@ export interface RelayerClientConstructor {
fetchDataOptions?: fetchDataOptions;
}
export type RelayerClientWithdraw = snarkProofs & {
contract: string;
};
export class RelayerClient {
netId: NetIdType;
config: Config;
@ -304,7 +304,7 @@ export class RelayerClient {
return pickWeightedRandomRelayer(relayers);
}
async tornadoWithdraw({ contract, proof, args }: RelayerClientWithdraw) {
async tornadoWithdraw({ contract, proof, args }: TornadoWithdrawParams) {
const { url } = this.selectedRelayer as RelayerInfo;
const withdrawResponse = (await fetchData(`${url}v1/tornadoWithdraw`, {

View File

@ -3,15 +3,14 @@ import * as websnarkUtils from '@tornado/websnark/src/utils';
// @ts-expect-error no-websnark-types
import websnarkGroth from '@tornado/websnark/src/groth16';
import type { Element } from '@tornado/fixed-merkle-tree';
import type { AddressLike, BytesLike, BigNumberish } from 'ethers';
import { toFixedHex } from './utils';
export type snarkInputs = {
// Public snark inputs
root: Element;
nullifierHex: string;
recipient: AddressLike;
relayer: AddressLike;
recipient: string;
relayer: string;
fee: bigint;
refund: bigint;
@ -22,18 +21,9 @@ export type snarkInputs = {
pathIndices: Element[];
};
export type snarkArgs = [
_root: BytesLike,
_nullifierHash: BytesLike,
_recipient: AddressLike,
_relayer: AddressLike,
_fee: BigNumberish,
_refund: BigNumberish,
];
export type snarkProofs = {
proof: BytesLike;
args: snarkArgs;
proof: string;
args: string[];
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@ -71,17 +61,17 @@ export async function calculateSnarkProof(
console.log('Start generating SNARK proof', snarkInput);
console.time('SNARK proof time');
const proofData = await websnarkUtils.genWitnessAndProve(await groth16, snarkInput, circuit, provingKey);
const proof = websnarkUtils.toSolidityInput(proofData).proof as BytesLike;
const proof = websnarkUtils.toSolidityInput(proofData).proof;
console.timeEnd('SNARK proof time');
const args = [
toFixedHex(input.root, 32) as BytesLike,
toFixedHex(input.nullifierHex, 32) as BytesLike,
toFixedHex(input.root, 32),
toFixedHex(input.nullifierHex, 32),
input.recipient,
input.relayer,
toFixedHex(input.fee, 32) as BigNumberish,
toFixedHex(input.refund, 32) as BigNumberish,
] as snarkArgs;
toFixedHex(input.fee, 32),
toFixedHex(input.refund, 32),
];
return { proof, args };
}