import { decodeWrappedError, WRAPPED_ERROR_SELECTOR } from '@tevm/voltaire/Abi/error/wrapped';
import { Address } from '@tevm/voltaire/Address';
function traceWrappedError(errorData: string, depth = 0) {
if (!errorData.startsWith('0x91a3a3b5')) {
console.log(' '.repeat(depth) + 'Original error:', errorData);
return;
}
const wrapped = decodeWrappedError(Buffer.from(errorData.slice(2), 'hex'));
console.log(' '.repeat(depth) + 'Call to:', wrapped.target.toHex());
console.log(' '.repeat(depth) + 'Function:', '0x' + Buffer.from(wrapped.selector).toString('hex'));
console.log(' '.repeat(depth) + 'Details:', new TextDecoder().decode(wrapped.details));
// Recurse if reason is also wrapped
const reasonHex = '0x' + Buffer.from(wrapped.reason).toString('hex');
traceWrappedError(reasonHex, depth + 1);
}
// Usage
try {
await complexMultiContractCall();
} catch (err) {
traceWrappedError(err.data);
// Output shows full call chain with context
}