Skip to content

Commit

Permalink
feat: fluid t1 state overrides (#537)
Browse files Browse the repository at this point in the history
  • Loading branch information
datluongductuan authored Oct 9, 2024
1 parent edfd70b commit d4cdb0d
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions pkg/liquidity-source/fluid/vault-t1/pool_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

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

type PoolTracker struct {
Expand All @@ -26,11 +27,28 @@ func NewPoolTracker(config *Config, 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) {
swapData, err := t.getPoolSwapData(ctx, p.Address)
swapData, err := t.getPoolSwapData(ctx, p.Address, overrides)
if swapData == nil || err != nil {
logger.WithFields(logger.Fields{"dexType": DexType, "error": err}).Error("Error getPoolSwapData")
return p, err
Expand All @@ -54,8 +72,15 @@ func (t *PoolTracker) GetNewPoolState(
return p, nil
}

func (t *PoolTracker) getPoolSwapData(ctx context.Context, poolAddress string) (*SwapData, error) {
func (t *PoolTracker) getPoolSwapData(
ctx context.Context,
poolAddress string,
overrides map[common.Address]gethclient.OverrideAccount,
) (*SwapData, error) {
req := t.ethrpcClient.R().SetContext(ctx)
if overrides != nil {
req.SetOverrides(overrides)
}

output := &Swap{}
req.AddCall(&ethrpc.Call{
Expand Down

0 comments on commit d4cdb0d

Please sign in to comment.