From 160f80018fe425306a90e5223d91051c5ab93a8d Mon Sep 17 00:00:00 2001 From: walker-16 Date: Thu, 10 Aug 2023 15:51:12 -0300 Subject: [PATCH] Use rpc standard for avalanche (#622) --- contract-watcher/cmd/service/run.go | 110 ++++++++++-------- contract-watcher/config/config.go | 46 ++++---- .../contract-watcher-service.yaml | 7 ++ .../env/production-mainnet.env | 2 + .../env/production-testnet.env | 2 + .../contract-watcher/env/staging-mainnet.env | 2 + .../contract-watcher/env/staging-testnet.env | 2 + deploy/contract-watcher/secrets.yaml | 1 + 8 files changed, 100 insertions(+), 72 deletions(-) diff --git a/contract-watcher/cmd/service/run.go b/contract-watcher/cmd/service/run.go index df04070d..ceaba2ec 100644 --- a/contract-watcher/cmd/service/run.go +++ b/contract-watcher/cmd/service/run.go @@ -42,6 +42,7 @@ type watchersConfig struct { ankr []config.WatcherBlockchainAddresses aptos *config.WatcherBlockchain arbitrum *config.WatcherBlockchainAddresses + avalanche *config.WatcherBlockchainAddresses base *config.WatcherBlockchainAddresses ethereum *config.WatcherBlockchainAddresses celo *config.WatcherBlockchainAddresses @@ -54,17 +55,18 @@ type watchersConfig struct { } type rateLimitConfig struct { - ankr int - aptos int - arbitrum int - base int - celo int - ethereum int - moonbeam int - oasis int - optimism int - solana int - terra int + ankr int + aptos int + arbitrum int + avalanche int + base int + celo int + ethereum int + moonbeam int + oasis int + optimism int + solana int + terra int } func Run() { @@ -178,6 +180,12 @@ func newWatchers(config *config.ServiceConfiguration, repo *storage.Repository, result = append(result, solanaWatcher) } + // add avalanche watcher + if watchers.avalanche != nil { + avalancheWatcher := builder.CreateEvmWatcher(watchers.rateLimit.avalanche, config.AvalancheUrl, *watchers.avalanche, logger, repo, metrics) + result = append(result, avalancheWatcher) + } + // add terra watcher if watchers.terra != nil { terraWatcher := builder.CreateTerraWatcher(watchers.rateLimit.terra, config.TerraUrl, *watchers.terra, logger, repo, metrics) @@ -235,28 +243,29 @@ func newWatchersForMainnet(cfg *config.ServiceConfiguration) *watchersConfig { config.POLYGON_MAINNET, config.BSC_MAINNET, config.FANTOM_MAINNET, - config.AVALANCHE_MAINNET, }, - aptos: &config.APTOS_MAINNET, - base: &config.BASE_MAINNET, - celo: &config.CELO_MAINNET, - ethereum: &config.ETHEREUM_MAINNET, - moonbeam: &config.MOONBEAM_MAINNET, - oasis: &config.OASIS_MAINNET, - solana: &config.SOLANA_MAINNET, - terra: &config.TERRA_MAINNET, + avalanche: &config.AVALANCHE_MAINNET, + aptos: &config.APTOS_MAINNET, + base: &config.BASE_MAINNET, + celo: &config.CELO_MAINNET, + ethereum: &config.ETHEREUM_MAINNET, + moonbeam: &config.MOONBEAM_MAINNET, + oasis: &config.OASIS_MAINNET, + solana: &config.SOLANA_MAINNET, + terra: &config.TERRA_MAINNET, rateLimit: rateLimitConfig{ - ankr: cfg.AnkrRequestsPerSecond, - aptos: cfg.AptosRequestsPerSecond, - arbitrum: cfg.ArbitrumRequestsPerSecond, - base: cfg.BaseRequestsPerSecond, - celo: cfg.CeloRequestsPerSecond, - ethereum: cfg.EthereumRequestsPerSecond, - moonbeam: cfg.MoonbeamRequestsPerSecond, - oasis: cfg.OasisRequestsPerSecond, - optimism: cfg.OptimismRequestsPerSecond, - solana: cfg.SolanaRequestsPerSecond, - terra: cfg.TerraRequestsPerSecond, + ankr: cfg.AnkrRequestsPerSecond, + avalanche: cfg.AvalancheRequestsPerSecond, + aptos: cfg.AptosRequestsPerSecond, + arbitrum: cfg.ArbitrumRequestsPerSecond, + base: cfg.BaseRequestsPerSecond, + celo: cfg.CeloRequestsPerSecond, + ethereum: cfg.EthereumRequestsPerSecond, + moonbeam: cfg.MoonbeamRequestsPerSecond, + oasis: cfg.OasisRequestsPerSecond, + optimism: cfg.OptimismRequestsPerSecond, + solana: cfg.SolanaRequestsPerSecond, + terra: cfg.TerraRequestsPerSecond, }, } } @@ -267,27 +276,28 @@ func newWatchersForTestnet(cfg *config.ServiceConfiguration) *watchersConfig { config.POLYGON_TESTNET, config.BSC_TESTNET, config.FANTOM_TESTNET, - config.AVALANCHE_TESTNET, }, - aptos: &config.APTOS_TESTNET, - celo: &config.CELO_TESTNET, - base: &config.BASE_TESTNET, - ethereum: &config.ETHEREUM_TESTNET, - moonbeam: &config.MOONBEAM_TESTNET, - oasis: &config.OASIS_TESTNET, - solana: &config.SOLANA_TESTNET, + avalanche: &config.AVALANCHE_TESTNET, + aptos: &config.APTOS_TESTNET, + celo: &config.CELO_TESTNET, + base: &config.BASE_TESTNET, + ethereum: &config.ETHEREUM_TESTNET, + moonbeam: &config.MOONBEAM_TESTNET, + oasis: &config.OASIS_TESTNET, + solana: &config.SOLANA_TESTNET, rateLimit: rateLimitConfig{ - ankr: cfg.AnkrRequestsPerSecond, - aptos: cfg.AptosRequestsPerSecond, - arbitrum: cfg.ArbitrumRequestsPerSecond, - base: cfg.BaseRequestsPerSecond, - celo: cfg.CeloRequestsPerSecond, - ethereum: cfg.EthereumRequestsPerSecond, - moonbeam: cfg.MoonbeamRequestsPerSecond, - oasis: cfg.OasisRequestsPerSecond, - optimism: cfg.OptimismRequestsPerSecond, - solana: cfg.SolanaRequestsPerSecond, - terra: cfg.TerraRequestsPerSecond, + ankr: cfg.AnkrRequestsPerSecond, + avalanche: cfg.AvalancheRequestsPerSecond, + aptos: cfg.AptosRequestsPerSecond, + arbitrum: cfg.ArbitrumRequestsPerSecond, + base: cfg.BaseRequestsPerSecond, + celo: cfg.CeloRequestsPerSecond, + ethereum: cfg.EthereumRequestsPerSecond, + moonbeam: cfg.MoonbeamRequestsPerSecond, + oasis: cfg.OasisRequestsPerSecond, + optimism: cfg.OptimismRequestsPerSecond, + solana: cfg.SolanaRequestsPerSecond, + terra: cfg.TerraRequestsPerSecond, }, } } diff --git a/contract-watcher/config/config.go b/contract-watcher/config/config.go index 8af90ac7..d48f253c 100644 --- a/contract-watcher/config/config.go +++ b/contract-watcher/config/config.go @@ -19,28 +19,30 @@ type ServiceConfiguration struct { AlertEnabled bool `env:"ALERT_ENABLED,required"` AlertApiKey string `env:"ALERT_API_KEY"` - AnkrUrl string `env:"ANKR_URL,required"` - AnkrRequestsPerSecond int `env:"ANKR_REQUESTS_PER_SECOND,required"` - AptosUrl string `env:"APTOS_URL,required"` - AptosRequestsPerSecond int `env:"APTOS_REQUESTS_PER_SECOND,required"` - ArbitrumUrl string `env:"ARBITRUM_URL,required"` - ArbitrumRequestsPerSecond int `env:"ARBITRUM_REQUESTS_PER_SECOND,required"` - BaseUrl string `env:"ARBITRUM_URL,required"` - BaseRequestsPerSecond int `env:"ARBITRUM_REQUESTS_PER_SECOND,required"` - CeloUrl string `env:"CELO_URL,required"` - CeloRequestsPerSecond int `env:"CELO_REQUESTS_PER_SECOND,required"` - EthereumUrl string `env:"ETHEREUM_URL,required"` - EthereumRequestsPerSecond int `env:"ETHEREUM_REQUESTS_PER_SECOND,required"` - MoonbeamUrl string `env:"MOONBEAM_URL,required"` - MoonbeamRequestsPerSecond int `env:"MOONBEAM_REQUESTS_PER_SECOND,required"` - OptimismUrl string `env:"OPTIMISM_URL,required"` - OptimismRequestsPerSecond int `env:"OPTIMISM_REQUESTS_PER_SECOND,required"` - OasisUrl string `env:"OASIS_URL,required"` - OasisRequestsPerSecond int `env:"OASIS_REQUESTS_PER_SECOND,required"` - SolanaUrl string `env:"SOLANA_URL,required"` - SolanaRequestsPerSecond int `env:"SOLANA_REQUESTS_PER_SECOND,required"` - TerraUrl string `env:"TERRA_URL,required"` - TerraRequestsPerSecond int `env:"TERRA_REQUESTS_PER_SECOND,required"` + AnkrUrl string `env:"ANKR_URL,required"` + AnkrRequestsPerSecond int `env:"ANKR_REQUESTS_PER_SECOND,required"` + AptosUrl string `env:"APTOS_URL,required"` + AptosRequestsPerSecond int `env:"APTOS_REQUESTS_PER_SECOND,required"` + ArbitrumUrl string `env:"ARBITRUM_URL,required"` + ArbitrumRequestsPerSecond int `env:"ARBITRUM_REQUESTS_PER_SECOND,required"` + AvalancheUrl string `env:"AVALANCHE_URL,required"` + AvalancheRequestsPerSecond int `env:"AVALANCHE_REQUESTS_PER_SECOND,required"` + BaseUrl string `env:"ARBITRUM_URL,required"` + BaseRequestsPerSecond int `env:"ARBITRUM_REQUESTS_PER_SECOND,required"` + CeloUrl string `env:"CELO_URL,required"` + CeloRequestsPerSecond int `env:"CELO_REQUESTS_PER_SECOND,required"` + EthereumUrl string `env:"ETHEREUM_URL,required"` + EthereumRequestsPerSecond int `env:"ETHEREUM_REQUESTS_PER_SECOND,required"` + MoonbeamUrl string `env:"MOONBEAM_URL,required"` + MoonbeamRequestsPerSecond int `env:"MOONBEAM_REQUESTS_PER_SECOND,required"` + OptimismUrl string `env:"OPTIMISM_URL,required"` + OptimismRequestsPerSecond int `env:"OPTIMISM_REQUESTS_PER_SECOND,required"` + OasisUrl string `env:"OASIS_URL,required"` + OasisRequestsPerSecond int `env:"OASIS_REQUESTS_PER_SECOND,required"` + SolanaUrl string `env:"SOLANA_URL,required"` + SolanaRequestsPerSecond int `env:"SOLANA_REQUESTS_PER_SECOND,required"` + TerraUrl string `env:"TERRA_URL,required"` + TerraRequestsPerSecond int `env:"TERRA_REQUESTS_PER_SECOND,required"` } // BackfillerConfiguration represents the application configuration when running as backfiller. diff --git a/deploy/contract-watcher/contract-watcher-service.yaml b/deploy/contract-watcher/contract-watcher-service.yaml index 04a81972..f8bb6553 100644 --- a/deploy/contract-watcher/contract-watcher-service.yaml +++ b/deploy/contract-watcher/contract-watcher-service.yaml @@ -137,6 +137,13 @@ spec: key: ethereum-url - name: ETHEREUM_REQUESTS_PER_SECOND value: "{{ .ETHEREUM_REQUESTS_PER_SECOND }}" + - name: AVALANCHE_URL + valueFrom: + secretKeyRef: + name: blockchain + key: avalanche-url + - name: AVALANCHE_REQUESTS_PER_SECOND + value: "{{ .AVALANCHE_REQUESTS_PER_SECOND }}" - name: ALERT_API_KEY valueFrom: secretKeyRef: diff --git a/deploy/contract-watcher/env/production-mainnet.env b/deploy/contract-watcher/env/production-mainnet.env index ef5af5ee..b16265c2 100644 --- a/deploy/contract-watcher/env/production-mainnet.env +++ b/deploy/contract-watcher/env/production-mainnet.env @@ -15,6 +15,8 @@ APTOS_URL= APTOS_REQUESTS_PER_SECOND=20 ARBITRUM_URL= ARBITRUM_REQUESTS_PER_SECOND=3 +AVALANCHE_URL= +AVALANCHE_REQUESTS_PER_SECOND=5 BASE_URL= BASE_REQUESTS_PER_SECOND=3 CELO_URL= diff --git a/deploy/contract-watcher/env/production-testnet.env b/deploy/contract-watcher/env/production-testnet.env index 465d372d..71a236f4 100644 --- a/deploy/contract-watcher/env/production-testnet.env +++ b/deploy/contract-watcher/env/production-testnet.env @@ -15,6 +15,8 @@ APTOS_URL= APTOS_REQUESTS_PER_SECOND=1 ARBITRUM_URL= ARBITRUM_REQUESTS_PER_SECOND=1 +AVALANCHE_URL= +AVALANCHE_REQUESTS_PER_SECOND=5 BASE_URL= BASE_REQUESTS_PER_SECOND=1 CELO_URL= diff --git a/deploy/contract-watcher/env/staging-mainnet.env b/deploy/contract-watcher/env/staging-mainnet.env index 37c5378d..2576a197 100644 --- a/deploy/contract-watcher/env/staging-mainnet.env +++ b/deploy/contract-watcher/env/staging-mainnet.env @@ -15,6 +15,8 @@ APTOS_URL= APTOS_REQUESTS_PER_SECOND=20 ARBITRUM_URL= ARBITRUM_REQUESTS_PER_SECOND=3 +AVALANCHE_URL= +AVALANCHE_REQUESTS_PER_SECOND=5 BASE_URL= BASE_REQUESTS_PER_SECOND=3 CELO_URL= diff --git a/deploy/contract-watcher/env/staging-testnet.env b/deploy/contract-watcher/env/staging-testnet.env index 6130f751..a7777d04 100644 --- a/deploy/contract-watcher/env/staging-testnet.env +++ b/deploy/contract-watcher/env/staging-testnet.env @@ -15,6 +15,8 @@ APTOS_URL= APTOS_REQUESTS_PER_SECOND=1 ARBITRUM_URL= ARBITRUM_REQUESTS_PER_SECOND=1 +AVALANCHE_URL= +AVALANCHE_REQUESTS_PER_SECOND=5 BASE_URL= BASE_REQUESTS_PER_SECOND=1 CELO_URL= diff --git a/deploy/contract-watcher/secrets.yaml b/deploy/contract-watcher/secrets.yaml index ee96b1f7..4ec9072d 100644 --- a/deploy/contract-watcher/secrets.yaml +++ b/deploy/contract-watcher/secrets.yaml @@ -15,4 +15,5 @@ data: arbitrum-url: {{ .ARBITRUM_URL | b64enc }} optimism-url: {{ .OPTIMISM_URL | b64enc }} ethereum-url: {{ .ETHEREUM_URL | b64enc }} + avalanche-url: {{ .AVALANCHE_URL | b64enc }} type: Opaque