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

tx-tracker: add support for the "Base" blockchain #568

Merged
merged 4 commits into from
Jul 20, 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
39 changes: 20 additions & 19 deletions common/domain/chainid.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ func TranslateEmitterAddress(chainID sdk.ChainID, address string) (string, error
// EVM chains use the classic hex, 0x-prefixed encoding.
// Also, Karura and Acala support EVM-compatible addresses, so they're handled here as well.
case sdk.ChainIDEthereum,
sdk.ChainIDBase,
sdk.ChainIDBSC,
sdk.ChainIDPolygon,
sdk.ChainIDAvalanche,
Expand All @@ -71,23 +72,23 @@ func TranslateEmitterAddress(chainID sdk.ChainID, address string) (string, error

// Terra addresses use bench32 encoding
case sdk.ChainIDTerra:
return encodeBench32("terra", addressBytes[12:])
return encodeBech32("terra", addressBytes[12:])

// Terra2 addresses use bench32 encoding
case sdk.ChainIDTerra2:
return encodeBench32("terra", addressBytes)
return encodeBech32("terra", addressBytes)

// Injective addresses use bench32 encoding
case sdk.ChainIDInjective:
return encodeBench32("inj", addressBytes[12:])
return encodeBech32("inj", addressBytes[12:])

// Xpla addresses use bench32 encoding
case sdk.ChainIDXpla:
return encodeBench32("xpla", addressBytes)
return encodeBech32("xpla", addressBytes)

// Sei addresses use bench32 encoding
case sdk.ChainIDSei:
return encodeBench32("sei", addressBytes)
return encodeBech32("sei", addressBytes)

// Algorand addresses use base32 encoding with a trailing checksum.
// We're using the SDK to handle the checksum logic.
Expand Down Expand Up @@ -137,17 +138,6 @@ func TranslateEmitterAddress(chainID sdk.ChainID, address string) (string, error
}
}

// encodeBench32 is a helper function to encode bench32 addresses.
func encodeBench32(hrp string, data []byte) (string, error) {

aligned, err := bech32.ConvertBits(data, 8, 5, true)
if err != nil {
return "", fmt.Errorf("bech32 encoding failed: %w", err)
}

return bech32.Encode(hrp, aligned)
}

// GetSupportedChainIDs returns a map of all supported chain IDs to their respective names.
func GetSupportedChainIDs() map[sdk.ChainID]string {
chainIDs := sdk.GetAllNetworkIDs()
Expand Down Expand Up @@ -213,7 +203,6 @@ func EncodeTrxHashByChainID(chainID sdk.ChainID, txHash []byte) (string, error)
//TODO: check if this is correct
return hex.EncodeToString(txHash), nil
case sdk.ChainIDBase:
//TODO: check if this is correct
return hex.EncodeToString(txHash), nil
case sdk.ChainIDSei:
return hex.EncodeToString(txHash), nil
Expand Down Expand Up @@ -244,6 +233,7 @@ func DecodeNativeAddressToHex(chainID sdk.ChainID, address string) (string, erro
// EVM chains use the classic hex, 0x-prefixed encoding.
// Also, Karura and Acala support EVM-compatible addresses, so they're handled here as well.
case sdk.ChainIDEthereum,
sdk.ChainIDBase,
sdk.ChainIDBSC,
sdk.ChainIDPolygon,
sdk.ChainIDAvalanche,
Expand Down Expand Up @@ -302,16 +292,27 @@ func DecodeNativeAddressToHex(chainID sdk.ChainID, address string) (string, erro
}
}

// decodeBech32 is a helper function to decode bech32 addresses.
// decodeBech32 is a helper function to decode a bech32 addresses.
func decodeBech32(h, address string) (string, error) {

hrp, decoded, err := bech32.Decode(address, bech32.MaxLengthBIP173)
if err != nil {
return "", fmt.Errorf("bech32 decoding failed: %w", err)
}
if hrp != h {
return "", fmt.Errorf("bech32 decoding failed: invalid prefix: %s", hrp)
return "", fmt.Errorf("bech32 decoding failed, invalid prefix: %s", hrp)
}

return hex.EncodeToString(decoded), nil
}

// encodeBech32 is a helper function to encode a bech32 addresses.
func encodeBech32(hrp string, data []byte) (string, error) {

aligned, err := bech32.ConvertBits(data, 8, 5, true)
if err != nil {
return "", fmt.Errorf("bech32 encoding failed: %w", err)
}

return bech32.Encode(hrp, aligned)
}
3 changes: 3 additions & 0 deletions deploy/tx-tracker-backfiller/env/production.env
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ ARBITRUM_REQUESTS_PER_MINUTE=1
AVALANCHE_BASE_URL=https://api.avax.network/ext/bc/C/rpc
AVALANCHE_REQUESTS_PER_MINUTE=2

BASE_BASE_URL=https://base-mainnet.public.blastapi.io
BASE_REQUESTS_PER_MINUTE=1

BSC_BASE_URL=https://bsc-dataseed2.defibit.io
BSC_REQUESTS_PER_MINUTE=2

Expand Down
3 changes: 3 additions & 0 deletions deploy/tx-tracker-backfiller/env/staging.env
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ ARBITRUM_REQUESTS_PER_MINUTE=1
AVALANCHE_BASE_URL=https://api.avax.network/ext/bc/C/rpc
AVALANCHE_REQUESTS_PER_MINUTE=1

BASE_BASE_URL=https://base-mainnet.public.blastapi.io
BASE_REQUESTS_PER_MINUTE=1

BSC_BASE_URL=https://bsc-dataseed2.defibit.io
BSC_REQUESTS_PER_MINUTE=1

Expand Down
3 changes: 3 additions & 0 deletions deploy/tx-tracker-backfiller/env/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ ARBITRUM_REQUESTS_PER_MINUTE=2
AVALANCHE_BASE_URL=https://rpc.ankr.com/avalanche_fuji
AVALANCHE_REQUESTS_PER_MINUTE=2

BASE_BASE_URL=https://base-goerli.public.blastapi.io
BASE_REQUESTS_PER_MINUTE=1

BSC_BASE_URL=https://data-seed-prebsc-1-s1.binance.org:8545
BSC_REQUESTS_PER_MINUTE=2

Expand Down
3 changes: 3 additions & 0 deletions deploy/tx-tracker/env/production.env
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ ARBITRUM_REQUESTS_PER_MINUTE=12
AVALANCHE_BASE_URL=https://api.avax.network/ext/bc/C/rpc
AVALANCHE_REQUESTS_PER_MINUTE=12

BASE_BASE_URL=https://base-mainnet.public.blastapi.io
BASE_REQUESTS_PER_MINUTE=12

BSC_BASE_URL=https://bsc-dataseed2.defibit.io
BSC_REQUESTS_PER_MINUTE=12

Expand Down
3 changes: 3 additions & 0 deletions deploy/tx-tracker/env/staging.env
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ ARBITRUM_REQUESTS_PER_MINUTE=12
AVALANCHE_BASE_URL=https://api.avax.network/ext/bc/C/rpc
AVALANCHE_REQUESTS_PER_MINUTE=12

BASE_BASE_URL=https://base-mainnet.public.blastapi.io
BASE_REQUESTS_PER_MINUTE=12

BSC_BASE_URL=https://bsc-dataseed2.defibit.io
BSC_REQUESTS_PER_MINUTE=12

Expand Down
3 changes: 3 additions & 0 deletions deploy/tx-tracker/env/test.env
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ ARBITRUM_REQUESTS_PER_MINUTE=12
AVALANCHE_BASE_URL=https://rpc.ankr.com/avalanche_fuji
AVALANCHE_REQUESTS_PER_MINUTE=12

BASE_BASE_URL=https://base-goerli.public.blastapi.io
BASE_REQUESTS_PER_MINUTE=12

BSC_BASE_URL=https://data-seed-prebsc-1-s1.binance.org:8545
BSC_REQUESTS_PER_MINUTE=12

Expand Down
3 changes: 3 additions & 0 deletions tx-tracker/chains/chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func Initialize(cfg *config.RpcProviderSettings) {
rateLimitersByChain[sdk.ChainIDAlgorand] = convertToRateLimiter(cfg.AlgorandRequestsPerMinute)
rateLimitersByChain[sdk.ChainIDAptos] = convertToRateLimiter(cfg.AptosRequestsPerMinute)
rateLimitersByChain[sdk.ChainIDAvalanche] = convertToRateLimiter(cfg.AvalancheRequestsPerMinute)
rateLimitersByChain[sdk.ChainIDBase] = convertToRateLimiter(cfg.BaseRequestsPerMinute)
rateLimitersByChain[sdk.ChainIDBSC] = convertToRateLimiter(cfg.BscRequestsPerMinute)
rateLimitersByChain[sdk.ChainIDCelo] = convertToRateLimiter(cfg.CeloRequestsPerMinute)
rateLimitersByChain[sdk.ChainIDEthereum] = convertToRateLimiter(cfg.EthereumRequestsPerMinute)
Expand All @@ -74,6 +75,7 @@ func Initialize(cfg *config.RpcProviderSettings) {
baseUrlsByChain[sdk.ChainIDAlgorand] = cfg.AlgorandBaseUrl
baseUrlsByChain[sdk.ChainIDAptos] = cfg.AptosBaseUrl
baseUrlsByChain[sdk.ChainIDAvalanche] = cfg.AvalancheBaseUrl
baseUrlsByChain[sdk.ChainIDBase] = cfg.BaseBaseUrl
baseUrlsByChain[sdk.ChainIDBSC] = cfg.BscBaseUrl
baseUrlsByChain[sdk.ChainIDCelo] = cfg.CeloBaseUrl
baseUrlsByChain[sdk.ChainIDEthereum] = cfg.EthereumBaseUrl
Expand Down Expand Up @@ -118,6 +120,7 @@ func FetchTx(
case sdk.ChainIDAcala,
sdk.ChainIDArbitrum,
sdk.ChainIDAvalanche,
sdk.ChainIDBase,
sdk.ChainIDBSC,
sdk.ChainIDCelo,
sdk.ChainIDEthereum,
Expand Down
2 changes: 2 additions & 0 deletions tx-tracker/config/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ type RpcProviderSettings struct {
ArbitrumRequestsPerMinute uint16 `split_words:"true" required:"true"`
AvalancheBaseUrl string `split_words:"true" required:"true"`
AvalancheRequestsPerMinute uint16 `split_words:"true" required:"true"`
BaseBaseUrl string `split_words:"true" required:"true"`
BaseRequestsPerMinute uint16 `split_words:"true" required:"true"`
BscBaseUrl string `split_words:"true" required:"true"`
BscRequestsPerMinute uint16 `split_words:"true" required:"true"`
CeloBaseUrl string `split_words:"true" required:"true"`
Expand Down
Loading