Skip to content
Closed
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
3 changes: 3 additions & 0 deletions go.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ flowchart LR
click capabilities/integration_tests href "https://github.com/smartcontractkit/capabilities"
capabilities/libs --> chainlink-common/x/config
click capabilities/libs href "https://github.com/smartcontractkit/capabilities"
capabilities/pricing/pricefeed --> capabilities/libs
click capabilities/pricing/pricefeed href "https://github.com/smartcontractkit/capabilities"
ccip-contract-examples/chains/evm
click ccip-contract-examples/chains/evm href "https://github.com/smartcontractkit/ccip-contract-examples"
ccip-owner-contracts
Expand Down Expand Up @@ -245,6 +247,7 @@ flowchart LR
capabilities/http_trigger
capabilities/integration_tests
capabilities/libs
capabilities/pricing/pricefeed
end
click capabilities-repo href "https://github.com/smartcontractkit/capabilities"

Expand Down
76 changes: 76 additions & 0 deletions pricing/pricefeed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Price Feed Action

A node-mode action that returns the current price of a cryptocurrency pair. The node operator configures the price
provider and holds its credentials, so a workflow needs no API URL, API key or response parsing of its own.

Capability ID: `price-feed@1.0.0-alpha`

## Use from a workflow

Each node fetches its own price. The workflow gets consensus on the result, for example with the median:

```go
func fetchPrice(config *Config, _ *slog.Logger, nodeRuntime *pricefeed.NodeRuntime) (decimal.Decimal, error) {
resp, err := (&pricefeed.Client{}).GetPrice(nodeRuntime, &pricefeed.GetPriceRequest{Ticker: config.Ticker}).Await()
...
}

price, err := pricefeed.RunInNodeMode(config, runtime, fetchPrice, cre.ConsensusMedianAggregation()).Await()
```

[`workflow/`](workflow) is a complete example. It runs against the real capability with an in-process stand-in for
`cre-sdk-go` (`workflow/fakesdk`), until the SDK is generated from the production protos.

## Input: `GetPriceRequest`

| Field | Type | Description |
|----------|--------|-------------------------------------------------------------------------------------------------|
| `ticker` | string | `BASE-QUOTE`, such as `BTC-USD`. `/` or `_` can also separate the pair. The case does not matter. |

## Output: `GetPriceResponse`

| Field | Type | Description |
|-------------|-----------------------------|-------------------------------------------------------------------------------------|
| `ticker` | string | The normalised pair, such as `BTC-USD`. |
| `price` | `values.v1.Decimal` | The price of one unit of the base currency in the quote currency. No precision loss. |
| `timestamp` | `google.protobuf.Timestamp` | When the provider observed the price. Coinbase gives none, so it is the receive time. |

## Providers

| Provider | Source | Timestamp | Credentials |
|--------------|---------------------------------------------------------------------|-------------------------------|-----------------------|
| `coinbase` | Coinbase Price API, `GET /v2/prices/{BASE-QUOTE}/spot` | When the node got the price | None |
| `dataengine` | Chainlink Data Engine REST API, `GET /api/v1/reports/latest?feedID` | Report `observationsTimestamp` | API key and secret (HMAC) |

Data Engine reports are decoded for the v2, v3 (crypto) and v4 (RWA) schemas, which have their price at the same
position, with 18 decimals. Each ticker must be mapped to a feed ID in `pricefeed.data-engine.feeds`. The report
signatures are not verified: the report comes from the authenticated API, and on-chain consumers verify it.

## Configuration

Set by flag, `CL_` environment variable or config file (`pricefeed run --help` lists them all):

| Name | Default | Description |
|---------------------------------------|------------------------------------|------------------------------------------------------------------|
| `pricefeed.provider` | `coinbase` | `coinbase` or `dataengine`. |
| `pricefeed.timeout` | `5s` | The longest a request to the provider can take. |
| `pricefeed.max-price-age` | `5m` | Prices with an older timestamp are rejected. `0` accepts any age. |
| `pricefeed.coinbase.url` | `https://api.coinbase.com` | Coinbase API base URL. |
| `pricefeed.data-engine.url` | `https://api.dataengine.chain.link` | Data Engine REST API base URL. |
| `pricefeed.data-engine.api-key` | | Data Engine API key. |
| `pricefeed.data-engine.api-secret` | | Data Engine API secret. Redacted in logs. |
| `pricefeed.data-engine.feeds.<TICKER>` | | The feed ID of a ticker, such as `BTC-USD=0x0003...`. |

## Errors

| Cause | Code | Origin |
|----------------------------------------------|--------------------|--------|
| Ticker is not `BASE-QUOTE` | `InvalidArgument` | User |
| Provider has no price for the ticker | `NotFound` | User |
| Provider timed out | `DeadlineExceeded` | System |
| Bad response: status, JSON, report, a price that is not positive, or a stale or future timestamp | `Unavailable` | System |
| Network failure (message kept private) | `Unavailable` | System |

## Not in scope

Historical prices (a non-goal of the PRD).
135 changes: 135 additions & 0 deletions pricing/pricefeed/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
module github.com/smartcontractkit/capabilities/pricing/pricefeed

go 1.27.3

require (
github.com/samber/do/v2 v2.1.0
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/capabilities/libs v0.0.0-20261112154143-07e64f263bce
github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109175429-6cfabeb021f5
github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20261102161601-beffc93e226e
github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c
github.com/stretchr/testify v1.12.1
google.golang.org/protobuf v1.36.12
)

require (
github.com/Masterminds/semver/v3 v3.4.0 // indirect
github.com/XSAM/otelsql v0.37.0 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/buger/jsonparser v1.1.2 // indirect
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudevents/sdk-go/binding/format/protobuf/v2 v2.16.1 // indirect
github.com/cloudevents/sdk-go/v2 v2.16.1 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.8 // indirect
github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874 // indirect
github.com/go-logr/logr v1.4.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.26.0 // indirect
github.com/go-viper/mapstructure/v2 v2.5.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grafana/otel-profiling-go v0.5.1 // indirect
github.com/grafana/pyroscope-go v1.2.8 // indirect
github.com/grafana/pyroscope-go/godeltaprof v0.1.9 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 // indirect
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.3.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
github.com/hashicorp/go-plugin v1.8.0 // indirect
github.com/hashicorp/yamux v0.1.2 // indirect
github.com/huandu/go-clone v1.7.3 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/jsonschema v0.13.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.9.2 // indirect
github.com/jackc/puddle/v2 v2.2.2 // indirect
github.com/jmoiron/sqlx v1.4.0 // indirect
github.com/jonboulle/clockwork v0.5.0 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.18.7 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/mailru/easyjson v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.21 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/oklog/run v1.2.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.4.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.23.2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.67.5 // indirect
github.com/prometheus/procfs v0.20.1 // indirect
github.com/samber/go-type-to-string v1.8.0 // indirect
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/scylladb/go-reflectx v1.0.1 // indirect
github.com/smartcontractkit/chain-selectors v1.0.104 // indirect
github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 // indirect
github.com/smartcontractkit/chainlink-protos/linking-service/go v0.0.0-20251002192024-d2ad9222409b // indirect
github.com/smartcontractkit/chainlink-protos/metering/go v0.0.0-20260710151514-27b5a126dabe // indirect
github.com/smartcontractkit/chainlink-protos/node-platform v0.0.0-20260709145319-7782fb89eb16 // indirect
github.com/smartcontractkit/freeport v0.1.3-0.20250716200817-cb5dfd0e369e // indirect
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 // indirect
github.com/smartcontractkit/libocr v0.0.0-20260810200708-618b5bf7f342 // indirect
github.com/spf13/cobra v1.10.2 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/stellar/go-stellar-sdk v0.4.0 // indirect
github.com/stellar/go-xdr v0.0.0-20260312225820-cc2b0611aabf // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
github.com/x448/float16 v0.8.4 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/bridges/prometheus v0.68.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.70.0 // indirect
go.opentelemetry.io/otel v1.46.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.22.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.22.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetricgrpc v1.46.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.46.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.46.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.46.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.46.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutlog v0.22.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdoutmetric v1.46.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.46.0 // indirect
go.opentelemetry.io/otel/log v0.22.0 // indirect
go.opentelemetry.io/otel/metric v1.46.0 // indirect
go.opentelemetry.io/otel/sdk v1.46.0 // indirect
go.opentelemetry.io/otel/sdk/log v0.22.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.46.0 // indirect
go.opentelemetry.io/otel/trace v1.46.0 // indirect
go.opentelemetry.io/proto/otlp v1.11.0 // indirect
go.uber.org/goleak v1.3.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.28.0 // indirect
go.yaml.in/yaml/v2 v2.4.4 // indirect
go.yaml.in/yaml/v3 v3.0.5 // indirect
golang.org/x/crypto v0.55.0 // indirect
golang.org/x/exp v0.0.0-20260508232706-74f9aab9d74a // indirect
golang.org/x/mod v0.38.0 // indirect
golang.org/x/net v0.58.0 // indirect
golang.org/x/sync v0.22.0 // indirect
golang.org/x/sys v0.47.0 // indirect
golang.org/x/text v0.41.0 // indirect
golang.org/x/time v0.15.0 // indirect
golang.org/x/tools v0.48.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20260819154853-08b0e4226688 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260819154853-08b0e4226688 // indirect
google.golang.org/grpc v1.83.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
sigs.k8s.io/yaml v1.6.0 // indirect
)
Loading
Loading