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 3 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
8 changes: 6 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,7 +5,6 @@ import (
"fmt"
"math/big"
"strconv"
"time"

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

createdAtTimestamp, ok := new(big.Int).SetString(p.CreatedAtTimestamp, 10)
if !ok {
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.Int64(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yo

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,7 +5,6 @@ import (
"fmt"
"math/big"
"strconv"
"time"

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

createdAtTimestamp, ok := new(big.Int).SetString(p.CreatedAtTimestamp, 10)
if !ok {
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.Int64(),
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,7 +5,6 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/ethrpc"
Expand Down Expand Up @@ -141,6 +140,12 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte
reserves = append(reserves, zeroString)
}

createdAtTimestamp, ok := new(big.Int).SetString(p.CreatedAtTimestamp, 10)
if !ok {
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.Int64(),
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,7 +5,6 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/ethrpc"
Expand Down Expand Up @@ -150,6 +149,12 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte

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

createdAtTimestamp, ok := new(big.Int).SetString(p.CreatedAtTimestamp, 10)
if !ok {
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.Int64(),
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,7 +5,6 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/ethrpc"
Expand Down Expand Up @@ -143,6 +142,12 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte

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

createdAtTimestamp, ok := new(big.Int).SetString(p.CreatedAtTimestamp, 10)
if !ok {
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.Int64(),
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,7 +5,6 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/ethrpc"
Expand Down Expand Up @@ -149,6 +148,12 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte
reserves = append(reserves, zeroString)
}

createdAtTimestamp, ok := new(big.Int).SetString(p.CreatedAtTimestamp, 10)
if !ok {
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.Int64(),
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,7 +5,6 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/ethrpc"
Expand Down Expand Up @@ -143,6 +142,12 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte

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

createdAtTimestamp, ok := new(big.Int).SetString(p.CreatedAtTimestamp, 10)
if !ok {
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.Int64(),
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,7 +5,6 @@ import (
"fmt"
"math/big"
"strconv"
"time"

"github.com/KyberNetwork/blockchain-toolkit/integer"
"github.com/KyberNetwork/ethrpc"
Expand Down Expand Up @@ -150,6 +149,12 @@ func (d *PoolsListUpdater) GetNewPools(ctx context.Context, metadataBytes []byte

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

createdAtTimestamp, ok := new(big.Int).SetString(p.CreatedAtTimestamp, 10)
if !ok {
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.Int64(),
Reserves: reserves,
Tokens: tokens,
Extra: string(extraBytes),
Expand Down
Loading