@0xsequence/account 1.10.14 → 2.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.
@@ -15,10 +15,10 @@ export class AccountOrchestratorWrapper implements signers.SapientSigner {
15
15
  return this.account.address
16
16
  }
17
17
 
18
- getChainIdFromMetadata(metadata: object): ethers.BigNumber {
18
+ getChainIdFromMetadata(metadata: object): bigint {
19
19
  try {
20
20
  const { chainId } = metadata as MetadataWithChainId
21
- return ethers.BigNumber.from(chainId)
21
+ return BigInt(chainId)
22
22
  } catch (err) {
23
23
  // Invalid metadata object
24
24
  throw new Error('AccountOrchestratorWrapper only supports metadata with chain id')
@@ -46,7 +46,7 @@ export class AccountOrchestratorWrapper implements signers.SapientSigner {
46
46
  return this.account.decorateTransactions(bundle, status)
47
47
  }
48
48
 
49
- sign(message: ethers.utils.BytesLike, metadata: object): Promise<ethers.utils.BytesLike> {
49
+ sign(message: ethers.BytesLike, metadata: object): Promise<ethers.BytesLike> {
50
50
  if (!commons.isWalletSignRequestMetadata(metadata)) {
51
51
  throw new Error('AccountOrchestratorWrapper only supports wallet metadata requests')
52
52
  }
@@ -63,7 +63,7 @@ export class AccountOrchestratorWrapper implements signers.SapientSigner {
63
63
 
64
64
  notifyStatusChange(_i: string, _s: Status, _m: object): void {}
65
65
 
66
- suffix(): ethers.utils.BytesLike {
67
- return [3]
66
+ suffix(): ethers.BytesLike {
67
+ return new Uint8Array([3])
68
68
  }
69
69
  }
package/src/signer.ts CHANGED
@@ -3,14 +3,14 @@ import { Account } from './account'
3
3
  import { ethers } from 'ethers'
4
4
  import { commons } from '@0xsequence/core'
5
5
  import { FeeOption, proto } from '@0xsequence/relayer'
6
- import { isDeferrable } from './utils'
6
+ import { toHexString } from '@0xsequence/utils'
7
7
 
8
8
  export type AccountSignerOptions = {
9
9
  nonceSpace?: ethers.BigNumberish
10
10
  cantValidateBehavior?: 'ignore' | 'eip6492' | 'throw'
11
11
  stubSignatureOverrides?: Map<string, string>
12
12
  selectFee?: (
13
- txs: ethers.utils.Deferrable<ethers.providers.TransactionRequest> | commons.transaction.Transactionish,
13
+ txs: ethers.TransactionRequest | commons.transaction.Transactionish,
14
14
  options: FeeOption[]
15
15
  ) => Promise<FeeOption | undefined>
16
16
  }
@@ -18,7 +18,7 @@ export type AccountSignerOptions = {
18
18
  function encodeGasRefundTransaction(option?: FeeOption) {
19
19
  if (!option) return []
20
20
 
21
- const value = ethers.BigNumber.from(option.value)
21
+ const value = BigInt(option.value)
22
22
 
23
23
  switch (option.token.type) {
24
24
  case proto.FeeTokenType.UNKNOWN:
@@ -28,8 +28,8 @@ function encodeGasRefundTransaction(option?: FeeOption) {
28
28
  revertOnError: true,
29
29
  gasLimit: option.gasLimit,
30
30
  to: option.to,
31
- value: value.toHexString(),
32
- data: []
31
+ value: toHexString(value),
32
+ data: '0x'
33
33
  }
34
34
  ]
35
35
 
@@ -45,7 +45,7 @@ function encodeGasRefundTransaction(option?: FeeOption) {
45
45
  gasLimit: option.gasLimit,
46
46
  to: option.token.contractAddress,
47
47
  value: 0,
48
- data: new ethers.utils.Interface([
48
+ data: new ethers.Interface([
49
49
  {
50
50
  constant: false,
51
51
  inputs: [{ type: 'address' }, { type: 'uint256' }],
@@ -53,7 +53,7 @@ function encodeGasRefundTransaction(option?: FeeOption) {
53
53
  outputs: [],
54
54
  type: 'function'
55
55
  }
56
- ]).encodeFunctionData('transfer', [option.to, value.toHexString()])
56
+ ]).encodeFunctionData('transfer', [option.to, toHexString(value)])
57
57
  }
58
58
  ]
59
59
 
@@ -62,9 +62,7 @@ function encodeGasRefundTransaction(option?: FeeOption) {
62
62
  }
63
63
  }
64
64
 
65
- export class AccountSigner implements ethers.Signer {
66
- public readonly _isSigner = true
67
-
65
+ export class AccountSigner implements ethers.AbstractSigner<ethers.Provider> {
68
66
  constructor(
69
67
  public account: Account,
70
68
  public chainId: ChainId,
@@ -79,14 +77,19 @@ export class AccountSigner implements ethers.Signer {
79
77
  return this.account.address
80
78
  }
81
79
 
82
- signMessage(message: string | ethers.utils.Bytes): Promise<string> {
80
+ signMessage(message: string | ethers.BytesLike): Promise<string> {
83
81
  return this.account.signMessage(message, this.chainId, this.options?.cantValidateBehavior ?? 'throw')
84
82
  }
85
83
 
86
- private async defaultSelectFee(
87
- _txs: ethers.utils.Deferrable<ethers.providers.TransactionRequest> | commons.transaction.Transactionish,
88
- options: FeeOption[]
89
- ): Promise<FeeOption | undefined> {
84
+ signTypedData(
85
+ domain: ethers.TypedDataDomain,
86
+ types: Record<string, Array<ethers.TypedDataField>>,
87
+ value: Record<string, any>
88
+ ): Promise<string> {
89
+ return this.account.signTypedData(domain, types, value, this.chainId, this.options?.cantValidateBehavior ?? 'throw')
90
+ }
91
+
92
+ private async defaultSelectFee(_txs: commons.transaction.Transactionish, options: FeeOption[]): Promise<FeeOption | undefined> {
90
93
  // If no options, return undefined
91
94
  if (options.length === 0) return undefined
92
95
 
@@ -106,14 +109,14 @@ export class AccountSigner implements ethers.Signer {
106
109
  if (option.token.type === proto.FeeTokenType.UNKNOWN) {
107
110
  // Native token
108
111
  const balance = await this.getBalance()
109
- if (balance.gte(ethers.BigNumber.from(option.value))) {
112
+ if (balance >= BigInt(option.value)) {
110
113
  return option
111
114
  }
112
115
  } else if (option.token.contractAddress && option.token.type === proto.FeeTokenType.ERC20_TOKEN) {
113
116
  // ERC20 token
114
117
  const token = new ethers.Contract(option.token.contractAddress, balanceOfAbi, this.provider)
115
118
  const balance = await token.balanceOf(this.account.address)
116
- if (balance.gte(ethers.BigNumber.from(option.value))) {
119
+ if (balance >= BigInt(option.value)) {
117
120
  return option
118
121
  }
119
122
  } else {
@@ -125,15 +128,11 @@ export class AccountSigner implements ethers.Signer {
125
128
  }
126
129
 
127
130
  async sendTransaction(
128
- txsPromise: ethers.utils.Deferrable<ethers.providers.TransactionRequest> | commons.transaction.Transactionish,
131
+ txs: commons.transaction.Transactionish,
129
132
  options?: {
130
133
  simulateForFeeOptions?: boolean
131
134
  }
132
- ): Promise<ethers.providers.TransactionResponse> {
133
- const txs = isDeferrable(txsPromise)
134
- ? await ethers.utils.resolveProperties(txsPromise as ethers.utils.Deferrable<ethers.providers.TransactionRequest>)
135
- : txsPromise
136
-
135
+ ): Promise<ethers.TransactionResponse> {
137
136
  const prepare = await this.account.prepareTransactions({
138
137
  txs,
139
138
  chainId: this.chainId,
@@ -157,18 +156,15 @@ export class AccountSigner implements ethers.Signer {
157
156
  nonceSpace: this.options.nonceSpace
158
157
  }
159
158
  : undefined
160
- ) as Promise<ethers.providers.TransactionResponse> // Will always have a transaction response
159
+ ) as Promise<ethers.TransactionResponse> // Will always have a transaction response
161
160
  }
162
161
 
163
- getBalance(blockTag?: ethers.providers.BlockTag | undefined): Promise<ethers.BigNumber> {
162
+ getBalance(blockTag?: ethers.BlockTag | undefined): Promise<bigint> {
164
163
  return this.provider.getBalance(this.account.address, blockTag)
165
164
  }
166
165
 
167
- call(
168
- transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>,
169
- blockTag?: ethers.providers.BlockTag | undefined
170
- ): Promise<string> {
171
- return this.provider.call(transaction, blockTag)
166
+ call(transaction: ethers.TransactionRequest, blockTag?: ethers.BlockTag): Promise<string> {
167
+ return this.provider.call({ ...transaction, blockTag })
172
168
  }
173
169
 
174
170
  async resolveName(name: string): Promise<string> {
@@ -177,43 +173,47 @@ export class AccountSigner implements ethers.Signer {
177
173
  return res
178
174
  }
179
175
 
180
- connect(_provider: ethers.providers.Provider): ethers.Signer {
176
+ connect(_provider: ethers.Provider): ethers.Signer {
181
177
  throw new Error('Method not implemented.')
182
178
  }
183
179
 
184
- signTransaction(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<string> {
180
+ signTransaction(transaction: ethers.TransactionRequest): Promise<string> {
185
181
  throw new Error('Method not implemented.')
186
182
  }
187
183
 
188
- getTransactionCount(blockTag?: ethers.providers.BlockTag | undefined): Promise<number> {
184
+ getTransactionCount(blockTag?: ethers.BlockTag | undefined): Promise<number> {
189
185
  throw new Error('Method not implemented.')
190
186
  }
191
187
 
192
- estimateGas(transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>): Promise<ethers.BigNumber> {
188
+ estimateGas(transaction: ethers.TransactionRequest): Promise<bigint> {
193
189
  throw new Error('Method not implemented.')
194
190
  }
195
191
 
196
192
  getChainId(): Promise<number> {
197
- return Promise.resolve(ethers.BigNumber.from(this.chainId).toNumber())
193
+ return Promise.resolve(Number(this.chainId))
194
+ }
195
+
196
+ getGasPrice(): Promise<bigint> {
197
+ throw new Error('Method not implemented.')
198
+ }
199
+
200
+ getFeeData(): Promise<ethers.FeeData> {
201
+ throw new Error('Method not implemented.')
198
202
  }
199
203
 
200
- getGasPrice(): Promise<ethers.BigNumber> {
204
+ getNonce(blockTag?: ethers.BlockTag): Promise<number> {
201
205
  throw new Error('Method not implemented.')
202
206
  }
203
207
 
204
- getFeeData(): Promise<ethers.providers.FeeData> {
208
+ populateCall(tx: ethers.TransactionRequest): Promise<ethers.TransactionLike<string>> {
205
209
  throw new Error('Method not implemented.')
206
210
  }
207
211
 
208
- checkTransaction(
209
- transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>
210
- ): ethers.utils.Deferrable<ethers.providers.TransactionRequest> {
212
+ checkTransaction(transaction: ethers.TransactionRequest): ethers.TransactionRequest {
211
213
  throw new Error('Method not implemented.')
212
214
  }
213
215
 
214
- populateTransaction(
215
- transaction: ethers.utils.Deferrable<ethers.providers.TransactionRequest>
216
- ): Promise<ethers.providers.TransactionRequest> {
216
+ async populateTransaction(tx: ethers.TransactionRequest): Promise<ethers.TransactionLike<string>> {
217
217
  throw new Error('Method not implemented.')
218
218
  }
219
219
 
package/src/utils.ts DELETED
@@ -1,14 +0,0 @@
1
- import { ethers } from 'ethers'
2
-
3
- function isPromise(value: any): value is Promise<any> {
4
- return !!value && typeof value.then === 'function'
5
- }
6
-
7
- export function isDeferrable<T>(value: any): value is ethers.utils.Deferrable<T> {
8
- // The value is deferrable if any of the properties is a Promises
9
- if (typeof value === 'object') {
10
- return Object.keys(value).some(key => isPromise(value[key]))
11
- }
12
-
13
- return false
14
- }