|
7 | 7 | TransactionPrecondition, |
8 | 8 | ETHTxnStatus, |
9 | 9 | } from './relayer.gen.js' |
10 | | -import { Address, Hex, Bytes, AbiFunction } from 'ox' |
| 10 | +import { Address, Hex, AbiFunction } from 'ox' |
11 | 11 | import { Constants, Payload, Network } from '@0xsequence/wallet-primitives' |
12 | 12 | import { FeeOption, FeeQuote, OperationStatus, Relayer } from '../index.js' |
13 | 13 | import { decodePrecondition } from '../../preconditions/index.js' |
@@ -137,15 +137,21 @@ export class RpcRelayer implements Relayer { |
137 | 137 | to: Address.Address, |
138 | 138 | calls: Payload.Call[], |
139 | 139 | ): Promise<{ options: FeeOption[]; quote?: FeeQuote }> { |
| 140 | + // IMPORTANT: |
| 141 | + // The relayer FeeOptions endpoint simulates `eth_call(to, data)`. |
| 142 | + // wallet-webapp-v3 requests FeeOptions with `to = wallet` and `data = Payload.encode(calls, self=wallet)`. |
| 143 | + // This works for undeployed wallets and avoids guest-module simulation pitfalls. |
140 | 144 | const callsStruct: Payload.Calls = { type: 'call', space: 0n, nonce: 0n, calls: calls } |
141 | | - const data = Payload.encode(callsStruct) |
| 145 | + |
| 146 | + const feeOptionsTo = wallet |
| 147 | + const data = Payload.encode(callsStruct, wallet) |
142 | 148 |
|
143 | 149 | try { |
144 | 150 | const result = await this.client.feeOptions( |
145 | 151 | { |
146 | 152 | wallet, |
147 | | - to, |
148 | | - data: Bytes.toHex(data), |
| 153 | + to: feeOptionsTo, |
| 154 | + data: Hex.fromBytes(data), |
149 | 155 | }, |
150 | 156 | { ...(this.projectAccessKey ? { 'X-Access-Key': this.projectAccessKey } : undefined) }, |
151 | 157 | ) |
|
0 commit comments