Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[goreleaser] Updated explorer indexer for migration #1685

Merged
merged 1 commit into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Comment on lines 127 to 132
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The removal of the RPCURL check in the IsValid method of the ChainConfig type implies that RPCURL is no longer required for a chain configuration to be considered valid. Ensure that this change is intentional and that all dependent services can handle a missing RPCURL without issues.

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 @@
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
}

Check warning on line 120 in services/explorer/consumer/parser/cctpparser.go

View check run for this annotation

Codecov / codecov/patch

services/explorer/consumer/parser/cctpparser.go#L117-L120

Added lines #L117 - L120 were not covered by tests
cctpEvent.TokenSymbol = tokenData.TokenID()
if (cctpEvent.Token == "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1") {
decimals = 18
cctpEvent.TokenSymbol = "DAI"
}
if chainID == 10 && (cctpEvent.Token == "0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9") {
decimals = 18
cctpEvent.TokenSymbol = "sUSD"
}

Check warning on line 129 in services/explorer/consumer/parser/cctpparser.go

View check run for this annotation

Codecov / codecov/patch

services/explorer/consumer/parser/cctpparser.go#L122-L129

Added lines #L122 - L129 were not covered by tests
Comment on lines +117 to +129
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MatureLogs function contains hardcoded values for decimals and cctpEvent.TokenSymbol based on the chainID and cctpEvent.Token. This approach is not scalable or maintainable. Consider retrieving these values from a configuration file or a service that can be updated without code changes.

cctpEvent.TokenDecimal = &decimals
c.applyPriceData(ctx, cctpEvent, usdcCoinGeckoID)

Expand Down Expand Up @@ -156,13 +168,13 @@
}

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

Check warning on line 171 in services/explorer/consumer/parser/cctpparser.go

View check run for this annotation

Codecov / codecov/patch

services/explorer/consumer/parser/cctpparser.go#L171

Added line #L171 was not covered by tests
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)

Check warning on line 177 in services/explorer/consumer/parser/cctpparser.go

View check run for this annotation

Codecov / codecov/patch

services/explorer/consumer/parser/cctpparser.go#L177

Added line #L177 was not covered by tests
Comment on lines +171 to +177
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the applyPriceData function, there is a potential nil pointer dereference when accessing *cctpEvent.TokenDecimal. Ensure that cctpEvent.TokenDecimal is not nil before dereferencing to prevent runtime panics.

}
}

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 @@

// 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
}

Check warning on line 68 in services/explorer/consumer/parser/tokendata/cache.go

View check run for this annotation

Codecov / codecov/patch

services/explorer/consumer/parser/tokendata/cache.go#L63-L68

Added lines #L63 - L68 were not covered by tests

// Handle USDbC
if chainID == 8453 && token.String() == "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA" {
return immutableTokenImpl{
tokenID: "USDbC",
decimals: 6,
tokenAddress: "0xd9aAEc86B65D86f6A7B5B1b0c42FFA531710b6CA",
}, nil
}

Check warning on line 77 in services/explorer/consumer/parser/tokendata/cache.go

View check run for this annotation

Codecov / codecov/patch

services/explorer/consumer/parser/tokendata/cache.go#L72-L77

Added lines #L72 - L77 were not covered by tests
if chainID == 8453 && token.String() == "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb" {
return immutableTokenImpl{
tokenID: "DAI",
decimals: 18,
tokenAddress: "0x50c5725949A6F0c72E6C4a641F24049A917DB0Cb",
}, nil
}

Check warning on line 84 in services/explorer/consumer/parser/tokendata/cache.go

View check run for this annotation

Codecov / codecov/patch

services/explorer/consumer/parser/tokendata/cache.go#L79-L84

Added lines #L79 - L84 were not covered by tests
if chainID == 10 && token.String() == "0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9" {
return immutableTokenImpl{
tokenID: "sUSD",
decimals: 18,
tokenAddress: "0x8c6f28f2F1A3C87F0f938b96d27520d9751ec8d9",
}, nil
}

Check warning on line 91 in services/explorer/consumer/parser/tokendata/cache.go

View check run for this annotation

Codecov / codecov/patch

services/explorer/consumer/parser/tokendata/cache.go#L86-L91

Added lines #L86 - L91 were not covered by tests
Comment on lines +60 to +91
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The GetTokenData, GetPoolTokenData, and GetCCTPTokenData functions contain hardcoded token data for specific tokens and chain IDs. This approach is not scalable or maintainable. Consider retrieving these values from a configuration file or a service that can be updated without code changes.

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 @@

// 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
}

Check warning on line 117 in services/explorer/consumer/parser/tokendata/cache.go

View check run for this annotation

Codecov / codecov/patch

services/explorer/consumer/parser/tokendata/cache.go#L109-L117

Added lines #L109 - L117 were not covered by tests

// 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
}

Check warning on line 133 in services/explorer/consumer/parser/tokendata/cache.go

View check run for this annotation

Codecov / codecov/patch

services/explorer/consumer/parser/tokendata/cache.go#L120-L133

Added lines #L120 - L133 were not covered by tests
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 @@

// 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
}

Check warning on line 159 in services/explorer/consumer/parser/tokendata/cache.go

View check run for this annotation

Codecov / codecov/patch

services/explorer/consumer/parser/tokendata/cache.go#L151-L159

Added lines #L151 - L159 were not covered by tests

// 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
}

Check warning on line 175 in services/explorer/consumer/parser/tokendata/cache.go

View check run for this annotation

Codecov / codecov/patch

services/explorer/consumer/parser/tokendata/cache.go#L162-L175

Added lines #L162 - L175 were not covered by tests
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'
Loading