Add gasPrice function for FeeOracle

This commit is contained in:
Tornado Contrib 2024-10-10 18:34:38 +00:00
parent d87e6c51f7
commit 4f0aaea790
Signed by: tornadocontrib
GPG Key ID: 60B4DF1A076C64B1
6 changed files with 363 additions and 172 deletions

13
dist/fees.d.ts vendored

@ -1,4 +1,4 @@
import type { BigNumberish, TransactionLike } from 'ethers';
import type { BigNumberish, JsonRpcApiProvider, TransactionLike } from 'ethers';
import { OvmGasPriceOracle } from './typechain';
/**
* Example:
@ -19,8 +19,17 @@ export interface RelayerFeeParams {
premiumPercent?: number;
}
export declare class TornadoFeeOracle {
provider: JsonRpcApiProvider;
ovmGasPriceOracle?: OvmGasPriceOracle;
constructor(ovmGasPriceOracle?: OvmGasPriceOracle);
constructor(provider: JsonRpcApiProvider, ovmGasPriceOracle?: OvmGasPriceOracle);
/**
* Calculates Gas Price
* We apply 50% premium of EIP-1559 network fees instead of 100% from ethers.js
* (This should cover up to 4 full blocks which is equivalent of minute)
* (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets)
* (Still it is recommended to use 100% premium for sending transactions to prevent stucking it)
*/
gasPrice(): Promise<bigint>;
/**
* Calculate L1 fee for op-stack chains
*

216
dist/index.js vendored

@ -33,7 +33,7 @@ function _interopNamespaceDefault(e) {
var websnarkUtils__namespace = /*#__PURE__*/_interopNamespaceDefault(websnarkUtils);
var __async$h = (__this, __arguments, generator) => {
var __async$i = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -142,7 +142,7 @@ function substring(str, length = 10) {
return `${str.substring(0, length)}...${str.substring(str.length - length)}`;
}
function digest(bytes, algo = "SHA-384") {
return __async$h(this, null, function* () {
return __async$i(this, null, function* () {
return new Uint8Array(yield crypto.subtle.digest(algo, bytes));
});
}
@ -169,7 +169,7 @@ var __spreadValues$8 = (a, b) => {
};
var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
var __superGet$2 = (cls, obj, key) => __reflectGet$2(__getProtoOf$2(cls), key, obj);
var __async$g = (__this, __arguments, generator) => {
var __async$h = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -218,7 +218,7 @@ function getHttpAgent({
}
}
function fetchData(_0) {
return __async$g(this, arguments, function* (url, options = {}) {
return __async$h(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;
@ -310,7 +310,7 @@ function fetchData(_0) {
throw errorObject;
});
}
const fetchGetUrlFunc = (options = {}) => (req, _signal) => __async$g(void 0, null, function* () {
const fetchGetUrlFunc = (options = {}) => (req, _signal) => __async$h(void 0, null, function* () {
let signal;
if (_signal) {
const controller = new AbortController();
@ -341,7 +341,7 @@ const fetchGetUrlFunc = (options = {}) => (req, _signal) => __async$g(void 0, nu
};
});
function getProvider(rpcUrl, fetchOptions) {
return __async$g(this, null, function* () {
return __async$h(this, null, function* () {
const fetchReq = new ethers.FetchRequest(rpcUrl);
fetchReq.getUrlFunc = fetchGetUrlFunc(fetchOptions);
const staticNetwork = yield new ethers.JsonRpcProvider(fetchReq).getNetwork();
@ -372,7 +372,7 @@ function getProviderWithNetId(netId, rpcUrl, config, fetchOptions) {
});
return provider;
}
const populateTransaction = (signer, tx) => __async$g(void 0, null, function* () {
const populateTransaction = (signer, tx) => __async$h(void 0, null, function* () {
const provider = signer.provider;
if (!tx.from) {
tx.from = signer.address;
@ -433,7 +433,7 @@ class TornadoWallet extends ethers.Wallet {
return new TornadoWallet(privateKey, provider, options);
}
populateTransaction(tx) {
return __async$g(this, null, function* () {
return __async$h(this, null, function* () {
const txObject = yield populateTransaction(this, tx);
this.nonce = Number(txObject.nonce);
return __superGet$2(TornadoWallet.prototype, this, "populateTransaction").call(this, txObject);
@ -449,7 +449,7 @@ class TornadoVoidSigner extends ethers.VoidSigner {
this.bumpNonce = bumpNonce != null ? bumpNonce : false;
}
populateTransaction(tx) {
return __async$g(this, null, function* () {
return __async$h(this, null, function* () {
const txObject = yield populateTransaction(this, tx);
this.nonce = Number(txObject.nonce);
return __superGet$2(TornadoVoidSigner.prototype, this, "populateTransaction").call(this, txObject);
@ -465,7 +465,7 @@ class TornadoRpcSigner extends ethers.JsonRpcSigner {
this.bumpNonce = bumpNonce != null ? bumpNonce : false;
}
sendUncheckedTransaction(tx) {
return __async$g(this, null, function* () {
return __async$h(this, null, function* () {
return __superGet$2(TornadoRpcSigner.prototype, this, "sendUncheckedTransaction").call(this, yield populateTransaction(this, tx));
});
}
@ -476,7 +476,7 @@ class TornadoBrowserProvider extends ethers.BrowserProvider {
this.options = options;
}
getSigner(address) {
return __async$g(this, null, function* () {
return __async$h(this, null, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
const signerAddress = (yield __superGet$2(TornadoBrowserProvider.prototype, this, "getSigner").call(this, address)).address;
if (((_a = this.options) == null ? void 0 : _a.netId) && ((_b = this.options) == null ? void 0 : _b.connectWallet) && Number(yield __superGet$2(TornadoBrowserProvider.prototype, this, "send").call(this, "net_version", [])) !== ((_c = this.options) == null ? void 0 : _c.netId)) {
@ -704,7 +704,7 @@ var __spreadValues$7 = (a, b) => {
return a;
};
var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
var __async$f = (__this, __arguments, generator) => {
var __async$g = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -727,7 +727,7 @@ var __async$f = (__this, __arguments, generator) => {
const isEmptyArray = (arr) => !Array.isArray(arr) || !arr.length;
const GRAPHQL_LIMIT = 1e3;
function queryGraph(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
query,
@ -756,7 +756,7 @@ function queryGraph(_0) {
});
}
function getStatistic(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
currency,
@ -803,7 +803,7 @@ function getStatistic(_0) {
});
}
function getMeta(_0) {
return __async$f(this, arguments, function* ({ graphApi, subgraphName, fetchDataOptions: fetchDataOptions2 }) {
return __async$g(this, arguments, function* ({ graphApi, subgraphName, fetchDataOptions: fetchDataOptions2 }) {
try {
const {
_meta: {
@ -848,7 +848,7 @@ function getRegisters({
});
}
function getAllRegisters(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
fromBlock,
@ -937,7 +937,7 @@ function getDeposits({
});
}
function getAllDeposits(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
currency,
@ -1034,7 +1034,7 @@ function getWithdrawals({
});
}
function getAllWithdrawals(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
currency,
@ -1110,7 +1110,7 @@ function getAllWithdrawals(_0) {
});
}
function getNoteAccounts(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
address,
@ -1163,7 +1163,7 @@ function getGraphEchoEvents({
});
}
function getAllGraphEchoEvents(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
fromBlock,
@ -1252,7 +1252,7 @@ function getEncryptedNotes({
});
}
function getAllEncryptedNotes(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
fromBlock,
@ -1337,7 +1337,7 @@ function getGovernanceEvents({
});
}
function getAllGovernanceEvents(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
fromBlock,
@ -1496,7 +1496,7 @@ var graph = /*#__PURE__*/Object.freeze({
queryGraph: queryGraph
});
var __async$e = (__this, __arguments, generator) => {
var __async$f = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -1535,7 +1535,7 @@ class BatchBlockService {
this.retryOn = retryOn;
}
getBlock(blockTag) {
return __async$e(this, null, function* () {
return __async$f(this, null, function* () {
const blockObject = yield this.provider.getBlock(blockTag);
if (!blockObject) {
const errMsg = `No block for ${blockTag}`;
@ -1545,9 +1545,9 @@ class BatchBlockService {
});
}
createBatchRequest(batchArray) {
return batchArray.map((blocks, index) => __async$e(this, null, function* () {
return batchArray.map((blocks, index) => __async$f(this, null, function* () {
yield sleep(20 * index);
return (() => __async$e(this, null, function* () {
return (() => __async$f(this, null, function* () {
let retries = 0;
let err;
while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) {
@ -1564,7 +1564,7 @@ class BatchBlockService {
}));
}
getBatchBlocks(blocks) {
return __async$e(this, null, function* () {
return __async$f(this, null, function* () {
let blockCount = 0;
const results = [];
for (const chunks of chunk(blocks, this.concurrencySize * this.batchSize)) {
@ -1602,7 +1602,7 @@ class BatchTransactionService {
this.retryOn = retryOn;
}
getTransaction(txHash) {
return __async$e(this, null, function* () {
return __async$f(this, null, function* () {
const txObject = yield this.provider.getTransaction(txHash);
if (!txObject) {
const errMsg = `No transaction for ${txHash}`;
@ -1612,9 +1612,9 @@ class BatchTransactionService {
});
}
createBatchRequest(batchArray) {
return batchArray.map((txs, index) => __async$e(this, null, function* () {
return batchArray.map((txs, index) => __async$f(this, null, function* () {
yield sleep(20 * index);
return (() => __async$e(this, null, function* () {
return (() => __async$f(this, null, function* () {
let retries = 0;
let err;
while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) {
@ -1631,7 +1631,7 @@ class BatchTransactionService {
}));
}
getBatchTransactions(txs) {
return __async$e(this, null, function* () {
return __async$f(this, null, function* () {
let txCount = 0;
const results = [];
for (const chunks of chunk(txs, this.concurrencySize * this.batchSize)) {
@ -1667,7 +1667,7 @@ class BatchEventsService {
this.retryOn = retryOn;
}
getPastEvents(_0) {
return __async$e(this, arguments, function* ({ fromBlock, toBlock, type }) {
return __async$f(this, arguments, function* ({ fromBlock, toBlock, type }) {
let err;
let retries = 0;
while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) {
@ -1687,13 +1687,13 @@ class BatchEventsService {
});
}
createBatchRequest(batchArray) {
return batchArray.map((event, index) => __async$e(this, null, function* () {
return batchArray.map((event, index) => __async$f(this, null, function* () {
yield sleep(20 * index);
return this.getPastEvents(event);
}));
}
getBatchEvents(_0) {
return __async$e(this, arguments, function* ({ fromBlock, toBlock, type = "*" }) {
return __async$f(this, arguments, function* ({ fromBlock, toBlock, type = "*" }) {
if (!toBlock) {
toBlock = yield this.provider.getBlockNumber();
}
@ -2734,7 +2734,7 @@ var __spreadValues$3 = (a, b) => {
return a;
};
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
var __async$d = (__this, __arguments, generator) => {
var __async$e = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -2800,7 +2800,7 @@ class RelayerClient {
this.tovarish = false;
}
askRelayerStatus(_0) {
return __async$d(this, arguments, function* ({
return __async$e(this, arguments, function* ({
hostname,
url,
relayerAddress
@ -2840,7 +2840,7 @@ class RelayerClient {
});
}
filterRelayer(relayer) {
return __async$d(this, null, function* () {
return __async$e(this, null, function* () {
var _a;
const hostname = relayer.hostnames[this.netId];
const { ensName, relayerAddress } = relayer;
@ -2874,7 +2874,7 @@ class RelayerClient {
});
}
getValidRelayers(relayers) {
return __async$d(this, null, function* () {
return __async$e(this, null, function* () {
const invalidRelayers = [];
const validRelayers = (yield Promise.all(relayers.map((relayer) => this.filterRelayer(relayer)))).filter((r) => {
if (!r) {
@ -2896,7 +2896,7 @@ class RelayerClient {
return pickWeightedRandomRelayer(relayers);
}
tornadoWithdraw(_0, _1) {
return __async$d(this, arguments, function* ({ contract, proof, args }, callback) {
return __async$e(this, arguments, function* ({ contract, proof, args }, callback) {
const { url } = this.selectedRelayer;
const withdrawResponse = yield fetchData(`${url}v1/tornadoWithdraw`, __spreadProps$2(__spreadValues$3({}, this.fetchDataOptions), {
method: "POST",
@ -2983,7 +2983,7 @@ var __spreadValues$2 = (a, b) => {
};
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
var __superGet$1 = (cls, obj, key) => __reflectGet$1(__getProtoOf$1(cls), key, obj);
var __async$c = (__this, __arguments, generator) => {
var __async$d = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -3063,7 +3063,7 @@ class BaseEventsService {
}
/* eslint-enable @typescript-eslint/no-unused-vars */
formatEvents(events) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return yield new Promise((resolve) => resolve(events));
});
}
@ -3071,7 +3071,7 @@ class BaseEventsService {
* Get saved or cached events
*/
getEventsFromDB() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return {
events: [],
lastBlock: 0
@ -3082,7 +3082,7 @@ class BaseEventsService {
* Events from remote cache (Either from local cache, CDN, or from IPFS)
*/
getEventsFromCache() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return {
events: [],
lastBlock: 0,
@ -3091,7 +3091,7 @@ class BaseEventsService {
});
}
getSavedEvents() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
let dbEvents = yield this.getEventsFromDB();
if (!dbEvents.lastBlock) {
dbEvents = yield this.getEventsFromCache();
@ -3103,7 +3103,7 @@ class BaseEventsService {
* Get latest events
*/
getEventsFromGraph(_0) {
return __async$c(this, arguments, function* ({
return __async$d(this, arguments, function* ({
fromBlock,
methodName = ""
}) {
@ -3123,7 +3123,7 @@ class BaseEventsService {
});
}
getEventsFromRpc(_0) {
return __async$c(this, arguments, function* ({
return __async$d(this, arguments, function* ({
fromBlock,
toBlock
}) {
@ -3155,7 +3155,7 @@ class BaseEventsService {
});
}
getLatestEvents(_0) {
return __async$c(this, arguments, function* ({ fromBlock }) {
return __async$d(this, arguments, function* ({ fromBlock }) {
var _a;
if (((_a = this.tovarishClient) == null ? void 0 : _a.selectedRelayer) && ![DEPOSIT, WITHDRAWAL].includes(this.type.toLowerCase())) {
const { events, lastSyncBlock: lastBlock } = yield this.tovarishClient.getEvents({
@ -3184,14 +3184,14 @@ class BaseEventsService {
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
saveEvents(_0) {
return __async$c(this, arguments, function* ({ events, lastBlock }) {
return __async$d(this, arguments, function* ({ events, lastBlock }) {
});
}
/**
* Trigger saving and receiving latest events
*/
updateEvents() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
var _a;
const savedEvents = yield this.getSavedEvents();
let fromBlock = this.deployedBlock;
@ -3276,7 +3276,7 @@ class BaseTornadoService extends BaseEventsService {
};
}
formatEvents(events) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
const type = this.getType().toLowerCase();
if (type === DEPOSIT) {
const formattedEvents = events.map(({ blockNumber, index: logIndex, transactionHash, args }) => {
@ -3333,7 +3333,7 @@ class BaseTornadoService extends BaseEventsService {
}
}
getLatestEvents(_0) {
return __async$c(this, arguments, function* ({ fromBlock }) {
return __async$d(this, arguments, function* ({ fromBlock }) {
var _a;
if ((_a = this.tovarishClient) == null ? void 0 : _a.selectedRelayer) {
const { events, lastSyncBlock: lastBlock } = yield this.tovarishClient.getEvents({
@ -3383,7 +3383,7 @@ class BaseEchoService extends BaseEventsService {
return "getAllGraphEchoEvents";
}
formatEvents(events) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return events.map(({ blockNumber, index: logIndex, transactionHash, args }) => {
const { who, data } = args;
if (who && data) {
@ -3401,7 +3401,7 @@ class BaseEchoService extends BaseEventsService {
});
}
getEventsFromGraph(_0) {
return __async$c(this, arguments, function* ({ fromBlock }) {
return __async$d(this, arguments, function* ({ fromBlock }) {
if (!this.graphApi || this.graphApi.includes("api.thegraph.com")) {
return {
events: [],
@ -3447,7 +3447,7 @@ class BaseEncryptedNotesService extends BaseEventsService {
return "getAllEncryptedNotes";
}
formatEvents(events) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return events.map(({ blockNumber, index: logIndex, transactionHash, args }) => {
const { encryptedNote } = args;
if (encryptedNote && encryptedNote !== "0x") {
@ -3503,7 +3503,7 @@ class BaseGovernanceService extends BaseEventsService {
return "getAllGovernanceEvents";
}
formatEvents(events) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
const proposalEvents = [];
const votedEvents = [];
const delegatedEvents = [];
@ -3570,7 +3570,7 @@ class BaseGovernanceService extends BaseEventsService {
});
}
getEventsFromGraph(_0) {
return __async$c(this, arguments, function* ({ fromBlock }) {
return __async$d(this, arguments, function* ({ fromBlock }) {
if (!this.graphApi || !this.subgraphName || this.graphApi.includes("api.thegraph.com")) {
return {
events: [],
@ -3582,9 +3582,9 @@ class BaseGovernanceService extends BaseEventsService {
}
}
function getTovarishNetworks(registryService, relayers) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
yield Promise.all(
relayers.filter((r) => r.tovarishHost).map((relayer) => __async$c(this, null, function* () {
relayers.filter((r) => r.tovarishHost).map((relayer) => __async$d(this, null, function* () {
var _a;
try {
relayer.tovarishNetworks = yield fetchData(relayer.tovarishHost, __spreadProps$1(__spreadValues$2({}, registryService.fetchDataOptions), {
@ -3652,7 +3652,7 @@ class BaseRegistryService extends BaseEventsService {
return "getAllRegisters";
}
formatEvents(events) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return events.map(({ blockNumber, index: logIndex, transactionHash, args }) => {
const eventObjects = {
blockNumber,
@ -3670,7 +3670,7 @@ class BaseRegistryService extends BaseEventsService {
* Get saved or cached relayers
*/
getRelayersFromDB() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return {
lastBlock: 0,
timestamp: 0,
@ -3682,7 +3682,7 @@ class BaseRegistryService extends BaseEventsService {
* Relayers from remote cache (Either from local cache, CDN, or from IPFS)
*/
getRelayersFromCache() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return {
lastBlock: 0,
timestamp: 0,
@ -3692,7 +3692,7 @@ class BaseRegistryService extends BaseEventsService {
});
}
getSavedRelayers() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
let cachedRelayers = yield this.getRelayersFromDB();
if (!cachedRelayers || !cachedRelayers.relayers.length) {
cachedRelayers = yield this.getRelayersFromCache();
@ -3701,7 +3701,7 @@ class BaseRegistryService extends BaseEventsService {
});
}
getLatestRelayers() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
const { events, lastBlock } = yield this.updateEvents();
const subdomains = Object.values(this.relayerEnsSubdomains);
const registerSet = /* @__PURE__ */ new Set();
@ -3761,14 +3761,14 @@ class BaseRegistryService extends BaseEventsService {
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
saveRelayers(_0) {
return __async$c(this, arguments, function* ({ lastBlock, timestamp, relayers }) {
return __async$d(this, arguments, function* ({ lastBlock, timestamp, relayers }) {
});
}
/**
* Get cached or latest relayer and save to local
*/
updateRelayers() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
let { lastBlock, timestamp, relayers, fromCache } = yield this.getSavedRelayers();
let shouldSave = fromCache != null ? fromCache : false;
if (!relayers.length || timestamp + this.updateInterval < Math.floor(Date.now() / 1e3)) {
@ -3784,7 +3784,7 @@ class BaseRegistryService extends BaseEventsService {
}
}
var __async$b = (__this, __arguments, generator) => {
var __async$c = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -3827,7 +3827,7 @@ function unzipAsync(data) {
});
}
function downloadZip(_0) {
return __async$b(this, arguments, function* ({
return __async$c(this, arguments, function* ({
staticUrl = "",
zipName,
zipDigest,
@ -3855,7 +3855,7 @@ function downloadZip(_0) {
});
}
var __async$a = (__this, __arguments, generator) => {
var __async$b = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -3876,7 +3876,7 @@ var __async$a = (__this, __arguments, generator) => {
});
};
function saveDBEvents(_0) {
return __async$a(this, arguments, function* ({
return __async$b(this, arguments, function* ({
idb,
instanceName,
events,
@ -3901,7 +3901,7 @@ function saveDBEvents(_0) {
});
}
function loadDBEvents(_0) {
return __async$a(this, arguments, function* ({
return __async$b(this, arguments, function* ({
idb,
instanceName
}) {
@ -3931,7 +3931,7 @@ function loadDBEvents(_0) {
});
}
function loadRemoteEvents(_0) {
return __async$a(this, arguments, function* ({
return __async$b(this, arguments, function* ({
staticUrl,
instanceName,
deployedBlock,
@ -3972,7 +3972,7 @@ class DBTornadoService extends BaseTornadoService {
this.idb = params.idb;
}
getEventsFromDB() {
return __async$a(this, null, function* () {
return __async$b(this, null, function* () {
return yield loadDBEvents({
idb: this.idb,
instanceName: this.getInstanceName()
@ -3980,7 +3980,7 @@ class DBTornadoService extends BaseTornadoService {
});
}
getEventsFromCache() {
return __async$a(this, null, function* () {
return __async$b(this, null, function* () {
return yield loadRemoteEvents({
staticUrl: this.staticUrl,
instanceName: this.getInstanceName(),
@ -3990,7 +3990,7 @@ class DBTornadoService extends BaseTornadoService {
});
}
saveEvents(_0) {
return __async$a(this, arguments, function* ({ events, lastBlock }) {
return __async$b(this, arguments, function* ({ events, lastBlock }) {
yield saveDBEvents({
idb: this.idb,
instanceName: this.getInstanceName(),
@ -6338,7 +6338,7 @@ var index = /*#__PURE__*/Object.freeze({
ReverseRecords__factory: ReverseRecords__factory
});
var __async$9 = (__this, __arguments, generator) => {
var __async$a = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -6363,13 +6363,13 @@ class Pedersen {
this.pedersenPromise = this.initPedersen();
}
initPedersen() {
return __async$9(this, null, function* () {
return __async$a(this, null, function* () {
this.pedersenHash = yield circomlibjs.buildPedersenHash();
this.babyJub = this.pedersenHash.babyJub;
});
}
unpackPoint(buffer) {
return __async$9(this, null, function* () {
return __async$a(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));
@ -6382,13 +6382,13 @@ class Pedersen {
}
const pedersen = new Pedersen();
function buffPedersenHash(buffer) {
return __async$9(this, null, function* () {
return __async$a(this, null, function* () {
const [hash] = yield pedersen.unpackPoint(buffer);
return pedersen.toStringBuffer(hash);
});
}
var __async$8 = (__this, __arguments, generator) => {
var __async$9 = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -6409,7 +6409,7 @@ var __async$8 = (__this, __arguments, generator) => {
});
};
function createDeposit(_0) {
return __async$8(this, arguments, function* ({ nullifier, secret }) {
return __async$9(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));
@ -6469,7 +6469,7 @@ class Deposit {
);
}
static createNote(_0) {
return __async$8(this, arguments, function* ({ currency, amount, netId, nullifier, secret }) {
return __async$9(this, arguments, function* ({ currency, amount, netId, nullifier, secret }) {
if (!nullifier) {
nullifier = rBigInt(31);
}
@ -6496,7 +6496,7 @@ class Deposit {
});
}
static parseNote(noteString) {
return __async$8(this, null, function* () {
return __async$9(this, null, function* () {
const noteRegex = new RegExp("tornado-(?<currency>\\w+)-(?<amount>[\\d.]+)-(?<netId>\\d+)-0x(?<note>[0-9a-fA-F]{124})", "g");
const match = noteRegex.exec(noteString);
if (!match) {
@ -6681,6 +6681,26 @@ class NoteAccount {
}
}
var __async$8 = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
const DUMMY_ADDRESS = "0x1111111111111111111111111111111111111111";
const DUMMY_NONCE = 1024;
const DUMMY_WITHDRAW_DATA = "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
@ -6689,11 +6709,41 @@ function convertETHToTokenAmount(amountInWei, tokenPriceInWei, tokenDecimals = 1
return BigInt(amountInWei) * tokenDecimalsMultiplier / BigInt(tokenPriceInWei);
}
class TornadoFeeOracle {
constructor(ovmGasPriceOracle) {
constructor(provider, ovmGasPriceOracle) {
this.provider = provider;
if (ovmGasPriceOracle) {
this.ovmGasPriceOracle = ovmGasPriceOracle;
}
}
/**
* Calculates Gas Price
* We apply 50% premium of EIP-1559 network fees instead of 100% from ethers.js
* (This should cover up to 4 full blocks which is equivalent of minute)
* (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets)
* (Still it is recommended to use 100% premium for sending transactions to prevent stucking it)
*/
gasPrice() {
return __async$8(this, null, function* () {
const [block, getGasPrice, getPriorityFee] = yield Promise.all([
this.provider.getBlock("latest"),
(() => __async$8(this, null, function* () {
try {
return BigInt(yield this.provider.send("eth_gasPrice", []));
} catch (e) {
return ethers.parseUnits("1", "gwei");
}
}))(),
(() => __async$8(this, null, function* () {
try {
return BigInt(yield this.provider.send("eth_maxPriorityFeePerGas", []));
} catch (e) {
return BigInt(0);
}
}))()
]);
return (block == null ? void 0 : block.baseFeePerGas) ? block.baseFeePerGas * BigInt(15) / BigInt(10) + getPriorityFee : getGasPrice;
});
}
/**
* Calculate L1 fee for op-stack chains
*

216
dist/index.mjs vendored

@ -12,7 +12,7 @@ import { MerkleTree, PartialMerkleTree } from '@tornado/fixed-merkle-tree';
import * as websnarkUtils from '@tornado/websnark/src/utils';
import websnarkGroth from '@tornado/websnark/src/groth16';
var __async$h = (__this, __arguments, generator) => {
var __async$i = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -121,7 +121,7 @@ function substring(str, length = 10) {
return `${str.substring(0, length)}...${str.substring(str.length - length)}`;
}
function digest(bytes, algo = "SHA-384") {
return __async$h(this, null, function* () {
return __async$i(this, null, function* () {
return new Uint8Array(yield crypto.subtle.digest(algo, bytes));
});
}
@ -148,7 +148,7 @@ var __spreadValues$8 = (a, b) => {
};
var __spreadProps$6 = (a, b) => __defProps$6(a, __getOwnPropDescs$6(b));
var __superGet$2 = (cls, obj, key) => __reflectGet$2(__getProtoOf$2(cls), key, obj);
var __async$g = (__this, __arguments, generator) => {
var __async$h = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -197,7 +197,7 @@ function getHttpAgent({
}
}
function fetchData(_0) {
return __async$g(this, arguments, function* (url, options = {}) {
return __async$h(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;
@ -289,7 +289,7 @@ function fetchData(_0) {
throw errorObject;
});
}
const fetchGetUrlFunc = (options = {}) => (req, _signal) => __async$g(void 0, null, function* () {
const fetchGetUrlFunc = (options = {}) => (req, _signal) => __async$h(void 0, null, function* () {
let signal;
if (_signal) {
const controller = new AbortController();
@ -320,7 +320,7 @@ const fetchGetUrlFunc = (options = {}) => (req, _signal) => __async$g(void 0, nu
};
});
function getProvider(rpcUrl, fetchOptions) {
return __async$g(this, null, function* () {
return __async$h(this, null, function* () {
const fetchReq = new FetchRequest(rpcUrl);
fetchReq.getUrlFunc = fetchGetUrlFunc(fetchOptions);
const staticNetwork = yield new JsonRpcProvider(fetchReq).getNetwork();
@ -351,7 +351,7 @@ function getProviderWithNetId(netId, rpcUrl, config, fetchOptions) {
});
return provider;
}
const populateTransaction = (signer, tx) => __async$g(void 0, null, function* () {
const populateTransaction = (signer, tx) => __async$h(void 0, null, function* () {
const provider = signer.provider;
if (!tx.from) {
tx.from = signer.address;
@ -412,7 +412,7 @@ class TornadoWallet extends Wallet {
return new TornadoWallet(privateKey, provider, options);
}
populateTransaction(tx) {
return __async$g(this, null, function* () {
return __async$h(this, null, function* () {
const txObject = yield populateTransaction(this, tx);
this.nonce = Number(txObject.nonce);
return __superGet$2(TornadoWallet.prototype, this, "populateTransaction").call(this, txObject);
@ -428,7 +428,7 @@ class TornadoVoidSigner extends VoidSigner {
this.bumpNonce = bumpNonce != null ? bumpNonce : false;
}
populateTransaction(tx) {
return __async$g(this, null, function* () {
return __async$h(this, null, function* () {
const txObject = yield populateTransaction(this, tx);
this.nonce = Number(txObject.nonce);
return __superGet$2(TornadoVoidSigner.prototype, this, "populateTransaction").call(this, txObject);
@ -444,7 +444,7 @@ class TornadoRpcSigner extends JsonRpcSigner {
this.bumpNonce = bumpNonce != null ? bumpNonce : false;
}
sendUncheckedTransaction(tx) {
return __async$g(this, null, function* () {
return __async$h(this, null, function* () {
return __superGet$2(TornadoRpcSigner.prototype, this, "sendUncheckedTransaction").call(this, yield populateTransaction(this, tx));
});
}
@ -455,7 +455,7 @@ class TornadoBrowserProvider extends BrowserProvider {
this.options = options;
}
getSigner(address) {
return __async$g(this, null, function* () {
return __async$h(this, null, function* () {
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
const signerAddress = (yield __superGet$2(TornadoBrowserProvider.prototype, this, "getSigner").call(this, address)).address;
if (((_a = this.options) == null ? void 0 : _a.netId) && ((_b = this.options) == null ? void 0 : _b.connectWallet) && Number(yield __superGet$2(TornadoBrowserProvider.prototype, this, "send").call(this, "net_version", [])) !== ((_c = this.options) == null ? void 0 : _c.netId)) {
@ -683,7 +683,7 @@ var __spreadValues$7 = (a, b) => {
return a;
};
var __spreadProps$5 = (a, b) => __defProps$5(a, __getOwnPropDescs$5(b));
var __async$f = (__this, __arguments, generator) => {
var __async$g = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -706,7 +706,7 @@ var __async$f = (__this, __arguments, generator) => {
const isEmptyArray = (arr) => !Array.isArray(arr) || !arr.length;
const GRAPHQL_LIMIT = 1e3;
function queryGraph(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
query,
@ -735,7 +735,7 @@ function queryGraph(_0) {
});
}
function getStatistic(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
currency,
@ -782,7 +782,7 @@ function getStatistic(_0) {
});
}
function getMeta(_0) {
return __async$f(this, arguments, function* ({ graphApi, subgraphName, fetchDataOptions: fetchDataOptions2 }) {
return __async$g(this, arguments, function* ({ graphApi, subgraphName, fetchDataOptions: fetchDataOptions2 }) {
try {
const {
_meta: {
@ -827,7 +827,7 @@ function getRegisters({
});
}
function getAllRegisters(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
fromBlock,
@ -916,7 +916,7 @@ function getDeposits({
});
}
function getAllDeposits(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
currency,
@ -1013,7 +1013,7 @@ function getWithdrawals({
});
}
function getAllWithdrawals(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
currency,
@ -1089,7 +1089,7 @@ function getAllWithdrawals(_0) {
});
}
function getNoteAccounts(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
address,
@ -1142,7 +1142,7 @@ function getGraphEchoEvents({
});
}
function getAllGraphEchoEvents(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
fromBlock,
@ -1231,7 +1231,7 @@ function getEncryptedNotes({
});
}
function getAllEncryptedNotes(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
fromBlock,
@ -1316,7 +1316,7 @@ function getGovernanceEvents({
});
}
function getAllGovernanceEvents(_0) {
return __async$f(this, arguments, function* ({
return __async$g(this, arguments, function* ({
graphApi,
subgraphName,
fromBlock,
@ -1475,7 +1475,7 @@ var graph = /*#__PURE__*/Object.freeze({
queryGraph: queryGraph
});
var __async$e = (__this, __arguments, generator) => {
var __async$f = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -1514,7 +1514,7 @@ class BatchBlockService {
this.retryOn = retryOn;
}
getBlock(blockTag) {
return __async$e(this, null, function* () {
return __async$f(this, null, function* () {
const blockObject = yield this.provider.getBlock(blockTag);
if (!blockObject) {
const errMsg = `No block for ${blockTag}`;
@ -1524,9 +1524,9 @@ class BatchBlockService {
});
}
createBatchRequest(batchArray) {
return batchArray.map((blocks, index) => __async$e(this, null, function* () {
return batchArray.map((blocks, index) => __async$f(this, null, function* () {
yield sleep(20 * index);
return (() => __async$e(this, null, function* () {
return (() => __async$f(this, null, function* () {
let retries = 0;
let err;
while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) {
@ -1543,7 +1543,7 @@ class BatchBlockService {
}));
}
getBatchBlocks(blocks) {
return __async$e(this, null, function* () {
return __async$f(this, null, function* () {
let blockCount = 0;
const results = [];
for (const chunks of chunk(blocks, this.concurrencySize * this.batchSize)) {
@ -1581,7 +1581,7 @@ class BatchTransactionService {
this.retryOn = retryOn;
}
getTransaction(txHash) {
return __async$e(this, null, function* () {
return __async$f(this, null, function* () {
const txObject = yield this.provider.getTransaction(txHash);
if (!txObject) {
const errMsg = `No transaction for ${txHash}`;
@ -1591,9 +1591,9 @@ class BatchTransactionService {
});
}
createBatchRequest(batchArray) {
return batchArray.map((txs, index) => __async$e(this, null, function* () {
return batchArray.map((txs, index) => __async$f(this, null, function* () {
yield sleep(20 * index);
return (() => __async$e(this, null, function* () {
return (() => __async$f(this, null, function* () {
let retries = 0;
let err;
while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) {
@ -1610,7 +1610,7 @@ class BatchTransactionService {
}));
}
getBatchTransactions(txs) {
return __async$e(this, null, function* () {
return __async$f(this, null, function* () {
let txCount = 0;
const results = [];
for (const chunks of chunk(txs, this.concurrencySize * this.batchSize)) {
@ -1646,7 +1646,7 @@ class BatchEventsService {
this.retryOn = retryOn;
}
getPastEvents(_0) {
return __async$e(this, arguments, function* ({ fromBlock, toBlock, type }) {
return __async$f(this, arguments, function* ({ fromBlock, toBlock, type }) {
let err;
let retries = 0;
while (!this.shouldRetry && retries === 0 || this.shouldRetry && retries < this.retryMax) {
@ -1666,13 +1666,13 @@ class BatchEventsService {
});
}
createBatchRequest(batchArray) {
return batchArray.map((event, index) => __async$e(this, null, function* () {
return batchArray.map((event, index) => __async$f(this, null, function* () {
yield sleep(20 * index);
return this.getPastEvents(event);
}));
}
getBatchEvents(_0) {
return __async$e(this, arguments, function* ({ fromBlock, toBlock, type = "*" }) {
return __async$f(this, arguments, function* ({ fromBlock, toBlock, type = "*" }) {
if (!toBlock) {
toBlock = yield this.provider.getBlockNumber();
}
@ -2713,7 +2713,7 @@ var __spreadValues$3 = (a, b) => {
return a;
};
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
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 @@ class RelayerClient {
this.tovarish = false;
}
askRelayerStatus(_0) {
return __async$d(this, arguments, function* ({
return __async$e(this, arguments, function* ({
hostname,
url,
relayerAddress
@ -2819,7 +2819,7 @@ class RelayerClient {
});
}
filterRelayer(relayer) {
return __async$d(this, null, function* () {
return __async$e(this, null, function* () {
var _a;
const hostname = relayer.hostnames[this.netId];
const { ensName, relayerAddress } = relayer;
@ -2853,7 +2853,7 @@ class RelayerClient {
});
}
getValidRelayers(relayers) {
return __async$d(this, null, function* () {
return __async$e(this, null, function* () {
const invalidRelayers = [];
const validRelayers = (yield Promise.all(relayers.map((relayer) => this.filterRelayer(relayer)))).filter((r) => {
if (!r) {
@ -2875,7 +2875,7 @@ class RelayerClient {
return pickWeightedRandomRelayer(relayers);
}
tornadoWithdraw(_0, _1) {
return __async$d(this, arguments, function* ({ contract, proof, args }, callback) {
return __async$e(this, arguments, function* ({ contract, proof, args }, callback) {
const { url } = this.selectedRelayer;
const withdrawResponse = yield fetchData(`${url}v1/tornadoWithdraw`, __spreadProps$2(__spreadValues$3({}, this.fetchDataOptions), {
method: "POST",
@ -2962,7 +2962,7 @@ var __spreadValues$2 = (a, b) => {
};
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
var __superGet$1 = (cls, obj, key) => __reflectGet$1(__getProtoOf$1(cls), key, obj);
var __async$c = (__this, __arguments, generator) => {
var __async$d = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -3042,7 +3042,7 @@ class BaseEventsService {
}
/* eslint-enable @typescript-eslint/no-unused-vars */
formatEvents(events) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return yield new Promise((resolve) => resolve(events));
});
}
@ -3050,7 +3050,7 @@ class BaseEventsService {
* Get saved or cached events
*/
getEventsFromDB() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return {
events: [],
lastBlock: 0
@ -3061,7 +3061,7 @@ class BaseEventsService {
* Events from remote cache (Either from local cache, CDN, or from IPFS)
*/
getEventsFromCache() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return {
events: [],
lastBlock: 0,
@ -3070,7 +3070,7 @@ class BaseEventsService {
});
}
getSavedEvents() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
let dbEvents = yield this.getEventsFromDB();
if (!dbEvents.lastBlock) {
dbEvents = yield this.getEventsFromCache();
@ -3082,7 +3082,7 @@ class BaseEventsService {
* Get latest events
*/
getEventsFromGraph(_0) {
return __async$c(this, arguments, function* ({
return __async$d(this, arguments, function* ({
fromBlock,
methodName = ""
}) {
@ -3102,7 +3102,7 @@ class BaseEventsService {
});
}
getEventsFromRpc(_0) {
return __async$c(this, arguments, function* ({
return __async$d(this, arguments, function* ({
fromBlock,
toBlock
}) {
@ -3134,7 +3134,7 @@ class BaseEventsService {
});
}
getLatestEvents(_0) {
return __async$c(this, arguments, function* ({ fromBlock }) {
return __async$d(this, arguments, function* ({ fromBlock }) {
var _a;
if (((_a = this.tovarishClient) == null ? void 0 : _a.selectedRelayer) && ![DEPOSIT, WITHDRAWAL].includes(this.type.toLowerCase())) {
const { events, lastSyncBlock: lastBlock } = yield this.tovarishClient.getEvents({
@ -3163,14 +3163,14 @@ class BaseEventsService {
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
saveEvents(_0) {
return __async$c(this, arguments, function* ({ events, lastBlock }) {
return __async$d(this, arguments, function* ({ events, lastBlock }) {
});
}
/**
* Trigger saving and receiving latest events
*/
updateEvents() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
var _a;
const savedEvents = yield this.getSavedEvents();
let fromBlock = this.deployedBlock;
@ -3255,7 +3255,7 @@ class BaseTornadoService extends BaseEventsService {
};
}
formatEvents(events) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
const type = this.getType().toLowerCase();
if (type === DEPOSIT) {
const formattedEvents = events.map(({ blockNumber, index: logIndex, transactionHash, args }) => {
@ -3312,7 +3312,7 @@ class BaseTornadoService extends BaseEventsService {
}
}
getLatestEvents(_0) {
return __async$c(this, arguments, function* ({ fromBlock }) {
return __async$d(this, arguments, function* ({ fromBlock }) {
var _a;
if ((_a = this.tovarishClient) == null ? void 0 : _a.selectedRelayer) {
const { events, lastSyncBlock: lastBlock } = yield this.tovarishClient.getEvents({
@ -3362,7 +3362,7 @@ class BaseEchoService extends BaseEventsService {
return "getAllGraphEchoEvents";
}
formatEvents(events) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return events.map(({ blockNumber, index: logIndex, transactionHash, args }) => {
const { who, data } = args;
if (who && data) {
@ -3380,7 +3380,7 @@ class BaseEchoService extends BaseEventsService {
});
}
getEventsFromGraph(_0) {
return __async$c(this, arguments, function* ({ fromBlock }) {
return __async$d(this, arguments, function* ({ fromBlock }) {
if (!this.graphApi || this.graphApi.includes("api.thegraph.com")) {
return {
events: [],
@ -3426,7 +3426,7 @@ class BaseEncryptedNotesService extends BaseEventsService {
return "getAllEncryptedNotes";
}
formatEvents(events) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return events.map(({ blockNumber, index: logIndex, transactionHash, args }) => {
const { encryptedNote } = args;
if (encryptedNote && encryptedNote !== "0x") {
@ -3482,7 +3482,7 @@ class BaseGovernanceService extends BaseEventsService {
return "getAllGovernanceEvents";
}
formatEvents(events) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
const proposalEvents = [];
const votedEvents = [];
const delegatedEvents = [];
@ -3549,7 +3549,7 @@ class BaseGovernanceService extends BaseEventsService {
});
}
getEventsFromGraph(_0) {
return __async$c(this, arguments, function* ({ fromBlock }) {
return __async$d(this, arguments, function* ({ fromBlock }) {
if (!this.graphApi || !this.subgraphName || this.graphApi.includes("api.thegraph.com")) {
return {
events: [],
@ -3561,9 +3561,9 @@ class BaseGovernanceService extends BaseEventsService {
}
}
function getTovarishNetworks(registryService, relayers) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
yield Promise.all(
relayers.filter((r) => r.tovarishHost).map((relayer) => __async$c(this, null, function* () {
relayers.filter((r) => r.tovarishHost).map((relayer) => __async$d(this, null, function* () {
var _a;
try {
relayer.tovarishNetworks = yield fetchData(relayer.tovarishHost, __spreadProps$1(__spreadValues$2({}, registryService.fetchDataOptions), {
@ -3631,7 +3631,7 @@ class BaseRegistryService extends BaseEventsService {
return "getAllRegisters";
}
formatEvents(events) {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return events.map(({ blockNumber, index: logIndex, transactionHash, args }) => {
const eventObjects = {
blockNumber,
@ -3649,7 +3649,7 @@ class BaseRegistryService extends BaseEventsService {
* Get saved or cached relayers
*/
getRelayersFromDB() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return {
lastBlock: 0,
timestamp: 0,
@ -3661,7 +3661,7 @@ class BaseRegistryService extends BaseEventsService {
* Relayers from remote cache (Either from local cache, CDN, or from IPFS)
*/
getRelayersFromCache() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
return {
lastBlock: 0,
timestamp: 0,
@ -3671,7 +3671,7 @@ class BaseRegistryService extends BaseEventsService {
});
}
getSavedRelayers() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
let cachedRelayers = yield this.getRelayersFromDB();
if (!cachedRelayers || !cachedRelayers.relayers.length) {
cachedRelayers = yield this.getRelayersFromCache();
@ -3680,7 +3680,7 @@ class BaseRegistryService extends BaseEventsService {
});
}
getLatestRelayers() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
const { events, lastBlock } = yield this.updateEvents();
const subdomains = Object.values(this.relayerEnsSubdomains);
const registerSet = /* @__PURE__ */ new Set();
@ -3740,14 +3740,14 @@ class BaseRegistryService extends BaseEventsService {
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
saveRelayers(_0) {
return __async$c(this, arguments, function* ({ lastBlock, timestamp, relayers }) {
return __async$d(this, arguments, function* ({ lastBlock, timestamp, relayers }) {
});
}
/**
* Get cached or latest relayer and save to local
*/
updateRelayers() {
return __async$c(this, null, function* () {
return __async$d(this, null, function* () {
let { lastBlock, timestamp, relayers, fromCache } = yield this.getSavedRelayers();
let shouldSave = fromCache != null ? fromCache : false;
if (!relayers.length || timestamp + this.updateInterval < Math.floor(Date.now() / 1e3)) {
@ -3763,7 +3763,7 @@ class BaseRegistryService extends BaseEventsService {
}
}
var __async$b = (__this, __arguments, generator) => {
var __async$c = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -3806,7 +3806,7 @@ function unzipAsync(data) {
});
}
function downloadZip(_0) {
return __async$b(this, arguments, function* ({
return __async$c(this, arguments, function* ({
staticUrl = "",
zipName,
zipDigest,
@ -3834,7 +3834,7 @@ function downloadZip(_0) {
});
}
var __async$a = (__this, __arguments, generator) => {
var __async$b = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -3855,7 +3855,7 @@ var __async$a = (__this, __arguments, generator) => {
});
};
function saveDBEvents(_0) {
return __async$a(this, arguments, function* ({
return __async$b(this, arguments, function* ({
idb,
instanceName,
events,
@ -3880,7 +3880,7 @@ function saveDBEvents(_0) {
});
}
function loadDBEvents(_0) {
return __async$a(this, arguments, function* ({
return __async$b(this, arguments, function* ({
idb,
instanceName
}) {
@ -3910,7 +3910,7 @@ function loadDBEvents(_0) {
});
}
function loadRemoteEvents(_0) {
return __async$a(this, arguments, function* ({
return __async$b(this, arguments, function* ({
staticUrl,
instanceName,
deployedBlock,
@ -3951,7 +3951,7 @@ class DBTornadoService extends BaseTornadoService {
this.idb = params.idb;
}
getEventsFromDB() {
return __async$a(this, null, function* () {
return __async$b(this, null, function* () {
return yield loadDBEvents({
idb: this.idb,
instanceName: this.getInstanceName()
@ -3959,7 +3959,7 @@ class DBTornadoService extends BaseTornadoService {
});
}
getEventsFromCache() {
return __async$a(this, null, function* () {
return __async$b(this, null, function* () {
return yield loadRemoteEvents({
staticUrl: this.staticUrl,
instanceName: this.getInstanceName(),
@ -3969,7 +3969,7 @@ class DBTornadoService extends BaseTornadoService {
});
}
saveEvents(_0) {
return __async$a(this, arguments, function* ({ events, lastBlock }) {
return __async$b(this, arguments, function* ({ events, lastBlock }) {
yield saveDBEvents({
idb: this.idb,
instanceName: this.getInstanceName(),
@ -6317,7 +6317,7 @@ var index = /*#__PURE__*/Object.freeze({
ReverseRecords__factory: ReverseRecords__factory
});
var __async$9 = (__this, __arguments, generator) => {
var __async$a = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -6342,13 +6342,13 @@ class Pedersen {
this.pedersenPromise = this.initPedersen();
}
initPedersen() {
return __async$9(this, null, function* () {
return __async$a(this, null, function* () {
this.pedersenHash = yield buildPedersenHash();
this.babyJub = this.pedersenHash.babyJub;
});
}
unpackPoint(buffer) {
return __async$9(this, null, function* () {
return __async$a(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));
@ -6361,13 +6361,13 @@ class Pedersen {
}
const pedersen = new Pedersen();
function buffPedersenHash(buffer) {
return __async$9(this, null, function* () {
return __async$a(this, null, function* () {
const [hash] = yield pedersen.unpackPoint(buffer);
return pedersen.toStringBuffer(hash);
});
}
var __async$8 = (__this, __arguments, generator) => {
var __async$9 = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
@ -6388,7 +6388,7 @@ var __async$8 = (__this, __arguments, generator) => {
});
};
function createDeposit(_0) {
return __async$8(this, arguments, function* ({ nullifier, secret }) {
return __async$9(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));
@ -6448,7 +6448,7 @@ class Deposit {
);
}
static createNote(_0) {
return __async$8(this, arguments, function* ({ currency, amount, netId, nullifier, secret }) {
return __async$9(this, arguments, function* ({ currency, amount, netId, nullifier, secret }) {
if (!nullifier) {
nullifier = rBigInt(31);
}
@ -6475,7 +6475,7 @@ class Deposit {
});
}
static parseNote(noteString) {
return __async$8(this, null, function* () {
return __async$9(this, null, function* () {
const noteRegex = new RegExp("tornado-(?<currency>\\w+)-(?<amount>[\\d.]+)-(?<netId>\\d+)-0x(?<note>[0-9a-fA-F]{124})", "g");
const match = noteRegex.exec(noteString);
if (!match) {
@ -6660,6 +6660,26 @@ class NoteAccount {
}
}
var __async$8 = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
const DUMMY_ADDRESS = "0x1111111111111111111111111111111111111111";
const DUMMY_NONCE = 1024;
const DUMMY_WITHDRAW_DATA = "0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
@ -6668,11 +6688,41 @@ function convertETHToTokenAmount(amountInWei, tokenPriceInWei, tokenDecimals = 1
return BigInt(amountInWei) * tokenDecimalsMultiplier / BigInt(tokenPriceInWei);
}
class TornadoFeeOracle {
constructor(ovmGasPriceOracle) {
constructor(provider, ovmGasPriceOracle) {
this.provider = provider;
if (ovmGasPriceOracle) {
this.ovmGasPriceOracle = ovmGasPriceOracle;
}
}
/**
* Calculates Gas Price
* We apply 50% premium of EIP-1559 network fees instead of 100% from ethers.js
* (This should cover up to 4 full blocks which is equivalent of minute)
* (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets)
* (Still it is recommended to use 100% premium for sending transactions to prevent stucking it)
*/
gasPrice() {
return __async$8(this, null, function* () {
const [block, getGasPrice, getPriorityFee] = yield Promise.all([
this.provider.getBlock("latest"),
(() => __async$8(this, null, function* () {
try {
return BigInt(yield this.provider.send("eth_gasPrice", []));
} catch (e) {
return parseUnits("1", "gwei");
}
}))(),
(() => __async$8(this, null, function* () {
try {
return BigInt(yield this.provider.send("eth_maxPriorityFeePerGas", []));
} catch (e) {
return BigInt(0);
}
}))()
]);
return (block == null ? void 0 : block.baseFeePerGas) ? block.baseFeePerGas * BigInt(15) / BigInt(10) + getPriorityFee : getGasPrice;
});
}
/**
* Calculate L1 fee for op-stack chains
*

52
dist/tornado.umd.js vendored

@ -60130,6 +60130,26 @@ __webpack_require__.r(__webpack_exports__);
/* harmony import */ var ethers__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(99770);
/* harmony import */ var ethers__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(79453);
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
const DUMMY_ADDRESS = "0x1111111111111111111111111111111111111111";
const DUMMY_NONCE = 1024;
@ -60139,11 +60159,41 @@ function convertETHToTokenAmount(amountInWei, tokenPriceInWei, tokenDecimals = 1
return BigInt(amountInWei) * tokenDecimalsMultiplier / BigInt(tokenPriceInWei);
}
class TornadoFeeOracle {
constructor(ovmGasPriceOracle) {
constructor(provider, ovmGasPriceOracle) {
this.provider = provider;
if (ovmGasPriceOracle) {
this.ovmGasPriceOracle = ovmGasPriceOracle;
}
}
/**
* Calculates Gas Price
* We apply 50% premium of EIP-1559 network fees instead of 100% from ethers.js
* (This should cover up to 4 full blocks which is equivalent of minute)
* (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets)
* (Still it is recommended to use 100% premium for sending transactions to prevent stucking it)
*/
gasPrice() {
return __async(this, null, function* () {
const [block, getGasPrice, getPriorityFee] = yield Promise.all([
this.provider.getBlock("latest"),
(() => __async(this, null, function* () {
try {
return BigInt(yield this.provider.send("eth_gasPrice", []));
} catch (e) {
return (0,ethers__WEBPACK_IMPORTED_MODULE_0__/* .parseUnits */ .XS)("1", "gwei");
}
}))(),
(() => __async(this, null, function* () {
try {
return BigInt(yield this.provider.send("eth_maxPriorityFeePerGas", []));
} catch (e) {
return BigInt(0);
}
}))()
]);
return (block == null ? void 0 : block.baseFeePerGas) ? block.baseFeePerGas * BigInt(15) / BigInt(10) + getPriorityFee : getGasPrice;
});
}
/**
* Calculate L1 fee for op-stack chains
*

File diff suppressed because one or more lines are too long

@ -1,5 +1,5 @@
import { Transaction, parseUnits } from 'ethers';
import type { BigNumberish, TransactionLike } from 'ethers';
import type { BigNumberish, JsonRpcApiProvider, TransactionLike } from 'ethers';
import { OvmGasPriceOracle } from './typechain';
const DUMMY_ADDRESS = '0x1111111111111111111111111111111111111111';
@ -37,14 +37,46 @@ export interface RelayerFeeParams {
}
export class TornadoFeeOracle {
provider: JsonRpcApiProvider;
ovmGasPriceOracle?: OvmGasPriceOracle;
constructor(ovmGasPriceOracle?: OvmGasPriceOracle) {
constructor(provider: JsonRpcApiProvider, ovmGasPriceOracle?: OvmGasPriceOracle) {
this.provider = provider;
if (ovmGasPriceOracle) {
this.ovmGasPriceOracle = ovmGasPriceOracle;
}
}
/**
* Calculates Gas Price
* We apply 50% premium of EIP-1559 network fees instead of 100% from ethers.js
* (This should cover up to 4 full blocks which is equivalent of minute)
* (A single block can bump 12.5% of fees, see the methodology https://hackmd.io/@tvanepps/1559-wallets)
* (Still it is recommended to use 100% premium for sending transactions to prevent stucking it)
*/
async gasPrice() {
const [block, getGasPrice, getPriorityFee] = await Promise.all([
this.provider.getBlock('latest'),
(async () => {
try {
return BigInt(await this.provider.send('eth_gasPrice', []));
} catch {
return parseUnits('1', 'gwei');
}
})(),
(async () => {
try {
return BigInt(await this.provider.send('eth_maxPriorityFeePerGas', []));
} catch {
return BigInt(0);
}
})(),
]);
return block?.baseFeePerGas ? (block.baseFeePerGas * BigInt(15)) / BigInt(10) + getPriorityFee : getGasPrice;
}
/**
* Calculate L1 fee for op-stack chains
*