Skip to content

Commit

Permalink
Updated explorer indexer for migration (#1685)
Browse files Browse the repository at this point in the history
  • Loading branch information
bsgrigorov authored Dec 23, 2023
1 parent 45ab6d6 commit ef79e78
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 4 deletions.
2 changes: 0 additions & 2 deletions services/explorer/config/indexer/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ func (c ChainConfig) IsValid() error {
switch {
case c.ChainID == 0:
return fmt.Errorf("chain_id, %w", config.ErrRequiredGlobalField)
case c.RPCURL == "":
return fmt.Errorf("rpc_url, %w", config.ErrRequiredGlobalField)
case c.MaxGoroutines == 0:
return fmt.Errorf("max_goroutines, %w", config.ErrRequiredGlobalField)
}
Expand Down
16 changes: 14 additions & 2 deletions services/explorer/consumer/parser/cctpparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,19 @@ func (c *CCTPParser) MatureLogs(ctx context.Context, cctpEvent *model.CCTPEvent,
return nil, fmt.Errorf("could not get pool token data: %w", err)
}
decimals := uint8(usdcDecimals)
// Hotfix
if chainID == 8453 &&(cctpEvent.Token == "0x417Ac0e078398C154EdFadD9Ef675d30Be60Af93" || cctpEvent.Token == "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb") {
decimals = 18
}
cctpEvent.TokenSymbol = tokenData.TokenID()
if (cctpEvent.Token == "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1") {
decimals = 18
cctpEvent.TokenSymbol = "DAI"
}
if chainID == 10 && (cctpEvent.Token == "0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9") {
decimals = 18
cctpEvent.TokenSymbol = "sUSD"
}
cctpEvent.TokenDecimal = &decimals
c.applyPriceData(ctx, cctpEvent, usdcCoinGeckoID)

Expand Down Expand Up @@ -156,13 +168,13 @@ func (c *CCTPParser) applyPriceData(ctx context.Context, cctpEvent *model.CCTPEv
}

if cctpEvent.Amount != nil {
amountUSD := GetAmountUSD(cctpEvent.Amount, usdcDecimals, tokenPrice)
amountUSD := GetAmountUSD(cctpEvent.Amount, *cctpEvent.TokenDecimal, tokenPrice)
if amountUSD != nil {
cctpEvent.AmountUSD = *amountUSD
}
}
if cctpEvent.Fee != nil {
cctpEvent.FeeUSD = GetAmountUSD(cctpEvent.Fee, usdcDecimals, tokenPrice)
cctpEvent.FeeUSD = GetAmountUSD(cctpEvent.Fee, *cctpEvent.TokenDecimal, tokenPrice)
}
}

Expand Down
82 changes: 82 additions & 0 deletions services/explorer/consumer/parser/tokendata/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,38 @@ func NewTokenDataService(service fetcher.Service, tokenSymbolToIDs map[string]st

// GetTokenData attempts to get token data from the cache otherwise it is fetched from the bridge config.
func (t *tokenDataServiceImpl) GetTokenData(ctx context.Context, chainID uint32, token common.Address) (ImmutableTokenData, error) {
// Hotfix for tokens not on bridge config.
// Handle CRVUSDC
if chainID == 8453 && token.String() == "0x417Ac0e078398C154EdFadD9Ef675d30Be60Af93" {
return immutableTokenImpl{
tokenID: "crvUSD",
decimals: 18,
tokenAddress: "0x417Ac0e078398C154EdFadD9Ef675d30Be60Af93",
}, nil
}

// Handle USDbC
if chainID == 8453 && token.String() == "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA" {
return immutableTokenImpl{
tokenID: "USDbC",
decimals: 6,
tokenAddress: "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA",
}, nil
}
if chainID == 8453 && token.String() == "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb" {
return immutableTokenImpl{
tokenID: "DAI",
decimals: 18,
tokenAddress: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
}, nil
}
if chainID == 10 && token.String() == "0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9" {
return immutableTokenImpl{
tokenID: "sUSD",
decimals: 18,
tokenAddress: "0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9",
}, nil
}
key := fmt.Sprintf("token_%d_%s", chainID, token.Hex())
if data, ok := t.tokenCache.Get(key); ok {
return data, nil
Expand All @@ -74,6 +106,31 @@ func (t *tokenDataServiceImpl) GetTokenData(ctx context.Context, chainID uint32,

// GetPoolTokenData attempts to get pool token data from the cache otherwise it is fetched from the erc20 interface for that token.
func (t *tokenDataServiceImpl) GetPoolTokenData(ctx context.Context, chainID uint32, token common.Address, swapService fetcher.SwapService) (ImmutableTokenData, error) {
// Hotfix for tokens not on bridge config.
// Handle CRVUSDC
if chainID == 8453 && token.String() == "0x417Ac0e078398C154EdFadD9Ef675d30Be60Af93" {
return immutableTokenImpl{
tokenID: "crvUSD",
decimals: 18,
tokenAddress: "0x417Ac0e078398C154EdFadD9Ef675d30Be60Af93",
}, nil
}

// Handle USDbC
if chainID == 8453 && token.String() == "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA" {
return immutableTokenImpl{
tokenID: "USDbC",
decimals: 6,
tokenAddress: "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA",
}, nil
}
if chainID == 8453 && token.String() == "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb" {
return immutableTokenImpl{
tokenID: "DAI",
decimals: 18,
tokenAddress: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
}, nil
}
key := fmt.Sprintf("token_%d_%s", chainID, token.Hex())
if data, ok := t.tokenCache.Get(key); ok {
return data, nil
Expand All @@ -91,6 +148,31 @@ func (t *tokenDataServiceImpl) GetPoolTokenData(ctx context.Context, chainID uin

// GetCCTPTokenData attempts to get cctp token data from the cache otherwise it is fetched using the cctp ref.
func (t *tokenDataServiceImpl) GetCCTPTokenData(ctx context.Context, chainID uint32, token common.Address, cctpService fetcher.CCTPService) (ImmutableTokenData, error) {
// Hotfix for tokens not on bridge config.
// Handle CRVUSDC
if chainID == 8453 && token.String() == "0x417Ac0e078398C154EdFadD9Ef675d30Be60Af93" {
return immutableTokenImpl{
tokenID: "crvUSD",
decimals: 18,
tokenAddress: "0x417Ac0e078398C154EdFadD9Ef675d30Be60Af93",
}, nil
}

// Handle USDbC
if chainID == 8453 && token.String() == "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA" {
return immutableTokenImpl{
tokenID: "USDbC",
decimals: 6,
tokenAddress: "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA",
}, nil
}
if chainID == 8453 && token.String() == "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb" {
return immutableTokenImpl{
tokenID: "DAI",
decimals: 18,
tokenAddress: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
}, nil
}
key := fmt.Sprintf("token_%d_%s", chainID, token.Hex())
if data, ok := t.tokenCache.Get(key); ok {
return data, nil
Expand Down
2 changes: 2 additions & 0 deletions services/explorer/static/tokenIDToCoinGeckoID.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ PLS: 'plutusdao'
NOTE: 'note'
PEPE: 'pepe'
UNIDX: 'unidex'
USDbC: 'usd-coin'
crvUSD: 'usd-coin'
2 changes: 2 additions & 0 deletions services/explorer/static/tokenSymbolToCoinGeckoID.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,5 @@ nusd: 'usd-coin'
m.usdc: 'usd-coin'
pepe: 'pepe'
unidx: 'unidex'
usdbc: 'usd-coin'
crvusd: 'usd-coin'
2 changes: 2 additions & 0 deletions services/explorer/static/tokenSymbolToTokenID.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ dai.e: 'DAI'
note: 'NOTE'
pepe: 'PEPE'
unidx: 'UNIDX'
usdbc: 'usd-coin'
crvusd: 'usd-coin'

0 comments on commit ef79e78

Please sign in to comment.