Module web30::amm

source · []

Structs

The DAI V2 Token’s address, on prod Ethereum

Uniswap V3’s Quoter interface for checking current swap prices, from prod Ethereum

Uniswap V3’s Router interface for swapping tokens, from prod Ethereum

The Wrapped Ether’s address, on prod Ethereum

Constants

Default padding multiplied to uniswap exchange gas limit values due to variablity of gas limit values between iterations

Functions

Decodes the Q64.96-encoded sqrt price from Uniswap into an intuitive price

Scales the input sqrt_price by scale factor to enable limited slippage in Uniswap swaps It is necessary to first identify the direction of the swap as Uniswap depends on that for slippage calculation, use get_uniswap_tokens() to receive an ordered tuple (token0: Address, token1: Address)

Computes the sqrt price of a pool given token_1’s liquidity and token_0’s liquidity When used as the sqrt price limit, this calculates the maximum price that a swap is allowed to push the pool to by changing the underlying liquidity without having the tx revert Attempts to encode the result as a Q64.96 by copying the javascript implementation (see https://en.wikipedia.org/wiki/Q_(number_format), a 160 bit number v represented in Q64.96 would be equal to (v/2^96))

Encodes a given spot price as a Q64.96 sqrt price which Uniswap expects, used in limiting slippage See uniswap_sqrt_price_from_amounts for the general case