tornado-core 1.0.16

* simplify populateTransaction func
* fixed relayerClient type defs
This commit is contained in:
Tornado Contrib 2024-09-28 02:42:27 +00:00
parent 82aeabd739
commit df1fcebfe3
Signed by: tornadocontrib
GPG Key ID: 60B4DF1A076C64B1
8 changed files with 153 additions and 262 deletions

89
dist/index.js vendored

@ -371,6 +371,7 @@ function getProviderWithNetId(netId, rpcUrl, config, fetchOptions) {
return provider; return provider;
} }
const populateTransaction = (signer, tx) => __async$c(void 0, null, function* () { const populateTransaction = (signer, tx) => __async$c(void 0, null, function* () {
var _a;
const provider = signer.provider; const provider = signer.provider;
if (!tx.from) { if (!tx.from) {
tx.from = signer.address; tx.from = signer.address;
@ -379,70 +380,42 @@ const populateTransaction = (signer, tx) => __async$c(void 0, null, function* ()
throw new Error(errMsg); throw new Error(errMsg);
} }
const [feeData, nonce] = yield Promise.all([ const [feeData, nonce] = yield Promise.all([
(() => __async$c(void 0, null, function* () { tx.maxFeePerGas || tx.gasPrice ? void 0 : provider.getFeeData(),
if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) { (_a = tx.nonce) != null ? _a : provider.getTransactionCount(signer.address, "pending")
return new ethers.FeeData(null, BigInt(tx.maxFeePerGas), BigInt(tx.maxPriorityFeePerGas));
}
if (tx.gasPrice) {
return new ethers.FeeData(BigInt(tx.gasPrice), null, null);
}
const fetchedFeeData = yield provider.getFeeData();
if (fetchedFeeData.maxFeePerGas && fetchedFeeData.maxPriorityFeePerGas) {
return new ethers.FeeData(
null,
fetchedFeeData.maxFeePerGas * (BigInt(1e4) + BigInt(signer.gasPriceBump)) / BigInt(1e4),
fetchedFeeData.maxPriorityFeePerGas
);
} else {
return new ethers.FeeData(
fetchedFeeData.gasPrice * (BigInt(1e4) + BigInt(signer.gasPriceBump)) / BigInt(1e4),
null,
null
);
}
}))(),
(() => __async$c(void 0, null, function* () {
if (tx.nonce) {
return tx.nonce;
}
let fetchedNonce = yield provider.getTransactionCount(signer.address, "pending");
if (signer.bumpNonce && signer.nonce && signer.nonce >= fetchedNonce) {
console.log(
`populateTransaction: bumping nonce from ${fetchedNonce} to ${fetchedNonce + 1} for ${signer.address}`
);
fetchedNonce++;
}
return fetchedNonce;
}))()
]); ]);
tx.nonce = nonce; if (feeData) {
if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) { if (feeData.maxFeePerGas) {
tx.maxFeePerGas = feeData.maxFeePerGas; if (!tx.type) {
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas; tx.type = 2;
if (!tx.type) { }
tx.type = 2; tx.maxFeePerGas = feeData.maxFeePerGas * (BigInt(1e4) + BigInt(signer.gasPriceBump)) / BigInt(1e4);
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
delete tx.gasPrice;
} else if (feeData.gasPrice) {
if (!tx.type) {
tx.type = 0;
}
tx.gasPrice = feeData.gasPrice;
delete tx.maxFeePerGas;
delete tx.maxPriorityFeePerGas;
} }
delete tx.gasPrice;
} else if (feeData.gasPrice) {
tx.gasPrice = feeData.gasPrice;
if (!tx.type) {
tx.type = 0;
}
delete tx.maxFeePerGas;
delete tx.maxPriorityFeePerGas;
} }
tx.gasLimit = tx.gasLimit || (yield (() => __async$c(void 0, null, function* () { if (nonce) {
tx.nonce = nonce;
}
if (!tx.gasLimit) {
try { try {
const gasLimit = yield provider.estimateGas(tx); const gasLimit = yield provider.estimateGas(tx);
return gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4); tx.gasLimit = gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4);
} catch (err) { } catch (error) {
if (signer.gasFailover) { if (signer.gasFailover) {
console.log("populateTransaction: warning gas estimation failed falling back to 3M gas"); console.log("populateTransaction: warning gas estimation failed falling back to 3M gas");
return BigInt("3000000"); tx.gasLimit = BigInt("3000000");
} else {
throw error;
} }
throw err;
} }
}))()); }
return tx; return tx;
}); });
class TornadoWallet extends ethers.Wallet { class TornadoWallet extends ethers.Wallet {
@ -2615,10 +2588,12 @@ class RelayerClient {
relayerAddress relayerAddress
}) { }) {
var _a, _b; var _a, _b;
if (!url) { if (!url && hostname) {
url = `https://${!hostname.endsWith("/") ? hostname + "/" : hostname}`; url = `https://${!hostname.endsWith("/") ? hostname + "/" : hostname}`;
} else if (!url.endsWith("/")) { } else if (url && !url.endsWith("/")) {
url += "/"; url += "/";
} else {
url = "";
} }
const rawStatus = yield fetchData(`${url}status`, __spreadProps$1(__spreadValues$1({}, this.fetchDataOptions), { const rawStatus = yield fetchData(`${url}status`, __spreadProps$1(__spreadValues$1({}, this.fetchDataOptions), {
headers: { headers: {

91
dist/index.mjs vendored

@ -1,4 +1,4 @@
import { FetchRequest, Network, EnsPlugin, GasCostPlugin, JsonRpcProvider, Wallet, HDNodeWallet, VoidSigner, JsonRpcSigner, BrowserProvider, FeeData, getAddress, parseEther, namehash, formatEther, Interface, Contract, computeAddress, parseUnits, Transaction, ZeroAddress } from 'ethers'; import { FetchRequest, Network, EnsPlugin, GasCostPlugin, JsonRpcProvider, Wallet, HDNodeWallet, VoidSigner, JsonRpcSigner, BrowserProvider, getAddress, parseEther, namehash, formatEther, Interface, Contract, computeAddress, parseUnits, Transaction, ZeroAddress } from 'ethers';
import crossFetch from 'cross-fetch'; import crossFetch from 'cross-fetch';
import { webcrypto } from 'crypto'; import { webcrypto } from 'crypto';
import BN from 'bn.js'; import BN from 'bn.js';
@ -350,6 +350,7 @@ function getProviderWithNetId(netId, rpcUrl, config, fetchOptions) {
return provider; return provider;
} }
const populateTransaction = (signer, tx) => __async$c(void 0, null, function* () { const populateTransaction = (signer, tx) => __async$c(void 0, null, function* () {
var _a;
const provider = signer.provider; const provider = signer.provider;
if (!tx.from) { if (!tx.from) {
tx.from = signer.address; tx.from = signer.address;
@ -358,70 +359,42 @@ const populateTransaction = (signer, tx) => __async$c(void 0, null, function* ()
throw new Error(errMsg); throw new Error(errMsg);
} }
const [feeData, nonce] = yield Promise.all([ const [feeData, nonce] = yield Promise.all([
(() => __async$c(void 0, null, function* () { tx.maxFeePerGas || tx.gasPrice ? void 0 : provider.getFeeData(),
if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) { (_a = tx.nonce) != null ? _a : provider.getTransactionCount(signer.address, "pending")
return new FeeData(null, BigInt(tx.maxFeePerGas), BigInt(tx.maxPriorityFeePerGas));
}
if (tx.gasPrice) {
return new FeeData(BigInt(tx.gasPrice), null, null);
}
const fetchedFeeData = yield provider.getFeeData();
if (fetchedFeeData.maxFeePerGas && fetchedFeeData.maxPriorityFeePerGas) {
return new FeeData(
null,
fetchedFeeData.maxFeePerGas * (BigInt(1e4) + BigInt(signer.gasPriceBump)) / BigInt(1e4),
fetchedFeeData.maxPriorityFeePerGas
);
} else {
return new FeeData(
fetchedFeeData.gasPrice * (BigInt(1e4) + BigInt(signer.gasPriceBump)) / BigInt(1e4),
null,
null
);
}
}))(),
(() => __async$c(void 0, null, function* () {
if (tx.nonce) {
return tx.nonce;
}
let fetchedNonce = yield provider.getTransactionCount(signer.address, "pending");
if (signer.bumpNonce && signer.nonce && signer.nonce >= fetchedNonce) {
console.log(
`populateTransaction: bumping nonce from ${fetchedNonce} to ${fetchedNonce + 1} for ${signer.address}`
);
fetchedNonce++;
}
return fetchedNonce;
}))()
]); ]);
tx.nonce = nonce; if (feeData) {
if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) { if (feeData.maxFeePerGas) {
tx.maxFeePerGas = feeData.maxFeePerGas; if (!tx.type) {
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas; tx.type = 2;
if (!tx.type) { }
tx.type = 2; tx.maxFeePerGas = feeData.maxFeePerGas * (BigInt(1e4) + BigInt(signer.gasPriceBump)) / BigInt(1e4);
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
delete tx.gasPrice;
} else if (feeData.gasPrice) {
if (!tx.type) {
tx.type = 0;
}
tx.gasPrice = feeData.gasPrice;
delete tx.maxFeePerGas;
delete tx.maxPriorityFeePerGas;
} }
delete tx.gasPrice;
} else if (feeData.gasPrice) {
tx.gasPrice = feeData.gasPrice;
if (!tx.type) {
tx.type = 0;
}
delete tx.maxFeePerGas;
delete tx.maxPriorityFeePerGas;
} }
tx.gasLimit = tx.gasLimit || (yield (() => __async$c(void 0, null, function* () { if (nonce) {
tx.nonce = nonce;
}
if (!tx.gasLimit) {
try { try {
const gasLimit = yield provider.estimateGas(tx); const gasLimit = yield provider.estimateGas(tx);
return gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4); tx.gasLimit = gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4);
} catch (err) { } catch (error) {
if (signer.gasFailover) { if (signer.gasFailover) {
console.log("populateTransaction: warning gas estimation failed falling back to 3M gas"); console.log("populateTransaction: warning gas estimation failed falling back to 3M gas");
return BigInt("3000000"); tx.gasLimit = BigInt("3000000");
} else {
throw error;
} }
throw err;
} }
}))()); }
return tx; return tx;
}); });
class TornadoWallet extends Wallet { class TornadoWallet extends Wallet {
@ -2594,10 +2567,12 @@ class RelayerClient {
relayerAddress relayerAddress
}) { }) {
var _a, _b; var _a, _b;
if (!url) { if (!url && hostname) {
url = `https://${!hostname.endsWith("/") ? hostname + "/" : hostname}`; url = `https://${!hostname.endsWith("/") ? hostname + "/" : hostname}`;
} else if (!url.endsWith("/")) { } else if (url && !url.endsWith("/")) {
url += "/"; url += "/";
} else {
url = "";
} }
const rawStatus = yield fetchData(`${url}status`, __spreadProps$1(__spreadValues$1({}, this.fetchDataOptions), { const rawStatus = yield fetchData(`${url}status`, __spreadProps$1(__spreadValues$1({}, this.fetchDataOptions), {
headers: { headers: {

@ -132,7 +132,7 @@ export declare class RelayerClient {
fetchDataOptions?: fetchDataOptions; fetchDataOptions?: fetchDataOptions;
constructor({ netId, config, fetchDataOptions }: RelayerClientConstructor); constructor({ netId, config, fetchDataOptions }: RelayerClientConstructor);
askRelayerStatus({ hostname, url, relayerAddress, }: { askRelayerStatus({ hostname, url, relayerAddress, }: {
hostname: string; hostname?: string;
url?: string; url?: string;
relayerAddress?: string; relayerAddress?: string;
}): Promise<RelayerStatus>; }): Promise<RelayerStatus>;

111
dist/tornado.umd.js vendored

@ -65048,7 +65048,7 @@ function injectCommonNetworks() {
} }
//# sourceMappingURL=network.js.map //# sourceMappingURL=network.js.map
// EXTERNAL MODULE: ./node_modules/ethers/lib.esm/providers/provider.js // EXTERNAL MODULE: ./node_modules/ethers/lib.esm/providers/provider.js
var providers_provider = __webpack_require__(43948); var provider = __webpack_require__(43948);
;// CONCATENATED MODULE: ./node_modules/ethers/lib.esm/providers/subscriber-polling.js ;// CONCATENATED MODULE: ./node_modules/ethers/lib.esm/providers/subscriber-polling.js
function copy(obj) { function copy(obj) {
@ -65663,7 +65663,7 @@ class AbstractProvider {
* sub-class of [[Block]]. * sub-class of [[Block]].
*/ */
_wrapBlock(value, network) { _wrapBlock(value, network) {
return new providers_provider/* Block */.eB(formatBlock(value), this); return new provider/* Block */.eB(formatBlock(value), this);
} }
/** /**
* Provides the opportunity for a sub-class to wrap a log before * Provides the opportunity for a sub-class to wrap a log before
@ -65671,7 +65671,7 @@ class AbstractProvider {
* sub-class of [[Log]]. * sub-class of [[Log]].
*/ */
_wrapLog(value, network) { _wrapLog(value, network) {
return new providers_provider/* Log */.tG(formatLog(value), this); return new provider/* Log */.tG(formatLog(value), this);
} }
/** /**
* Provides the opportunity for a sub-class to wrap a transaction * Provides the opportunity for a sub-class to wrap a transaction
@ -65679,7 +65679,7 @@ class AbstractProvider {
* alternate sub-class of [[TransactionReceipt]]. * alternate sub-class of [[TransactionReceipt]].
*/ */
_wrapTransactionReceipt(value, network) { _wrapTransactionReceipt(value, network) {
return new providers_provider/* TransactionReceipt */.z5(formatTransactionReceipt(value), this); return new provider/* TransactionReceipt */.z5(formatTransactionReceipt(value), this);
} }
/** /**
* Provides the opportunity for a sub-class to wrap a transaction * Provides the opportunity for a sub-class to wrap a transaction
@ -65687,7 +65687,7 @@ class AbstractProvider {
* alternate sub-class of [[TransactionResponse]]. * alternate sub-class of [[TransactionResponse]].
*/ */
_wrapTransactionResponse(tx, network) { _wrapTransactionResponse(tx, network) {
return new providers_provider/* TransactionResponse */.uI(formatTransactionResponse(tx), this); return new provider/* TransactionResponse */.uI(formatTransactionResponse(tx), this);
} }
/** /**
* Resolves to the Network, forcing a network detection using whatever * Resolves to the Network, forcing a network detection using whatever
@ -65851,7 +65851,7 @@ class AbstractProvider {
* transaction. * transaction.
*/ */
_getTransactionRequest(_request) { _getTransactionRequest(_request) {
const request = (0,providers_provider/* copyRequest */.VS)(_request); const request = (0,provider/* copyRequest */.VS)(_request);
const promises = []; const promises = [];
["to", "from"].forEach((key) => { ["to", "from"].forEach((key) => {
if (request[key] == null) { if (request[key] == null) {
@ -65955,14 +65955,14 @@ class AbstractProvider {
maxPriorityFeePerGas = (priorityFee != null) ? priorityFee : BigInt("1000000000"); maxPriorityFeePerGas = (priorityFee != null) ? priorityFee : BigInt("1000000000");
maxFeePerGas = (block.baseFeePerGas * BN_2) + maxPriorityFeePerGas; maxFeePerGas = (block.baseFeePerGas * BN_2) + maxPriorityFeePerGas;
} }
return new providers_provider/* FeeData */.J9(gasPrice, maxFeePerGas, maxPriorityFeePerGas); return new provider/* FeeData */.J9(gasPrice, maxFeePerGas, maxPriorityFeePerGas);
}; };
// Check for a FeeDataNetWorkPlugin // Check for a FeeDataNetWorkPlugin
const plugin = network.getPlugin("org.ethers.plugins.network.FetchUrlFeeDataPlugin"); const plugin = network.getPlugin("org.ethers.plugins.network.FetchUrlFeeDataPlugin");
if (plugin) { if (plugin) {
const req = new FetchRequest(plugin.url); const req = new FetchRequest(plugin.url);
const feeData = await plugin.processFunc(getFeeDataFunc, this, req); const feeData = await plugin.processFunc(getFeeDataFunc, this, req);
return new providers_provider/* FeeData */.J9(feeData.gasPrice, feeData.maxFeePerGas, feeData.maxPriorityFeePerGas); return new provider/* FeeData */.J9(feeData.gasPrice, feeData.maxFeePerGas, feeData.maxPriorityFeePerGas);
} }
return await getFeeDataFunc(); return await getFeeDataFunc();
} }
@ -65981,7 +65981,7 @@ class AbstractProvider {
transaction: Object.assign({}, tx, { blockTag, enableCcipRead: true }) transaction: Object.assign({}, tx, { blockTag, enableCcipRead: true })
}); });
// This came in as a PerformActionTransaction, so to/from are safe; we can cast // This came in as a PerformActionTransaction, so to/from are safe; we can cast
const transaction = (0,providers_provider/* copyRequest */.VS)(tx); const transaction = (0,provider/* copyRequest */.VS)(tx);
try { try {
return (0,utils_data/* hexlify */.c$)(await this._perform({ method: "call", transaction, blockTag })); return (0,utils_data/* hexlify */.c$)(await this._perform({ method: "call", transaction, blockTag }));
} }
@ -66756,7 +66756,7 @@ function checkProvider(signer, operation) {
(0,errors/* assert */.vA)(false, "missing provider", "UNSUPPORTED_OPERATION", { operation }); (0,errors/* assert */.vA)(false, "missing provider", "UNSUPPORTED_OPERATION", { operation });
} }
async function populate(signer, tx) { async function populate(signer, tx) {
let pop = (0,providers_provider/* copyRequest */.VS)(tx); let pop = (0,provider/* copyRequest */.VS)(tx);
if (pop.to != null) { if (pop.to != null) {
pop.to = (0,checks/* resolveAddress */.tG)(pop.to, signer); pop.to = (0,checks/* resolveAddress */.tG)(pop.to, signer);
} }
@ -68214,7 +68214,7 @@ class BaseWallet extends AbstractSigner {
return new BaseWallet(this.#signingKey, provider); return new BaseWallet(this.#signingKey, provider);
} }
async signTransaction(tx) { async signTransaction(tx) {
tx = (0,providers_provider/* copyRequest */.VS)(tx); tx = (0,provider/* copyRequest */.VS)(tx);
// Replace any Addressable or ENS name with an address // Replace any Addressable or ENS name with an address
const { to, from } = await (0,properties/* resolveProperties */.k)({ const { to, from } = await (0,properties/* resolveProperties */.k)({
to: (tx.to ? (0,checks/* resolveAddress */.tG)(tx.to, this.provider) : undefined), to: (tx.to ? (0,checks/* resolveAddress */.tG)(tx.to, this.provider) : undefined),
@ -71300,6 +71300,7 @@ function getProviderWithNetId(netId, rpcUrl, config, fetchOptions) {
return provider; return provider;
} }
const populateTransaction = (signer, tx) => __async(void 0, null, function* () { const populateTransaction = (signer, tx) => __async(void 0, null, function* () {
var _a;
const provider = signer.provider; const provider = signer.provider;
if (!tx.from) { if (!tx.from) {
tx.from = signer.address; tx.from = signer.address;
@ -71308,70 +71309,42 @@ const populateTransaction = (signer, tx) => __async(void 0, null, function* () {
throw new Error(errMsg); throw new Error(errMsg);
} }
const [feeData, nonce] = yield Promise.all([ const [feeData, nonce] = yield Promise.all([
(() => __async(void 0, null, function* () { tx.maxFeePerGas || tx.gasPrice ? void 0 : provider.getFeeData(),
if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) { (_a = tx.nonce) != null ? _a : provider.getTransactionCount(signer.address, "pending")
return new providers_provider/* FeeData */.J9(null, BigInt(tx.maxFeePerGas), BigInt(tx.maxPriorityFeePerGas));
}
if (tx.gasPrice) {
return new providers_provider/* FeeData */.J9(BigInt(tx.gasPrice), null, null);
}
const fetchedFeeData = yield provider.getFeeData();
if (fetchedFeeData.maxFeePerGas && fetchedFeeData.maxPriorityFeePerGas) {
return new providers_provider/* FeeData */.J9(
null,
fetchedFeeData.maxFeePerGas * (BigInt(1e4) + BigInt(signer.gasPriceBump)) / BigInt(1e4),
fetchedFeeData.maxPriorityFeePerGas
);
} else {
return new providers_provider/* FeeData */.J9(
fetchedFeeData.gasPrice * (BigInt(1e4) + BigInt(signer.gasPriceBump)) / BigInt(1e4),
null,
null
);
}
}))(),
(() => __async(void 0, null, function* () {
if (tx.nonce) {
return tx.nonce;
}
let fetchedNonce = yield provider.getTransactionCount(signer.address, "pending");
if (signer.bumpNonce && signer.nonce && signer.nonce >= fetchedNonce) {
console.log(
`populateTransaction: bumping nonce from ${fetchedNonce} to ${fetchedNonce + 1} for ${signer.address}`
);
fetchedNonce++;
}
return fetchedNonce;
}))()
]); ]);
tx.nonce = nonce; if (feeData) {
if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) { if (feeData.maxFeePerGas) {
tx.maxFeePerGas = feeData.maxFeePerGas; if (!tx.type) {
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas; tx.type = 2;
if (!tx.type) { }
tx.type = 2; tx.maxFeePerGas = feeData.maxFeePerGas * (BigInt(1e4) + BigInt(signer.gasPriceBump)) / BigInt(1e4);
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
delete tx.gasPrice;
} else if (feeData.gasPrice) {
if (!tx.type) {
tx.type = 0;
}
tx.gasPrice = feeData.gasPrice;
delete tx.maxFeePerGas;
delete tx.maxPriorityFeePerGas;
} }
delete tx.gasPrice;
} else if (feeData.gasPrice) {
tx.gasPrice = feeData.gasPrice;
if (!tx.type) {
tx.type = 0;
}
delete tx.maxFeePerGas;
delete tx.maxPriorityFeePerGas;
} }
tx.gasLimit = tx.gasLimit || (yield (() => __async(void 0, null, function* () { if (nonce) {
tx.nonce = nonce;
}
if (!tx.gasLimit) {
try { try {
const gasLimit = yield provider.estimateGas(tx); const gasLimit = yield provider.estimateGas(tx);
return gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4); tx.gasLimit = gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4);
} catch (err) { } catch (error) {
if (signer.gasFailover) { if (signer.gasFailover) {
console.log("populateTransaction: warning gas estimation failed falling back to 3M gas"); console.log("populateTransaction: warning gas estimation failed falling back to 3M gas");
return BigInt("3000000"); tx.gasLimit = BigInt("3000000");
} else {
throw error;
} }
throw err;
} }
}))()); }
return tx; return tx;
}); });
class TornadoWallet extends Wallet { class TornadoWallet extends Wallet {
@ -71570,10 +71543,12 @@ class RelayerClient {
relayerAddress relayerAddress
}) { }) {
var _a, _b; var _a, _b;
if (!url) { if (!url && hostname) {
url = `https://${!hostname.endsWith("/") ? hostname + "/" : hostname}`; url = `https://${!hostname.endsWith("/") ? hostname + "/" : hostname}`;
} else if (!url.endsWith("/")) { } else if (url && !url.endsWith("/")) {
url += "/"; url += "/";
} else {
url = "";
} }
const rawStatus = yield (0,_providers__WEBPACK_IMPORTED_MODULE_2__/* .fetchData */ .Fd)(`${url}status`, __spreadProps(__spreadValues({}, this.fetchDataOptions), { const rawStatus = yield (0,_providers__WEBPACK_IMPORTED_MODULE_2__/* .fetchData */ .Fd)(`${url}status`, __spreadProps(__spreadValues({}, this.fetchDataOptions), {
headers: { headers: {

File diff suppressed because one or more lines are too long

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

@ -17,7 +17,6 @@ import {
Eip1193Provider, Eip1193Provider,
VoidSigner, VoidSigner,
Network, Network,
FeeData,
EnsPlugin, EnsPlugin,
GasCostPlugin, GasCostPlugin,
} from 'ethers'; } from 'ethers';
@ -322,87 +321,52 @@ export const populateTransaction = async (
} }
const [feeData, nonce] = await Promise.all([ const [feeData, nonce] = await Promise.all([
(async () => { tx.maxFeePerGas || tx.gasPrice ? undefined : provider.getFeeData(),
if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) { tx.nonce ?? provider.getTransactionCount(signer.address, 'pending'),
return new FeeData(null, BigInt(tx.maxFeePerGas), BigInt(tx.maxPriorityFeePerGas));
}
if (tx.gasPrice) {
return new FeeData(BigInt(tx.gasPrice), null, null);
}
const fetchedFeeData = await provider.getFeeData();
if (fetchedFeeData.maxFeePerGas && fetchedFeeData.maxPriorityFeePerGas) {
return new FeeData(
null,
(fetchedFeeData.maxFeePerGas * (BigInt(10000) + BigInt(signer.gasPriceBump))) / BigInt(10000),
fetchedFeeData.maxPriorityFeePerGas,
);
} else {
return new FeeData(
((fetchedFeeData.gasPrice as bigint) * (BigInt(10000) + BigInt(signer.gasPriceBump))) / BigInt(10000),
null,
null,
);
}
})(),
(async () => {
if (tx.nonce) {
return tx.nonce;
}
let fetchedNonce = await provider.getTransactionCount(signer.address, 'pending');
// Deal with cached nonce results
if (signer.bumpNonce && signer.nonce && signer.nonce >= fetchedNonce) {
console.log(
`populateTransaction: bumping nonce from ${fetchedNonce} to ${fetchedNonce + 1} for ${signer.address}`,
);
fetchedNonce++;
}
return fetchedNonce;
})(),
]); ]);
tx.nonce = nonce; if (feeData) {
// EIP-1559
if (feeData.maxFeePerGas) {
if (!tx.type) {
tx.type = 2;
}
// EIP-1559 tx.maxFeePerGas = (feeData.maxFeePerGas * (BigInt(10000) + BigInt(signer.gasPriceBump))) / BigInt(10000);
if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) { tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
tx.maxFeePerGas = feeData.maxFeePerGas; delete tx.gasPrice;
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas; } else if (feeData.gasPrice) {
if (!tx.type) { if (!tx.type) {
tx.type = 2; tx.type = 0;
}
tx.gasPrice = feeData.gasPrice;
delete tx.maxFeePerGas;
delete tx.maxPriorityFeePerGas;
} }
delete tx.gasPrice;
} else if (feeData.gasPrice) {
tx.gasPrice = feeData.gasPrice;
if (!tx.type) {
tx.type = 0;
}
delete tx.maxFeePerGas;
delete tx.maxPriorityFeePerGas;
} }
// gasLimit if (nonce) {
tx.gasLimit = tx.nonce = nonce;
tx.gasLimit || }
(await (async () => {
try { if (!tx.gasLimit) {
const gasLimit = await provider.estimateGas(tx); try {
return gasLimit === BigInt(21000) const gasLimit = await provider.estimateGas(tx);
tx.gasLimit =
gasLimit === BigInt(21000)
? gasLimit ? gasLimit
: (gasLimit * (BigInt(10000) + BigInt(signer.gasLimitBump))) / BigInt(10000); : (gasLimit * (BigInt(10000) + BigInt(signer.gasLimitBump))) / BigInt(10000);
} catch (err) { } catch (error) {
if (signer.gasFailover) { if (signer.gasFailover) {
console.log('populateTransaction: warning gas estimation failed falling back to 3M gas'); console.log('populateTransaction: warning gas estimation failed falling back to 3M gas');
// Gas failover // Gas failover
return BigInt('3000000'); tx.gasLimit = BigInt('3000000');
} } else {
throw err; throw error;
} }
})()); }
}
return tx; return tx;
}; };

@ -202,16 +202,18 @@ export class RelayerClient {
url, url,
relayerAddress, relayerAddress,
}: { }: {
hostname: string; hostname?: string;
// optional url if entered manually // optional url if entered manually
url?: string; url?: string;
// relayerAddress from registry contract to prevent cheating // relayerAddress from registry contract to prevent cheating
relayerAddress?: string; relayerAddress?: string;
}): Promise<RelayerStatus> { }): Promise<RelayerStatus> {
if (!url) { if (!url && hostname) {
url = `https://${!hostname.endsWith('/') ? hostname + '/' : hostname}`; url = `https://${!hostname.endsWith('/') ? hostname + '/' : hostname}`;
} else if (!url.endsWith('/')) { } else if (url && !url.endsWith('/')) {
url += '/'; url += '/';
} else {
url = '';
} }
const rawStatus = (await fetchData(`${url}status`, { const rawStatus = (await fetchData(`${url}status`, {