forked from tornado-packages/tornado-core
tornado-core 1.0.16
* simplify populateTransaction func * fixed relayerClient type defs
This commit is contained in:
parent
82aeabd739
commit
df1fcebfe3
89
dist/index.js
vendored
89
dist/index.js
vendored
@ -371,6 +371,7 @@ function getProviderWithNetId(netId, rpcUrl, config, fetchOptions) {
|
||||
return provider;
|
||||
}
|
||||
const populateTransaction = (signer, tx) => __async$c(void 0, null, function* () {
|
||||
var _a;
|
||||
const provider = signer.provider;
|
||||
if (!tx.from) {
|
||||
tx.from = signer.address;
|
||||
@ -379,70 +380,42 @@ const populateTransaction = (signer, tx) => __async$c(void 0, null, function* ()
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
const [feeData, nonce] = yield Promise.all([
|
||||
(() => __async$c(void 0, null, function* () {
|
||||
if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) {
|
||||
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.maxFeePerGas || tx.gasPrice ? void 0 : provider.getFeeData(),
|
||||
(_a = tx.nonce) != null ? _a : provider.getTransactionCount(signer.address, "pending")
|
||||
]);
|
||||
tx.nonce = nonce;
|
||||
if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) {
|
||||
tx.maxFeePerGas = feeData.maxFeePerGas;
|
||||
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
||||
if (!tx.type) {
|
||||
tx.type = 2;
|
||||
if (feeData) {
|
||||
if (feeData.maxFeePerGas) {
|
||||
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 {
|
||||
const gasLimit = yield provider.estimateGas(tx);
|
||||
return gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4);
|
||||
} catch (err) {
|
||||
tx.gasLimit = gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4);
|
||||
} catch (error) {
|
||||
if (signer.gasFailover) {
|
||||
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;
|
||||
});
|
||||
class TornadoWallet extends ethers.Wallet {
|
||||
@ -2615,10 +2588,12 @@ class RelayerClient {
|
||||
relayerAddress
|
||||
}) {
|
||||
var _a, _b;
|
||||
if (!url) {
|
||||
if (!url && hostname) {
|
||||
url = `https://${!hostname.endsWith("/") ? hostname + "/" : hostname}`;
|
||||
} else if (!url.endsWith("/")) {
|
||||
} else if (url && !url.endsWith("/")) {
|
||||
url += "/";
|
||||
} else {
|
||||
url = "";
|
||||
}
|
||||
const rawStatus = yield fetchData(`${url}status`, __spreadProps$1(__spreadValues$1({}, this.fetchDataOptions), {
|
||||
headers: {
|
||||
|
91
dist/index.mjs
vendored
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 { webcrypto } from 'crypto';
|
||||
import BN from 'bn.js';
|
||||
@ -350,6 +350,7 @@ function getProviderWithNetId(netId, rpcUrl, config, fetchOptions) {
|
||||
return provider;
|
||||
}
|
||||
const populateTransaction = (signer, tx) => __async$c(void 0, null, function* () {
|
||||
var _a;
|
||||
const provider = signer.provider;
|
||||
if (!tx.from) {
|
||||
tx.from = signer.address;
|
||||
@ -358,70 +359,42 @@ const populateTransaction = (signer, tx) => __async$c(void 0, null, function* ()
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
const [feeData, nonce] = yield Promise.all([
|
||||
(() => __async$c(void 0, null, function* () {
|
||||
if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) {
|
||||
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.maxFeePerGas || tx.gasPrice ? void 0 : provider.getFeeData(),
|
||||
(_a = tx.nonce) != null ? _a : provider.getTransactionCount(signer.address, "pending")
|
||||
]);
|
||||
tx.nonce = nonce;
|
||||
if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) {
|
||||
tx.maxFeePerGas = feeData.maxFeePerGas;
|
||||
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
||||
if (!tx.type) {
|
||||
tx.type = 2;
|
||||
if (feeData) {
|
||||
if (feeData.maxFeePerGas) {
|
||||
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 {
|
||||
const gasLimit = yield provider.estimateGas(tx);
|
||||
return gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4);
|
||||
} catch (err) {
|
||||
tx.gasLimit = gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4);
|
||||
} catch (error) {
|
||||
if (signer.gasFailover) {
|
||||
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;
|
||||
});
|
||||
class TornadoWallet extends Wallet {
|
||||
@ -2594,10 +2567,12 @@ class RelayerClient {
|
||||
relayerAddress
|
||||
}) {
|
||||
var _a, _b;
|
||||
if (!url) {
|
||||
if (!url && hostname) {
|
||||
url = `https://${!hostname.endsWith("/") ? hostname + "/" : hostname}`;
|
||||
} else if (!url.endsWith("/")) {
|
||||
} else if (url && !url.endsWith("/")) {
|
||||
url += "/";
|
||||
} else {
|
||||
url = "";
|
||||
}
|
||||
const rawStatus = yield fetchData(`${url}status`, __spreadProps$1(__spreadValues$1({}, this.fetchDataOptions), {
|
||||
headers: {
|
||||
|
2
dist/relayerClient.d.ts
vendored
2
dist/relayerClient.d.ts
vendored
@ -132,7 +132,7 @@ export declare class RelayerClient {
|
||||
fetchDataOptions?: fetchDataOptions;
|
||||
constructor({ netId, config, fetchDataOptions }: RelayerClientConstructor);
|
||||
askRelayerStatus({ hostname, url, relayerAddress, }: {
|
||||
hostname: string;
|
||||
hostname?: string;
|
||||
url?: string;
|
||||
relayerAddress?: string;
|
||||
}): Promise<RelayerStatus>;
|
||||
|
111
dist/tornado.umd.js
vendored
111
dist/tornado.umd.js
vendored
@ -65048,7 +65048,7 @@ function injectCommonNetworks() {
|
||||
}
|
||||
//# sourceMappingURL=network.js.map
|
||||
// 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
|
||||
|
||||
function copy(obj) {
|
||||
@ -65663,7 +65663,7 @@ class AbstractProvider {
|
||||
* sub-class of [[Block]].
|
||||
*/
|
||||
_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
|
||||
@ -65671,7 +65671,7 @@ class AbstractProvider {
|
||||
* sub-class of [[Log]].
|
||||
*/
|
||||
_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
|
||||
@ -65679,7 +65679,7 @@ class AbstractProvider {
|
||||
* alternate sub-class of [[TransactionReceipt]].
|
||||
*/
|
||||
_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
|
||||
@ -65687,7 +65687,7 @@ class AbstractProvider {
|
||||
* alternate sub-class of [[TransactionResponse]].
|
||||
*/
|
||||
_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
|
||||
@ -65851,7 +65851,7 @@ class AbstractProvider {
|
||||
* transaction.
|
||||
*/
|
||||
_getTransactionRequest(_request) {
|
||||
const request = (0,providers_provider/* copyRequest */.VS)(_request);
|
||||
const request = (0,provider/* copyRequest */.VS)(_request);
|
||||
const promises = [];
|
||||
["to", "from"].forEach((key) => {
|
||||
if (request[key] == null) {
|
||||
@ -65955,14 +65955,14 @@ class AbstractProvider {
|
||||
maxPriorityFeePerGas = (priorityFee != null) ? priorityFee : BigInt("1000000000");
|
||||
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
|
||||
const plugin = network.getPlugin("org.ethers.plugins.network.FetchUrlFeeDataPlugin");
|
||||
if (plugin) {
|
||||
const req = new FetchRequest(plugin.url);
|
||||
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();
|
||||
}
|
||||
@ -65981,7 +65981,7 @@ class AbstractProvider {
|
||||
transaction: Object.assign({}, tx, { blockTag, enableCcipRead: true })
|
||||
});
|
||||
// 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 {
|
||||
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 });
|
||||
}
|
||||
async function populate(signer, tx) {
|
||||
let pop = (0,providers_provider/* copyRequest */.VS)(tx);
|
||||
let pop = (0,provider/* copyRequest */.VS)(tx);
|
||||
if (pop.to != null) {
|
||||
pop.to = (0,checks/* resolveAddress */.tG)(pop.to, signer);
|
||||
}
|
||||
@ -68214,7 +68214,7 @@ class BaseWallet extends AbstractSigner {
|
||||
return new BaseWallet(this.#signingKey, provider);
|
||||
}
|
||||
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
|
||||
const { to, from } = await (0,properties/* resolveProperties */.k)({
|
||||
to: (tx.to ? (0,checks/* resolveAddress */.tG)(tx.to, this.provider) : undefined),
|
||||
@ -71300,6 +71300,7 @@ function getProviderWithNetId(netId, rpcUrl, config, fetchOptions) {
|
||||
return provider;
|
||||
}
|
||||
const populateTransaction = (signer, tx) => __async(void 0, null, function* () {
|
||||
var _a;
|
||||
const provider = signer.provider;
|
||||
if (!tx.from) {
|
||||
tx.from = signer.address;
|
||||
@ -71308,70 +71309,42 @@ const populateTransaction = (signer, tx) => __async(void 0, null, function* () {
|
||||
throw new Error(errMsg);
|
||||
}
|
||||
const [feeData, nonce] = yield Promise.all([
|
||||
(() => __async(void 0, null, function* () {
|
||||
if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) {
|
||||
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.maxFeePerGas || tx.gasPrice ? void 0 : provider.getFeeData(),
|
||||
(_a = tx.nonce) != null ? _a : provider.getTransactionCount(signer.address, "pending")
|
||||
]);
|
||||
tx.nonce = nonce;
|
||||
if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) {
|
||||
tx.maxFeePerGas = feeData.maxFeePerGas;
|
||||
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
||||
if (!tx.type) {
|
||||
tx.type = 2;
|
||||
if (feeData) {
|
||||
if (feeData.maxFeePerGas) {
|
||||
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 {
|
||||
const gasLimit = yield provider.estimateGas(tx);
|
||||
return gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4);
|
||||
} catch (err) {
|
||||
tx.gasLimit = gasLimit === BigInt(21e3) ? gasLimit : gasLimit * (BigInt(1e4) + BigInt(signer.gasLimitBump)) / BigInt(1e4);
|
||||
} catch (error) {
|
||||
if (signer.gasFailover) {
|
||||
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;
|
||||
});
|
||||
class TornadoWallet extends Wallet {
|
||||
@ -71570,10 +71543,12 @@ class RelayerClient {
|
||||
relayerAddress
|
||||
}) {
|
||||
var _a, _b;
|
||||
if (!url) {
|
||||
if (!url && hostname) {
|
||||
url = `https://${!hostname.endsWith("/") ? hostname + "/" : hostname}`;
|
||||
} else if (!url.endsWith("/")) {
|
||||
} else if (url && !url.endsWith("/")) {
|
||||
url += "/";
|
||||
} else {
|
||||
url = "";
|
||||
}
|
||||
const rawStatus = yield (0,_providers__WEBPACK_IMPORTED_MODULE_2__/* .fetchData */ .Fd)(`${url}status`, __spreadProps(__spreadValues({}, this.fetchDataOptions), {
|
||||
headers: {
|
||||
|
2
dist/tornado.umd.min.js
vendored
2
dist/tornado.umd.min.js
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@tornado/core",
|
||||
"version": "1.0.15",
|
||||
"version": "1.0.16",
|
||||
"description": "An SDK for building applications on top of Privacy Pools",
|
||||
"main": "./dist/index.js",
|
||||
"module": "./dist/index.mjs",
|
||||
|
110
src/providers.ts
110
src/providers.ts
@ -17,7 +17,6 @@ import {
|
||||
Eip1193Provider,
|
||||
VoidSigner,
|
||||
Network,
|
||||
FeeData,
|
||||
EnsPlugin,
|
||||
GasCostPlugin,
|
||||
} from 'ethers';
|
||||
@ -322,87 +321,52 @@ export const populateTransaction = async (
|
||||
}
|
||||
|
||||
const [feeData, nonce] = await Promise.all([
|
||||
(async () => {
|
||||
if (tx.maxFeePerGas && tx.maxPriorityFeePerGas) {
|
||||
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.maxFeePerGas || tx.gasPrice ? undefined : provider.getFeeData(),
|
||||
tx.nonce ?? provider.getTransactionCount(signer.address, 'pending'),
|
||||
]);
|
||||
|
||||
tx.nonce = nonce;
|
||||
if (feeData) {
|
||||
// EIP-1559
|
||||
if (feeData.maxFeePerGas) {
|
||||
if (!tx.type) {
|
||||
tx.type = 2;
|
||||
}
|
||||
|
||||
// EIP-1559
|
||||
if (feeData.maxFeePerGas && feeData.maxPriorityFeePerGas) {
|
||||
tx.maxFeePerGas = feeData.maxFeePerGas;
|
||||
tx.maxPriorityFeePerGas = feeData.maxPriorityFeePerGas;
|
||||
if (!tx.type) {
|
||||
tx.type = 2;
|
||||
tx.maxFeePerGas = (feeData.maxFeePerGas * (BigInt(10000) + BigInt(signer.gasPriceBump))) / BigInt(10000);
|
||||
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;
|
||||
}
|
||||
|
||||
// gasLimit
|
||||
tx.gasLimit =
|
||||
tx.gasLimit ||
|
||||
(await (async () => {
|
||||
try {
|
||||
const gasLimit = await provider.estimateGas(tx);
|
||||
return gasLimit === BigInt(21000)
|
||||
if (nonce) {
|
||||
tx.nonce = nonce;
|
||||
}
|
||||
|
||||
if (!tx.gasLimit) {
|
||||
try {
|
||||
const gasLimit = await provider.estimateGas(tx);
|
||||
|
||||
tx.gasLimit =
|
||||
gasLimit === BigInt(21000)
|
||||
? gasLimit
|
||||
: (gasLimit * (BigInt(10000) + BigInt(signer.gasLimitBump))) / BigInt(10000);
|
||||
} catch (err) {
|
||||
if (signer.gasFailover) {
|
||||
console.log('populateTransaction: warning gas estimation failed falling back to 3M gas');
|
||||
// Gas failover
|
||||
return BigInt('3000000');
|
||||
}
|
||||
throw err;
|
||||
} catch (error) {
|
||||
if (signer.gasFailover) {
|
||||
console.log('populateTransaction: warning gas estimation failed falling back to 3M gas');
|
||||
// Gas failover
|
||||
tx.gasLimit = BigInt('3000000');
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
})());
|
||||
}
|
||||
}
|
||||
|
||||
return tx;
|
||||
};
|
||||
|
@ -202,16 +202,18 @@ export class RelayerClient {
|
||||
url,
|
||||
relayerAddress,
|
||||
}: {
|
||||
hostname: string;
|
||||
hostname?: string;
|
||||
// optional url if entered manually
|
||||
url?: string;
|
||||
// relayerAddress from registry contract to prevent cheating
|
||||
relayerAddress?: string;
|
||||
}): Promise<RelayerStatus> {
|
||||
if (!url) {
|
||||
if (!url && hostname) {
|
||||
url = `https://${!hostname.endsWith('/') ? hostname + '/' : hostname}`;
|
||||
} else if (!url.endsWith('/')) {
|
||||
} else if (url && !url.endsWith('/')) {
|
||||
url += '/';
|
||||
} else {
|
||||
url = '';
|
||||
}
|
||||
|
||||
const rawStatus = (await fetchData(`${url}status`, {
|
||||
|
Loading…
Reference in New Issue
Block a user