Socket
Socket
Sign inDemoInstall

@0xsequence/relayer

Package Overview
Dependencies
Maintainers
0
Versions
473
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-20240812142652 to 0.0.0-20240814043648

64

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

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

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

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

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

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

// Respect gasLimit request of the transaction (as long as its not 0)
if (tx.gasLimit && BigInt(tx.gasLimit || 0) !== 0n) {
if (tx.gasLimit && !ethers.ethers.BigNumber.from(tx.gasLimit || 0).eq(ethers.ethers.constants.Zero)) {
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.getBytes(code).length === 0))) {
if (tx.to === wallet && (await _this.provider.getCode(wallet).then(code => ethers.ethers.utils.arrayify(code).length === 0))) {
return DEFAULT_GAS_LIMIT;

@@ -82,4 +82,4 @@ }

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

@@ -155,3 +155,3 @@ }

// Find a transaction with a TxExecuted log
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 &&
const found = txs.find(tx => tx.logs.find(l => l.topics.length === 0 && l.data.replace('0x', '') === normalMetaTxnId || l.topics.length === 1 &&
// TxFailed event topic

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

if (found) {
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;
return _extends({
receipt: found
}, await retry(() => _this2.provider.getTransaction(found.transactionHash), `unable to get transaction ${found.transactionHash}`));
}

@@ -195,7 +187,7 @@

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

@@ -207,3 +199,3 @@ } : _extends({}, options, {

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

@@ -238,3 +230,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 + tx.gasLimit, 0n)
// const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), ethers.BigNumber.from(0))
// txRequest.gasLimit = gasLimit

@@ -987,3 +979,3 @@

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

@@ -1018,3 +1010,3 @@ const fetch = globalThis.fetch;

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

@@ -1026,6 +1018,4 @@ } else {

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

@@ -1064,3 +1054,3 @@ }

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

@@ -1119,3 +1109,3 @@ return (await this.service.simulate({

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

@@ -1139,3 +1129,3 @@ });

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

@@ -1145,3 +1135,3 @@ walletContractAddress: address,

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

@@ -1199,6 +1189,2 @@ 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;

@@ -1220,9 +1206,5 @@ }

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: Number(txReceipt.blockNumber),
blockNumber: ethers.ethers.BigNumber.from(txReceipt.blockNumber).toNumber(),
confirmations: 1,

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

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

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

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

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

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

// Respect gasLimit request of the transaction (as long as its not 0)
if (tx.gasLimit && BigInt(tx.gasLimit || 0) !== 0n) {
if (tx.gasLimit && !ethers.ethers.BigNumber.from(tx.gasLimit || 0).eq(ethers.ethers.constants.Zero)) {
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.getBytes(code).length === 0))) {
if (tx.to === wallet && (await _this.provider.getCode(wallet).then(code => ethers.ethers.utils.arrayify(code).length === 0))) {
return DEFAULT_GAS_LIMIT;

@@ -82,4 +82,4 @@ }

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

@@ -155,3 +155,3 @@ }

// Find a transaction with a TxExecuted log
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 &&
const found = txs.find(tx => tx.logs.find(l => l.topics.length === 0 && l.data.replace('0x', '') === normalMetaTxnId || l.topics.length === 1 &&
// TxFailed event topic

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

if (found) {
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;
return _extends({
receipt: found
}, await retry(() => _this2.provider.getTransaction(found.transactionHash), `unable to get transaction ${found.transactionHash}`));
}

@@ -195,7 +187,7 @@

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

@@ -207,3 +199,3 @@ } : _extends({}, options, {

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

@@ -238,3 +230,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 + tx.gasLimit, 0n)
// const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), ethers.BigNumber.from(0))
// txRequest.gasLimit = gasLimit

@@ -987,3 +979,3 @@

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

@@ -1018,3 +1010,3 @@ const fetch = globalThis.fetch;

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

@@ -1026,6 +1018,4 @@ } else {

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

@@ -1064,3 +1054,3 @@ }

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

@@ -1119,3 +1109,3 @@ return (await this.service.simulate({

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

@@ -1139,3 +1129,3 @@ });

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

@@ -1145,3 +1135,3 @@ walletContractAddress: address,

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

@@ -1199,6 +1189,2 @@ 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;

@@ -1220,9 +1206,5 @@ }

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: Number(txReceipt.blockNumber),
blockNumber: ethers.ethers.BigNumber.from(txReceipt.blockNumber).toNumber(),
confirmations: 1,

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

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

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

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

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

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

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

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

// Respect gasLimit request of the transaction (as long as its not 0)
if (tx.gasLimit && BigInt(tx.gasLimit || 0) !== 0n) {
if (tx.gasLimit && !ethers.BigNumber.from(tx.gasLimit || 0).eq(ethers.constants.Zero)) {
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.getBytes(code).length === 0))) {
if (tx.to === wallet && (await _this.provider.getCode(wallet).then(code => ethers.utils.arrayify(code).length === 0))) {
return DEFAULT_GAS_LIMIT;

@@ -78,4 +78,4 @@ }

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

@@ -151,3 +151,3 @@ }

// Find a transaction with a TxExecuted log
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 &&
const found = txs.find(tx => tx.logs.find(l => l.topics.length === 0 && l.data.replace('0x', '') === normalMetaTxnId || l.topics.length === 1 &&
// TxFailed event topic

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

if (found) {
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;
return _extends({
receipt: found
}, await retry(() => _this2.provider.getTransaction(found.transactionHash), `unable to get transaction ${found.transactionHash}`));
}

@@ -191,7 +183,7 @@

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

@@ -203,3 +195,3 @@ } : _extends({}, options, {

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

@@ -234,3 +226,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 + tx.gasLimit, 0n)
// const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), ethers.BigNumber.from(0))
// txRequest.gasLimit = gasLimit

@@ -983,3 +975,3 @@

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

@@ -1014,3 +1006,3 @@ const fetch = globalThis.fetch;

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

@@ -1022,6 +1014,4 @@ } else {

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

@@ -1060,3 +1050,3 @@ }

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

@@ -1115,3 +1105,3 @@ return (await this.service.simulate({

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

@@ -1135,3 +1125,3 @@ });

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

@@ -1141,3 +1131,3 @@ walletContractAddress: address,

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

@@ -1195,6 +1185,2 @@ 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;

@@ -1216,9 +1202,5 @@ }

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: Number(txReceipt.blockNumber),
blockNumber: ethers.BigNumber.from(txReceipt.blockNumber).toNumber(),
confirmations: 1,

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

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

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

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

}>;
getFeeOptionsRaw(entrypoint: string, data: ethers.BytesLike, options?: {
getFeeOptionsRaw(entrypoint: string, data: ethers.utils.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?: ethers.BlockTag): Promise<ethers.BigNumberish>;
getNonce(address: string, space?: ethers.BigNumberish, blockTag?: providers.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 { ethers } from 'ethers';
import { Signer as AbstractSigner, providers, BytesLike } 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: ethers.Signer;
signer: AbstractSigner;
};

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

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

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

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

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

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

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

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

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

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

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

}>;
abstract getFeeOptionsRaw(entrypoint: string, data: ethers.BytesLike, options?: {
abstract getFeeOptionsRaw(entrypoint: string, data: ethers.utils.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?: ethers.BlockTag): Promise<ethers.BigNumberish>;
wait(metaTxnId: string | commons.transaction.SignedTransactionBundle, timeoutDuration?: number, delay?: number, maxFails?: number): Promise<ethers.TransactionResponse & {
receipt: ethers.TransactionReceipt;
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;
}>;
}

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

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

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

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

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

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

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

{
"name": "@0xsequence/relayer",
"version": "0.0.0-20240812142652",
"version": "0.0.0-20240814043648",
"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-20240812142652",
"@0xsequence/core": "0.0.0-20240812142652",
"@0xsequence/utils": "0.0.0-20240812142652"
"@0xsequence/abi": "0.0.0-20240814043648",
"@0xsequence/core": "0.0.0-20240814043648",
"@0xsequence/utils": "0.0.0-20240814043648"
},
"peerDependencies": {
"ethers": ">=6"
"ethers": ">=5.5 < 6"
},
"devDependencies": {
"@0xsequence/wallet-contracts": "^3.0.1",
"ethers": "^6.13.0",
"@0xsequence/signhub": "0.0.0-20240812142652",
"@0xsequence/tests": "0.0.0-20240812142652"
"@0xsequence/wallet-contracts": "^1.10.0",
"ethers": "^5.7.2",
"@0xsequence/signhub": "0.0.0-20240814043648",
"@0xsequence/tests": "0.0.0-20240814043648"
},

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

"test:run": "pnpm test:file tests/**/*.spec.ts",
"test:file": "NODE_OPTIONS='--import tsx' mocha --timeout 60000",
"test:file": "NODE_OPTIONS='--import tsx' mocha --timeout 30000",
"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 } from 'ethers'
import { ethers, providers } from 'ethers'
import { proto } from './rpc-relayer'

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

entrypoint: string,
data: ethers.BytesLike,
data: ethers.utils.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?: ethers.BlockTag): Promise<ethers.BigNumberish>
getNonce(address: string, space?: ethers.BigNumberish, blockTag?: providers.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 { ethers } from 'ethers'
import { Signer as AbstractSigner, providers, BytesLike } from 'ethers'
import { logger } from '@0xsequence/utils'

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

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

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

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

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

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

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

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

@@ -69,3 +65,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 + tx.gasLimit, 0n)
// const gasLimit = signedTxs.transactions.reduce((sum, tx) => sum.add(tx.gasLimit), ethers.BigNumber.from(0))
// txRequest.gasLimit = gasLimit

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

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

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

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

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

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

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

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

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

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

// Respect gasLimit request of the transaction (as long as its not 0)
if (tx.gasLimit && BigInt(tx.gasLimit || 0) !== 0n) {
if (tx.gasLimit && !ethers.BigNumber.from(tx.gasLimit || 0).eq(ethers.constants.Zero)) {
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.getBytes(code).length === 0))) {
if (tx.to === wallet && (await this.provider.getCode(wallet).then(code => ethers.utils.arrayify(code).length === 0))) {
return DEFAULT_GAS_LIMIT

@@ -103,8 +103,8 @@ }

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

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

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

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

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

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

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

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

if (found) {
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}`)
return {
receipt: found,
...(await retry(
() => this.provider.getTransaction(found.transactionHash),
`unable to get transaction ${found.transactionHash}`
))
}
// 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
}

@@ -250,3 +246,3 @@

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

@@ -253,0 +249,0 @@ timedOut = true

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

to: entrypoint,
data: ethers.hexlify(data),
data: ethers.utils.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 ? toHexString(BigInt(space)) : undefined
const encodedNonce = space !== undefined ? ethers.BigNumber.from(space).toHexString() : undefined
const resp = await this.service.getMetaTxnNonce({ walletContractAddress: address, space: encodedNonce })
const nonce = BigInt(resp.nonce)
const nonce = ethers.BigNumber.from(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.TransactionReceipt | null> => Promise.reject(new Error('impossible'))
wait: (_confirmations?: number): Promise<ethers.providers.TransactionReceipt> => Promise.reject(new Error('impossible'))
}
const wait = async (confirmations?: number): Promise<ethers.TransactionReceipt | null> => {
const wait = async (confirmations?: number): Promise<ethers.providers.TransactionReceipt> => {
if (!this.provider) {

@@ -269,5 +269,2 @@ 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

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

// 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: Number(txReceipt.blockNumber),
blockNumber: ethers.BigNumber.from(txReceipt.blockNumber).toNumber(),
confirmations: 1,

@@ -311,0 +305,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