diff --git a/dist/index.js b/dist/index.js index 1927152..809b43b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2667,7 +2667,7 @@ function substring(str, length = 10) { return `${str.substring(0, length)}...${str.substring(str.length - length)}`; } -var __async$e = (__this, __arguments, generator) => { +var __async$f = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -2688,7 +2688,7 @@ var __async$e = (__this, __arguments, generator) => { }); }; function multicall(Multicall2, calls) { - return __async$e(this, null, function* () { + return __async$f(this, null, function* () { const calldata = calls.map((call) => { var _a, _b, _c; const target = ((_a = call.contract) == null ? void 0 : _a.target) || call.address; @@ -2733,7 +2733,7 @@ var __spreadValues$5 = (a, b) => { }; var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b)); var __superGet$1 = (cls, obj, key) => __reflectGet$1(__getProtoOf$1(cls), key, obj); -var __async$d = (__this, __arguments, generator) => { +var __async$e = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -2779,7 +2779,7 @@ function getHttpAgent({ } } function fetchData(_0) { - return __async$d(this, arguments, function* (url, options = {}) { + return __async$e(this, arguments, function* (url, options = {}) { var _a, _b, _c; const MAX_RETRY = (_a = options.maxRetry) != null ? _a : 3; const RETRY_ON = (_b = options.retryOn) != null ? _b : 500; @@ -2871,7 +2871,7 @@ function fetchData(_0) { throw errorObject; }); } -const fetchGetUrlFunc = (options = {}) => (req, _signal) => __async$d(void 0, null, function* () { +const fetchGetUrlFunc = (options = {}) => (req, _signal) => __async$e(void 0, null, function* () { let signal; if (_signal) { const controller = new AbortController(); @@ -2905,7 +2905,7 @@ const oracleMapper = /* @__PURE__ */ new Map(); const multicallMapper = /* @__PURE__ */ new Map(); function getGasOraclePlugin(networkKey, fetchOptions) { const gasStationApi = (fetchOptions == null ? void 0 : fetchOptions.gasStationApi) || "https://gasstation.polygon.technology/v2"; - return new ethers.FetchUrlFeeDataNetworkPlugin(gasStationApi, (fetchFeeData, provider, request) => __async$d(this, null, function* () { + return new ethers.FetchUrlFeeDataNetworkPlugin(gasStationApi, (fetchFeeData, provider, request) => __async$e(this, null, function* () { if (!oracleMapper.has(networkKey)) { oracleMapper.set(networkKey, GasPriceOracle__factory.connect(fetchOptions == null ? void 0 : fetchOptions.gasPriceOracle, provider)); } @@ -2964,7 +2964,7 @@ function getGasOraclePlugin(networkKey, fetchOptions) { })); } function getProvider(rpcUrl, fetchOptions) { - return __async$d(this, null, function* () { + return __async$e(this, null, function* () { const fetchReq = new ethers.FetchRequest(rpcUrl); fetchReq.getUrlFunc = fetchGetUrlFunc(fetchOptions); const _staticNetwork = yield new ethers.JsonRpcProvider(fetchReq).getNetwork(); @@ -3014,7 +3014,7 @@ function getProviderWithNetId(netId, rpcUrl, config, fetchOptions) { provider.pollingInterval = (fetchOptions == null ? void 0 : fetchOptions.pollingInterval) || pollInterval * 1e3; return provider; } -const populateTransaction = (signer, tx) => __async$d(void 0, null, function* () { +const populateTransaction = (signer, tx) => __async$e(void 0, null, function* () { const provider = signer.provider; if (!tx.from) { tx.from = signer.address; @@ -3023,7 +3023,7 @@ const populateTransaction = (signer, tx) => __async$d(void 0, null, function* () throw new Error(errMsg); } const [feeData, nonce] = yield Promise.all([ - (() => __async$d(void 0, null, function* () { + (() => __async$e(void 0, null, function* () { if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) { return new ethers.FeeData(null, BigInt(tx.maxFeePerGas), BigInt(tx.maxPriorityFeePerGas)); } @@ -3045,7 +3045,7 @@ const populateTransaction = (signer, tx) => __async$d(void 0, null, function* () ); } }))(), - (() => __async$d(void 0, null, function* () { + (() => __async$e(void 0, null, function* () { if (tx.nonce) { return tx.nonce; } @@ -3075,7 +3075,7 @@ const populateTransaction = (signer, tx) => __async$d(void 0, null, function* () delete tx.maxFeePerGas; delete tx.maxPriorityFeePerGas; } - tx.gasLimit = tx.gasLimit || (yield (() => __async$d(void 0, null, function* () { + tx.gasLimit = tx.gasLimit || (yield (() => __async$e(void 0, null, function* () { try { const gasLimit = yield provider.estimateGas(tx); return gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4); @@ -3103,7 +3103,7 @@ class TornadoWallet extends ethers.Wallet { return new TornadoWallet(privateKey, provider, options); } populateTransaction(tx) { - return __async$d(this, null, function* () { + return __async$e(this, null, function* () { const txObject = yield populateTransaction(this, tx); this.nonce = txObject.nonce; return __superGet$1(TornadoWallet.prototype, this, "populateTransaction").call(this, txObject); @@ -3119,7 +3119,7 @@ class TornadoVoidSigner extends ethers.VoidSigner { this.bumpNonce = bumpNonce != null ? bumpNonce : false; } populateTransaction(tx) { - return __async$d(this, null, function* () { + return __async$e(this, null, function* () { const txObject = yield populateTransaction(this, tx); this.nonce = txObject.nonce; return __superGet$1(TornadoVoidSigner.prototype, this, "populateTransaction").call(this, txObject); @@ -3135,7 +3135,7 @@ class TornadoRpcSigner extends ethers.JsonRpcSigner { this.bumpNonce = bumpNonce != null ? bumpNonce : false; } sendUncheckedTransaction(tx) { - return __async$d(this, null, function* () { + return __async$e(this, null, function* () { return __superGet$1(TornadoRpcSigner.prototype, this, "sendUncheckedTransaction").call(this, yield populateTransaction(this, tx)); }); } @@ -3146,7 +3146,7 @@ class TornadoBrowserProvider extends ethers.BrowserProvider { this.options = options; } getSigner(address) { - return __async$d(this, null, function* () { + return __async$e(this, null, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _i; const signerAddress = (yield __superGet$1(TornadoBrowserProvider.prototype, this, "getSigner").call(this, address)).address; if (((_a = this.options) == null ? void 0 : _a.webChainId) && ((_b = this.options) == null ? void 0 : _b.connectWallet) && Number(yield __superGet$1(TornadoBrowserProvider.prototype, this, "send").call(this, "eth_chainId", [])) !== Number((_c = this.options) == null ? void 0 : _c.webChainId)) { @@ -3374,7 +3374,7 @@ var __spreadValues$4 = (a, b) => { return a; }; var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)); -var __async$c = (__this, __arguments, generator) => { +var __async$d = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -3397,7 +3397,7 @@ var __async$c = (__this, __arguments, generator) => { const isEmptyArray = (arr) => !Array.isArray(arr) || !arr.length; const first = 1e3; function queryGraph(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, query, @@ -3426,7 +3426,7 @@ function queryGraph(_0) { }); } function getStatistic(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, currency, @@ -3473,7 +3473,7 @@ function getStatistic(_0) { }); } function getMeta(_0) { - return __async$c(this, arguments, function* ({ graphApi, subgraphName, fetchDataOptions: fetchDataOptions2 }) { + return __async$d(this, arguments, function* ({ graphApi, subgraphName, fetchDataOptions: fetchDataOptions2 }) { try { const { _meta: { @@ -3518,7 +3518,7 @@ function getRegisters({ }); } function getAllRegisters(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, fromBlock, @@ -3607,7 +3607,7 @@ function getDeposits({ }); } function getAllDeposits(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, currency, @@ -3704,7 +3704,7 @@ function getWithdrawals({ }); } function getAllWithdrawals(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, currency, @@ -3780,7 +3780,7 @@ function getAllWithdrawals(_0) { }); } function getNoteAccounts(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, address, @@ -3833,7 +3833,7 @@ function getGraphEchoEvents({ }); } function getAllGraphEchoEvents(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, fromBlock, @@ -3922,7 +3922,7 @@ function getEncryptedNotes({ }); } function getAllEncryptedNotes(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, fromBlock, @@ -4007,7 +4007,7 @@ function getGovernanceEvents({ }); } function getAllGovernanceEvents(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, fromBlock, @@ -4166,7 +4166,7 @@ var graph = /*#__PURE__*/Object.freeze({ queryGraph: queryGraph }); -var __async$b = (__this, __arguments, generator) => { +var __async$c = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -4205,7 +4205,7 @@ class BatchBlockService { this.retryOn = retryOn; } getBlock(blockTag) { - return __async$b(this, null, function* () { + return __async$c(this, null, function* () { const blockObject = yield this.provider.getBlock(blockTag); if (!blockObject) { const errMsg = `No block for ${blockTag}`; @@ -4215,9 +4215,9 @@ class BatchBlockService { }); } createBatchRequest(batchArray) { - return batchArray.map((blocks, index) => __async$b(this, null, function* () { + return batchArray.map((blocks, index) => __async$c(this, null, function* () { yield sleep(20 * index); - return (() => __async$b(this, null, function* () { + return (() => __async$c(this, null, function* () { let retries = 0; let err; while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) { @@ -4234,7 +4234,7 @@ class BatchBlockService { })); } getBatchBlocks(blocks) { - return __async$b(this, null, function* () { + return __async$c(this, null, function* () { let blockCount = 0; const results = []; for (const chunks of chunk(blocks, this.concurrencySize * this.batchSize)) { @@ -4272,7 +4272,7 @@ class BatchTransactionService { this.retryOn = retryOn; } getTransaction(txHash) { - return __async$b(this, null, function* () { + return __async$c(this, null, function* () { const txObject = yield this.provider.getTransaction(txHash); if (!txObject) { const errMsg = `No transaction for ${txHash}`; @@ -4282,9 +4282,9 @@ class BatchTransactionService { }); } createBatchRequest(batchArray) { - return batchArray.map((txs, index) => __async$b(this, null, function* () { + return batchArray.map((txs, index) => __async$c(this, null, function* () { yield sleep(20 * index); - return (() => __async$b(this, null, function* () { + return (() => __async$c(this, null, function* () { let retries = 0; let err; while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) { @@ -4301,7 +4301,7 @@ class BatchTransactionService { })); } getBatchTransactions(txs) { - return __async$b(this, null, function* () { + return __async$c(this, null, function* () { let txCount = 0; const results = []; for (const chunks of chunk(txs, this.concurrencySize * this.batchSize)) { @@ -4337,7 +4337,7 @@ class BatchEventsService { this.retryOn = retryOn; } getPastEvents(_0) { - return __async$b(this, arguments, function* ({ fromBlock, toBlock, type }) { + return __async$c(this, arguments, function* ({ fromBlock, toBlock, type }) { let err; let retries = 0; while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) { @@ -4357,13 +4357,13 @@ class BatchEventsService { }); } createBatchRequest(batchArray) { - return batchArray.map((event, index) => __async$b(this, null, function* () { + return batchArray.map((event, index) => __async$c(this, null, function* () { yield sleep(20 * index); return this.getPastEvents(event); })); } getBatchEvents(_0) { - return __async$b(this, arguments, function* ({ fromBlock, toBlock, type = "*" }) { + return __async$c(this, arguments, function* ({ fromBlock, toBlock, type = "*" }) { if (!toBlock) { toBlock = yield this.provider.getBlockNumber(); } @@ -4416,7 +4416,7 @@ var __spreadValues$3 = (a, b) => { }; var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b)); var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj); -var __async$a = (__this, __arguments, generator) => { +var __async$b = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -4491,7 +4491,7 @@ class BaseEventsService { } /* eslint-enable @typescript-eslint/no-unused-vars */ formatEvents(events) { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return yield new Promise((resolve) => resolve(events)); }); } @@ -4499,7 +4499,7 @@ class BaseEventsService { * Get saved or cached events */ getEventsFromDB() { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return { events: [], lastBlock: null @@ -4507,7 +4507,7 @@ class BaseEventsService { }); } getEventsFromCache() { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return { events: [], lastBlock: null @@ -4515,7 +4515,7 @@ class BaseEventsService { }); } getSavedEvents() { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { let cachedEvents = yield this.getEventsFromDB(); if (!cachedEvents || !cachedEvents.events.length) { cachedEvents = yield this.getEventsFromCache(); @@ -4527,7 +4527,7 @@ class BaseEventsService { * Get latest events */ getEventsFromGraph(_0) { - return __async$a(this, arguments, function* ({ + return __async$b(this, arguments, function* ({ fromBlock, methodName = "" }) { @@ -4547,7 +4547,7 @@ class BaseEventsService { }); } getEventsFromRpc(_0) { - return __async$a(this, arguments, function* ({ + return __async$b(this, arguments, function* ({ fromBlock, toBlock }) { @@ -4585,7 +4585,7 @@ class BaseEventsService { }); } getLatestEvents(_0) { - return __async$a(this, arguments, function* ({ fromBlock }) { + return __async$b(this, arguments, function* ({ fromBlock }) { const allEvents = []; const graphEvents = yield this.getEventsFromGraph({ fromBlock }); const lastSyncBlock = graphEvents.lastBlock && graphEvents.lastBlock >= fromBlock ? graphEvents.lastBlock : fromBlock; @@ -4607,14 +4607,14 @@ class BaseEventsService { */ // eslint-disable-next-line @typescript-eslint/no-unused-vars saveEvents(_0) { - return __async$a(this, arguments, function* ({ events, lastBlock }) { + return __async$b(this, arguments, function* ({ events, lastBlock }) { }); } /** * Trigger saving and receiving latest events */ updateEvents() { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { const savedEvents = yield this.getSavedEvents(); let fromBlock = this.deployedBlock; if (savedEvents && savedEvents.lastBlock) { @@ -4688,7 +4688,7 @@ class BaseDepositsService extends BaseEventsService { }; } formatEvents(events) { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { const type = this.getType().toLowerCase(); if (type === DEPOSIT) { const formattedEvents = events.map(({ blockNumber, index: logIndex, transactionHash, args }) => { @@ -4767,7 +4767,7 @@ class BaseEchoService extends BaseEventsService { return "getAllGraphEchoEvents"; } formatEvents(events) { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return events.map(({ blockNumber, index: logIndex, transactionHash, args }) => { const { who, data } = args; if (who && data) { @@ -4785,7 +4785,7 @@ class BaseEchoService extends BaseEventsService { }); } getEventsFromGraph(_0) { - return __async$a(this, arguments, function* ({ fromBlock }) { + return __async$b(this, arguments, function* ({ fromBlock }) { if (!this.graphApi || this.graphApi.includes("api.thegraph.com")) { return { events: [], @@ -4818,7 +4818,7 @@ class BaseEncryptedNotesService extends BaseEventsService { return "getAllEncryptedNotes"; } formatEvents(events) { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return events.map(({ blockNumber, index: logIndex, transactionHash, args }) => { const { encryptedNote } = args; if (encryptedNote) { @@ -4861,7 +4861,7 @@ class BaseGovernanceService extends BaseEventsService { return "getAllGovernanceEvents"; } formatEvents(events) { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { const proposalEvents = []; const votedEvents = []; const delegatedEvents = []; @@ -4928,7 +4928,7 @@ class BaseGovernanceService extends BaseEventsService { }); } getEventsFromGraph(_0) { - return __async$a(this, arguments, function* ({ fromBlock }) { + return __async$b(this, arguments, function* ({ fromBlock }) { if (!this.graphApi || !this.subgraphName || this.graphApi.includes("api.thegraph.com")) { return { events: [], @@ -4963,7 +4963,7 @@ class BaseRegistryService extends BaseEventsService { return "getAllRegisters"; } formatEvents(events) { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return events.map(({ blockNumber, index: logIndex, transactionHash, args }) => { const eventObjects = { blockNumber, @@ -4978,13 +4978,13 @@ class BaseRegistryService extends BaseEventsService { }); } fetchRelayers() { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return (yield this.updateEvents()).events; }); } } -var __async$9 = (__this, __arguments, generator) => { +var __async$a = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -5005,7 +5005,7 @@ var __async$9 = (__this, __arguments, generator) => { }); }; function existsAsync(fileOrDir) { - return __async$9(this, null, function* () { + return __async$a(this, null, function* () { try { yield promises.stat(fileOrDir); return true; @@ -5037,7 +5037,7 @@ function unzipAsync(data) { }); } function saveUserFile(_0) { - return __async$9(this, arguments, function* ({ + return __async$a(this, arguments, function* ({ fileName, userDirectory, dataString @@ -5055,7 +5055,7 @@ function saveUserFile(_0) { }); } function loadSavedEvents(_0) { - return __async$9(this, arguments, function* ({ + return __async$a(this, arguments, function* ({ name, userDirectory, deployedBlock @@ -5084,7 +5084,7 @@ function loadSavedEvents(_0) { }); } function download(_0) { - return __async$9(this, arguments, function* ({ name, cacheDirectory }) { + return __async$a(this, arguments, function* ({ name, cacheDirectory }) { const fileName = `${name}.json`.toLowerCase(); const zipName = `${fileName}.zip`; const zipPath = path.join(cacheDirectory, zipName); @@ -5094,7 +5094,7 @@ function download(_0) { }); } function loadCachedEvents(_0) { - return __async$9(this, arguments, function* ({ + return __async$a(this, arguments, function* ({ name, cacheDirectory, deployedBlock @@ -5124,7 +5124,7 @@ function loadCachedEvents(_0) { }); } -var __async$8 = (__this, __arguments, generator) => { +var __async$9 = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -5209,7 +5209,7 @@ class NodeDepositsService extends BaseDepositsService { } } getEventsFromDB() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.userDirectory) { console.log( "Updating events for", @@ -5240,7 +5240,7 @@ class NodeDepositsService extends BaseDepositsService { }); } getEventsFromCache() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.cacheDirectory) { console.log(`cachedEvents count - ${0}`); console.log(`cachedEvents lastBlock - ${this.deployedBlock} @@ -5262,7 +5262,7 @@ class NodeDepositsService extends BaseDepositsService { }); } saveEvents(_0) { - return __async$8(this, arguments, function* ({ events, lastBlock }) { + return __async$9(this, arguments, function* ({ events, lastBlock }) { const instanceName = this.getInstanceName(); console.log("\ntotalEvents count - ", events.length); console.log( @@ -5341,7 +5341,7 @@ class NodeEchoService extends BaseEchoService { } } getEventsFromDB() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.userDirectory) { console.log(`Updating events for ${this.netId} chain echo events `); @@ -5367,7 +5367,7 @@ class NodeEchoService extends BaseEchoService { }); } getEventsFromCache() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.cacheDirectory) { console.log(`cachedEvents count - ${0}`); console.log(`cachedEvents lastBlock - ${this.deployedBlock} @@ -5389,7 +5389,7 @@ class NodeEchoService extends BaseEchoService { }); } saveEvents(_0) { - return __async$8(this, arguments, function* ({ events, lastBlock }) { + return __async$9(this, arguments, function* ({ events, lastBlock }) { const instanceName = this.getInstanceName(); console.log("\ntotalEvents count - ", events.length); console.log( @@ -5467,7 +5467,7 @@ class NodeEncryptedNotesService extends BaseEncryptedNotesService { } } getEventsFromDB() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.userDirectory) { console.log(`Updating events for ${this.netId} chain encrypted events `); @@ -5493,7 +5493,7 @@ class NodeEncryptedNotesService extends BaseEncryptedNotesService { }); } getEventsFromCache() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.cacheDirectory) { console.log(`cachedEvents count - ${0}`); console.log(`cachedEvents lastBlock - ${this.deployedBlock} @@ -5515,7 +5515,7 @@ class NodeEncryptedNotesService extends BaseEncryptedNotesService { }); } saveEvents(_0) { - return __async$8(this, arguments, function* ({ events, lastBlock }) { + return __async$9(this, arguments, function* ({ events, lastBlock }) { const instanceName = this.getInstanceName(); console.log("\ntotalEvents count - ", events.length); console.log( @@ -5598,7 +5598,7 @@ class NodeGovernanceService extends BaseGovernanceService { } } getEventsFromDB() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.userDirectory) { console.log(`Updating events for ${this.netId} chain governance events `); @@ -5624,7 +5624,7 @@ class NodeGovernanceService extends BaseGovernanceService { }); } getEventsFromCache() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.cacheDirectory) { console.log(`cachedEvents count - ${0}`); console.log(`cachedEvents lastBlock - ${this.deployedBlock} @@ -5646,7 +5646,7 @@ class NodeGovernanceService extends BaseGovernanceService { }); } saveEvents(_0) { - return __async$8(this, arguments, function* ({ events, lastBlock }) { + return __async$9(this, arguments, function* ({ events, lastBlock }) { const instanceName = this.getInstanceName(); console.log("\ntotalEvents count - ", events.length); console.log( @@ -5724,7 +5724,7 @@ class NodeRegistryService extends BaseRegistryService { } } getEventsFromDB() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.userDirectory) { console.log(`Updating events for ${this.netId} chain registry events `); @@ -5750,7 +5750,7 @@ class NodeRegistryService extends BaseRegistryService { }); } getEventsFromCache() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.cacheDirectory) { console.log(`cachedEvents count - ${0}`); console.log(`cachedEvents lastBlock - ${this.deployedBlock} @@ -5772,7 +5772,7 @@ class NodeRegistryService extends BaseRegistryService { }); } saveEvents(_0) { - return __async$8(this, arguments, function* ({ events, lastBlock }) { + return __async$9(this, arguments, function* ({ events, lastBlock }) { const instanceName = this.getInstanceName(); console.log("\ntotalEvents count - ", events.length); console.log( @@ -6603,7 +6603,7 @@ ajv.addKeyword({ errors: true }); -var __async$7 = (__this, __arguments, generator) => { +var __async$8 = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -6628,13 +6628,13 @@ class Pedersen { this.pedersenPromise = this.initPedersen(); } initPedersen() { - return __async$7(this, null, function* () { + return __async$8(this, null, function* () { this.pedersenHash = yield circomlibjs.buildPedersenHash(); this.babyJub = this.pedersenHash.babyJub; }); } unpackPoint(buffer) { - return __async$7(this, null, function* () { + return __async$8(this, null, function* () { var _a, _b; yield this.pedersenPromise; return (_b = this.babyJub) == null ? void 0 : _b.unpackPoint((_a = this.pedersenHash) == null ? void 0 : _a.hash(buffer)); @@ -6647,13 +6647,13 @@ class Pedersen { } const pedersen = new Pedersen(); function buffPedersenHash(buffer) { - return __async$7(this, null, function* () { + return __async$8(this, null, function* () { const [hash] = yield pedersen.unpackPoint(buffer); return pedersen.toStringBuffer(hash); }); } -var __async$6 = (__this, __arguments, generator) => { +var __async$7 = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -6674,7 +6674,7 @@ var __async$6 = (__this, __arguments, generator) => { }); }; function createDeposit(_0) { - return __async$6(this, arguments, function* ({ nullifier, secret }) { + return __async$7(this, arguments, function* ({ nullifier, secret }) { const preimage = new Uint8Array([...leInt2Buff(nullifier), ...leInt2Buff(secret)]); const noteHex = toFixedHex(bytesToBN(preimage), 62); const commitment = BigInt(yield buffPedersenHash(preimage)); @@ -6734,7 +6734,7 @@ class Deposit { ); } static createNote(_0) { - return __async$6(this, arguments, function* ({ currency, amount, netId, nullifier, secret }) { + return __async$7(this, arguments, function* ({ currency, amount, netId, nullifier, secret }) { if (!nullifier) { nullifier = rBigInt(31); } @@ -6761,7 +6761,7 @@ class Deposit { }); } static parseNote(noteString) { - return __async$6(this, null, function* () { + return __async$7(this, null, function* () { const noteRegex = new RegExp("tornado-(?\\w+)-(?[\\d.]+)-(?\\d+)-0x(?[0-9a-fA-F]{124})", "g"); const match = noteRegex.exec(noteString); if (!match) { @@ -7021,7 +7021,7 @@ class TornadoFeeOracle { } } -var __async$5 = (__this, __arguments, generator) => { +var __async$6 = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -7046,7 +7046,7 @@ class Mimc { this.mimcPromise = this.initMimc(); } initMimc() { - return __async$5(this, null, function* () { + return __async$6(this, null, function* () { this.sponge = yield circomlibjs.buildMimcSponge(); this.hash = (left, right) => { var _a, _b; @@ -7055,7 +7055,7 @@ class Mimc { }); } getHash() { - return __async$5(this, null, function* () { + return __async$6(this, null, function* () { yield this.mimcPromise; return { sponge: this.sponge, @@ -7066,7 +7066,7 @@ class Mimc { } const mimc = new Mimc(); -var __async$4 = (__this, __arguments, generator) => { +var __async$5 = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -7109,7 +7109,7 @@ class MerkleTreeService { this.merkleWorkerPath = merkleWorkerPath; } createTree(events) { - return __async$4(this, null, function* () { + return __async$5(this, null, function* () { const { hash: hashFunction } = yield mimc.getHash(); if (this.merkleWorkerPath) { console.log("Using merkleWorker\n"); @@ -7161,7 +7161,7 @@ class MerkleTreeService { }); } createPartialTree(_0) { - return __async$4(this, arguments, function* ({ edge, elements }) { + return __async$5(this, arguments, function* ({ edge, elements }) { const { hash: hashFunction } = yield mimc.getHash(); if (this.merkleWorkerPath) { console.log("Using merkleWorker\n"); @@ -7215,7 +7215,7 @@ class MerkleTreeService { }); } verifyTree(events) { - return __async$4(this, null, function* () { + return __async$5(this, null, function* () { console.log( ` Creating deposit tree for ${this.netId} ${this.amount} ${this.currency.toUpperCase()} would take a while @@ -7300,6 +7300,26 @@ function parseRecoveryKey(value) { return value; } +var __async$4 = (__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()); + }); +}; class TokenPriceOracle { constructor(provider, multicall2, oracle) { this.provider = provider; @@ -7307,17 +7327,22 @@ class TokenPriceOracle { this.oracle = oracle; } fetchPrices(tokens) { - if (!this.oracle) { - return new Promise((resolve) => resolve(tokens.map(() => ethers.parseEther("0.0001")))); - } - return multicall( - this.multicall, - tokens.map((token) => ({ - contract: this.oracle, - name: "getRateToEth", - params: [token, true] - })) - ); + return __async$4(this, null, function* () { + if (!this.oracle) { + return new Promise((resolve) => resolve(tokens.map(() => ethers.parseEther("0.0001")))); + } + const prices = yield multicall( + this.multicall, + tokens.map(({ tokenAddress }) => ({ + contract: this.oracle, + name: "getRateToEth", + params: [tokenAddress, true] + })) + ); + return prices.map((price, index) => { + return price * BigInt(10 ** tokens[index].decimals) / BigInt(10 ** 18); + }); + }); } } diff --git a/dist/index.mjs b/dist/index.mjs index a2be197..436419f 100644 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -2646,7 +2646,7 @@ function substring(str, length = 10) { return `${str.substring(0, length)}...${str.substring(str.length - length)}`; } -var __async$e = (__this, __arguments, generator) => { +var __async$f = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -2667,7 +2667,7 @@ var __async$e = (__this, __arguments, generator) => { }); }; function multicall(Multicall2, calls) { - return __async$e(this, null, function* () { + return __async$f(this, null, function* () { const calldata = calls.map((call) => { var _a, _b, _c; const target = ((_a = call.contract) == null ? void 0 : _a.target) || call.address; @@ -2712,7 +2712,7 @@ var __spreadValues$5 = (a, b) => { }; var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b)); var __superGet$1 = (cls, obj, key) => __reflectGet$1(__getProtoOf$1(cls), key, obj); -var __async$d = (__this, __arguments, generator) => { +var __async$e = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -2758,7 +2758,7 @@ function getHttpAgent({ } } function fetchData(_0) { - return __async$d(this, arguments, function* (url, options = {}) { + return __async$e(this, arguments, function* (url, options = {}) { var _a, _b, _c; const MAX_RETRY = (_a = options.maxRetry) != null ? _a : 3; const RETRY_ON = (_b = options.retryOn) != null ? _b : 500; @@ -2850,7 +2850,7 @@ function fetchData(_0) { throw errorObject; }); } -const fetchGetUrlFunc = (options = {}) => (req, _signal) => __async$d(void 0, null, function* () { +const fetchGetUrlFunc = (options = {}) => (req, _signal) => __async$e(void 0, null, function* () { let signal; if (_signal) { const controller = new AbortController(); @@ -2884,7 +2884,7 @@ const oracleMapper = /* @__PURE__ */ new Map(); const multicallMapper = /* @__PURE__ */ new Map(); function getGasOraclePlugin(networkKey, fetchOptions) { const gasStationApi = (fetchOptions == null ? void 0 : fetchOptions.gasStationApi) || "https://gasstation.polygon.technology/v2"; - return new FetchUrlFeeDataNetworkPlugin(gasStationApi, (fetchFeeData, provider, request) => __async$d(this, null, function* () { + return new FetchUrlFeeDataNetworkPlugin(gasStationApi, (fetchFeeData, provider, request) => __async$e(this, null, function* () { if (!oracleMapper.has(networkKey)) { oracleMapper.set(networkKey, GasPriceOracle__factory.connect(fetchOptions == null ? void 0 : fetchOptions.gasPriceOracle, provider)); } @@ -2943,7 +2943,7 @@ function getGasOraclePlugin(networkKey, fetchOptions) { })); } function getProvider(rpcUrl, fetchOptions) { - return __async$d(this, null, function* () { + return __async$e(this, null, function* () { const fetchReq = new FetchRequest(rpcUrl); fetchReq.getUrlFunc = fetchGetUrlFunc(fetchOptions); const _staticNetwork = yield new JsonRpcProvider(fetchReq).getNetwork(); @@ -2993,7 +2993,7 @@ function getProviderWithNetId(netId, rpcUrl, config, fetchOptions) { provider.pollingInterval = (fetchOptions == null ? void 0 : fetchOptions.pollingInterval) || pollInterval * 1e3; return provider; } -const populateTransaction = (signer, tx) => __async$d(void 0, null, function* () { +const populateTransaction = (signer, tx) => __async$e(void 0, null, function* () { const provider = signer.provider; if (!tx.from) { tx.from = signer.address; @@ -3002,7 +3002,7 @@ const populateTransaction = (signer, tx) => __async$d(void 0, null, function* () throw new Error(errMsg); } const [feeData, nonce] = yield Promise.all([ - (() => __async$d(void 0, null, function* () { + (() => __async$e(void 0, null, function* () { if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) { return new FeeData(null, BigInt(tx.maxFeePerGas), BigInt(tx.maxPriorityFeePerGas)); } @@ -3024,7 +3024,7 @@ const populateTransaction = (signer, tx) => __async$d(void 0, null, function* () ); } }))(), - (() => __async$d(void 0, null, function* () { + (() => __async$e(void 0, null, function* () { if (tx.nonce) { return tx.nonce; } @@ -3054,7 +3054,7 @@ const populateTransaction = (signer, tx) => __async$d(void 0, null, function* () delete tx.maxFeePerGas; delete tx.maxPriorityFeePerGas; } - tx.gasLimit = tx.gasLimit || (yield (() => __async$d(void 0, null, function* () { + tx.gasLimit = tx.gasLimit || (yield (() => __async$e(void 0, null, function* () { try { const gasLimit = yield provider.estimateGas(tx); return gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4); @@ -3082,7 +3082,7 @@ class TornadoWallet extends Wallet { return new TornadoWallet(privateKey, provider, options); } populateTransaction(tx) { - return __async$d(this, null, function* () { + return __async$e(this, null, function* () { const txObject = yield populateTransaction(this, tx); this.nonce = txObject.nonce; return __superGet$1(TornadoWallet.prototype, this, "populateTransaction").call(this, txObject); @@ -3098,7 +3098,7 @@ class TornadoVoidSigner extends VoidSigner { this.bumpNonce = bumpNonce != null ? bumpNonce : false; } populateTransaction(tx) { - return __async$d(this, null, function* () { + return __async$e(this, null, function* () { const txObject = yield populateTransaction(this, tx); this.nonce = txObject.nonce; return __superGet$1(TornadoVoidSigner.prototype, this, "populateTransaction").call(this, txObject); @@ -3114,7 +3114,7 @@ class TornadoRpcSigner extends JsonRpcSigner { this.bumpNonce = bumpNonce != null ? bumpNonce : false; } sendUncheckedTransaction(tx) { - return __async$d(this, null, function* () { + return __async$e(this, null, function* () { return __superGet$1(TornadoRpcSigner.prototype, this, "sendUncheckedTransaction").call(this, yield populateTransaction(this, tx)); }); } @@ -3125,7 +3125,7 @@ class TornadoBrowserProvider extends BrowserProvider { this.options = options; } getSigner(address) { - return __async$d(this, null, function* () { + return __async$e(this, null, function* () { var _a, _b, _c, _d, _e, _f, _g, _h, _i; const signerAddress = (yield __superGet$1(TornadoBrowserProvider.prototype, this, "getSigner").call(this, address)).address; if (((_a = this.options) == null ? void 0 : _a.webChainId) && ((_b = this.options) == null ? void 0 : _b.connectWallet) && Number(yield __superGet$1(TornadoBrowserProvider.prototype, this, "send").call(this, "eth_chainId", [])) !== Number((_c = this.options) == null ? void 0 : _c.webChainId)) { @@ -3353,7 +3353,7 @@ var __spreadValues$4 = (a, b) => { return a; }; var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b)); -var __async$c = (__this, __arguments, generator) => { +var __async$d = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -3376,7 +3376,7 @@ var __async$c = (__this, __arguments, generator) => { const isEmptyArray = (arr) => !Array.isArray(arr) || !arr.length; const first = 1e3; function queryGraph(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, query, @@ -3405,7 +3405,7 @@ function queryGraph(_0) { }); } function getStatistic(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, currency, @@ -3452,7 +3452,7 @@ function getStatistic(_0) { }); } function getMeta(_0) { - return __async$c(this, arguments, function* ({ graphApi, subgraphName, fetchDataOptions: fetchDataOptions2 }) { + return __async$d(this, arguments, function* ({ graphApi, subgraphName, fetchDataOptions: fetchDataOptions2 }) { try { const { _meta: { @@ -3497,7 +3497,7 @@ function getRegisters({ }); } function getAllRegisters(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, fromBlock, @@ -3586,7 +3586,7 @@ function getDeposits({ }); } function getAllDeposits(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, currency, @@ -3683,7 +3683,7 @@ function getWithdrawals({ }); } function getAllWithdrawals(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, currency, @@ -3759,7 +3759,7 @@ function getAllWithdrawals(_0) { }); } function getNoteAccounts(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, address, @@ -3812,7 +3812,7 @@ function getGraphEchoEvents({ }); } function getAllGraphEchoEvents(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, fromBlock, @@ -3901,7 +3901,7 @@ function getEncryptedNotes({ }); } function getAllEncryptedNotes(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, fromBlock, @@ -3986,7 +3986,7 @@ function getGovernanceEvents({ }); } function getAllGovernanceEvents(_0) { - return __async$c(this, arguments, function* ({ + return __async$d(this, arguments, function* ({ graphApi, subgraphName, fromBlock, @@ -4145,7 +4145,7 @@ var graph = /*#__PURE__*/Object.freeze({ queryGraph: queryGraph }); -var __async$b = (__this, __arguments, generator) => { +var __async$c = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -4184,7 +4184,7 @@ class BatchBlockService { this.retryOn = retryOn; } getBlock(blockTag) { - return __async$b(this, null, function* () { + return __async$c(this, null, function* () { const blockObject = yield this.provider.getBlock(blockTag); if (!blockObject) { const errMsg = `No block for ${blockTag}`; @@ -4194,9 +4194,9 @@ class BatchBlockService { }); } createBatchRequest(batchArray) { - return batchArray.map((blocks, index) => __async$b(this, null, function* () { + return batchArray.map((blocks, index) => __async$c(this, null, function* () { yield sleep(20 * index); - return (() => __async$b(this, null, function* () { + return (() => __async$c(this, null, function* () { let retries = 0; let err; while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) { @@ -4213,7 +4213,7 @@ class BatchBlockService { })); } getBatchBlocks(blocks) { - return __async$b(this, null, function* () { + return __async$c(this, null, function* () { let blockCount = 0; const results = []; for (const chunks of chunk(blocks, this.concurrencySize * this.batchSize)) { @@ -4251,7 +4251,7 @@ class BatchTransactionService { this.retryOn = retryOn; } getTransaction(txHash) { - return __async$b(this, null, function* () { + return __async$c(this, null, function* () { const txObject = yield this.provider.getTransaction(txHash); if (!txObject) { const errMsg = `No transaction for ${txHash}`; @@ -4261,9 +4261,9 @@ class BatchTransactionService { }); } createBatchRequest(batchArray) { - return batchArray.map((txs, index) => __async$b(this, null, function* () { + return batchArray.map((txs, index) => __async$c(this, null, function* () { yield sleep(20 * index); - return (() => __async$b(this, null, function* () { + return (() => __async$c(this, null, function* () { let retries = 0; let err; while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) { @@ -4280,7 +4280,7 @@ class BatchTransactionService { })); } getBatchTransactions(txs) { - return __async$b(this, null, function* () { + return __async$c(this, null, function* () { let txCount = 0; const results = []; for (const chunks of chunk(txs, this.concurrencySize * this.batchSize)) { @@ -4316,7 +4316,7 @@ class BatchEventsService { this.retryOn = retryOn; } getPastEvents(_0) { - return __async$b(this, arguments, function* ({ fromBlock, toBlock, type }) { + return __async$c(this, arguments, function* ({ fromBlock, toBlock, type }) { let err; let retries = 0; while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) { @@ -4336,13 +4336,13 @@ class BatchEventsService { }); } createBatchRequest(batchArray) { - return batchArray.map((event, index) => __async$b(this, null, function* () { + return batchArray.map((event, index) => __async$c(this, null, function* () { yield sleep(20 * index); return this.getPastEvents(event); })); } getBatchEvents(_0) { - return __async$b(this, arguments, function* ({ fromBlock, toBlock, type = "*" }) { + return __async$c(this, arguments, function* ({ fromBlock, toBlock, type = "*" }) { if (!toBlock) { toBlock = yield this.provider.getBlockNumber(); } @@ -4395,7 +4395,7 @@ var __spreadValues$3 = (a, b) => { }; var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b)); var __superGet = (cls, obj, key) => __reflectGet(__getProtoOf(cls), key, obj); -var __async$a = (__this, __arguments, generator) => { +var __async$b = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -4470,7 +4470,7 @@ class BaseEventsService { } /* eslint-enable @typescript-eslint/no-unused-vars */ formatEvents(events) { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return yield new Promise((resolve) => resolve(events)); }); } @@ -4478,7 +4478,7 @@ class BaseEventsService { * Get saved or cached events */ getEventsFromDB() { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return { events: [], lastBlock: null @@ -4486,7 +4486,7 @@ class BaseEventsService { }); } getEventsFromCache() { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return { events: [], lastBlock: null @@ -4494,7 +4494,7 @@ class BaseEventsService { }); } getSavedEvents() { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { let cachedEvents = yield this.getEventsFromDB(); if (!cachedEvents || !cachedEvents.events.length) { cachedEvents = yield this.getEventsFromCache(); @@ -4506,7 +4506,7 @@ class BaseEventsService { * Get latest events */ getEventsFromGraph(_0) { - return __async$a(this, arguments, function* ({ + return __async$b(this, arguments, function* ({ fromBlock, methodName = "" }) { @@ -4526,7 +4526,7 @@ class BaseEventsService { }); } getEventsFromRpc(_0) { - return __async$a(this, arguments, function* ({ + return __async$b(this, arguments, function* ({ fromBlock, toBlock }) { @@ -4564,7 +4564,7 @@ class BaseEventsService { }); } getLatestEvents(_0) { - return __async$a(this, arguments, function* ({ fromBlock }) { + return __async$b(this, arguments, function* ({ fromBlock }) { const allEvents = []; const graphEvents = yield this.getEventsFromGraph({ fromBlock }); const lastSyncBlock = graphEvents.lastBlock && graphEvents.lastBlock >= fromBlock ? graphEvents.lastBlock : fromBlock; @@ -4586,14 +4586,14 @@ class BaseEventsService { */ // eslint-disable-next-line @typescript-eslint/no-unused-vars saveEvents(_0) { - return __async$a(this, arguments, function* ({ events, lastBlock }) { + return __async$b(this, arguments, function* ({ events, lastBlock }) { }); } /** * Trigger saving and receiving latest events */ updateEvents() { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { const savedEvents = yield this.getSavedEvents(); let fromBlock = this.deployedBlock; if (savedEvents && savedEvents.lastBlock) { @@ -4667,7 +4667,7 @@ class BaseDepositsService extends BaseEventsService { }; } formatEvents(events) { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { const type = this.getType().toLowerCase(); if (type === DEPOSIT) { const formattedEvents = events.map(({ blockNumber, index: logIndex, transactionHash, args }) => { @@ -4746,7 +4746,7 @@ class BaseEchoService extends BaseEventsService { return "getAllGraphEchoEvents"; } formatEvents(events) { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return events.map(({ blockNumber, index: logIndex, transactionHash, args }) => { const { who, data } = args; if (who && data) { @@ -4764,7 +4764,7 @@ class BaseEchoService extends BaseEventsService { }); } getEventsFromGraph(_0) { - return __async$a(this, arguments, function* ({ fromBlock }) { + return __async$b(this, arguments, function* ({ fromBlock }) { if (!this.graphApi || this.graphApi.includes("api.thegraph.com")) { return { events: [], @@ -4797,7 +4797,7 @@ class BaseEncryptedNotesService extends BaseEventsService { return "getAllEncryptedNotes"; } formatEvents(events) { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return events.map(({ blockNumber, index: logIndex, transactionHash, args }) => { const { encryptedNote } = args; if (encryptedNote) { @@ -4840,7 +4840,7 @@ class BaseGovernanceService extends BaseEventsService { return "getAllGovernanceEvents"; } formatEvents(events) { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { const proposalEvents = []; const votedEvents = []; const delegatedEvents = []; @@ -4907,7 +4907,7 @@ class BaseGovernanceService extends BaseEventsService { }); } getEventsFromGraph(_0) { - return __async$a(this, arguments, function* ({ fromBlock }) { + return __async$b(this, arguments, function* ({ fromBlock }) { if (!this.graphApi || !this.subgraphName || this.graphApi.includes("api.thegraph.com")) { return { events: [], @@ -4942,7 +4942,7 @@ class BaseRegistryService extends BaseEventsService { return "getAllRegisters"; } formatEvents(events) { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return events.map(({ blockNumber, index: logIndex, transactionHash, args }) => { const eventObjects = { blockNumber, @@ -4957,13 +4957,13 @@ class BaseRegistryService extends BaseEventsService { }); } fetchRelayers() { - return __async$a(this, null, function* () { + return __async$b(this, null, function* () { return (yield this.updateEvents()).events; }); } } -var __async$9 = (__this, __arguments, generator) => { +var __async$a = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -4984,7 +4984,7 @@ var __async$9 = (__this, __arguments, generator) => { }); }; function existsAsync(fileOrDir) { - return __async$9(this, null, function* () { + return __async$a(this, null, function* () { try { yield stat(fileOrDir); return true; @@ -5016,7 +5016,7 @@ function unzipAsync(data) { }); } function saveUserFile(_0) { - return __async$9(this, arguments, function* ({ + return __async$a(this, arguments, function* ({ fileName, userDirectory, dataString @@ -5034,7 +5034,7 @@ function saveUserFile(_0) { }); } function loadSavedEvents(_0) { - return __async$9(this, arguments, function* ({ + return __async$a(this, arguments, function* ({ name, userDirectory, deployedBlock @@ -5063,7 +5063,7 @@ function loadSavedEvents(_0) { }); } function download(_0) { - return __async$9(this, arguments, function* ({ name, cacheDirectory }) { + return __async$a(this, arguments, function* ({ name, cacheDirectory }) { const fileName = `${name}.json`.toLowerCase(); const zipName = `${fileName}.zip`; const zipPath = path.join(cacheDirectory, zipName); @@ -5073,7 +5073,7 @@ function download(_0) { }); } function loadCachedEvents(_0) { - return __async$9(this, arguments, function* ({ + return __async$a(this, arguments, function* ({ name, cacheDirectory, deployedBlock @@ -5103,7 +5103,7 @@ function loadCachedEvents(_0) { }); } -var __async$8 = (__this, __arguments, generator) => { +var __async$9 = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -5188,7 +5188,7 @@ class NodeDepositsService extends BaseDepositsService { } } getEventsFromDB() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.userDirectory) { console.log( "Updating events for", @@ -5219,7 +5219,7 @@ class NodeDepositsService extends BaseDepositsService { }); } getEventsFromCache() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.cacheDirectory) { console.log(`cachedEvents count - ${0}`); console.log(`cachedEvents lastBlock - ${this.deployedBlock} @@ -5241,7 +5241,7 @@ class NodeDepositsService extends BaseDepositsService { }); } saveEvents(_0) { - return __async$8(this, arguments, function* ({ events, lastBlock }) { + return __async$9(this, arguments, function* ({ events, lastBlock }) { const instanceName = this.getInstanceName(); console.log("\ntotalEvents count - ", events.length); console.log( @@ -5320,7 +5320,7 @@ class NodeEchoService extends BaseEchoService { } } getEventsFromDB() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.userDirectory) { console.log(`Updating events for ${this.netId} chain echo events `); @@ -5346,7 +5346,7 @@ class NodeEchoService extends BaseEchoService { }); } getEventsFromCache() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.cacheDirectory) { console.log(`cachedEvents count - ${0}`); console.log(`cachedEvents lastBlock - ${this.deployedBlock} @@ -5368,7 +5368,7 @@ class NodeEchoService extends BaseEchoService { }); } saveEvents(_0) { - return __async$8(this, arguments, function* ({ events, lastBlock }) { + return __async$9(this, arguments, function* ({ events, lastBlock }) { const instanceName = this.getInstanceName(); console.log("\ntotalEvents count - ", events.length); console.log( @@ -5446,7 +5446,7 @@ class NodeEncryptedNotesService extends BaseEncryptedNotesService { } } getEventsFromDB() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.userDirectory) { console.log(`Updating events for ${this.netId} chain encrypted events `); @@ -5472,7 +5472,7 @@ class NodeEncryptedNotesService extends BaseEncryptedNotesService { }); } getEventsFromCache() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.cacheDirectory) { console.log(`cachedEvents count - ${0}`); console.log(`cachedEvents lastBlock - ${this.deployedBlock} @@ -5494,7 +5494,7 @@ class NodeEncryptedNotesService extends BaseEncryptedNotesService { }); } saveEvents(_0) { - return __async$8(this, arguments, function* ({ events, lastBlock }) { + return __async$9(this, arguments, function* ({ events, lastBlock }) { const instanceName = this.getInstanceName(); console.log("\ntotalEvents count - ", events.length); console.log( @@ -5577,7 +5577,7 @@ class NodeGovernanceService extends BaseGovernanceService { } } getEventsFromDB() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.userDirectory) { console.log(`Updating events for ${this.netId} chain governance events `); @@ -5603,7 +5603,7 @@ class NodeGovernanceService extends BaseGovernanceService { }); } getEventsFromCache() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.cacheDirectory) { console.log(`cachedEvents count - ${0}`); console.log(`cachedEvents lastBlock - ${this.deployedBlock} @@ -5625,7 +5625,7 @@ class NodeGovernanceService extends BaseGovernanceService { }); } saveEvents(_0) { - return __async$8(this, arguments, function* ({ events, lastBlock }) { + return __async$9(this, arguments, function* ({ events, lastBlock }) { const instanceName = this.getInstanceName(); console.log("\ntotalEvents count - ", events.length); console.log( @@ -5703,7 +5703,7 @@ class NodeRegistryService extends BaseRegistryService { } } getEventsFromDB() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.userDirectory) { console.log(`Updating events for ${this.netId} chain registry events `); @@ -5729,7 +5729,7 @@ class NodeRegistryService extends BaseRegistryService { }); } getEventsFromCache() { - return __async$8(this, null, function* () { + return __async$9(this, null, function* () { if (!this.cacheDirectory) { console.log(`cachedEvents count - ${0}`); console.log(`cachedEvents lastBlock - ${this.deployedBlock} @@ -5751,7 +5751,7 @@ class NodeRegistryService extends BaseRegistryService { }); } saveEvents(_0) { - return __async$8(this, arguments, function* ({ events, lastBlock }) { + return __async$9(this, arguments, function* ({ events, lastBlock }) { const instanceName = this.getInstanceName(); console.log("\ntotalEvents count - ", events.length); console.log( @@ -6582,7 +6582,7 @@ ajv.addKeyword({ errors: true }); -var __async$7 = (__this, __arguments, generator) => { +var __async$8 = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -6607,13 +6607,13 @@ class Pedersen { this.pedersenPromise = this.initPedersen(); } initPedersen() { - return __async$7(this, null, function* () { + return __async$8(this, null, function* () { this.pedersenHash = yield buildPedersenHash(); this.babyJub = this.pedersenHash.babyJub; }); } unpackPoint(buffer) { - return __async$7(this, null, function* () { + return __async$8(this, null, function* () { var _a, _b; yield this.pedersenPromise; return (_b = this.babyJub) == null ? void 0 : _b.unpackPoint((_a = this.pedersenHash) == null ? void 0 : _a.hash(buffer)); @@ -6626,13 +6626,13 @@ class Pedersen { } const pedersen = new Pedersen(); function buffPedersenHash(buffer) { - return __async$7(this, null, function* () { + return __async$8(this, null, function* () { const [hash] = yield pedersen.unpackPoint(buffer); return pedersen.toStringBuffer(hash); }); } -var __async$6 = (__this, __arguments, generator) => { +var __async$7 = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -6653,7 +6653,7 @@ var __async$6 = (__this, __arguments, generator) => { }); }; function createDeposit(_0) { - return __async$6(this, arguments, function* ({ nullifier, secret }) { + return __async$7(this, arguments, function* ({ nullifier, secret }) { const preimage = new Uint8Array([...leInt2Buff(nullifier), ...leInt2Buff(secret)]); const noteHex = toFixedHex(bytesToBN(preimage), 62); const commitment = BigInt(yield buffPedersenHash(preimage)); @@ -6713,7 +6713,7 @@ class Deposit { ); } static createNote(_0) { - return __async$6(this, arguments, function* ({ currency, amount, netId, nullifier, secret }) { + return __async$7(this, arguments, function* ({ currency, amount, netId, nullifier, secret }) { if (!nullifier) { nullifier = rBigInt(31); } @@ -6740,7 +6740,7 @@ class Deposit { }); } static parseNote(noteString) { - return __async$6(this, null, function* () { + return __async$7(this, null, function* () { const noteRegex = new RegExp("tornado-(?\\w+)-(?[\\d.]+)-(?\\d+)-0x(?[0-9a-fA-F]{124})", "g"); const match = noteRegex.exec(noteString); if (!match) { @@ -7000,7 +7000,7 @@ class TornadoFeeOracle { } } -var __async$5 = (__this, __arguments, generator) => { +var __async$6 = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -7025,7 +7025,7 @@ class Mimc { this.mimcPromise = this.initMimc(); } initMimc() { - return __async$5(this, null, function* () { + return __async$6(this, null, function* () { this.sponge = yield buildMimcSponge(); this.hash = (left, right) => { var _a, _b; @@ -7034,7 +7034,7 @@ class Mimc { }); } getHash() { - return __async$5(this, null, function* () { + return __async$6(this, null, function* () { yield this.mimcPromise; return { sponge: this.sponge, @@ -7045,7 +7045,7 @@ class Mimc { } const mimc = new Mimc(); -var __async$4 = (__this, __arguments, generator) => { +var __async$5 = (__this, __arguments, generator) => { return new Promise((resolve, reject) => { var fulfilled = (value) => { try { @@ -7088,7 +7088,7 @@ class MerkleTreeService { this.merkleWorkerPath = merkleWorkerPath; } createTree(events) { - return __async$4(this, null, function* () { + return __async$5(this, null, function* () { const { hash: hashFunction } = yield mimc.getHash(); if (this.merkleWorkerPath) { console.log("Using merkleWorker\n"); @@ -7140,7 +7140,7 @@ class MerkleTreeService { }); } createPartialTree(_0) { - return __async$4(this, arguments, function* ({ edge, elements }) { + return __async$5(this, arguments, function* ({ edge, elements }) { const { hash: hashFunction } = yield mimc.getHash(); if (this.merkleWorkerPath) { console.log("Using merkleWorker\n"); @@ -7194,7 +7194,7 @@ class MerkleTreeService { }); } verifyTree(events) { - return __async$4(this, null, function* () { + return __async$5(this, null, function* () { console.log( ` Creating deposit tree for ${this.netId} ${this.amount} ${this.currency.toUpperCase()} would take a while @@ -7279,6 +7279,26 @@ function parseRecoveryKey(value) { return value; } +var __async$4 = (__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()); + }); +}; class TokenPriceOracle { constructor(provider, multicall2, oracle) { this.provider = provider; @@ -7286,17 +7306,22 @@ class TokenPriceOracle { this.oracle = oracle; } fetchPrices(tokens) { - if (!this.oracle) { - return new Promise((resolve) => resolve(tokens.map(() => parseEther("0.0001")))); - } - return multicall( - this.multicall, - tokens.map((token) => ({ - contract: this.oracle, - name: "getRateToEth", - params: [token, true] - })) - ); + return __async$4(this, null, function* () { + if (!this.oracle) { + return new Promise((resolve) => resolve(tokens.map(() => parseEther("0.0001")))); + } + const prices = yield multicall( + this.multicall, + tokens.map(({ tokenAddress }) => ({ + contract: this.oracle, + name: "getRateToEth", + params: [tokenAddress, true] + })) + ); + return prices.map((price, index) => { + return price * BigInt(10 ** tokens[index].decimals) / BigInt(10 ** 18); + }); + }); } } diff --git a/dist/index.umd.js b/dist/index.umd.js index 860c3bb..037735a 100644 --- a/dist/index.umd.js +++ b/dist/index.umd.js @@ -67531,6 +67531,26 @@ function buffPedersenHash(buffer) { /* harmony import */ var ethers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(99770); /* harmony import */ var _multicall__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(48486); +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()); + }); +}; class TokenPriceOracle { @@ -67540,17 +67560,22 @@ class TokenPriceOracle { this.oracle = oracle; } fetchPrices(tokens) { - if (!this.oracle) { - return new Promise((resolve) => resolve(tokens.map(() => (0,ethers__WEBPACK_IMPORTED_MODULE_0__/* .parseEther */ .g5)("0.0001")))); - } - return (0,_multicall__WEBPACK_IMPORTED_MODULE_1__/* .multicall */ .C)( - this.multicall, - tokens.map((token) => ({ - contract: this.oracle, - name: "getRateToEth", - params: [token, true] - })) - ); + return __async(this, null, function* () { + if (!this.oracle) { + return new Promise((resolve) => resolve(tokens.map(() => (0,ethers__WEBPACK_IMPORTED_MODULE_0__/* .parseEther */ .g5)("0.0001")))); + } + const prices = yield (0,_multicall__WEBPACK_IMPORTED_MODULE_1__/* .multicall */ .C)( + this.multicall, + tokens.map(({ tokenAddress }) => ({ + contract: this.oracle, + name: "getRateToEth", + params: [tokenAddress, true] + })) + ); + return prices.map((price, index) => { + return price * BigInt(10 ** tokens[index].decimals) / BigInt(10 ** 18); + }); + }); } } diff --git a/dist/prices.d.ts b/dist/prices.d.ts index 52b33cf..021a3aa 100644 --- a/dist/prices.d.ts +++ b/dist/prices.d.ts @@ -5,5 +5,8 @@ export declare class TokenPriceOracle { multicall: Multicall; provider: Provider; constructor(provider: Provider, multicall: Multicall, oracle?: OffchainOracle); - fetchPrices(tokens: string[]): Promise; + fetchPrices(tokens: { + tokenAddress: string; + decimals: number; + }[]): Promise; } diff --git a/src/prices.ts b/src/prices.ts index e022c85..35097d0 100644 --- a/src/prices.ts +++ b/src/prices.ts @@ -13,19 +13,28 @@ export class TokenPriceOracle { this.oracle = oracle; } - fetchPrices(tokens: string[]): Promise { + async fetchPrices( + tokens: { + tokenAddress: string; + decimals: number; + }[], + ): Promise { // setup mock price for testnets if (!this.oracle) { return new Promise((resolve) => resolve(tokens.map(() => parseEther('0.0001')))); } - return multicall( + const prices = (await multicall( this.multicall, - tokens.map((token) => ({ + tokens.map(({ tokenAddress }) => ({ contract: this.oracle, name: 'getRateToEth', - params: [token, true], + params: [tokenAddress, true], })), - ); + )) as bigint[]; + + return prices.map((price, index) => { + return (price * BigInt(10 ** tokens[index].decimals)) / BigInt(10 ** 18); + }); } }