diff --git a/go.mod b/go.mod index ea71ed468..02851f8c5 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,6 @@ require ( github.com/gagliardetto/gofuzz v1.2.2 github.com/gagliardetto/solana-go v1.13.0 github.com/gagliardetto/treeout v0.1.4 - github.com/gagliardetto/utilz v0.1.1 github.com/go-viper/mapstructure/v2 v2.4.0 github.com/google/uuid v1.6.0 github.com/hashicorp/go-plugin v1.6.3 @@ -23,7 +22,7 @@ require ( github.com/smartcontractkit/chainlink-ccip v0.0.0-20250627133416-1d85eec09097 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250707132450-d1f5f0be212a github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20250804184440-c0506474fc44 - github.com/smartcontractkit/chainlink-common v0.9.4-0.20250822114026-4186ff61208b + github.com/smartcontractkit/chainlink-common v0.9.4-0.20250822210039-df24f468593d github.com/smartcontractkit/chainlink-common/pkg/monitoring v0.0.0-20250415235644-8703639403c7 github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20250818175541-3389ac08a563 github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250717121125-2350c82883e2 @@ -60,6 +59,7 @@ require ( github.com/fatih/color v1.18.0 // indirect github.com/fxamacker/cbor/v2 v2.7.0 // indirect github.com/gabriel-vasile/mimetype v1.4.8 // indirect + github.com/gagliardetto/utilz v0.1.3 // indirect github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874 // indirect github.com/go-kit/log v0.2.1 // indirect github.com/go-logfmt/logfmt v0.6.0 // indirect diff --git a/go.sum b/go.sum index 49b1b430b..5b2a51b7c 100644 --- a/go.sum +++ b/go.sum @@ -104,8 +104,8 @@ github.com/gagliardetto/solana-go v1.13.0 h1:uNzhjwdAdbq9xMaX2DF0MwXNMw6f8zdZ7JP github.com/gagliardetto/solana-go v1.13.0/go.mod h1:l/qqqIN6qJJPtxW/G1PF4JtcE3Zg2vD2EliZrr9Gn5k= github.com/gagliardetto/treeout v0.1.4 h1:ozeYerrLCmCubo1TcIjFiOWTTGteOOHND1twdFpgwaw= github.com/gagliardetto/treeout v0.1.4/go.mod h1:loUefvXTrlRG5rYmJmExNryyBRh8f89VZhmMOyCyqok= -github.com/gagliardetto/utilz v0.1.1 h1:/etW4hl607emKg6R6Lj9jRJ9d6ue2AQOyjhuAwjzs1U= -github.com/gagliardetto/utilz v0.1.1/go.mod h1:b+rGFkRHz3HWJD0RYMzat47JyvbTtpE0iEcYTRJTLLA= +github.com/gagliardetto/utilz v0.1.3 h1:A+asc+6/3a9qNBrgticApj3yW5F7y4TaJd8Ijg+o0zM= +github.com/gagliardetto/utilz v0.1.3/go.mod h1:b+rGFkRHz3HWJD0RYMzat47JyvbTtpE0iEcYTRJTLLA= github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874 h1:F8d1AJ6M9UQCavhwmO6ZsrYLfG8zVFWfEfMS2MXPkSY= github.com/go-json-experiment/json v0.0.0-20250223041408-d3c622f1b874/go.mod h1:TiCD2a1pcmjd7YnhGH0f/zKNcCD06B029pHhzV23c2M= github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY= @@ -410,8 +410,8 @@ github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250707132450-d github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250707132450-d1f5f0be212a/go.mod h1:XEtEV52YIISL1Xp2l9XqyXFonKF9WxuGQQJu/lMozl8= github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20250804184440-c0506474fc44 h1:S00lus9RPu5JuxKRtGEET+aIUfASahHpTRV5RgPARSI= github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20250804184440-c0506474fc44/go.mod h1:xtZNi6pOKdC3sLvokDvXOhgHzT+cyBqH/gWwvxTxqrg= -github.com/smartcontractkit/chainlink-common v0.9.4-0.20250822114026-4186ff61208b h1:SOTBUmlyMVlKPeNAuxB4ZGkhQRXOEWRGbV6PQ+bs5Nw= -github.com/smartcontractkit/chainlink-common v0.9.4-0.20250822114026-4186ff61208b/go.mod h1:0OMQFyxibohHOzskRmEz4wr+w0SdAFsU6CjW/VhRf34= +github.com/smartcontractkit/chainlink-common v0.9.4-0.20250822210039-df24f468593d h1:z1DOZ+CrXqyS2OFPnUTqJCRH+QOpti8kpNS8uZ4KkbQ= +github.com/smartcontractkit/chainlink-common v0.9.4-0.20250822210039-df24f468593d/go.mod h1:Kp54d3kbM4eGPEmJW7fcRWYUk6emXy+F5TEu5czFcH8= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.1 h1:ca2z5OXgnbBPQRxpwXwBLJsUA1+cAp5ncfW4Ssvd6eY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.1/go.mod h1:NZv/qKYGFRnkjOYBouajnDfFoZ+WDa6H2KNmSf1dnKc= github.com/smartcontractkit/chainlink-common/pkg/monitoring v0.0.0-20250415235644-8703639403c7 h1:9wh1G+WbXwPVqf0cfSRSgwIcaXTQgvYezylEAfwmrbw= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 294f6ffe2..7fc620037 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -16,15 +16,15 @@ require ( github.com/pelletier/go-toml/v2 v2.2.4 github.com/rs/zerolog v1.33.0 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250805210128-7f8a0f403c3a - github.com/smartcontractkit/chainlink-common v0.9.4-0.20250822114026-4186ff61208b + github.com/smartcontractkit/chainlink-common v0.9.4-0.20250822210039-df24f468593d github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20250819150450-95ef563f6e6d - github.com/smartcontractkit/chainlink-solana v1.1.2-0.20250822114658-478d76fce6b9 + github.com/smartcontractkit/chainlink-solana v1.1.2-0.20250825220915-aa665a71ecd0 github.com/smartcontractkit/chainlink-testing-framework/lib v1.54.4 github.com/smartcontractkit/chainlink-testing-framework/parrot v0.6.2 github.com/smartcontractkit/chainlink-testing-framework/seth v1.51.2 - github.com/smartcontractkit/chainlink/deployment v0.0.0-20250822122521-7924eae1304f - github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20250822122521-7924eae1304f - github.com/smartcontractkit/chainlink/v2 v2.26.0-debug-tracing.0.20250822122521-7924eae1304f + github.com/smartcontractkit/chainlink/deployment v0.0.0-20250825221423-6ed54fd5fc70 + github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20250825221423-6ed54fd5fc70 + github.com/smartcontractkit/chainlink/v2 v2.26.0-debug-tracing.0.20250825221423-6ed54fd5fc70 github.com/smartcontractkit/libocr v0.0.0-20250707144819-babe0ec4e358 github.com/stretchr/testify v1.10.0 github.com/testcontainers/testcontainers-go v0.37.0 @@ -172,7 +172,7 @@ require ( github.com/fxamacker/cbor/v2 v2.7.0 // indirect github.com/gabriel-vasile/mimetype v1.4.8 // indirect github.com/gagliardetto/treeout v0.1.4 // indirect - github.com/gagliardetto/utilz v0.1.1 // indirect + github.com/gagliardetto/utilz v0.1.3 // indirect github.com/getsentry/sentry-go v0.27.0 // indirect github.com/gibson042/canonicaljson-go v1.0.3 // indirect github.com/gin-contrib/sessions v0.0.5 // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 5f984b424..accffffeb 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -464,8 +464,8 @@ github.com/gagliardetto/solana-go v1.13.0 h1:uNzhjwdAdbq9xMaX2DF0MwXNMw6f8zdZ7JP github.com/gagliardetto/solana-go v1.13.0/go.mod h1:l/qqqIN6qJJPtxW/G1PF4JtcE3Zg2vD2EliZrr9Gn5k= github.com/gagliardetto/treeout v0.1.4 h1:ozeYerrLCmCubo1TcIjFiOWTTGteOOHND1twdFpgwaw= github.com/gagliardetto/treeout v0.1.4/go.mod h1:loUefvXTrlRG5rYmJmExNryyBRh8f89VZhmMOyCyqok= -github.com/gagliardetto/utilz v0.1.1 h1:/etW4hl607emKg6R6Lj9jRJ9d6ue2AQOyjhuAwjzs1U= -github.com/gagliardetto/utilz v0.1.1/go.mod h1:b+rGFkRHz3HWJD0RYMzat47JyvbTtpE0iEcYTRJTLLA= +github.com/gagliardetto/utilz v0.1.3 h1:A+asc+6/3a9qNBrgticApj3yW5F7y4TaJd8Ijg+o0zM= +github.com/gagliardetto/utilz v0.1.3/go.mod h1:b+rGFkRHz3HWJD0RYMzat47JyvbTtpE0iEcYTRJTLLA= github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08 h1:f6D9Hr8xV8uYKlyuj8XIruxlh9WjVjdh1gIicAS7ays= github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww= github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 h1:Uc+IZ7gYqAf/rSGFplbWBSHaGolEQlNLgMgSE3ccnIQ= @@ -1253,8 +1253,8 @@ github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250805210128-7 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20250805210128-7f8a0f403c3a/go.mod h1:Ve1xD71bl193YIZQEoJMmBqLGQJdNs29bwbuObwvbhQ= github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20250805210128-7f8a0f403c3a h1:38dAlTPRUQHZus5dCnBnQyf/V4oYn0p2svWlbPgHDQ4= github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20250805210128-7f8a0f403c3a/go.mod h1:xtZNi6pOKdC3sLvokDvXOhgHzT+cyBqH/gWwvxTxqrg= -github.com/smartcontractkit/chainlink-common v0.9.4-0.20250822114026-4186ff61208b h1:SOTBUmlyMVlKPeNAuxB4ZGkhQRXOEWRGbV6PQ+bs5Nw= -github.com/smartcontractkit/chainlink-common v0.9.4-0.20250822114026-4186ff61208b/go.mod h1:0OMQFyxibohHOzskRmEz4wr+w0SdAFsU6CjW/VhRf34= +github.com/smartcontractkit/chainlink-common v0.9.4-0.20250822210039-df24f468593d h1:z1DOZ+CrXqyS2OFPnUTqJCRH+QOpti8kpNS8uZ4KkbQ= +github.com/smartcontractkit/chainlink-common v0.9.4-0.20250822210039-df24f468593d/go.mod h1:Kp54d3kbM4eGPEmJW7fcRWYUk6emXy+F5TEu5czFcH8= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.1 h1:ca2z5OXgnbBPQRxpwXwBLJsUA1+cAp5ncfW4Ssvd6eY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.1/go.mod h1:NZv/qKYGFRnkjOYBouajnDfFoZ+WDa6H2KNmSf1dnKc= github.com/smartcontractkit/chainlink-common/pkg/monitoring v0.0.0-20250415235644-8703639403c7 h1:9wh1G+WbXwPVqf0cfSRSgwIcaXTQgvYezylEAfwmrbw= @@ -1305,12 +1305,12 @@ github.com/smartcontractkit/chainlink-tron/relayer v0.0.11-0.20250815105909-7549 github.com/smartcontractkit/chainlink-tron/relayer v0.0.11-0.20250815105909-75499abc4335/go.mod h1:ccjEgNeqOO+bjPddnL4lUrNLzyCvGCxgBjJdhFX3wa8= github.com/smartcontractkit/chainlink-tron/relayer/gotron-sdk v0.0.5-0.20250422175525-b7575d96bd4d h1:qLmSOOtB/Ogn79eIDkuujOu8M5Jd747V1H7Brk/nTvo= github.com/smartcontractkit/chainlink-tron/relayer/gotron-sdk v0.0.5-0.20250422175525-b7575d96bd4d/go.mod h1:4WhGgCA0smBbBud5mK+jnDb2wwndMvoqaWBJ3OV/7Bw= -github.com/smartcontractkit/chainlink/deployment v0.0.0-20250822122521-7924eae1304f h1:v6V7rbwxnKQDkV1+bXNySC5+eRDgq5i/Zhilj1Dkg3c= -github.com/smartcontractkit/chainlink/deployment v0.0.0-20250822122521-7924eae1304f/go.mod h1:hOBwMZV5wGR5U6LKTNH2agxDqiM5yJl0i/d0qsIeGek= -github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20250822122521-7924eae1304f h1:Tp/3Op3n08gbzCZaLFUDtS3Pg1477BW8A3/n00ncDwc= -github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20250822122521-7924eae1304f/go.mod h1:EZnjwYZToUpLw1VsFYU64fV2OhbnJFvjsick1804DJA= -github.com/smartcontractkit/chainlink/v2 v2.26.0-debug-tracing.0.20250822122521-7924eae1304f h1:VuA3mpTiqwo9UaCPESYJeS+ONtPdiqZIqa4I30d8QDQ= -github.com/smartcontractkit/chainlink/v2 v2.26.0-debug-tracing.0.20250822122521-7924eae1304f/go.mod h1:FsbzpAb719eV79qc2ixb3BHEW7YCNEVpIU1Q0yajHGo= +github.com/smartcontractkit/chainlink/deployment v0.0.0-20250825221423-6ed54fd5fc70 h1:sHr+O1v7wBNtpO1ymj5R+UH+uPc3zdj12GDa0d8fpKs= +github.com/smartcontractkit/chainlink/deployment v0.0.0-20250825221423-6ed54fd5fc70/go.mod h1:VojWOERGFaR0/vc0TDrppuksJ3gYzNNYWd7eZkjrV/I= +github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20250825221423-6ed54fd5fc70 h1:HuxvHvfD1kYAfn38Fv/bWuq/gxYvFyF2tF/7chsh5vk= +github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20250825221423-6ed54fd5fc70/go.mod h1:N7YNnckw4beJYxtkKDP8mCH0kueES7c+fr985A3rkHg= +github.com/smartcontractkit/chainlink/v2 v2.26.0-debug-tracing.0.20250825221423-6ed54fd5fc70 h1:0EfDhrjlsA8ZZmsy9LexU/yVUk1O4/3UPnFDPERnMvo= +github.com/smartcontractkit/chainlink/v2 v2.26.0-debug-tracing.0.20250825221423-6ed54fd5fc70/go.mod h1:3/VehDaq2C74UoUn7I4cxEG0oFrGVurtqOYFPQjEc9Y= github.com/smartcontractkit/cre-sdk-go v0.5.1-0.20250818135829-9ea58491207f h1:pgupmqPyAqfl2xgqHaRwfI/Kd6HtGbB8WeMt9XPM5L0= github.com/smartcontractkit/cre-sdk-go v0.5.1-0.20250818135829-9ea58491207f/go.mod h1:C1KXVcxUy89lFVqJ335pEPeeC/wJy0jCF0ZztwWdCmU= github.com/smartcontractkit/freeport v0.1.3-0.20250716200817-cb5dfd0e369e h1:Hv9Mww35LrufCdM9wtS9yVi/rEWGI1UnjHbcKKU0nVY= diff --git a/integration-tests/relayinterface/buffer_payload_test.go b/integration-tests/relayinterface/buffer_payload_test.go index 64e93e116..6202c8e6c 100644 --- a/integration-tests/relayinterface/buffer_payload_test.go +++ b/integration-tests/relayinterface/buffer_payload_test.go @@ -18,6 +18,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/services/servicetest" "github.com/smartcontractkit/chainlink-common/pkg/types" + soltypes "github.com/smartcontractkit/chainlink-common/pkg/types/solana" "github.com/smartcontractkit/chainlink-solana/contracts/generated/buffer_payload" "github.com/smartcontractkit/chainlink-solana/integration-tests/utils" @@ -76,25 +77,25 @@ func Test_BufferPayload(t *testing.T) { contractName := "buffer" methodName := "execute" - cwConfig := chainwriter.ChainWriterConfig{ - Programs: map[string]chainwriter.ProgramConfig{ + cwConfig := soltypes.ContractWriterConfig{ + Programs: map[string]soltypes.ProgramConfig{ contractName: { - Methods: map[string]chainwriter.MethodConfig{ + Methods: map[string]soltypes.MethodConfig{ methodName: { FromAddress: sender.PublicKey().String(), ChainSpecificName: "execute", ComputeUnitLimitOverhead: 150_000, BufferPayloadMethod: "CCIPExecutionReportBuffer", - Accounts: []chainwriter.Lookup{ + Accounts: []soltypes.Lookup{ { - AccountConstant: &chainwriter.AccountConstant{ + AccountConstant: &soltypes.AccountConstant{ Address: sender.PublicKey().String(), IsSigner: true, IsWritable: true, }, }, { - AccountConstant: &chainwriter.AccountConstant{ + AccountConstant: &soltypes.AccountConstant{ Address: solana.SystemProgramID.String(), IsSigner: false, IsWritable: false, @@ -176,7 +177,7 @@ func Test_BufferPayload(t *testing.T) { }) } -func initializeAndRunCW(t *testing.T, lggr logger.Logger, multiClient client.MultiClient, txm *txm.Txm, config chainwriter.ChainWriterConfig) *chainwriter.SolanaChainWriterService { +func initializeAndRunCW(t *testing.T, lggr logger.Logger, multiClient client.MultiClient, txm *txm.Txm, config soltypes.ContractWriterConfig) *chainwriter.SolanaChainWriterService { cw, err := chainwriter.NewSolanaChainWriterService(lggr, multiClient, txm, nil, config) require.NoError(t, err) servicetest.Run(t, cw) diff --git a/integration-tests/relayinterface/chain_components_test.go b/integration-tests/relayinterface/chain_components_test.go index 17653adcf..f258f2363 100644 --- a/integration-tests/relayinterface/chain_components_test.go +++ b/integration-tests/relayinterface/chain_components_test.go @@ -23,7 +23,7 @@ import ( "github.com/gagliardetto/solana-go/rpc/ws" "github.com/google/uuid" "github.com/jmoiron/sqlx" - "github.com/smartcontractkit/chainlink-common/pkg/sqlutil/pg" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "github.com/stretchr/testify/require" @@ -34,11 +34,13 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" commontestutils "github.com/smartcontractkit/chainlink-common/pkg/loop/testutils" "github.com/smartcontractkit/chainlink-common/pkg/services/servicetest" + "github.com/smartcontractkit/chainlink-common/pkg/sqlutil/pg" "github.com/smartcontractkit/chainlink-common/pkg/sqlutil/sqltest" "github.com/smartcontractkit/chainlink-common/pkg/types" . "github.com/smartcontractkit/chainlink-common/pkg/types/interfacetests" //nolint common practice to import test mods with . "github.com/smartcontractkit/chainlink-common/pkg/types/query" "github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives" + soltypes "github.com/smartcontractkit/chainlink-common/pkg/types/solana" "github.com/smartcontractkit/chainlink-protos/cre/go/values" contractprimary "github.com/smartcontractkit/chainlink-solana/contracts/generated/contract_reader_interface" @@ -1343,24 +1345,24 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T uint64ReadDef := config.ReadDefinition{ ChainSpecificName: "DataAccount", ReadType: config.Account, - PDADefinition: codec.PDATypeDef{ + PDADefinition: soltypes.PDATypeDef{ Prefix: pdaDataPrefix, }, OutputModifications: commoncodec.ModifiersConfig{ &commoncodec.PropertyExtractorConfig{FieldName: "U64Value"}, }, } - basicContractDef := config.ChainContractReader{ + basicContractDef := soltypes.ChainContractReader{ IDL: mustUnmarshalIDL(t, string(it.Helper.GetPrimaryIDL(t))), - Reads: map[string]config.ReadDefinition{ + Reads: map[string]soltypes.ReadDefinition{ MethodReturningUint64: uint64ReadDef, }, } - readWithAddressHardCodedIntoResponseDef := config.ReadDefinition{ + readWithAddressHardCodedIntoResponseDef := soltypes.ReadDefinition{ ChainSpecificName: "MultiRead1", - ReadType: config.Account, - PDADefinition: codec.PDATypeDef{ + ReadType: soltypes.Account, + PDADefinition: soltypes.PDATypeDef{ Prefix: []byte("multi_read1"), }, ResponseAddressHardCoder: &commoncodec.HardCodeModifierConfig{ @@ -1379,38 +1381,38 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T OffChainValues: map[string]any{"U": "", "V": false}, }, } - multiReadDef.MultiReader = &config.MultiReader{ - Reads: []config.ReadDefinition{{ + multiReadDef.MultiReader = &soltypes.MultiReader{ + Reads: []soltypes.ReadDefinition{{ ChainSpecificName: "MultiRead2", - PDADefinition: codec.PDATypeDef{Prefix: []byte("multi_read2")}, - ReadType: config.Account, + PDADefinition: soltypes.PDATypeDef{Prefix: []byte("multi_read2")}, + ReadType: soltypes.Account, }}, } idl := mustUnmarshalIDL(t, string(it.Helper.GetPrimaryIDL(t))) - idl.Accounts = append(idl.Accounts, codec.IdlTypeDef{ + idl.Accounts = append(idl.Accounts, soltypes.IdlTypeDef{ Name: "USDPerToken", - Type: codec.IdlTypeDefTy{ - Kind: codec.IdlTypeDefTyKindStruct, - Fields: &codec.IdlTypeDefStruct{ + Type: soltypes.IdlTypeDefTy{ + Kind: soltypes.IdlTypeDefTyKindStruct, + Fields: &soltypes.IdlTypeDefStruct{ { Name: "tokenPrices", - Type: codec.IdlType{ - AsIdlTypeVec: &codec.IdlTypeVec{Vec: codec.IdlType{AsIdlTypeDefined: &codec.IdlTypeDefined{Defined: "TimestampedPackedU224"}}}, + Type: soltypes.IdlType{ + AsIdlTypeVec: &soltypes.IdlTypeVec{Vec: soltypes.IdlType{AsIdlTypeDefined: &soltypes.IdlTypeDefined{Defined: "TimestampedPackedU224"}}}, }, }, }, }, }) - cfg := config.ContractReader{ - Namespaces: map[string]config.ChainContractReader{ + cfg := soltypes.ContractReader{ + Namespaces: map[string]soltypes.ChainContractReader{ AnyContractName: { IDL: idl, - Reads: map[string]config.ReadDefinition{ + Reads: map[string]soltypes.ReadDefinition{ ReadUninitializedPDA: { ChainSpecificName: "DataAccount", - ReadType: config.Account, + ReadType: soltypes.Account, PDADefinition: codec.PDATypeDef{ Prefix: []byte("AAAAAAAAAA"), }, @@ -1418,15 +1420,15 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T ReadWithAddressHardCodedIntoResponse: readWithAddressHardCodedIntoResponseDef, GetTokenPrices: { ChainSpecificName: "USDPerToken", - ReadType: config.Account, - PDADefinition: codec.PDATypeDef{ + ReadType: soltypes.Account, + PDADefinition: soltypes.PDATypeDef{ Prefix: []byte("fee_billing_token_config"), - Seeds: []codec.PDASeed{ + Seeds: []soltypes.PDASeed{ { Name: "Tokens", - Type: codec.IdlType{ - AsIdlTypeVec: &codec.IdlTypeVec{ - Vec: codec.IdlType{AsString: codec.IdlTypePublicKey}, + Type: soltypes.IdlType{ + AsIdlTypeVec: &soltypes.IdlTypeVec{ + Vec: soltypes.IdlType{AsString: soltypes.IdlTypePublicKey}, }, }, }, @@ -1439,34 +1441,34 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T MultiRead: multiReadDef, MultiReadWithParamsReuse: { ChainSpecificName: "MultiRead3", - PDADefinition: codec.PDATypeDef{ + PDADefinition: soltypes.PDATypeDef{ Prefix: []byte("multi_read_with_params3"), - Seeds: []codec.PDASeed{{Name: "ID", Type: codec.IdlType{AsString: codec.IdlTypeU64}}}, + Seeds: []soltypes.PDASeed{{Name: "ID", Type: soltypes.IdlType{AsString: soltypes.IdlTypeU64}}}, }, OutputModifications: commoncodec.ModifiersConfig{ &commoncodec.HardCodeModifierConfig{ OffChainValues: map[string]any{"U": "", "V": false}, }, }, - MultiReader: &config.MultiReader{ + MultiReader: &soltypes.MultiReader{ ReuseParams: true, - Reads: []config.ReadDefinition{ + Reads: []soltypes.ReadDefinition{ { ChainSpecificName: "MultiRead4", - PDADefinition: codec.PDATypeDef{ + PDADefinition: soltypes.PDATypeDef{ Prefix: []byte("multi_read_with_params4"), - Seeds: []codec.PDASeed{{Name: "ID", Type: codec.IdlType{AsString: codec.IdlTypeU64}}}, + Seeds: []soltypes.PDASeed{{Name: "ID", Type: soltypes.IdlType{AsString: soltypes.IdlTypeU64}}}, }, - ReadType: config.Account, + ReadType: soltypes.Account, }, }}, - ReadType: config.Account, + ReadType: soltypes.Account, }, MethodReturningUint64: uint64ReadDef, MethodReturningUint64Slice: { ChainSpecificName: "DataAccount", - ReadType: config.Account, - PDADefinition: codec.PDATypeDef{ + ReadType: soltypes.Account, + PDADefinition: soltypes.PDATypeDef{ Prefix: pdaDataPrefix, }, OutputModifications: commoncodec.ModifiersConfig{ @@ -1475,8 +1477,8 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T }, MethodSettingUint64: { ChainSpecificName: "DataAccount", - ReadType: config.Account, - PDADefinition: codec.PDATypeDef{ + ReadType: soltypes.Account, + PDADefinition: soltypes.PDATypeDef{ Prefix: pdaDataPrefix, }, OutputModifications: commoncodec.ModifiersConfig{ @@ -1485,8 +1487,8 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T }, MethodReturningSeenStruct: { ChainSpecificName: "TestStruct", - ReadType: config.Account, - PDADefinition: codec.PDATypeDef{ + ReadType: soltypes.Account, + PDADefinition: soltypes.PDATypeDef{ Prefix: pdaStructDataPrefix, }, OutputModifications: commoncodec.ModifiersConfig{ @@ -1502,14 +1504,14 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T }, MethodTakingLatestParamsReturningTestStruct: { ChainSpecificName: "TestStruct", - ReadType: config.Account, + ReadType: soltypes.Account, ErrOnMissingAccountData: true, - PDADefinition: codec.PDATypeDef{ + PDADefinition: soltypes.PDATypeDef{ Prefix: pdaStructDataPrefix, - Seeds: []codec.PDASeed{ + Seeds: []soltypes.PDASeed{ { Name: "I", // this is read from params passed in while reading the account, its analogous to ListIdx which is used while writing to chain - Type: codec.IdlType{AsString: codec.IdlTypeU64}, + Type: soltypes.IdlType{AsString: soltypes.IdlTypeU64}, }, }, }, @@ -1521,21 +1523,21 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T }, StateChangedEventName: { ChainSpecificName: "StateChangedEvent", - ReadType: config.Event, - EventDefinitions: &config.EventDefinitions{ - PollingFilter: &config.PollingFilter{ + ReadType: soltypes.Event, + EventDefinitions: &soltypes.EventDefinitions{ + PollingFilter: &soltypes.PollingFilter{ IncludeReverted: &trueVal, }, }, }, EventName: { ChainSpecificName: "SomeEvent", - ReadType: config.Event, - EventDefinitions: &config.EventDefinitions{ - PollingFilter: &config.PollingFilter{ + ReadType: soltypes.Event, + EventDefinitions: &soltypes.EventDefinitions{ + PollingFilter: &soltypes.PollingFilter{ IncludeReverted: &trueVal, }, - IndexedField0: &config.IndexedField{ + IndexedField0: &soltypes.IndexedField{ OffChainPath: "Field", OnChainPath: "Field", }, @@ -1555,10 +1557,10 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T }, AnySecondContractName: { IDL: mustUnmarshalIDL(t, string(it.Helper.GetSecondaryIDL(t))), - Reads: map[string]config.ReadDefinition{ + Reads: map[string]soltypes.ReadDefinition{ MethodReturningUint64: { ChainSpecificName: "Data", - PDADefinition: codec.PDATypeDef{ + PDADefinition: soltypes.PDATypeDef{ Prefix: pdaDataPrefix, }, OutputModifications: commoncodec.ModifiersConfig{ @@ -1567,14 +1569,14 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractReaderConfig(t T }, MethodTakingLatestParamsReturningTestStruct: { ChainSpecificName: "TestStruct", - ReadType: config.Account, + ReadType: soltypes.Account, ErrOnMissingAccountData: true, - PDADefinition: codec.PDATypeDef{ + PDADefinition: soltypes.PDATypeDef{ Prefix: pdaStructDataPrefix, - Seeds: []codec.PDASeed{ + Seeds: []soltypes.PDASeed{ { Name: "I", - Type: codec.IdlType{AsString: codec.IdlTypeU64}, + Type: soltypes.IdlType{AsString: soltypes.IdlTypeU64}, }, }, }, @@ -1603,7 +1605,7 @@ const ( GetTokenPricesPubKey2 = "47XyyAALxH7WeNT1DGWsPeA8veSVJaF8MHFMqBM5DkP6" ) -func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T) chainwriter.ChainWriterConfig { +func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T) soltypes.ContractWriterConfig { idx := it.getTestIdx(t.Name()) testIdx := binary.LittleEndian.AppendUint64([]byte{}, idx) fromAddress := solana.MustPrivateKeyFromBase58(solclient.DefaultPrivateKeysSolValidator[1]).PublicKey().String() @@ -1612,36 +1614,36 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T pubKey2, err := solana.PublicKeyFromBase58(GetTokenPricesPubKey2) require.NoError(t, err) - return chainwriter.ChainWriterConfig{ - Programs: map[string]chainwriter.ProgramConfig{ + return soltypes.ContractWriterConfig{ + Programs: map[string]soltypes.ProgramConfig{ AnyContractName: { IDL: string(it.Helper.GetPrimaryIDL(t)), - Methods: map[string]chainwriter.MethodConfig{ + Methods: map[string]soltypes.MethodConfig{ "initialize": { FromAddress: fromAddress, InputModifications: nil, ChainSpecificName: "initialize", - LookupTables: chainwriter.LookupTables{}, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + LookupTables: soltypes.LookupTables{}, + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Signer", Address: fromAddress, IsSigner: true, IsWritable: true, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "Account", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Address: primaryProgramPubKey, }}, - Seeds: []chainwriter.Seed{ + Seeds: []soltypes.Seed{ {Static: []byte("data")}, {Static: testIdx}, }, IsWritable: true, IsSigner: false, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "SystemProgram", Address: solana.SystemProgramID.String(), IsWritable: false, @@ -1654,39 +1656,39 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T FromAddress: fromAddress, InputModifications: nil, ChainSpecificName: "initializemultiread", - LookupTables: chainwriter.LookupTables{}, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + LookupTables: soltypes.LookupTables{}, + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Signer", Address: fromAddress, IsSigner: true, IsWritable: true, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "MultiRead1", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Name: "ProgramID", Address: primaryProgramPubKey, }}, - Seeds: []chainwriter.Seed{ + Seeds: []soltypes.Seed{ {Static: []byte("multi_read1")}, }, IsWritable: true, IsSigner: false, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "MultiRead2", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Name: "ProgramID", Address: primaryProgramPubKey, }}, - Seeds: []chainwriter.Seed{ + Seeds: []soltypes.Seed{ {Static: []byte("multi_read2")}, }, IsWritable: true, IsSigner: false, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "SystemProgram", Address: solana.SystemProgramID.String(), IsWritable: false, @@ -1699,41 +1701,41 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T FromAddress: fromAddress, InputModifications: nil, ChainSpecificName: "initializemultireadwithparams", - LookupTables: chainwriter.LookupTables{}, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + LookupTables: soltypes.LookupTables{}, + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Signer", Address: fromAddress, IsSigner: true, IsWritable: true, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "MultiRead3", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Name: "ProgramID", Address: primaryProgramPubKey, }}, - Seeds: []chainwriter.Seed{ + Seeds: []soltypes.Seed{ {Static: []byte("multi_read_with_params3")}, {Static: binary.LittleEndian.AppendUint64([]byte{}, 1)}, }, IsWritable: true, IsSigner: false, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "MultiRead4", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Name: "ProgramID", Address: primaryProgramPubKey, }}, - Seeds: []chainwriter.Seed{ + Seeds: []soltypes.Seed{ {Static: []byte("multi_read_with_params4")}, {Static: binary.LittleEndian.AppendUint64([]byte{}, 1)}, }, IsWritable: true, IsSigner: false, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "SystemProgram", Address: solana.SystemProgramID.String(), IsWritable: false, @@ -1746,41 +1748,41 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T FromAddress: fromAddress, InputModifications: nil, ChainSpecificName: "initializetokenprices", - LookupTables: chainwriter.LookupTables{}, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + LookupTables: soltypes.LookupTables{}, + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Signer", Address: fromAddress, IsSigner: true, IsWritable: true, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "BillingTokenConfigWrapper1", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Name: "ProgramID", Address: primaryProgramPubKey, }}, - Seeds: []chainwriter.Seed{ + Seeds: []soltypes.Seed{ {Static: []byte("fee_billing_token_config")}, {Static: pubKey1.Bytes()}, }, IsWritable: true, IsSigner: false, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "BillingTokenConfigWrapper2", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Name: "ProgramID", Address: primaryProgramPubKey, }}, - Seeds: []chainwriter.Seed{ + Seeds: []soltypes.Seed{ {Static: []byte("fee_billing_token_config")}, {Static: pubKey2.Bytes()}, }, IsWritable: true, IsSigner: false, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "SystemProgram", Address: solana.SystemProgramID.String(), IsWritable: false, @@ -1793,26 +1795,26 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T FromAddress: fromAddress, InputModifications: nil, ChainSpecificName: "initializelookuptable", - LookupTables: chainwriter.LookupTables{}, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + LookupTables: soltypes.LookupTables{}, + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Signer", Address: fromAddress, IsSigner: true, IsWritable: true, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "Account", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Address: primaryProgramPubKey, }}, - Seeds: []chainwriter.Seed{ + Seeds: []soltypes.Seed{ {Static: []byte("lookup")}, }, IsWritable: true, IsSigner: false, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "SystemProgram", Address: solana.SystemProgramID.String(), IsWritable: false, @@ -1825,19 +1827,19 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T FromAddress: fromAddress, InputModifications: nil, ChainSpecificName: "storeval", - LookupTables: chainwriter.LookupTables{ - DerivedLookupTables: []chainwriter.DerivedLookupTable{ + LookupTables: soltypes.LookupTables{ + DerivedLookupTables: []soltypes.DerivedLookupTable{ { Name: "LookupTable", - Accounts: chainwriter.Lookup{PDALookups: &chainwriter.PDALookups{ + Accounts: soltypes.Lookup{PDALookups: &soltypes.PDALookups{ Name: "LookupTableAccount", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Address: primaryProgramPubKey, }}, - Seeds: []chainwriter.Seed{ + Seeds: []soltypes.Seed{ {Static: []byte("lookup")}, }, - InternalField: chainwriter.InternalField{ + InternalField: soltypes.InternalField{ TypeName: "LookupTableDataAccount", Location: "LookupTable", IDL: string(it.Helper.GetPrimaryIDL(t)), @@ -1846,26 +1848,26 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T }, }, }, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Signer", Address: fromAddress, IsSigner: true, IsWritable: true, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "Account", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Address: primaryProgramPubKey, }}, - Seeds: []chainwriter.Seed{ + Seeds: []soltypes.Seed{ {Static: []byte("data")}, {Static: testIdx}, }, IsWritable: true, IsSigner: false, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "SystemProgram", Address: solana.SystemProgramID.String(), IsWritable: false, @@ -1877,39 +1879,39 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T "storeTokenAccount": { FromAddress: fromAddress, ChainSpecificName: "storeTokenAccount", - ATAs: []chainwriter.ATALookup{ + ATAs: []soltypes.ATALookup{ { Location: "ATAInfo.Receiver", - WalletAddress: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Location: "ATAInfo.Wallet"}}, - TokenProgram: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Location: "ATAInfo.TokenProgram"}}, - MintAddress: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Location: "ATAInfo.Mint"}}, + WalletAddress: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Location: "ATAInfo.Wallet"}}, + TokenProgram: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Location: "ATAInfo.TokenProgram"}}, + MintAddress: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Location: "ATAInfo.Mint"}}, }, }, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Signer", Address: fromAddress, IsSigner: true, IsWritable: true, }}, - {AccountLookup: &chainwriter.AccountLookup{ + {AccountLookup: &soltypes.AccountLookup{ Location: "TokenAccount", - IsWritable: chainwriter.MetaBool{Value: true}, - IsSigner: chainwriter.MetaBool{Value: false}, + IsWritable: soltypes.MetaBool{Value: true}, + IsSigner: soltypes.MetaBool{Value: false}, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "Account", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Address: primaryProgramPubKey, }}, - Seeds: []chainwriter.Seed{ + Seeds: []soltypes.Seed{ {Static: []byte("token_account")}, {Static: testIdx}, }, IsWritable: true, IsSigner: false, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "SystemProgram", Address: solana.SystemProgramID.String(), IsWritable: false, @@ -1931,25 +1933,25 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T }, }, ChainSpecificName: "store", - LookupTables: chainwriter.LookupTables{}, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + LookupTables: soltypes.LookupTables{}, + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Signer", Address: fromAddress, IsSigner: true, IsWritable: true, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "Account", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Name: "ProgramID", Address: primaryProgramPubKey, }}, - Seeds: []chainwriter.Seed{ + Seeds: []soltypes.Seed{ {Static: []byte("struct_data")}, {Static: testIdx}, - {Dynamic: chainwriter.Lookup{ - AccountLookup: &chainwriter.AccountLookup{ + {Dynamic: soltypes.Lookup{ + AccountLookup: &soltypes.AccountLookup{ Location: "ListIdx", // this will be sent as input params while writing to chain, see StoreTestStruct }, }}, @@ -1957,7 +1959,7 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T IsWritable: true, IsSigner: false, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "SystemProgram", Address: solana.SystemProgramID.String(), IsWritable: false, @@ -1969,15 +1971,15 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T MethodTriggeringEventBeforeFailing: { FromAddress: fromAddress, ChainSpecificName: "createEventAndFail", - LookupTables: chainwriter.LookupTables{}, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + LookupTables: soltypes.LookupTables{}, + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Signer", Address: fromAddress, IsSigner: true, IsWritable: true, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "SystemProgram", Address: solana.SystemProgramID.String(), IsWritable: false, @@ -1994,15 +1996,15 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T Fields: []string{"Data.AccountStruct.AccountStr"}, }, }, - LookupTables: chainwriter.LookupTables{}, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + LookupTables: soltypes.LookupTables{}, + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Signer", Address: fromAddress, IsSigner: true, IsWritable: true, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "SystemProgram", Address: solana.SystemProgramID.String(), IsWritable: false, @@ -2015,35 +2017,35 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T }, AnySecondContractName: { IDL: string(it.Helper.GetSecondaryIDL(t)), - Methods: map[string]chainwriter.MethodConfig{ + Methods: map[string]soltypes.MethodConfig{ "initialize": { FromAddress: fromAddress, InputModifications: nil, ChainSpecificName: "initialize", - LookupTables: chainwriter.LookupTables{}, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + LookupTables: soltypes.LookupTables{}, + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Signer", Address: fromAddress, IsSigner: true, IsWritable: true, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "Account", - PublicKey: chainwriter.Lookup{ - AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{ + AccountConstant: &soltypes.AccountConstant{ Name: "ProgramID", Address: secondaryProgramPubKey, // line ~1338 }, // line ~1339 closes AccountConstant - }, // line ~1340 closes chainwriter.Lookup - Seeds: []chainwriter.Seed{ + }, // line ~1340 closes soltypes.Lookup + Seeds: []soltypes.Seed{ {Static: []byte("data")}, {Static: testIdx}, }, IsWritable: true, IsSigner: false, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "SystemAccount", Address: solana.SystemProgramID.String(), IsWritable: false, @@ -2065,25 +2067,25 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T }, }, ChainSpecificName: "store", - LookupTables: chainwriter.LookupTables{}, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + LookupTables: soltypes.LookupTables{}, + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Signer", Address: fromAddress, IsSigner: true, IsWritable: true, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "Account", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Name: "ProgramID", Address: secondaryProgramPubKey, }}, - Seeds: []chainwriter.Seed{ + Seeds: []soltypes.Seed{ {Static: []byte("struct_data")}, {Static: testIdx}, - {Dynamic: chainwriter.Lookup{ - AccountLookup: &chainwriter.AccountLookup{ + {Dynamic: soltypes.Lookup{ + AccountLookup: &soltypes.AccountLookup{ Location: "ListIdx", }, }}, @@ -2091,7 +2093,7 @@ func (it *SolanaChainComponentsInterfaceTester[T]) buildContractWriterConfig(t T IsWritable: true, IsSigner: false, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "SystemProgram", Address: solana.SystemProgramID.String(), IsWritable: false, diff --git a/integration-tests/relayinterface/lookups_test.go b/integration-tests/relayinterface/lookups_test.go index e4f8fdcfb..6836bf8d8 100644 --- a/integration-tests/relayinterface/lookups_test.go +++ b/integration-tests/relayinterface/lookups_test.go @@ -14,6 +14,7 @@ import ( "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/tokens" "github.com/smartcontractkit/chainlink-common/pkg/logger" ccipocr3common "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" + soltypes "github.com/smartcontractkit/chainlink-common/pkg/types/solana" "github.com/smartcontractkit/chainlink-solana/integration-tests/utils" "github.com/smartcontractkit/chainlink-solana/pkg/solana/chainwriter" @@ -38,11 +39,11 @@ var testContractIDL = chainwriter.FetchTestContractIDL() func TestLookup(t *testing.T) { t.Run("Resolve fails on a lookup with multiple lookup types", func(t *testing.T) { lookupConfig := chainwriter.Lookup{ - AccountConstant: &chainwriter.AccountConstant{ + AccountConstant: &soltypes.AccountConstant{ Name: "TestAccount", Address: "test", }, - AccountLookup: &chainwriter.AccountLookup{ + AccountLookup: &soltypes.AccountLookup{ Name: "TestAccount", Location: "test", }, @@ -62,13 +63,13 @@ func TestAccountContant(t *testing.T) { IsWritable: true, }, } - constantConfig := chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + constantConfig := chainwriter.Lookup{AccountConstant: &soltypes.AccountConstant{ Name: "TestAccount", Address: expectedAddr.String(), IsSigner: true, IsWritable: true, }} - result, err := constantConfig.AccountConstant.Resolve() + result, err := chainwriter.ResolveAccountConstant(constantConfig.AccountConstant) require.NoError(t, err) require.Equal(t, expectedMeta, result) }) @@ -89,13 +90,13 @@ func TestAccountLookups(t *testing.T) { }, } - lookupConfig := chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + lookupConfig := chainwriter.Lookup{AccountLookup: &soltypes.AccountLookup{ Name: "TestAccount", Location: "Inner.Address", - IsSigner: chainwriter.MetaBool{Value: true}, - IsWritable: chainwriter.MetaBool{Value: true}, + IsSigner: soltypes.MetaBool{Value: true}, + IsWritable: soltypes.MetaBool{Value: true}, }} - result, err := lookupConfig.AccountLookup.Resolve(testArgs) + result, err := chainwriter.ResolveAccountLookup(lookupConfig.AccountLookup, testArgs) require.NoError(t, err) require.Equal(t, expectedMeta, result) }) @@ -123,13 +124,13 @@ func TestAccountLookups(t *testing.T) { }, } - lookupConfig := chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + lookupConfig := chainwriter.Lookup{AccountLookup: &soltypes.AccountLookup{ Name: "TestAccount", Location: "Inner.Address", - IsSigner: chainwriter.MetaBool{Value: true}, - IsWritable: chainwriter.MetaBool{Value: true}, + IsSigner: soltypes.MetaBool{Value: true}, + IsWritable: soltypes.MetaBool{Value: true}, }} - result, err := lookupConfig.AccountLookup.Resolve(testArgs) + result, err := chainwriter.ResolveAccountLookup(lookupConfig.AccountLookup, testArgs) require.NoError(t, err) for i, meta := range result { require.Equal(t, expectedMeta[i], meta) @@ -144,13 +145,13 @@ func TestAccountLookups(t *testing.T) { {Address: expectedAddr.Bytes()}, }, } - lookupConfig := chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + lookupConfig := chainwriter.Lookup{AccountLookup: &soltypes.AccountLookup{ Name: "InvalidAccount", Location: "Invalid.Directory", - IsSigner: chainwriter.MetaBool{Value: true}, - IsWritable: chainwriter.MetaBool{Value: true}, + IsSigner: soltypes.MetaBool{Value: true}, + IsWritable: soltypes.MetaBool{Value: true}, }} - _, err := lookupConfig.AccountLookup.Resolve(testArgs) + _, err := chainwriter.ResolveAccountLookup(lookupConfig.AccountLookup, testArgs) require.ErrorIs(t, err, chainwriter.ErrLookupNotFoundAtLocation) }) @@ -165,11 +166,11 @@ func TestAccountLookups(t *testing.T) { } } - lookupConfig := chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + lookupConfig := chainwriter.Lookup{AccountLookup: &soltypes.AccountLookup{ Name: "TestAccount", Location: "Inner.Accounts.PublicKey", - IsSigner: chainwriter.MetaBool{BitmapLocation: "Inner.Bitmap"}, - IsWritable: chainwriter.MetaBool{BitmapLocation: "Inner.Bitmap"}, + IsSigner: soltypes.MetaBool{BitmapLocation: "Inner.Bitmap"}, + IsWritable: soltypes.MetaBool{BitmapLocation: "Inner.Bitmap"}, }} args := TestAccountArgs{ @@ -180,7 +181,7 @@ func TestAccountLookups(t *testing.T) { }, } - result, err := lookupConfig.AccountLookup.Resolve(args) + result, err := chainwriter.ResolveAccountLookup(lookupConfig.AccountLookup, args) require.NoError(t, err) for i, meta := range result { @@ -204,11 +205,11 @@ func TestAccountLookups(t *testing.T) { } } - lookupConfig := chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + lookupConfig := chainwriter.Lookup{AccountLookup: &soltypes.AccountLookup{ Name: "InvalidAccount", Location: "Inner.Accounts.PublicKey", - IsSigner: chainwriter.MetaBool{BitmapLocation: "Bitmaps"}, - IsWritable: chainwriter.MetaBool{BitmapLocation: "Bitmaps"}, + IsSigner: soltypes.MetaBool{BitmapLocation: "Bitmaps"}, + IsWritable: soltypes.MetaBool{BitmapLocation: "Bitmaps"}, }} args := TestAccountArgsExtended{ @@ -218,7 +219,7 @@ func TestAccountLookups(t *testing.T) { Bitmaps: []uint64{5, 3}, } - _, err := lookupConfig.AccountLookup.Resolve(args) + _, err := chainwriter.ResolveAccountLookup(lookupConfig.AccountLookup, args) require.Contains(t, err.Error(), "bitmap value is not a single value") }) @@ -232,11 +233,11 @@ func TestAccountLookups(t *testing.T) { } } - lookupConfig := chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + lookupConfig := chainwriter.Lookup{AccountLookup: &soltypes.AccountLookup{ Name: "InvalidAccount", Location: "Inner.Accounts.PublicKey", - IsSigner: chainwriter.MetaBool{BitmapLocation: "Invalid.Bitmap"}, - IsWritable: chainwriter.MetaBool{BitmapLocation: "Invalid.Bitmap"}, + IsSigner: soltypes.MetaBool{BitmapLocation: "Invalid.Bitmap"}, + IsWritable: soltypes.MetaBool{BitmapLocation: "Invalid.Bitmap"}, }} args := TestAccountArgs{ @@ -245,7 +246,7 @@ func TestAccountLookups(t *testing.T) { }, } - _, err := lookupConfig.AccountLookup.Resolve(args) + _, err := chainwriter.ResolveAccountLookup(lookupConfig.AccountLookup, args) require.Contains(t, err.Error(), "error reading bitmap from location") }) @@ -259,11 +260,11 @@ func TestAccountLookups(t *testing.T) { } } - lookupConfig := chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + lookupConfig := chainwriter.Lookup{AccountLookup: &soltypes.AccountLookup{ Name: "InvalidAccount", Location: "Inner.Accounts.PublicKey", - IsSigner: chainwriter.MetaBool{BitmapLocation: "Inner"}, - IsWritable: chainwriter.MetaBool{BitmapLocation: "Inner"}, + IsSigner: soltypes.MetaBool{BitmapLocation: "Inner"}, + IsWritable: soltypes.MetaBool{BitmapLocation: "Inner"}, }} args := TestAccountArgs{ @@ -272,7 +273,7 @@ func TestAccountLookups(t *testing.T) { }, } - _, err := lookupConfig.AccountLookup.Resolve(args) + _, err := chainwriter.ResolveAccountLookup(lookupConfig.AccountLookup, args) require.Contains(t, err.Error(), "invalid value format at path") }) @@ -286,18 +287,18 @@ func TestAccountLookups(t *testing.T) { } } - lookupConfig := chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + lookupConfig := chainwriter.Lookup{AccountLookup: &soltypes.AccountLookup{ Name: "TestAccount", Location: "Inner.Accounts.PublicKey", - IsSigner: chainwriter.MetaBool{Value: true}, - IsWritable: chainwriter.MetaBool{Value: true}, + IsSigner: soltypes.MetaBool{Value: true}, + IsWritable: soltypes.MetaBool{Value: true}, }} args := TestAccountArgs{ Inner: InnerAccountArgs{ Accounts: accounts[:], }, } - _, err := lookupConfig.AccountLookup.Resolve(args) + _, err := chainwriter.ResolveAccountLookup(lookupConfig.AccountLookup, args) require.Error(t, err) }) @@ -312,11 +313,11 @@ func TestAccountLookups(t *testing.T) { } } - lookupConfig := chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + lookupConfig := chainwriter.Lookup{AccountLookup: &soltypes.AccountLookup{ Name: "TestAccount", Location: "Accounts.PublicKey", - IsSigner: chainwriter.MetaBool{BitmapLocation: "Bitmap"}, - IsWritable: chainwriter.MetaBool{BitmapLocation: "Bitmap"}, + IsSigner: soltypes.MetaBool{BitmapLocation: "Bitmap"}, + IsWritable: soltypes.MetaBool{BitmapLocation: "Bitmap"}, }} args := struct { @@ -327,7 +328,7 @@ func TestAccountLookups(t *testing.T) { Bitmap: make([]byte, 3), // invalid bitmap length } - _, err := lookupConfig.AccountLookup.Resolve(args) + _, err := chainwriter.ResolveAccountLookup(lookupConfig.AccountLookup, args) require.Error(t, err) }) } @@ -350,11 +351,11 @@ func TestPDALookups(t *testing.T) { }, } - pdaLookup := chainwriter.Lookup{PDALookups: &chainwriter.PDALookups{ + pdaLookup := chainwriter.Lookup{PDALookups: &soltypes.PDALookups{ Name: "TestPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "ProgramID", Address: programID.String()}}, - Seeds: []chainwriter.Seed{ - {Dynamic: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "seed", Address: seed.String()}}}, + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "ProgramID", Address: programID.String()}}, + Seeds: []soltypes.Seed{ + {Dynamic: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "seed", Address: seed.String()}}}, }, IsSigner: false, IsWritable: true, @@ -385,14 +386,14 @@ func TestPDALookups(t *testing.T) { }, } - pdaLookup := chainwriter.Lookup{PDALookups: &chainwriter.PDALookups{ + pdaLookup := chainwriter.Lookup{PDALookups: &soltypes.PDALookups{ Name: "TestPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "ProgramID", Address: programID.String()}}, - Seeds: []chainwriter.Seed{ - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "seed1", Location: "test_seed"}}}, - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "seed2", Location: "another_seed"}}}, - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "seed3", Location: "ccip_chain_selector"}}}, - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "seed4", Location: "ccip_bytes"}}}, + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "ProgramID", Address: programID.String()}}, + Seeds: []soltypes.Seed{ + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "seed1", Location: "test_seed"}}}, + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "seed2", Location: "another_seed"}}}, + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "seed3", Location: "ccip_chain_selector"}}}, + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "seed4", Location: "ccip_bytes"}}}, }, IsSigner: false, IsWritable: true, @@ -411,11 +412,11 @@ func TestPDALookups(t *testing.T) { }) t.Run("PDALookup fails with missing seeds", func(t *testing.T) { - pdaLookup := chainwriter.Lookup{PDALookups: &chainwriter.PDALookups{ + pdaLookup := chainwriter.Lookup{PDALookups: &soltypes.PDALookups{ Name: "TestPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "ProgramID", Address: programID.String()}}, - Seeds: []chainwriter.Seed{ - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "seed1", Location: "MissingSeed"}}}, + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "ProgramID", Address: programID.String()}}, + Seeds: []soltypes.Seed{ + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "seed1", Location: "MissingSeed"}}}, }, IsSigner: false, IsWritable: true, @@ -446,13 +447,13 @@ func TestPDALookups(t *testing.T) { }, } - pdaLookup := chainwriter.Lookup{PDALookups: &chainwriter.PDALookups{ + pdaLookup := chainwriter.Lookup{PDALookups: &soltypes.PDALookups{ Name: "TestPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "ProgramID", Address: programID.String()}}, - Seeds: []chainwriter.Seed{ - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "seed1", Location: "test_seed"}}}, - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "seed2", Location: "another_seed"}}}, - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "seed3", Location: "unknown_encoded_address"}}}, + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "ProgramID", Address: programID.String()}}, + Seeds: []soltypes.Seed{ + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "seed1", Location: "test_seed"}}}, + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "seed2", Location: "another_seed"}}}, + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "seed3", Location: "unknown_encoded_address"}}}, }, IsSigner: false, IsWritable: true, @@ -486,12 +487,12 @@ func TestPDALookups(t *testing.T) { expectedMeta = append(expectedMeta, meta) } - pdaLookup := chainwriter.Lookup{PDALookups: &chainwriter.PDALookups{ + pdaLookup := chainwriter.Lookup{PDALookups: &soltypes.PDALookups{ Name: "TestPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "ProgramID", Address: programID.String()}}, - Seeds: []chainwriter.Seed{ - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "seed1", Location: "single_seed"}}}, - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "seed2", Location: "array_seed"}}}, + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "ProgramID", Address: programID.String()}}, + Seeds: []soltypes.Seed{ + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "seed1", Location: "single_seed"}}}, + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "seed2", Location: "array_seed"}}}, }, IsSigner: false, IsWritable: false, @@ -526,12 +527,12 @@ func TestPDALookups(t *testing.T) { } } - pdaLookup := chainwriter.Lookup{PDALookups: &chainwriter.PDALookups{ + pdaLookup := chainwriter.Lookup{PDALookups: &soltypes.PDALookups{ Name: "TestPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "ProgramID", Address: programID.String()}}, - Seeds: []chainwriter.Seed{ - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "seed1", Location: "seed1"}}}, - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "seed2", Location: "seed2"}}}, + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "ProgramID", Address: programID.String()}}, + Seeds: []soltypes.Seed{ + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "seed1", Location: "seed1"}}}, + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "seed2", Location: "seed2"}}}, }, IsSigner: false, IsWritable: false, @@ -573,15 +574,15 @@ func TestLookupTables(t *testing.T) { txm := txm.NewTxm("localnet", loader, nil, cfg, mkey, lggr) - cw, err := chainwriter.NewSolanaChainWriterService(logger.Test(t), multiClient, txm, nil, chainwriter.ChainWriterConfig{}) + cw, err := chainwriter.NewSolanaChainWriterService(logger.Test(t), multiClient, txm, nil, soltypes.ContractWriterConfig{}) require.NoError(t, err) t.Run("StaticLookup table resolves properly", func(t *testing.T) { pubKeys := CreateTestPubKeys(t, 8) table := utils.CreateTestLookupTable(t, rpcClient, sender, pubKeys) - lookupConfig := chainwriter.LookupTables{ + lookupConfig := soltypes.LookupTables{ DerivedLookupTables: nil, - StaticLookupTables: []solana.PublicKey{table}, + StaticLookupTables: [][32]byte{table}, } _, staticTableMap, resolveErr := cw.ResolveLookupTables(ctx, nil, lookupConfig) require.NoError(t, resolveErr) @@ -590,11 +591,11 @@ func TestLookupTables(t *testing.T) { t.Run("Derived lookup table resolves properly with constant address", func(t *testing.T) { pubKeys := CreateTestPubKeys(t, 8) table := utils.CreateTestLookupTable(t, rpcClient, sender, pubKeys) - lookupConfig := chainwriter.LookupTables{ - DerivedLookupTables: []chainwriter.DerivedLookupTable{ + lookupConfig := soltypes.LookupTables{ + DerivedLookupTables: []soltypes.DerivedLookupTable{ { Name: "DerivedTable", - Accounts: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + Accounts: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Name: "TestLookupTable", Address: table.String(), IsSigner: true, @@ -617,11 +618,11 @@ func TestLookupTables(t *testing.T) { t.Run("Derived lookup table fails with invalid address", func(t *testing.T) { invalidTable := GetRandomPubKey(t) - lookupConfig := chainwriter.LookupTables{ - DerivedLookupTables: []chainwriter.DerivedLookupTable{ + lookupConfig := soltypes.LookupTables{ + DerivedLookupTables: []soltypes.DerivedLookupTable{ { Name: "DerivedTable", - Accounts: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + Accounts: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Name: "InvalidTable", Address: invalidTable.String(), IsSigner: true, @@ -643,7 +644,7 @@ func TestLookupTables(t *testing.T) { "DerivedTable": {}, } accountsFromLookupTable := chainwriter.Lookup{ - AccountsFromLookupTable: &chainwriter.AccountsFromLookupTable{ + AccountsFromLookupTable: &soltypes.AccountsFromLookupTable{ LookupTableName: "InvalidTable", IncludeIndexes: []int{}, }, @@ -656,9 +657,9 @@ func TestLookupTables(t *testing.T) { t.Run("Static lookup table fails with invalid address", func(t *testing.T) { invalidTable := GetRandomPubKey(t) - lookupConfig := chainwriter.LookupTables{ + lookupConfig := soltypes.LookupTables{ DerivedLookupTables: nil, - StaticLookupTables: []solana.PublicKey{invalidTable}, + StaticLookupTables: [][32]byte{invalidTable}, } _, _, err = cw.ResolveLookupTables(ctx, nil, lookupConfig) @@ -669,14 +670,14 @@ func TestLookupTables(t *testing.T) { t.Run("Derived lookup table resolves properly with account lookup address", func(t *testing.T) { pubKeys := CreateTestPubKeys(t, 8) table := utils.CreateTestLookupTable(t, rpcClient, sender, pubKeys) - lookupConfig := chainwriter.LookupTables{ - DerivedLookupTables: []chainwriter.DerivedLookupTable{ + lookupConfig := soltypes.LookupTables{ + DerivedLookupTables: []soltypes.DerivedLookupTable{ { Name: "DerivedTable", - Accounts: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + Accounts: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{ Name: "TestLookupTable", Location: "Inner.Address", - IsSigner: chainwriter.MetaBool{Value: true}, + IsSigner: soltypes.MetaBool{Value: true}, }}, }, }, @@ -693,7 +694,7 @@ func TestLookupTables(t *testing.T) { require.NoError(t, err) accountsFromLookupTable := chainwriter.Lookup{ - AccountsFromLookupTable: &chainwriter.AccountsFromLookupTable{ + AccountsFromLookupTable: &soltypes.AccountsFromLookupTable{ LookupTableName: "DerivedTable", IncludeIndexes: []int{}, }, @@ -719,19 +720,19 @@ func TestLookupTables(t *testing.T) { "seed1": []byte("lookup"), } - lookupConfig := chainwriter.LookupTables{ - DerivedLookupTables: []chainwriter.DerivedLookupTable{ + lookupConfig := soltypes.LookupTables{ + DerivedLookupTables: []soltypes.DerivedLookupTable{ { Name: "DerivedTable", - Accounts: chainwriter.Lookup{PDALookups: &chainwriter.PDALookups{ + Accounts: soltypes.Lookup{PDALookups: &soltypes.PDALookups{ Name: "DataAccountPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "WriteTest", Address: programID.String()}}, - Seeds: []chainwriter.Seed{ - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "seed1", Location: "seed1"}}}, + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "WriteTest", Address: programID.String()}}, + Seeds: []soltypes.Seed{ + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "seed1", Location: "seed1"}}}, }, IsSigner: false, IsWritable: false, - InternalField: chainwriter.InternalField{ + InternalField: soltypes.InternalField{ TypeName: "LookupTableDataAccount", Location: "LookupTable", IDL: testContractIDL, @@ -746,7 +747,7 @@ func TestLookupTables(t *testing.T) { require.NoError(t, err) accountsFromLookupTable := chainwriter.Lookup{ - AccountsFromLookupTable: &chainwriter.AccountsFromLookupTable{ + AccountsFromLookupTable: &soltypes.AccountsFromLookupTable{ LookupTableName: "DerivedTable", IncludeIndexes: []int{}, }, @@ -767,19 +768,19 @@ func TestLookupTables(t *testing.T) { "seed1": []byte("lookup"), } - lookupConfig := chainwriter.LookupTables{ - DerivedLookupTables: []chainwriter.DerivedLookupTable{ + lookupConfig := soltypes.LookupTables{ + DerivedLookupTables: []soltypes.DerivedLookupTable{ { Name: "DerivedTable", - Accounts: chainwriter.Lookup{PDALookups: &chainwriter.PDALookups{ + Accounts: soltypes.Lookup{PDALookups: &soltypes.PDALookups{ Name: "DataAccountPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "WriteTest", Address: programID.String()}}, - Seeds: []chainwriter.Seed{ - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "missing_seed", Location: "missing_seed"}}}, + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "WriteTest", Address: programID.String()}}, + Seeds: []soltypes.Seed{ + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "missing_seed", Location: "missing_seed"}}}, }, IsSigner: false, IsWritable: false, - InternalField: chainwriter.InternalField{ + InternalField: soltypes.InternalField{ TypeName: "LookupTableDataAccount", Location: "LookupTable", IDL: testContractIDL, @@ -793,13 +794,13 @@ func TestLookupTables(t *testing.T) { derivedTableMap, _, err := cw.ResolveLookupTables(ctx, args, lookupConfig) require.NoError(t, err) - pdaWithAccountLookupSeed := chainwriter.Lookup{ - PDALookups: &chainwriter.PDALookups{ - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Address: GetRandomPubKey(t).String()}}, - Seeds: []chainwriter.Seed{ + pdaWithAccountLookupSeed := soltypes.Lookup{ + PDALookups: &soltypes.PDALookups{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Address: GetRandomPubKey(t).String()}}, + Seeds: []soltypes.Seed{ { - Dynamic: chainwriter.Lookup{ - AccountsFromLookupTable: &chainwriter.AccountsFromLookupTable{ + Dynamic: soltypes.Lookup{ + AccountsFromLookupTable: &soltypes.AccountsFromLookupTable{ LookupTableName: "DerivedTable", IncludeIndexes: []int{}, }, @@ -810,7 +811,7 @@ func TestLookupTables(t *testing.T) { Optional: true, } - accounts, err := chainwriter.GetAddresses(ctx, nil, []chainwriter.Lookup{pdaWithAccountLookupSeed}, derivedTableMap, multiClient) + accounts, err := chainwriter.GetAddresses(ctx, nil, []soltypes.Lookup{pdaWithAccountLookupSeed}, derivedTableMap, multiClient) require.NoError(t, err) require.Empty(t, accounts) }) @@ -904,13 +905,13 @@ func TestCreateATAs(t *testing.T) { t.Run("returns no instructions when no ATA location is found", func(t *testing.T) { user := GetRandomPubKey(t) - lookups := []chainwriter.ATALookup{ + lookups := []soltypes.ATALookup{ { Location: "Invalid.Address", - WalletAddress: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + WalletAddress: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Address: user.String(), }}, - MintAddress: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + MintAddress: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{ Location: "Invalid.Address", }}, }, @@ -928,13 +929,13 @@ func TestCreateATAs(t *testing.T) { }) t.Run("fails with multiple wallet addresses", func(t *testing.T) { - lookups := []chainwriter.ATALookup{ + lookups := []soltypes.ATALookup{ { Location: "", - WalletAddress: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + WalletAddress: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{ Location: "Addresses", }}, - MintAddress: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + MintAddress: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Address: mint1.String(), }}, }, @@ -953,13 +954,13 @@ func TestCreateATAs(t *testing.T) { ataAddress, _, err := tokens.FindAssociatedTokenAddress(tokenProgram, mint1, user) require.NoError(t, err) require.False(t, checkIfATAExists(t, rpcClient, ataAddress)) - lookups := []chainwriter.ATALookup{ + lookups := []soltypes.ATALookup{ { Location: "Inner.Address", - WalletAddress: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + WalletAddress: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Address: user.String(), }}, - MintAddress: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + MintAddress: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{ Location: "Inner.Address", }}, }, @@ -980,13 +981,13 @@ func TestCreateATAs(t *testing.T) { ataAddress, _, err := tokens.FindAssociatedTokenAddress(tokenProgram, mint1, user) require.NoError(t, err) require.False(t, checkIfATAExists(t, rpcClient, ataAddress)) - lookups := []chainwriter.ATALookup{ + lookups := []soltypes.ATALookup{ { Location: "Inner.Address", - WalletAddress: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + WalletAddress: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Address: user.String(), }}, - MintAddress: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + MintAddress: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{ Location: "Inner.Address", }}, }, @@ -1022,13 +1023,13 @@ func TestCreateATAs(t *testing.T) { ataAddresses = append(ataAddresses, ataAddress) } - lookups := []chainwriter.ATALookup{ + lookups := []soltypes.ATALookup{ { Location: "Inner.Address", - WalletAddress: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + WalletAddress: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Address: user.String(), }}, - MintAddress: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + MintAddress: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{ Location: "Inner.Address", }}, }, @@ -1061,13 +1062,13 @@ func TestCreateATAs(t *testing.T) { t.Run("optional ATA creation does not return error if lookups fail", func(t *testing.T) { user := GetRandomPubKey(t) - lookups := []chainwriter.ATALookup{ + lookups := []soltypes.ATALookup{ { Location: "Inner.Address", - WalletAddress: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + WalletAddress: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Address: user.String(), }}, - MintAddress: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + MintAddress: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{ Location: "Inner.BadLocation", }}, Optional: true, diff --git a/pkg/solana/chainreader/chain_reader.go b/pkg/solana/chainreader/chain_reader.go index 790d0b662..bad0c25dc 100644 --- a/pkg/solana/chainreader/chain_reader.go +++ b/pkg/solana/chainreader/chain_reader.go @@ -16,6 +16,7 @@ import ( "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/v0_1_1/fee_quoter" ccipconsts "github.com/smartcontractkit/chainlink-ccip/pkg/consts" + soltypes "github.com/smartcontractkit/chainlink-common/pkg/types/solana" commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec" "github.com/smartcontractkit/chainlink-common/pkg/logger" @@ -585,7 +586,7 @@ func (s *ContractReaderService) addAddressResponseHardCoderModifier(namespace st } func (s *ContractReaderService) addEventRead( - common *config.PollingFilter, + common *soltypes.PollingFilter, namespace, genericName string, idl codec.IDL, readDefinition config.ReadDefinition, @@ -921,10 +922,14 @@ func (s *ContractReaderService) getPDAsForGetTokenPrices(params any, values read return pdaAddresses, nil } -func setPollingFilterOverrides(common *config.PollingFilter, overrides ...*config.PollingFilter) (config.PollingFilter, error) { - final := reflect.New(reflect.TypeOf(common).Elem()) - valOfF := final.Elem() - allOverrides := append([]*config.PollingFilter{common}, overrides...) +func setPollingFilterOverrides(common *soltypes.PollingFilter, overrides ...*soltypes.PollingFilter) (config.PollingFilter, error) { + allOverrides := make([]*config.PollingFilter, len(overrides)+1) + allOverrides[0] = (*config.PollingFilter)(common) + for i, o := range overrides { + allOverrides[i+1] = (*config.PollingFilter)(o) + } + + valOfF := reflect.New(reflect.TypeOf(allOverrides[0]).Elem()).Elem() for _, override := range allOverrides { if override == nil { @@ -949,9 +954,9 @@ func setPollingFilterOverrides(common *config.PollingFilter, overrides ...*confi } } - filter, ok := final.Elem().Interface().(config.PollingFilter) + filter, ok := valOfF.Interface().(config.PollingFilter) if !ok { - return config.PollingFilter{}, fmt.Errorf("encountered unexpected type: %T, expected: %T", final.Elem().Interface(), config.PollingFilter{}) + return config.PollingFilter{}, fmt.Errorf("encountered unexpected type: %T, expected: %T", valOfF.Interface(), config.PollingFilter{}) } return filter, nil diff --git a/pkg/solana/chainreader/chain_reader_test.go b/pkg/solana/chainreader/chain_reader_test.go index 5c13b1ae6..b64de7c90 100644 --- a/pkg/solana/chainreader/chain_reader_test.go +++ b/pkg/solana/chainreader/chain_reader_test.go @@ -22,6 +22,7 @@ import ( "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink-common/pkg/sqlutil/sqltest" + soltypes "github.com/smartcontractkit/chainlink-common/pkg/types/solana" "github.com/smartcontractkit/libocr/commontypes" @@ -122,7 +123,7 @@ func TestSolanaChainReaderService_Start(t *testing.T) { OffChainPath: "A.B", OnChainPath: "A.B", }, - PollingFilter: &config.PollingFilter{}, + PollingFilter: &soltypes.PollingFilter{}, }, } diff --git a/pkg/solana/chainwriter/ata_creation.go b/pkg/solana/chainwriter/ata_creation.go index 0f9221ea9..2eac2a511 100644 --- a/pkg/solana/chainwriter/ata_creation.go +++ b/pkg/solana/chainwriter/ata_creation.go @@ -11,6 +11,7 @@ import ( "github.com/google/uuid" "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/tokens" + soltypes "github.com/smartcontractkit/chainlink-common/pkg/types/solana" "github.com/smartcontractkit/chainlink-common/pkg/logger" @@ -39,7 +40,7 @@ func CreateATAs(ctx context.Context, args any, lookups []ATALookup, derivedTable return nil, fmt.Errorf("error getting values at location: %w", err) } } - walletAddresses, err := GetAddresses(ctx, args, []Lookup{lookup.WalletAddress}, derivedTableMap, client) + walletAddresses, err := GetAddresses(ctx, args, []soltypes.Lookup{lookup.WalletAddress}, derivedTableMap, client) if lookup.Optional && isIgnorableError(err) { continue } else if err != nil { @@ -50,7 +51,7 @@ func CreateATAs(ctx context.Context, args any, lookups []ATALookup, derivedTable } wallet := walletAddresses[0].PublicKey - mints, err := GetAddresses(ctx, args, []Lookup{lookup.MintAddress}, derivedTableMap, client) + mints, err := GetAddresses(ctx, args, []soltypes.Lookup{lookup.MintAddress}, derivedTableMap, client) if lookup.Optional && isIgnorableError(err) { continue } else if err != nil { diff --git a/pkg/solana/chainwriter/chain_writer.go b/pkg/solana/chainwriter/chain_writer.go index 399c3d2ed..d33b038ce 100644 --- a/pkg/solana/chainwriter/chain_writer.go +++ b/pkg/solana/chainwriter/chain_writer.go @@ -11,10 +11,10 @@ import ( addresslookuptable "github.com/gagliardetto/solana-go/programs/address-lookup-table" "github.com/gagliardetto/solana-go/rpc" - commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec" "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/services" "github.com/smartcontractkit/chainlink-common/pkg/types" + soltypes "github.com/smartcontractkit/chainlink-common/pkg/types/solana" "github.com/smartcontractkit/chainlink-solana/pkg/solana/client" "github.com/smartcontractkit/chainlink-solana/pkg/solana/codec" @@ -47,31 +47,15 @@ var ( _ types.ContractWriter = &SolanaChainWriterService{} ) +// Deprecated // nolint // ignoring naming suggestion -type ChainWriterConfig struct { - Programs map[string]ProgramConfig `json:"programs"` -} +type ChainWriterConfig = soltypes.ContractWriterConfig -type ProgramConfig struct { - Methods map[string]MethodConfig `json:"methods"` - IDL string `json:"idl"` -} +// Deprecated +type ProgramConfig = soltypes.ProgramConfig -type MethodConfig struct { - FromAddress string `json:"fromAddress"` - InputModifications commoncodec.ModifiersConfig `json:"inputModifications,omitempty"` - ChainSpecificName string `json:"chainSpecificName"` - LookupTables LookupTables `json:"lookupTables,omitempty"` - Accounts []Lookup `json:"accounts"` - ATAs []ATALookup `json:"atas,omitempty"` - // Location in the args where the debug ID is stored - DebugIDLocation string `json:"debugIDLocation,omitempty"` - ArgsTransform string `json:"argsTransform,omitempty"` - // Overhead added to calculated compute units in the args transform - ComputeUnitLimitOverhead uint32 `json:"ComputeUnitLimitOverhead,omitempty"` - // Configs for buffering payloads to support larger transaction sizes for this method - BufferPayloadMethod string `json:"bufferPayloadMethod,omitempty"` -} +// Deprecated +type MethodConfig = soltypes.MethodConfig func NewSolanaChainWriterService(logger logger.Logger, client client.MultiClient, txm txm.TxManager, ge fees.Estimator, config ChainWriterConfig) (*SolanaChainWriterService, error) { w := SolanaChainWriterService{ @@ -157,10 +141,10 @@ for Solana transactions. It handles constant addresses, dynamic lookups, program ### Error Handling: - Errors are wrapped with the `debugID` for easier tracing. */ -func GetAddresses(ctx context.Context, args any, accounts []Lookup, derivedTableMap map[string]map[string][]*solana.AccountMeta, client client.MultiClient) ([]*solana.AccountMeta, error) { +func GetAddresses(ctx context.Context, args any, accounts []soltypes.Lookup, derivedTableMap map[string]map[string][]*solana.AccountMeta, client client.MultiClient) ([]*solana.AccountMeta, error) { var addresses []*solana.AccountMeta for _, accountConfig := range accounts { - meta, err := accountConfig.Resolve(ctx, args, derivedTableMap, client) + meta, err := Lookup(accountConfig).Resolve(ctx, args, derivedTableMap, client) if accountConfig.Optional && err != nil && isIgnorableError(err) { // skip optional accounts if they are not found continue @@ -465,7 +449,7 @@ func (s *SolanaChainWriterService) ResolveLookupTables(ctx context.Context, args func (s *SolanaChainWriterService) loadTable(ctx context.Context, args any, rlt DerivedLookupTable) (map[string]map[string][]*solana.AccountMeta, error) { // Resolve all addresses specified by the identifier - lookupTableAddresses, err := GetAddresses(ctx, args, []Lookup{rlt.Accounts}, nil, s.client) + lookupTableAddresses, err := GetAddresses(ctx, args, []soltypes.Lookup{rlt.Accounts}, nil, s.client) if err != nil { return nil, fmt.Errorf("error resolving addresses for lookup table: %w", err) } diff --git a/pkg/solana/chainwriter/chain_writer_test.go b/pkg/solana/chainwriter/chain_writer_test.go index 3186ccfd9..111cfc484 100644 --- a/pkg/solana/chainwriter/chain_writer_test.go +++ b/pkg/solana/chainwriter/chain_writer_test.go @@ -19,6 +19,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/codec" "github.com/smartcontractkit/chainlink-common/pkg/types" + soltypes "github.com/smartcontractkit/chainlink-common/pkg/types/solana" ccipsolana "github.com/smartcontractkit/chainlink-ccip/chains/solana" "github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings/v0_1_1/ccip_offramp" @@ -65,7 +66,7 @@ func TestChainWriter_GetAddresses(t *testing.T) { txm := txmMocks.NewTxManager(t) // initialize chain writer - cw, err := chainwriter.NewSolanaChainWriterService(testutils.NewNullLogger(), mc, txm, ge, chainwriter.ChainWriterConfig{}) + cw, err := chainwriter.NewSolanaChainWriterService(testutils.NewNullLogger(), mc, txm, ge, soltypes.ContractWriterConfig{}) require.NoError(t, err) // expected account meta for constant account @@ -105,20 +106,20 @@ func TestChainWriter_GetAddresses(t *testing.T) { IsWritable: true, } - lookupTableConfig := chainwriter.LookupTables{ - DerivedLookupTables: []chainwriter.DerivedLookupTable{ + lookupTableConfig := soltypes.LookupTables{ + DerivedLookupTables: []soltypes.DerivedLookupTable{ { Name: "DerivedTable", - Accounts: chainwriter.Lookup{PDALookups: &chainwriter.PDALookups{ + Accounts: soltypes.Lookup{PDALookups: &soltypes.PDALookups{ Name: "DataAccountPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "WriteTest", Address: programID.String()}}, - Seeds: []chainwriter.Seed{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "WriteTest", Address: programID.String()}}, + Seeds: []soltypes.Seed{ // extract seed2 for PDA lookup - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "Seed2", Location: "Seed2"}}}, + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "Seed2", Location: "Seed2"}}}, }, IsSigner: derivedTablePdaLookupMeta.IsSigner, IsWritable: derivedTablePdaLookupMeta.IsWritable, - InternalField: chainwriter.InternalField{ + InternalField: soltypes.InternalField{ TypeName: "LookupTableDataAccount", Location: "LookupTable", IDL: testContractIDL, @@ -141,32 +142,32 @@ func TestChainWriter_GetAddresses(t *testing.T) { Seed2: seed2, } - accountLookupConfig := []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + accountLookupConfig := []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Constant", Address: constantAccountMeta.PublicKey.String(), IsSigner: constantAccountMeta.IsSigner, IsWritable: constantAccountMeta.IsWritable, }}, - {AccountLookup: &chainwriter.AccountLookup{ + {AccountLookup: &soltypes.AccountLookup{ Name: "LookupTable", Location: "LookupTable", - IsSigner: chainwriter.MetaBool{Value: accountLookupMeta.IsSigner}, - IsWritable: chainwriter.MetaBool{Value: accountLookupMeta.IsWritable}, + IsSigner: soltypes.MetaBool{Value: accountLookupMeta.IsSigner}, + IsWritable: soltypes.MetaBool{Value: accountLookupMeta.IsWritable}, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "DataAccountPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "WriteTest", Address: solana.SystemProgramID.String()}}, - Seeds: []chainwriter.Seed{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "WriteTest", Address: solana.SystemProgramID.String()}}, + Seeds: []soltypes.Seed{ // extract seed1 for PDA lookup - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "Seed1", Location: "Seed1"}}}, + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "Seed1", Location: "Seed1"}}}, }, IsSigner: pdaLookupMeta.IsSigner, IsWritable: pdaLookupMeta.IsWritable, // Just get the address of the account, nothing internal. - InternalField: chainwriter.InternalField{}, + InternalField: soltypes.InternalField{}, }}, - {AccountsFromLookupTable: &chainwriter.AccountsFromLookupTable{ + {AccountsFromLookupTable: &soltypes.AccountsFromLookupTable{ LookupTableName: "DerivedTable", IncludeIndexes: []int{0}, }}, @@ -209,8 +210,8 @@ func TestChainWriter_GetAddresses(t *testing.T) { Seed2: seed2, } - accountLookupConfig := []chainwriter.Lookup{ - {AccountsFromLookupTable: &chainwriter.AccountsFromLookupTable{ + accountLookupConfig := []soltypes.Lookup{ + {AccountsFromLookupTable: &soltypes.AccountsFromLookupTable{ LookupTableName: "DerivedTable", IncludeIndexes: []int{0, 2}, }}, @@ -234,8 +235,8 @@ func TestChainWriter_GetAddresses(t *testing.T) { Seed2: seed2, } - accountLookupConfig := []chainwriter.Lookup{ - {AccountsFromLookupTable: &chainwriter.AccountsFromLookupTable{ + accountLookupConfig := []soltypes.Lookup{ + {AccountsFromLookupTable: &soltypes.AccountsFromLookupTable{ LookupTableName: "DerivedTable", }}, } @@ -258,13 +259,13 @@ func TestChainWriter_GetAddresses(t *testing.T) { const invalidLocation = "Invalid.Path" t.Run("AccountLookup error is skipped when Lookup is optional", func(t *testing.T) { - accountLookupConfig := []chainwriter.Lookup{ + accountLookupConfig := []soltypes.Lookup{ { - AccountLookup: &chainwriter.AccountLookup{ + AccountLookup: &soltypes.AccountLookup{ Name: "OptionalAccountLookup", Location: invalidLocation, - IsSigner: chainwriter.MetaBool{Value: false}, - IsWritable: chainwriter.MetaBool{Value: false}, + IsSigner: soltypes.MetaBool{Value: false}, + IsWritable: soltypes.MetaBool{Value: false}, }, Optional: true, }, @@ -278,12 +279,12 @@ func TestChainWriter_GetAddresses(t *testing.T) { }) t.Run("AccountLookup error is returned when Lookup is required", func(t *testing.T) { - accountLookupConfig := []chainwriter.Lookup{ - {AccountLookup: &chainwriter.AccountLookup{ + accountLookupConfig := []soltypes.Lookup{ + {AccountLookup: &soltypes.AccountLookup{ Name: "NonOptionalAccountLookup", Location: invalidLocation, - IsSigner: chainwriter.MetaBool{Value: false}, - IsWritable: chainwriter.MetaBool{Value: false}, + IsSigner: soltypes.MetaBool{Value: false}, + IsWritable: soltypes.MetaBool{Value: false}, }}, } @@ -294,13 +295,13 @@ func TestChainWriter_GetAddresses(t *testing.T) { }) t.Run("PDALookups error is skipped when Lookup is optional", func(t *testing.T) { - accountLookupConfig := []chainwriter.Lookup{ + accountLookupConfig := []soltypes.Lookup{ { - PDALookups: &chainwriter.PDALookups{ + PDALookups: &soltypes.PDALookups{ Name: "OptionalPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "ProgramID", Address: solana.SystemProgramID.String()}}, - Seeds: []chainwriter.Seed{ - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Location: invalidLocation}}}, + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "ProgramID", Address: solana.SystemProgramID.String()}}, + Seeds: []soltypes.Seed{ + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Location: invalidLocation}}}, }, }, Optional: true, @@ -314,12 +315,12 @@ func TestChainWriter_GetAddresses(t *testing.T) { }) t.Run("PDALookups error is returned when Lookup is required", func(t *testing.T) { - accountLookupConfig := []chainwriter.Lookup{ - {PDALookups: &chainwriter.PDALookups{ + accountLookupConfig := []soltypes.Lookup{ + {PDALookups: &soltypes.PDALookups{ Name: "NonOptionalPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "ProgramID", Address: solana.SystemProgramID.String()}}, - Seeds: []chainwriter.Seed{ - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Location: invalidLocation}}}, + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "ProgramID", Address: solana.SystemProgramID.String()}}, + Seeds: []soltypes.Seed{ + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Location: invalidLocation}}}, }, }}, } @@ -331,12 +332,12 @@ func TestChainWriter_GetAddresses(t *testing.T) { }) t.Run("DerivedLookupTable error is skipped when Lookup is optional", func(t *testing.T) { - lookupTables := chainwriter.LookupTables{ - DerivedLookupTables: []chainwriter.DerivedLookupTable{ + lookupTables := soltypes.LookupTables{ + DerivedLookupTables: []soltypes.DerivedLookupTable{ { Name: "OptionalDerivedTable", Optional: true, - Accounts: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + Accounts: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{ Location: invalidLocation, }}, }, @@ -351,11 +352,11 @@ func TestChainWriter_GetAddresses(t *testing.T) { }) t.Run("DerivedLookupTable error is returned when Lookup is required", func(t *testing.T) { - lookupTables := chainwriter.LookupTables{ - DerivedLookupTables: []chainwriter.DerivedLookupTable{ + lookupTables := soltypes.LookupTables{ + DerivedLookupTables: []soltypes.DerivedLookupTable{ { Name: "NonOptionalDerivedTable", - Accounts: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{ + Accounts: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{ Location: invalidLocation, }}, Optional: false, @@ -369,9 +370,9 @@ func TestChainWriter_GetAddresses(t *testing.T) { }) t.Run("AccountsFromLookupTable error is skipped when Lookup is optional", func(t *testing.T) { - accountLookupConfig := []chainwriter.Lookup{ + accountLookupConfig := []soltypes.Lookup{ { - AccountsFromLookupTable: &chainwriter.AccountsFromLookupTable{ + AccountsFromLookupTable: &soltypes.AccountsFromLookupTable{ LookupTableName: "NonExistent", }, Optional: true, @@ -386,8 +387,8 @@ func TestChainWriter_GetAddresses(t *testing.T) { }) t.Run("AccountsFromLookupTable error is returned when Lookup is required", func(t *testing.T) { - accountLookupConfig := []chainwriter.Lookup{ - {AccountsFromLookupTable: &chainwriter.AccountsFromLookupTable{ + accountLookupConfig := []soltypes.Lookup{ + {AccountsFromLookupTable: &soltypes.AccountsFromLookupTable{ LookupTableName: "NonExistent", }}, } @@ -413,7 +414,7 @@ func TestChainWriter_FilterLookupTableAddresses(t *testing.T) { txm := txmMocks.NewTxManager(t) // initialize chain writer - cw, err := chainwriter.NewSolanaChainWriterService(testutils.NewNullLogger(), mc, txm, ge, chainwriter.ChainWriterConfig{}) + cw, err := chainwriter.NewSolanaChainWriterService(testutils.NewNullLogger(), mc, txm, ge, soltypes.ContractWriterConfig{}) require.NoError(t, err) programID := GetRandomPubKey(t) @@ -441,20 +442,20 @@ func TestChainWriter_FilterLookupTableAddresses(t *testing.T) { staticLookupTablePubkey2 := GetRandomPubKey(t) mockFetchLookupTableAddresses(t, rw, staticLookupTablePubkey2, CreateTestPubKeys(t, 2)) - lookupTableConfig := chainwriter.LookupTables{ - DerivedLookupTables: []chainwriter.DerivedLookupTable{ + lookupTableConfig := soltypes.LookupTables{ + DerivedLookupTables: []soltypes.DerivedLookupTable{ { Name: "DerivedTable", - Accounts: chainwriter.Lookup{PDALookups: &chainwriter.PDALookups{ + Accounts: soltypes.Lookup{PDALookups: &soltypes.PDALookups{ Name: "DataAccountPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "WriteTest", Address: programID.String()}}, - Seeds: []chainwriter.Seed{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "WriteTest", Address: programID.String()}}, + Seeds: []soltypes.Seed{ // extract seed1 for PDA lookup - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "Seed1", Location: "Seed1"}}}, + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "Seed1", Location: "Seed1"}}}, }, IsSigner: true, IsWritable: true, - InternalField: chainwriter.InternalField{ + InternalField: soltypes.InternalField{ TypeName: "LookupTableDataAccount", Location: "LookupTable", IDL: testContractIDL, @@ -463,16 +464,16 @@ func TestChainWriter_FilterLookupTableAddresses(t *testing.T) { }, { Name: "MiscDerivedTable", - Accounts: chainwriter.Lookup{PDALookups: &chainwriter.PDALookups{ + Accounts: soltypes.Lookup{PDALookups: &soltypes.PDALookups{ Name: "MiscPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "UnusedAccount", Address: unusedProgramID.String()}}, - Seeds: []chainwriter.Seed{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "UnusedAccount", Address: unusedProgramID.String()}}, + Seeds: []soltypes.Seed{ // extract seed2 for PDA lookup - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "Seed2", Location: "Seed2"}}}, + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "Seed2", Location: "Seed2"}}}, }, IsSigner: true, IsWritable: true, - InternalField: chainwriter.InternalField{ + InternalField: soltypes.InternalField{ TypeName: "LookupTableDataAccount", Location: "LookupTable", IDL: testContractIDL, @@ -480,7 +481,7 @@ func TestChainWriter_FilterLookupTableAddresses(t *testing.T) { }}, }, }, - StaticLookupTables: []solana.PublicKey{staticLookupTablePubkey1, staticLookupTablePubkey2}, + StaticLookupTables: [][32]byte{staticLookupTablePubkey1, staticLookupTablePubkey2}, } args := Arguments{ @@ -489,8 +490,8 @@ func TestChainWriter_FilterLookupTableAddresses(t *testing.T) { } t.Run("returns filtered map with only relevant lookup tables required by account lookup config", func(t *testing.T) { - accountLookupConfig := []chainwriter.Lookup{ - {AccountsFromLookupTable: &chainwriter.AccountsFromLookupTable{ + accountLookupConfig := []soltypes.Lookup{ + {AccountsFromLookupTable: &soltypes.AccountsFromLookupTable{ LookupTableName: "DerivedTable", IncludeIndexes: []int{0}, }}, @@ -516,8 +517,8 @@ func TestChainWriter_FilterLookupTableAddresses(t *testing.T) { }) t.Run("returns filtered map and ignores nil account meta and nil entry in lookup table", func(t *testing.T) { - accountLookupConfig := []chainwriter.Lookup{ - {AccountsFromLookupTable: &chainwriter.AccountsFromLookupTable{ + accountLookupConfig := []soltypes.Lookup{ + {AccountsFromLookupTable: &soltypes.AccountsFromLookupTable{ LookupTableName: "DerivedTable", IncludeIndexes: []int{0}, }}, @@ -548,7 +549,7 @@ func TestChainWriter_FilterLookupTableAddresses(t *testing.T) { }) t.Run("returns empty map if empty account lookup config provided", func(t *testing.T) { - accountLookupConfig := []chainwriter.Lookup{} + accountLookupConfig := []soltypes.Lookup{} // Fetch derived table map derivedTableMap, staticTableMap, err := cw.ResolveLookupTables(ctx, args, lookupTableConfig) @@ -564,8 +565,8 @@ func TestChainWriter_FilterLookupTableAddresses(t *testing.T) { }) t.Run("returns empty map if only constant account lookup required", func(t *testing.T) { - accountLookupConfig := []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + accountLookupConfig := []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Constant", Address: GetRandomPubKey(t).String(), IsSigner: false, @@ -628,27 +629,27 @@ func TestChainWriter_SubmitTransaction(t *testing.T) { staticLookupKeys := CreateTestPubKeys(t, 2) mockFetchLookupTableAddresses(t, rw, staticLookupTablePubkey, staticLookupKeys) - cwConfig := chainwriter.ChainWriterConfig{ - Programs: map[string]chainwriter.ProgramConfig{ + cwConfig := soltypes.ContractWriterConfig{ + Programs: map[string]soltypes.ProgramConfig{ "contract_reader_interface": { - Methods: map[string]chainwriter.MethodConfig{ + Methods: map[string]soltypes.MethodConfig{ "initializeLookupTable": { FromAddress: admin.String(), ChainSpecificName: "initializeLookupTable", - LookupTables: chainwriter.LookupTables{ - DerivedLookupTables: []chainwriter.DerivedLookupTable{ + LookupTables: soltypes.LookupTables{ + DerivedLookupTables: []soltypes.DerivedLookupTable{ { Name: "DerivedTable", - Accounts: chainwriter.Lookup{PDALookups: &chainwriter.PDALookups{ + Accounts: soltypes.Lookup{PDALookups: &soltypes.PDALookups{ Name: "DataAccountPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "WriteTest", Address: programID.String()}}, - Seeds: []chainwriter.Seed{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "WriteTest", Address: programID.String()}}, + Seeds: []soltypes.Seed{ // extract seed2 for PDA lookup - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "Seed2", Location: "Seed2"}}}, + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "Seed2", Location: "Seed2"}}}, }, IsSigner: false, IsWritable: false, - InternalField: chainwriter.InternalField{ + InternalField: soltypes.InternalField{ TypeName: "LookupTableDataAccount", Location: "LookupTable", IDL: testContractIDL, @@ -656,44 +657,44 @@ func TestChainWriter_SubmitTransaction(t *testing.T) { }}, }, }, - StaticLookupTables: []solana.PublicKey{staticLookupTablePubkey}, + StaticLookupTables: [][32]byte{staticLookupTablePubkey}, }, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "feepayer", Address: admin.String(), IsSigner: false, IsWritable: false, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "Constant", Address: account1.String(), IsSigner: false, IsWritable: false, }}, - {AccountLookup: &chainwriter.AccountLookup{ + {AccountLookup: &soltypes.AccountLookup{ Name: "LookupTable", Location: "LookupTable", - IsSigner: chainwriter.MetaBool{Value: false}, - IsWritable: chainwriter.MetaBool{Value: false}, + IsSigner: soltypes.MetaBool{Value: false}, + IsWritable: soltypes.MetaBool{Value: false}, }}, - {PDALookups: &chainwriter.PDALookups{ + {PDALookups: &soltypes.PDALookups{ Name: "DataAccountPDA", - PublicKey: chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{Name: "WriteTest", Address: solana.SystemProgramID.String()}}, - Seeds: []chainwriter.Seed{ + PublicKey: soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{Name: "WriteTest", Address: solana.SystemProgramID.String()}}, + Seeds: []soltypes.Seed{ // extract seed1 for PDA lookup - {Dynamic: chainwriter.Lookup{AccountLookup: &chainwriter.AccountLookup{Name: "Seed1", Location: "Seed1"}}}, + {Dynamic: soltypes.Lookup{AccountLookup: &soltypes.AccountLookup{Name: "Seed1", Location: "Seed1"}}}, }, IsSigner: false, IsWritable: false, // Just get the address of the account, nothing internal. - InternalField: chainwriter.InternalField{}, + InternalField: soltypes.InternalField{}, }}, - {AccountsFromLookupTable: &chainwriter.AccountsFromLookupTable{ + {AccountsFromLookupTable: &soltypes.AccountsFromLookupTable{ LookupTableName: "DerivedTable", IncludeIndexes: []int{0}, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "systemprogram", Address: solana.SystemProgramID.String(), IsSigner: false, @@ -706,7 +707,7 @@ func TestChainWriter_SubmitTransaction(t *testing.T) { IDL: testContractIDL, }, "buffer_payload": { - Methods: map[string]chainwriter.MethodConfig{ + Methods: map[string]soltypes.MethodConfig{ "execute": { FromAddress: admin.String(), ChainSpecificName: "execute", @@ -714,14 +715,14 @@ func TestChainWriter_SubmitTransaction(t *testing.T) { InputModifications: codec.ModifiersConfig{ &codec.HardCodeModifierConfig{OnChainValues: map[string]any{"Fail": false}}, }, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "feepayer", Address: admin.String(), IsSigner: false, IsWritable: false, }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "system", Address: solana.SystemProgramID.String(), IsSigner: false, @@ -740,10 +741,10 @@ func TestChainWriter_SubmitTransaction(t *testing.T) { require.NoError(t, err) t.Run("fails with invalid ABI", func(t *testing.T) { - invalidCWConfig := chainwriter.ChainWriterConfig{ - Programs: map[string]chainwriter.ProgramConfig{ + invalidCWConfig := soltypes.ContractWriterConfig{ + Programs: map[string]soltypes.ProgramConfig{ "invalid_program": { - Methods: map[string]chainwriter.MethodConfig{ + Methods: map[string]soltypes.MethodConfig{ "invalid": { ChainSpecificName: "invalid", }, @@ -815,17 +816,17 @@ func TestChainWriter_SubmitTransaction(t *testing.T) { t.Run("invalid buffer methods", func(t *testing.T) { recentBlockHash := solana.Hash{} - customConfig := chainwriter.ChainWriterConfig{ - Programs: map[string]chainwriter.ProgramConfig{ + customConfig := soltypes.ContractWriterConfig{ + Programs: map[string]soltypes.ProgramConfig{ "buffer_payload": { - Methods: map[string]chainwriter.MethodConfig{ + Methods: map[string]soltypes.MethodConfig{ "execute": { FromAddress: admin.String(), ChainSpecificName: "execute", InputModifications: codec.ModifiersConfig{ &codec.HardCodeModifierConfig{OnChainValues: map[string]any{"Fail": false}}, }, - Accounts: []chainwriter.Lookup{}, + Accounts: []soltypes.Lookup{}, }, }, IDL: testBufferContractIDL, @@ -932,10 +933,10 @@ func TestChainWriter_SubmitTransaction(t *testing.T) { rw.On("LatestBlockhash", mock.Anything).Return(&rpc.GetLatestBlockhashResult{Value: &rpc.LatestBlockhashResult{Blockhash: recentBlockHash, LastValidBlockHeight: uint64(100)}}, nil).Twice() txID := uuid.NewString() - customConfig := chainwriter.ChainWriterConfig{ - Programs: map[string]chainwriter.ProgramConfig{ + customConfig := soltypes.ContractWriterConfig{ + Programs: map[string]soltypes.ProgramConfig{ "buffer_payload": { - Methods: map[string]chainwriter.MethodConfig{ + Methods: map[string]soltypes.MethodConfig{ "execute": { FromAddress: admin.String(), ChainSpecificName: "execute", @@ -943,7 +944,7 @@ func TestChainWriter_SubmitTransaction(t *testing.T) { InputModifications: codec.ModifiersConfig{ &codec.HardCodeModifierConfig{OnChainValues: map[string]any{"Fail": false}}, }, - Accounts: []chainwriter.Lookup{}, + Accounts: []soltypes.Lookup{}, }, }, IDL: testBufferContractIDL, @@ -953,7 +954,7 @@ func TestChainWriter_SubmitTransaction(t *testing.T) { methodConfig := customConfig.Programs["buffer_payload"].Methods["execute"] for i := range 40 { - methodConfig.Accounts = append(methodConfig.Accounts, chainwriter.Lookup{AccountConstant: &chainwriter.AccountConstant{ + methodConfig.Accounts = append(methodConfig.Accounts, soltypes.Lookup{AccountConstant: &soltypes.AccountConstant{ Name: fmt.Sprintf("randomAccount%d", i), Address: GetRandomPubKey(t).String(), IsSigner: false, @@ -995,10 +996,10 @@ func TestChainWriter_CCIPOfframp(t *testing.T) { staticCUOverhead := uint32(150_000) // simplified CCIP Config - does not contain full account list - ccipCWConfig := chainwriter.ChainWriterConfig{ - Programs: map[string]chainwriter.ProgramConfig{ + ccipCWConfig := soltypes.ContractWriterConfig{ + Programs: map[string]soltypes.ProgramConfig{ ccipconsts.ContractNameOffRamp: { - Methods: map[string]chainwriter.MethodConfig{ + Methods: map[string]soltypes.MethodConfig{ ccipconsts.MethodExecute: { FromAddress: admin.String(), InputModifications: []codec.ModifierConfig{ @@ -1025,17 +1026,17 @@ func TestChainWriter_CCIPOfframp(t *testing.T) { }, ChainSpecificName: "commit", ArgsTransform: "CCIPCommit", - LookupTables: chainwriter.LookupTables{}, - Accounts: []chainwriter.Lookup{ - {AccountConstant: &chainwriter.AccountConstant{ + LookupTables: soltypes.LookupTables{}, + Accounts: []soltypes.Lookup{ + {AccountConstant: &soltypes.AccountConstant{ Name: "testAcc1", Address: GetRandomPubKey(t).String(), }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "testAcc2", Address: GetRandomPubKey(t).String(), }}, - {AccountConstant: &chainwriter.AccountConstant{ + {AccountConstant: &soltypes.AccountConstant{ Name: "testAcc3", Address: GetRandomPubKey(t).String(), }}, @@ -1235,7 +1236,7 @@ func TestChainWriter_GetTransactionStatus(t *testing.T) { txm := txmMocks.NewTxManager(t) // initialize chain writer - cw, err := chainwriter.NewSolanaChainWriterService(testutils.NewNullLogger(), mc, txm, ge, chainwriter.ChainWriterConfig{}) + cw, err := chainwriter.NewSolanaChainWriterService(testutils.NewNullLogger(), mc, txm, ge, soltypes.ContractWriterConfig{}) require.NoError(t, err) t.Run("returns unknown with error if ID not found", func(t *testing.T) { @@ -1301,7 +1302,7 @@ func TestChainWriter_GetFeeComponents(t *testing.T) { // mock txm txm := txmMocks.NewTxManager(t) - cw, err := chainwriter.NewSolanaChainWriterService(testutils.NewNullLogger(), mc, txm, ge, chainwriter.ChainWriterConfig{}) + cw, err := chainwriter.NewSolanaChainWriterService(testutils.NewNullLogger(), mc, txm, ge, soltypes.ContractWriterConfig{}) require.NoError(t, err) t.Run("returns valid compute unit price and non-nil data availability fee", func(t *testing.T) { @@ -1312,7 +1313,7 @@ func TestChainWriter_GetFeeComponents(t *testing.T) { }) t.Run("fails if gas estimator not set", func(t *testing.T) { - cwNoEstimator, err := chainwriter.NewSolanaChainWriterService(testutils.NewNullLogger(), mc, txm, nil, chainwriter.ChainWriterConfig{}) + cwNoEstimator, err := chainwriter.NewSolanaChainWriterService(testutils.NewNullLogger(), mc, txm, nil, soltypes.ContractWriterConfig{}) require.NoError(t, err) _, err = cwNoEstimator.GetFeeComponents(ctx) require.Error(t, err) diff --git a/pkg/solana/chainwriter/lookups.go b/pkg/solana/chainwriter/lookups.go index a77bdabf3..9609c2bac 100644 --- a/pkg/solana/chainwriter/lookups.go +++ b/pkg/solana/chainwriter/lookups.go @@ -9,6 +9,7 @@ import ( "github.com/gagliardetto/solana-go" "github.com/gagliardetto/solana-go/rpc" + types "github.com/smartcontractkit/chainlink-common/pkg/types/solana" "github.com/smartcontractkit/chainlink-solana/pkg/solana/client" "github.com/smartcontractkit/chainlink-solana/pkg/solana/codec" ) @@ -19,6 +20,10 @@ var ( ErrGettingSeedAtLocation = fmt.Errorf("error getting address seed for location") ) +var _ = Lookup(types.Lookup{}) + +// Lookup is not an alias like the others, because it has a widely used method with solana types that cannot be imported +// in to chainlink-common. However, it can be directly converted from [types.Lookup]. type Lookup struct { Optional bool AccountConstant *AccountConstant `json:"accountConstant,omitempty"` @@ -27,83 +32,35 @@ type Lookup struct { AccountsFromLookupTable *AccountsFromLookupTable `json:"accountsFromLookupTable,omitempty"` } -// AccountConstant represents a fixed address, provided in Base58 format, converted into a `solana.PublicKey`. -type AccountConstant struct { - Name string `json:"name,omitempty"` - Address string `json:"address"` - IsSigner bool `json:"isSigner,omitempty"` - IsWritable bool `json:"isWritable,omitempty"` -} +// Deprecated +type AccountConstant = types.AccountConstant -// AccountLookup dynamically derives an account address from args using a specified location path. -type AccountLookup struct { - Name string `json:"name,omitempty"` - Location string `json:"location"` - // IsSigner and IsWritable can either be a constant bool or a location to a bitmap which decides the bools - IsSigner MetaBool `json:"isSigner,omitempty"` - IsWritable MetaBool `json:"isWritable,omitempty"` -} +// Deprecated +type AccountLookup = types.AccountLookup -type MetaBool struct { - Value bool `json:"value,omitempty"` // bool value - BitmapLocation string `json:"bitmapLocation,omitempty"` // dot separated location of the bitmap -} +// Deprecated +type MetaBool = types.MetaBool -type Seed struct { - Static []byte `json:"static,omitempty"` // Static seed value - Dynamic Lookup `json:"dynamic,omitempty"` // Dynamic lookup for seed -} +// Deprecated +type Seed = types.Seed -// PDALookups generates Program Derived Addresses (PDA) by combining a derived public key with one or more seeds. -type PDALookups struct { - Name string `json:"name,omitempty"` - // The public key of the PDA to be combined with seeds. If there are multiple PublicKeys - // there will be multiple PDAs generated by combining each PublicKey with the seeds. - PublicKey Lookup `json:"publicKey"` - // Seeds to be derived from an additional lookup - Seeds []Seed `json:"seeds"` - IsSigner bool `json:"isSigner,omitempty"` - IsWritable bool `json:"isWritable,omitempty"` - // OPTIONAL: On-chain location and type of desired data from PDA (e.g. a sub-account of the data account) - InternalField InternalField `json:"internalField,omitempty"` -} +// Deprecated +type PDALookups = types.PDALookups -type InternalField struct { - // must map directly to IDL type - TypeName string `json:"typeName"` - Location string `json:"location"` - IDL string `json:"idl"` -} +// Deprecated +type InternalField = types.InternalField -// LookupTables represents a list of lookup tables that are used to derive addresses for a program. -type LookupTables struct { - DerivedLookupTables []DerivedLookupTable `json:"derivedLookupTables,omitempty"` - StaticLookupTables []solana.PublicKey `json:"staticLookupTables,omitempty"` -} +// Deprecated +type LookupTables = types.LookupTables -// DerivedLookupTable represents a lookup table that is used to derive addresses for a program. -type DerivedLookupTable struct { - Name string `json:"name,omitempty"` - Accounts Lookup `json:"accounts"` - Optional bool `json:"optional"` -} +// Deprecated +type DerivedLookupTable = types.DerivedLookupTable -// AccountsFromLookupTable extracts accounts from a lookup table that was previously read and stored in memory. -type AccountsFromLookupTable struct { - LookupTableName string `json:"lookupTableName"` - IncludeIndexes []int `json:"includeIndexes"` -} +// Deprecated +type AccountsFromLookupTable = types.AccountsFromLookupTable -type ATALookup struct { - // Field that determines whether the ATA lookup is necessary. Basically - // just need to check this field exists. Dot separated location. - Location string - // If the field exists, initialize a ATA account using the Wallet, Token Program, and Mint addresses below - WalletAddress Lookup - TokenProgram Lookup // Deprecated: The token program is now fetched from the mint account - MintAddress Lookup - Optional bool -} +// Deprecated +type ATALookup = types.ATALookup func (l Lookup) validate() error { count := 0 @@ -125,18 +82,18 @@ func (l Lookup) Resolve(ctx context.Context, args any, derivedTableMap map[strin return nil, err } if l.AccountConstant != nil { - return l.AccountConstant.Resolve() + return ResolveAccountConstant(l.AccountConstant) } else if l.AccountLookup != nil { - return l.AccountLookup.Resolve(args) + return ResolveAccountLookup(l.AccountLookup, args) } else if l.PDALookups != nil { - return l.PDALookups.Resolve(ctx, args, derivedTableMap, client) + return ResolvePDALookups(ctx, l.PDALookups, args, derivedTableMap, client) } else if l.AccountsFromLookupTable != nil { - return l.AccountsFromLookupTable.Resolve(derivedTableMap) + return ResolveAccountsFromLookupTable(l.AccountsFromLookupTable, derivedTableMap) } return nil, fmt.Errorf("no lookup type specified") } -func (ac AccountConstant) Resolve() ([]*solana.AccountMeta, error) { +func ResolveAccountConstant(ac *AccountConstant) ([]*solana.AccountMeta, error) { address, err := solana.PublicKeyFromBase58(ac.Address) if err != nil { return nil, lookupErrWithName(ac.Name, fmt.Errorf("error getting account from constant: %w", err)) @@ -150,7 +107,7 @@ func (ac AccountConstant) Resolve() ([]*solana.AccountMeta, error) { }, nil } -func (al AccountLookup) Resolve(args any) ([]*solana.AccountMeta, error) { +func ResolveAccountLookup(al *AccountLookup, args any) ([]*solana.AccountMeta, error) { derivedValues, err := GetValuesAtLocation(args, al.Location) if err != nil { return nil, lookupErrWithName(al.Name, fmt.Errorf("%w: %v", ErrLookupNotFoundAtLocation, err)) @@ -222,7 +179,7 @@ func resolveBitMap(mb MetaBool, args any, length int) ([]bool, error) { return result, nil } -func (alt AccountsFromLookupTable) Resolve(derivedTableMap map[string]map[string][]*solana.AccountMeta) ([]*solana.AccountMeta, error) { +func ResolveAccountsFromLookupTable(alt *AccountsFromLookupTable, derivedTableMap map[string]map[string][]*solana.AccountMeta) ([]*solana.AccountMeta, error) { // Fetch the inner map for the specified lookup table name innerMap, ok := derivedTableMap[alt.LookupTableName] if !ok { @@ -252,8 +209,8 @@ func (alt AccountsFromLookupTable) Resolve(derivedTableMap map[string]map[string return result, nil } -func (pda PDALookups) Resolve(ctx context.Context, args any, derivedTableMap map[string]map[string][]*solana.AccountMeta, client client.MultiClient) ([]*solana.AccountMeta, error) { - publicKeys, err := GetAddresses(ctx, args, []Lookup{pda.PublicKey}, derivedTableMap, client) +func ResolvePDALookups(ctx context.Context, pda *PDALookups, args any, derivedTableMap map[string]map[string][]*solana.AccountMeta, client client.MultiClient) ([]*solana.AccountMeta, error) { + publicKeys, err := GetAddresses(ctx, args, []types.Lookup{pda.PublicKey}, derivedTableMap, client) if err != nil { return nil, lookupErrWithName(pda.Name, fmt.Errorf("error getting public key for PDALookups: %w", err)) } @@ -329,7 +286,7 @@ func (pda PDALookups) Resolve(ctx context.Context, args any, derivedTableMap map // to multiple addresses, multiplying the combinations accordingly. func getSeedBytesCombinations( ctx context.Context, - lookup PDALookups, + lookup *PDALookups, args any, derivedTableMap map[string]map[string][]*solana.AccountMeta, client client.MultiClient, @@ -364,7 +321,7 @@ func getSeedBytesCombinations( } } else { // Get address seeds from the lookup - seedAddresses, err := GetAddresses(ctx, args, []Lookup{dynamicSeed}, derivedTableMap, client) + seedAddresses, err := GetAddresses(ctx, args, []types.Lookup{dynamicSeed}, derivedTableMap, client) if err != nil { return nil, fmt.Errorf("error getting address seed: %w", err) } @@ -397,17 +354,13 @@ func getSeedBytesCombinations( return allCombinations, nil } -func (l Lookup) IsNil() bool { - return l.AccountConstant == nil && l.AccountLookup == nil && l.PDALookups == nil && l.AccountsFromLookupTable == nil -} - // generatePDAs generates program-derived addresses (PDAs) from public keys and seeds. // it will result in a list of PDAs whose length is the product of the number of public keys // and the number of seed combinations. func generatePDAs( publicKeys []*solana.AccountMeta, seedCombos [][][]byte, - lookup PDALookups, + lookup *PDALookups, ) ([]*solana.AccountMeta, error) { var results []*solana.AccountMeta for _, publicKeyMeta := range publicKeys { diff --git a/pkg/solana/chainwriter/transform_registry.go b/pkg/solana/chainwriter/transform_registry.go index 6592048d6..40d70323f 100644 --- a/pkg/solana/chainwriter/transform_registry.go +++ b/pkg/solana/chainwriter/transform_registry.go @@ -23,6 +23,8 @@ import ( "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/common" "github.com/smartcontractkit/chainlink-ccip/chains/solana/utils/state" ccipconsts "github.com/smartcontractkit/chainlink-ccip/pkg/consts" + soltypes "github.com/smartcontractkit/chainlink-common/pkg/types/solana" + "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3" "github.com/smartcontractkit/chainlink-solana/pkg/solana/client" @@ -165,7 +167,7 @@ func CCIPExecuteArgsTransformV2(ctx context.Context, client client.MultiClient, IsWritable: MetaBool{BitmapLocation: "ExtraData.ExtraArgsDecoded.accountIsWritableBitmap"}, IsSigner: MetaBool{Value: false}, } - userAccounts, resolveErr := userAccountsLookup.Resolve(args) + userAccounts, resolveErr := ResolveAccountLookup(&userAccountsLookup, args) // If err is ErrLookupNotFoundAtLocation, allow process to continue in case accounts are not needed if resolveErr != nil && !errors.Is(resolveErr, ErrLookupNotFoundAtLocation) { return nil, nil, nil, nil, fmt.Errorf("failed to resolve user accounts: %w", resolveErr) @@ -212,7 +214,7 @@ func CCIPExecuteArgsTransformV2(ctx context.Context, client client.MultiClient, }) } tokenReceiverLookup := AccountLookup{Name: "TokenReceiver", Location: "ExtraData.ExtraArgsDecoded.tokenReceiver"} - tokenReceivers, resolveErr := tokenReceiverLookup.Resolve(args) + tokenReceivers, resolveErr := ResolveAccountLookup(&tokenReceiverLookup, args) if resolveErr != nil { return nil, nil, nil, nil, fmt.Errorf("failed to find token receiver, required for token transfers: %w", resolveErr) } @@ -320,7 +322,7 @@ func resolveCommonTokenTransferAccounts(ctx context.Context, tokenAccountsRequir } tokenReceiverLookup := AccountLookup{Name: "TokenReceiver", Location: "ExtraData.ExtraArgsDecoded.tokenReceiver"} - tokenReceivers, err := tokenReceiverLookup.Resolve(args) + tokenReceivers, err := ResolveAccountLookup(&tokenReceiverLookup, args) if err != nil { return commonTokenTransferAccounts{}, fmt.Errorf("failed to find token receiver, required for token transfers: %w", err) } @@ -376,7 +378,7 @@ func appendMessagingAccounts(accounts solana.AccountMetaSlice, logicReceiver cci IsWritable: MetaBool{BitmapLocation: "ExtraData.ExtraArgsDecoded.accountIsWritableBitmap"}, IsSigner: MetaBool{Value: false}, } - userAccounts, err := userAccountsLookup.Resolve(args) + userAccounts, err := ResolveAccountLookup(&userAccountsLookup, args) // If err is ErrLookupNotFoundAtLocation, allow process to continue in case only logic receiver is needed for messaging if err != nil && !errors.Is(err, ErrLookupNotFoundAtLocation) { return nil, fmt.Errorf("failed to resolve user accounts: %w", err) @@ -573,7 +575,7 @@ func getFeeQuoterAddress(ctx context.Context, toAddress string, args any, client lookup := Lookup{ PDALookups: &PDALookups{ Name: ccipconsts.ContractNameFeeQuoter, - PublicKey: Lookup{AccountConstant: &AccountConstant{Address: toAddress}}, + PublicKey: soltypes.Lookup{AccountConstant: &AccountConstant{Address: toAddress}}, Seeds: []Seed{ {Static: []byte("reference_addresses")}, }, diff --git a/pkg/solana/codec/anchoridl.go b/pkg/solana/codec/anchoridl.go index 97856a528..54a336500 100644 --- a/pkg/solana/codec/anchoridl.go +++ b/pkg/solana/codec/anchoridl.go @@ -1,508 +1,134 @@ package codec -/* -copied from https://github.com/gagliardetto/anchor-go where the IDL definition is not importable due to being defined -in the `main` package. -*/ +import "github.com/smartcontractkit/chainlink-common/pkg/types/solana" -import ( - "encoding/json" - "fmt" +// Deprecated +type IDL = solana.IDL - "github.com/davecgh/go-spew/spew" - "github.com/gagliardetto/utilz" -) - -// https://github.com/project-serum/anchor/blob/97e9e03fb041b8b888a9876a7c0676d9bb4736f3/ts/src/idl.ts -type IDL struct { - Version string `json:"version"` - Name string `json:"name"` - Instructions []IdlInstruction `json:"instructions"` - Accounts IdlTypeDefSlice `json:"accounts,omitempty"` - Types IdlTypeDefSlice `json:"types,omitempty"` - Events []IdlEvent `json:"events,omitempty"` - Errors []IdlErrorCode `json:"errors,omitempty"` - Constants []IdlConstant `json:"constants,omitempty"` -} - -type IdlConstant struct { - Name string - Type IdlType - Value string -} - -type IdlTypeDefSlice []IdlTypeDef - -func (named IdlTypeDefSlice) GetByName(name string) *IdlTypeDef { - for i := range named { - v := named[i] - if v.Name == name { - return &v - } - } - return nil -} - -type IdlEvent struct { - Name string `json:"name"` - Fields []IdlEventField `json:"fields"` -} - -type IdlEventField struct { - Name string `json:"name"` - Type IdlType `json:"type"` - Index bool `json:"index"` -} - -type IdlInstruction struct { - Name string `json:"name"` - Docs []string `json:"docs"` // @custom - Accounts IdlAccountItemSlice `json:"accounts"` - Args []IdlField `json:"args"` -} - -type IdlAccountItemSlice []IdlAccountItem - -func (slice IdlAccountItemSlice) NumAccounts() (count int) { - for _, item := range slice { - if item.IdlAccount != nil { - count++ - } +// Deprecated +type IdlConstant solana.IdlConstant - if item.IdlAccounts != nil { - count += item.IdlAccounts.Accounts.NumAccounts() - } - } +// Deprecated +type IdlTypeDefSlice = solana.IdlTypeDefSlice - return count -} +// Deprecated +type IdlEvent = solana.IdlEvent -// type IdlAccountItem = IdlAccount | IdlAccounts; -type IdlAccountItem struct { - IdlAccount *IdlAccount - IdlAccounts *IdlAccounts -} +// Deprecated +type IdlEventField = solana.IdlEventField -func (env *IdlAccountItem) UnmarshalJSON(data []byte) error { - var temp interface{} - if err := json.Unmarshal(data, &temp); err != nil { - return err - } - - if temp == nil { - return fmt.Errorf("envelope is nil: %v", env) - } - - switch v := temp.(type) { - case map[string]interface{}: - if len(v) == 0 { - return nil - } - - _, hasAccounts := v["accounts"] - _, hasIsMut := v["isMut"] - - if hasAccounts == hasIsMut { - return fmt.Errorf("invalid idl structure: expected exactly one of 'accounts' or 'isMut'") - } - - if hasAccounts { - return utilz.TranscodeJSON(temp, &env.IdlAccounts) - } - - return utilz.TranscodeJSON(temp, &env.IdlAccount) - default: - return fmt.Errorf("unknown kind: %s", spew.Sdump(temp)) - } -} +// Deprecated +type IdlInstruction = solana.IdlInstruction -func (env IdlAccountItem) MarshalJSON() ([]byte, error) { - if (env.IdlAccount == nil) == (env.IdlAccounts == nil) { - return nil, fmt.Errorf("invalid structure: expected either IdlAccount or IdlAccounts to be defined") - } - - visited := make(map[*IdlAccounts]struct{}) - if err := checkForIdlAccountsCycle(env.IdlAccounts, visited); err != nil { - return nil, err - } - - var result interface{} - if env.IdlAccounts != nil { - result = map[string]interface{}{ - "accounts": env.IdlAccounts, - } - } else { - result = env.IdlAccount - } - - return json.Marshal(result) -} +// Deprecated +type IdlAccountItemSlice = solana.IdlAccountItem -func checkForIdlAccountsCycle(acc *IdlAccounts, visited map[*IdlAccounts]struct{}) error { - if acc == nil { - return nil - } - - if _, exists := visited[acc]; exists { - return fmt.Errorf("cycle detected in IdlAccounts named %q", acc.Name) - } - visited[acc] = struct{}{} - - for _, item := range acc.Accounts { - if (item.IdlAccount == nil) == (item.IdlAccounts == nil) { - return fmt.Errorf("invalid nested structure: expected either IdlAccount or IdlAccounts to be defined") - } - if item.IdlAccounts != nil { - if err := checkForIdlAccountsCycle(item.IdlAccounts, visited); err != nil { - return err - } - } - } - return nil -} +// Deprecated +type IdlAccountItem = solana.IdlAccountItem -type IdlAccount struct { - Docs []string `json:"docs"` // @custom - Name string `json:"name"` - IsMut bool `json:"isMut"` - IsSigner bool `json:"isSigner"` - Optional bool `json:"optional"` // @custom -} +// Deprecated +type IdlAccount = solana.IdlAccounts -// A nested/recursive version of IdlAccount. -type IdlAccounts struct { - Name string `json:"name"` - Docs []string `json:"docs"` // @custom - Accounts IdlAccountItemSlice `json:"accounts"` -} +// Deprecated +type IdlAccounts = solana.IdlAccounts -type IdlField struct { - Name string `json:"name"` - Docs []string `json:"docs"` // @custom - Type IdlType `json:"type"` -} +// Deprecated +type IdlField = solana.IdlField -// PDA is a struct that does not correlate to an official IDL type -// It is needed to encode seeds to calculate the address for PDA account reads -type PDATypeDef struct { - Prefix []byte `json:"prefix,omitempty"` - Seeds []PDASeed `json:"seeds,omitempty"` -} +// Deprecated +type PDATypeDef = solana.PDATypeDef -type PDASeed struct { - Name string `json:"name"` - Type IdlType `json:"type"` -} +// Deprecated +type PDASeed = solana.PDASeed -type IdlTypeAsString string +// Deprecated +type IdlTypeAsString = solana.IdlTypeAsString +// Deprecated const ( - IdlTypeBool IdlTypeAsString = "bool" - IdlTypeU8 IdlTypeAsString = "u8" - IdlTypeI8 IdlTypeAsString = "i8" - IdlTypeU16 IdlTypeAsString = "u16" - IdlTypeI16 IdlTypeAsString = "i16" - IdlTypeU32 IdlTypeAsString = "u32" - IdlTypeI32 IdlTypeAsString = "i32" - IdlTypeU64 IdlTypeAsString = "u64" - IdlTypeI64 IdlTypeAsString = "i64" - IdlTypeU128 IdlTypeAsString = "u128" - IdlTypeI128 IdlTypeAsString = "i128" - IdlTypeBytes IdlTypeAsString = "bytes" - IdlTypeString IdlTypeAsString = "string" - IdlTypePublicKey IdlTypeAsString = "publicKey" + IdlTypeBool = solana.IdlTypeBool + IdlTypeU8 = solana.IdlTypeU8 + IdlTypeI8 = solana.IdlTypeI8 + IdlTypeU16 = solana.IdlTypeU16 + IdlTypeI16 = solana.IdlTypeI16 + IdlTypeU32 = solana.IdlTypeU32 + IdlTypeI32 = solana.IdlTypeI32 + IdlTypeU64 = solana.IdlTypeU64 + IdlTypeI64 = solana.IdlTypeI64 + IdlTypeU128 = solana.IdlTypeU128 + IdlTypeI128 = solana.IdlTypeI128 + IdlTypeBytes = solana.IdlTypeBytes + IdlTypeString = solana.IdlTypeString + IdlTypePublicKey = solana.IdlTypePublicKey // Custom additions: - IdlTypeUnixTimestamp IdlTypeAsString = "unixTimestamp" - IdlTypeHash IdlTypeAsString = "hash" - IdlTypeDuration IdlTypeAsString = "duration" + IdlTypeUnixTimestamp = solana.IdlTypeUnixTimestamp + IdlTypeHash = solana.IdlTypeHash + IdlTypeDuration = solana.IdlTypeDuration ) -type IdlTypeVec struct { - Vec IdlType `json:"vec"` -} +// Deprecated +type IdlTypeVec = solana.IdlTypeVec -type IdlTypeOption struct { - Option IdlType `json:"option"` -} +// Deprecated +type IdlTypeOption = solana.IdlType -// User defined type. -type IdlTypeDefined struct { - Defined string `json:"defined"` -} +// Deprecated +type IdlTypeDefined = solana.IdlTypeDefined -// Wrapper type: -type IdlTypeArray struct { - Thing IdlType - Num int -} +// Deprecated +type IdlTypeArray = solana.IdlTypeArray -func (env IdlType) MarshalJSON() ([]byte, error) { - var result interface{} - switch { - case env.IsString(): - result = env.GetString() - case env.IsIdlTypeVec(): - result = env.GetIdlTypeVec() - case env.IsIdlTypeOption(): - result = env.GetIdlTypeOption() - case env.IsIdlTypeDefined(): - result = env.GetIdlTypeDefined() - case env.IsArray(): - array := env.GetArray() - result = map[string]interface{}{ - "array": []interface{}{array.Thing, array.Num}, - } - default: - return nil, fmt.Errorf("nil envelope is not supported in IdlType") - } - - return json.Marshal(result) -} - -func (env *IdlType) UnmarshalJSON(data []byte) error { - var temp interface{} - if err := json.Unmarshal(data, &temp); err != nil { - return err - } - - if temp == nil { - return fmt.Errorf("envelope is nil: %v", env) - } - - switch v := temp.(type) { - case string: - env.AsString = IdlTypeAsString(v) - case map[string]interface{}: - if len(v) == 0 { - return nil - } - - var typeFound bool - if _, ok := v["vec"]; ok { - var target IdlTypeVec - if err := utilz.TranscodeJSON(temp, &target); err != nil { - return err - } - typeFound = true - env.AsIdlTypeVec = &target - } - if _, ok := v["option"]; ok { - if typeFound { - return fmt.Errorf("multiple types found for IdlType: %s", spew.Sdump(temp)) - } - var target IdlTypeOption - if err := utilz.TranscodeJSON(temp, &target); err != nil { - return err - } - typeFound = true - env.asIdlTypeOption = &target - } - if _, ok := v["defined"]; ok { - if typeFound { - return fmt.Errorf("multiple types found for IdlType: %s", spew.Sdump(temp)) - } - var target IdlTypeDefined - if err := utilz.TranscodeJSON(temp, &target); err != nil { - return err - } - typeFound = true - env.AsIdlTypeDefined = &target - } - if got, ok := v["array"]; ok { - if typeFound { - return fmt.Errorf("multiple types found for IdlType: %s", spew.Sdump(temp)) - } - arrVal, ok := got.([]interface{}) - if !ok { - return fmt.Errorf("array is not in expected format: %s", spew.Sdump(got)) - } - if len(arrVal) != 2 { - return fmt.Errorf("array is not of expected length: %s", spew.Sdump(got)) - } - var target IdlTypeArray - if err := utilz.TranscodeJSON(arrVal[0], &target.Thing); err != nil { - return err - } - num, ok := arrVal[1].(float64) - if !ok { - return fmt.Errorf("value is unexpected type: %T, expected float64", arrVal[1]) - } - target.Num = int(num) - env.AsIdlTypeArray = &target - } - default: - return fmt.Errorf("Unknown kind: %s", spew.Sdump(temp)) - } - - return nil -} - -// Wrapper type: -type IdlType struct { - AsString IdlTypeAsString - AsIdlTypeVec *IdlTypeVec - asIdlTypeOption *IdlTypeOption - AsIdlTypeDefined *IdlTypeDefined - AsIdlTypeArray *IdlTypeArray -} +// Deprecated +type IdlType = solana.IdlType +// Deprecated func NewIdlStringType(asString IdlTypeAsString) IdlType { - return IdlType{ - AsString: asString, - } -} - -func (env *IdlType) IsString() bool { - return env.AsString != "" -} -func (env *IdlType) IsIdlTypeVec() bool { - return env.AsIdlTypeVec != nil -} -func (env *IdlType) IsIdlTypeOption() bool { - return env.asIdlTypeOption != nil -} -func (env *IdlType) IsIdlTypeDefined() bool { - return env.AsIdlTypeDefined != nil -} -func (env *IdlType) IsArray() bool { - return env.AsIdlTypeArray != nil -} - -// Getters: -func (env *IdlType) GetString() IdlTypeAsString { - return env.AsString -} -func (env *IdlType) GetIdlTypeVec() *IdlTypeVec { - return env.AsIdlTypeVec -} -func (env *IdlType) GetIdlTypeOption() *IdlTypeOption { - return env.asIdlTypeOption -} -func (env *IdlType) GetIdlTypeDefined() *IdlTypeDefined { - return env.AsIdlTypeDefined -} -func (env *IdlType) GetArray() *IdlTypeArray { - return env.AsIdlTypeArray + return solana.NewIdlStringType(asString) } -type IdlTypeDef struct { - Name string `json:"name"` - Type IdlTypeDefTy `json:"type"` -} +// Deprecated +type IdlTypeDef = solana.IdlTypeDef -type IdlTypeDefTyKind string +// Deprecated +type IdlTypeDefTyKind = solana.IdlTypeDefTyKind +// Deprecated const ( - IdlTypeDefTyKindStruct IdlTypeDefTyKind = "struct" - IdlTypeDefTyKindEnum IdlTypeDefTyKind = "enum" - IdlTypeDefTyKindCustom IdlTypeDefTyKind = "custom" + IdlTypeDefTyKindStruct = solana.IdlTypeDefTyKindStruct + IdlTypeDefTyKindEnum = solana.IdlTypeDefTyKindEnum + IdlTypeDefTyKindCustom = solana.IdlTypeDefTyKindCustom ) -type IdlTypeDefTyStruct struct { - Kind IdlTypeDefTyKind `json:"kind"` // == "struct" +// Deprecated +type IdlTypeDefTyStruct = solana.IdlTypeDefTyStruct - Fields *IdlTypeDefStruct `json:"fields,omitempty"` -} - -type IdlTypeDefTyEnum struct { - Kind IdlTypeDefTyKind `json:"kind"` // == "enum" - - Variants IdlEnumVariantSlice `json:"variants,omitempty"` -} +// Deprecated +type IdlTypeDefTyEnum = solana.IdlTypeDefTyEnum -var NilIdlTypeDefTy = IdlTypeDef{Type: IdlTypeDefTy{ - Kind: "struct", - Fields: &IdlTypeDefStruct{}, -}} +// Deprecated +var NilIdlTypeDefTy = solana.NilIdlTypeDefTy -type IdlTypeDefTy struct { - Kind IdlTypeDefTyKind `json:"kind"` +// Deprecated +type IdlTypeDefTy = solana.IdlTypeDefTy - Fields *IdlTypeDefStruct `json:"fields,omitempty"` - Variants IdlEnumVariantSlice `json:"variants,omitempty"` - Codec string `json:"codec,omitempty"` -} +// Deprecated +type IdlEnumVariantSlice = solana.IdlEnumVariantSlice -type IdlEnumVariantSlice []IdlEnumVariant +// Deprecated +type IdlTypeDefStruct = solana.IdlTypeDefStruct -func (slice IdlEnumVariantSlice) IsAllUint8() bool { - for _, elem := range slice { - if !elem.IsUint8() { - return false - } - } - return true -} +// Deprecated +type IdlEnumVariant = solana.IdlEnumVariant -func (slice IdlEnumVariantSlice) IsSimpleEnum() bool { - return slice.IsAllUint8() -} +// Deprecated +type IdlEnumFields = solana.IdlEnumFields -type IdlTypeDefStruct = []IdlField +// Deprecated +type IdlEnumFieldsNamed solana.IdlEnumFieldsNamed -type IdlEnumVariant struct { - Name string `json:"name"` - Docs []string `json:"docs"` // @custom - Fields *IdlEnumFields `json:"fields,omitempty"` -} +// Deprecated +type IdlEnumFieldsTuple = solana.IdlEnumFieldsTuple -func (variant *IdlEnumVariant) IsUint8() bool { - // it's a simple uint8 if there is no fields data - return variant.Fields == nil -} - -// type IdlEnumFields = IdlEnumFieldsNamed | IdlEnumFieldsTuple; -type IdlEnumFields struct { - IdlEnumFieldsNamed *IdlEnumFieldsNamed - IdlEnumFieldsTuple *IdlEnumFieldsTuple -} - -type IdlEnumFieldsNamed []IdlField - -type IdlEnumFieldsTuple []IdlType - -// TODO: verify with examples -func (env *IdlEnumFields) UnmarshalJSON(data []byte) error { - var temp any - if err := json.Unmarshal(data, &temp); err != nil { - return err - } - - if temp == nil { - return fmt.Errorf("envelope is nil: %v", env) - } - - switch v := temp.(type) { - case []any: - if len(v) == 0 { - return nil - } - - firstItem := v[0] - - if _, ok := firstItem.(map[string]any)["name"]; ok { - // TODO: - // If has `name` field, then it's most likely a IdlEnumFieldsNamed. - return utilz.TranscodeJSON(temp, &env.IdlEnumFieldsNamed) - } - return utilz.TranscodeJSON(temp, &env.IdlEnumFieldsTuple) - case map[string]any: - // Only one or the other field is set. Returning early is safe - if named, ok := v["IdlEnumFieldsNamed"]; ok { - return utilz.TranscodeJSON(named, &env.IdlEnumFieldsNamed) - } - if tuple, ok := v["IdlEnumFieldsTuple"]; ok { - return utilz.TranscodeJSON(tuple, &env.IdlEnumFieldsTuple) - } - return fmt.Errorf("Unknown type: %s", spew.Sdump(v)) - default: - return fmt.Errorf("Unknown kind: %s", spew.Sdump(temp)) - } -} - -type IdlErrorCode struct { - Code int `json:"code"` - Name string `json:"name"` - Msg string `json:"msg,omitempty"` -} +// Deprecated +type IdlErrorCode = solana.IdlErrorCode diff --git a/pkg/solana/config/chain_reader.go b/pkg/solana/config/chain_reader.go index bce9f352a..c6f7bcc46 100644 --- a/pkg/solana/config/chain_reader.go +++ b/pkg/solana/config/chain_reader.go @@ -1,14 +1,9 @@ package config import ( - "encoding/json" - "fmt" "time" - commoncodec "github.com/smartcontractkit/chainlink-common/pkg/codec" - commontypes "github.com/smartcontractkit/chainlink-common/pkg/types" - - "github.com/smartcontractkit/chainlink-solana/pkg/solana/codec" + "github.com/smartcontractkit/chainlink-common/pkg/types/solana" ) const ( @@ -18,6 +13,9 @@ const ( DefaultIncludeReverted = false ) +var _ = PollingFilter(solana.PollingFilter{}) + +// PollingFilter is directly convertable from solana.PollingFilter, and extends it with methods. type PollingFilter struct { Retention *time.Duration `json:"retention,omitempty"` // maximum amount of time to retain logs MaxLogsKept *int64 `json:"maxLogsKept,omitempty"` // maximum number of logs to retain ( 0 = unlimited ) @@ -56,144 +54,29 @@ func (f PollingFilter) GetIncludeReverted() bool { return *f.IncludeReverted } -type ContractReader struct { - Namespaces map[string]ChainContractReader `json:"namespaces"` - // AddressShareGroups lists namespaces groups that share the same address. - // Whichever namespace or i.e. Binding from the list is Bound first will share that address with the rest of the group. - // Namespaces that were bound after the first one still have to be Bound to be initialised. - // If they are Bound with an empty address string, they will use the address of the first Bound contract. - // If they are Bound with a non-empty address string, an error will be thrown unless the address matches the address of the first Bound shared contract. - AddressShareGroups [][]string `json:"addressShareGroups,omitempty"` -} - -type ChainContractReader struct { - codec.IDL `json:"anchorIDL"` - *PollingFilter `json:"pollingFilter,omitempty"` - // Reads key is the off-chain name for this read. - Reads map[string]ReadDefinition `json:"reads"` -} +// Deprecated +type ContractReader = solana.ContractReader -type EventDefinitions struct { - IndexedField0 *IndexedField `json:"indexedField0"` - IndexedField1 *IndexedField `json:"indexedField1"` - IndexedField2 *IndexedField `json:"indexedField2"` - IndexedField3 *IndexedField `json:"indexedField3"` - // PollingFilter should be defined on a contract level in ContractPollingFilter, unless event needs to override the - // contract level filter options. - *PollingFilter `json:"pollingFilter,omitempty"` -} +// Deprecated +type ChainContractReader = solana.ChainContractReader -type MultiReader struct { - // Reads is a list of reads that is sequentially read to fill out a complete response for the parent read. - // Parent ReadDefinition has to define codec modifiers which adds fields that are to be filled out by the reads in Reads. - Reads []ReadDefinition `json:"reads,omitempty"` - // ReuseParams If true, params from parent read will be reused for all MultiReader Reads. - ReuseParams bool `json:"reuseParams"` -} +// Deprecated +type EventDefinitions = solana.EventDefinitions -type ReadDefinition struct { - ChainSpecificName string `json:"chainSpecificName"` - ReadType ReadType `json:"readType,omitempty"` - ErrOnMissingAccountData bool `json:"errOnMissingAccountData,omitempty"` - InputModifications commoncodec.ModifiersConfig `json:"inputModifications,omitempty"` - OutputModifications commoncodec.ModifiersConfig `json:"outputModifications,omitempty"` - PDADefinition codec.PDATypeDef `json:"pdaDefinition,omitempty"` // Only used for PDA account reads - MultiReader *MultiReader `json:"multiReader,omitempty"` - EventDefinitions *EventDefinitions `json:"eventDefinitions,omitempty"` - // ResponseAddressHardCoder hardcodes the address of the contract into the defined field in the response. - ResponseAddressHardCoder *commoncodec.HardCodeModifierConfig `json:"responseAddressHardCoder,omitempty"` -} +// Deprecated +type MultiReader = solana.MultiReader -func (d ReadDefinition) HasPollingFilter() bool { - return d.EventDefinitions != nil && d.EventDefinitions.PollingFilter != nil -} +// Deprecated +type ReadDefinition = solana.ReadDefinition -type ReadType int +// Deprecated +type ReadType = solana.ReadType +// Deprecated const ( - Account ReadType = iota - Event + Account = solana.Account + Event = solana.Event ) -func (r ReadType) String() string { - switch r { - case Account: - return "Account" - case Event: - return "Event" - default: - return fmt.Sprintf("Unknown(%d)", r) - } -} - -type IndexedField struct { - OffChainPath string `json:"offChainPath"` - OnChainPath string `json:"onChainPath"` -} - -func (c *ContractReader) UnmarshalJSON(bytes []byte) error { - rawJSON := make(map[string]json.RawMessage) - if err := json.Unmarshal(bytes, &rawJSON); err != nil { - return err - } - - c.Namespaces = make(map[string]ChainContractReader) - if err := json.Unmarshal(rawJSON["namespaces"], &c.Namespaces); err != nil { - return err - } - - if rawJSON["addressShareGroups"] != nil { - if err := json.Unmarshal(rawJSON["addressShareGroups"], &c.AddressShareGroups); err != nil { - return err - } - } - - if c.AddressShareGroups != nil { - seen := make(map[string][]string) - for _, group := range c.AddressShareGroups { - for _, namespace := range group { - if seenIn, alreadySeen := seen[namespace]; alreadySeen { - return fmt.Errorf("namespace %s is already in share group %v: %w", namespace, seenIn, commontypes.ErrInvalidConfig) - } - seen[namespace] = group - } - } - } - - return nil -} - -func (c *ChainContractReader) UnmarshalJSON(bytes []byte) error { - rawJSON := make(map[string]json.RawMessage) - if err := json.Unmarshal(bytes, &rawJSON); err != nil { - return err - } - - idlBytes := rawJSON["anchorIDL"] - var rawString string - if err := json.Unmarshal(idlBytes, &rawString); err == nil { - if err = json.Unmarshal([]byte(rawString), &c.IDL); err != nil { - return fmt.Errorf("failed to parse anchorIDL string as IDL struct: %w", err) - } - return nil - } - - // If we didn't get a string, attempt to parse directly as an IDL object - if err := json.Unmarshal(idlBytes, &c.IDL); err != nil { - return fmt.Errorf("anchorIDL field is neither a valid JSON string nor a valid IDL object: %w", err) - } - - if len(c.IDL.Accounts) == 0 && len(c.IDL.Events) == 0 { - return fmt.Errorf("namespace idl must have at least one account or event: %w", commontypes.ErrInvalidConfig) - } - - if err := json.Unmarshal(rawJSON["reads"], &c.Reads); err != nil { - return err - } - - if len(c.Reads) == 0 { - return fmt.Errorf("namespace must have at least one read: %w", commontypes.ErrInvalidConfig) - } - - return nil -} +// Deprecated +type IndexedField = solana.IndexedField