Skip to content

Commit

Permalink
add priceLimit to pool extra (#602)
Browse files Browse the repository at this point in the history
* add priceLimit to pool extra

* fix
  • Loading branch information
it4rb authored Nov 20, 2024
1 parent 24c7ba1 commit b2f8e3f
Show file tree
Hide file tree
Showing 16 changed files with 56 additions and 12 deletions.
4 changes: 3 additions & 1 deletion pkg/source/algebrav1/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ func (p *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) {
p.globalState = si.GlobalState
}

func (p *PoolSimulator) GetMetaInfo(tokenIn string, tokenOut string) interface{} {
func (p *PoolSimulator) GetMetaInfo(tokenIn string, _ string) interface{} {
zeroForOne := strings.EqualFold(tokenIn, p.Info.Tokens[0])
return PoolMeta{
BlockNumber: p.Pool.Info.BlockNumber,
PriceLimit: p.getSqrtPriceLimit(zeroForOne),
}
}
3 changes: 2 additions & 1 deletion pkg/source/algebrav1/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ type StateUpdate struct {
}

type PoolMeta struct {
BlockNumber uint64 `json:"blockNumber"`
BlockNumber uint64 `json:"blockNumber"`
PriceLimit *big.Int `json:"priceLimit"`
}

func transformTickRespToTick(tickResp TickResp) (v3Entities.Tick, error) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/source/nuriv2/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,8 @@ func (p *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) {
}

func (p *PoolSimulator) GetMetaInfo(tokenIn string, tokenOut string) interface{} {
return nil
zeroForOne := strings.EqualFold(tokenIn, p.V3Pool.Token0.Address.String())
return PoolMeta{
PriceLimit: p.getSqrtPriceLimit(zeroForOne),
}
}
4 changes: 4 additions & 0 deletions pkg/source/nuriv2/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ type Extra struct {
Ticks []Tick `json:"ticks"`
}

type PoolMeta struct {
PriceLimit *big.Int `json:"priceLimit"`
}

type Slot0 struct {
SqrtPriceX96 *big.Int `json:"sqrtPriceX96"`
Tick *big.Int `json:"tick"`
Expand Down
7 changes: 6 additions & 1 deletion pkg/source/pancakev3/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,13 @@ func (p *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) {
p.V3Pool.TickCurrent = si.nextStateTickCurrent
}

func (p *PoolSimulator) GetMetaInfo(_ string, _ string) interface{} {
func (p *PoolSimulator) GetMetaInfo(tokenIn string, _ string) interface{} {
zeroForOne := strings.EqualFold(tokenIn, p.V3Pool.Token0.Address.String())
var priceLimit v3Utils.Uint160
_ = p.getSqrtPriceLimit(zeroForOne, &priceLimit)

return PoolMeta{
BlockNumber: p.Pool.Info.BlockNumber,
PriceLimit: priceLimit.ToBig(),
}
}
4 changes: 3 additions & 1 deletion pkg/source/pancakev3/pool_simulator_bigint.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,10 @@ func (p *PoolSimulatorBigInt) UpdateBalance(params pool.UpdateBalanceParams) {
p.V3Pool.TickCurrent = si.nextStateTickCurrent
}

func (p *PoolSimulatorBigInt) GetMetaInfo(_ string, _ string) interface{} {
func (p *PoolSimulatorBigInt) GetMetaInfo(tokenIn string, _ string) interface{} {
zeroForOne := strings.EqualFold(tokenIn, p.V3Pool.Token0.Address.String())
return PoolMeta{
BlockNumber: p.Pool.Info.BlockNumber,
PriceLimit: p.getSqrtPriceLimit(zeroForOne),
}
}
3 changes: 2 additions & 1 deletion pkg/source/pancakev3/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ type FetchRPCResult struct {
}

type PoolMeta struct {
BlockNumber uint64 `json:"blockNumber"`
BlockNumber uint64 `json:"blockNumber"`
PriceLimit *big.Int `json:"priceLimit"`
}

func transformTickRespToTick(tickResp TickResp) (Tick, error) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/source/ramsesv2/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,5 +203,8 @@ func (p *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) {
}

func (p *PoolSimulator) GetMetaInfo(tokenIn string, tokenOut string) interface{} {
return nil
zeroForOne := strings.EqualFold(tokenIn, p.V3Pool.Token0.Address.String())
return PoolMeta{
PriceLimit: p.getSqrtPriceLimit(zeroForOne),
}
}
4 changes: 4 additions & 0 deletions pkg/source/ramsesv2/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ type Extra struct {
Ticks []Tick `json:"ticks"`
}

type PoolMeta struct {
PriceLimit *big.Int `json:"priceLimit"`
}

type Slot0 struct {
SqrtPriceX96 *big.Int `json:"sqrtPriceX96"`
Tick *big.Int `json:"tick"`
Expand Down
4 changes: 4 additions & 0 deletions pkg/source/slipstream/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,11 @@ func (p *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) {
}

func (p *PoolSimulator) GetMetaInfo(tokenIn string, tokenOut string) interface{} {
zeroForOne := strings.EqualFold(tokenIn, p.V3Pool.Token0.Address.String())
var priceLimit v3Utils.Uint160
_ = p.getSqrtPriceLimit(zeroForOne, &priceLimit)
return PoolMeta{
BlockNumber: p.Pool.Info.BlockNumber,
PriceLimit: priceLimit.ToBig(),
}
}
3 changes: 2 additions & 1 deletion pkg/source/slipstream/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ type FetchRPCResult struct {
}

type PoolMeta struct {
BlockNumber uint64 `json:"blockNumber"`
BlockNumber uint64 `json:"blockNumber"`
PriceLimit *big.Int `json:"priceLimit"`
}

func transformTickRespToTick(tickResp TickResp) (Tick, error) {
Expand Down
5 changes: 4 additions & 1 deletion pkg/source/solidly-v3/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,8 @@ func (p *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) {
}

func (p *PoolSimulator) GetMetaInfo(tokenIn string, tokenOut string) interface{} {
return nil
zeroForOne := strings.EqualFold(tokenIn, p.V3Pool.Token0.Address.String())
return PoolMeta{
PriceLimit: p.getSqrtPriceLimit(zeroForOne),
}
}
4 changes: 4 additions & 0 deletions pkg/source/solidly-v3/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ type Extra struct {
Ticks []Tick `json:"ticks"`
}

type PoolMeta struct {
PriceLimit *big.Int `json:"priceLimit"`
}

type Slot0 struct {
SqrtPriceX96 *big.Int `json:"sqrtPriceX96"`
Tick *big.Int `json:"tick"`
Expand Down
6 changes: 5 additions & 1 deletion pkg/source/uniswapv3/pool_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,12 @@ func (p *PoolSimulator) UpdateBalance(params pool.UpdateBalanceParams) {
p.V3Pool.TickCurrent = si.nextStateTickCurrent
}

func (p *PoolSimulator) GetMetaInfo(_ string, _ string) interface{} {
func (p *PoolSimulator) GetMetaInfo(tokenIn string, _ string) interface{} {
zeroForOne := strings.EqualFold(tokenIn, p.V3Pool.Token0.Address.String())
var priceLimit v3Utils.Uint160
_ = p.getSqrtPriceLimit(zeroForOne, &priceLimit)
return PoolMeta{
BlockNumber: p.Pool.Info.BlockNumber,
PriceLimit: priceLimit.ToBig(),
}
}
4 changes: 3 additions & 1 deletion pkg/source/uniswapv3/pool_simulator_bigint.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,10 @@ func (p *PoolSimulatorBigInt) UpdateBalance(params pool.UpdateBalanceParams) {
p.V3Pool.TickCurrent = si.nextStateTickCurrent
}

func (p *PoolSimulatorBigInt) GetMetaInfo(_ string, _ string) interface{} {
func (p *PoolSimulatorBigInt) GetMetaInfo(tokenIn string, _ string) interface{} {
zeroForOne := strings.EqualFold(tokenIn, p.V3Pool.Token0.Address.String())
return PoolMeta{
BlockNumber: p.Pool.Info.BlockNumber,
PriceLimit: p.getSqrtPriceLimit(zeroForOne),
}
}
3 changes: 2 additions & 1 deletion pkg/source/uniswapv3/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ type FetchRPCResult struct {
}

type PoolMeta struct {
BlockNumber uint64 `json:"blockNumber"`
BlockNumber uint64 `json:"blockNumber"`
PriceLimit *big.Int `json:"priceLimit"`
}

func transformTickRespToTick(tickResp TickResp) (Tick, error) {
Expand Down

0 comments on commit b2f8e3f

Please sign in to comment.