Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@0xsequence/relayer

Package Overview
Dependencies
Maintainers
6
Versions
497
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@0xsequence/relayer - npm Package Compare versions

Comparing version 0.0.0-20240626143910 to 0.0.0-20240703210534

68

dist/0xsequence-relayer.cjs.dev.js

@@ -25,3 +25,3 @@ 'use strict';

const DEFAULT_GAS_LIMIT = ethers.ethers.BigNumber.from(800000);
const DEFAULT_GAS_LIMIT = 800000n;
const ProviderRelayerDefaults = {

@@ -33,3 +33,3 @@ waitPollRate: 1000,

function isProviderRelayerOptions(obj) {
return obj.provider !== undefined && ethers.providers.Provider.isProvider(obj.provider);
return obj.provider !== undefined && obj.provider instanceof ethers.ethers.AbstractProvider;
}

@@ -52,3 +52,3 @@ class ProviderRelayer {

// Respect gasLimit request of the transaction (as long as its not 0)
if (tx.gasLimit && !ethers.ethers.BigNumber.from(tx.gasLimit || 0).eq(ethers.ethers.constants.Zero)) {
if (tx.gasLimit && BigInt(tx.gasLimit || 0) !== 0n) {
return tx.gasLimit;

@@ -63,3 +63,3 @@ }

// Fee can't be estimated for self-called if wallet hasn't been deployed
if (tx.to === wallet && (await _this.provider.getCode(wallet).then(code => ethers.ethers.utils.arrayify(code).length === 0))) {
if (tx.to === wallet && (await _this.provider.getCode(wallet).then(code => ethers.ethers.getBytes(code).length === 0))) {
return DEFAULT_GAS_LIMIT;

@@ -73,6 +73,6 @@ }

// estimated with more accurately by using self-calls with the batch transactions one by one
return _this.provider.estimateGas({
return await _this.provider.estimateGas({
from: wallet,
to: tx.to,
data: tx.data,
data: tx.data && ethers.ethers.hexlify(tx.data),
value: tx.value

@@ -83,4 +83,4 @@ });

succeeded: true,
gasUsed: ethers.ethers.BigNumber.from(gasLimit).toNumber(),
gasLimit: ethers.ethers.BigNumber.from(gasLimit).toNumber()
gasUsed: Number(BigInt(gasLimit)),
gasLimit: Number(BigInt(gasLimit))
}));

@@ -156,3 +156,3 @@ }

// Find a transaction with a TxExecuted log
const found = txs.find(tx => tx.logs.find(l => l.topics.length === 0 && l.data.replace('0x', '') === normalMetaTxnId || l.topics.length === 1 &&
const found = txs.find(tx => tx == null ? void 0 : tx.logs.find(l => l.topics.length === 0 && l.data.replace('0x', '') === normalMetaTxnId || l.topics.length === 1 &&
// TxFailed event topic

@@ -163,5 +163,13 @@ l.topics[0] === '0x3dbd1590ea96dd3253a91f24e64e3a502e1225d602a5731357bc12643070ccd7' && l.data.length >= 64 && l.data.replace('0x', '').startsWith(normalMetaTxnId)));

if (found) {
return _extends({
receipt: found
}, await retry(() => _this2.provider.getTransaction(found.transactionHash), `unable to get transaction ${found.transactionHash}`));
const response = await retry(() => _this2.provider.getTransaction(found.hash), `unable to get transaction ${found.hash}`);
if (!response) {
throw new Error(`Transaction response not found for ${metaTxnId}`);
}
// NOTE: we have to do this, because ethers-v6 uses private fields
// and we can't just extend the class and override the method, so
// we just modify the response object directly by adding the receipt to it.
const out = response;
out.receipt = found;
return out;
}

@@ -188,7 +196,7 @@

function isLocalRelayerOptions(obj) {
return obj.signer !== undefined && ethers.Signer.isSigner(obj.signer);
return obj.signer !== undefined && obj.signer instanceof ethers.ethers.AbstractSigner;
}
class LocalRelayer extends ProviderRelayer {
constructor(options) {
super(ethers.Signer.isSigner(options) ? {
super(options instanceof ethers.ethers.AbstractSigner ? {
provider: options.provider

@@ -200,3 +208,3 @@ } : _extends({}, options, {

this.txnOptions = void 0;
this.signer = ethers.Signer.isSigner(options) ? options : options.signer;
this.signer = options instanceof ethers.ethers.AbstractSigner ? options : options.signer;
if (!this.signer.provider) throw new Error('Signer must have a provider');

@@ -231,3 +239,3 @@ }

// NOTE: we expect that all txns have set their gasLimit ahead of time through proper estimation
// const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), ethers.BigNumber.from(0))
// const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), 0n)
// txRequest.gasLimit = gasLimit

@@ -980,3 +988,3 @@

function isRpcRelayerOptions(obj) {
return obj.url !== undefined && typeof obj.url === 'string' && obj.provider !== undefined && ethers.ethers.providers.Provider.isProvider(obj.provider);
return obj.url !== undefined && typeof obj.url === 'string' && obj.provider !== undefined && obj.provider instanceof ethers.ethers.AbstractProvider;
}

@@ -1011,3 +1019,3 @@ const fetch = typeof global === 'object' ? global.fetch : window.fetch;

this.service = new Relayer(options.url, this._fetch);
if (ethers.ethers.providers.Provider.isProvider(options.provider)) {
if (options.provider instanceof ethers.ethers.AbstractProvider) {
this.provider = options.provider;

@@ -1019,4 +1027,6 @@ } else {

} = this.options;
const providerConnectionInfo = utils.getEthersConnectionInfo(options.provider.url, projectAccessKey, jwtAuth);
this.provider = new ethers.ethers.providers.StaticJsonRpcProvider(providerConnectionInfo);
const fetchRequest = utils.getFetchRequest(options.provider.url, projectAccessKey, jwtAuth);
this.provider = new ethers.ethers.JsonRpcProvider(fetchRequest, undefined, {
staticNetwork: true
});
}

@@ -1055,3 +1065,3 @@ }

async simulate(wallet, ...transactions) {
const coder = ethers.ethers.utils.defaultAbiCoder;
const coder = ethers.ethers.AbiCoder.defaultAbiCoder();
const encoded = coder.encode([core.commons.transaction.MetaTransactionsType], [core.commons.transaction.sequenceTxAbiEncode(transactions)]);

@@ -1110,3 +1120,3 @@ return (await this.service.simulate({

to: entrypoint,
data: ethers.ethers.utils.hexlify(data),
data: ethers.ethers.hexlify(data),
simulate: options == null ? void 0 : options.simulate

@@ -1130,3 +1140,3 @@ });

utils.logger.info(`[rpc-relayer/getNonce] get nonce for wallet ${address} space: ${space}`);
const encodedNonce = space !== undefined ? ethers.ethers.BigNumber.from(space).toHexString() : undefined;
const encodedNonce = space !== undefined ? utils.toHexString(BigInt(space)) : undefined;
const resp = await this.service.getMetaTxnNonce({

@@ -1136,3 +1146,3 @@ walletContractAddress: address,

});
const nonce = ethers.ethers.BigNumber.from(resp.nonce);
const nonce = BigInt(resp.nonce);
const [decodedSpace, decodedNonce] = core.commons.transaction.decodeNonce(nonce);

@@ -1190,2 +1200,6 @@ utils.logger.info(`[rpc-relayer/getNonce] got next nonce for wallet ${address} ${decodedNonce} space: ${decodedSpace}`);

response.wait = wait;
// NOTE: we just ignore these errors which come from the private fields
// of ethers-v6 .. but, we should probably rework this instead..
// @ts-ignore
return response;

@@ -1207,5 +1221,9 @@ }

const txReceipt = JSON.parse(receipt.txnReceipt);
// NOTE: we just ignore these errors which come from the private fields
// of ethers-v6 .. but, we should probably rework this instead..
// @ts-ignore
return {
blockHash: txReceipt.blockHash,
blockNumber: ethers.ethers.BigNumber.from(txReceipt.blockNumber).toNumber(),
blockNumber: Number(BigInt(txReceipt.blockNumber)),
confirmations: 1,

@@ -1212,0 +1230,0 @@ from: typeof metaTxnId === 'string' ? undefined : metaTxnId.intent.wallet,

@@ -25,3 +25,3 @@ 'use strict';

const DEFAULT_GAS_LIMIT = ethers.ethers.BigNumber.from(800000);
const DEFAULT_GAS_LIMIT = 800000n;
const ProviderRelayerDefaults = {

@@ -33,3 +33,3 @@ waitPollRate: 1000,

function isProviderRelayerOptions(obj) {
return obj.provider !== undefined && ethers.providers.Provider.isProvider(obj.provider);
return obj.provider !== undefined && obj.provider instanceof ethers.ethers.AbstractProvider;
}

@@ -52,3 +52,3 @@ class ProviderRelayer {

// Respect gasLimit request of the transaction (as long as its not 0)
if (tx.gasLimit && !ethers.ethers.BigNumber.from(tx.gasLimit || 0).eq(ethers.ethers.constants.Zero)) {
if (tx.gasLimit && BigInt(tx.gasLimit || 0) !== 0n) {
return tx.gasLimit;

@@ -63,3 +63,3 @@ }

// Fee can't be estimated for self-called if wallet hasn't been deployed
if (tx.to === wallet && (await _this.provider.getCode(wallet).then(code => ethers.ethers.utils.arrayify(code).length === 0))) {
if (tx.to === wallet && (await _this.provider.getCode(wallet).then(code => ethers.ethers.getBytes(code).length === 0))) {
return DEFAULT_GAS_LIMIT;

@@ -73,6 +73,6 @@ }

// estimated with more accurately by using self-calls with the batch transactions one by one
return _this.provider.estimateGas({
return await _this.provider.estimateGas({
from: wallet,
to: tx.to,
data: tx.data,
data: tx.data && ethers.ethers.hexlify(tx.data),
value: tx.value

@@ -83,4 +83,4 @@ });

succeeded: true,
gasUsed: ethers.ethers.BigNumber.from(gasLimit).toNumber(),
gasLimit: ethers.ethers.BigNumber.from(gasLimit).toNumber()
gasUsed: Number(BigInt(gasLimit)),
gasLimit: Number(BigInt(gasLimit))
}));

@@ -156,3 +156,3 @@ }

// Find a transaction with a TxExecuted log
const found = txs.find(tx => tx.logs.find(l => l.topics.length === 0 && l.data.replace('0x', '') === normalMetaTxnId || l.topics.length === 1 &&
const found = txs.find(tx => tx == null ? void 0 : tx.logs.find(l => l.topics.length === 0 && l.data.replace('0x', '') === normalMetaTxnId || l.topics.length === 1 &&
// TxFailed event topic

@@ -163,5 +163,13 @@ l.topics[0] === '0x3dbd1590ea96dd3253a91f24e64e3a502e1225d602a5731357bc12643070ccd7' && l.data.length >= 64 && l.data.replace('0x', '').startsWith(normalMetaTxnId)));

if (found) {
return _extends({
receipt: found
}, await retry(() => _this2.provider.getTransaction(found.transactionHash), `unable to get transaction ${found.transactionHash}`));
const response = await retry(() => _this2.provider.getTransaction(found.hash), `unable to get transaction ${found.hash}`);
if (!response) {
throw new Error(`Transaction response not found for ${metaTxnId}`);
}
// NOTE: we have to do this, because ethers-v6 uses private fields
// and we can't just extend the class and override the method, so
// we just modify the response object directly by adding the receipt to it.
const out = response;
out.receipt = found;
return out;
}

@@ -188,7 +196,7 @@

function isLocalRelayerOptions(obj) {
return obj.signer !== undefined && ethers.Signer.isSigner(obj.signer);
return obj.signer !== undefined && obj.signer instanceof ethers.ethers.AbstractSigner;
}
class LocalRelayer extends ProviderRelayer {
constructor(options) {
super(ethers.Signer.isSigner(options) ? {
super(options instanceof ethers.ethers.AbstractSigner ? {
provider: options.provider

@@ -200,3 +208,3 @@ } : _extends({}, options, {

this.txnOptions = void 0;
this.signer = ethers.Signer.isSigner(options) ? options : options.signer;
this.signer = options instanceof ethers.ethers.AbstractSigner ? options : options.signer;
if (!this.signer.provider) throw new Error('Signer must have a provider');

@@ -231,3 +239,3 @@ }

// NOTE: we expect that all txns have set their gasLimit ahead of time through proper estimation
// const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), ethers.BigNumber.from(0))
// const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), 0n)
// txRequest.gasLimit = gasLimit

@@ -980,3 +988,3 @@

function isRpcRelayerOptions(obj) {
return obj.url !== undefined && typeof obj.url === 'string' && obj.provider !== undefined && ethers.ethers.providers.Provider.isProvider(obj.provider);
return obj.url !== undefined && typeof obj.url === 'string' && obj.provider !== undefined && obj.provider instanceof ethers.ethers.AbstractProvider;
}

@@ -1011,3 +1019,3 @@ const fetch = typeof global === 'object' ? global.fetch : window.fetch;

this.service = new Relayer(options.url, this._fetch);
if (ethers.ethers.providers.Provider.isProvider(options.provider)) {
if (options.provider instanceof ethers.ethers.AbstractProvider) {
this.provider = options.provider;

@@ -1019,4 +1027,6 @@ } else {

} = this.options;
const providerConnectionInfo = utils.getEthersConnectionInfo(options.provider.url, projectAccessKey, jwtAuth);
this.provider = new ethers.ethers.providers.StaticJsonRpcProvider(providerConnectionInfo);
const fetchRequest = utils.getFetchRequest(options.provider.url, projectAccessKey, jwtAuth);
this.provider = new ethers.ethers.JsonRpcProvider(fetchRequest, undefined, {
staticNetwork: true
});
}

@@ -1055,3 +1065,3 @@ }

async simulate(wallet, ...transactions) {
const coder = ethers.ethers.utils.defaultAbiCoder;
const coder = ethers.ethers.AbiCoder.defaultAbiCoder();
const encoded = coder.encode([core.commons.transaction.MetaTransactionsType], [core.commons.transaction.sequenceTxAbiEncode(transactions)]);

@@ -1110,3 +1120,3 @@ return (await this.service.simulate({

to: entrypoint,
data: ethers.ethers.utils.hexlify(data),
data: ethers.ethers.hexlify(data),
simulate: options == null ? void 0 : options.simulate

@@ -1130,3 +1140,3 @@ });

utils.logger.info(`[rpc-relayer/getNonce] get nonce for wallet ${address} space: ${space}`);
const encodedNonce = space !== undefined ? ethers.ethers.BigNumber.from(space).toHexString() : undefined;
const encodedNonce = space !== undefined ? utils.toHexString(BigInt(space)) : undefined;
const resp = await this.service.getMetaTxnNonce({

@@ -1136,3 +1146,3 @@ walletContractAddress: address,

});
const nonce = ethers.ethers.BigNumber.from(resp.nonce);
const nonce = BigInt(resp.nonce);
const [decodedSpace, decodedNonce] = core.commons.transaction.decodeNonce(nonce);

@@ -1190,2 +1200,6 @@ utils.logger.info(`[rpc-relayer/getNonce] got next nonce for wallet ${address} ${decodedNonce} space: ${decodedSpace}`);

response.wait = wait;
// NOTE: we just ignore these errors which come from the private fields
// of ethers-v6 .. but, we should probably rework this instead..
// @ts-ignore
return response;

@@ -1207,5 +1221,9 @@ }

const txReceipt = JSON.parse(receipt.txnReceipt);
// NOTE: we just ignore these errors which come from the private fields
// of ethers-v6 .. but, we should probably rework this instead..
// @ts-ignore
return {
blockHash: txReceipt.blockHash,
blockNumber: ethers.ethers.BigNumber.from(txReceipt.blockNumber).toNumber(),
blockNumber: Number(BigInt(txReceipt.blockNumber)),
confirmations: 1,

@@ -1212,0 +1230,0 @@ from: typeof metaTxnId === 'string' ? undefined : metaTxnId.intent.wallet,

@@ -1,3 +0,3 @@

import { ethers, providers, Signer } from 'ethers';
import { logger, getEthersConnectionInfo } from '@0xsequence/utils';
import { ethers } from 'ethers';
import { logger, getFetchRequest, toHexString } from '@0xsequence/utils';
import { walletContracts } from '@0xsequence/abi';

@@ -21,3 +21,3 @@ import { commons } from '@0xsequence/core';

const DEFAULT_GAS_LIMIT = ethers.BigNumber.from(800000);
const DEFAULT_GAS_LIMIT = 800000n;
const ProviderRelayerDefaults = {

@@ -29,3 +29,3 @@ waitPollRate: 1000,

function isProviderRelayerOptions(obj) {
return obj.provider !== undefined && providers.Provider.isProvider(obj.provider);
return obj.provider !== undefined && obj.provider instanceof ethers.AbstractProvider;
}

@@ -48,3 +48,3 @@ class ProviderRelayer {

// Respect gasLimit request of the transaction (as long as its not 0)
if (tx.gasLimit && !ethers.BigNumber.from(tx.gasLimit || 0).eq(ethers.constants.Zero)) {
if (tx.gasLimit && BigInt(tx.gasLimit || 0) !== 0n) {
return tx.gasLimit;

@@ -59,3 +59,3 @@ }

// Fee can't be estimated for self-called if wallet hasn't been deployed
if (tx.to === wallet && (await _this.provider.getCode(wallet).then(code => ethers.utils.arrayify(code).length === 0))) {
if (tx.to === wallet && (await _this.provider.getCode(wallet).then(code => ethers.getBytes(code).length === 0))) {
return DEFAULT_GAS_LIMIT;

@@ -69,6 +69,6 @@ }

// estimated with more accurately by using self-calls with the batch transactions one by one
return _this.provider.estimateGas({
return await _this.provider.estimateGas({
from: wallet,
to: tx.to,
data: tx.data,
data: tx.data && ethers.hexlify(tx.data),
value: tx.value

@@ -79,4 +79,4 @@ });

succeeded: true,
gasUsed: ethers.BigNumber.from(gasLimit).toNumber(),
gasLimit: ethers.BigNumber.from(gasLimit).toNumber()
gasUsed: Number(BigInt(gasLimit)),
gasLimit: Number(BigInt(gasLimit))
}));

@@ -152,3 +152,3 @@ }

// Find a transaction with a TxExecuted log
const found = txs.find(tx => tx.logs.find(l => l.topics.length === 0 && l.data.replace('0x', '') === normalMetaTxnId || l.topics.length === 1 &&
const found = txs.find(tx => tx == null ? void 0 : tx.logs.find(l => l.topics.length === 0 && l.data.replace('0x', '') === normalMetaTxnId || l.topics.length === 1 &&
// TxFailed event topic

@@ -159,5 +159,13 @@ l.topics[0] === '0x3dbd1590ea96dd3253a91f24e64e3a502e1225d602a5731357bc12643070ccd7' && l.data.length >= 64 && l.data.replace('0x', '').startsWith(normalMetaTxnId)));

if (found) {
return _extends({
receipt: found
}, await retry(() => _this2.provider.getTransaction(found.transactionHash), `unable to get transaction ${found.transactionHash}`));
const response = await retry(() => _this2.provider.getTransaction(found.hash), `unable to get transaction ${found.hash}`);
if (!response) {
throw new Error(`Transaction response not found for ${metaTxnId}`);
}
// NOTE: we have to do this, because ethers-v6 uses private fields
// and we can't just extend the class and override the method, so
// we just modify the response object directly by adding the receipt to it.
const out = response;
out.receipt = found;
return out;
}

@@ -184,7 +192,7 @@

function isLocalRelayerOptions(obj) {
return obj.signer !== undefined && Signer.isSigner(obj.signer);
return obj.signer !== undefined && obj.signer instanceof ethers.AbstractSigner;
}
class LocalRelayer extends ProviderRelayer {
constructor(options) {
super(Signer.isSigner(options) ? {
super(options instanceof ethers.AbstractSigner ? {
provider: options.provider

@@ -196,3 +204,3 @@ } : _extends({}, options, {

this.txnOptions = void 0;
this.signer = Signer.isSigner(options) ? options : options.signer;
this.signer = options instanceof ethers.AbstractSigner ? options : options.signer;
if (!this.signer.provider) throw new Error('Signer must have a provider');

@@ -227,3 +235,3 @@ }

// NOTE: we expect that all txns have set their gasLimit ahead of time through proper estimation
// const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), ethers.BigNumber.from(0))
// const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), 0n)
// txRequest.gasLimit = gasLimit

@@ -976,3 +984,3 @@

function isRpcRelayerOptions(obj) {
return obj.url !== undefined && typeof obj.url === 'string' && obj.provider !== undefined && ethers.providers.Provider.isProvider(obj.provider);
return obj.url !== undefined && typeof obj.url === 'string' && obj.provider !== undefined && obj.provider instanceof ethers.AbstractProvider;
}

@@ -1007,3 +1015,3 @@ const fetch = typeof global === 'object' ? global.fetch : window.fetch;

this.service = new Relayer(options.url, this._fetch);
if (ethers.providers.Provider.isProvider(options.provider)) {
if (options.provider instanceof ethers.AbstractProvider) {
this.provider = options.provider;

@@ -1015,4 +1023,6 @@ } else {

} = this.options;
const providerConnectionInfo = getEthersConnectionInfo(options.provider.url, projectAccessKey, jwtAuth);
this.provider = new ethers.providers.StaticJsonRpcProvider(providerConnectionInfo);
const fetchRequest = getFetchRequest(options.provider.url, projectAccessKey, jwtAuth);
this.provider = new ethers.JsonRpcProvider(fetchRequest, undefined, {
staticNetwork: true
});
}

@@ -1051,3 +1061,3 @@ }

async simulate(wallet, ...transactions) {
const coder = ethers.utils.defaultAbiCoder;
const coder = ethers.AbiCoder.defaultAbiCoder();
const encoded = coder.encode([commons.transaction.MetaTransactionsType], [commons.transaction.sequenceTxAbiEncode(transactions)]);

@@ -1106,3 +1116,3 @@ return (await this.service.simulate({

to: entrypoint,
data: ethers.utils.hexlify(data),
data: ethers.hexlify(data),
simulate: options == null ? void 0 : options.simulate

@@ -1126,3 +1136,3 @@ });

logger.info(`[rpc-relayer/getNonce] get nonce for wallet ${address} space: ${space}`);
const encodedNonce = space !== undefined ? ethers.BigNumber.from(space).toHexString() : undefined;
const encodedNonce = space !== undefined ? toHexString(BigInt(space)) : undefined;
const resp = await this.service.getMetaTxnNonce({

@@ -1132,3 +1142,3 @@ walletContractAddress: address,

});
const nonce = ethers.BigNumber.from(resp.nonce);
const nonce = BigInt(resp.nonce);
const [decodedSpace, decodedNonce] = commons.transaction.decodeNonce(nonce);

@@ -1186,2 +1196,6 @@ logger.info(`[rpc-relayer/getNonce] got next nonce for wallet ${address} ${decodedNonce} space: ${decodedSpace}`);

response.wait = wait;
// NOTE: we just ignore these errors which come from the private fields
// of ethers-v6 .. but, we should probably rework this instead..
// @ts-ignore
return response;

@@ -1203,5 +1217,9 @@ }

const txReceipt = JSON.parse(receipt.txnReceipt);
// NOTE: we just ignore these errors which come from the private fields
// of ethers-v6 .. but, we should probably rework this instead..
// @ts-ignore
return {
blockHash: txReceipt.blockHash,
blockNumber: ethers.BigNumber.from(txReceipt.blockNumber).toNumber(),
blockNumber: Number(BigInt(txReceipt.blockNumber)),
confirmations: 1,

@@ -1208,0 +1226,0 @@ from: typeof metaTxnId === 'string' ? undefined : metaTxnId.intent.wallet,

@@ -1,2 +0,2 @@

import { ethers, providers } from 'ethers';
import { ethers } from 'ethers';
import { proto } from "./rpc-relayer/index.js";

@@ -10,3 +10,3 @@ import { commons } from '@0xsequence/core';

}>;
getFeeOptionsRaw(entrypoint: string, data: ethers.utils.BytesLike, options?: {
getFeeOptionsRaw(entrypoint: string, data: ethers.BytesLike, options?: {
simulate?: boolean;

@@ -18,3 +18,3 @@ }): Promise<{

gasRefundOptions(address: string, ...transactions: commons.transaction.Transaction[]): Promise<FeeOption[]>;
getNonce(address: string, space?: ethers.BigNumberish, blockTag?: providers.BlockTag): Promise<ethers.BigNumberish>;
getNonce(address: string, space?: ethers.BigNumberish, blockTag?: ethers.BlockTag): Promise<ethers.BigNumberish>;
relay(signedTxs: commons.transaction.IntendedTransactionBundle, quote?: FeeQuote, waitForReceipt?: boolean): Promise<commons.transaction.TransactionResponse>;

@@ -21,0 +21,0 @@ wait(metaTxnId: string | commons.transaction.SignedTransactionBundle, timeout?: number, delay?: number, maxFails?: number): Promise<commons.transaction.TransactionResponse>;

@@ -1,2 +0,2 @@

import { Signer as AbstractSigner, providers, BytesLike } from 'ethers';
import { ethers } from 'ethers';
import { FeeOption, FeeQuote, Relayer } from "./index.js";

@@ -6,3 +6,3 @@ import { ProviderRelayer, ProviderRelayerOptions } from "./provider-relayer.js";

export type LocalRelayerOptions = Omit<ProviderRelayerOptions, 'provider'> & {
signer: AbstractSigner;
signer: ethers.Signer;
};

@@ -13,7 +13,7 @@ export declare function isLocalRelayerOptions(obj: any): obj is LocalRelayerOptions;

private txnOptions;
constructor(options: LocalRelayerOptions | AbstractSigner);
constructor(options: LocalRelayerOptions | ethers.AbstractSigner);
getFeeOptions(_address: string, ..._transactions: commons.transaction.Transaction[]): Promise<{
options: FeeOption[];
}>;
getFeeOptionsRaw(_entrypoint: string, _data: BytesLike, _options?: {
getFeeOptionsRaw(_entrypoint: string, _data: ethers.BytesLike, _options?: {
simulate?: boolean;

@@ -24,4 +24,4 @@ }): Promise<{

gasRefundOptions(address: string, ...transactions: commons.transaction.Transaction[]): Promise<FeeOption[]>;
setTransactionOptions(transactionRequest: providers.TransactionRequest): void;
relay(signedTxs: commons.transaction.IntendedTransactionBundle, quote?: FeeQuote, waitForReceipt?: boolean): Promise<commons.transaction.TransactionResponse<providers.TransactionReceipt>>;
setTransactionOptions(transactionRequest: ethers.TransactionRequest): void;
relay(signedTxs: commons.transaction.IntendedTransactionBundle, quote?: FeeQuote, waitForReceipt?: boolean): Promise<commons.transaction.TransactionResponse<ethers.TransactionReceipt>>;
}

@@ -1,2 +0,2 @@

import { ethers, providers } from 'ethers';
import { ethers } from 'ethers';
import { FeeOption, FeeQuote, Relayer, SimulateResult } from "./index.js";

@@ -6,3 +6,3 @@ import { Optionals } from '@0xsequence/utils';

export interface ProviderRelayerOptions {
provider: providers.Provider;
provider: ethers.Provider;
waitPollRate?: number;

@@ -15,3 +15,3 @@ deltaBlocksLog?: number;

export declare abstract class ProviderRelayer implements Relayer {
provider: providers.Provider;
provider: ethers.Provider;
waitPollRate: number;

@@ -25,3 +25,3 @@ deltaBlocksLog: number;

}>;
abstract getFeeOptionsRaw(entrypoint: string, data: ethers.utils.BytesLike, options?: {
abstract getFeeOptionsRaw(entrypoint: string, data: ethers.BytesLike, options?: {
simulate?: boolean;

@@ -35,6 +35,6 @@ }): Promise<{

simulate(wallet: string, ...transactions: commons.transaction.Transaction[]): Promise<SimulateResult[]>;
getNonce(address: string, space?: ethers.BigNumberish, blockTag?: providers.BlockTag): Promise<ethers.BigNumberish>;
wait(metaTxnId: string | commons.transaction.SignedTransactionBundle, timeoutDuration?: number, delay?: number, maxFails?: number): Promise<providers.TransactionResponse & {
receipt: providers.TransactionReceipt;
getNonce(address: string, space?: ethers.BigNumberish, blockTag?: ethers.BlockTag): Promise<ethers.BigNumberish>;
wait(metaTxnId: string | commons.transaction.SignedTransactionBundle, timeoutDuration?: number, delay?: number, maxFails?: number): Promise<ethers.TransactionResponse & {
receipt: ethers.TransactionReceipt;
}>;
}

@@ -7,3 +7,3 @@ import { ethers } from 'ethers';

export interface RpcRelayerOptions {
provider: ethers.providers.Provider | {
provider: ethers.AbstractProvider | {
url: string;

@@ -19,3 +19,3 @@ };

private readonly service;
readonly provider: ethers.providers.Provider;
readonly provider: ethers.Provider;
constructor(options: RpcRelayerOptions);

@@ -29,3 +29,3 @@ _fetch: (input: RequestInfo, init?: RequestInit) => Promise<Response>;

}>;
getFeeOptionsRaw(entrypoint: string, data: ethers.utils.BytesLike, options?: {
getFeeOptionsRaw(entrypoint: string, data: ethers.BytesLike, options?: {
simulate?: boolean;

@@ -32,0 +32,0 @@ }): Promise<{

{
"name": "@0xsequence/relayer",
"version": "0.0.0-20240626143910",
"version": "0.0.0-20240703210534",
"description": "relayer sub-package for Sequence",

@@ -12,14 +12,14 @@ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/relayer",

"dependencies": {
"@0xsequence/abi": "0.0.0-20240626143910",
"@0xsequence/core": "0.0.0-20240626143910",
"@0xsequence/utils": "0.0.0-20240626143910"
"@0xsequence/abi": "0.0.0-20240703210534",
"@0xsequence/core": "0.0.0-20240703210534",
"@0xsequence/utils": "0.0.0-20240703210534"
},
"peerDependencies": {
"ethers": ">=5.5 < 6"
"ethers": ">=6"
},
"devDependencies": {
"@0xsequence/wallet-contracts": "^1.10.0",
"ethers": "^5.7.2",
"@0xsequence/signhub": "0.0.0-20240626143910",
"@0xsequence/tests": "0.0.0-20240626143910"
"@0xsequence/wallet-contracts": "^3.0.1",
"ethers": "^6.13.0",
"@0xsequence/signhub": "0.0.0-20240703210534",
"@0xsequence/tests": "0.0.0-20240703210534"
},

@@ -33,3 +33,3 @@ "files": [

"test:run": "pnpm test:file tests/**/*.spec.ts",
"test:file": "NODE_OPTIONS='--import tsx' mocha --timeout 30000",
"test:file": "NODE_OPTIONS='--import tsx' mocha --timeout 60000",
"test:concurrently": "concurrently -k --success first 'pnpm start:hardhat > /dev/null' ",

@@ -36,0 +36,0 @@ "start:hardhat": "pnpm hardhat node --port 9547",

@@ -1,2 +0,2 @@

import { ethers, providers } from 'ethers'
import { ethers } from 'ethers'
import { proto } from './rpc-relayer'

@@ -22,3 +22,3 @@

entrypoint: string,
data: ethers.utils.BytesLike,
data: ethers.BytesLike,
options?: {

@@ -36,3 +36,3 @@ simulate?: boolean

// Otherwise, the relayer must return a nonce encoded for the given nonce space.
getNonce(address: string, space?: ethers.BigNumberish, blockTag?: providers.BlockTag): Promise<ethers.BigNumberish>
getNonce(address: string, space?: ethers.BigNumberish, blockTag?: ethers.BlockTag): Promise<ethers.BigNumberish>

@@ -39,0 +39,0 @@ // relayer will submit the transaction(s) to the network and return the transaction response.

@@ -1,2 +0,2 @@

import { Signer as AbstractSigner, providers, BytesLike } from 'ethers'
import { ethers } from 'ethers'
import { logger } from '@0xsequence/utils'

@@ -8,16 +8,20 @@ import { FeeOption, FeeQuote, Relayer } from '.'

export type LocalRelayerOptions = Omit<ProviderRelayerOptions, 'provider'> & {
signer: AbstractSigner
signer: ethers.Signer
}
export function isLocalRelayerOptions(obj: any): obj is LocalRelayerOptions {
return obj.signer !== undefined && AbstractSigner.isSigner(obj.signer)
return obj.signer !== undefined && obj.signer instanceof ethers.AbstractSigner
}
export class LocalRelayer extends ProviderRelayer implements Relayer {
private signer: AbstractSigner
private txnOptions: providers.TransactionRequest
private signer: ethers.Signer
private txnOptions: ethers.TransactionRequest
constructor(options: LocalRelayerOptions | AbstractSigner) {
super(AbstractSigner.isSigner(options) ? { provider: options.provider! } : { ...options, provider: options.signer.provider! })
this.signer = AbstractSigner.isSigner(options) ? options : options.signer
constructor(options: LocalRelayerOptions | ethers.AbstractSigner) {
super(
options instanceof ethers.AbstractSigner
? { provider: options.provider! }
: { ...options, provider: options.signer.provider! }
)
this.signer = options instanceof ethers.AbstractSigner ? options : options.signer
if (!this.signer.provider) throw new Error('Signer must have a provider')

@@ -32,3 +36,3 @@ }

_entrypoint: string,
_data: BytesLike,
_data: ethers.BytesLike,
_options?: {

@@ -46,3 +50,3 @@ simulate?: boolean

setTransactionOptions(transactionRequest: providers.TransactionRequest) {
setTransactionOptions(transactionRequest: ethers.TransactionRequest) {
this.txnOptions = transactionRequest

@@ -55,3 +59,3 @@ }

waitForReceipt: boolean = true
): Promise<commons.transaction.TransactionResponse<providers.TransactionReceipt>> {
): Promise<commons.transaction.TransactionResponse<ethers.TransactionReceipt>> {
if (quote !== undefined) {

@@ -65,3 +69,3 @@ logger.warn(`LocalRelayer doesn't accept fee quotes`)

// NOTE: we expect that all txns have set their gasLimit ahead of time through proper estimation
// const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), ethers.BigNumber.from(0))
// const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), 0n)
// txRequest.gasLimit = gasLimit

@@ -68,0 +72,0 @@

@@ -1,2 +0,2 @@

import { ethers, providers } from 'ethers'
import { ethers } from 'ethers'
import { walletContracts } from '@0xsequence/abi'

@@ -7,6 +7,6 @@ import { FeeOption, FeeQuote, Relayer, SimulateResult } from '.'

const DEFAULT_GAS_LIMIT = ethers.BigNumber.from(800000)
const DEFAULT_GAS_LIMIT = 800000n
export interface ProviderRelayerOptions {
provider: providers.Provider
provider: ethers.Provider
waitPollRate?: number

@@ -24,7 +24,7 @@ deltaBlocksLog?: number

export function isProviderRelayerOptions(obj: any): obj is ProviderRelayerOptions {
return obj.provider !== undefined && providers.Provider.isProvider(obj.provider)
return obj.provider !== undefined && obj.provider instanceof ethers.AbstractProvider
}
export abstract class ProviderRelayer implements Relayer {
public provider: providers.Provider
public provider: ethers.Provider
public waitPollRate: number

@@ -50,3 +50,3 @@ public deltaBlocksLog: number

entrypoint: string,
data: ethers.utils.BytesLike,
data: ethers.BytesLike,
options?: {

@@ -70,3 +70,3 @@ simulate?: boolean

// Respect gasLimit request of the transaction (as long as its not 0)
if (tx.gasLimit && !ethers.BigNumber.from(tx.gasLimit || 0).eq(ethers.constants.Zero)) {
if (tx.gasLimit && BigInt(tx.gasLimit || 0) !== 0n) {
return tx.gasLimit

@@ -81,3 +81,3 @@ }

// Fee can't be estimated for self-called if wallet hasn't been deployed
if (tx.to === wallet && (await this.provider.getCode(wallet).then(code => ethers.utils.arrayify(code).length === 0))) {
if (tx.to === wallet && (await this.provider.getCode(wallet).then(code => ethers.getBytes(code).length === 0))) {
return DEFAULT_GAS_LIMIT

@@ -92,6 +92,6 @@ }

// estimated with more accurately by using self-calls with the batch transactions one by one
return this.provider.estimateGas({
return await this.provider.estimateGas({
from: wallet,
to: tx.to,
data: tx.data,
data: tx.data && ethers.hexlify(tx.data),
value: tx.value

@@ -104,8 +104,8 @@ })

succeeded: true,
gasUsed: ethers.BigNumber.from(gasLimit).toNumber(),
gasLimit: ethers.BigNumber.from(gasLimit).toNumber()
gasUsed: Number(BigInt(gasLimit)),
gasLimit: Number(BigInt(gasLimit))
}))
}
async getNonce(address: string, space?: ethers.BigNumberish, blockTag?: providers.BlockTag): Promise<ethers.BigNumberish> {
async getNonce(address: string, space?: ethers.BigNumberish, blockTag?: ethers.BlockTag): Promise<ethers.BigNumberish> {
if (!this.provider) {

@@ -133,3 +133,3 @@ throw new Error('provider is not set')

maxFails: number = 5
): Promise<providers.TransactionResponse & { receipt: providers.TransactionReceipt }> {
): Promise<ethers.TransactionResponse & { receipt: ethers.TransactionReceipt }> {
if (typeof metaTxnId !== 'string') {

@@ -166,3 +166,3 @@ metaTxnId = commons.transaction.intendedTransactionID(metaTxnId)

const waitReceipt = async (): Promise<providers.TransactionResponse & { receipt: providers.TransactionReceipt }> => {
const waitReceipt = async (): Promise<ethers.TransactionResponse & { receipt: ethers.TransactionReceipt }> => {
// Transactions can only get executed on nonce change

@@ -211,3 +211,3 @@ // get all nonce changes and look for metaTxnIds in between logs

const found = txs.find(tx =>
tx.logs.find(
tx?.logs.find(
l =>

@@ -225,9 +225,13 @@ (l.topics.length === 0 && l.data.replace('0x', '') === normalMetaTxnId) ||

if (found) {
return {
receipt: found,
...(await retry(
() => this.provider.getTransaction(found.transactionHash),
`unable to get transaction ${found.transactionHash}`
))
const response = await retry(() => this.provider.getTransaction(found.hash), `unable to get transaction ${found.hash}`)
if (!response) {
throw new Error(`Transaction response not found for ${metaTxnId}`)
}
// NOTE: we have to do this, because ethers-v6 uses private fields
// and we can't just extend the class and override the method, so
// we just modify the response object directly by adding the receipt to it.
const out: any = response
out.receipt = found
return out
}

@@ -247,3 +251,3 @@

waitReceipt(),
new Promise<providers.TransactionResponse & { receipt: providers.TransactionReceipt }>((_, reject) =>
new Promise<ethers.TransactionResponse & { receipt: ethers.TransactionReceipt }>((_, reject) =>
setTimeout(() => {

@@ -250,0 +254,0 @@ timedOut = true

@@ -5,3 +5,3 @@ import { ethers } from 'ethers'

import { commons } from '@0xsequence/core'
import { getEthersConnectionInfo, logger } from '@0xsequence/utils'
import { getFetchRequest, logger, toHexString } from '@0xsequence/utils'

@@ -20,3 +20,3 @@ export { proto }

export interface RpcRelayerOptions {
provider: ethers.providers.Provider | { url: string }
provider: ethers.AbstractProvider | { url: string }
url: string

@@ -32,3 +32,3 @@ projectAccessKey?: string

obj.provider !== undefined &&
ethers.providers.Provider.isProvider(obj.provider)
obj.provider instanceof ethers.AbstractProvider
)

@@ -42,3 +42,3 @@ }

private readonly service: proto.Relayer
public readonly provider: ethers.providers.Provider
public readonly provider: ethers.Provider

@@ -48,8 +48,8 @@ constructor(public options: RpcRelayerOptions) {

if (ethers.providers.Provider.isProvider(options.provider)) {
if (options.provider instanceof ethers.AbstractProvider) {
this.provider = options.provider
} else {
const { jwtAuth, projectAccessKey } = this.options
const providerConnectionInfo = getEthersConnectionInfo(options.provider.url, projectAccessKey, jwtAuth)
this.provider = new ethers.providers.StaticJsonRpcProvider(providerConnectionInfo)
const fetchRequest = getFetchRequest(options.provider.url, projectAccessKey, jwtAuth)
this.provider = new ethers.JsonRpcProvider(fetchRequest, undefined, { staticNetwork: true })
}

@@ -122,3 +122,3 @@ }

async simulate(wallet: string, ...transactions: commons.transaction.Transaction[]): Promise<SimulateResult[]> {
const coder = ethers.utils.defaultAbiCoder
const coder = ethers.AbiCoder.defaultAbiCoder()
const encoded = coder.encode(

@@ -171,3 +171,3 @@ [commons.transaction.MetaTransactionsType],

entrypoint: string,
data: ethers.utils.BytesLike,
data: ethers.BytesLike,
options?: {

@@ -180,3 +180,3 @@ simulate?: boolean

to: entrypoint,
data: ethers.utils.hexlify(data),
data: ethers.hexlify(data),
simulate: options?.simulate

@@ -195,5 +195,5 @@ })

logger.info(`[rpc-relayer/getNonce] get nonce for wallet ${address} space: ${space}`)
const encodedNonce = space !== undefined ? ethers.BigNumber.from(space).toHexString() : undefined
const encodedNonce = space !== undefined ? toHexString(BigInt(space)) : undefined
const resp = await this.service.getMetaTxnNonce({ walletContractAddress: address, space: encodedNonce })
const nonce = ethers.BigNumber.from(resp.nonce)
const nonce = BigInt(resp.nonce)
const [decodedSpace, decodedNonce] = commons.transaction.decodeNonce(nonce)

@@ -246,6 +246,6 @@ logger.info(`[rpc-relayer/getNonce] got next nonce for wallet ${address} ${decodedNonce} space: ${decodedSpace}`)

from: signedTxs.intent.wallet,
wait: (_confirmations?: number): Promise<ethers.providers.TransactionReceipt> => Promise.reject(new Error('impossible'))
wait: (_confirmations?: number): Promise<ethers.TransactionReceipt | null> => Promise.reject(new Error('impossible'))
}
const wait = async (confirmations?: number): Promise<ethers.providers.TransactionReceipt> => {
const wait = async (confirmations?: number): Promise<ethers.TransactionReceipt | null> => {
if (!this.provider) {

@@ -269,2 +269,5 @@ throw new Error('cannot wait for receipt, relayer has no provider set')

// NOTE: we just ignore these errors which come from the private fields
// of ethers-v6 .. but, we should probably rework this instead..
// @ts-ignore
return response as commons.transaction.TransactionResponse

@@ -300,5 +303,8 @@ }

// NOTE: we just ignore these errors which come from the private fields
// of ethers-v6 .. but, we should probably rework this instead..
// @ts-ignore
return {
blockHash: txReceipt.blockHash,
blockNumber: ethers.BigNumber.from(txReceipt.blockNumber).toNumber(),
blockNumber: Number(BigInt(txReceipt.blockNumber)),
confirmations: 1,

@@ -305,0 +311,0 @@ from: typeof metaTxnId === 'string' ? undefined : metaTxnId.intent.wallet,

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc