Skip to content

Commit

Permalink
added Msgpack encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
phqb committed May 22, 2024
1 parent c375b63 commit ff725e2
Show file tree
Hide file tree
Showing 9 changed files with 907 additions and 13 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/go_generate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
on: [push, pull_request]
name: Check go generate
jobs:
go-generate-check:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Go
uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
- name: Run go generate
run: go generate ./...
- name: Check working tree clean
run: if [ -z "$(git status --porcelain)" ]; then exit 0; else exit 1; fi
20 changes: 18 additions & 2 deletions entities/pool.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//go:generate go run github.com/tinylib/msgp -unexported -tests=false -v
//msgp:tuple Pool
//msgp:shim *big.Int as:[]byte using:msgpencode.EncodeInt/msgpencode.DecodeInt
//msgp:shim constants.FeeAmount as:uint64 using:uint64/constants.FeeAmount
//msgp:ignore StepComputations SwapResult GetOutputAmountResult GetInputAmountResult TickDataProvider

package entities

import (
Expand Down Expand Up @@ -36,7 +42,7 @@ type Pool struct {
SqrtRatioX96 *big.Int
Liquidity *big.Int
TickCurrent int
TickDataProvider TickDataProvider
TickDataProvider *TickListDataProvider

token0Price *entities.Price
token1Price *entities.Price
Expand Down Expand Up @@ -107,14 +113,24 @@ func NewPool(tokenA, tokenB *entities.Token, fee constants.FeeAmount, sqrtRatioX
token1 = tokenA
}

var tickListDataProvider *TickListDataProvider
if ticks != nil {
switch ticks := ticks.(type) {
case *TickListDataProvider:
tickListDataProvider = ticks
default:
return nil, errors.New("unsupported TickDataProvider concrete type")
}
}

return &Pool{
Token0: token0,
Token1: token1,
Fee: fee,
SqrtRatioX96: sqrtRatioX96,
Liquidity: liquidity,
TickCurrent: tickCurrent,
TickDataProvider: ticks, // TODO: new tick data provider
TickDataProvider: tickListDataProvider,
}, nil
}

Expand Down
Loading

0 comments on commit ff725e2

Please sign in to comment.