Skip to content

Commit e4ea0c9

Browse files
authored
Migrate ChainId from bigint to number (#841)
* Migrating Network and ChainId configs from bigint to number * Migrating packages from chainId: bigint to number * Fixing chainId related tests for packages/wallet/primitives * Fixing chainId related tests for packages/wallet/core * Fixing chainId related tests for packages/wallet/wdk
1 parent c1e11c8 commit e4ea0c9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+525
-496
lines changed

packages/wallet/core/src/envelope.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Address, Hex } from 'ox'
33

44
export type Envelope<T extends Payload.Payload> = {
55
readonly wallet: Address.Address
6-
readonly chainId: bigint
6+
readonly chainId: number
77
readonly configuration: Config.Config
88
readonly payload: T
99
}
@@ -67,7 +67,7 @@ export function encodeSignature(envelope: Signed<Payload.Payload>): Signature.Ra
6767
(s) => signatureForLeaf(envelope, s)?.signature,
6868
)
6969
return {
70-
noChainId: envelope.chainId === 0n,
70+
noChainId: envelope.chainId === 0,
7171
configuration: { ...envelope.configuration, topology },
7272
}
7373
}

packages/wallet/core/src/preconditions/selectors.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import { Precondition, NativeBalancePrecondition, Erc20BalancePrecondition } from './types.js'
22
import { IntentPrecondition, decodePreconditions } from './codec.js'
33

4-
export function extractChainID(precondition: IntentPrecondition): bigint | undefined {
4+
export function extractChainID(precondition: IntentPrecondition): number | undefined {
55
if (!precondition) {
66
return undefined
77
}
88

99
try {
1010
const data = JSON.parse(precondition.data)
11-
return data.chainID ? BigInt(data.chainID) : undefined
11+
return data.chainID ? Number(data.chainID) : undefined
1212
} catch (e) {
1313
return undefined
1414
}

packages/wallet/core/src/relayer/bundler.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ export interface Bundler {
1313
payload: Payload.Calls4337_07,
1414
): Promise<{ speed?: 'slow' | 'standard' | 'fast'; payload: Payload.Calls4337_07 }[]>
1515
relay(entrypoint: Address.Address, userOperation: UserOperation.RpcV07): Promise<{ opHash: Hex.Hex }>
16-
status(opHash: Hex.Hex, chainId: bigint): Promise<OperationStatus>
16+
status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus>
1717

18-
isAvailable(entrypoint: Address.Address, chainId: bigint): Promise<boolean>
18+
isAvailable(entrypoint: Address.Address, chainId: number): Promise<boolean>
1919
}
2020

2121
export function isBundler(relayer: any): relayer is Bundler {

packages/wallet/core/src/relayer/bundlers/pimlico.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ export class PimlicoBundler implements Bundler {
2828
this.bundlerRpcUrl = bundlerRpcUrl
2929
}
3030

31-
async isAvailable(entrypoint: Address.Address, chainId: bigint): Promise<boolean> {
31+
async isAvailable(entrypoint: Address.Address, chainId: number): Promise<boolean> {
3232
const [bundlerChainId, supportedEntryPoints] = await Promise.all([
3333
this.bundlerRpc<string>('eth_chainId', []),
3434
this.bundlerRpc<Address.Address[]>('eth_supportedEntryPoints', []),
3535
])
3636

37-
if (chainId !== BigInt(bundlerChainId)) {
37+
if (chainId !== Number(bundlerChainId)) {
3838
return false
3939
}
4040

@@ -103,7 +103,7 @@ export class PimlicoBundler implements Bundler {
103103
}
104104
}
105105

106-
async status(opHash: Hex.Hex, _chainId: bigint): Promise<OperationStatus> {
106+
async status(opHash: Hex.Hex, _chainId: number): Promise<OperationStatus> {
107107
try {
108108
type PimlicoStatusResp = {
109109
status: 'not_found' | 'not_submitted' | 'submitted' | 'rejected' | 'included' | 'failed' | 'reverted'

packages/wallet/core/src/relayer/relayer.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ export interface Relayer {
6161
type: string
6262
id: string
6363

64-
isAvailable(wallet: Address.Address, chainId: bigint): Promise<boolean>
64+
isAvailable(wallet: Address.Address, chainId: number): Promise<boolean>
6565

6666
feeOptions(
6767
wallet: Address.Address,
68-
chainId: bigint,
68+
chainId: number,
6969
calls: Payload.Call[],
7070
): Promise<{ options: FeeOption[]; quote?: FeeQuote }>
7171

72-
relay(to: Address.Address, data: Hex.Hex, chainId: bigint, quote?: FeeQuote): Promise<{ opHash: Hex.Hex }>
72+
relay(to: Address.Address, data: Hex.Hex, chainId: number, quote?: FeeQuote): Promise<{ opHash: Hex.Hex }>
7373

74-
status(opHash: Hex.Hex, chainId: bigint): Promise<OperationStatus>
74+
status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus>
7575

7676
checkPrecondition(precondition: Precondition.Precondition): Promise<boolean>
7777
}

packages/wallet/core/src/relayer/standard/eip6963.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ export class EIP6963Relayer implements Relayer {
1919
this.relayer = new LocalRelayer(new EIP1193ProviderAdapter(detail.provider))
2020
}
2121

22-
isAvailable(wallet: Address.Address, chainId: bigint): Promise<boolean> {
22+
isAvailable(wallet: Address.Address, chainId: number): Promise<boolean> {
2323
return this.relayer.isAvailable(wallet, chainId)
2424
}
2525

2626
feeOptions(
2727
wallet: Address.Address,
28-
chainId: bigint,
28+
chainId: number,
2929
calls: Payload.Call[],
3030
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
3131
return this.relayer.feeOptions(wallet, chainId, calls)
3232
}
3333

34-
async relay(to: Address.Address, data: Hex.Hex, chainId: bigint, _?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
34+
async relay(to: Address.Address, data: Hex.Hex, chainId: number, _?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
3535
return this.relayer.relay(to, data, chainId)
3636
}
3737

38-
status(opHash: Hex.Hex, chainId: bigint): Promise<OperationStatus> {
38+
status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus> {
3939
return this.relayer.status(opHash, chainId)
4040
}
4141

packages/wallet/core/src/relayer/standard/local.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import {
1616
type GenericProviderTransactionReceipt = 'success' | 'failed' | 'unknown'
1717

1818
export interface GenericProvider {
19-
sendTransaction(args: { to: Address.Address; data: Hex.Hex }, chainId: bigint): Promise<string | undefined>
19+
sendTransaction(args: { to: Address.Address; data: Hex.Hex }, chainId: number): Promise<string | undefined>
2020
getBalance(address: Address.Address): Promise<bigint>
2121
call(args: { to: Address.Address; data: Hex.Hex }): Promise<string>
22-
getTransactionReceipt(txHash: Hex.Hex, chainId: bigint): Promise<GenericProviderTransactionReceipt>
22+
getTransactionReceipt(txHash: Hex.Hex, chainId: number): Promise<GenericProviderTransactionReceipt>
2323
}
2424

2525
export class LocalRelayer implements Relayer {
@@ -29,7 +29,7 @@ export class LocalRelayer implements Relayer {
2929

3030
constructor(public readonly provider: GenericProvider) {}
3131

32-
isAvailable(_wallet: Address.Address, _chainId: bigint): Promise<boolean> {
32+
isAvailable(_wallet: Address.Address, _chainId: number): Promise<boolean> {
3333
return Promise.resolve(true)
3434
}
3535

@@ -49,7 +49,7 @@ export class LocalRelayer implements Relayer {
4949

5050
feeOptions(
5151
wallet: Address.Address,
52-
chainId: bigint,
52+
chainId: number,
5353
calls: Payload.Call[],
5454
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
5555
return Promise.resolve({ options: [] })
@@ -72,7 +72,7 @@ export class LocalRelayer implements Relayer {
7272
async relay(
7373
to: Address.Address,
7474
data: Hex.Hex,
75-
chainId: bigint,
75+
chainId: number,
7676
quote?: FeeQuote,
7777
preconditions?: IntentPrecondition[],
7878
checkInterval: number = 5000,
@@ -151,7 +151,7 @@ export class LocalRelayer implements Relayer {
151151
})
152152
}
153153

154-
async status(opHash: Hex.Hex, chainId: bigint): Promise<OperationStatus> {
154+
async status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus> {
155155
const receipt = await this.provider.getTransactionReceipt(opHash, chainId)
156156
if (receipt === 'unknown') {
157157
// Could be pending but we don't know
@@ -272,7 +272,7 @@ export class LocalRelayer implements Relayer {
272272
export class EIP1193ProviderAdapter implements GenericProvider {
273273
constructor(private readonly provider: EIP1193Provider) {}
274274

275-
private async trySwitchChain(chainId: bigint) {
275+
private async trySwitchChain(chainId: number) {
276276
try {
277277
await this.provider.request({
278278
method: 'wallet_switchEthereumChain',
@@ -288,7 +288,7 @@ export class EIP1193ProviderAdapter implements GenericProvider {
288288
}
289289
}
290290

291-
async sendTransaction(args: { to: Address.Address; data: Hex.Hex }, chainId: bigint) {
291+
async sendTransaction(args: { to: Address.Address; data: Hex.Hex }, chainId: number) {
292292
const accounts: Address.Address[] = await this.provider.request({ method: 'eth_requestAccounts' })
293293
const from = accounts[0]
294294

@@ -328,7 +328,7 @@ export class EIP1193ProviderAdapter implements GenericProvider {
328328
})
329329
}
330330

331-
async getTransactionReceipt(txHash: Hex.Hex, chainId: bigint) {
331+
async getTransactionReceipt(txHash: Hex.Hex, chainId: number) {
332332
await this.trySwitchChain(chainId)
333333

334334
const rpcReceipt = await this.provider.request({ method: 'eth_getTransactionReceipt', params: [txHash] })

packages/wallet/core/src/relayer/standard/pk-relayer.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class PkRelayer implements Relayer {
1616
const relayerAddress = Address.fromPublicKey(Secp256k1.getPublicKey({ privateKey }))
1717
this.relayer = new LocalRelayer({
1818
sendTransaction: async (args, chainId) => {
19-
const providerChainId = BigInt(await this.provider.request({ method: 'eth_chainId' }))
19+
const providerChainId = Number(await this.provider.request({ method: 'eth_chainId' }))
2020
if (providerChainId !== chainId) {
2121
throw new Error('Provider chain id does not match relayer chain id')
2222
}
@@ -83,10 +83,10 @@ export class PkRelayer implements Relayer {
8383
const callArgs = { to: args.to as `0x${string}`, data: args.data as `0x${string}` }
8484
return await this.provider.request({ method: 'eth_call', params: [callArgs, 'latest'] })
8585
},
86-
getTransactionReceipt: async (txHash: string, chainId: bigint) => {
86+
getTransactionReceipt: async (txHash: string, chainId: number) => {
8787
Hex.assert(txHash)
8888

89-
const providerChainId = BigInt(await this.provider.request({ method: 'eth_chainId' }))
89+
const providerChainId = Number(await this.provider.request({ method: 'eth_chainId' }))
9090
if (providerChainId !== chainId) {
9191
throw new Error('Provider chain id does not match relayer chain id')
9292
}
@@ -101,28 +101,28 @@ export class PkRelayer implements Relayer {
101101
})
102102
}
103103

104-
async isAvailable(_wallet: Address.Address, chainId: bigint): Promise<boolean> {
105-
const providerChainId = BigInt(await this.provider.request({ method: 'eth_chainId' }))
104+
async isAvailable(_wallet: Address.Address, chainId: number): Promise<boolean> {
105+
const providerChainId = Number(await this.provider.request({ method: 'eth_chainId' }))
106106
return providerChainId === chainId
107107
}
108108

109109
feeOptions(
110110
wallet: Address.Address,
111-
chainId: bigint,
111+
chainId: number,
112112
calls: Payload.Call[],
113113
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
114114
return this.relayer.feeOptions(wallet, chainId, calls)
115115
}
116116

117-
async relay(to: Address.Address, data: Hex.Hex, chainId: bigint, _?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
118-
const providerChainId = BigInt(await this.provider.request({ method: 'eth_chainId' }))
117+
async relay(to: Address.Address, data: Hex.Hex, chainId: number, _?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
118+
const providerChainId = Number(await this.provider.request({ method: 'eth_chainId' }))
119119
if (providerChainId !== chainId) {
120120
throw new Error('Provider chain id does not match relayer chain id')
121121
}
122122
return this.relayer.relay(to, data, chainId)
123123
}
124124

125-
status(opHash: Hex.Hex, chainId: bigint): Promise<OperationStatus> {
125+
status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus> {
126126
return this.relayer.status(opHash, chainId)
127127
}
128128

packages/wallet/core/src/relayer/standard/rpc/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ export class RpcRelayer implements Relayer {
6262
})
6363
}
6464

65-
isAvailable(_wallet: Address.Address, chainId: bigint): Promise<boolean> {
66-
return Promise.resolve(BigInt(this.chainId) === chainId)
65+
isAvailable(_wallet: Address.Address, chainId: number): Promise<boolean> {
66+
return Promise.resolve(this.chainId === chainId)
6767
}
6868

6969
async feeOptions(
7070
wallet: Address.Address,
71-
chainId: bigint,
71+
chainId: number,
7272
calls: Payload.Call[],
7373
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
7474
const callsStruct: Payload.Calls = { type: 'call', space: 0n, nonce: 0n, calls: calls }
@@ -103,7 +103,7 @@ export class RpcRelayer implements Relayer {
103103
walletAddress: Address.Address,
104104
to: Address.Address,
105105
data: Hex.Hex,
106-
chainId: bigint,
106+
chainId: number,
107107
quote?: FeeQuote,
108108
preconditions?: IntentPrecondition[],
109109
): Promise<{ opHash: Hex.Hex }> {
@@ -131,7 +131,7 @@ export class RpcRelayer implements Relayer {
131131
async relay(
132132
to: Address.Address,
133133
data: Hex.Hex,
134-
chainId: bigint,
134+
chainId: number,
135135
quote?: FeeQuote,
136136
preconditions?: IntentPrecondition[],
137137
): Promise<{ opHash: Hex.Hex }> {
@@ -156,7 +156,7 @@ export class RpcRelayer implements Relayer {
156156
return { opHash: `0x${result.txnHash}` }
157157
}
158158

159-
async status(opHash: Hex.Hex, chainId: bigint): Promise<OperationStatus> {
159+
async status(opHash: Hex.Hex, chainId: number): Promise<OperationStatus> {
160160
try {
161161
const cleanedOpHash = opHash.startsWith('0x') ? opHash.substring(2) : opHash
162162
const result = await this.client.getMetaTxnReceipt({ metaTxID: cleanedOpHash })

packages/wallet/core/src/relayer/standard/sequence.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ export class SequenceRelayer implements Relayer {
1414
this.service = new Service(host, fetch)
1515
}
1616

17-
async isAvailable(_wallet: Address.Address, _chainId: bigint): Promise<boolean> {
17+
async isAvailable(_wallet: Address.Address, _chainId: number): Promise<boolean> {
1818
return true
1919
}
2020

2121
async feeOptions(
2222
wallet: Address.Address,
23-
_chainId: bigint,
23+
_chainId: number,
2424
calls: Payload.Call[],
2525
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
2626
const to = wallet // TODO: this might be the guest module
@@ -42,7 +42,7 @@ export class SequenceRelayer implements Relayer {
4242
return false
4343
}
4444

45-
async relay(to: Address.Address, data: Hex.Hex, _chainId: bigint, quote?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
45+
async relay(to: Address.Address, data: Hex.Hex, _chainId: number, quote?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
4646
const walletAddress = to // TODO: pass wallet address or stop requiring it
4747

4848
const { txnHash } = await this.service.sendMetaTxn({
@@ -53,7 +53,7 @@ export class SequenceRelayer implements Relayer {
5353
return { opHash: `0x${txnHash}` }
5454
}
5555

56-
async status(opHash: Hex.Hex, _chainId: bigint): Promise<OperationStatus> {
56+
async status(opHash: Hex.Hex, _chainId: number): Promise<OperationStatus> {
5757
try {
5858
const {
5959
receipt: { status, revertReason, txnReceipt },

0 commit comments

Comments
 (0)