diff --git a/client/spot_prices.go b/client/spot_prices.go index eac9481..1cdcfa8 100644 --- a/client/spot_prices.go +++ b/client/spot_prices.go @@ -91,7 +91,8 @@ func (c *Client) QueryBalancerSpotPrice(p pool.Pool, blockNum uint64) indexer.Sp c.reportError(fmt.Errorf("error initializing %s pool caller: %w", p.ExchangePair(), err)) return indexer.SpotPrice{} } - poolRate, err := poolCaller.GetTokenRate(nil, common.HexToAddress(p.TokenAddress)) + + poolRate, err := poolCaller.GetTokenRate(nil, common.HexToAddress(p.BaseAddress)) if err != nil { c.reportError(fmt.Errorf("error getting %s token rate from pool: %w", p.ExchangePair(), err)) return indexer.SpotPrice{} diff --git a/client/swaps.go b/client/swaps.go index f4057da..80e7cc1 100644 --- a/client/swaps.go +++ b/client/swaps.go @@ -129,9 +129,11 @@ func (c *Client) WatchBalancerSwapEvent(p pool.Pool) error { poolIdParam := make([][32]byte, 1) poolIdParam[0] = poolId tokenInParam := make([]common.Address, 1) - tokenInParam[0] = common.HexToAddress(p.TokenAddress) - tokenOutParam := make([]common.Address, 1) - tokenOutParam[0] = common.HexToAddress(p.TokenAddress) + tokenInParam[0] = common.HexToAddress(p.BaseAddress) + tokenOutParam := []common.Address{} + for _, tokenAddress := range p.QuoteAddresses{ + tokenOutParam = append(tokenOutParam, common.HexToAddress(tokenAddress)) + } vaultFilterer, err := vault.NewPoolFilterer(vaultAddress, c.ethClient) if err != nil { @@ -156,7 +158,7 @@ func (c *Client) WatchBalancerSwapEvent(p pool.Pool) error { return err case event := <-eventSink: // query rate from pool contract - poolRate, err := poolCaller.GetRate(nil) + poolRate, err := poolCaller.GetTokenRate(nil, common.HexToAddress(p.BaseAddress)) if err != nil { return err } diff --git a/pool/pool.go b/pool/pool.go index 573d81d..837657c 100644 --- a/pool/pool.go +++ b/pool/pool.go @@ -13,13 +13,14 @@ import ( ) type Pool struct { - Address string `yaml:"address"` - TokenAddress string `yaml:"token_address"` - Base string `yaml:"base"` - Quote string `yaml:"quote"` - BaseDecimal uint64 `yaml:"base_decimal"` - QuoteDecimal uint64 `yaml:"quote_decimal"` - InvertPrice bool `yaml:"invert_price"` + Address string `yaml:"address"` + Base string `yaml:"base"` + Quote string `yaml:"quote"` + BaseAddress string `yaml:"base_address"` + QuoteAddresses []string `yaml:"quote_addresses"` + BaseDecimal uint64 `yaml:"base_decimal"` + QuoteDecimal uint64 `yaml:"quote_decimal"` + InvertPrice bool `yaml:"invert_price"` } func (p *Pool) ExchangePair() string { @@ -78,7 +79,7 @@ func (p *Pool) ConvertBalancerEventToSwap(event *vault.PoolSwap, price *big.Int) BlockNum: indexer.BlockNum(event.Raw.BlockNumber), Timestamp: utils.CurrentUnixTime(), ExchangePair: p.ExchangePair(), - Price: p.SqrtPriceX96ToDec(price), + Price: sdkmath.LegacyNewDecFromBigIntWithPrec(price, 18), Volume: p.swapBalancerVolume(event), } } diff --git a/sample-config.yaml b/sample-config.yaml index 3c1dfef..72b28a6 100644 --- a/sample-config.yaml +++ b/sample-config.yaml @@ -68,9 +68,50 @@ exchanges: - "wss://mainnet.infura.io/ws/v3/6849a09aeeb044b592d46bcdce07ccef" pools: - address: "0x4216d5900a6109bba48418b5e2AB6cc4e61Cf477" - token_address: "0x84631c0d0081FDe56DeB72F6DE77abBbF6A9f93a" + base: "AMPHRETH" + quote: "ETH" + base_address: "0x5fD13359Ba15A84B76f7F87568309040176167cd" + quote_addresses: + - "0x7a4EffD87C2f3C55CA251080b1343b605f327E3a" + - "0x84631c0d0081FDe56DeB72F6DE77abBbF6A9f93a" + - "0xBEEF69Ac7870777598A04B2bd4771c71212E6aBc" + - "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0" + base_decimal: 18 + quote_decimal: 18 + invert_price: false + - address: "0x4216d5900a6109bba48418b5e2AB6cc4e61Cf477" + base: "RSTETH" + quote: "ETH" + base_address: "0x7a4EffD87C2f3C55CA251080b1343b605f327E3a" + quote_addresses: + - "0x5fD13359Ba15A84B76f7F87568309040176167cd" + - "0x84631c0d0081FDe56DeB72F6DE77abBbF6A9f93a" + - "0xBEEF69Ac7870777598A04B2bd4771c71212E6aBc" + - "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0" + base_decimal: 18 + quote_decimal: 18 + invert_price: false + - address: "0x4216d5900a6109bba48418b5e2AB6cc4e61Cf477" base: "RE7LRT" quote: "ETH" + base_address: "0x84631c0d0081FDe56DeB72F6DE77abBbF6A9f93a" + quote_addresses: + - "0x5fD13359Ba15A84B76f7F87568309040176167cd" + - "0x7a4EffD87C2f3C55CA251080b1343b605f327E3a" + - "0xBEEF69Ac7870777598A04B2bd4771c71212E6aBc" + - "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0" + base_decimal: 18 + quote_decimal: 18 + invert_price: false + - address: "0x4216d5900a6109bba48418b5e2AB6cc4e61Cf477" + base: "STEAKLRT" + quote: "ETH" + base_address: "0xBEEF69Ac7870777598A04B2bd4771c71212E6aBc" + quote_addresses: + - "0x5fD13359Ba15A84B76f7F87568309040176167cd" + - "0x7a4EffD87C2f3C55CA251080b1343b605f327E3a" + - "0x84631c0d0081FDe56DeB72F6DE77abBbF6A9f93a" + - "0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0" base_decimal: 18 quote_decimal: 18 invert_price: false