Skip to content
Open
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
14 changes: 10 additions & 4 deletions packages/services/relayer/src/relayer/rpc-relayer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
TransactionPrecondition,
ETHTxnStatus,
} from './relayer.gen.js'
import { Address, Hex, Bytes, AbiFunction } from 'ox'
import { Address, Hex, AbiFunction } from 'ox'
import { Constants, Payload, Network } from '@0xsequence/wallet-primitives'
import { FeeOption, FeeQuote, OperationStatus, Relayer } from '../index.js'
import { decodePrecondition } from '../../preconditions/index.js'
Expand Down Expand Up @@ -137,15 +137,21 @@ export class RpcRelayer implements Relayer {
to: Address.Address,
calls: Payload.Call[],
): Promise<{ options: FeeOption[]; quote?: FeeQuote }> {
// IMPORTANT:
// The relayer FeeOptions endpoint simulates `eth_call(to, data)`.
// wallet-webapp-v3 requests FeeOptions with `to = wallet` and `data = Payload.encode(calls, self=wallet)`.
// This works for undeployed wallets and avoids guest-module simulation pitfalls.
const callsStruct: Payload.Calls = { type: 'call', space: 0n, nonce: 0n, calls: calls }
const data = Payload.encode(callsStruct)

const feeOptionsTo = wallet
const data = Payload.encode(callsStruct, wallet)

try {
const result = await this.client.feeOptions(
{
wallet,
to,
data: Bytes.toHex(data),
to: feeOptionsTo,
data: Hex.fromBytes(data),
},
{ ...(this.projectAccessKey ? { 'X-Access-Key': this.projectAccessKey } : undefined) },
)
Expand Down