/** * Revert decoding — turn the bytes a failed call came back with into the name * the contract actually reverted with. * * `isUnpredictableGas` says only THAT the call would revert. That was enough * while the answer was always the same one: a `transferFrom` failing on a * balance that cannot cover the deposit. It is not enough any more, because * `requestDepositWithKyc` reverts for a whole family of reasons the ABI * declares and the lender can do nothing about — the pool is stopped, the pool * is mid-clearing, their KYC lapsed, they are not on the allow list, the * allow-list signature's block window closed. Every one of those was reported * as "insufficient balance", so a fully funded lender was told to top up a * wallet that was never short. * * The revert data carries the answer. This module extracts it from whatever * envelope the provider wrapped it in and matches the 4-byte selector against * the custom errors the protocol declares. * * Pure, like everything else in `domain/`: bytes in, a name out. It never * decides what a lender is shown — `DepositFlow` maps the name to a code and * the application maps the code to its own words. */ /** * Which family a recognised revert belongs to, because the two are acted on * differently. * * `erc20` is the case `insufficient-balance` was named for and still means: * the token transfer itself failed, so the lender genuinely has to fund or * re-approve. `protocol` is everything else the protocol declares — a * condition of the pool or the lender's standing, which topping up cannot fix. */ export type RevertFamily = 'protocol' | 'erc20'; export interface DecodedRevert { /** The custom error's name, exactly as the ABI declares it. */ name: string; family: RevertFamily; /** The reason of a `require(..., "…")` revert, when it was one. */ reason?: string; } /** * Find the revert data on an error, wherever the provider left it. * * ethers v5 raises `UNPREDICTABLE_GAS_LIMIT` with the provider's own error * attached, and each provider nests the bytes one layer differently: * `error.data`, `error.error.data`, `error.data.originalError.data`, or only * inside the JSON `body` of a `SERVER_ERROR`. Rather than enumerate the * products, walk a fixed set of keys to a fixed depth and take the first value * that is shaped like revert data. */ export declare function extractRevertData(err: unknown): string | null; /** * Decode a failed call's revert into the error the contract named, or `null` * when there is nothing recognisable to name. * * `null` is the honest answer for an unknown selector, an unrelated `require` * string, or an error with no revert data at all — the caller keeps whatever * it did before rather than inventing a diagnosis from bytes it cannot read. */ export declare function decodeRevert(err: unknown): DecodedRevert | null;