Compare commits

..

1 Commits

Author SHA1 Message Date
a32659b8e4
Add BaseMultiTornadoService 2024-11-19 01:16:36 +00:00
10 changed files with 48 additions and 327 deletions

View File

@ -112,6 +112,7 @@ export declare class BaseMultiTornadoService extends BaseEventsService<MultiDepo
constructor(serviceConstructor: BaseMultiTornadoServiceConstructor); constructor(serviceConstructor: BaseMultiTornadoServiceConstructor);
getInstanceName(): string; getInstanceName(): string;
getTovarishType(): string; getTovarishType(): string;
updateEventProgress({ percentage, type, fromBlock, toBlock, count }: Parameters<BatchEventOnProgress>[0]): void;
formatEvents(events: EventLog[]): Promise<(MultiDepositsEvents | MultiWithdrawalsEvents)[]>; formatEvents(events: EventLog[]): Promise<(MultiDepositsEvents | MultiWithdrawalsEvents)[]>;
validateEvents<S>({ events, newEvents, }: BaseEvents<MultiDepositsEvents | MultiWithdrawalsEvents> & { validateEvents<S>({ events, newEvents, }: BaseEvents<MultiDepositsEvents | MultiWithdrawalsEvents> & {
newEvents: (MultiDepositsEvents | MultiWithdrawalsEvents)[]; newEvents: (MultiDepositsEvents | MultiWithdrawalsEvents)[];

62
dist/index.js vendored
View File

@ -1702,61 +1702,6 @@ const withdrawalsEventsSchema = {
additionalProperties: false additionalProperties: false
} }
}; };
const tornadoEventsSchema = {
type: "array",
items: {
anyOf: [
// depositsEvents
{
type: "object",
properties: {
...baseEventsSchemaProperty,
event: { type: "string" },
instanceAddress: { type: "string" },
commitment: bytes32SchemaType,
leafIndex: { type: "number" },
timestamp: { type: "number" },
from: addressSchemaType
},
required: [
...baseEventsSchemaRequired,
"event",
"instanceAddress",
"commitment",
"leafIndex",
"timestamp",
"from"
],
additionalProperties: false
},
// withdrawalEvents
{
type: "object",
properties: {
...baseEventsSchemaProperty,
event: { type: "string" },
instanceAddress: { type: "string" },
nullifierHash: bytes32SchemaType,
to: addressSchemaType,
relayerAddress: addressSchemaType,
fee: bnSchemaType,
timestamp: { type: "number" }
},
required: [
...baseEventsSchemaRequired,
"event",
"instanceAddress",
"nullifierHash",
"to",
"relayerAddress",
"fee",
"timestamp"
],
additionalProperties: false
}
]
}
};
const echoEventsSchema = { const echoEventsSchema = {
type: "array", type: "array",
items: { items: {
@ -1783,9 +1728,6 @@ const encryptedNotesSchema = {
} }
}; };
function getEventsSchemaValidator(type) { function getEventsSchemaValidator(type) {
if (type === "tornado") {
return ajv.compile(tornadoEventsSchema);
}
if (type === "deposit") { if (type === "deposit") {
return ajv.compile(depositsEventsSchema); return ajv.compile(depositsEventsSchema);
} }
@ -2482,6 +2424,9 @@ class BaseMultiTornadoService extends BaseEventsService {
getTovarishType() { getTovarishType() {
return "tornado"; return "tornado";
} }
updateEventProgress({ percentage, type, fromBlock, toBlock, count }) {
console.log({ percentage, type, fromBlock, toBlock, count });
}
async formatEvents(events) { async formatEvents(events) {
const txs = await this.batchTransactionService.getBatchTransactions([ const txs = await this.batchTransactionService.getBatchTransactions([
...new Set( ...new Set(
@ -10774,7 +10719,6 @@ exports.substring = substring;
exports.toContentHash = toContentHash; exports.toContentHash = toContentHash;
exports.toFixedHex = toFixedHex; exports.toFixedHex = toFixedHex;
exports.toFixedLength = toFixedLength; exports.toFixedLength = toFixedLength;
exports.tornadoEventsSchema = tornadoEventsSchema;
exports.unpackEncryptedMessage = unpackEncryptedMessage; exports.unpackEncryptedMessage = unpackEncryptedMessage;
exports.unzipAsync = unzipAsync; exports.unzipAsync = unzipAsync;
exports.validateUrl = validateUrl; exports.validateUrl = validateUrl;

63
dist/index.mjs vendored
View File

@ -1680,61 +1680,6 @@ const withdrawalsEventsSchema = {
additionalProperties: false additionalProperties: false
} }
}; };
const tornadoEventsSchema = {
type: "array",
items: {
anyOf: [
// depositsEvents
{
type: "object",
properties: {
...baseEventsSchemaProperty,
event: { type: "string" },
instanceAddress: { type: "string" },
commitment: bytes32SchemaType,
leafIndex: { type: "number" },
timestamp: { type: "number" },
from: addressSchemaType
},
required: [
...baseEventsSchemaRequired,
"event",
"instanceAddress",
"commitment",
"leafIndex",
"timestamp",
"from"
],
additionalProperties: false
},
// withdrawalEvents
{
type: "object",
properties: {
...baseEventsSchemaProperty,
event: { type: "string" },
instanceAddress: { type: "string" },
nullifierHash: bytes32SchemaType,
to: addressSchemaType,
relayerAddress: addressSchemaType,
fee: bnSchemaType,
timestamp: { type: "number" }
},
required: [
...baseEventsSchemaRequired,
"event",
"instanceAddress",
"nullifierHash",
"to",
"relayerAddress",
"fee",
"timestamp"
],
additionalProperties: false
}
]
}
};
const echoEventsSchema = { const echoEventsSchema = {
type: "array", type: "array",
items: { items: {
@ -1761,9 +1706,6 @@ const encryptedNotesSchema = {
} }
}; };
function getEventsSchemaValidator(type) { function getEventsSchemaValidator(type) {
if (type === "tornado") {
return ajv.compile(tornadoEventsSchema);
}
if (type === "deposit") { if (type === "deposit") {
return ajv.compile(depositsEventsSchema); return ajv.compile(depositsEventsSchema);
} }
@ -2460,6 +2402,9 @@ class BaseMultiTornadoService extends BaseEventsService {
getTovarishType() { getTovarishType() {
return "tornado"; return "tornado";
} }
updateEventProgress({ percentage, type, fromBlock, toBlock, count }) {
console.log({ percentage, type, fromBlock, toBlock, count });
}
async formatEvents(events) { async formatEvents(events) {
const txs = await this.batchTransactionService.getBatchTransactions([ const txs = await this.batchTransactionService.getBatchTransactions([
...new Set( ...new Set(
@ -10604,4 +10549,4 @@ async function calculateSnarkProof(input, circuit, provingKey) {
return { proof, args }; return { proof, args };
} }
export { BaseEchoService, BaseEncryptedNotesService, BaseEventsService, BaseGovernanceService, BaseMultiTornadoService, BaseRegistryService, BaseRevenueService, BaseTornadoService, BatchBlockService, BatchEventsService, BatchTransactionService, DBEchoService, DBEncryptedNotesService, DBGovernanceService, DBRegistryService, DBRevenueService, DBTornadoService, Deposit, ENSNameWrapper__factory, ENSRegistry__factory, ENSResolver__factory, ENSUtils, ENS__factory, ERC20__factory, EnsContracts, INDEX_DB_ERROR, IndexedDB, Invoice, MAX_FEE, MAX_TOVARISH_EVENTS, 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, TovarishClient, addNetwork, addressSchemaType, ajv, base64ToBytes, bigIntReplacer, bnSchemaType, bnToBytes, buffPedersenHash, bufferToBytes, bytes32BNSchemaType, bytes32SchemaType, bytesToBN, bytesToBase64, bytesToHex, calculateScore, calculateSnarkProof, chunk, concatBytes, convertETHToTokenAmount, createDeposit, crypto, customConfig, defaultConfig, defaultUserAgent, deployHasher, depositsEventsSchema, digest, downloadZip, echoEventsSchema, enabledChains, encodedLabelToLabelhash, encryptedNotesSchema, index as factories, fetchData, fetchGetUrlFunc, fetchIp, fromContentHash, gasZipID, gasZipInbounds, gasZipInput, gasZipMinMax, getActiveTokenInstances, getActiveTokens, getConfig, getEventsSchemaValidator, getHttpAgent, getIndexedDB, getInstanceByAddress, getMultiInstances, getNetworkConfig, getPermit2CommitmentsSignature, getPermit2Signature, getPermitCommitmentsSignature, getPermitSignature, getProvider, getProviderWithNetId, getRelayerEnsSubdomains, getStatusSchema, getSubInfo, getSupportedInstances, getTokenBalances, getTovarishNetworks, getWeightRandom, governanceEventsSchema, hasherBytecode, hexToBytes, initGroth16, isHex, isNode, jobRequestSchema, jobsSchema, labelhash, leBuff2Int, leInt2Buff, loadDBEvents, loadRemoteEvents, makeLabelNodeAndParent, mimc, multiQueryFilter, multicall, numberFormatter, packEncryptedMessage, parseInvoice, parseNote, pedersen, permit2Address, pickWeightedRandomRelayer, populateTransaction, proofSchemaType, proposalState, rBigInt, rHex, relayerRegistryEventsSchema, saveDBEvents, sleep, stakeBurnedEventsSchema, substring, toContentHash, toFixedHex, toFixedLength, tornadoEventsSchema, unpackEncryptedMessage, unzipAsync, validateUrl, withdrawalsEventsSchema, zipAsync }; export { BaseEchoService, BaseEncryptedNotesService, BaseEventsService, BaseGovernanceService, BaseMultiTornadoService, BaseRegistryService, BaseRevenueService, BaseTornadoService, BatchBlockService, BatchEventsService, BatchTransactionService, DBEchoService, DBEncryptedNotesService, DBGovernanceService, DBRegistryService, DBRevenueService, DBTornadoService, Deposit, ENSNameWrapper__factory, ENSRegistry__factory, ENSResolver__factory, ENSUtils, ENS__factory, ERC20__factory, EnsContracts, INDEX_DB_ERROR, IndexedDB, Invoice, MAX_FEE, MAX_TOVARISH_EVENTS, 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, TovarishClient, addNetwork, addressSchemaType, ajv, base64ToBytes, bigIntReplacer, bnSchemaType, bnToBytes, buffPedersenHash, bufferToBytes, bytes32BNSchemaType, bytes32SchemaType, bytesToBN, bytesToBase64, bytesToHex, calculateScore, calculateSnarkProof, chunk, concatBytes, convertETHToTokenAmount, createDeposit, crypto, customConfig, defaultConfig, defaultUserAgent, deployHasher, depositsEventsSchema, digest, downloadZip, echoEventsSchema, enabledChains, encodedLabelToLabelhash, encryptedNotesSchema, index as factories, fetchData, fetchGetUrlFunc, fetchIp, fromContentHash, gasZipID, gasZipInbounds, gasZipInput, gasZipMinMax, getActiveTokenInstances, getActiveTokens, getConfig, getEventsSchemaValidator, getHttpAgent, getIndexedDB, getInstanceByAddress, getMultiInstances, getNetworkConfig, getPermit2CommitmentsSignature, getPermit2Signature, getPermitCommitmentsSignature, getPermitSignature, getProvider, getProviderWithNetId, getRelayerEnsSubdomains, getStatusSchema, getSubInfo, getSupportedInstances, getTokenBalances, getTovarishNetworks, getWeightRandom, governanceEventsSchema, hasherBytecode, hexToBytes, initGroth16, isHex, isNode, jobRequestSchema, jobsSchema, labelhash, leBuff2Int, leInt2Buff, loadDBEvents, loadRemoteEvents, makeLabelNodeAndParent, mimc, multiQueryFilter, multicall, numberFormatter, packEncryptedMessage, parseInvoice, parseNote, pedersen, permit2Address, pickWeightedRandomRelayer, populateTransaction, proofSchemaType, proposalState, rBigInt, rHex, relayerRegistryEventsSchema, saveDBEvents, sleep, stakeBurnedEventsSchema, substring, toContentHash, toFixedHex, toFixedLength, unpackEncryptedMessage, unzipAsync, validateUrl, withdrawalsEventsSchema, zipAsync };

View File

@ -352,92 +352,6 @@ export declare const withdrawalsEventsSchema: {
readonly additionalProperties: false; readonly additionalProperties: false;
}; };
}; };
export declare const tornadoEventsSchema: {
readonly type: "array";
readonly items: {
readonly anyOf: readonly [{
readonly type: "object";
readonly properties: {
readonly event: {
readonly type: "string";
};
readonly instanceAddress: {
readonly type: "string";
};
readonly commitment: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
readonly leafIndex: {
readonly type: "number";
};
readonly timestamp: {
readonly type: "number";
};
readonly from: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly blockNumber: {
readonly type: "number";
};
readonly logIndex: {
readonly type: "number";
};
readonly transactionHash: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
};
readonly required: readonly [...string[], "event", "instanceAddress", "commitment", "leafIndex", "timestamp", "from"];
readonly additionalProperties: false;
}, {
readonly type: "object";
readonly properties: {
readonly event: {
readonly type: "string";
};
readonly instanceAddress: {
readonly type: "string";
};
readonly nullifierHash: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
readonly to: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly relayerAddress: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{40}$";
readonly isAddress: true;
};
readonly fee: {
readonly type: "string";
readonly BN: true;
};
readonly timestamp: {
readonly type: "number";
};
readonly blockNumber: {
readonly type: "number";
};
readonly logIndex: {
readonly type: "number";
};
readonly transactionHash: {
readonly type: "string";
readonly pattern: "^0x[a-fA-F0-9]{64}$";
};
};
readonly required: readonly [...string[], "event", "instanceAddress", "nullifierHash", "to", "relayerAddress", "fee", "timestamp"];
readonly additionalProperties: false;
}];
};
};
export declare const echoEventsSchema: { export declare const echoEventsSchema: {
readonly type: "array"; readonly type: "array";
readonly items: { readonly items: {

63
dist/tornado.umd.js vendored
View File

@ -90694,6 +90694,9 @@ class BaseMultiTornadoService extends BaseEventsService {
getTovarishType() { getTovarishType() {
return "tornado"; return "tornado";
} }
updateEventProgress({ percentage, type, fromBlock, toBlock, count }) {
console.log({ percentage, type, fromBlock, toBlock, count });
}
async formatEvents(events) { async formatEvents(events) {
const txs = await this.batchTransactionService.getBatchTransactions([ const txs = await this.batchTransactionService.getBatchTransactions([
...new Set( ...new Set(
@ -101657,7 +101660,6 @@ __webpack_require__.d(__webpack_exports__, {
Y6: () => (/* reexport */ proofSchemaType), Y6: () => (/* reexport */ proofSchemaType),
cl: () => (/* reexport */ relayerRegistryEventsSchema), cl: () => (/* reexport */ relayerRegistryEventsSchema),
Fz: () => (/* reexport */ stakeBurnedEventsSchema), Fz: () => (/* reexport */ stakeBurnedEventsSchema),
U7: () => (/* reexport */ tornadoEventsSchema),
$j: () => (/* reexport */ withdrawalsEventsSchema) $j: () => (/* reexport */ withdrawalsEventsSchema)
}); });
@ -101912,61 +101914,6 @@ const withdrawalsEventsSchema = {
additionalProperties: false additionalProperties: false
} }
}; };
const tornadoEventsSchema = {
type: "array",
items: {
anyOf: [
// depositsEvents
{
type: "object",
properties: {
...baseEventsSchemaProperty,
event: { type: "string" },
instanceAddress: { type: "string" },
commitment: bytes32SchemaType,
leafIndex: { type: "number" },
timestamp: { type: "number" },
from: addressSchemaType
},
required: [
...baseEventsSchemaRequired,
"event",
"instanceAddress",
"commitment",
"leafIndex",
"timestamp",
"from"
],
additionalProperties: false
},
// withdrawalEvents
{
type: "object",
properties: {
...baseEventsSchemaProperty,
event: { type: "string" },
instanceAddress: { type: "string" },
nullifierHash: bytes32SchemaType,
to: addressSchemaType,
relayerAddress: addressSchemaType,
fee: bnSchemaType,
timestamp: { type: "number" }
},
required: [
...baseEventsSchemaRequired,
"event",
"instanceAddress",
"nullifierHash",
"to",
"relayerAddress",
"fee",
"timestamp"
],
additionalProperties: false
}
]
}
};
const echoEventsSchema = { const echoEventsSchema = {
type: "array", type: "array",
items: { items: {
@ -101993,9 +101940,6 @@ const encryptedNotesSchema = {
} }
}; };
function getEventsSchemaValidator(type) { function getEventsSchemaValidator(type) {
if (type === "tornado") {
return ajv_ajv.compile(tornadoEventsSchema);
}
if (type === "deposit") { if (type === "deposit") {
return ajv_ajv.compile(depositsEventsSchema); return ajv_ajv.compile(depositsEventsSchema);
} }
@ -217841,7 +217785,6 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ toContentHash: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_23__.vd), /* harmony export */ toContentHash: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_23__.vd),
/* harmony export */ toFixedHex: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_23__.$W), /* harmony export */ toFixedHex: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_23__.$W),
/* harmony export */ toFixedLength: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_23__.sY), /* harmony export */ toFixedLength: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_23__.sY),
/* harmony export */ tornadoEventsSchema: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_1__.U7),
/* harmony export */ unpackEncryptedMessage: () => (/* reexport safe */ _encryptedNotes__WEBPACK_IMPORTED_MODULE_5__.ol), /* harmony export */ unpackEncryptedMessage: () => (/* reexport safe */ _encryptedNotes__WEBPACK_IMPORTED_MODULE_5__.ol),
/* harmony export */ unzipAsync: () => (/* reexport safe */ _zip__WEBPACK_IMPORTED_MODULE_25__.fY), /* harmony export */ unzipAsync: () => (/* reexport safe */ _zip__WEBPACK_IMPORTED_MODULE_25__.fY),
/* harmony export */ validateUrl: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_23__.wv), /* harmony export */ validateUrl: () => (/* reexport safe */ _utils__WEBPACK_IMPORTED_MODULE_23__.wv),

File diff suppressed because one or more lines are too long

View File

@ -5,13 +5,27 @@ export interface EventsStatus {
events: number; events: number;
lastBlock: number; lastBlock: number;
} }
export interface InstanceEventsStatus {
[index: string]: {
deposits: EventsStatus;
withdrawals: EventsStatus;
};
}
export interface CurrencyEventsStatus {
[index: string]: InstanceEventsStatus;
}
export interface TovarishEventsStatus { export interface TovarishEventsStatus {
governance?: EventsStatus; governance?: EventsStatus;
registered?: {
lastBlock: number;
timestamp: number;
relayers: number;
};
registry?: EventsStatus; registry?: EventsStatus;
revenue?: EventsStatus; revenue?: EventsStatus;
echo: EventsStatus; echo: EventsStatus;
encrypted_notes: EventsStatus; encrypted_notes: EventsStatus;
tornado: EventsStatus; instances: CurrencyEventsStatus;
} }
export interface TovarishSyncStatus { export interface TovarishSyncStatus {
events: boolean; events: boolean;

View File

@ -494,6 +494,10 @@ export class BaseMultiTornadoService extends BaseEventsService<MultiDepositsEven
return 'tornado'; return 'tornado';
} }
updateEventProgress({ percentage, type, fromBlock, toBlock, count }: Parameters<BatchEventOnProgress>[0]) {
console.log({ percentage, type, fromBlock, toBlock, count });
}
async formatEvents(events: EventLog[]): Promise<(MultiDepositsEvents | MultiWithdrawalsEvents)[]> { async formatEvents(events: EventLog[]): Promise<(MultiDepositsEvents | MultiWithdrawalsEvents)[]> {
const txs = await this.batchTransactionService.getBatchTransactions([ const txs = await this.batchTransactionService.getBatchTransactions([
...new Set( ...new Set(

View File

@ -201,62 +201,6 @@ export const withdrawalsEventsSchema = {
}, },
} as const; } as const;
export const tornadoEventsSchema = {
type: 'array',
items: {
anyOf: [
// depositsEvents
{
type: 'object',
properties: {
...baseEventsSchemaProperty,
event: { type: 'string' },
instanceAddress: { type: 'string' },
commitment: bytes32SchemaType,
leafIndex: { type: 'number' },
timestamp: { type: 'number' },
from: addressSchemaType,
},
required: [
...baseEventsSchemaRequired,
'event',
'instanceAddress',
'commitment',
'leafIndex',
'timestamp',
'from',
],
additionalProperties: false,
},
// withdrawalEvents
{
type: 'object',
properties: {
...baseEventsSchemaProperty,
event: { type: 'string' },
instanceAddress: { type: 'string' },
nullifierHash: bytes32SchemaType,
to: addressSchemaType,
relayerAddress: addressSchemaType,
fee: bnSchemaType,
timestamp: { type: 'number' },
},
required: [
...baseEventsSchemaRequired,
'event',
'instanceAddress',
'nullifierHash',
'to',
'relayerAddress',
'fee',
'timestamp',
],
additionalProperties: false,
},
],
},
} as const;
export const echoEventsSchema = { export const echoEventsSchema = {
type: 'array', type: 'array',
items: { items: {
@ -285,10 +229,6 @@ export const encryptedNotesSchema = {
} as const; } as const;
export function getEventsSchemaValidator(type: string) { export function getEventsSchemaValidator(type: string) {
if (type === 'tornado') {
return ajv.compile(tornadoEventsSchema);
}
if (type === 'deposit') { if (type === 'deposit') {
return ajv.compile(depositsEventsSchema); return ajv.compile(depositsEventsSchema);
} }

View File

@ -21,13 +21,29 @@ export interface EventsStatus {
lastBlock: number; lastBlock: number;
} }
export interface InstanceEventsStatus {
[index: string]: {
deposits: EventsStatus;
withdrawals: EventsStatus;
};
}
export interface CurrencyEventsStatus {
[index: string]: InstanceEventsStatus;
}
export interface TovarishEventsStatus { export interface TovarishEventsStatus {
governance?: EventsStatus; governance?: EventsStatus;
registered?: {
lastBlock: number;
timestamp: number;
relayers: number;
};
registry?: EventsStatus; registry?: EventsStatus;
revenue?: EventsStatus; revenue?: EventsStatus;
echo: EventsStatus; echo: EventsStatus;
encrypted_notes: EventsStatus; encrypted_notes: EventsStatus;
tornado: EventsStatus; instances: CurrencyEventsStatus;
} }
export interface TovarishSyncStatus { export interface TovarishSyncStatus {