@0xsequence/relayer 0.43.33 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,35 +0,0 @@
1
- import { ethers, providers } from 'ethers';
2
- import { WalletContext } from '@0xsequence/network';
3
- import { WalletConfig, DecodedSignature } from '@0xsequence/config';
4
- import { SignedTransactions, Transaction } from '@0xsequence/transactions';
5
- import { Optionals } from '@0xsequence/utils';
6
- export interface BaseRelayerOptions {
7
- bundleCreation?: boolean;
8
- creationGasLimit?: ethers.BigNumberish;
9
- provider?: ethers.providers.Provider;
10
- }
11
- export declare function isBaseRelayerOptions(obj: any): obj is BaseRelayerOptions;
12
- export declare const BaseRelayerDefaults: Omit<Required<Optionals<BaseRelayerOptions>>, 'provider'>;
13
- export declare class BaseRelayer {
14
- readonly provider: providers.Provider | undefined;
15
- readonly bundleCreation: boolean;
16
- creationGasLimit: ethers.BigNumber;
17
- constructor(options?: BaseRelayerOptions);
18
- isWalletDeployed(walletAddress: string): Promise<boolean>;
19
- prepareWalletDeploy(config: WalletConfig, context: WalletContext): {
20
- to: string;
21
- data: string;
22
- };
23
- prependWalletDeploy(signedTransactions: Pick<SignedTransactions, 'config' | 'context' | 'transactions' | 'nonce' | 'signature'>): Promise<{
24
- to: string;
25
- execute: {
26
- transactions: Transaction[];
27
- nonce: ethers.BigNumber;
28
- signature: string;
29
- };
30
- }>;
31
- prepareTransactions(config: WalletConfig, context: WalletContext, signature: string | Promise<string> | DecodedSignature | Promise<DecodedSignature>, ...transactions: Transaction[]): Promise<{
32
- to: string;
33
- data: string;
34
- }>;
35
- }
@@ -1,136 +0,0 @@
1
- import { ethers, providers, utils } from 'ethers'
2
- import { walletContracts } from '@0xsequence/abi'
3
- import { WalletContext } from '@0xsequence/network'
4
- import { WalletConfig, addressOf, imageHash, DecodedSignature, encodeSignature } from '@0xsequence/config'
5
- import { SignedTransactions, Transaction, sequenceTxAbiEncode, readSequenceNonce } from '@0xsequence/transactions'
6
- import { isBigNumberish, Optionals } from '@0xsequence/utils'
7
-
8
-
9
- export interface BaseRelayerOptions {
10
- bundleCreation?: boolean
11
- creationGasLimit?: ethers.BigNumberish
12
- provider?: ethers.providers.Provider
13
- }
14
-
15
- export function isBaseRelayerOptions(obj: any): obj is BaseRelayerOptions {
16
- return (
17
- (obj.bundleCreation !== undefined && typeof obj.bundleCreation === 'boolean') ||
18
- (obj.creationGasLimit !== undefined && isBigNumberish(obj.creationGasLimit)) ||
19
- (obj.provider !== undefined && (providers.Provider.isProvider(obj.provider) || typeof obj.provider === 'string'))
20
- )
21
- }
22
-
23
- export const BaseRelayerDefaults: Omit<Required<Optionals<BaseRelayerOptions>>, 'provider'> = {
24
- bundleCreation: true,
25
- creationGasLimit: ethers.constants.Two.pow(17)
26
- }
27
-
28
- export class BaseRelayer {
29
- readonly provider: providers.Provider | undefined
30
- public readonly bundleCreation: boolean
31
- public creationGasLimit: ethers.BigNumber
32
-
33
- constructor(options?: BaseRelayerOptions) {
34
- const opts = { ...BaseRelayerDefaults, ...options }
35
- this.bundleCreation = opts.bundleCreation
36
- this.provider = opts.provider
37
- this.creationGasLimit = ethers.BigNumber.from(opts.creationGasLimit)
38
- }
39
-
40
- async isWalletDeployed(walletAddress: string): Promise<boolean> {
41
- if (!this.provider) throw new Error('Bundled creation provider not found')
42
- return (await this.provider.getCode(walletAddress)) !== '0x'
43
- }
44
-
45
- prepareWalletDeploy(
46
- config: WalletConfig,
47
- context: WalletContext
48
- ): { to: string, data: string} {
49
- const factoryInterface = new utils.Interface(walletContracts.factory.abi)
50
-
51
- return {
52
- to: context.factory,
53
- data: factoryInterface.encodeFunctionData(factoryInterface.getFunction('deploy'),
54
- [context.mainModule, imageHash(config)]
55
- )
56
- }
57
- }
58
-
59
- async prependWalletDeploy(
60
- signedTransactions: Pick<SignedTransactions, 'config' | 'context' | 'transactions' | 'nonce' | 'signature'>
61
- ): Promise<{ to: string, execute: { transactions: Transaction[], nonce: ethers.BigNumber, signature: string } }> {
62
- const { config, context, transactions, nonce, signature } = signedTransactions
63
- const walletAddress = addressOf(config, context)
64
- const walletInterface = new utils.Interface(walletContracts.mainModule.abi)
65
-
66
- const encodedSignature = (async () => {
67
- const sig = await signature
68
-
69
- if (typeof sig === 'string') return sig
70
- return encodeSignature(sig)
71
- })()
72
-
73
- if (this.bundleCreation && !(await this.isWalletDeployed(walletAddress))) {
74
- return {
75
- to: context.guestModule!,
76
- execute: {
77
- transactions: [
78
- {
79
- ...this.prepareWalletDeploy(config, context),
80
- delegateCall: false,
81
- revertOnError: false,
82
- gasLimit: this.creationGasLimit,
83
- value: ethers.constants.Zero
84
- },
85
- {
86
- delegateCall: false,
87
- revertOnError: true,
88
- gasLimit: ethers.constants.Zero,
89
- to: walletAddress,
90
- value: ethers.constants.Zero,
91
- data: walletInterface.encodeFunctionData(walletInterface.getFunction('execute'),
92
- [
93
- sequenceTxAbiEncode(transactions),
94
- nonce,
95
- await encodedSignature
96
- ]
97
- )
98
- }
99
- ],
100
- nonce: ethers.constants.Zero,
101
- signature: '0x'
102
- }
103
- }
104
- } else {
105
- return {
106
- to: walletAddress,
107
- execute: {
108
- transactions,
109
- nonce: ethers.BigNumber.from(nonce),
110
- signature: await encodedSignature
111
- }
112
- }
113
- }
114
- }
115
-
116
- async prepareTransactions(
117
- config: WalletConfig,
118
- context: WalletContext,
119
- signature: string | Promise<string> | DecodedSignature | Promise<DecodedSignature>,
120
- ...transactions: Transaction[]
121
- ): Promise<{ to: string, data: string }> { //, gasLimit?: ethers.BigNumberish }> {
122
- const nonce = readSequenceNonce(...transactions)
123
- if (!nonce) {
124
- throw new Error('Unable to prepare transactions without a defined nonce')
125
- }
126
- const { to, execute } = await this.prependWalletDeploy({ config, context, transactions, nonce, signature })
127
- const walletInterface = new utils.Interface(walletContracts.mainModule.abi)
128
- return {
129
- to, data: walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [
130
- sequenceTxAbiEncode(execute.transactions),
131
- execute.nonce,
132
- execute.signature
133
- ])
134
- }
135
- }
136
- }