From cb44f4e4a0cdc4a26b9201a5f0685bbdf6561bef Mon Sep 17 00:00:00 2001 From: Hiep Nguyen Date: Thu, 21 Sep 2023 15:05:29 +0700 Subject: [PATCH 1/5] Update interface for IPoolTracker to pass more params --- pkg/source/algebrav1/pool_tracker.go | 7 ++++++- .../balancer-composable-stable/pool_tracker.go | 7 ++++++- pkg/source/balancer/pool_tracker.go | 7 ++++++- pkg/source/biswap/pool_tracker.go | 7 ++++++- pkg/source/camelot/pool_tracker.go | 7 ++++++- pkg/source/curve/pool_tracker.go | 2 ++ pkg/source/dmm/pool_tracker.go | 7 ++++++- pkg/source/dodo/pool_tracker.go | 7 ++++++- pkg/source/dystopia/pool_tracker.go | 7 ++++++- pkg/source/elastic/pool_tracker.go | 7 ++++++- pkg/source/fraxswap/pool_tracker.go | 7 ++++++- pkg/source/gmx/pool_tracker.go | 7 ++++++- pkg/source/ironstable/pool_tracker.go | 7 ++++++- pkg/source/iziswap/pool_tracker.go | 7 ++++++- pkg/source/kyber-pmm/pool_tracker.go | 7 ++++++- pkg/source/lido-steth/pool_tracker.go | 7 ++++++- pkg/source/lido/pool_tracker.go | 7 ++++++- pkg/source/limitorder/pool_tracker.go | 7 ++++++- pkg/source/madmex/pool_tracker.go | 7 ++++++- pkg/source/makerpsm/pool_tracker.go | 7 ++++++- pkg/source/maverickv1/pool_tracker.go | 14 ++++++++++---- pkg/source/metavault/pool_tracker.go | 7 ++++++- pkg/source/muteswitch/pool_tracker.go | 7 ++++++- pkg/source/nerve/pool_tracker.go | 7 ++++++- pkg/source/oneswap/pool_tracker.go | 7 ++++++- pkg/source/pancakev3/pool_tracker.go | 7 ++++++- pkg/source/pearl/pool_tracker.go | 7 ++++++- pkg/source/platypus/pool_tracker.go | 7 ++++++- pkg/source/polydex/pool_tracker.go | 7 ++++++- pkg/source/pool/iface.go | 5 +++++ pkg/source/ramses/pool_tracker.go | 7 ++++++- pkg/source/saddle/pool_tracker.go | 7 ++++++- pkg/source/syncswap/pool_tracker.go | 7 ++++++- pkg/source/synthetix/pool_tracker.go | 7 ++++++- pkg/source/traderjoev20/pool_test.go | 3 ++- pkg/source/traderjoev20/pool_tracker.go | 7 ++++++- pkg/source/traderjoev21/pool_test.go | 3 ++- pkg/source/traderjoev21/pool_tracker.go | 7 ++++++- pkg/source/uniswap/pool_tracker.go | 7 ++++++- pkg/source/uniswapv3/pool_tracker.go | 7 ++++++- pkg/source/velocimeter/pool_tracker.go | 11 ++++++++--- pkg/source/velodrome/pool_tracker.go | 7 ++++++- pkg/source/velodromev2/pool_tracker.go | 9 +++++++-- pkg/source/wombat/pool_tracker.go | 12 +++++++++--- 44 files changed, 261 insertions(+), 50 deletions(-) diff --git a/pkg/source/algebrav1/pool_tracker.go b/pkg/source/algebrav1/pool_tracker.go index 98764a6c0..68e89cf0e 100644 --- a/pkg/source/algebrav1/pool_tracker.go +++ b/pkg/source/algebrav1/pool_tracker.go @@ -15,6 +15,7 @@ import ( "github.com/sourcegraph/conc/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/bignumber" graphqlPkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/graphql" ) @@ -38,7 +39,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ dexpool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.Infof("[%v] Start getting new state of pool: %v", d.config.DexID, p.Address) var ( diff --git a/pkg/source/balancer-composable-stable/pool_tracker.go b/pkg/source/balancer-composable-stable/pool_tracker.go index 3441e0e21..38af95bec 100644 --- a/pkg/source/balancer-composable-stable/pool_tracker.go +++ b/pkg/source/balancer-composable-stable/pool_tracker.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/valueobject" ) @@ -28,7 +29,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.WithFields(logger.Fields{ "poolAddress": p.Address, }).Infof("[Balancer-Composable-Stable] Start updating state ...") diff --git a/pkg/source/balancer/pool_tracker.go b/pkg/source/balancer/pool_tracker.go index 9b2a866a2..7f968f8fa 100644 --- a/pkg/source/balancer/pool_tracker.go +++ b/pkg/source/balancer/pool_tracker.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -27,7 +28,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.WithFields(logger.Fields{ "poolAddress": p.Address, }).Infof("[Balancer] Start updating state ...") diff --git a/pkg/source/biswap/pool_tracker.go b/pkg/source/biswap/pool_tracker.go index 6ccfc3729..c71126f40 100644 --- a/pkg/source/biswap/pool_tracker.go +++ b/pkg/source/biswap/pool_tracker.go @@ -8,6 +8,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -25,7 +26,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.WithFields(logger.Fields{ "poolAddress": p.Address, }).Infof("[%s] Start getting new state of pool", d.config.DexID) diff --git a/pkg/source/camelot/pool_tracker.go b/pkg/source/camelot/pool_tracker.go index 7e4007c75..53b24dd25 100644 --- a/pkg/source/camelot/pool_tracker.go +++ b/pkg/source/camelot/pool_tracker.go @@ -11,6 +11,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/timer" ) @@ -26,7 +27,11 @@ func NewPoolTracker(cfg *Config, ethrpcClient *ethrpc.Client) *PoolTracker { } } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { finish := timer.Start(fmt.Sprintf("[%s] get new pool state", d.cfg.DexID)) defer finish() diff --git a/pkg/source/curve/pool_tracker.go b/pkg/source/curve/pool_tracker.go index 23a53bd61..285fa18ec 100644 --- a/pkg/source/curve/pool_tracker.go +++ b/pkg/source/curve/pool_tracker.go @@ -8,6 +8,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -34,6 +35,7 @@ func NewPoolTracker( func (d *PoolTracker) GetNewPoolState( ctx context.Context, p entity.Pool, + _ pool.GetNewPoolStateParams, ) (entity.Pool, error) { switch p.Type { case poolTypeBase: diff --git a/pkg/source/dmm/pool_tracker.go b/pkg/source/dmm/pool_tracker.go index f9ef41f94..dfb59b61b 100644 --- a/pkg/source/dmm/pool_tracker.go +++ b/pkg/source/dmm/pool_tracker.go @@ -9,6 +9,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -23,7 +24,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.WithFields(logger.Fields{ "poolAddress": p.Address, }).Infof("[DMM] Start getting new state of pool") diff --git a/pkg/source/dodo/pool_tracker.go b/pkg/source/dodo/pool_tracker.go index 13e8b0123..80fe6e31c 100644 --- a/pkg/source/dodo/pool_tracker.go +++ b/pkg/source/dodo/pool_tracker.go @@ -15,6 +15,7 @@ import ( cmap "github.com/orcaman/concurrent-map" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -39,7 +40,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { var staticExtraData = struct { Type string `json:"type"` }{} diff --git a/pkg/source/dystopia/pool_tracker.go b/pkg/source/dystopia/pool_tracker.go index da5b98633..71b27b19c 100644 --- a/pkg/source/dystopia/pool_tracker.go +++ b/pkg/source/dystopia/pool_tracker.go @@ -8,6 +8,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -20,7 +21,11 @@ func NewPoolTracker(ethrpcClient *ethrpc.Client) *PoolTracker { } } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { log := logger.WithFields(logger.Fields{ "poolAddress": p.Address, }) diff --git a/pkg/source/elastic/pool_tracker.go b/pkg/source/elastic/pool_tracker.go index 493ac4d87..849650846 100644 --- a/pkg/source/elastic/pool_tracker.go +++ b/pkg/source/elastic/pool_tracker.go @@ -13,6 +13,7 @@ import ( "github.com/sourcegraph/conc/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" graphqlPkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/graphql" ) @@ -35,7 +36,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ dexpool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.Infof("[Elastic] Start getting new state of pool: %v", p.Address) var ( diff --git a/pkg/source/fraxswap/pool_tracker.go b/pkg/source/fraxswap/pool_tracker.go index b76c2b160..2038c5d4d 100644 --- a/pkg/source/fraxswap/pool_tracker.go +++ b/pkg/source/fraxswap/pool_tracker.go @@ -10,6 +10,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -22,7 +23,11 @@ func NewPoolTracker(ethrpcClient *ethrpc.Client) *PoolTracker { } } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { log := logger.WithFields(logger.Fields{ "poolAddress": p.Address, }) diff --git a/pkg/source/gmx/pool_tracker.go b/pkg/source/gmx/pool_tracker.go index ebd36fa75..cafaab690 100644 --- a/pkg/source/gmx/pool_tracker.go +++ b/pkg/source/gmx/pool_tracker.go @@ -10,6 +10,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -27,7 +28,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { log := logger.WithFields(logger.Fields{ "liquiditySource": DexTypeGmx, "poolAddress": p.Address, diff --git a/pkg/source/ironstable/pool_tracker.go b/pkg/source/ironstable/pool_tracker.go index 1d900f341..f94cd74c6 100644 --- a/pkg/source/ironstable/pool_tracker.go +++ b/pkg/source/ironstable/pool_tracker.go @@ -11,6 +11,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/timer" ) @@ -26,7 +27,11 @@ func NewPoolTracker(cfg *Config, ethrpcClient *ethrpc.Client) (*PoolTracker, err }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { finish := timer.Start(fmt.Sprintf("[%s] get new pool state", d.cfg.DexID)) defer finish() diff --git a/pkg/source/iziswap/pool_tracker.go b/pkg/source/iziswap/pool_tracker.go index a855e980e..e2c682f07 100644 --- a/pkg/source/iziswap/pool_tracker.go +++ b/pkg/source/iziswap/pool_tracker.go @@ -7,6 +7,7 @@ import ( "github.com/KyberNetwork/ethrpc" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/logger" "github.com/ethereum/go-ethereum/common" "github.com/izumiFinance/iZiSwap-SDK-go/swap" @@ -31,7 +32,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ dexpool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.Infof("[iZiSwap] Start getting new state of pool: %v", p.Address) g := pool.New().WithContext(ctx) diff --git a/pkg/source/kyber-pmm/pool_tracker.go b/pkg/source/kyber-pmm/pool_tracker.go index c9192d1d7..91a008a17 100644 --- a/pkg/source/kyber-pmm/pool_tracker.go +++ b/pkg/source/kyber-pmm/pool_tracker.go @@ -10,6 +10,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -24,7 +25,11 @@ func NewPoolTracker(cfg *Config, client IClient) *PoolTracker { } } -func (t *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (t *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.Infof("[Kyber PMM] Start getting new states for pool %v", p.Address) if len(p.Tokens) != 2 { diff --git a/pkg/source/lido-steth/pool_tracker.go b/pkg/source/lido-steth/pool_tracker.go index cfe968f78..3bf47543b 100644 --- a/pkg/source/lido-steth/pool_tracker.go +++ b/pkg/source/lido-steth/pool_tracker.go @@ -9,6 +9,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -21,7 +22,11 @@ func NewPoolTracker(ethrpcClient *ethrpc.Client) *PoolTracker { } } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { log := logger.WithFields(logger.Fields{ "poolAddress": p.Address, }) diff --git a/pkg/source/lido/pool_tracker.go b/pkg/source/lido/pool_tracker.go index 804648648..1f86bf6c0 100644 --- a/pkg/source/lido/pool_tracker.go +++ b/pkg/source/lido/pool_tracker.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -23,7 +24,11 @@ func NewPoolTracker(ethrpcClient *ethrpc.Client) *PoolTracker { } } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { log := logger.WithFields(logger.Fields{ "poolAddress": p.Address, }) diff --git a/pkg/source/limitorder/pool_tracker.go b/pkg/source/limitorder/pool_tracker.go index 512af7e47..ac66e8ad6 100644 --- a/pkg/source/limitorder/pool_tracker.go +++ b/pkg/source/limitorder/pool_tracker.go @@ -11,6 +11,7 @@ import ( "golang.org/x/sync/errgroup" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -27,7 +28,11 @@ func NewPoolTracker(cfg *Config) *PoolTracker { } } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.Infof("[LimitOrder] Start getting new states for pool %v", p.Address) if len(p.Tokens) < 2 { err := errors.New("number of token should be greater than or equal 2") diff --git a/pkg/source/madmex/pool_tracker.go b/pkg/source/madmex/pool_tracker.go index 1e20e61ef..3e9582454 100644 --- a/pkg/source/madmex/pool_tracker.go +++ b/pkg/source/madmex/pool_tracker.go @@ -10,6 +10,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -27,7 +28,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { log := logger.WithFields(logger.Fields{ "liquiditySource": DexTypeMadmex, "poolAddress": p.Address, diff --git a/pkg/source/makerpsm/pool_tracker.go b/pkg/source/makerpsm/pool_tracker.go index eb9ab6063..a03aca88b 100644 --- a/pkg/source/makerpsm/pool_tracker.go +++ b/pkg/source/makerpsm/pool_tracker.go @@ -10,6 +10,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -26,7 +27,11 @@ func NewPoolTracker(cfg *Config, ethrpcClient *ethrpc.Client) *PoolTracker { } } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, pool entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + pool entity.Pool, + _ dexpool.GetNewPoolStateParams, +) (entity.Pool, error) { defer func(startTime time.Time) { logger. WithFields(logger.Fields{ diff --git a/pkg/source/maverickv1/pool_tracker.go b/pkg/source/maverickv1/pool_tracker.go index 95a8f85a7..34771230b 100644 --- a/pkg/source/maverickv1/pool_tracker.go +++ b/pkg/source/maverickv1/pool_tracker.go @@ -3,12 +3,14 @@ package maverickv1 import ( "context" "encoding/json" - "github.com/KyberNetwork/ethrpc" - "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" - "github.com/KyberNetwork/logger" "math/big" "strconv" "time" + + "github.com/KyberNetwork/ethrpc" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" + "github.com/KyberNetwork/logger" ) type PoolTracker struct { @@ -26,7 +28,11 @@ func NewPoolTracker( } } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.WithFields(logger.Fields{ "address": p.Address, }).Infof("[%s] Start getting new state of pool", p.Type) diff --git a/pkg/source/metavault/pool_tracker.go b/pkg/source/metavault/pool_tracker.go index 490bda8b3..29684ddbe 100644 --- a/pkg/source/metavault/pool_tracker.go +++ b/pkg/source/metavault/pool_tracker.go @@ -10,6 +10,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -27,7 +28,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { log := logger.WithFields(logger.Fields{ "liquiditySource": DexTypeMetavault, "poolAddress": p.Address, diff --git a/pkg/source/muteswitch/pool_tracker.go b/pkg/source/muteswitch/pool_tracker.go index eee32c25e..e774112f6 100644 --- a/pkg/source/muteswitch/pool_tracker.go +++ b/pkg/source/muteswitch/pool_tracker.go @@ -9,6 +9,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -26,7 +27,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.WithFields(logger.Fields{ "address": p.Address, }).Infof("[%s] Start getting new state of pool", p.Type) diff --git a/pkg/source/nerve/pool_tracker.go b/pkg/source/nerve/pool_tracker.go index b6e9d4405..4d87fd5df 100644 --- a/pkg/source/nerve/pool_tracker.go +++ b/pkg/source/nerve/pool_tracker.go @@ -11,6 +11,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -28,7 +29,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { log := logger.WithFields(logger.Fields{ "liquiditySource": DexTypeNerve, "poolAddress": p.Address, diff --git a/pkg/source/oneswap/pool_tracker.go b/pkg/source/oneswap/pool_tracker.go index eb4660e4a..8b40ee3e9 100644 --- a/pkg/source/oneswap/pool_tracker.go +++ b/pkg/source/oneswap/pool_tracker.go @@ -11,6 +11,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -23,7 +24,11 @@ func NewPoolTracker(ethrpcClient *ethrpc.Client) *PoolTracker { } } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.Infof("[Oneswap] Start getting new state of pool %v", p.Address) var ( diff --git a/pkg/source/pancakev3/pool_tracker.go b/pkg/source/pancakev3/pool_tracker.go index d0201f0af..6ec4da5f8 100644 --- a/pkg/source/pancakev3/pool_tracker.go +++ b/pkg/source/pancakev3/pool_tracker.go @@ -13,6 +13,7 @@ import ( "github.com/sourcegraph/conc/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" graphqlPkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/graphql" ) @@ -35,7 +36,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ dexpool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.Infof("[Pancake V3] Start getting new state of pool: %v", p.Address) var ( diff --git a/pkg/source/pearl/pool_tracker.go b/pkg/source/pearl/pool_tracker.go index c0811741c..8cc1dc253 100644 --- a/pkg/source/pearl/pool_tracker.go +++ b/pkg/source/pearl/pool_tracker.go @@ -9,6 +9,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -26,7 +27,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.WithFields(logger.Fields{ "address": p.Address, }).Infof("[%s] Start getting new state of pool", p.Type) diff --git a/pkg/source/platypus/pool_tracker.go b/pkg/source/platypus/pool_tracker.go index becf94748..9bc51cd84 100644 --- a/pkg/source/platypus/pool_tracker.go +++ b/pkg/source/platypus/pool_tracker.go @@ -12,6 +12,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -24,7 +25,11 @@ func NewPoolTracker(ethClient *ethrpc.Client) *PoolTracker { } } -func (t *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (t *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.WithFields(logger.Fields{ "address": p.Address, }).Infof("[Platypus] Start getting new pool's state") diff --git a/pkg/source/polydex/pool_tracker.go b/pkg/source/polydex/pool_tracker.go index 49f461e7b..a2eb58a63 100644 --- a/pkg/source/polydex/pool_tracker.go +++ b/pkg/source/polydex/pool_tracker.go @@ -8,6 +8,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -22,7 +23,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { log := logger.WithFields(logger.Fields{ "liquiditySource": DexTypePolydex, "poolAddress": p.Address, diff --git a/pkg/source/pool/iface.go b/pkg/source/pool/iface.go index 13b503a21..47747c389 100644 --- a/pkg/source/pool/iface.go +++ b/pkg/source/pool/iface.go @@ -5,6 +5,7 @@ import ( "math/big" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/ethereum/go-ethereum/core/types" ) type IPoolsListUpdater interface { @@ -17,6 +18,10 @@ type IPoolsListUpdater interface { GetNewPools(ctx context.Context, metadataBytes []byte) ([]entity.Pool, []byte, error) } +type GetNewPoolStateParams struct { + Logs []types.Log +} + type IPoolTracker interface { GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) } diff --git a/pkg/source/ramses/pool_tracker.go b/pkg/source/ramses/pool_tracker.go index 9339e593c..3e350ef27 100644 --- a/pkg/source/ramses/pool_tracker.go +++ b/pkg/source/ramses/pool_tracker.go @@ -12,6 +12,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -29,7 +30,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { var ( reserve Reserves stableFee, volatileFee, pairFee *big.Int diff --git a/pkg/source/saddle/pool_tracker.go b/pkg/source/saddle/pool_tracker.go index 18f75310c..c5ef4b2d3 100644 --- a/pkg/source/saddle/pool_tracker.go +++ b/pkg/source/saddle/pool_tracker.go @@ -10,6 +10,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -24,7 +25,11 @@ func NewPoolTracker(cfg *Config, ethrpcClient *ethrpc.Client) *PoolTracker { } } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.Infof("[%s] Start getting new state of pool: %v", d.config.DexID, p.Address) var ( diff --git a/pkg/source/syncswap/pool_tracker.go b/pkg/source/syncswap/pool_tracker.go index ed709d9b5..73495f8c6 100644 --- a/pkg/source/syncswap/pool_tracker.go +++ b/pkg/source/syncswap/pool_tracker.go @@ -12,6 +12,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -29,7 +30,11 @@ func NewPoolTracker( } } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { switch p.Type { case poolTypeSyncSwapClassic: return d.getClassicPoolState(ctx, p) diff --git a/pkg/source/synthetix/pool_tracker.go b/pkg/source/synthetix/pool_tracker.go index ea162bf79..dc8a0cfe4 100644 --- a/pkg/source/synthetix/pool_tracker.go +++ b/pkg/source/synthetix/pool_tracker.go @@ -13,6 +13,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/timer" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/valueobject" ) @@ -51,7 +52,11 @@ func NewPoolTracker(cfg *Config, ethrpcClient *ethrpc.Client) *PoolTracker { } } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, pool entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + pool entity.Pool, + _ dexpool.GetNewPoolStateParams, +) (entity.Pool, error) { finish := timer.Start(fmt.Sprintf("[%s] get new pool state", d.cfg.DexID)) defer finish() diff --git a/pkg/source/traderjoev20/pool_test.go b/pkg/source/traderjoev20/pool_test.go index cf82b5ca1..1a84d57bc 100644 --- a/pkg/source/traderjoev20/pool_test.go +++ b/pkg/source/traderjoev20/pool_test.go @@ -12,6 +12,7 @@ import ( "github.com/KyberNetwork/ethrpc" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/traderjoecommon" ) @@ -68,7 +69,7 @@ func TestGetPoolState(t *testing.T) { }) require.NoError(t, err) - pool, err := tracker.GetNewPoolState(context.Background(), entity.Pool{Address: usdceUSDCPool}) + pool, err := tracker.GetNewPoolState(context.Background(), entity.Pool{Address: usdceUSDCPool}, dexpool.GetNewPoolStateParams{}) require.NoError(t, err) spew.Dump(pool) diff --git a/pkg/source/traderjoev20/pool_tracker.go b/pkg/source/traderjoev20/pool_tracker.go index ace16c994..80918ed8b 100644 --- a/pkg/source/traderjoev20/pool_tracker.go +++ b/pkg/source/traderjoev20/pool_tracker.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/traderjoecommon" ) @@ -29,7 +30,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.Infof("[TraderJoe v2.0] Start getting new state of pool: %v", p.Address) rpcRequest := d.EthrpcClient.NewRequest() diff --git a/pkg/source/traderjoev21/pool_test.go b/pkg/source/traderjoev21/pool_test.go index d5fe7fa5a..014537aaf 100644 --- a/pkg/source/traderjoev21/pool_test.go +++ b/pkg/source/traderjoev21/pool_test.go @@ -12,6 +12,7 @@ import ( "github.com/KyberNetwork/ethrpc" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/traderjoecommon" ) @@ -65,7 +66,7 @@ func TestGetPoolState(t *testing.T) { tracker, err := NewPoolTracker(client) require.NoError(t, err) - pool, err := tracker.GetNewPoolState(context.Background(), entity.Pool{Address: btcbUSDCPool}) + pool, err := tracker.GetNewPoolState(context.Background(), entity.Pool{Address: btcbUSDCPool}, dexpool.GetNewPoolStateParams{}) require.NoError(t, err) spew.Dump(pool) diff --git a/pkg/source/traderjoev21/pool_tracker.go b/pkg/source/traderjoev21/pool_tracker.go index a551d002b..e63e68dff 100644 --- a/pkg/source/traderjoev21/pool_tracker.go +++ b/pkg/source/traderjoev21/pool_tracker.go @@ -10,6 +10,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/traderjoecommon" ) @@ -25,7 +26,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.Infof("[TraderJoe v2.0] Start getting new state of pool: %v", p.Address) rpcRequest := d.EthrpcClient.NewRequest() diff --git a/pkg/source/uniswap/pool_tracker.go b/pkg/source/uniswap/pool_tracker.go index 422af0608..1e84592a8 100644 --- a/pkg/source/uniswap/pool_tracker.go +++ b/pkg/source/uniswap/pool_tracker.go @@ -8,6 +8,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -22,7 +23,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.Infof("[Uniswap V2] Start getting new state of pool: %v", p.Address) rpcRequest := d.ethrpcClient.NewRequest() diff --git a/pkg/source/uniswapv3/pool_tracker.go b/pkg/source/uniswapv3/pool_tracker.go index b8a5bb8e2..5eaf40327 100644 --- a/pkg/source/uniswapv3/pool_tracker.go +++ b/pkg/source/uniswapv3/pool_tracker.go @@ -15,6 +15,7 @@ import ( "github.com/sourcegraph/conc/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" graphqlPkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/graphql" ) @@ -70,7 +71,11 @@ func initializeConfig(cfg *Config) (*Config, error) { return cfg, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ dexpool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.Infof("[%s] Start getting new state of pool: %v", d.config.DexID, p.Address) var ( diff --git a/pkg/source/velocimeter/pool_tracker.go b/pkg/source/velocimeter/pool_tracker.go index 60cca988a..7c06d1ea8 100644 --- a/pkg/source/velocimeter/pool_tracker.go +++ b/pkg/source/velocimeter/pool_tracker.go @@ -11,6 +11,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -28,14 +29,18 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.WithFields(logger.Fields{ "address": p.Address, }).Infof("[%s] Start getting new state of pool", p.Type) var ( - reserve Reserves - poolFee *big.Int + reserve Reserves + poolFee *big.Int ) calls := d.ethrpcClient.NewRequest().SetContext(ctx) diff --git a/pkg/source/velodrome/pool_tracker.go b/pkg/source/velodrome/pool_tracker.go index c72e01f81..778d908b1 100644 --- a/pkg/source/velodrome/pool_tracker.go +++ b/pkg/source/velodrome/pool_tracker.go @@ -9,6 +9,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -26,7 +27,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.WithFields(logger.Fields{ "address": p.Address, }).Infof("[%s] Start getting new state of pool", p.Type) diff --git a/pkg/source/velodromev2/pool_tracker.go b/pkg/source/velodromev2/pool_tracker.go index 466ba8839..639183fb4 100644 --- a/pkg/source/velodromev2/pool_tracker.go +++ b/pkg/source/velodromev2/pool_tracker.go @@ -2,14 +2,15 @@ package velodromev2 import ( "context" - "github.com/ethereum/go-ethereum/common" "math/big" "time" "github.com/KyberNetwork/ethrpc" "github.com/KyberNetwork/logger" + "github.com/ethereum/go-ethereum/common" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -27,7 +28,11 @@ func NewPoolTracker( }, nil } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.WithFields(logger.Fields{ "address": p.Address, }).Infof("[%s] Start getting new state of pool", p.Type) diff --git a/pkg/source/wombat/pool_tracker.go b/pkg/source/wombat/pool_tracker.go index ad6c6ee87..9230b4348 100644 --- a/pkg/source/wombat/pool_tracker.go +++ b/pkg/source/wombat/pool_tracker.go @@ -3,12 +3,14 @@ package wombat import ( "context" "encoding/json" + "math/big" + "time" + "github.com/KyberNetwork/ethrpc" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" + "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/logger" "github.com/ethereum/go-ethereum/common" - "math/big" - "time" ) type PoolTracker struct { @@ -23,7 +25,11 @@ func NewPoolTracker(cfg *Config, ethrpcClient *ethrpc.Client) *PoolTracker { } } -func (d *PoolTracker) GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) { +func (d *PoolTracker) GetNewPoolState( + ctx context.Context, + p entity.Pool, + _ pool.GetNewPoolStateParams, +) (entity.Pool, error) { logger.WithFields(logger.Fields{ "address": p.Address, }).Infof("[%s] Start getting new states of pool", p.Type) From 0f2faf4b2b8adc9f3605f721f158f9b9ea536245 Mon Sep 17 00:00:00 2001 From: Hiep Nguyen Date: Thu, 21 Sep 2023 15:10:02 +0700 Subject: [PATCH 2/5] Upgrade ethrpc package to v0.4.0 --- go.mod | 2 +- go.sum | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index c2b78d056..66c8f511c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.20 require ( github.com/KyberNetwork/blockchain-toolkit v0.2.0 github.com/KyberNetwork/elastic-go-sdk/v2 v2.0.2 - github.com/KyberNetwork/ethrpc v0.3.0 + github.com/KyberNetwork/ethrpc v0.4.0 github.com/KyberNetwork/logger v0.1.0 github.com/KyberNetwork/pancake-v3-sdk v0.1.0 github.com/daoleno/uniswap-sdk-core v0.1.7 diff --git a/go.sum b/go.sum index 0fce97966..945d5d5ce 100644 --- a/go.sum +++ b/go.sum @@ -5,6 +5,8 @@ github.com/KyberNetwork/elastic-go-sdk/v2 v2.0.2 h1:kN7ez6MPJEaFbacmvR+22PRa5pJk github.com/KyberNetwork/elastic-go-sdk/v2 v2.0.2/go.mod h1:3DThBH6zHAYSWUVmtj9deQO1XuiwbawdKxj5yV4SuMo= github.com/KyberNetwork/ethrpc v0.3.0 h1:LoqtmSR4ABgsCvSc+qPUbPibPhVZpd12YQLbMGAyVWk= github.com/KyberNetwork/ethrpc v0.3.0/go.mod h1:QOlJ7bWKIVlo3ZfJt3cmyc5oke9uU+4hl9Vth5IHK/Y= +github.com/KyberNetwork/ethrpc v0.4.0 h1:ghG8s8D/V9fWAQMnTicIDUv0I6VFDSqN3T6kbE9No6c= +github.com/KyberNetwork/ethrpc v0.4.0/go.mod h1:QOlJ7bWKIVlo3ZfJt3cmyc5oke9uU+4hl9Vth5IHK/Y= github.com/KyberNetwork/logger v0.1.0 h1:Iibu9Ls+tipjR+C0iXhzUYM1VtRgmmR1HHWGufPYcbs= github.com/KyberNetwork/logger v0.1.0/go.mod h1:zBqHbtJ3nJn6HQnp6UW8pbQkR+U6tSRFd5CzfiKL3Kw= github.com/KyberNetwork/pancake-v3-sdk v0.1.0 h1:HVUD13Qbwl4kiU1uSprQVpkis6fYYp3A32mVuK+f1Iw= @@ -114,6 +116,7 @@ github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9yS github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= From b1ff06346e709683d8008c4c1af2bfa0373e430e Mon Sep 17 00:00:00 2001 From: Hiep Nguyen Date: Thu, 21 Sep 2023 17:00:26 +0700 Subject: [PATCH 3/5] rename dexpool to sourcePool --- pkg/source/algebrav1/pool_tracker.go | 4 ++-- pkg/source/elastic/pool_tracker.go | 4 ++-- pkg/source/iziswap/pool_tracker.go | 4 ++-- pkg/source/makerpsm/pool_tracker.go | 4 ++-- pkg/source/pancakev3/pool_tracker.go | 4 ++-- pkg/source/synthetix/pool_tracker.go | 4 ++-- pkg/source/traderjoev21/pool_test.go | 4 ++-- pkg/source/uniswapv3/pool_tracker.go | 4 ++-- 8 files changed, 16 insertions(+), 16 deletions(-) diff --git a/pkg/source/algebrav1/pool_tracker.go b/pkg/source/algebrav1/pool_tracker.go index 68e89cf0e..3f23f1d8b 100644 --- a/pkg/source/algebrav1/pool_tracker.go +++ b/pkg/source/algebrav1/pool_tracker.go @@ -15,7 +15,7 @@ import ( "github.com/sourcegraph/conc/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" - dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" + sourcePool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/bignumber" graphqlPkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/graphql" ) @@ -42,7 +42,7 @@ func NewPoolTracker( func (d *PoolTracker) GetNewPoolState( ctx context.Context, p entity.Pool, - _ dexpool.GetNewPoolStateParams, + _ sourcePool.GetNewPoolStateParams, ) (entity.Pool, error) { logger.Infof("[%v] Start getting new state of pool: %v", d.config.DexID, p.Address) diff --git a/pkg/source/elastic/pool_tracker.go b/pkg/source/elastic/pool_tracker.go index 849650846..7599dce58 100644 --- a/pkg/source/elastic/pool_tracker.go +++ b/pkg/source/elastic/pool_tracker.go @@ -13,7 +13,7 @@ import ( "github.com/sourcegraph/conc/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" - dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" + sourcePool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" graphqlPkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/graphql" ) @@ -39,7 +39,7 @@ func NewPoolTracker( func (d *PoolTracker) GetNewPoolState( ctx context.Context, p entity.Pool, - _ dexpool.GetNewPoolStateParams, + _ sourcePool.GetNewPoolStateParams, ) (entity.Pool, error) { logger.Infof("[Elastic] Start getting new state of pool: %v", p.Address) diff --git a/pkg/source/iziswap/pool_tracker.go b/pkg/source/iziswap/pool_tracker.go index e2c682f07..1189335c1 100644 --- a/pkg/source/iziswap/pool_tracker.go +++ b/pkg/source/iziswap/pool_tracker.go @@ -7,7 +7,7 @@ import ( "github.com/KyberNetwork/ethrpc" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" - dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" + sourcePool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/logger" "github.com/ethereum/go-ethereum/common" "github.com/izumiFinance/iZiSwap-SDK-go/swap" @@ -35,7 +35,7 @@ func NewPoolTracker( func (d *PoolTracker) GetNewPoolState( ctx context.Context, p entity.Pool, - _ dexpool.GetNewPoolStateParams, + _ sourcePool.GetNewPoolStateParams, ) (entity.Pool, error) { logger.Infof("[iZiSwap] Start getting new state of pool: %v", p.Address) diff --git a/pkg/source/makerpsm/pool_tracker.go b/pkg/source/makerpsm/pool_tracker.go index a03aca88b..17de1f529 100644 --- a/pkg/source/makerpsm/pool_tracker.go +++ b/pkg/source/makerpsm/pool_tracker.go @@ -10,7 +10,7 @@ import ( "github.com/KyberNetwork/logger" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" - dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" + sourcePool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" ) type PoolTracker struct { @@ -30,7 +30,7 @@ func NewPoolTracker(cfg *Config, ethrpcClient *ethrpc.Client) *PoolTracker { func (d *PoolTracker) GetNewPoolState( ctx context.Context, pool entity.Pool, - _ dexpool.GetNewPoolStateParams, + _ sourcePool.GetNewPoolStateParams, ) (entity.Pool, error) { defer func(startTime time.Time) { logger. diff --git a/pkg/source/pancakev3/pool_tracker.go b/pkg/source/pancakev3/pool_tracker.go index 6ec4da5f8..1e1489df6 100644 --- a/pkg/source/pancakev3/pool_tracker.go +++ b/pkg/source/pancakev3/pool_tracker.go @@ -13,7 +13,7 @@ import ( "github.com/sourcegraph/conc/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" - dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" + sourcePool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" graphqlPkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/graphql" ) @@ -39,7 +39,7 @@ func NewPoolTracker( func (d *PoolTracker) GetNewPoolState( ctx context.Context, p entity.Pool, - _ dexpool.GetNewPoolStateParams, + _ sourcePool.GetNewPoolStateParams, ) (entity.Pool, error) { logger.Infof("[Pancake V3] Start getting new state of pool: %v", p.Address) diff --git a/pkg/source/synthetix/pool_tracker.go b/pkg/source/synthetix/pool_tracker.go index dc8a0cfe4..31fc9816f 100644 --- a/pkg/source/synthetix/pool_tracker.go +++ b/pkg/source/synthetix/pool_tracker.go @@ -13,7 +13,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" - dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" + sourcePool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/timer" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/valueobject" ) @@ -55,7 +55,7 @@ func NewPoolTracker(cfg *Config, ethrpcClient *ethrpc.Client) *PoolTracker { func (d *PoolTracker) GetNewPoolState( ctx context.Context, pool entity.Pool, - _ dexpool.GetNewPoolStateParams, + _ sourcePool.GetNewPoolStateParams, ) (entity.Pool, error) { finish := timer.Start(fmt.Sprintf("[%s] get new pool state", d.cfg.DexID)) defer finish() diff --git a/pkg/source/traderjoev21/pool_test.go b/pkg/source/traderjoev21/pool_test.go index 014537aaf..173f5d97d 100644 --- a/pkg/source/traderjoev21/pool_test.go +++ b/pkg/source/traderjoev21/pool_test.go @@ -12,7 +12,7 @@ import ( "github.com/KyberNetwork/ethrpc" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" - dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" + sourcePool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/traderjoecommon" ) @@ -66,7 +66,7 @@ func TestGetPoolState(t *testing.T) { tracker, err := NewPoolTracker(client) require.NoError(t, err) - pool, err := tracker.GetNewPoolState(context.Background(), entity.Pool{Address: btcbUSDCPool}, dexpool.GetNewPoolStateParams{}) + pool, err := tracker.GetNewPoolState(context.Background(), entity.Pool{Address: btcbUSDCPool}, sourcePool.GetNewPoolStateParams{}) require.NoError(t, err) spew.Dump(pool) diff --git a/pkg/source/uniswapv3/pool_tracker.go b/pkg/source/uniswapv3/pool_tracker.go index 5eaf40327..39f4da9d1 100644 --- a/pkg/source/uniswapv3/pool_tracker.go +++ b/pkg/source/uniswapv3/pool_tracker.go @@ -15,7 +15,7 @@ import ( "github.com/sourcegraph/conc/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" - dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" + sourcePool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" graphqlPkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/util/graphql" ) @@ -74,7 +74,7 @@ func initializeConfig(cfg *Config) (*Config, error) { func (d *PoolTracker) GetNewPoolState( ctx context.Context, p entity.Pool, - _ dexpool.GetNewPoolStateParams, + _ sourcePool.GetNewPoolStateParams, ) (entity.Pool, error) { logger.Infof("[%s] Start getting new state of pool: %v", d.config.DexID, p.Address) From 298b21be6bd72d9b7b5ee3719cd76233a92f5e83 Mon Sep 17 00:00:00 2001 From: Hiep Nguyen Date: Thu, 21 Sep 2023 17:04:47 +0700 Subject: [PATCH 4/5] Refine code for test --- pkg/source/traderjoev20/pool_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/source/traderjoev20/pool_test.go b/pkg/source/traderjoev20/pool_test.go index 1a84d57bc..5c5a167a6 100644 --- a/pkg/source/traderjoev20/pool_test.go +++ b/pkg/source/traderjoev20/pool_test.go @@ -12,7 +12,7 @@ import ( "github.com/KyberNetwork/ethrpc" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" - dexpool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" + sourcePool "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/traderjoecommon" ) @@ -69,7 +69,7 @@ func TestGetPoolState(t *testing.T) { }) require.NoError(t, err) - pool, err := tracker.GetNewPoolState(context.Background(), entity.Pool{Address: usdceUSDCPool}, dexpool.GetNewPoolStateParams{}) + pool, err := tracker.GetNewPoolState(context.Background(), entity.Pool{Address: usdceUSDCPool}, sourcePool.GetNewPoolStateParams{}) require.NoError(t, err) spew.Dump(pool) From 96a58baef3527c48fe135a2c420f75127d6651de Mon Sep 17 00:00:00 2001 From: Hiep Nguyen Date: Fri, 22 Sep 2023 13:34:18 +0700 Subject: [PATCH 5/5] Correct PoolTracker interface --- pkg/source/pool/iface.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/source/pool/iface.go b/pkg/source/pool/iface.go index 47747c389..eaccd101f 100644 --- a/pkg/source/pool/iface.go +++ b/pkg/source/pool/iface.go @@ -23,7 +23,7 @@ type GetNewPoolStateParams struct { } type IPoolTracker interface { - GetNewPoolState(ctx context.Context, p entity.Pool) (entity.Pool, error) + GetNewPoolState(ctx context.Context, p entity.Pool, params GetNewPoolStateParams) (entity.Pool, error) } type IPoolSimulator interface {