Skip to content

Document off-chain calculation methods #11

@sambacha

Description

@sambacha

Off chain calculations

Frontends like Uniswap do calculations off chain to compute gas cost, this should be documented to see how APIs are actually used in production

see https://github.com/Uniswap/smart-order-router/blob/c63deae67dcc2113efa0fe6348b2a2ddca3e6265/src/routers/alpha-router/gas-models/v3/v3-heuristic-gas-model.ts?rgh-link-date=2022-02-15T05%3A33%3A45Z#L30-L47

/**
 * Computes a gas estimate for a V3 swap using heuristics.
 * Considers number of hops in the route, number of ticks crossed
 * and the typical base cost for a swap.
 *
 * We get the number of ticks crossed in a swap from the QuoterV2
 * contract.
 *
 * We compute gas estimates off-chain because
 *  1/ Calling eth_estimateGas for a swaps requires the caller to have
 *     the full balance token being swapped, and approvals.
 *  2/ Tracking gas used using a wrapper contract is not accurate with Multicall
 *     due to EIP-2929. We would have to make a request for every swap we wanted to estimate.
 *  3/ For V2 we simulate all our swaps off-chain so have no way to track gas used.
 */

Metadata

Metadata

Assignees

Labels

documentationImprovements or additions to documentationenhancementNew feature or requesthelp wantedExtra attention is needed

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions