Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
0f516d6
Added injected df decoder
silaslenihan Apr 9, 2025
deda7c5
extracted metadata to common
silaslenihan Apr 9, 2025
34ec523
moved Metadata to this repo
silaslenihan Apr 10, 2025
5af65e1
Refactored for processor injection and restructured code
silaslenihan Apr 10, 2025
5aca00f
added emitterAwareProcessor
silaslenihan Apr 10, 2025
f66fc9c
moved dfprocessor to chainlink-evm
silaslenihan Apr 10, 2025
003bec7
address feedback
silaslenihan Apr 10, 2025
7ac775b
updated data feeds ns
silaslenihan Apr 10, 2025
13c83b4
Restructured code
silaslenihan Apr 11, 2025
4531fbe
Added product specific processor, passing target config values to Wri…
silaslenihan Apr 17, 2025
7d23f69
Refactored to use common Metadata type
silaslenihan Apr 25, 2025
6c82a7c
Updated WriteConfirmed to extract only processor from report
silaslenihan Apr 28, 2025
021079f
Moved all chain-agnostic WT code to chainlink-framework
silaslenihan Apr 30, 2025
aea94cd
bumped go.mod
silaslenihan May 7, 2025
0a50d80
Enabled CCIP in DF processor
silaslenihan May 7, 2025
f23deca
bumped go.mod
silaslenihan May 12, 2025
64efeba
bumped go.mod
silaslenihan May 13, 2025
896cbc3
bumped go.mod
silaslenihan May 13, 2025
b7fec1d
Added POR report processor
silaslenihan May 14, 2025
110c0cb
fixed lint
silaslenihan May 14, 2025
0d42405
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan May 19, 2025
c2f891d
bumped go.mod
silaslenihan May 19, 2025
600c679
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan May 23, 2025
ffeb92e
Removed processor Name()
silaslenihan May 23, 2025
4c7249c
Added config for write target polling
silaslenihan May 23, 2025
3dd961e
fixed config tests
silaslenihan May 28, 2025
d4d11a4
bumped go.mod
silaslenihan May 28, 2025
a91625a
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan May 28, 2025
8be5634
fixed test
silaslenihan May 28, 2025
af9ef3b
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan May 30, 2025
19809e2
changed default TxAcceptanceState to 2
silaslenihan May 30, 2025
a8dd460
shifted bundle to slot 9 in proto
silaslenihan May 30, 2025
c099eb3
bump go.mod
silaslenihan Jun 3, 2025
02928f9
fixed config test
silaslenihan Jun 3, 2025
494a451
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan Jun 3, 2025
8b3653c
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan Jun 5, 2025
744075c
Refactored processor logic to be cleaner and injectible
silaslenihan Jun 6, 2025
e96ee74
Fixed lint
silaslenihan Jun 6, 2025
d64b26d
Fixed config
silaslenihan Jun 6, 2025
66f2310
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan Jun 6, 2025
0199af8
Revert "pkg/chains/legacyevm: reduce LegacyChains to ChainService (#92)"
silaslenihan Jun 6, 2025
000554f
Revert "pkg/chains/legacyevm: reduce LegacyChains to ChainService (#92)"
silaslenihan Jun 6, 2025
f0685c0
Merge branch 'fix/inject-df-decoder' of github.com:smartcontractkit/c…
silaslenihan Jun 6, 2025
6506229
Reapply "pkg/chains/legacyevm: reduce LegacyChains to ChainService (#…
silaslenihan Jun 6, 2025
fd1b021
bumped go mod
silaslenihan Jun 6, 2025
4590ac0
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan Jun 9, 2025
5033db9
moved datafeeds protos to chainlink-framework
silaslenihan Jun 9, 2025
a702de8
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan Jun 9, 2025
18c1ea9
bumped go.mod
silaslenihan Jun 11, 2025
9cd2ef6
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan Jun 17, 2025
95cf323
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan Jun 17, 2025
6f7a456
Merge branch 'develop' into fix/inject-df-decoder
silaslenihan Jun 18, 2025
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
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ require (
github.com/prometheus/client_model v0.6.1
github.com/prometheus/common v0.63.0
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250521190241-65a9b738252b
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250522110034-65c54665034a
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250618162808-a5a42ee8701b
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250618164021-9b34289a9502
github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20250616180023-87b70c08d7c0
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250618135814-7e3f79ab707e
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250522110034-65c54665034a
Expand All @@ -36,7 +36,6 @@ require (
github.com/zksync-sdk/zksync2-go v1.0.0
go.opentelemetry.io/otel v1.35.0
go.opentelemetry.io/otel/metric v1.35.0
go.opentelemetry.io/otel/trace v1.35.0
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.36.0
Expand Down Expand Up @@ -156,16 +155,16 @@ require (
github.com/santhosh-tekuri/jsonschema/v5 v5.2.0 // indirect
github.com/scylladb/go-reflectx v1.0.1 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/smartcontractkit/freeport v0.1.0 // indirect
github.com/smartcontractkit/freeport v0.1.1 // indirect
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 // indirect
github.com/stephenlacy/go-ethereum-hdwallet v0.0.0-20230913225845-a4fa94429863 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/supranational/blst v0.3.14 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tklauser/go-sysconf v0.3.13 // indirect
github.com/tklauser/numcpus v0.7.0 // indirect
github.com/tklauser/go-sysconf v0.3.15 // indirect
github.com/tklauser/numcpus v0.10.0 // indirect
github.com/tyler-smith/go-bip39 v1.1.0 // indirect
github.com/urfave/cli/v2 v2.27.5 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
Expand All @@ -189,6 +188,7 @@ require (
go.opentelemetry.io/otel/sdk v1.35.0 // indirect
go.opentelemetry.io/otel/sdk/log v0.10.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.35.0 // indirect
go.opentelemetry.io/otel/trace v1.35.0 // indirect
go.opentelemetry.io/proto/otlp v1.5.0 // indirect
golang.org/x/mod v0.24.0 // indirect
golang.org/x/net v0.38.0 // indirect
Expand Down
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -636,10 +636,10 @@ github.com/shurcooL/vfsgen v0.0.0-20200824052919-0d455de96546/go.mod h1:TrYk7fJV
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250521190241-65a9b738252b h1:sa0p3y99hBWvmFYXPvts5aM2SPc7SWUeEpUrySzWWiY=
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250521190241-65a9b738252b/go.mod h1:TF9ZqBV0QA3X1T4BoLGp0FfJpOQOcQ+ggKu1MlsWKYw=
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250522110034-65c54665034a h1:XpT8sAcjUVVD7Tcuxx77rD9g5DXFZu3LFxk59SDmPm0=
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250522110034-65c54665034a/go.mod h1:NVoJQoPYr6BorpaXTusoIH1IYTySCmanQ8Q1yv3mNh4=
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250618162808-a5a42ee8701b h1:nS5njF5W9lY1LnTITt3V2M35dT19JPpuVg6//vlzFiU=
github.com/smartcontractkit/chainlink-common v0.7.1-0.20250618162808-a5a42ee8701b/go.mod h1:1ntZ0rtQpPx6h+xlcOJp0ccqHFaxTzW2Z62FJG358q0=
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250618164021-9b34289a9502 h1:WLgEB8/lIfA1vI+7O4RE/PYitO57TRkKUqVllDIgJD4=
github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250618164021-9b34289a9502/go.mod h1:Kb8f+wt2YmBdD0PfbsC9bDhdUG/Y8sqUkzAvC2Dn8/M=
github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20250616180023-87b70c08d7c0 h1:OpFlG2f+LXsDp3cejSQju2rmoNsxBlhgrwXMIsk72IA=
github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20250616180023-87b70c08d7c0/go.mod h1:X+a4k2a+2G2/yeAaRQMCTLmlhNdQYAeN6v+ZpLzRZww=
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250618135814-7e3f79ab707e h1:LRT+PltY99+hxZAJn+4nyTfqGVNEM1S6FJ675B9BtJo=
Expand All @@ -652,8 +652,8 @@ github.com/smartcontractkit/chainlink-tron/relayer v0.0.11-0.20250528121202-2925
github.com/smartcontractkit/chainlink-tron/relayer v0.0.11-0.20250528121202-292529af39df/go.mod h1:EQl7VcrSvpSNOL8qWkc2CV/2cOII5CIkKTeIqzqCWKk=
github.com/smartcontractkit/chainlink-tron/relayer/gotron-sdk v0.0.5-0.20250528121202-292529af39df h1:36e3ROIZyV/qE8SvFOACXtXfMOMd9vG4+zY2v2ScXkI=
github.com/smartcontractkit/chainlink-tron/relayer/gotron-sdk v0.0.5-0.20250528121202-292529af39df/go.mod h1:4WhGgCA0smBbBud5mK+jnDb2wwndMvoqaWBJ3OV/7Bw=
github.com/smartcontractkit/freeport v0.1.0 h1:3MZHeti5m+tSTBCq5R8rhawFHxrnQZYBZVL+xgS1sPo=
github.com/smartcontractkit/freeport v0.1.0/go.mod h1:T4zH9R8R8lVWKfU7tUvYz2o2jMv1OpGCdpY2j2QZXzU=
github.com/smartcontractkit/freeport v0.1.1 h1:B5fhEtmgomdIhw03uPVbVTP6oPv27fBhZsoZZMSIS8I=
github.com/smartcontractkit/freeport v0.1.1/go.mod h1:T4zH9R8R8lVWKfU7tUvYz2o2jMv1OpGCdpY2j2QZXzU=
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7 h1:12ijqMM9tvYVEm+nR826WsrNi6zCKpwBhuApq127wHs=
github.com/smartcontractkit/grpc-proxy v0.0.0-20240830132753-a7e17fec5ab7/go.mod h1:FX7/bVdoep147QQhsOPkYsPEXhGZjeYx6lBSaSXtZOA=
github.com/smartcontractkit/libocr v0.0.0-20250328171017-609ec10a5510 h1:gm8Jli0sdkrZYnrWBngAkPSDzFDkdNCy1/Dj86kVtYk=
Expand Down Expand Up @@ -706,10 +706,10 @@ github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JT
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
github.com/tklauser/go-sysconf v0.3.13 h1:GBUpcahXSpR2xN01jhkNAbTLRk2Yzgggk8IM08lq3r4=
github.com/tklauser/go-sysconf v0.3.13/go.mod h1:zwleP4Q4OehZHGn4CYZDipCgg9usW5IJePewFCGVEa0=
github.com/tklauser/numcpus v0.7.0 h1:yjuerZP127QG9m5Zh/mSO4wqurYil27tHrqwRoRjpr4=
github.com/tklauser/numcpus v0.7.0/go.mod h1:bb6dMVcj8A42tSE7i32fsIUCbQNllK5iDguyOZRUzAY=
github.com/tklauser/go-sysconf v0.3.15 h1:VE89k0criAymJ/Os65CSn1IXaol+1wrsFHEB8Ol49K4=
github.com/tklauser/go-sysconf v0.3.15/go.mod h1:Dmjwr6tYFIseJw7a3dRLJfsHAMXZ3nEnL/aZY+0IuI4=
github.com/tklauser/numcpus v0.10.0 h1:18njr6LDBk1zuna922MgdjQuJFjrdppsZG60sHGfjso=
github.com/tklauser/numcpus v0.10.0/go.mod h1:BiTKazU708GQTYF4mB+cmlpT2Is1gLk7XVuEeem8LsQ=
github.com/tyler-smith/go-bip39 v1.1.0 h1:5eUemwrMargf3BSLRRCalXT93Ns6pQJIjYQN2nyfOP8=
github.com/tyler-smith/go-bip39 v1.1.0/go.mod h1:gUYDtqQw1JS3ZJ8UWVcGTGqqr6YIN3CWg+kkNaLt55U=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
Expand Down
4 changes: 4 additions & 0 deletions pkg/.mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ packages:
github.com/smartcontractkit/chainlink-evm/pkg/monitor:
interfaces:
BalanceMonitor:

github.com/smartcontractkit/chainlink-evm/pkg/writetarget:
interfaces:
ProductSpecificProcessor:
github.com/smartcontractkit/chainlink-framework/multinode:
config:
dir: client/clienttest
Expand Down
14 changes: 14 additions & 0 deletions pkg/config/chain_scoped_workflow.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package config

import (
"time"

commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-evm/pkg/config/toml"
"github.com/smartcontractkit/chainlink-evm/pkg/types"
)
Expand All @@ -20,3 +23,14 @@ func (b *workflowConfig) ForwarderAddress() *types.EIP55Address {
func (b *workflowConfig) GasLimitDefault() *uint64 {
return b.c.GasLimitDefault
}

func (b *workflowConfig) TxAcceptanceState() *commontypes.TransactionStatus {
return b.c.TxAcceptanceState
}

func (b *workflowConfig) PollPeriod() time.Duration {
return b.c.PollPeriod.Duration()
}
func (b *workflowConfig) AcceptanceTimeout() time.Duration {
return b.c.AcceptanceTimeout.Duration()
}
6 changes: 5 additions & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
gethcommon "github.com/ethereum/go-ethereum/common"

commonassets "github.com/smartcontractkit/chainlink-common/pkg/assets"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"

"github.com/smartcontractkit/chainlink-evm/pkg/assets"
"github.com/smartcontractkit/chainlink-evm/pkg/config/chaintype"
Expand Down Expand Up @@ -187,9 +188,12 @@ type FeeHistory interface {
}

type Workflow interface {
FromAddress() *types.EIP55Address
AcceptanceTimeout() time.Duration
ForwarderAddress() *types.EIP55Address
FromAddress() *types.EIP55Address
GasLimitDefault() *uint64
PollPeriod() time.Duration
TxAcceptanceState() *commontypes.TransactionStatus
}

type NodePool interface {
Expand Down
18 changes: 15 additions & 3 deletions pkg/config/toml/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,12 @@ func (a *Automation) setFrom(f *Automation) {
}

type Workflow struct {
FromAddress *types.EIP55Address `toml:",omitempty"`
ForwarderAddress *types.EIP55Address `toml:",omitempty"`
GasLimitDefault *uint64
FromAddress *types.EIP55Address `toml:",omitempty"`
ForwarderAddress *types.EIP55Address `toml:",omitempty"`
GasLimitDefault *uint64
TxAcceptanceState *commontypes.TransactionStatus
PollPeriod *commonconfig.Duration
AcceptanceTimeout *commonconfig.Duration
}

func (m *Workflow) setFrom(f *Workflow) {
Expand All @@ -645,6 +648,15 @@ func (m *Workflow) setFrom(f *Workflow) {
if v := f.GasLimitDefault; v != nil {
m.GasLimitDefault = v
}
if v := f.TxAcceptanceState; v != nil {
m.TxAcceptanceState = v
}
if v := f.PollPeriod; v != nil {
m.PollPeriod = v
}
if v := f.AcceptanceTimeout; v != nil {
m.AcceptanceTimeout = v
}
}

type BalanceMonitor struct {
Expand Down
11 changes: 8 additions & 3 deletions pkg/config/toml/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
commonassets "github.com/smartcontractkit/chainlink-common/pkg/assets"
"github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink-common/pkg/config/configtest"
commontypes "github.com/smartcontractkit/chainlink-common/pkg/types"

"github.com/smartcontractkit/chainlink-framework/multinode"

"github.com/smartcontractkit/chainlink-evm/pkg/assets"
Expand Down Expand Up @@ -345,9 +347,12 @@ var fullConfig = EVMConfig{
},
},
Workflow: Workflow{
FromAddress: ptr(types.MustEIP55Address("0x627306090abaB3A6e1400e9345bC60c78a8BEf57")),
ForwarderAddress: ptr(types.MustEIP55Address("0x9FBDa871d559710256a2502A2517b794B482Db40")),
GasLimitDefault: ptr[uint64](400000),
FromAddress: ptr(types.MustEIP55Address("0x627306090abaB3A6e1400e9345bC60c78a8BEf57")),
ForwarderAddress: ptr(types.MustEIP55Address("0x9FBDa871d559710256a2502A2517b794B482Db40")),
GasLimitDefault: ptr[uint64](400000),
TxAcceptanceState: ptr(commontypes.Unconfirmed),
PollPeriod: config.MustNewDuration(2 * time.Second),
AcceptanceTimeout: config.MustNewDuration(30 * time.Second),
},
},
Nodes: EVMNodes{
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/toml/defaults/fallback.toml
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,6 @@ GasLimit = 5400000

[Workflow]
GasLimitDefault = 400_000
TxAcceptanceState = 2
PollPeriod = '2s'
AcceptanceTimeout = '30s'
6 changes: 6 additions & 0 deletions pkg/config/toml/docs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -536,3 +536,9 @@ FromAddress = '0x2a3e23c6f242F5345320814aC8a1b4E58707D292' # Example
ForwarderAddress = '0x2a3e23c6f242F5345320814aC8a1b4E58707D292' # Example
# GasLimitDefault is the default gas limit for workflow transactions.
GasLimitDefault = 400_000 # Default
# TxAcceptanceState is the default acceptance state for writer DON tranmissions.
TxAcceptanceState = 2 # Default
# PollPeriod is the default poll period for checking transmission state
PollPeriod = '2s' # Default
# AcceptanceTimeout is the default timeout for a tranmission to be accepted on chain
AcceptanceTimeout = '30s' # Default
3 changes: 3 additions & 0 deletions pkg/config/toml/testdata/config-full.toml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ GasLimit = 540
FromAddress = '0x627306090abaB3A6e1400e9345bC60c78a8BEf57'
ForwarderAddress = '0x9FBDa871d559710256a2502A2517b794B482Db40'
GasLimitDefault = 400000
TxAcceptanceState = 2
PollPeriod = '2s'
AcceptanceTimeout = '30s'

[[Nodes]]
Name = 'foo'
Expand Down
159 changes: 159 additions & 0 deletions pkg/report/datafeeds/decode.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
package datafeeds

import (
"context"
"fmt"
"math"
"math/big"

"github.com/ethereum/go-ethereum/accounts/abi"
"google.golang.org/protobuf/proto"

"github.com/smartcontractkit/chainlink-common/pkg/beholder"

"github.com/smartcontractkit/chainlink-framework/capabilities/writetarget/monitoring/pb/common"
df "github.com/smartcontractkit/chainlink-framework/capabilities/writetarget/monitoring/pb/data-feeds/on-chain/registry"
wt "github.com/smartcontractkit/chainlink-framework/capabilities/writetarget/monitoring/pb/platform"
"github.com/smartcontractkit/chainlink-framework/capabilities/writetarget/report/platform"
)

// EVM POR specific processor decodes writes as 'data-feeds.registry.FeedUpdated' messages + metrics
type Processor struct {
emitter beholder.ProtoEmitter
metrics *df.Metrics
schema abi.Arguments
decodeReport func(*wt.WriteConfirmed, []byte, abi.Arguments) ([]*df.FeedUpdated, error)
}

func NewProcessor(metrics *df.Metrics, emitter beholder.ProtoEmitter, schema abi.Arguments, decodeReport func(*wt.WriteConfirmed, []byte, abi.Arguments) ([]*df.FeedUpdated, error)) *Processor {
return &Processor{
metrics: metrics,
emitter: emitter,
schema: schema,
decodeReport: decodeReport,
}
}

func (p *Processor) Process(ctx context.Context, m proto.Message, attrKVs ...any) error {
// Switch on the type of the proto.Message
switch msg := m.(type) {
case *wt.WriteConfirmed:
updates, err := p.DecodeAsFeedUpdated(msg)
if err != nil {
return fmt.Errorf("failed to decode as 'data-feeds.registry.df.FeedUpdated': %w", err)
}
for _, update := range updates {
err = p.emitter.EmitWithLog(ctx, update, attrKVs...)
if err != nil {
return fmt.Errorf("failed to emit with log: %w", err)
}
// Process emit and derive metrics
err = p.metrics.OnFeedUpdated(ctx, update, attrKVs...)
if err != nil {
return fmt.Errorf("failed to publish feed updated metrics: %w", err)
}
}
return nil
default:
return nil // fallthrough
}
}

func GetSchema(typ string, internalType string, components []abi.ArgumentMarshaling) abi.Arguments {
result, err := abi.NewType(typ, internalType, components)
if err != nil {
panic(fmt.Sprintf("Unexpected error during abi.NewType: %s", err))
}
return abi.Arguments([]abi.Argument{
{
// This defines the array of tuple records.
Type: result,
},
})
}

func (p *Processor) DecodeAsFeedUpdated(m *wt.WriteConfirmed) ([]*df.FeedUpdated, error) {
// Decode the confirmed report (WT -> DF contract event)
r, err := platform.Decode(m.Report)
if err != nil {
return nil, fmt.Errorf("failed to decode report: %w", err)
}

msgs, err := p.decodeReport(m, r.Data, p.schema)
if err != nil {
return nil, fmt.Errorf("failed to decode Data Feeds report: %w", err)
}

return msgs, nil
}

// newdf.FeedUpdated creates a df.FeedUpdated from the given common parameters.
// If includeTxInfo is true, TxSender and TxReceiver are set.
func NewFeedUpdated(
m *wt.WriteConfirmed,
feedID FeedID,
observationsTimestamp uint32,
benchmarkPrice *big.Int,
bundle []byte,
report []byte,
includeTxInfo bool,
) *df.FeedUpdated {
fu := &df.FeedUpdated{
FeedId: feedID.String(),
ObservationsTimestamp: observationsTimestamp,
Benchmark: benchmarkPrice.Bytes(),
Bundle: bundle,
Report: report,
BenchmarkVal: ToBenchmarkVal(feedID, benchmarkPrice),

// Head data - when was the event produced on-chain
BlockData: m.BlockData,

ExecutionContext: m.ExecutionContext,
}

if includeTxInfo {
fu.TransactionData = &common.TransactionData{
TxSender: m.Transmitter,
TxReceiver: m.Forwarder,
}
}

return fu
}

// ToBenchmarkVal returns the benchmark i192 on-chain value decoded as an double (float64), scaled by number of decimals (e.g., 1e-18)
// Where the number of decimals is extracted from the feed ID.
//
// This is the largest type Prometheus supports, and this conversion can overflow but so far was sufficient
// for most use-cases. For big numbers, benchmark bytes should be used instead.
//
// Returns `math.NaN()` if report data type not a number, or `+/-Inf` if number doesn't fit in double.
func ToBenchmarkVal(feedID FeedID, val *big.Int) float64 {
// Return NaN if the value is nil
if val == nil {
return math.NaN()
}

// Get the number of decimals from the feed ID
t := feedID.GetDataType()
decimals, isNumber := GetDecimals(t)

// Return NaN if the value is not a number
if !isNumber {
return math.NaN()
}

// Convert the i192 to a big Float, scaled by the number of decimals
valF := new(big.Float).SetInt(val)

if decimals > 0 {
denominator := big.NewFloat(math.Pow10(int(decimals)))
valF = new(big.Float).Quo(valF, denominator)
}

// Notice: this can overflow, but so far was sufficient for most use-cases
// On overflow, returns +/-Inf (valid Prometheus value)
valRes, _ := valF.Float64()
return valRes
}
Loading
Loading