Skip to content

Commit

Permalink
Filter Comparator Remapping
Browse files Browse the repository at this point in the history
This commit remaps chain-agnostic filters into solana specific subkey filters. Event fields can be
queried by providing a comparator filter with the off-chain field name and the off-chain field value.
Both the field name and value will be converted to their on-chain equivalent. All input modifiers
defined in the contract reader config will be applied to the value.
  • Loading branch information
EasterTheBunny committed Feb 4, 2025
1 parent 8c3390b commit 77f0055
Show file tree
Hide file tree
Showing 20 changed files with 683 additions and 117 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ require (
github.com/jackc/pgx/v4 v4.18.3
github.com/pelletier/go-toml/v2 v2.2.3
github.com/prometheus/client_golang v1.20.5
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250128162345-af4c8fd4481a
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250128162345-af4c8fd4481a
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250127125541-a8fa42cc0f36
github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20250203183025-939526523893
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,8 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250128162345-af4c8fd4481a h1:xr9/8DDQKWTLcswFJVDquEOuICfsVKEAtJDrzTCknSM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250128162345-af4c8fd4481a/go.mod h1:UEnHaxkUsfreeA7rR45LMmua1Uen95tOFUR8/AI9BAo=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405 h1:5QyaPGLmt+rlnvQL7drAE23Wq9rX5hO35kTZirAb97A=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405/go.mod h1:UEnHaxkUsfreeA7rR45LMmua1Uen95tOFUR8/AI9BAo=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250128162345-af4c8fd4481a h1:1MrD2OiP/CRfyBSwTQE66R1+gLWBgWcU/SYl/+DmZ/Y=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250128162345-af4c8fd4481a/go.mod h1:Bmwq4lNb5tE47sydN0TKetcLEGbgl+VxHEWp4S0LI60=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250127125541-a8fa42cc0f36 h1:dytZPggag6auyzmbhpIDmkHu7KrflIBEhLLec4/xFIk=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ require (
github.com/slack-go/slack v0.15.0 // indirect
github.com/smartcontractkit/chain-selectors v1.0.37 // indirect
github.com/smartcontractkit/chainlink-automation v0.8.1 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203130001-13e2609047e9 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405 // indirect
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250128162345-af4c8fd4481a // indirect
github.com/smartcontractkit/chainlink-cosmos v0.5.2-0.20250130125138-3df261e09ddc // indirect
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20250128203428-08031923fbe5 // indirect
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1227,8 +1227,8 @@ github.com/smartcontractkit/chain-selectors v1.0.37 h1:EKVl8wayhOVfnlqfVmEyZ8rXO
github.com/smartcontractkit/chain-selectors v1.0.37/go.mod h1:xsKM0aN3YGcQKTPRPDDtPx2l4mlTN1Djmg0VVXV40b8=
github.com/smartcontractkit/chainlink-automation v0.8.1 h1:sTc9LKpBvcKPc1JDYAmgBc2xpDKBco/Q4h4ydl6+UUU=
github.com/smartcontractkit/chainlink-automation v0.8.1/go.mod h1:Iij36PvWZ6blrdC5A/nrQUBuf3MH3JvsBB9sSyc9W08=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203130001-13e2609047e9 h1:+/KEPuWctPObgOoEEBCnli1/H3XnjMdCY3Tn+J32XRM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203130001-13e2609047e9/go.mod h1:UEnHaxkUsfreeA7rR45LMmua1Uen95tOFUR8/AI9BAo=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405 h1:5QyaPGLmt+rlnvQL7drAE23Wq9rX5hO35kTZirAb97A=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20250203132120-f0d42463e405/go.mod h1:UEnHaxkUsfreeA7rR45LMmua1Uen95tOFUR8/AI9BAo=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250128162345-af4c8fd4481a h1:1MrD2OiP/CRfyBSwTQE66R1+gLWBgWcU/SYl/+DmZ/Y=
github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250128162345-af4c8fd4481a/go.mod h1:Bmwq4lNb5tE47sydN0TKetcLEGbgl+VxHEWp4S0LI60=
github.com/smartcontractkit/chainlink-common v0.4.2-0.20250130202959-6f1f48342e36 h1:bS51NFGHVjkCy7yu9L2Ss4sBsCW6jpa5GuhRAdWWxzM=
Expand Down
15 changes: 12 additions & 3 deletions pkg/solana/chainreader/account_read_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package chainreader

import (
"context"
"errors"
"fmt"

"github.com/gagliardetto/solana-go"

commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query"

"github.com/smartcontractkit/chainlink-solana/pkg/solana/codec"
)
Expand Down Expand Up @@ -35,6 +38,8 @@ func (b *accountReadBinding) SetCodec(codec types.RemoteCodec) {
b.codec = codec
}

func (b *accountReadBinding) SetModifier(commoncodec.Modifier) {}

func (b *accountReadBinding) SetAddress(key solana.PublicKey) {
b.key = key
}
Expand All @@ -57,11 +62,11 @@ func (b *accountReadBinding) GetAddress(ctx context.Context, params any) (solana
}

func (b *accountReadBinding) CreateType(forEncoding bool) (any, error) {
return b.codec.CreateType(codec.WrapItemType(forEncoding, b.namespace, b.genericName, codec.ChainConfigTypeAccountDef), forEncoding)
return b.codec.CreateType(codec.WrapItemType(forEncoding, b.namespace, b.genericName), forEncoding)
}

func (b *accountReadBinding) Decode(ctx context.Context, bts []byte, outVal any) error {
return b.codec.Decode(ctx, bts, outVal, codec.WrapItemType(false, b.namespace, b.genericName, codec.ChainConfigTypeAccountDef))
return b.codec.Decode(ctx, bts, outVal, codec.WrapItemType(false, b.namespace, b.genericName))
}

// buildSeedsSlice encodes and builds the seedslist to calculate the PDA public key
Expand All @@ -70,7 +75,7 @@ func (b *accountReadBinding) buildSeedsSlice(ctx context.Context, params any) ([
// Append the static prefix string first
flattenedSeeds = append(flattenedSeeds, []byte(b.prefix)...)
// Encode the seeds provided in the params
encodedParamSeeds, err := b.codec.Encode(ctx, params, codec.WrapItemType(true, b.namespace, b.genericName, ""))
encodedParamSeeds, err := b.codec.Encode(ctx, params, codec.WrapItemType(true, b.namespace, b.genericName))
if err != nil {
return nil, fmt.Errorf("failed to encode params into bytes for PDA seeds: %w", err)
}
Expand Down Expand Up @@ -99,3 +104,7 @@ func (b *accountReadBinding) buildSeedsSlice(ctx context.Context, params any) ([
}
return seedByteArray, nil
}

func (b *accountReadBinding) QueryKey(_ context.Context, _ query.KeyFilter, _ query.LimitAndSort, _ any) ([]types.Sequence, error) {
return nil, errors.New("unimplemented")
}
14 changes: 13 additions & 1 deletion pkg/solana/chainreader/bindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@ import (

"github.com/gagliardetto/solana-go"

commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query"
)

type readBinding interface {
SetAddress(solana.PublicKey)
GetAddress(context.Context, any) (solana.PublicKey, error)
SetCodec(types.RemoteCodec)
SetModifier(commoncodec.Modifier)
CreateType(bool) (any, error)
Decode(context.Context, []byte, any) error
QueryKey(context.Context, query.KeyFilter, query.LimitAndSort, any) ([]types.Sequence, error)
}

// key is namespace
Expand Down Expand Up @@ -72,10 +76,18 @@ func (b namespaceBindings) Bind(binding types.BoundContract) error {
return nil
}

func (b namespaceBindings) SetCodec(codec types.RemoteCodec) {
func (b namespaceBindings) SetCodecs(codec types.RemoteCodec) {
for _, nbs := range b {
for _, rb := range nbs {
rb.SetCodec(codec)
}
}
}

func (b namespaceBindings) SetModifiers(modifier commoncodec.Modifier) {
for _, nbs := range b {
for _, rb := range nbs {
rb.SetModifier(modifier)
}
}
}
17 changes: 17 additions & 0 deletions pkg/solana/chainreader/bindings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query"
)

func TestBindings_CreateType(t *testing.T) {
Expand Down Expand Up @@ -54,6 +56,10 @@ func (_m *mockBinding) GetAddress(_ context.Context, _ any) (solana.PublicKey, e
return solana.PublicKey{}, nil
}

func (_m *mockBinding) SetModifier(a commoncodec.Modifier) {
_m.Called(a)
}

func (_m *mockBinding) CreateType(b bool) (any, error) {
ret := _m.Called(b)

Expand All @@ -63,3 +69,14 @@ func (_m *mockBinding) CreateType(b bool) (any, error) {
func (_m *mockBinding) Decode(_ context.Context, _ []byte, _ any) error {
return nil
}

func (_m *mockBinding) QueryKey(
a context.Context,
b query.KeyFilter,
c query.LimitAndSort,
d any,
) ([]types.Sequence, error) {
ret := _m.Called(a, b, c, d)

return ret.Get(0).([]types.Sequence), ret.Error(1)
}
Loading

0 comments on commit 77f0055

Please sign in to comment.