Skip to content

feat: stork integration#22

Merged
Kefancao merged 16 commits intomainfrom
feat/stork
Mar 24, 2026
Merged

feat: stork integration#22
Kefancao merged 16 commits intomainfrom
feat/stork

Conversation

@pp346
Copy link
Copy Markdown

@pp346 pp346 commented Feb 18, 2026

Summary

  • Introduces a Stork PriceAPIDataHandler that queries /v1/prices/latest with comma-separated asset IDs.

Details

  • Parses Stork’s integer price strings into floats and returns current UTC timestamps.
  • Registers the provider in APIQueryHandlerFactory.
  • API
    • Request: GET https://rest.jp.stork-oracle.network/v1/prices/latest?assets=<ID1,ID2,...>
    • Response: JSON map of asset_id -> price (string), scaled by 10^18.
    • Parsing: Converts price string to big.Float and divides by 1e18; unknown assets are ignored.
    • Timestamps: Uses time.Now().UTC() (provider timestamp not propagated).
  • Config
    • New provider name: stork_api.
    • DefaultAPIConfig: Enabled, Atomic=true, Timeout/Interval=3s, ReconnectTimeout=2s, MaxQueries=1.
    • Authentication: Authorization header populated from env var STORK_API_KEY.
  • Implementation
    • Caches requested tickers during CreateURL to map returned asset IDs back to ProviderTicker.
    • Error handling:
      • JSON decode failure → unresolved for all tickers (ErrorFailedToDecode).
      • Price parse failure → unresolved for that ticker (ErrorFailedToParsePrice).
      • Missing response for a requested ticker → unresolved (ErrorNoResponse).
  • Factory
    • Adds stork_api branch to instantiate the new API data handler.

Risk & Impact

  • Low risk: additive provider; no changes to existing providers or schemas.
  • Operational: requires configuring STORK_API_KEY when enabling this provider.
  • Security: introduces API key usage via Authorization header.

Testing

  • New unit tests:
    • URL creation: empty, single, multiple assets.
    • Response parsing: valid single/multiple, bad JSON, bad/empty price, missing/null data, no responses.
    • Numeric edges: hex literal, very small (1), very large, zero.
    • Verifies timestamps are set to “now” and unresolved errors are surfaced.

@pp346 pp346 requested a review from a team as a code owner February 18, 2026 22:08
tqin7
tqin7 previously approved these changes Feb 19, 2026
Comment thread providers/apis/stork/utils.go Outdated
Comment thread providers/apis/stork/api_handler.go Outdated
Comment thread providers/apis/stork/api_handler_test.go
tqin7
tqin7 previously approved these changes Feb 23, 2026
@Kefancao Kefancao requested a review from a team as a code owner March 21, 2026 01:09
Comment thread providers/apis/stork/utils.go
Comment thread providers/apis/stork/utils.go
Comment thread providers/apis/stork/utils.go
Comment thread providers/apis/stork/api_handler.go
Comment thread providers/apis/stork/api_handler.go
@Kefancao Kefancao merged commit 9d2c096 into main Mar 24, 2026
15 of 16 checks passed

// NewAPIHandler returns a new Stork PriceAPIDataHandler.
func NewAPIHandler(
api config.APIConfig,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit: this is config, not an api instance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants