Skip to content

Commit

Permalink
adding hot fix for eth and token price discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
Defi-Moses committed Apr 12, 2024
1 parent f3c9668 commit 4fd8820
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions services/explorer/consumer/parser/rfqparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"database/sql"
"fmt"
"strings"
"time"

"github.com/jpillora/backoff"
Expand All @@ -20,6 +21,8 @@ import (
rfqTypes "github.com/synapsecns/sanguine/services/explorer/types/fastbridge"
)

const ethCoinGeckoID = "ethereum"

// RFQParser parsers rfq logs.
type RFQParser struct {
// consumerDB is the database to store parsed data in
Expand Down Expand Up @@ -108,16 +111,24 @@ func (p *RFQParser) MatureLogs(ctx context.Context, rfqEvent *model.RFQEvent, iF
timeStampBig := uint64(*timeStamp)
rfqEvent.TimeStamp = &timeStampBig

tokenData, err := p.tokenDataService.GetTokenData(ctx, chainID, common.HexToAddress(rfqEvent.OriginToken))
if err != nil {
logger.Errorf("could not get token data: %v", err)
return nil, fmt.Errorf("could not get pool token data: %w", err)
}
decimals := tokenData.Decimals()
rfqEvent.TokenSymbol = tokenData.TokenID()
var curCoinGeckoId string

Check failure on line 114 in services/explorer/consumer/parser/rfqparser.go

View workflow job for this annotation

GitHub Actions / Lint (services/explorer)

var `curCoinGeckoId` should be `curCoinGeckoID` (golint)
tokenAddressStr := common.HexToAddress(rfqEvent.OriginToken).Hex()
const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"

rfqEvent.TokenDecimal = &decimals
p.applyPriceData(ctx, rfqEvent, usdcCoinGeckoID)
if strings.EqualFold(tokenAddressStr, ethAddress) {
rfqEvent.TokenSymbol = "ETH"
rfqEvent.TokenDecimal = new(uint8)
*rfqEvent.TokenDecimal = 18
curCoinGeckoId = ethCoinGeckoID
} else {
// Assuming any other token is USDC
rfqEvent.TokenSymbol = "USDC"
rfqEvent.TokenDecimal = new(uint8)
*rfqEvent.TokenDecimal = 6
curCoinGeckoId = usdcCoinGeckoID
}
// find the price data for that specific token
p.applyPriceData(ctx, rfqEvent, curCoinGeckoId)

// Would store into bridge database with a new goroutine but saw unreliable storage of events w/parent context cancellation.
bridgeEvent := rfqEventToBridgeEvent(*rfqEvent)
Expand Down Expand Up @@ -159,7 +170,7 @@ func (p *RFQParser) applyPriceData(ctx context.Context, rfqEvent *model.RFQEvent
if rfqEvent.OriginAmount != nil {
amountUSD := GetAmountUSD(rfqEvent.OriginAmount, *rfqEvent.TokenDecimal, tokenPrice)
if amountUSD != nil {
logger.Warnf("RFQ GetAmountUSD could not get token price for coingecko token: %s", coinGeckoID)
logger.Warnf("RFQ GetAmountUSD properly found the token price for coingecko token: %s", coinGeckoID)
rfqEvent.AmountUSD = *amountUSD
}
}
Expand Down

0 comments on commit 4fd8820

Please sign in to comment.