Skip to content

Commit

Permalink
Merge pull request #2 from KyberNetwork/msgpack_encoding
Browse files Browse the repository at this point in the history
Msgpack encoding
  • Loading branch information
phqb authored May 23, 2024
2 parents d851d27 + 43c16e6 commit 176808a
Show file tree
Hide file tree
Showing 11 changed files with 1,059 additions and 9 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
14 changes: 10 additions & 4 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 @@ -37,7 +43,7 @@ type Pool struct {
SqrtRatioX96 *big.Int
Liquidity *big.Int
TickCurrent int
TickDataProvider TickDataProvider
TickDataProvider *TickDataProviderWrapper

token0Price *entities.Price
token1Price *entities.Price
Expand Down Expand Up @@ -115,7 +121,7 @@ func NewPool(tokenA, tokenB *entities.Token, fee constants.FeeAmount, sqrtRatioX
SqrtRatioX96: sqrtRatioX96,
Liquidity: liquidity,
TickCurrent: tickCurrent,
TickDataProvider: ticks, // TODO: new tick data provider
TickDataProvider: NewTickDataProviderWrapper(ticks), // TODO: new tick data provider
}, nil
}

Expand Down Expand Up @@ -194,7 +200,7 @@ func (p *Pool) GetOutputAmount(inputAmount *entities.CurrencyAmount, sqrtPriceLi
swapResult.sqrtRatioX96,
swapResult.liquidity,
swapResult.currentTick,
p.TickDataProvider,
p.TickDataProvider.Get(),
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -236,7 +242,7 @@ func (p *Pool) GetInputAmount(outputAmount *entities.CurrencyAmount, sqrtPriceLi
swapResult.sqrtRatioX96,
swapResult.liquidity,
swapResult.currentTick,
p.TickDataProvider,
p.TickDataProvider.Get(),
)
if err != nil {
return nil, err
Expand Down
Loading

0 comments on commit 176808a

Please sign in to comment.