Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ticks-based DEX] Set timestamp from subgraph for entity.Pool #661

Merged
merged 4 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
module github.com/KyberNetwork/kyberswap-dex-lib

go 1.22.8

toolchain go1.22.9
go 1.23.1

require (
github.com/KyberNetwork/blockchain-toolkit v0.8.2-0.20241123202223-0b77d465adc4
github.com/KyberNetwork/elastic-go-sdk/v2 v2.0.2
github.com/KyberNetwork/ethrpc v0.7.3
github.com/KyberNetwork/iZiSwap-SDK-go v1.1.0
github.com/KyberNetwork/int256 v0.1.4
github.com/KyberNetwork/kutils v0.3.8
github.com/KyberNetwork/logger v0.2.1
github.com/KyberNetwork/msgpack/v5 v5.4.2
github.com/KyberNetwork/pancake-v3-sdk v0.2.0
Expand All @@ -18,7 +17,7 @@ require (
github.com/daoleno/uniswapv3-sdk v0.4.0
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set/v2 v2.6.0
github.com/dgraph-io/ristretto v0.1.1
github.com/dgraph-io/ristretto v0.2.0
github.com/ethereum/go-ethereum v1.14.12
github.com/go-resty/resty/v2 v2.14.0
github.com/goccy/go-json v0.10.3
Expand All @@ -41,8 +40,13 @@ require (

require (
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/aws/smithy-go v1.15.0 // indirect
github.com/bits-and-blooms/bitset v1.14.3 // indirect
github.com/bytedance/sonic v1.12.1 // indirect
github.com/bytedance/sonic/loader v0.2.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/consensys/bavard v0.1.15 // indirect
github.com/consensys/gnark-crypto v0.12.1 // indirect
github.com/crate-crypto/go-ipa v0.0.0-20240223125850-b1e8a79f509c // indirect
Expand All @@ -53,28 +57,36 @@ require (
github.com/ethereum/go-verkle v0.1.1-0.20240829091221-dffa7562dbe9 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/golang/glog v1.1.2 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/matryer/is v1.4.1 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/supranational/blst v0.3.13 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
github.com/tklauser/numcpus v0.8.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/arch v0.9.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/tools v0.25.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
64 changes: 52 additions & 12 deletions go.sum

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions pkg/liquidity-source/algebra/integral/pool_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/kutils"
"github.com/KyberNetwork/logger"
"github.com/goccy/go-json"
"github.com/machinebox/graphql"
Expand Down Expand Up @@ -148,13 +148,18 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte
return nil, metadataBytes, err
}

createdAtTimestamp, err := kutils.Atoi[int64](p.CreatedAtTimestamp)
if err != nil {
return nil, metadataBytes, fmt.Errorf("invalid CreatedAtTimestamp: %v, pool: %v", p.CreatedAtTimestamp, p.ID)
}

var newPool = entity.Pool{
Address: p.ID,
ReserveUsd: 0,
AmplifiedTvl: 0,
Exchange: d.config.DexID,
Type: DexType,
Timestamp: time.Now().Unix(),
Timestamp: createdAtTimestamp,
Reserves: reserves,
Tokens: tokens,
StaticExtra: string(staticExtra),
Expand Down
9 changes: 7 additions & 2 deletions pkg/liquidity-source/algebra/v1/pool_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/kutils"
"github.com/KyberNetwork/logger"
"github.com/goccy/go-json"
"github.com/machinebox/graphql"
Expand Down Expand Up @@ -138,13 +138,18 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte
reserves = append(reserves, zeroString)
}

createdAtTimestamp, err := kutils.Atoi[int64](p.CreatedAtTimestamp)
if err != nil {
return nil, metadataBytes, fmt.Errorf("invalid CreatedAtTimestamp: %v, pool: %v", p.CreatedAtTimestamp, p.ID)
}

var newPool = entity.Pool{
Address: p.ID,
ReserveUsd: 0,
AmplifiedTvl: 0,
Exchange: d.config.DexID,
Type: DexTypeAlgebraV1,
Timestamp: time.Now().Unix(),
Timestamp: createdAtTimestamp,
Reserves: reserves,
Tokens: tokens,
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/source/nuriv2/pools_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/kutils"
"github.com/KyberNetwork/logger"
"github.com/goccy/go-json"
"github.com/machinebox/graphql"
Expand Down Expand Up @@ -141,6 +141,11 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte
reserves = append(reserves, zeroString)
}

createdAtTimestamp, err := kutils.Atoi[int64](p.CreatedAtTimestamp)
if err != nil {
return nil, metadataBytes, fmt.Errorf("invalid CreatedAtTimestamp: %v, pool: %v", p.CreatedAtTimestamp, p.ID)
}

var swapFee, _ = strconv.ParseFloat(p.FeeTier, 64)

extraBytes, _ := json.Marshal(extraField)
Expand All @@ -152,7 +157,7 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte
SwapFee: swapFee,
Exchange: d.config.DexID,
Type: DexType,
Timestamp: time.Now().Unix(),
Timestamp: createdAtTimestamp,
Reserves: reserves,
Tokens: tokens,
Extra: string(extraBytes),
Expand Down
9 changes: 7 additions & 2 deletions pkg/source/pancakev3/pools_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/kutils"
"github.com/KyberNetwork/logger"
"github.com/goccy/go-json"
"github.com/machinebox/graphql"
Expand Down Expand Up @@ -150,6 +150,11 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte

var swapFee, _ = strconv.ParseFloat(p.FeeTier, 64)

createdAtTimestamp, err := kutils.Atoi[int64](p.CreatedAtTimestamp)
if err != nil {
return nil, metadataBytes, fmt.Errorf("invalid CreatedAtTimestamp: %v, pool: %v", p.CreatedAtTimestamp, p.ID)
}

extraBytes, _ := json.Marshal(extraField)
staticBytes, _ := json.Marshal(staticField)
var newPool = entity.Pool{
Expand All @@ -159,7 +164,7 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte
SwapFee: swapFee,
Exchange: d.config.DexID,
Type: DexTypePancakeV3,
Timestamp: time.Now().Unix(),
Timestamp: createdAtTimestamp,
Reserves: reserves,
Tokens: tokens,
Extra: string(extraBytes),
Expand Down
9 changes: 7 additions & 2 deletions pkg/source/ramsesv2/pools_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/kutils"
"github.com/KyberNetwork/logger"
"github.com/goccy/go-json"
"github.com/machinebox/graphql"
Expand Down Expand Up @@ -143,6 +143,11 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte

var swapFee, _ = strconv.ParseFloat(p.FeeTier, 64)

createdAtTimestamp, err := kutils.Atoi[int64](p.CreatedAtTimestamp)
if err != nil {
return nil, metadataBytes, fmt.Errorf("invalid CreatedAtTimestamp: %v, pool: %v", p.CreatedAtTimestamp, p.ID)
}

extraBytes, _ := json.Marshal(extraField)

var newPool = entity.Pool{
Expand All @@ -152,7 +157,7 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte
SwapFee: swapFee,
Exchange: d.config.DexID,
Type: DexTypeRamsesV2,
Timestamp: time.Now().Unix(),
Timestamp: createdAtTimestamp,
Reserves: reserves,
Tokens: tokens,
Extra: string(extraBytes),
Expand Down
9 changes: 7 additions & 2 deletions pkg/source/slipstream/pools_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/kutils"
"github.com/KyberNetwork/logger"
"github.com/goccy/go-json"
"github.com/machinebox/graphql"
Expand Down Expand Up @@ -149,6 +149,11 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte
reserves = append(reserves, zeroString)
}

createdAtTimestamp, err := kutils.Atoi[int64](p.CreatedAtTimestamp)
if err != nil {
return nil, metadataBytes, fmt.Errorf("invalid CreatedAtTimestamp: %v, pool: %v", p.CreatedAtTimestamp, p.ID)
}

extraBytes, _ := json.Marshal(extraField)
staticBytes, _ := json.Marshal(staticField)
var newPool = entity.Pool{
Expand All @@ -158,7 +163,7 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte
SwapFee: 0,
Exchange: d.config.DexID,
Type: DexType,
Timestamp: time.Now().Unix(),
Timestamp: createdAtTimestamp,
Reserves: reserves,
Tokens: tokens,
Extra: string(extraBytes),
Expand Down
9 changes: 7 additions & 2 deletions pkg/source/solidly-v3/pools_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/kutils"
"github.com/KyberNetwork/logger"
"github.com/goccy/go-json"
"github.com/machinebox/graphql"
Expand Down Expand Up @@ -143,6 +143,11 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte

var swapFee, _ = strconv.ParseFloat(p.FeeTier, 64)

createdAtTimestamp, err := kutils.Atoi[int64](p.CreatedAtTimestamp)
if err != nil {
return nil, metadataBytes, fmt.Errorf("invalid CreatedAtTimestamp: %v, pool: %v", p.CreatedAtTimestamp, p.ID)
}

extraBytes, _ := json.Marshal(extraField)

var newPool = entity.Pool{
Expand All @@ -152,7 +157,7 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte
SwapFee: swapFee,
Exchange: d.config.DexID,
Type: DexTypeSolidlyV3,
Timestamp: time.Now().Unix(),
Timestamp: createdAtTimestamp,
Reserves: reserves,
Tokens: tokens,
Extra: string(extraBytes),
Expand Down
9 changes: 7 additions & 2 deletions pkg/source/uniswapv3/pools_list_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/ethrpc"
"github.com/KyberNetwork/kutils"
"github.com/KyberNetwork/logger"
"github.com/goccy/go-json"
"github.com/machinebox/graphql"
Expand Down Expand Up @@ -150,6 +150,11 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte

var swapFee, _ = strconv.ParseFloat(p.FeeTier, 64)

createdAtTimestamp, err := kutils.Atoi[int64](p.CreatedAtTimestamp)
if err != nil {
return nil, metadataBytes, fmt.Errorf("invalid CreatedAtTimestamp: %v, pool: %v", p.CreatedAtTimestamp, p.ID)
}

extraBytes, _ := json.Marshal(extraField)
staticBytes, _ := json.Marshal(staticField)
var newPool = entity.Pool{
Expand All @@ -159,7 +164,7 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte
SwapFee: swapFee,
Exchange: d.config.DexID,
Type: DexTypeUniswapV3,
Timestamp: time.Now().Unix(),
Timestamp: createdAtTimestamp,
Reserves: reserves,
Tokens: tokens,
Extra: string(extraBytes),
Expand Down
Loading