Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into vt/bebop
Browse files Browse the repository at this point in the history
  • Loading branch information
thanhpp committed Oct 4, 2024
2 parents 6368ceb + 9792140 commit 083cf45
Show file tree
Hide file tree
Showing 48 changed files with 905 additions and 124 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pr-bump-go-mod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
uses: KyberNetwork/service-framework/.github/workflows/pr-bump-go-mod.yaml@main
secrets: inherit
with:
repos: '["aggregator-encoding", "pool-service"]'
repos: '["aggregator-encoding", "pool-service", "router-service"]'
1 change: 1 addition & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ jobs:
service: ${{ github.event.repository.name }}
version_bump: ${{ inputs.version_bump }}
version: ${{ inputs.version }}
runs-on: ubuntu-latest
secrets: inherit
28 changes: 28 additions & 0 deletions pkg/liquidity-source/balancer-v2/composable-stable/pool_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/balancer-v2/math"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/balancer-v2/shared"
poolpkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
"github.com/ethereum/go-ethereum/ethclient/gethclient"
)

type PoolTracker struct {
Expand All @@ -35,9 +36,26 @@ func NewPoolTracker(
}

func (t *PoolTracker) GetNewPoolState(
ctx context.Context,
p entity.Pool,
params poolpkg.GetNewPoolStateParams,
) (entity.Pool, error) {
return t.getNewPoolState(ctx, p, params, nil)
}

func (t *PoolTracker) GetNewPoolStateWithOverrides(
ctx context.Context,
p entity.Pool,
params poolpkg.GetNewPoolStateWithOverridesParams,
) (entity.Pool, error) {
return t.getNewPoolState(ctx, p, poolpkg.GetNewPoolStateParams{Logs: params.Logs}, params.Overrides)
}

func (t *PoolTracker) getNewPoolState(
ctx context.Context,
p entity.Pool,
_ poolpkg.GetNewPoolStateParams,
overrides map[common.Address]gethclient.OverrideAccount,
) (entity.Pool, error) {
logger.WithFields(logger.Fields{
"dexId": t.config.DexID,
Expand Down Expand Up @@ -72,6 +90,7 @@ func (t *PoolTracker) GetNewPoolState(
staticExtra.PoolTypeVer,
p.Tokens,
staticExtra.Vault,
overrides,
)
if err != nil {
logger.WithFields(logger.Fields{
Expand Down Expand Up @@ -127,6 +146,7 @@ func (t *PoolTracker) queryRPC(
poolTypeVer int,
tokens []*entity.PoolToken,
vault string,
overrides map[common.Address]gethclient.OverrideAccount,
) (*rpcRes, error) {
var (
tokenNbr = len(tokens)
Expand Down Expand Up @@ -166,6 +186,10 @@ func (t *PoolTracker) queryRPC(
*/

req := t.ethrpcClient.R().SetContext(ctx)
if overrides != nil {
req.SetOverrides(overrides)
}

req.AddCall(&ethrpc.Call{
ABI: shared.VaultABI,
Target: vault,
Expand Down Expand Up @@ -266,6 +290,10 @@ func (t *PoolTracker) queryRPC(

canNotUpdateTokenRates := false
req = t.ethrpcClient.R().SetContext(ctx).SetBlockNumber(blockNbr)
if overrides != nil {
req.SetOverrides(overrides)
}

rateUpdatedTokenIndexes := []int{}
updatedRate := make([]*big.Int, tokenNbr)
for i, token := range tokens {
Expand Down
24 changes: 23 additions & 1 deletion pkg/liquidity-source/balancer-v2/stable/pool_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/balancer-v2/shared"
poolpkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
"github.com/ethereum/go-ethereum/ethclient/gethclient"
)

var ErrReserveNotFound = errors.New("reserve not found")
Expand All @@ -36,9 +37,26 @@ func NewPoolTracker(
}

func (t *PoolTracker) GetNewPoolState(
ctx context.Context,
p entity.Pool,
params poolpkg.GetNewPoolStateParams,
) (entity.Pool, error) {
return t.getNewPoolState(ctx, p, params, nil)
}

func (t *PoolTracker) GetNewPoolStateWithOverrides(
ctx context.Context,
p entity.Pool,
params poolpkg.GetNewPoolStateWithOverridesParams,
) (entity.Pool, error) {
return t.getNewPoolState(ctx, p, poolpkg.GetNewPoolStateParams{Logs: params.Logs}, params.Overrides)
}

func (t *PoolTracker) getNewPoolState(
ctx context.Context,
p entity.Pool,
_ poolpkg.GetNewPoolStateParams,
overrides map[common.Address]gethclient.OverrideAccount,
) (entity.Pool, error) {
logger.WithFields(logger.Fields{
"dexId": t.config.DexID,
Expand Down Expand Up @@ -78,7 +96,7 @@ func (t *PoolTracker) GetNewPoolState(
scalingFactors := oldExtra.ScalingFactors

// call RPC
rpcRes, err := t.queryRPC(ctx, p.Address, staticExtra.PoolID, staticExtra.Vault, staticExtra.PoolType)
rpcRes, err := t.queryRPC(ctx, p.Address, staticExtra.PoolID, staticExtra.Vault, staticExtra.PoolType, overrides)
if err != nil {
return p, err
}
Expand Down Expand Up @@ -168,6 +186,7 @@ func (t *PoolTracker) queryRPC(
poolID string,
vault string,
poolType string,
overrides map[common.Address]gethclient.OverrideAccount,
) (*rpcRes, error) {
var (
poolTokens PoolTokens
Expand All @@ -180,6 +199,9 @@ func (t *PoolTracker) queryRPC(
req := t.ethrpcClient.R().
SetContext(ctx).
SetRequireSuccess(true)
if overrides != nil {
req.SetOverrides(overrides)
}

req.AddCall(&ethrpc.Call{
ABI: shared.VaultABI,
Expand Down
40 changes: 36 additions & 4 deletions pkg/liquidity-source/bancor-v3/pool_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
poolpkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/valueobject"
"github.com/ethereum/go-ethereum/ethclient/gethclient"
)

var (
Expand All @@ -39,9 +40,26 @@ func NewPoolTracker(
}

func (t *PoolTracker) GetNewPoolState(
ctx context.Context,
p entity.Pool,
params poolpkg.GetNewPoolStateParams,
) (entity.Pool, error) {
return t.getNewPoolState(ctx, p, params, nil)
}

func (t *PoolTracker) GetNewPoolStateWithOverrides(
ctx context.Context,
p entity.Pool,
params poolpkg.GetNewPoolStateWithOverridesParams,
) (entity.Pool, error) {
return t.getNewPoolState(ctx, p, poolpkg.GetNewPoolStateParams{Logs: params.Logs}, params.Overrides)
}

func (t *PoolTracker) getNewPoolState(
ctx context.Context,
p entity.Pool,
_ poolpkg.GetNewPoolStateParams,
overrides map[common.Address]gethclient.OverrideAccount,
) (entity.Pool, error) {
logger.WithFields(logger.Fields{
"dexId": t.config.DexID,
Expand All @@ -57,7 +75,7 @@ func (t *PoolTracker) GetNewPoolState(
}).Info("Finish updating state.")
}()

liquidityPools, blockNbr, err := t.getLiquidityPools(ctx, p.Address)
liquidityPools, blockNbr, err := t.getLiquidityPools(ctx, p.Address, overrides)
if err != nil {
logger.WithFields(logger.Fields{
"dexId": t.config.DexID,
Expand All @@ -67,7 +85,7 @@ func (t *PoolTracker) GetNewPoolState(
return p, err
}

collectionByPool, err := t.getCollectionByPool(ctx, blockNbr, p.Address, liquidityPools)
collectionByPool, err := t.getCollectionByPool(ctx, blockNbr, p.Address, liquidityPools, overrides)
if err != nil {
logger.WithFields(logger.Fields{
"dexId": t.config.DexID,
Expand All @@ -77,7 +95,7 @@ func (t *PoolTracker) GetNewPoolState(
return p, err
}

poolCollections, err := t.getPoolCollections(ctx, blockNbr, collectionByPool)
poolCollections, err := t.getPoolCollections(ctx, blockNbr, collectionByPool, overrides)
if err != nil {
logger.WithFields(logger.Fields{
"dexId": t.config.DexID,
Expand Down Expand Up @@ -194,6 +212,7 @@ func (t *PoolTracker) getPoolCollections(
ctx context.Context,
blockNbr *big.Int,
collectionByPool map[string]string,
overrides map[common.Address]gethclient.OverrideAccount,
) (map[string]*poolCollectionResp, error) {
ret := map[string]*poolCollectionResp{}
poolsByPoolCollection := t.groupPoolsByPoolCollection(collectionByPool)
Expand All @@ -203,6 +222,7 @@ func (t *PoolTracker) getPoolCollections(
blockNbr,
poolCollectionAddr,
pools,
overrides,
)
if err != nil {
return nil, err
Expand All @@ -217,11 +237,14 @@ func (t *PoolTracker) getPoolCollection(
blockNbr *big.Int,
poolCollection string,
pools []string,
overrides map[common.Address]gethclient.OverrideAccount,
) (*poolCollectionResp, error) {
req := t.ethrpcClient.R().
SetContext(ctx).
SetBlockNumber(blockNbr)

if overrides != nil {
req.SetOverrides(overrides)
}
poolDatResp := make([]*poolDataResp, len(pools))
for idx, p := range pools {
poolDatResp[idx] = &poolDataResp{}
Expand Down Expand Up @@ -261,10 +284,14 @@ func (t *PoolTracker) getCollectionByPool(
blockNbr *big.Int,
bancorNetworkAddress string,
liquidityPools []string,
overrides map[common.Address]gethclient.OverrideAccount,
) (map[string]string, error) {
req := t.ethrpcClient.R().
SetContext(ctx).
SetBlockNumber(blockNbr)
if overrides != nil {
req.SetOverrides(overrides)
}
poolCollections := make([]common.Address, len(liquidityPools))
for idx, liquidityPool := range liquidityPools {
req.AddCall(&ethrpc.Call{
Expand All @@ -290,9 +317,14 @@ func (t *PoolTracker) getCollectionByPool(
func (t *PoolTracker) getLiquidityPools(
ctx context.Context,
bancorNetworkAddress string,
overrides map[common.Address]gethclient.OverrideAccount,
) ([]string, *big.Int, error) {
var addresses []common.Address
req := t.ethrpcClient.R().SetContext(ctx)
if overrides != nil {
req.SetOverrides(overrides)
}

req.AddCall(&ethrpc.Call{
ABI: bancorNetworkABI,
Target: bancorNetworkAddress,
Expand Down
30 changes: 28 additions & 2 deletions pkg/liquidity-source/bedrock/unieth/pool_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient/gethclient"
)

type PoolTracker struct {
Expand All @@ -23,11 +25,28 @@ func NewPoolTracker(ethrpcClient *ethrpc.Client) *PoolTracker {
}

func (t *PoolTracker) GetNewPoolState(
ctx context.Context,
p entity.Pool,
params pool.GetNewPoolStateParams,
) (entity.Pool, error) {
return t.getNewPoolState(ctx, p, params, nil)
}

func (t *PoolTracker) GetNewPoolStateWithOverrides(
ctx context.Context,
p entity.Pool,
params pool.GetNewPoolStateWithOverridesParams,
) (entity.Pool, error) {
return t.getNewPoolState(ctx, p, pool.GetNewPoolStateParams{Logs: params.Logs}, params.Overrides)
}

func (t *PoolTracker) getNewPoolState(
ctx context.Context,
p entity.Pool,
_ pool.GetNewPoolStateParams,
overrides map[common.Address]gethclient.OverrideAccount,
) (entity.Pool, error) {
extra, blockNumber, err := t.getExtra(ctx)
extra, blockNumber, err := t.getExtra(ctx, overrides)
if err != nil {
return p, err
}
Expand All @@ -44,14 +63,21 @@ func (t *PoolTracker) GetNewPoolState(
return p, nil
}

func (t *PoolTracker) getExtra(ctx context.Context) (PoolExtra, uint64, error) {
func (t *PoolTracker) getExtra(
ctx context.Context,
overrides map[common.Address]gethclient.OverrideAccount,
) (PoolExtra, uint64, error) {
var (
paused bool
totalSupply *big.Int
currentReserve *big.Int
)

getPoolStateRequest := t.ethrpcClient.NewRequest().SetContext(ctx)
if overrides != nil {
getPoolStateRequest.SetOverrides(overrides)
}

getPoolStateRequest.AddCall(&ethrpc.Call{
ABI: StakingABI,
Target: Staking,
Expand Down
22 changes: 22 additions & 0 deletions pkg/liquidity-source/curve/twocrypto-ng/pool_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/entity"
"github.com/KyberNetwork/kyberswap-dex-lib/pkg/liquidity-source/curve/shared"
poolpkg "github.com/KyberNetwork/kyberswap-dex-lib/pkg/source/pool"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethclient/gethclient"
)

type PoolTracker struct {
Expand All @@ -40,9 +42,26 @@ func NewPoolTracker(
}

func (t *PoolTracker) GetNewPoolState(
ctx context.Context,
p entity.Pool,
params poolpkg.GetNewPoolStateParams,
) (entity.Pool, error) {
return t.getNewPoolState(ctx, p, params, nil)
}

func (t *PoolTracker) GetNewPoolStateWithOverrides(
ctx context.Context,
p entity.Pool,
params poolpkg.GetNewPoolStateWithOverridesParams,
) (entity.Pool, error) {
return t.getNewPoolState(ctx, p, poolpkg.GetNewPoolStateParams{Logs: params.Logs}, params.Overrides)
}

func (t *PoolTracker) getNewPoolState(
ctx context.Context,
p entity.Pool,
_ poolpkg.GetNewPoolStateParams,
overrides map[common.Address]gethclient.OverrideAccount,
) (entity.Pool, error) {
lg := t.logger.WithFields(logger.Fields{"poolAddress": p.Address})
lg.Info("Start updating state ...")
Expand All @@ -64,6 +83,9 @@ func (t *PoolTracker) GetNewPoolState(
)

calls := t.ethrpcClient.NewRequest().SetContext(ctx)
if overrides != nil {
calls.SetOverrides(overrides)
}

calls.AddCall(&ethrpc.Call{
ABI: curveTwocryptoNGABI,
Expand Down
8 changes: 8 additions & 0 deletions pkg/liquidity-source/dai-usds/pool_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ func (d *PoolTracker) GetNewPoolState(
) (entity.Pool, error) {
return p, nil
}

func (d *PoolTracker) GetNewPoolStateWithOverrides(
ctx context.Context,
p entity.Pool,
params pool.GetNewPoolStateWithOverridesParams,
) (entity.Pool, error) {
return p, nil
}
Loading

0 comments on commit 083cf45

Please sign in to comment.