Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/services/relayer/src/relayer/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface Relayer {
feeOptions(
wallet: Address.Address,
chainId: number,
to: Address.Address,
calls: Payload.Call[],
): Promise<{ options: FeeOption[]; quote?: FeeQuote }>

Expand Down
5 changes: 3 additions & 2 deletions packages/services/relayer/src/relayer/rpc-relayer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ export class RpcRelayer implements Relayer {
async feeOptions(
wallet: Address.Address,
chainId: number,
to: Address.Address,
calls: Payload.Call[],
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
const callsStruct: Payload.Calls = { type: 'call', space: 0n, nonce: 0n, calls: calls }
Expand All @@ -142,8 +143,8 @@ export class RpcRelayer implements Relayer {
try {
const result = await this.client.feeOptions(
{
wallet: wallet,
to: wallet,
wallet,
to,
data: Bytes.toHex(data),
},
{ ...(this.projectAccessKey ? { 'X-Access-Key': this.projectAccessKey } : undefined) },
Expand Down
3 changes: 2 additions & 1 deletion packages/services/relayer/src/relayer/standard/eip6963.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ export class EIP6963Relayer implements Relayer {
feeOptions(
wallet: Address.Address,
chainId: number,
to: Address.Address,
calls: Payload.Call[],
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
return this.relayer.feeOptions(wallet, chainId, calls)
return this.relayer.feeOptions(wallet, chainId, to, calls)
}

async relay(to: Address.Address, data: Hex.Hex, chainId: number, _?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
Expand Down
21 changes: 4 additions & 17 deletions packages/services/relayer/src/relayer/standard/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,14 @@ export class LocalRelayer implements Relayer {
}

feeOptions(
wallet: Address.Address,
chainId: number,
calls: Payload.Call[],
_wallet: Address.Address,
_chainId: number,
_to: Address.Address,
_calls: Payload.Call[],
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
return Promise.resolve({ options: [] })
}

private decodeCalls(data: Hex.Hex): Payload.Calls {
const executeSelector = AbiFunction.getSelector(Constants.EXECUTE)

let packedPayload
if (data.startsWith(executeSelector)) {
const decode = AbiFunction.decodeData(Constants.EXECUTE, data)
packedPayload = decode[0]
} else {
packedPayload = data
}

return Payload.decode(Bytes.fromHex(packedPayload))
}

async relay(
to: Address.Address,
data: Hex.Hex,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,10 @@ export class PkRelayer implements Relayer {
feeOptions(
wallet: Address.Address,
chainId: number,
to: Address.Address,
calls: Payload.Call[],
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
return this.relayer.feeOptions(wallet, chainId, calls)
return this.relayer.feeOptions(wallet, chainId, to, calls)
}

async relay(to: Address.Address, data: Hex.Hex, chainId: number, _?: FeeQuote): Promise<{ opHash: Hex.Hex }> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ export class SequenceRelayer implements Relayer {
async feeOptions(
wallet: Address.Address,
_chainId: number,
to: Address.Address,
calls: Payload.Call[],
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
const to = wallet // TODO: this might be the guest module
const execute = AbiFunction.from('function execute(bytes calldata _payload, bytes calldata _signature)')
const payload = Payload.encode({ type: 'call', space: 0n, nonce: 0n, calls }, to)
const signature = '0x0001' // TODO: use a stub signature
Expand Down
2 changes: 1 addition & 1 deletion packages/services/relayer/test/relayer/relayer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ describe('Relayer', () => {
const isAvailable = await mockRelayer.isAvailable(TEST_WALLET_ADDRESS, TEST_CHAIN_ID)
expect(isAvailable).toBe(true)

const feeOptions = await mockRelayer.feeOptions(TEST_WALLET_ADDRESS, TEST_CHAIN_ID, [])
const feeOptions = await mockRelayer.feeOptions(TEST_WALLET_ADDRESS, TEST_CHAIN_ID, TEST_TO_ADDRESS, [])
expect(feeOptions.options).toEqual([])

const relayResult = await mockRelayer.relay(TEST_TO_ADDRESS, TEST_DATA, TEST_CHAIN_ID)
Expand Down
4 changes: 3 additions & 1 deletion packages/wallet/dapp-client/src/ChainSessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,9 @@ export class ChainSessionManager {
createdAtMs: Date.now(),
}
}
const feeOptions = await this.relayer.feeOptions(signedCall.to, this.chainId, callsToSend)
const walletAddress = this.walletAddress
if (!walletAddress) throw new InitializationError('Wallet is not initialized.')
const feeOptions = await this.relayer.feeOptions(walletAddress, this.chainId, signedCall.to, callsToSend)
return feeOptions.options
} catch (err) {
throw new FeeOptionError(`Failed to get fee options: ${err instanceof Error ? err.message : String(err)}`)
Expand Down
6 changes: 5 additions & 1 deletion packages/wallet/wdk/src/sequence/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,11 @@ export class Transactions implements TransactionsInterface {
return []
}

const feeOptions = await relayer.feeOptions(tx.wallet, tx.envelope.chainId, tx.envelope.payload.calls)
// Determine the to address for the built transaction
const walletStatus = await wallet.getStatus(provider)
const to = walletStatus.isDeployed ? wallet.address : wallet.guest

const feeOptions = await relayer.feeOptions(tx.wallet, tx.envelope.chainId, to, tx.envelope.payload.calls)

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