Skip to content

Commit

Permalink
Merge pull request #62 from Team-Kujira/fix-pancake
Browse files Browse the repository at this point in the history
Fix pancake int overflow
  • Loading branch information
starsquidnodes authored Mar 15, 2024
2 parents 90561ed + 1bd7303 commit 10d2cc0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module price-feeder
go 1.20

require (
cosmossdk.io/math v1.1.2
github.com/BurntSushi/toml v1.2.1
github.com/Team-Kujira/core v0.9.1
github.com/armon/go-metrics v0.4.1
Expand All @@ -19,6 +20,7 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/rs/cors v1.8.3
github.com/rs/zerolog v1.30.0
github.com/shopspring/decimal v1.3.1
github.com/sirkon/goproxy v1.4.8
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
Expand All @@ -40,7 +42,6 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.0 // indirect
cosmossdk.io/log v1.2.1 // indirect
cosmossdk.io/math v1.1.2 // indirect
cosmossdk.io/simapp v0.0.0-20230224204036-a6adb0821462 // indirect
cosmossdk.io/tools/rosetta v0.2.1 // indirect
filippo.io/edwards25519 v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,8 @@ github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAm
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c h1:W65qqJCIOVP4jpqPQ0YvHYKwcMEMVWIzWC5iNQQfBTU=
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c/go.mod h1:/PevMnwAxekIXwN8qQyfc5gl2NlkB3CQlkizAbOkeBs=
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMTu2PcXUg8+E1lC7eC3UO/RA=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
Expand Down
18 changes: 16 additions & 2 deletions oracle/provider/pancakev3.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/rs/zerolog"
"github.com/shopspring/decimal"
)

var (
Expand Down Expand Up @@ -240,8 +241,21 @@ func (p *PancakeProvider) query(
}

for _, pool := range response.Data.Pools {
price := strToDec(pool.SqrtPrice)
prices[pool.Id] = price.Power(2).Quo(sdk.NewDec(2).Power(192))
dec, err := decimal.NewFromString(pool.SqrtPrice)
if err != nil {
p.logger.Error().
Err(err).
Msg("failed parsing sqrt price")
return nil, nil, err
}

d2 := decimal.NewFromInt(2)
d192 := decimal.NewFromInt(192)

dec = dec.Pow(d2).Div(d2.Pow(d192))
price := strToDec(dec.String())

prices[pool.Id] = price
}

return prices, volumes, nil
Expand Down

0 comments on commit 10d2cc0

Please sign in to comment.