From 64bdb664daa6ac7059436454daaccb532dfa4d90 Mon Sep 17 00:00:00 2001 From: Vu Tien Date: Sun, 23 Feb 2025 08:48:25 +0700 Subject: [PATCH 1/3] get dependencies for wombat --- pkg/source/pool/iface.go | 8 ++++++++ pkg/source/wombat/pool_tracker.go | 26 +++++++++++++++++++------ pkg/source/wombat/pools_list_updater.go | 24 +++++++++++++++++++++++ pkg/source/wombat/type.go | 13 +++++++------ 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/pkg/source/pool/iface.go b/pkg/source/pool/iface.go index 8442414d5..644e529db 100644 --- a/pkg/source/pool/iface.go +++ b/pkg/source/pool/iface.go @@ -21,6 +21,10 @@ type IPoolsListUpdater interface { GetNewPools(ctx context.Context, metadataBytes []byte) ([]entity.Pool, []byte, error) } +type IPoolsListUpdaterWithDependencies interface { + GetDependencies(ctx context.Context, p entity.Pool) ([]string, bool, error) +} + type GetNewPoolStateParams struct { Logs []types.Log } @@ -38,6 +42,10 @@ type IPoolTracker interface { GetNewPoolState(ctx context.Context, p entity.Pool, params GetNewPoolStateParams) (entity.Pool, error) } +type IPoolTrackerWithDependencies interface { + GetDependencies(ctx context.Context, p entity.Pool) ([]string, bool, error) +} + type IPoolSimulator interface { // CalcAmountOut amountOut, fee, gas // the required params is TokenAmountIn and TokenOut. diff --git a/pkg/source/wombat/pool_tracker.go b/pkg/source/wombat/pool_tracker.go index 372f5b623..3420d95af 100644 --- a/pkg/source/wombat/pool_tracker.go +++ b/pkg/source/wombat/pool_tracker.go @@ -11,6 +11,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient/gethclient" "github.com/goccy/go-json" + "github.com/samber/lo" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool" @@ -192,12 +193,13 @@ func (d *PoolTracker) getNewPoolState( } extraByte, err := json.Marshal(Extra{ - Paused: paused, - HaircutRate: haircutRate, - AmpFactor: ampFactor, - StartCovRatio: startCovRatio, - EndCovRatio: endcovRatio, - AssetMap: assetMap, + Paused: paused, + HaircutRate: haircutRate, + AmpFactor: ampFactor, + StartCovRatio: startCovRatio, + EndCovRatio: endcovRatio, + AssetMap: assetMap, + DependenciesStored: true, }) if err != nil { logger.WithFields(logger.Fields{ @@ -220,3 +222,15 @@ func (d *PoolTracker) getNewPoolState( return p, nil } + +func (d *PoolTracker) GetDependencies(ctx context.Context, p entity.Pool) ([]string, bool, error) { + var extra Extra + err := json.Unmarshal([]byte(p.Extra), &extra) + if err != nil { + return nil, false, err + } + + return lo.MapToSlice(extra.AssetMap, func(_ string, asset Asset) string { + return asset.Address + }), extra.DependenciesStored, nil +} diff --git a/pkg/source/wombat/pools_list_updater.go b/pkg/source/wombat/pools_list_updater.go index e7a5ec656..c8e2d862b 100644 --- a/pkg/source/wombat/pools_list_updater.go +++ b/pkg/source/wombat/pools_list_updater.go @@ -10,6 +10,7 @@ import ( "github.com/KyberNetwork/ethrpc" "github.com/KyberNetwork/logger" "github.com/goccy/go-json" + "github.com/samber/lo" "github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity" poollist "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool/list" @@ -111,6 +112,16 @@ func (d *PoolsListUpdater) getNewPoolFromSubgraph(ctx context.Context, lastCreat continue } + extraByte, err := json.Marshal(Extra{ + AssetMap: lo.SliceToMap(p.Assets, func(item AssetSubgraph) (string, Asset) { + return item.ID, Asset{Address: item.ID} + }), + DependenciesStored: true, + }) + if err != nil { + return nil, lastCreateTime, err + } + var newPool = entity.Pool{ Address: p.ID, Exchange: d.config.DexID, @@ -118,6 +129,7 @@ func (d *PoolsListUpdater) getNewPoolFromSubgraph(ctx context.Context, lastCreat Timestamp: time.Now().Unix(), Reserves: reserves, Tokens: tokens, + Extra: string(extraByte), } pools = append(pools, newPool) @@ -221,3 +233,15 @@ func (d *PoolsListUpdater) classifyPoolType(ctx context.Context, p *SubgraphPool return PoolTypeWombatMain, nil } + +func (d *PoolsListUpdater) GetDependencies(ctx context.Context, p entity.Pool) ([]string, bool, error) { + var extra Extra + err := json.Unmarshal([]byte(p.Extra), &extra) + if err != nil { + return nil, false, err + } + + return lo.MapToSlice(extra.AssetMap, func(_ string, asset Asset) string { + return asset.Address + }), extra.DependenciesStored, nil +} diff --git a/pkg/source/wombat/type.go b/pkg/source/wombat/type.go index 1f6e4dff4..a848280b5 100644 --- a/pkg/source/wombat/type.go +++ b/pkg/source/wombat/type.go @@ -3,12 +3,13 @@ package wombat import "math/big" type Extra struct { - Paused bool `json:"paused"` - HaircutRate *big.Int `json:"haircutRate"` - AmpFactor *big.Int `json:"ampFactor"` - StartCovRatio *big.Int `json:"startCovRatio"` - EndCovRatio *big.Int `json:"endCovRatio"` - AssetMap map[string]Asset `json:"assetMap"` + Paused bool `json:"paused"` + HaircutRate *big.Int `json:"haircutRate"` + AmpFactor *big.Int `json:"ampFactor"` + StartCovRatio *big.Int `json:"startCovRatio"` + EndCovRatio *big.Int `json:"endCovRatio"` + AssetMap map[string]Asset `json:"assetMap"` + DependenciesStored bool `json:dependenciesStored` } type Asset struct { From 9b38de63b62fe598b812a9a7c3c8ea139c099186 Mon Sep 17 00:00:00 2001 From: Vu Tien Date: Tue, 25 Feb 2025 06:52:47 +0700 Subject: [PATCH 2/3] lint --- pkg/source/wombat/type.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/source/wombat/type.go b/pkg/source/wombat/type.go index a848280b5..d8e097f3d 100644 --- a/pkg/source/wombat/type.go +++ b/pkg/source/wombat/type.go @@ -9,7 +9,7 @@ type Extra struct { StartCovRatio *big.Int `json:"startCovRatio"` EndCovRatio *big.Int `json:"endCovRatio"` AssetMap map[string]Asset `json:"assetMap"` - DependenciesStored bool `json:dependenciesStored` + DependenciesStored bool `json:"dependenciesStored"` } type Asset struct { From 9293e5fa48a9b9e2c8d5aeb3ab27e11e931bc68f Mon Sep 17 00:00:00 2001 From: Vu Tien Date: Tue, 25 Feb 2025 15:27:39 +0700 Subject: [PATCH 3/3] update json tag --- pkg/source/wombat/type.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/source/wombat/type.go b/pkg/source/wombat/type.go index d8e097f3d..49e711e6a 100644 --- a/pkg/source/wombat/type.go +++ b/pkg/source/wombat/type.go @@ -9,7 +9,7 @@ type Extra struct { StartCovRatio *big.Int `json:"startCovRatio"` EndCovRatio *big.Int `json:"endCovRatio"` AssetMap map[string]Asset `json:"assetMap"` - DependenciesStored bool `json:"dependenciesStored"` + DependenciesStored bool `json:"ds"` } type Asset struct {