Documentation ¶
Index ¶
- Variables
- type Pool
- func (p *Pool) GetAmountOut(amountIn *uint256.Int, zeroForOne bool) (*uint256.Int, error)
- func (p *Pool) GetHackyRounds() (hackyRounds int)
- func (p *Pool) GetState() (tick int, sqrtPriceX96, liquidity *uint256.Int)
- func (p *Pool) GetTickList() (tickList []Tick)
- func (p *Pool) SetHackyRounds(hackyRounds int)
- func (p *Pool) SetState(tick int, sqrtPriceX96, liquidity *uint256.Int)
- func (p *Pool) SetTickList(tickList []Tick)
- type Tick
Constants ¶
This section is empty.
Variables ¶
var ( // MinTick The minimum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**-128 MinTick = -887272 // MaxTick The maximum tick that may be passed to #getSqrtRatioAtTick computed from log base 1.0001 of 2**128 MaxTick = -MinTick )
var ( // NegativeOneBig is -1 in big.Int NegativeOneBig = big.NewInt(-1) // ZeroBig is 0 in big.Int ZeroBig = big.NewInt(0) )
var ( // FeeMultiplier uint256.Int multiplier for calculating fees FeeMultiplier = uint256.NewInt(1000000) // ZeroUint256 is 0 in uint256.Int ZeroUint256 = uint256.NewInt(0) // OneUint256 is 1 in uint256.Int OneUint256 = uint256.NewInt(1) // Q32Uint256 is the q32 representation in uint256.Int Q32Uint256 = uint256.NewInt(1 << 32) // MaxUint256 is the maximum value for an uint256.Int MaxUint256, _ = uint256.FromHex("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") // MinSqrtRatio The minimum value that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MIN_TICK) MinSqrtRatio = uint256.NewInt(4295128739) // MinSqrtRatioAddOne is MinSqrtRatio + 1 MinSqrtRatioAddOne = uint256.NewInt(4295128740) // MaxSqrtRatio The maximum value (1461446703485210103287273052203988822378723970342) that can be returned from #getSqrtRatioAtTick. Equivalent to getSqrtRatioAtTick(MAX_TICK) MaxSqrtRatio, _ = uint256.FromHex("0xFFFD8963EFD1FC6A506488495D951D5263988D26") // MaxSqrtRatioSubOne is MaxSqrtRatio - 1 (1461446703485210103287273052203988822378723970341) MaxSqrtRatioSubOne, _ = uint256.FromHex("0xFFFD8963EFD1FC6A506488495D951D5263988D25") // Q96Uint256 is the Q96 (79228162514264337593543950336) representation in uint256.Int Q96Uint256, _ = uint256.FromHex("0x1000000000000000000000000") // MaxUint160 max value for an uint160 (1461501637330902918203684832716283019655932542975) in uint256.Int MaxUint160, _ = uint256.FromHex("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF") // MagicSqrt10001 tick-math magic (255738958999603826347141) MagicSqrt10001, _ = uint256.FromHex("0x3627A301D71055774C85") // MagicTickLow tick-math magic (3402992956809132418596140100660247210) MagicTickLow, _ = uint256.FromHex("0x28F6481AB7F045A5AF012A19D003AAA") // MagicTickHigh tick-math magic (291339464771989622907027621153398088495) MagicTickHigh, _ = uint256.FromHex("0xDB2DF09E81959A81455E260799A0632F") )
var ( ErrPoolState = errors.New("PoolState - SqrtPriceX96 | Liquidity not set") ErrTickList = errors.New("TickList is empty") ErrPoolCreate = errors.New("TickSpacing | Fee nil or 0") )
Errors for pools
var ( ErrAddOverflow = errors.New("add overflow") ErrMulOverflow = errors.New("mul overflow") ErrInvariant = errors.New("invariant") ErrSqrtLessThanZero = errors.New("sqrt less than zero") ErrLiquidityLessThanZero = errors.New("liquidity less than zero") )
Errors for swap math functions
var ( ErrInvalidInput = errors.New("invalid input") ErrInvalidSqrtRatio = errors.New("invalid sqrt ratio") )
Errors for tick math functions
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool represents an UniswapV3 pair representation
func NewPool ¶
NewPool creates a new UniswapV3 pair that holds all the needed information
- a good hackyRounds default is 10, you can set a higher number or 0 for more iterations to get probably to a later tick, but in exchange for speed
func (*Pool) GetAmountOut ¶
GetAmountOut calculates the amount you will receive for the amount you give in
For now it's the only way, the amountIn is an uint256.Int for faster calculations - still should be easy to also implement the GetAmountIn function later on
func (*Pool) GetHackyRounds ¶
GetHackyRounds get the current max rounds the pool is using in the calculation
func (*Pool) GetTickList ¶
GetTickList get the current tickList from the pool
func (*Pool) SetHackyRounds ¶
SetHackyRounds is used to stop the swap loop if we didn't find liquidity in the next x ticks
func (*Pool) SetTickList ¶
SetTickList sets the tickList for the pool