From e55f6e35e3127b0669780c5d89844e10249cb36d Mon Sep 17 00:00:00 2001 From: ftocal <46001274+ftocal@users.noreply.github.com> Date: Wed, 27 Mar 2024 10:58:50 -0300 Subject: [PATCH 1/2] Fix operations query by txHash when the vaa was processed correctly (#1255) Co-authored-by: walker-16 --- api/handlers/operations/repository.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/handlers/operations/repository.go b/api/handlers/operations/repository.go index 63a6fe25..92355fa6 100644 --- a/api/handlers/operations/repository.go +++ b/api/handlers/operations/repository.go @@ -172,6 +172,8 @@ func (r *Repository) matchOperationByTxHash(ctx context.Context, txHash string) return bson.D{{Key: "$match", Value: bson.D{{Key: "$or", Value: bson.A{ bson.D{{Key: "originTx.nativeTxHash", Value: bson.M{"$eq": txHashHex}}}, bson.D{{Key: "originTx.nativeTxHash", Value: bson.M{"$eq": txHash}}}, + bson.D{{Key: "originTx.nativeTxHash", Value: bson.M{"$eq": qLower}}}, + bson.D{{Key: "originTx.nativeTxHash", Value: bson.M{"$eq": qHigher}}}, bson.D{{Key: "originTx.attribute.value.originTxHash", Value: bson.M{"$eq": txHashHex}}}, bson.D{{Key: "originTx.attribute.value.originTxHash", Value: bson.M{"$eq": txHash}}}, bson.D{{Key: "originTx.attribute.value.originTxHash", Value: bson.M{"$eq": qLower}}}, From 36e6c0a715a626bcb25c94c05840781aaac6e82e Mon Sep 17 00:00:00 2001 From: ftocal <46001274+ftocal@users.noreply.github.com> Date: Wed, 27 Mar 2024 14:42:04 -0300 Subject: [PATCH 2/2] Add api key for coingecko api in notional jobs (#1259) Co-authored-by: walker-16 --- deploy/jobs/configmap.yaml | 4 +++- deploy/jobs/notional.yaml | 15 ++++++++++++++- jobs/cmd/main.go | 4 ++-- jobs/config/config.go | 18 ++++++++++-------- jobs/internal/coingecko/coingecko.go | 12 ++++++++++-- 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/deploy/jobs/configmap.yaml b/deploy/jobs/configmap.yaml index 1df31c19..e5208e40 100644 --- a/deploy/jobs/configmap.yaml +++ b/deploy/jobs/configmap.yaml @@ -6,4 +6,6 @@ metadata: namespace: {{ .NAMESPACE }} data: aws-region: {{ .AWS_REGION }} - aws-bucket: {{ .AWS_BUCKET }} \ No newline at end of file + aws-bucket: {{ .AWS_BUCKET }} + coingecko-url: {{ .COINGECKO_URL }} + coingecko-header-key: {{ .COINGECKO_HEADER_KEY }} diff --git a/deploy/jobs/notional.yaml b/deploy/jobs/notional.yaml index 0fa95e0e..ced71c21 100644 --- a/deploy/jobs/notional.yaml +++ b/deploy/jobs/notional.yaml @@ -24,7 +24,20 @@ spec: - name: JOB_ID value: JOB_NOTIONAL_USD - name: COINGECKO_URL - value: {{ .COINGECKO_URL }} + valueFrom: + configMapKeyRef: + name: jobs + key: coingecko-url + - name: COINGECKO_HEADER_KEY + valueFrom: + configMapKeyRef: + name: jobs + key: coingecko-header-key + - name: COINGECKO_API_KEY + valueFrom: + secretKeyRef: + name: jobs + key: coingecko-api-key - name: NOTIONAL_CHANNEL value: {{ .NOTIONAL_CHANNEL }} - name: CACHE_URL diff --git a/jobs/cmd/main.go b/jobs/cmd/main.go index e33923f2..ecff3d81 100644 --- a/jobs/cmd/main.go +++ b/jobs/cmd/main.go @@ -103,9 +103,9 @@ func main() { } // initNotionalJob initializes notional job. -func initNotionalJob(ctx context.Context, cfg *config.NotionalConfiguration, logger *zap.Logger) *notional.NotionalJob { +func initNotionalJob(_ context.Context, cfg *config.NotionalConfiguration, logger *zap.Logger) *notional.NotionalJob { // init coingecko api client. - api := coingecko.NewCoingeckoAPI(cfg.CoingeckoURL, logger) + api := coingecko.NewCoingeckoAPI(cfg.CoingeckoURL, cfg.CoingeckoHeaderKey, cfg.CoingeckoApiKey, logger) // init redis client. redisClient := redis.NewClient(&redis.Options{Addr: cfg.CacheURL}) // init token provider. diff --git a/jobs/config/config.go b/jobs/config/config.go index a09fe61b..5c3ce48d 100644 --- a/jobs/config/config.go +++ b/jobs/config/config.go @@ -9,14 +9,16 @@ type Configuration struct { } type NotionalConfiguration struct { - Environment string `env:"ENVIRONMENT,required"` - CoingeckoURL string `env:"COINGECKO_URL,required"` - CacheURL string `env:"CACHE_URL,required"` - CachePrefix string `env:"CACHE_PREFIX,required"` - NotionalChannel string `env:"NOTIONAL_CHANNEL,required"` - P2pNetwork string `env:"P2P_NETWORK,required"` - AwsRegion string `env:"AWS_REGION"` - AwsBucket string `env:"AWS_BUCKET"` + Environment string `env:"ENVIRONMENT,required"` + CoingeckoURL string `env:"COINGECKO_URL,required"` + CoingeckoHeaderKey string `env:"COINGECKO_HEADER_KEY"` + CoingeckoApiKey string `env:"COINGECKO_API_KEY"` + CacheURL string `env:"CACHE_URL,required"` + CachePrefix string `env:"CACHE_PREFIX,required"` + NotionalChannel string `env:"NOTIONAL_CHANNEL,required"` + P2pNetwork string `env:"P2P_NETWORK,required"` + AwsRegion string `env:"AWS_REGION"` + AwsBucket string `env:"AWS_BUCKET"` } type TransferReportConfiguration struct { diff --git a/jobs/internal/coingecko/coingecko.go b/jobs/internal/coingecko/coingecko.go index 0ece3dbf..318e0d2d 100644 --- a/jobs/internal/coingecko/coingecko.go +++ b/jobs/internal/coingecko/coingecko.go @@ -17,14 +17,18 @@ type CoingeckoAPI struct { chunkSize int client *http.Client logger *zap.Logger + headerKey string + apiKey string } // NewCoingeckoAPI creates a new coingecko client -func NewCoingeckoAPI(url string, logger *zap.Logger) *CoingeckoAPI { +func NewCoingeckoAPI(url string, headerKey, apiKey string, logger *zap.Logger) *CoingeckoAPI { return &CoingeckoAPI{ url: url, chunkSize: 200, client: http.DefaultClient, + headerKey: headerKey, + apiKey: apiKey, logger: logger, } } @@ -45,12 +49,16 @@ func (c *CoingeckoAPI) GetNotionalUSD(ids []string) (map[string]NotionalUSD, err // iterate over chunks of ids. for i, chunk := range chunksIds { - notionalUrl := fmt.Sprintf("%s/simple/price?ids=%s&vs_currencies=usd", c.url, strings.Join(chunk, ",")) + notionalUrl := fmt.Sprintf("%s/api/v3/simple/price?ids=%s&vs_currencies=usd", c.url, strings.Join(chunk, ",")) req, err := http.NewRequest(http.MethodGet, notionalUrl, nil) if err != nil { return response, err } + if c.headerKey != "" && c.apiKey != "" { + req.Header.Add(c.headerKey, c.apiKey) + } + res, err := c.client.Do(req) if err != nil { return response, err