Skip to content

Commit c75e77f

Browse files
Seq.js uses to address for feeOptions (#962)
1 parent 93aa730 commit c75e77f

9 files changed

Lines changed: 22 additions & 25 deletions

File tree

packages/services/relayer/src/relayer/relayer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface Relayer {
1616
feeOptions(
1717
wallet: Address.Address,
1818
chainId: number,
19+
to: Address.Address,
1920
calls: Payload.Call[],
2021
): Promise<{ options: FeeOption[]; quote?: FeeQuote }>
2122

packages/services/relayer/src/relayer/rpc-relayer/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ export class RpcRelayer implements Relayer {
134134
async feeOptions(
135135
wallet: Address.Address,
136136
chainId: number,
137+
to: Address.Address,
137138
calls: Payload.Call[],
138139
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
139140
const callsStruct: Payload.Calls = { type: 'call', space: 0n, nonce: 0n, calls: calls }
@@ -142,8 +143,8 @@ export class RpcRelayer implements Relayer {
142143
try {
143144
const result = await this.client.feeOptions(
144145
{
145-
wallet: wallet,
146-
to: wallet,
146+
wallet,
147+
to,
147148
data: Bytes.toHex(data),
148149
},
149150
{ ...(this.projectAccessKey ? { 'X-Access-Key': this.projectAccessKey } : undefined) },

packages/services/relayer/src/relayer/standard/eip6963.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,10 @@ export class EIP6963Relayer implements Relayer {
3030
feeOptions(
3131
wallet: Address.Address,
3232
chainId: number,
33+
to: Address.Address,
3334
calls: Payload.Call[],
3435
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
35-
return this.relayer.feeOptions(wallet, chainId, calls)
36+
return this.relayer.feeOptions(wallet, chainId, to, calls)
3637
}
3738

3839
async relay(to: Address.Address, data: Hex.Hex, chainId: number, _?: FeeQuote): Promise<{ opHash: Hex.Hex }> {

packages/services/relayer/src/relayer/standard/local.ts

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,14 @@ export class LocalRelayer implements Relayer {
5454
}
5555

5656
feeOptions(
57-
wallet: Address.Address,
58-
chainId: number,
59-
calls: Payload.Call[],
57+
_wallet: Address.Address,
58+
_chainId: number,
59+
_to: Address.Address,
60+
_calls: Payload.Call[],
6061
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
6162
return Promise.resolve({ options: [] })
6263
}
6364

64-
private decodeCalls(data: Hex.Hex): Payload.Calls {
65-
const executeSelector = AbiFunction.getSelector(Constants.EXECUTE)
66-
67-
let packedPayload
68-
if (data.startsWith(executeSelector)) {
69-
const decode = AbiFunction.decodeData(Constants.EXECUTE, data)
70-
packedPayload = decode[0]
71-
} else {
72-
packedPayload = data
73-
}
74-
75-
return Payload.decode(Bytes.fromHex(packedPayload))
76-
}
77-
7865
async relay(
7966
to: Address.Address,
8067
data: Hex.Hex,

packages/services/relayer/src/relayer/standard/pk-relayer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,10 @@ export class PkRelayer implements Relayer {
114114
feeOptions(
115115
wallet: Address.Address,
116116
chainId: number,
117+
to: Address.Address,
117118
calls: Payload.Call[],
118119
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
119-
return this.relayer.feeOptions(wallet, chainId, calls)
120+
return this.relayer.feeOptions(wallet, chainId, to, calls)
120121
}
121122

122123
async relay(to: Address.Address, data: Hex.Hex, chainId: number, _?: FeeQuote): Promise<{ opHash: Hex.Hex }> {

packages/services/relayer/src/relayer/standard/sequence.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ export class SequenceRelayer implements Relayer {
3636
async feeOptions(
3737
wallet: Address.Address,
3838
_chainId: number,
39+
to: Address.Address,
3940
calls: Payload.Call[],
4041
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
41-
const to = wallet // TODO: this might be the guest module
4242
const execute = AbiFunction.from('function execute(bytes calldata _payload, bytes calldata _signature)')
4343
const payload = Payload.encode({ type: 'call', space: 0n, nonce: 0n, calls }, to)
4444
const signature = '0x0001' // TODO: use a stub signature

packages/services/relayer/test/relayer/relayer.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ describe('Relayer', () => {
310310
const isAvailable = await mockRelayer.isAvailable(TEST_WALLET_ADDRESS, TEST_CHAIN_ID)
311311
expect(isAvailable).toBe(true)
312312

313-
const feeOptions = await mockRelayer.feeOptions(TEST_WALLET_ADDRESS, TEST_CHAIN_ID, [])
313+
const feeOptions = await mockRelayer.feeOptions(TEST_WALLET_ADDRESS, TEST_CHAIN_ID, TEST_TO_ADDRESS, [])
314314
expect(feeOptions.options).toEqual([])
315315

316316
const relayResult = await mockRelayer.relay(TEST_TO_ADDRESS, TEST_DATA, TEST_CHAIN_ID)

packages/wallet/dapp-client/src/ChainSessionManager.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,9 @@ export class ChainSessionManager {
851851
createdAtMs: Date.now(),
852852
}
853853
}
854-
const feeOptions = await this.relayer.feeOptions(signedCall.to, this.chainId, callsToSend)
854+
const walletAddress = this.walletAddress
855+
if (!walletAddress) throw new InitializationError('Wallet is not initialized.')
856+
const feeOptions = await this.relayer.feeOptions(walletAddress, this.chainId, signedCall.to, callsToSend)
855857
return feeOptions.options
856858
} catch (err) {
857859
throw new FeeOptionError(`Failed to get fee options: ${err instanceof Error ? err.message : String(err)}`)

packages/wallet/wdk/src/sequence/transactions.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,11 @@ export class Transactions implements TransactionsInterface {
347347
return []
348348
}
349349

350-
const feeOptions = await relayer.feeOptions(tx.wallet, tx.envelope.chainId, tx.envelope.payload.calls)
350+
// Determine the to address for the built transaction
351+
const walletStatus = await wallet.getStatus(provider)
352+
const to = walletStatus.isDeployed ? wallet.address : wallet.guest
353+
354+
const feeOptions = await relayer.feeOptions(tx.wallet, tx.envelope.chainId, to, tx.envelope.payload.calls)
351355

352356
if (feeOptions.options.length === 0) {
353357
const { name, icon } = relayer instanceof Relayer.EIP6963.EIP6963Relayer ? relayer.info : {}

0 commit comments

Comments
 (0)