From f57b557a122b410513312cc1bfb967d403e7c564 Mon Sep 17 00:00:00 2001 From: Vladimir Shchukin Date: Fri, 3 Apr 2026 00:14:33 -0400 Subject: [PATCH 1/2] Convert package level map into instance field --- .../solana/anchor-go/generator/accounts.go | 21 +++++++++---------- .../anchor-go/generator/complex-enums.go | 17 +++++++-------- .../solana/anchor-go/generator/generator.go | 10 +++++---- .../anchor-go/generator/instructions.go | 6 +++--- .../solana/anchor-go/generator/marshal.go | 10 ++++----- .../solana/anchor-go/generator/types.go | 14 ++++++------- .../solana/anchor-go/generator/unmarshal.go | 10 ++++----- 7 files changed, 43 insertions(+), 45 deletions(-) diff --git a/cmd/generate-bindings/solana/anchor-go/generator/accounts.go b/cmd/generate-bindings/solana/anchor-go/generator/accounts.go index efadafe5..9ab08df7 100644 --- a/cmd/generate-bindings/solana/anchor-go/generator/accounts.go +++ b/cmd/generate-bindings/solana/anchor-go/generator/accounts.go @@ -154,7 +154,7 @@ func (g *Generator) gen_IDLTypeDefTyStruct( // TODO: optionality for complex enums is a nil interface. uniqueFieldName := uniqueFieldNames[field.Name] - fieldsGroup.Add(genFieldWithName(field, uniqueFieldName, optionality)). + fieldsGroup.Add(g.genFieldWithName(field, uniqueFieldName, optionality)). Add(func() Code { tagMap := map[string]string{} if IsOption(field.Ty) { @@ -180,7 +180,7 @@ func (g *Generator) gen_IDLTypeDefTyStruct( fieldsGroup.Line() optionality := IsOption(field) || IsCOption(field) - fieldsGroup.Add(genFieldNamed( + fieldsGroup.Add(g.genFieldNamed( FormatTupleItemName(fieldIndex), field, optionality, @@ -223,7 +223,7 @@ func (g *Generator) gen_IDLTypeDefTyStruct( // Declare MarshalWithEncoder: // TODO: code.Line().Line().Add( - gen_MarshalWithEncoder_struct( + g.gen_MarshalWithEncoder_struct( g.idl, withDiscriminator, exportedAccountName, @@ -234,7 +234,7 @@ func (g *Generator) gen_IDLTypeDefTyStruct( // Declare UnmarshalWithDecoder code.Line().Line().Add( - gen_UnmarshalWithDecoder_struct( + g.gen_UnmarshalWithDecoder_struct( g.idl, withDiscriminator, exportedAccountName, @@ -284,20 +284,19 @@ func generateUniqueFieldNames(fields []idl.IdlField) map[string]string { return fieldNameMap } -func genField(field idl.IdlField, pointer bool) Code { - return genFieldNamed(field.Name, field.Ty, pointer) +func (g *Generator) genField(field idl.IdlField, pointer bool) Code { + return g.genFieldNamed(field.Name, field.Ty, pointer) } -// genFieldWithName generates a field with a custom field name (for handling duplicates) -func genFieldWithName(field idl.IdlField, fieldName string, pointer bool) Code { - return genFieldNamed(fieldName, field.Ty, pointer) +func (g *Generator) genFieldWithName(field idl.IdlField, fieldName string, pointer bool) Code { + return g.genFieldNamed(fieldName, field.Ty, pointer) } -func genFieldNamed(name string, typ idltype.IdlType, pointer bool) Code { +func (g *Generator) genFieldNamed(name string, typ idltype.IdlType, pointer bool) Code { st := newStatement() st.Id(tools.ToCamelUpper(name)). Add(func() Code { - if isComplexEnum(typ) { + if g.isComplexEnum(typ) { return nil } if pointer { diff --git a/cmd/generate-bindings/solana/anchor-go/generator/complex-enums.go b/cmd/generate-bindings/solana/anchor-go/generator/complex-enums.go index a5bd2bf5..6755fe16 100644 --- a/cmd/generate-bindings/solana/anchor-go/generator/complex-enums.go +++ b/cmd/generate-bindings/solana/anchor-go/generator/complex-enums.go @@ -6,33 +6,30 @@ import ( "github.com/gagliardetto/anchor-go/idl/idltype" ) -// typeRegistryComplexEnum contains all types that are a complex enum (and thus implemented as an interface). -var typeRegistryComplexEnum = make(map[string]struct{}) - -func isComplexEnum(envel idltype.IdlType) bool { +func (g *Generator) isComplexEnum(envel idltype.IdlType) bool { switch vv := envel.(type) { case *idltype.Defined: - _, ok := typeRegistryComplexEnum[vv.Name] + _, ok := g.complexEnumRegistry[vv.Name] return ok } return false } -func register_TypeName_as_ComplexEnum(name string) { - typeRegistryComplexEnum[name] = struct{}{} +func (g *Generator) registerComplexEnumType(name string) { + g.complexEnumRegistry[name] = struct{}{} } -func registerComplexEnums(def idl.IdlTypeDef) { +func (g *Generator) registerComplexEnums(def idl.IdlTypeDef) { switch vv := def.Ty.(type) { case *idl.IdlTypeDefTyEnum: enumTypeName := def.Name if !vv.IsAllSimple() { - register_TypeName_as_ComplexEnum(enumTypeName) + g.registerComplexEnumType(enumTypeName) } case idl.IdlTypeDefTyEnum: enumTypeName := def.Name if !vv.IsAllSimple() { - register_TypeName_as_ComplexEnum(enumTypeName) + g.registerComplexEnumType(enumTypeName) } } } diff --git a/cmd/generate-bindings/solana/anchor-go/generator/generator.go b/cmd/generate-bindings/solana/anchor-go/generator/generator.go index 4eddb47d..b95e1bc5 100644 --- a/cmd/generate-bindings/solana/anchor-go/generator/generator.go +++ b/cmd/generate-bindings/solana/anchor-go/generator/generator.go @@ -12,8 +12,9 @@ import ( var Debug = false // Set to true to enable debug logging. type Generator struct { - options *GeneratorOptions - idl *idl.Idl + options *GeneratorOptions + idl *idl.Idl + complexEnumRegistry map[string]struct{} } type GeneratorOptions struct { @@ -62,13 +63,14 @@ func (g *Generator) Generate() (*Output, error) { Files: make([]*OutputFile, 0), } + g.complexEnumRegistry = make(map[string]struct{}) + { // Register complex enums. { - // register complex enums: // TODO: .types is the only place where we can find complex enums? (or enums in general?) for _, typ := range g.idl.Types { - registerComplexEnums(typ) + g.registerComplexEnums(typ) } } if len(g.idl.Docs) > 0 { diff --git a/cmd/generate-bindings/solana/anchor-go/generator/instructions.go b/cmd/generate-bindings/solana/anchor-go/generator/instructions.go index 2f8123ba..b0e237b1 100644 --- a/cmd/generate-bindings/solana/anchor-go/generator/instructions.go +++ b/cmd/generate-bindings/solana/anchor-go/generator/instructions.go @@ -134,9 +134,9 @@ func (g *Generator) gen_instructions() (*OutputFile, error) { // ) // } checkNil := true - body.BlockFunc(func(g *Group) { - gen_marshal_DefinedFieldsNamed( - g, + body.BlockFunc(func(grp *Group) { + g.gen_marshal_DefinedFieldsNamed( + grp, instruction.Args, checkNil, func(param idl.IdlField) *Statement { diff --git a/cmd/generate-bindings/solana/anchor-go/generator/marshal.go b/cmd/generate-bindings/solana/anchor-go/generator/marshal.go index d5dd14a2..8984cf8c 100644 --- a/cmd/generate-bindings/solana/anchor-go/generator/marshal.go +++ b/cmd/generate-bindings/solana/anchor-go/generator/marshal.go @@ -10,7 +10,7 @@ import ( "github.com/gagliardetto/anchor-go/tools" ) -func gen_MarshalWithEncoder_struct( +func (g *Generator) gen_MarshalWithEncoder_struct( idl_ *idl.Idl, withDiscriminator bool, receiverTypeName string, @@ -45,7 +45,7 @@ func gen_MarshalWithEncoder_struct( } switch fields := fields.(type) { case idl.IdlDefinedFieldsNamed: - gen_marshal_DefinedFieldsNamed( + g.gen_marshal_DefinedFieldsNamed( body, fields, checkNil, @@ -60,7 +60,7 @@ func gen_MarshalWithEncoder_struct( ) case idl.IdlDefinedFieldsTuple: convertedFields := tupleToFieldsNamed(fields) - gen_marshal_DefinedFieldsNamed( + g.gen_marshal_DefinedFieldsNamed( body, convertedFields, checkNil, @@ -135,7 +135,7 @@ func gen_MarshalWithEncoder_struct( return code } -func gen_marshal_DefinedFieldsNamed( +func (g *Generator) gen_marshal_DefinedFieldsNamed( body *Group, fields idl.IdlDefinedFieldsNamed, checkNil bool, @@ -152,7 +152,7 @@ func gen_marshal_DefinedFieldsNamed( body.Commentf("Serialize `%s`:", exportedArgName) } - if isComplexEnum(field.Ty) || (IsArray(field.Ty) && isComplexEnum(field.Ty.(*idltype.Array).Type)) || (IsVec(field.Ty) && isComplexEnum(field.Ty.(*idltype.Vec).Vec)) { + if g.isComplexEnum(field.Ty) || (IsArray(field.Ty) && g.isComplexEnum(field.Ty.(*idltype.Array).Type)) || (IsVec(field.Ty) && g.isComplexEnum(field.Ty.(*idltype.Vec).Vec)) { switch field.Ty.(type) { case *idltype.Defined: enumTypeName := field.Ty.(*idltype.Defined).Name diff --git a/cmd/generate-bindings/solana/anchor-go/generator/types.go b/cmd/generate-bindings/solana/anchor-go/generator/types.go index d3822fb1..670b9903 100644 --- a/cmd/generate-bindings/solana/anchor-go/generator/types.go +++ b/cmd/generate-bindings/solana/anchor-go/generator/types.go @@ -117,7 +117,7 @@ func (g *Generator) gen_complexEnum(name string, docs []string, typ idl.IdlTypeD // Add comments for the enum type: addComments(code, docs) { - register_TypeName_as_ComplexEnum(name) + g.registerComplexEnumType(name) containerName := formatEnumContainerName(enumTypeName) interfaceMethodName := formatInterfaceMethodName(enumTypeName) @@ -259,7 +259,7 @@ func (g *Generator) gen_complexEnum(name string, docs []string, typ idl.IdlTypeD case idl.IdlDefinedFieldsNamed: for _, variantField := range fields { optionality := IsOption(variantField.Ty) || IsCOption(variantField.Ty) - structGroup.Add(genField(variantField, optionality)). + structGroup.Add(g.genField(variantField, optionality)). Add(func() Code { tagMap := map[string]string{} if IsOption(variantField.Ty) { @@ -282,7 +282,7 @@ func (g *Generator) gen_complexEnum(name string, docs []string, typ idl.IdlTypeD for itemIndex, tupleItem := range fields { optionality := IsOption(tupleItem) || IsCOption(tupleItem) tupleItemName := FormatTupleItemName(itemIndex) - structGroup.Add(genFieldNamed(tupleItemName, tupleItem, optionality)). + structGroup.Add(g.genFieldNamed(tupleItemName, tupleItem, optionality)). Add(func() Code { tagMap := map[string]string{} if IsOption(tupleItem) { @@ -351,7 +351,7 @@ func (g *Generator) gen_complexEnum(name string, docs []string, typ idl.IdlTypeD case idl.IdlDefinedFieldsNamed: // Declare MarshalWithEncoder: code.Line().Line().Add( - gen_MarshalWithEncoder_struct( + g.gen_MarshalWithEncoder_struct( g.idl, false, variantTypeNameComplex, @@ -362,7 +362,7 @@ func (g *Generator) gen_complexEnum(name string, docs []string, typ idl.IdlTypeD // Declare UnmarshalWithDecoder code.Line().Line().Add( - gen_UnmarshalWithDecoder_struct( + g.gen_UnmarshalWithDecoder_struct( g.idl, false, variantTypeNameComplex, @@ -374,7 +374,7 @@ func (g *Generator) gen_complexEnum(name string, docs []string, typ idl.IdlTypeD // TODO: handle tuples // Declare MarshalWithEncoder: code.Line().Line().Add( - gen_MarshalWithEncoder_struct( + g.gen_MarshalWithEncoder_struct( g.idl, false, variantTypeNameComplex, @@ -385,7 +385,7 @@ func (g *Generator) gen_complexEnum(name string, docs []string, typ idl.IdlTypeD // Declare UnmarshalWithDecoder code.Line().Line().Add( - gen_UnmarshalWithDecoder_struct( + g.gen_UnmarshalWithDecoder_struct( g.idl, false, variantTypeNameComplex, diff --git a/cmd/generate-bindings/solana/anchor-go/generator/unmarshal.go b/cmd/generate-bindings/solana/anchor-go/generator/unmarshal.go index 5e7b6a35..7715bff7 100644 --- a/cmd/generate-bindings/solana/anchor-go/generator/unmarshal.go +++ b/cmd/generate-bindings/solana/anchor-go/generator/unmarshal.go @@ -72,7 +72,7 @@ func formatEnumEncoderName(enumTypeName string) string { return "Encode" + enumTypeName } -func gen_UnmarshalWithDecoder_struct( +func (g *Generator) gen_UnmarshalWithDecoder_struct( idl_ *idl.Idl, withDiscriminator bool, receiverTypeName string, @@ -118,10 +118,10 @@ func gen_UnmarshalWithDecoder_struct( switch fields := fields.(type) { case idl.IdlDefinedFieldsNamed: - gen_unmarshal_DefinedFieldsNamed(body, fields) + g.gen_unmarshal_DefinedFieldsNamed(body, fields) case idl.IdlDefinedFieldsTuple: convertedFields := tupleToFieldsNamed(fields) - gen_unmarshal_DefinedFieldsNamed(body, convertedFields) + g.gen_unmarshal_DefinedFieldsNamed(body, convertedFields) case nil: // No fields, just an empty struct. // TODO: should we panic here? @@ -226,7 +226,7 @@ func tupleToFieldsNamed( return fields } -func gen_unmarshal_DefinedFieldsNamed( +func (g *Generator) gen_unmarshal_DefinedFieldsNamed( body *Group, fields idl.IdlDefinedFieldsNamed, ) { @@ -238,7 +238,7 @@ func gen_unmarshal_DefinedFieldsNamed( body.Commentf("Deserialize `%s`:", exportedArgName) } - if isComplexEnum(field.Ty) || (IsArray(field.Ty) && isComplexEnum(field.Ty.(*idltype.Array).Type)) || (IsVec(field.Ty) && isComplexEnum(field.Ty.(*idltype.Vec).Vec)) { + if g.isComplexEnum(field.Ty) || (IsArray(field.Ty) && g.isComplexEnum(field.Ty.(*idltype.Array).Type)) || (IsVec(field.Ty) && g.isComplexEnum(field.Ty.(*idltype.Vec).Vec)) { // TODO: this assumes this cannot be an option; // - check whether this is an option? switch field.Ty.(type) { From ff4d438d4cd7bff6f01fd1f151424603fb33c128 Mon Sep 17 00:00:00 2001 From: Vladimir Shchukin Date: Tue, 26 May 2026 23:56:46 -0400 Subject: [PATCH 2/2] rm sol generated files --- .../generated/data_feeds_cache/accounts.go | 162 - .../generated/data_feeds_cache/constants.go | 4 - .../generated/data_feeds_cache/constructor.go | 112 - .../data_feeds_cache/discriminators.go | 53 - .../src/generated/data_feeds_cache/doc.go | 10 - .../src/generated/data_feeds_cache/errors.go | 4 - .../src/generated/data_feeds_cache/events.go | 381 -- .../generated/data_feeds_cache/fetchers.go | 4 - .../data_feeds_cache/instructions.go | 2859 -------------- .../generated/data_feeds_cache/program_id.go | 8 - .../generated/data_feeds_cache/tests_test.go | 4 - .../src/generated/data_feeds_cache/types.go | 3401 ----------------- 12 files changed, 7002 deletions(-) delete mode 100644 contracts/solana/src/generated/data_feeds_cache/accounts.go delete mode 100644 contracts/solana/src/generated/data_feeds_cache/constants.go delete mode 100644 contracts/solana/src/generated/data_feeds_cache/constructor.go delete mode 100644 contracts/solana/src/generated/data_feeds_cache/discriminators.go delete mode 100644 contracts/solana/src/generated/data_feeds_cache/doc.go delete mode 100644 contracts/solana/src/generated/data_feeds_cache/errors.go delete mode 100644 contracts/solana/src/generated/data_feeds_cache/events.go delete mode 100644 contracts/solana/src/generated/data_feeds_cache/fetchers.go delete mode 100644 contracts/solana/src/generated/data_feeds_cache/instructions.go delete mode 100644 contracts/solana/src/generated/data_feeds_cache/program_id.go delete mode 100644 contracts/solana/src/generated/data_feeds_cache/tests_test.go delete mode 100644 contracts/solana/src/generated/data_feeds_cache/types.go diff --git a/contracts/solana/src/generated/data_feeds_cache/accounts.go b/contracts/solana/src/generated/data_feeds_cache/accounts.go deleted file mode 100644 index 49f899d4..00000000 --- a/contracts/solana/src/generated/data_feeds_cache/accounts.go +++ /dev/null @@ -1,162 +0,0 @@ -// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -// This file contains parsers for the accounts defined in the IDL. -// Code generated by https://github.com/smartcontractkit/cre-cli. DO NOT EDIT. - -package data_feeds_cache - -import ( - "fmt" - binary "github.com/gagliardetto/binary" -) - -func ParseAnyAccount(accountData []byte) (any, error) { - decoder := binary.NewBorshDecoder(accountData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek account discriminator: %w", err) - } - switch discriminator { - case Account_CacheState: - value := new(CacheState) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account as CacheState: %w", err) - } - return value, nil - case Account_DecimalReport: - value := new(DecimalReport) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account as DecimalReport: %w", err) - } - return value, nil - case Account_FeedConfig: - value := new(FeedConfig) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account as FeedConfig: %w", err) - } - return value, nil - case Account_ForwarderState: - value := new(ForwarderState) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account as ForwarderState: %w", err) - } - return value, nil - case Account_LegacyFeedsConfig: - value := new(LegacyFeedsConfig) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account as LegacyFeedsConfig: %w", err) - } - return value, nil - default: - return nil, fmt.Errorf("unknown discriminator: %s", binary.FormatDiscriminator(discriminator)) - } -} - -func ParseAccount_CacheState(accountData []byte) (*CacheState, error) { - decoder := binary.NewBorshDecoder(accountData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Account_CacheState { - return nil, fmt.Errorf("expected discriminator %v, got %s", Account_CacheState, binary.FormatDiscriminator(discriminator)) - } - acc := new(CacheState) - err = acc.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account of type CacheState: %w", err) - } - return acc, nil -} - -func (c *Codec) DecodeCacheState(data []byte) (*CacheState, error) { - return ParseAccount_CacheState(data) -} - -func ParseAccount_DecimalReport(accountData []byte) (*DecimalReport, error) { - decoder := binary.NewBorshDecoder(accountData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Account_DecimalReport { - return nil, fmt.Errorf("expected discriminator %v, got %s", Account_DecimalReport, binary.FormatDiscriminator(discriminator)) - } - acc := new(DecimalReport) - err = acc.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account of type DecimalReport: %w", err) - } - return acc, nil -} - -func (c *Codec) DecodeDecimalReport(data []byte) (*DecimalReport, error) { - return ParseAccount_DecimalReport(data) -} - -func ParseAccount_FeedConfig(accountData []byte) (*FeedConfig, error) { - decoder := binary.NewBorshDecoder(accountData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Account_FeedConfig { - return nil, fmt.Errorf("expected discriminator %v, got %s", Account_FeedConfig, binary.FormatDiscriminator(discriminator)) - } - acc := new(FeedConfig) - err = acc.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account of type FeedConfig: %w", err) - } - return acc, nil -} - -func (c *Codec) DecodeFeedConfig(data []byte) (*FeedConfig, error) { - return ParseAccount_FeedConfig(data) -} - -func ParseAccount_ForwarderState(accountData []byte) (*ForwarderState, error) { - decoder := binary.NewBorshDecoder(accountData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Account_ForwarderState { - return nil, fmt.Errorf("expected discriminator %v, got %s", Account_ForwarderState, binary.FormatDiscriminator(discriminator)) - } - acc := new(ForwarderState) - err = acc.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account of type ForwarderState: %w", err) - } - return acc, nil -} - -func (c *Codec) DecodeForwarderState(data []byte) (*ForwarderState, error) { - return ParseAccount_ForwarderState(data) -} - -func ParseAccount_LegacyFeedsConfig(accountData []byte) (*LegacyFeedsConfig, error) { - decoder := binary.NewBorshDecoder(accountData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Account_LegacyFeedsConfig { - return nil, fmt.Errorf("expected discriminator %v, got %s", Account_LegacyFeedsConfig, binary.FormatDiscriminator(discriminator)) - } - acc := new(LegacyFeedsConfig) - err = acc.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account of type LegacyFeedsConfig: %w", err) - } - return acc, nil -} - -func (c *Codec) DecodeLegacyFeedsConfig(data []byte) (*LegacyFeedsConfig, error) { - return ParseAccount_LegacyFeedsConfig(data) -} diff --git a/contracts/solana/src/generated/data_feeds_cache/constants.go b/contracts/solana/src/generated/data_feeds_cache/constants.go deleted file mode 100644 index 84ba5e8e..00000000 --- a/contracts/solana/src/generated/data_feeds_cache/constants.go +++ /dev/null @@ -1,4 +0,0 @@ -// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -// This file contains constants. - -package data_feeds_cache diff --git a/contracts/solana/src/generated/data_feeds_cache/constructor.go b/contracts/solana/src/generated/data_feeds_cache/constructor.go deleted file mode 100644 index 2c4d6607..00000000 --- a/contracts/solana/src/generated/data_feeds_cache/constructor.go +++ /dev/null @@ -1,112 +0,0 @@ -// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -// This file contains the constructor for the program. - -package data_feeds_cache - -import ( - "bytes" - "encoding/binary" - sdk "github.com/smartcontractkit/chainlink-protos/cre/go/sdk" - solana "github.com/smartcontractkit/cre-sdk-go/capabilities/blockchain/solana" - bindings "github.com/smartcontractkit/cre-sdk-go/capabilities/blockchain/solana/bindings" - cre "github.com/smartcontractkit/cre-sdk-go/cre" -) - -var IDL = "{\"address\":\"3kX63udXtYcsdj2737Wi2KGd2PhqiKPgAFAxstrjtRUa\",\"metadata\":{\"name\":\"data_feeds_cache\",\"version\":\"0.1.0\",\"spec\":\"0.1.0\",\"description\":\"Created with Anchor\"},\"docs\":[\"Data Feed Cache receives report updates from an pre-authorized Forwarder authority (sender)\",\"only for pre-authorized data ids and workflows.\",\"Feed Admins are highly priveleged roles who can unilaterally edit the configuration of feeds\",\"and the authorization of workflows.\"],\"instructions\":[{\"name\":\"accept_ownership\",\"docs\":[\"Step 2 of 2-step ownership process: accept ownership\"],\"discriminator\":[172,23,43,13,238,213,85,150],\"accounts\":[{\"name\":\"new_owner\",\"signer\":true},{\"name\":\"state\",\"writable\":true}],\"args\":[]},{\"name\":\"close_decimal_report\",\"docs\":[\"Closes the data id's associated decimal report account and feed config account.\",\"The feed config must have an empty workflow metadata list, by calling\",\"`set_decimal_feeds_config` prior to clear out the workflow metadata and\",\"close write permission flag accounts\"],\"discriminator\":[15,125,64,179,200,37,232,175],\"accounts\":[{\"name\":\"feed_admin\",\"writable\":true,\"signer\":true},{\"name\":\"state\"},{\"name\":\"decimal_report\",\"writable\":true},{\"name\":\"feed_config\",\"writable\":true}],\"args\":[{\"name\":\"data_id\",\"type\":{\"array\":[\"u8\",16]}}]},{\"name\":\"close_legacy_feeds_config\",\"docs\":[\"Closes the legacy feeds config. Only to be used once all legacy feeds are\",\"no longer used.\"],\"discriminator\":[160,24,243,158,44,206,6,172],\"accounts\":[{\"name\":\"owner\",\"writable\":true,\"signer\":true},{\"name\":\"state\"},{\"name\":\"legacy_feeds_config\",\"writable\":true}],\"args\":[]},{\"name\":\"init_decimal_reports\",\"docs\":[\"Create decimal report accounts, where report data lives (i.e answer, timestamp, etc.)\",\"Recommended limit of N = 20 data ids can be initialized at once.\",\"The decimal report account and feed config account must exist before reports can\",\"be received successfully in `on_report`\"],\"discriminator\":[87,82,35,252,161,44,178,58],\"accounts\":[{\"name\":\"feed_admin\",\"writable\":true,\"signer\":true},{\"name\":\"state\"},{\"name\":\"system_program\"}],\"args\":[{\"name\":\"data_ids\",\"type\":{\"vec\":{\"array\":[\"u8\",16]}}}]},{\"name\":\"init_legacy_feeds_config\",\"docs\":[\"Initializes the legacy feeds config account, which stores the legacy store program\",\"and data id to legacy feed account mappings for double writing if enabled.\",\"Write disabled flags are set to 0 by default (writes enabled), however if\",\"optional legacy accounts are omitted in `on_report` context no legacy writes will occur\",\"(see `on_report`).\",\"Recommended limit of 15 legacy feeds can be initialized at once.\",\"Instruction does not verify internally if data id and associated legacy feed account\",\"are correct pairs or if aforementioned legacy feed account is owned by the legacy store.\"],\"discriminator\":[17,239,221,132,185,117,103,77],\"accounts\":[{\"name\":\"owner\",\"writable\":true,\"signer\":true},{\"name\":\"state\"},{\"name\":\"legacy_store\"},{\"name\":\"legacy_feeds_config\",\"writable\":true},{\"name\":\"system_program\"}],\"args\":[{\"name\":\"data_ids\",\"type\":{\"vec\":{\"array\":[\"u8\",16]}}}]},{\"name\":\"initialize\",\"docs\":[\"Creates a new data cache instance with a dedicated state account.\",\"Sets the initial feed admins and state configuration.\"],\"discriminator\":[175,175,109,31,13,152,155,237],\"accounts\":[{\"name\":\"owner\",\"writable\":true,\"signer\":true},{\"name\":\"state\",\"writable\":true,\"signer\":true},{\"name\":\"forwarder_program\",\"docs\":[\"the actual program id on chain may have been generated through a different mechanism\"]},{\"name\":\"system_program\"}],\"args\":[{\"name\":\"feed_admins\",\"type\":{\"vec\":\"pubkey\"}}]},{\"name\":\"on_report\",\"docs\":[\"Receives the a forwarder report that contains a list of [`ReceivedDecimalReport`]\",\"Maximum amount of 6 ReceivedDecimalReports can be included in the report before\",\"the transaction limit will be exceeded.\",\"For calculation look to ../../docs/data-feeds-cache/README.md#L579\",\"There are three optional accounts, all related to legacy feed writing.\",\"If you omit any of these or have write_disabled = 1 for all feeds\",\"then we guarentee no legacy feeds will be written to.\"],\"discriminator\":[214,173,18,221,173,148,151,208],\"accounts\":[{\"name\":\"forwarder_state\"},{\"name\":\"forwarder_authority\",\"signer\":true},{\"name\":\"cache_state\"},{\"name\":\"legacy_store\",\"optional\":true},{\"name\":\"legacy_feeds_config\",\"optional\":true},{\"name\":\"legacy_writer\",\"optional\":true}],\"args\":[{\"name\":\"metadata\",\"type\":\"bytes\"},{\"name\":\"report\",\"type\":\"bytes\"}]},{\"name\":\"preview_decimal_feed_configs\",\"docs\":[\"An instruction which is only meant to be simulated off-chain. This instruction\",\"does nothing beyond returning a list of permission accounts to be closed when\",\"calling `set_decimal_feed_configs`. No account state changes in this function.\",\"You should call this function before calling `set_decimal_feed_configs` in order\",\"to know the write permission accounts that must be passed into the `set_decimal_feed_configs`\",\"context to be closed.\"],\"discriminator\":[143,191,130,189,199,99,21,20],\"accounts\":[{\"name\":\"state\"}],\"args\":[{\"name\":\"data_ids\",\"type\":{\"vec\":{\"array\":[\"u8\",16]}}},{\"name\":\"descriptions\",\"type\":{\"vec\":{\"array\":[\"u8\",32]}}},{\"name\":\"workflow_metadatas\",\"type\":{\"vec\":{\"defined\":{\"name\":\"WorkflowMetadata\"}}}}],\"returns\":{\"vec\":\"pubkey\"}},{\"name\":\"query_feed_metadata\",\"docs\":[\"Returns a feed's workflow metadata. Chunks return\",\"values by `max_count`.\",\"Can be used on-chain to verify a feed's configuration.\",\"If `start_index` is out of bounds the function will return an\",\"empty array.\",\"If `max_count = 0` then function will return the entire\",\"workflow metadata list.\"],\"discriminator\":[15,34,2,194,151,1,220,249],\"accounts\":[{\"name\":\"cache_state\"},{\"name\":\"feed_config\"}],\"args\":[{\"name\":\"_data_id\",\"type\":{\"array\":[\"u8\",16]}},{\"name\":\"start_index\",\"type\":\"u8\"},{\"name\":\"max_count\",\"type\":\"u8\"}],\"returns\":{\"vec\":{\"defined\":{\"name\":\"WorkflowMetadata\"}}}},{\"name\":\"query_values\",\"docs\":[\"The data ids passed in must match the ordering of the decimal report accounts\",\"passed into the remaining account context.\"],\"discriminator\":[54,59,186,144,227,236,61,188],\"accounts\":[{\"name\":\"cache_state\"}],\"args\":[{\"name\":\"data_ids\",\"type\":{\"vec\":{\"array\":[\"u8\",16]}}}],\"returns\":{\"vec\":{\"defined\":{\"name\":\"DecimalReport\"}}}},{\"name\":\"set_decimal_feed_configs\",\"docs\":[\"Given N data ids and M workflows, configures N feed config accounts and N*M write permission accounts.\",\"Creates feed config and permission accounts where they do not exist.\",\"All feed config accounts and permission accounts are passed as ctx.remaining_accounts (see SetDecimalFeedConfigs context).\",\"If you'd like to prepare the feed config account for closing by calling `close_decimal_report` you need to\",\"set the data id's feed config to an empty workflow metadata and [0; 32] (empty) description.\",\"Because there are two variables N and M which directly influence the size, the table in\",\"docs/data-feeds-cache/README.md#L297 shows safe ranges for N and M as guidelines.\"],\"discriminator\":[69,240,155,225,111,33,32,66],\"accounts\":[{\"name\":\"feed_admin\",\"writable\":true,\"signer\":true},{\"name\":\"state\"},{\"name\":\"system_program\"}],\"args\":[{\"name\":\"data_ids\",\"type\":{\"vec\":{\"array\":[\"u8\",16]}}},{\"name\":\"descriptions\",\"type\":{\"vec\":{\"array\":[\"u8\",32]}}},{\"name\":\"workflow_metadatas\",\"type\":{\"vec\":{\"defined\":{\"name\":\"WorkflowMetadata\"}}}}]},{\"name\":\"set_feed_admin\",\"docs\":[\"Add or remove a feed admin.\",\"Feed Admins are highly priveleged roles who can unilaterally edit the configuration of feeds\",\"and the authorization of workflows.\"],\"discriminator\":[211,48,243,150,226,199,26,136],\"accounts\":[{\"name\":\"owner\",\"signer\":true},{\"name\":\"state\",\"writable\":true}],\"args\":[{\"name\":\"admin\",\"type\":\"pubkey\"},{\"name\":\"is_admin\",\"type\":\"bool\"}]},{\"name\":\"transfer_ownership\",\"docs\":[\"Step 1 of 2-step ownership process: propose a new owner\"],\"discriminator\":[65,177,215,73,53,45,99,47],\"accounts\":[{\"name\":\"owner\",\"signer\":true},{\"name\":\"state\",\"writable\":true}],\"args\":[{\"name\":\"proposed_owner\",\"type\":\"pubkey\"}]},{\"name\":\"update_forwarder_id\",\"docs\":[\"Not to be used in normal circumstances unless the original forwarder\",\"undergoes maintenance.\"],\"discriminator\":[171,157,65,47,251,113,255,46],\"accounts\":[{\"name\":\"owner\",\"signer\":true},{\"name\":\"state\",\"writable\":true},{\"name\":\"forwarder_program\",\"docs\":[\"the actual program id on chain may have been generated through a different mechanism\"]}],\"args\":[]},{\"name\":\"update_legacy_feeds_config\",\"docs\":[\"Updates legacy feed config.\",\"Recommended limit of 15 legacy feeds can be updated at once.\",\"Instruction does not verify internally if data id and associated legacy feed account\",\"are correct pairs or if aforementioned legacy feed account is owned by the legacy store.\"],\"discriminator\":[241,2,112,110,169,254,252,44],\"accounts\":[{\"name\":\"owner\",\"writable\":true,\"signer\":true},{\"name\":\"state\"},{\"name\":\"legacy_store\"},{\"name\":\"legacy_feeds_config\",\"writable\":true}],\"args\":[{\"name\":\"data_ids\",\"type\":{\"vec\":{\"array\":[\"u8\",16]}}},{\"name\":\"write_disabled\",\"type\":{\"vec\":\"bool\"}}]}],\"accounts\":[{\"name\":\"CacheState\",\"discriminator\":[50,155,248,164,94,213,5,207]},{\"name\":\"DecimalReport\",\"discriminator\":[76,136,231,103,56,74,228,250]},{\"name\":\"FeedConfig\",\"discriminator\":[75,97,12,15,89,221,78,71]},{\"name\":\"ForwarderState\",\"discriminator\":[211,150,18,11,12,158,235,175]},{\"name\":\"LegacyFeedsConfig\",\"discriminator\":[12,51,197,142,51,196,138,153]}],\"events\":[{\"name\":\"CacheInitialized\",\"discriminator\":[224,184,123,189,45,184,204,177]},{\"name\":\"DecimalFeedConfigSet\",\"discriminator\":[146,166,103,68,94,131,150,201]},{\"name\":\"DecimalReportClosed\",\"discriminator\":[122,95,223,41,96,49,126,74]},{\"name\":\"DecimalReportInitialized\",\"discriminator\":[179,48,201,187,92,14,58,174]},{\"name\":\"DecimalReportUpdated\",\"discriminator\":[22,65,41,137,113,131,185,67]},{\"name\":\"FeedAdminUpdated\",\"discriminator\":[176,188,86,155,192,145,175,52]},{\"name\":\"ForwarderUpdated\",\"discriminator\":[91,195,248,117,50,125,217,251]},{\"name\":\"InvalidUpdatePermission\",\"discriminator\":[140,196,100,239,180,175,183,154]},{\"name\":\"LegacyFeedsConfigInitialized\",\"discriminator\":[184,138,105,90,6,213,19,159]},{\"name\":\"LegacyFeedsConfigUpdated\",\"discriminator\":[93,166,35,139,151,131,196,108]},{\"name\":\"LegacyFeedsReported\",\"discriminator\":[251,139,216,35,35,31,108,6]},{\"name\":\"OwnershipAcceptance\",\"discriminator\":[210,153,45,4,216,55,115,233]},{\"name\":\"OwnershipTransfer\",\"discriminator\":[182,234,119,37,105,210,22,38]},{\"name\":\"ReceivedDecimalReportsSchema\",\"discriminator\":[252,197,106,23,119,120,186,69]},{\"name\":\"StaleDecimalReport\",\"discriminator\":[111,26,116,235,108,211,34,85]}],\"errors\":[{\"code\":6000,\"name\":\"EmptyConfig\",\"msg\":\"config is empty\"},{\"code\":6001,\"name\":\"ArrayLengthMismatch\",\"msg\":\"array length should be equal\"},{\"code\":6002,\"name\":\"InvalidDataId\",\"msg\":\"invalid data id\"},{\"code\":6003,\"name\":\"InvalidAccountCount\",\"msg\":\"invalid number of accounts\"},{\"code\":6004,\"name\":\"AccountMismatch\",\"msg\":\"account mismatch\"},{\"code\":6005,\"name\":\"InvalidAddress\",\"msg\":\"invalid address\"},{\"code\":6006,\"name\":\"InvalidWorkflowName\",\"msg\":\"invalid workflow name\"},{\"code\":6007,\"name\":\"MaxWorkflowsExceeded\",\"msg\":\"exceeded max amount allowed\"},{\"code\":6008,\"name\":\"AddressesMustStrictlyIncrease\",\"msg\":\"addresses must strictly increase\"},{\"code\":6009,\"name\":\"OutOfBounds\",\"msg\":\"out of bounds\"},{\"code\":6010,\"name\":\"IdsMustStrictlyIncrease\",\"msg\":\"ids must strictly increase\"},{\"code\":6011,\"name\":\"MissingLegacyFeedAccount\",\"msg\":\"missing legacy feed account\"},{\"code\":6012,\"name\":\"FeedNotConfigured\",\"msg\":\"feed not configured\"},{\"code\":6013,\"name\":\"InvalidLength\",\"msg\":\"invalid length\"},{\"code\":6014,\"name\":\"MalformedReport\",\"msg\":\"malformed report\"},{\"code\":6015,\"name\":\"FailedLegacyWrite\",\"msg\":\"failed legacy write\"},{\"code\":6016,\"name\":\"InvalidProposedOwner\",\"msg\":\"Invalid proposed owner\"},{\"code\":6017,\"name\":\"FeedConfigListNotEmpty\",\"msg\":\"feed config workflow list not empty\"},{\"code\":6018,\"name\":\"EmptyDescriptionEnforced\",\"msg\":\"empty description enforced\"},{\"code\":6019,\"name\":\"InvalidDescription\",\"msg\":\"invalid description\"}],\"types\":[{\"name\":\"AccountList\",\"docs\":[\"Fixed size struct which stores list of public keys\"],\"serialization\":\"bytemuck\",\"repr\":{\"kind\":\"c\"},\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"xs\",\"type\":{\"array\":[\"pubkey\",64]}},{\"name\":\"len\",\"type\":\"u64\"}]}},{\"name\":\"CacheInitialized\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"state\",\"type\":\"pubkey\"},{\"name\":\"forwarder_id\",\"type\":\"pubkey\"},{\"name\":\"legacy_writer_bump\",\"type\":\"u8\"}]}},{\"name\":\"CacheState\",\"docs\":[\"Cache State account contains owners and admin\",\"information in addition to the bump/nonce for the\",\"PDA which writes to legacy data feeds\"],\"serialization\":\"bytemuck\",\"repr\":{\"kind\":\"c\"},\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"owner\",\"type\":\"pubkey\"},{\"name\":\"proposed_owner\",\"type\":\"pubkey\"},{\"name\":\"feed_admins\",\"type\":{\"defined\":{\"name\":\"AccountList\"}}},{\"name\":\"forwarder_id\",\"type\":\"pubkey\"},{\"name\":\"legacy_writer_bump\",\"type\":\"u8\"},{\"name\":\"_padding\",\"type\":{\"array\":[\"u8\",7]}}]}},{\"name\":\"DecimalFeedConfigSet\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"state\",\"type\":\"pubkey\"},{\"name\":\"data_id\",\"type\":{\"array\":[\"u8\",16]}},{\"name\":\"decimals\",\"type\":\"u8\"},{\"name\":\"description\",\"type\":{\"array\":[\"u8\",32]}},{\"name\":\"workflow_metadatas\",\"type\":{\"vec\":{\"defined\":{\"name\":\"WorkflowMetadata\"}}}}]}},{\"name\":\"DecimalReport\",\"docs\":[\"Decimal Report stored\"],\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"timestamp\",\"type\":\"u32\"},{\"name\":\"answer\",\"type\":\"u128\"}]}},{\"name\":\"DecimalReportClosed\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"state\",\"type\":\"pubkey\"},{\"name\":\"data_id\",\"type\":{\"array\":[\"u8\",16]}}]}},{\"name\":\"DecimalReportInitialized\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"state\",\"type\":\"pubkey\"},{\"name\":\"data_id\",\"type\":{\"array\":[\"u8\",16]}}]}},{\"name\":\"DecimalReportUpdated\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"state\",\"type\":\"pubkey\"},{\"name\":\"data_id\",\"type\":{\"array\":[\"u8\",16]}},{\"name\":\"timestamp\",\"type\":\"u32\"},{\"name\":\"answer\",\"type\":\"u128\"}]}},{\"name\":\"FeedAdminUpdated\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"state\",\"type\":\"pubkey\"},{\"name\":\"admin\",\"type\":\"pubkey\"},{\"name\":\"is_admin\",\"type\":\"bool\"}]}},{\"name\":\"FeedConfig\",\"docs\":[\"Contains feed information such as description\",\"and the authorized workflows permitted to\",\"report on the data id. Account key is derived by the data id.\"],\"serialization\":\"bytemuck\",\"repr\":{\"kind\":\"c\"},\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"description\",\"type\":{\"array\":[\"u8\",32]}},{\"name\":\"workflow_metadata\",\"type\":{\"defined\":{\"name\":\"WorkflowMetadataList\"}}}]}},{\"name\":\"ForwarderState\",\"docs\":[\"Account which represents a distinct instance of a forwarder.\"],\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"version\",\"type\":\"u8\"},{\"name\":\"owner\",\"type\":\"pubkey\"},{\"name\":\"proposed_owner\",\"type\":\"pubkey\"}]}},{\"name\":\"ForwarderUpdated\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"previous_forwarder\",\"type\":\"pubkey\"},{\"name\":\"new_forwarder\",\"type\":\"pubkey\"}]}},{\"name\":\"InvalidUpdatePermission\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"state\",\"type\":\"pubkey\"},{\"name\":\"data_id\",\"type\":{\"array\":[\"u8\",16]}},{\"name\":\"sender\",\"type\":\"pubkey\"},{\"name\":\"workflow_owner\",\"type\":{\"array\":[\"u8\",20]}},{\"name\":\"workflow_name\",\"type\":{\"array\":[\"u8\",10]}}]}},{\"name\":\"LegacyFeedEntry\",\"docs\":[\"Contains config information of a legacy feed\"],\"serialization\":\"bytemuck\",\"repr\":{\"kind\":\"c\"},\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"data_id\",\"type\":{\"array\":[\"u8\",16]}},{\"name\":\"legacy_feed\",\"type\":\"pubkey\"},{\"name\":\"write_disabled\",\"type\":\"u8\"}]}},{\"name\":\"LegacyFeedList\",\"docs\":[\"Fixed size struct which stores list of legacy feed entries.\"],\"serialization\":\"bytemuck\",\"repr\":{\"kind\":\"c\"},\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"xs\",\"type\":{\"array\":[{\"defined\":{\"name\":\"LegacyFeedEntry\"}},64]}},{\"name\":\"len\",\"type\":\"u64\"}]}},{\"name\":\"LegacyFeedsConfig\",\"docs\":[\"Stores data ids which are flagged to have their reports written to\",\"the legacy store program as well.\",\"We can assume there's only going to be a limited amount of legacy feeds to write to\"],\"serialization\":\"bytemuck\",\"repr\":{\"kind\":\"c\"},\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"id_to_feed\",\"type\":{\"defined\":{\"name\":\"LegacyFeedList\"}}},{\"name\":\"legacy_store\",\"type\":\"pubkey\"}]}},{\"name\":\"LegacyFeedsConfigInitialized\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"state\",\"type\":\"pubkey\"},{\"name\":\"config\",\"type\":\"pubkey\"}]}},{\"name\":\"LegacyFeedsConfigUpdated\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"state\",\"type\":\"pubkey\"},{\"name\":\"config\",\"type\":\"pubkey\"}]}},{\"name\":\"LegacyFeedsReported\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"state\",\"type\":\"pubkey\"},{\"name\":\"feeds_skipped\",\"type\":{\"vec\":{\"array\":[\"u8\",16]}}},{\"name\":\"feeds_written\",\"type\":{\"vec\":{\"array\":[\"u8\",16]}}}]}},{\"name\":\"OwnershipAcceptance\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"state\",\"type\":\"pubkey\"},{\"name\":\"previous_owner\",\"type\":\"pubkey\"},{\"name\":\"new_owner\",\"type\":\"pubkey\"}]}},{\"name\":\"OwnershipTransfer\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"state\",\"type\":\"pubkey\"},{\"name\":\"current_owner\",\"type\":\"pubkey\"},{\"name\":\"proposed_owner\",\"type\":\"pubkey\"}]}},{\"name\":\"ReceivedDecimalReport\",\"docs\":[\"Decimal report received by the cache from the forwarder\"],\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"timestamp\",\"type\":\"u32\"},{\"name\":\"answer\",\"type\":\"u128\"},{\"name\":\"data_id\",\"type\":{\"array\":[\"u8\",16]}}]}},{\"name\":\"ReceivedDecimalReportsSchema\",\"docs\":[\"IDL exposure helper: surfaces `ReceivedDecimalReport` in the generated IDL\",\"so off-chain bindings can construct the `on_report` payload without\",\"re-declaring the wire schema. This event is intentionally never emitted\",\"by the program; declaring it is sufficient for Anchor's IDL generator to\",\"pull `ReceivedDecimalReport` into `types`.\"],\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"reports\",\"type\":{\"vec\":{\"defined\":{\"name\":\"ReceivedDecimalReport\"}}}}]}},{\"name\":\"StaleDecimalReport\",\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"state\",\"type\":\"pubkey\"},{\"name\":\"data_id\",\"type\":{\"array\":[\"u8\",16]}},{\"name\":\"received_timestamp\",\"type\":\"u32\"},{\"name\":\"latest_timestamp\",\"type\":\"u32\"}]}},{\"name\":\"WorkflowMetadata\",\"docs\":[\"Represents information about a workflow which can be used to authorize it\",\"for the reporting of a feed\"],\"serialization\":\"bytemuck\",\"repr\":{\"kind\":\"c\"},\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"allowed_sender\",\"type\":\"pubkey\"},{\"name\":\"allowed_workflow_owner\",\"type\":{\"array\":[\"u8\",20]}},{\"name\":\"allowed_workflow_name\",\"type\":{\"array\":[\"u8\",10]}}]}},{\"name\":\"WorkflowMetadataList\",\"docs\":[\"Fixed size struct which stores list of workflow metadatas\"],\"serialization\":\"bytemuck\",\"repr\":{\"kind\":\"c\"},\"type\":{\"kind\":\"struct\",\"fields\":[{\"name\":\"xs\",\"type\":{\"array\":[{\"defined\":{\"name\":\"WorkflowMetadata\"}},16]}},{\"name\":\"len\",\"type\":\"u64\"}]}}]}" - -type DataFeedsCache struct { - client *solana.Client - Codec DataFeedsCacheCodec -} - -type Codec struct{} - -func NewDataFeedsCache(client *solana.Client) (*DataFeedsCache, error) { - return &DataFeedsCache{ - Codec: &Codec{}, - client: client, - }, nil -} - -// EncodeBorshVecU32 returns Anchor/Borsh encoding of a Vec whose elements are opaque byte payloads. // Each [][]byte element must already be fully serialized for one Vec item on the wire. // Layout: little-endian u32 length followed by concatenated element payloads. -func EncodeBorshVecU32(elements [][]byte) ([]byte, error) { - buf := bytes.NewBuffer(nil) - if err := binary.Write(buf, binary.LittleEndian, uint32(len(elements))); err != nil { - return nil, err - } - for _, elem := range elements { - _, err := buf.Write(elem) - if err != nil { - return nil, err - } - } - return buf.Bytes(), nil -} - -// WriteReportFromBorshEncodedVec publishes through the CRE signer using a forwarder payload built from // Borsh Vec semantics (EncodeBorshVecU32). Compose each elementPayload for your program (e.g. one encoded struct per row). // Pass computeConfig = nil to use the host default Solana compute budget. -func (c *DataFeedsCache) WriteReportFromBorshEncodedVec(runtime cre.Runtime, elementPayloads [][]byte, remainingAccounts []*solana.AccountMeta, computeConfig *solana.ComputeConfig) cre.Promise[*solana.WriteReportReply] { - payload, err := EncodeBorshVecU32(elementPayloads) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: payload, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -type DataFeedsCacheCodec interface { - DecodeCacheState(data []byte) (*CacheState, error) - DecodeDecimalReport(data []byte) (*DecimalReport, error) - DecodeFeedConfig(data []byte) (*FeedConfig, error) - DecodeForwarderState(data []byte) (*ForwarderState, error) - DecodeLegacyFeedsConfig(data []byte) (*LegacyFeedsConfig, error) - EncodeAccountListStruct(in AccountList) ([]byte, error) - EncodeCacheInitializedStruct(in CacheInitialized) ([]byte, error) - EncodeCacheStateStruct(in CacheState) ([]byte, error) - EncodeDecimalFeedConfigSetStruct(in DecimalFeedConfigSet) ([]byte, error) - EncodeDecimalReportStruct(in DecimalReport) ([]byte, error) - EncodeDecimalReportClosedStruct(in DecimalReportClosed) ([]byte, error) - EncodeDecimalReportInitializedStruct(in DecimalReportInitialized) ([]byte, error) - EncodeDecimalReportUpdatedStruct(in DecimalReportUpdated) ([]byte, error) - EncodeFeedAdminUpdatedStruct(in FeedAdminUpdated) ([]byte, error) - EncodeFeedConfigStruct(in FeedConfig) ([]byte, error) - EncodeForwarderStateStruct(in ForwarderState) ([]byte, error) - EncodeForwarderUpdatedStruct(in ForwarderUpdated) ([]byte, error) - EncodeInvalidUpdatePermissionStruct(in InvalidUpdatePermission) ([]byte, error) - EncodeLegacyFeedEntryStruct(in LegacyFeedEntry) ([]byte, error) - EncodeLegacyFeedListStruct(in LegacyFeedList) ([]byte, error) - EncodeLegacyFeedsConfigStruct(in LegacyFeedsConfig) ([]byte, error) - EncodeLegacyFeedsConfigInitializedStruct(in LegacyFeedsConfigInitialized) ([]byte, error) - EncodeLegacyFeedsConfigUpdatedStruct(in LegacyFeedsConfigUpdated) ([]byte, error) - EncodeLegacyFeedsReportedStruct(in LegacyFeedsReported) ([]byte, error) - EncodeOwnershipAcceptanceStruct(in OwnershipAcceptance) ([]byte, error) - EncodeOwnershipTransferStruct(in OwnershipTransfer) ([]byte, error) - EncodeReceivedDecimalReportStruct(in ReceivedDecimalReport) ([]byte, error) - EncodeReceivedDecimalReportsSchemaStruct(in ReceivedDecimalReportsSchema) ([]byte, error) - EncodeStaleDecimalReportStruct(in StaleDecimalReport) ([]byte, error) - EncodeWorkflowMetadataStruct(in WorkflowMetadata) ([]byte, error) - EncodeWorkflowMetadataListStruct(in WorkflowMetadataList) ([]byte, error) -} diff --git a/contracts/solana/src/generated/data_feeds_cache/discriminators.go b/contracts/solana/src/generated/data_feeds_cache/discriminators.go deleted file mode 100644 index aa5040cb..00000000 --- a/contracts/solana/src/generated/data_feeds_cache/discriminators.go +++ /dev/null @@ -1,53 +0,0 @@ -// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -// This file contains the discriminators for accounts and events defined in the IDL. - -package data_feeds_cache - -import binary "github.com/gagliardetto/binary" - -// Account discriminators -var ( - Account_CacheState = binary.TypeID{50, 155, 248, 164, 94, 213, 5, 207} - Account_DecimalReport = binary.TypeID{76, 136, 231, 103, 56, 74, 228, 250} - Account_FeedConfig = binary.TypeID{75, 97, 12, 15, 89, 221, 78, 71} - Account_ForwarderState = binary.TypeID{211, 150, 18, 11, 12, 158, 235, 175} - Account_LegacyFeedsConfig = binary.TypeID{12, 51, 197, 142, 51, 196, 138, 153} -) - -// Event discriminators -var ( - Event_CacheInitialized = binary.TypeID{224, 184, 123, 189, 45, 184, 204, 177} - Event_DecimalFeedConfigSet = binary.TypeID{146, 166, 103, 68, 94, 131, 150, 201} - Event_DecimalReportClosed = binary.TypeID{122, 95, 223, 41, 96, 49, 126, 74} - Event_DecimalReportInitialized = binary.TypeID{179, 48, 201, 187, 92, 14, 58, 174} - Event_DecimalReportUpdated = binary.TypeID{22, 65, 41, 137, 113, 131, 185, 67} - Event_FeedAdminUpdated = binary.TypeID{176, 188, 86, 155, 192, 145, 175, 52} - Event_ForwarderUpdated = binary.TypeID{91, 195, 248, 117, 50, 125, 217, 251} - Event_InvalidUpdatePermission = binary.TypeID{140, 196, 100, 239, 180, 175, 183, 154} - Event_LegacyFeedsConfigInitialized = binary.TypeID{184, 138, 105, 90, 6, 213, 19, 159} - Event_LegacyFeedsConfigUpdated = binary.TypeID{93, 166, 35, 139, 151, 131, 196, 108} - Event_LegacyFeedsReported = binary.TypeID{251, 139, 216, 35, 35, 31, 108, 6} - Event_OwnershipAcceptance = binary.TypeID{210, 153, 45, 4, 216, 55, 115, 233} - Event_OwnershipTransfer = binary.TypeID{182, 234, 119, 37, 105, 210, 22, 38} - Event_ReceivedDecimalReportsSchema = binary.TypeID{252, 197, 106, 23, 119, 120, 186, 69} - Event_StaleDecimalReport = binary.TypeID{111, 26, 116, 235, 108, 211, 34, 85} -) - -// Instruction discriminators -var ( - Instruction_AcceptOwnership = binary.TypeID{172, 23, 43, 13, 238, 213, 85, 150} - Instruction_CloseDecimalReport = binary.TypeID{15, 125, 64, 179, 200, 37, 232, 175} - Instruction_CloseLegacyFeedsConfig = binary.TypeID{160, 24, 243, 158, 44, 206, 6, 172} - Instruction_InitDecimalReports = binary.TypeID{87, 82, 35, 252, 161, 44, 178, 58} - Instruction_InitLegacyFeedsConfig = binary.TypeID{17, 239, 221, 132, 185, 117, 103, 77} - Instruction_Initialize = binary.TypeID{175, 175, 109, 31, 13, 152, 155, 237} - Instruction_OnReport = binary.TypeID{214, 173, 18, 221, 173, 148, 151, 208} - Instruction_PreviewDecimalFeedConfigs = binary.TypeID{143, 191, 130, 189, 199, 99, 21, 20} - Instruction_QueryFeedMetadata = binary.TypeID{15, 34, 2, 194, 151, 1, 220, 249} - Instruction_QueryValues = binary.TypeID{54, 59, 186, 144, 227, 236, 61, 188} - Instruction_SetDecimalFeedConfigs = binary.TypeID{69, 240, 155, 225, 111, 33, 32, 66} - Instruction_SetFeedAdmin = binary.TypeID{211, 48, 243, 150, 226, 199, 26, 136} - Instruction_TransferOwnership = binary.TypeID{65, 177, 215, 73, 53, 45, 99, 47} - Instruction_UpdateForwarderId = binary.TypeID{171, 157, 65, 47, 251, 113, 255, 46} - Instruction_UpdateLegacyFeedsConfig = binary.TypeID{241, 2, 112, 110, 169, 254, 252, 44} -) diff --git a/contracts/solana/src/generated/data_feeds_cache/doc.go b/contracts/solana/src/generated/data_feeds_cache/doc.go deleted file mode 100644 index a8d9ef1e..00000000 --- a/contracts/solana/src/generated/data_feeds_cache/doc.go +++ /dev/null @@ -1,10 +0,0 @@ -// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -// This file contains documentation and example usage for the generated code. - -package data_feeds_cache - -// Documentation from the IDL: -// Data Feed Cache receives report updates from an pre-authorized Forwarder authority (sender) -// only for pre-authorized data ids and workflows. -// Feed Admins are highly priveleged roles who can unilaterally edit the configuration of feeds -// and the authorization of workflows. diff --git a/contracts/solana/src/generated/data_feeds_cache/errors.go b/contracts/solana/src/generated/data_feeds_cache/errors.go deleted file mode 100644 index 32d8614b..00000000 --- a/contracts/solana/src/generated/data_feeds_cache/errors.go +++ /dev/null @@ -1,4 +0,0 @@ -// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -// This file contains errors. - -package data_feeds_cache diff --git a/contracts/solana/src/generated/data_feeds_cache/events.go b/contracts/solana/src/generated/data_feeds_cache/events.go deleted file mode 100644 index 5048c8d3..00000000 --- a/contracts/solana/src/generated/data_feeds_cache/events.go +++ /dev/null @@ -1,381 +0,0 @@ -// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -// This file contains parsers for the events defined in the IDL. - -package data_feeds_cache - -import ( - "fmt" - binary "github.com/gagliardetto/binary" -) - -func ParseAnyEvent(eventData []byte) (any, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek event discriminator: %w", err) - } - switch discriminator { - case Event_CacheInitialized: - value := new(CacheInitialized) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as CacheInitialized: %w", err) - } - return value, nil - case Event_DecimalFeedConfigSet: - value := new(DecimalFeedConfigSet) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as DecimalFeedConfigSet: %w", err) - } - return value, nil - case Event_DecimalReportClosed: - value := new(DecimalReportClosed) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as DecimalReportClosed: %w", err) - } - return value, nil - case Event_DecimalReportInitialized: - value := new(DecimalReportInitialized) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as DecimalReportInitialized: %w", err) - } - return value, nil - case Event_DecimalReportUpdated: - value := new(DecimalReportUpdated) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as DecimalReportUpdated: %w", err) - } - return value, nil - case Event_FeedAdminUpdated: - value := new(FeedAdminUpdated) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as FeedAdminUpdated: %w", err) - } - return value, nil - case Event_ForwarderUpdated: - value := new(ForwarderUpdated) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as ForwarderUpdated: %w", err) - } - return value, nil - case Event_InvalidUpdatePermission: - value := new(InvalidUpdatePermission) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as InvalidUpdatePermission: %w", err) - } - return value, nil - case Event_LegacyFeedsConfigInitialized: - value := new(LegacyFeedsConfigInitialized) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as LegacyFeedsConfigInitialized: %w", err) - } - return value, nil - case Event_LegacyFeedsConfigUpdated: - value := new(LegacyFeedsConfigUpdated) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as LegacyFeedsConfigUpdated: %w", err) - } - return value, nil - case Event_LegacyFeedsReported: - value := new(LegacyFeedsReported) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as LegacyFeedsReported: %w", err) - } - return value, nil - case Event_OwnershipAcceptance: - value := new(OwnershipAcceptance) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as OwnershipAcceptance: %w", err) - } - return value, nil - case Event_OwnershipTransfer: - value := new(OwnershipTransfer) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as OwnershipTransfer: %w", err) - } - return value, nil - case Event_ReceivedDecimalReportsSchema: - value := new(ReceivedDecimalReportsSchema) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as ReceivedDecimalReportsSchema: %w", err) - } - return value, nil - case Event_StaleDecimalReport: - value := new(StaleDecimalReport) - err := value.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event as StaleDecimalReport: %w", err) - } - return value, nil - default: - return nil, fmt.Errorf("unknown discriminator: %s", binary.FormatDiscriminator(discriminator)) - } -} - -func ParseEvent_CacheInitialized(eventData []byte) (*CacheInitialized, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_CacheInitialized { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_CacheInitialized, binary.FormatDiscriminator(discriminator)) - } - event := new(CacheInitialized) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type CacheInitialized: %w", err) - } - return event, nil -} - -func ParseEvent_DecimalFeedConfigSet(eventData []byte) (*DecimalFeedConfigSet, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_DecimalFeedConfigSet { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_DecimalFeedConfigSet, binary.FormatDiscriminator(discriminator)) - } - event := new(DecimalFeedConfigSet) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type DecimalFeedConfigSet: %w", err) - } - return event, nil -} - -func ParseEvent_DecimalReportClosed(eventData []byte) (*DecimalReportClosed, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_DecimalReportClosed { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_DecimalReportClosed, binary.FormatDiscriminator(discriminator)) - } - event := new(DecimalReportClosed) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type DecimalReportClosed: %w", err) - } - return event, nil -} - -func ParseEvent_DecimalReportInitialized(eventData []byte) (*DecimalReportInitialized, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_DecimalReportInitialized { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_DecimalReportInitialized, binary.FormatDiscriminator(discriminator)) - } - event := new(DecimalReportInitialized) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type DecimalReportInitialized: %w", err) - } - return event, nil -} - -func ParseEvent_DecimalReportUpdated(eventData []byte) (*DecimalReportUpdated, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_DecimalReportUpdated { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_DecimalReportUpdated, binary.FormatDiscriminator(discriminator)) - } - event := new(DecimalReportUpdated) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type DecimalReportUpdated: %w", err) - } - return event, nil -} - -func ParseEvent_FeedAdminUpdated(eventData []byte) (*FeedAdminUpdated, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_FeedAdminUpdated { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_FeedAdminUpdated, binary.FormatDiscriminator(discriminator)) - } - event := new(FeedAdminUpdated) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type FeedAdminUpdated: %w", err) - } - return event, nil -} - -func ParseEvent_ForwarderUpdated(eventData []byte) (*ForwarderUpdated, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_ForwarderUpdated { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_ForwarderUpdated, binary.FormatDiscriminator(discriminator)) - } - event := new(ForwarderUpdated) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type ForwarderUpdated: %w", err) - } - return event, nil -} - -func ParseEvent_InvalidUpdatePermission(eventData []byte) (*InvalidUpdatePermission, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_InvalidUpdatePermission { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_InvalidUpdatePermission, binary.FormatDiscriminator(discriminator)) - } - event := new(InvalidUpdatePermission) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type InvalidUpdatePermission: %w", err) - } - return event, nil -} - -func ParseEvent_LegacyFeedsConfigInitialized(eventData []byte) (*LegacyFeedsConfigInitialized, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_LegacyFeedsConfigInitialized { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_LegacyFeedsConfigInitialized, binary.FormatDiscriminator(discriminator)) - } - event := new(LegacyFeedsConfigInitialized) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type LegacyFeedsConfigInitialized: %w", err) - } - return event, nil -} - -func ParseEvent_LegacyFeedsConfigUpdated(eventData []byte) (*LegacyFeedsConfigUpdated, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_LegacyFeedsConfigUpdated { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_LegacyFeedsConfigUpdated, binary.FormatDiscriminator(discriminator)) - } - event := new(LegacyFeedsConfigUpdated) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type LegacyFeedsConfigUpdated: %w", err) - } - return event, nil -} - -func ParseEvent_LegacyFeedsReported(eventData []byte) (*LegacyFeedsReported, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_LegacyFeedsReported { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_LegacyFeedsReported, binary.FormatDiscriminator(discriminator)) - } - event := new(LegacyFeedsReported) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type LegacyFeedsReported: %w", err) - } - return event, nil -} - -func ParseEvent_OwnershipAcceptance(eventData []byte) (*OwnershipAcceptance, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_OwnershipAcceptance { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_OwnershipAcceptance, binary.FormatDiscriminator(discriminator)) - } - event := new(OwnershipAcceptance) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type OwnershipAcceptance: %w", err) - } - return event, nil -} - -func ParseEvent_OwnershipTransfer(eventData []byte) (*OwnershipTransfer, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_OwnershipTransfer { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_OwnershipTransfer, binary.FormatDiscriminator(discriminator)) - } - event := new(OwnershipTransfer) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type OwnershipTransfer: %w", err) - } - return event, nil -} - -func ParseEvent_ReceivedDecimalReportsSchema(eventData []byte) (*ReceivedDecimalReportsSchema, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_ReceivedDecimalReportsSchema { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_ReceivedDecimalReportsSchema, binary.FormatDiscriminator(discriminator)) - } - event := new(ReceivedDecimalReportsSchema) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type ReceivedDecimalReportsSchema: %w", err) - } - return event, nil -} - -func ParseEvent_StaleDecimalReport(eventData []byte) (*StaleDecimalReport, error) { - decoder := binary.NewBorshDecoder(eventData) - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return nil, fmt.Errorf("failed to peek discriminator: %w", err) - } - if discriminator != Event_StaleDecimalReport { - return nil, fmt.Errorf("expected discriminator %v, got %s", Event_StaleDecimalReport, binary.FormatDiscriminator(discriminator)) - } - event := new(StaleDecimalReport) - err = event.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal event of type StaleDecimalReport: %w", err) - } - return event, nil -} diff --git a/contracts/solana/src/generated/data_feeds_cache/fetchers.go b/contracts/solana/src/generated/data_feeds_cache/fetchers.go deleted file mode 100644 index c2526278..00000000 --- a/contracts/solana/src/generated/data_feeds_cache/fetchers.go +++ /dev/null @@ -1,4 +0,0 @@ -// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -// This file contains fetcher functions. - -package data_feeds_cache diff --git a/contracts/solana/src/generated/data_feeds_cache/instructions.go b/contracts/solana/src/generated/data_feeds_cache/instructions.go deleted file mode 100644 index 677fbaf9..00000000 --- a/contracts/solana/src/generated/data_feeds_cache/instructions.go +++ /dev/null @@ -1,2859 +0,0 @@ -// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -// This file contains instructions and instruction parsers. - -package data_feeds_cache - -import ( - "bytes" - "fmt" - errors "github.com/gagliardetto/anchor-go/errors" - binary "github.com/gagliardetto/binary" - solanago "github.com/gagliardetto/solana-go" -) - -// Builds a "accept_ownership" instruction. -// Step 2 of 2-step ownership process: accept ownership -func NewAcceptOwnershipInstruction( - newOwnerAccount solanago.PublicKey, - stateAccount solanago.PublicKey, -) (solanago.Instruction, error) { - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "new_owner": Read-only, Signer, Required - accounts__.Append(solanago.NewAccountMeta(newOwnerAccount, false, true)) - // Account 1 "state": Writable, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(stateAccount, true, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - nil, - ), nil -} - -// Builds a "close_decimal_report" instruction. -// Closes the data id's associated decimal report account and feed config account. // The feed config must have an empty workflow metadata list, by calling // `set_decimal_feeds_config` prior to clear out the workflow metadata and // close write permission flag accounts -func NewCloseDecimalReportInstruction( - // Params: - dataIdParam [16]uint8, - - // Accounts: - feedAdminAccount solanago.PublicKey, - stateAccount solanago.PublicKey, - decimalReportAccount solanago.PublicKey, - feedConfigAccount solanago.PublicKey, -) (solanago.Instruction, error) { - buf__ := new(bytes.Buffer) - enc__ := binary.NewBorshEncoder(buf__) - - // Encode the instruction discriminator. - err := enc__.WriteBytes(Instruction_CloseDecimalReport[:], false) - if err != nil { - return nil, fmt.Errorf("failed to write instruction discriminator: %w", err) - } - { - // Serialize `dataIdParam`: - err = enc__.Encode(dataIdParam) - if err != nil { - return nil, errors.NewField("dataIdParam", err) - } - } - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "feed_admin": Writable, Signer, Required - accounts__.Append(solanago.NewAccountMeta(feedAdminAccount, true, true)) - // Account 1 "state": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(stateAccount, false, false)) - // Account 2 "decimal_report": Writable, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(decimalReportAccount, true, false)) - // Account 3 "feed_config": Writable, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(feedConfigAccount, true, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - buf__.Bytes(), - ), nil -} - -// Builds a "close_legacy_feeds_config" instruction. -// Closes the legacy feeds config. Only to be used once all legacy feeds are // no longer used. -func NewCloseLegacyFeedsConfigInstruction( - ownerAccount solanago.PublicKey, - stateAccount solanago.PublicKey, - legacyFeedsConfigAccount solanago.PublicKey, -) (solanago.Instruction, error) { - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "owner": Writable, Signer, Required - accounts__.Append(solanago.NewAccountMeta(ownerAccount, true, true)) - // Account 1 "state": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(stateAccount, false, false)) - // Account 2 "legacy_feeds_config": Writable, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(legacyFeedsConfigAccount, true, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - nil, - ), nil -} - -// Builds a "init_decimal_reports" instruction. -// Create decimal report accounts, where report data lives (i.e answer, timestamp, etc.) // Recommended limit of N = 20 data ids can be initialized at once. // The decimal report account and feed config account must exist before reports can // be received successfully in `on_report` -func NewInitDecimalReportsInstruction( - // Params: - dataIdsParam [][16]uint8, - - // Accounts: - feedAdminAccount solanago.PublicKey, - stateAccount solanago.PublicKey, - systemProgramAccount solanago.PublicKey, -) (solanago.Instruction, error) { - buf__ := new(bytes.Buffer) - enc__ := binary.NewBorshEncoder(buf__) - - // Encode the instruction discriminator. - err := enc__.WriteBytes(Instruction_InitDecimalReports[:], false) - if err != nil { - return nil, fmt.Errorf("failed to write instruction discriminator: %w", err) - } - { - // Serialize `dataIdsParam`: - err = enc__.Encode(dataIdsParam) - if err != nil { - return nil, errors.NewField("dataIdsParam", err) - } - } - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "feed_admin": Writable, Signer, Required - accounts__.Append(solanago.NewAccountMeta(feedAdminAccount, true, true)) - // Account 1 "state": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(stateAccount, false, false)) - // Account 2 "system_program": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(systemProgramAccount, false, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - buf__.Bytes(), - ), nil -} - -// Builds a "init_legacy_feeds_config" instruction. -// Initializes the legacy feeds config account, which stores the legacy store program // and data id to legacy feed account mappings for double writing if enabled. // Write disabled flags are set to 0 by default (writes enabled), however if // optional legacy accounts are omitted in `on_report` context no legacy writes will occur // (see `on_report`). // Recommended limit of 15 legacy feeds can be initialized at once. // Instruction does not verify internally if data id and associated legacy feed account // are correct pairs or if aforementioned legacy feed account is owned by the legacy store. -func NewInitLegacyFeedsConfigInstruction( - // Params: - dataIdsParam [][16]uint8, - - // Accounts: - ownerAccount solanago.PublicKey, - stateAccount solanago.PublicKey, - legacyStoreAccount solanago.PublicKey, - legacyFeedsConfigAccount solanago.PublicKey, - systemProgramAccount solanago.PublicKey, -) (solanago.Instruction, error) { - buf__ := new(bytes.Buffer) - enc__ := binary.NewBorshEncoder(buf__) - - // Encode the instruction discriminator. - err := enc__.WriteBytes(Instruction_InitLegacyFeedsConfig[:], false) - if err != nil { - return nil, fmt.Errorf("failed to write instruction discriminator: %w", err) - } - { - // Serialize `dataIdsParam`: - err = enc__.Encode(dataIdsParam) - if err != nil { - return nil, errors.NewField("dataIdsParam", err) - } - } - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "owner": Writable, Signer, Required - accounts__.Append(solanago.NewAccountMeta(ownerAccount, true, true)) - // Account 1 "state": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(stateAccount, false, false)) - // Account 2 "legacy_store": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(legacyStoreAccount, false, false)) - // Account 3 "legacy_feeds_config": Writable, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(legacyFeedsConfigAccount, true, false)) - // Account 4 "system_program": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(systemProgramAccount, false, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - buf__.Bytes(), - ), nil -} - -// Builds a "initialize" instruction. -// Creates a new data cache instance with a dedicated state account. // Sets the initial feed admins and state configuration. -func NewInitializeInstruction( - // Params: - feedAdminsParam []solanago.PublicKey, - - // Accounts: - ownerAccount solanago.PublicKey, - stateAccount solanago.PublicKey, - forwarderProgramAccount solanago.PublicKey, - systemProgramAccount solanago.PublicKey, -) (solanago.Instruction, error) { - buf__ := new(bytes.Buffer) - enc__ := binary.NewBorshEncoder(buf__) - - // Encode the instruction discriminator. - err := enc__.WriteBytes(Instruction_Initialize[:], false) - if err != nil { - return nil, fmt.Errorf("failed to write instruction discriminator: %w", err) - } - { - // Serialize `feedAdminsParam`: - err = enc__.Encode(feedAdminsParam) - if err != nil { - return nil, errors.NewField("feedAdminsParam", err) - } - } - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "owner": Writable, Signer, Required - accounts__.Append(solanago.NewAccountMeta(ownerAccount, true, true)) - // Account 1 "state": Writable, Signer, Required - accounts__.Append(solanago.NewAccountMeta(stateAccount, true, true)) - // Account 2 "forwarder_program": Read-only, Non-signer, Required - // the actual program id on chain may have been generated through a different mechanism - accounts__.Append(solanago.NewAccountMeta(forwarderProgramAccount, false, false)) - // Account 3 "system_program": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(systemProgramAccount, false, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - buf__.Bytes(), - ), nil -} - -// Builds a "on_report" instruction. -// Receives the a forwarder report that contains a list of [`ReceivedDecimalReport`] // Maximum amount of 6 ReceivedDecimalReports can be included in the report before // the transaction limit will be exceeded. // For calculation look to ../../docs/data-feeds-cache/README.md#L579 // There are three optional accounts, all related to legacy feed writing. // If you omit any of these or have write_disabled = 1 for all feeds // then we guarentee no legacy feeds will be written to. -func NewOnReportInstruction( - // Params: - metadataParam []byte, - reportParam []byte, - - // Accounts: - forwarderStateAccount solanago.PublicKey, - forwarderAuthorityAccount solanago.PublicKey, - cacheStateAccount solanago.PublicKey, - legacyStoreAccount solanago.PublicKey, - legacyFeedsConfigAccount solanago.PublicKey, - legacyWriterAccount solanago.PublicKey, -) (solanago.Instruction, error) { - buf__ := new(bytes.Buffer) - enc__ := binary.NewBorshEncoder(buf__) - - // Encode the instruction discriminator. - err := enc__.WriteBytes(Instruction_OnReport[:], false) - if err != nil { - return nil, fmt.Errorf("failed to write instruction discriminator: %w", err) - } - { - // Serialize `metadataParam`: - err = enc__.Encode(metadataParam) - if err != nil { - return nil, errors.NewField("metadataParam", err) - } - // Serialize `reportParam`: - err = enc__.Encode(reportParam) - if err != nil { - return nil, errors.NewField("reportParam", err) - } - } - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "forwarder_state": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(forwarderStateAccount, false, false)) - // Account 1 "forwarder_authority": Read-only, Signer, Required - accounts__.Append(solanago.NewAccountMeta(forwarderAuthorityAccount, false, true)) - // Account 2 "cache_state": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(cacheStateAccount, false, false)) - // Account 3 "legacy_store": Read-only, Non-signer, Optional - accounts__.Append(solanago.NewAccountMeta(legacyStoreAccount, false, false)) - // Account 4 "legacy_feeds_config": Read-only, Non-signer, Optional - accounts__.Append(solanago.NewAccountMeta(legacyFeedsConfigAccount, false, false)) - // Account 5 "legacy_writer": Read-only, Non-signer, Optional - accounts__.Append(solanago.NewAccountMeta(legacyWriterAccount, false, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - buf__.Bytes(), - ), nil -} - -// Builds a "preview_decimal_feed_configs" instruction. -// An instruction which is only meant to be simulated off-chain. This instruction // does nothing beyond returning a list of permission accounts to be closed when // calling `set_decimal_feed_configs`. No account state changes in this function. // You should call this function before calling `set_decimal_feed_configs` in order // to know the write permission accounts that must be passed into the `set_decimal_feed_configs` // context to be closed. -func NewPreviewDecimalFeedConfigsInstruction( - // Params: - dataIdsParam [][16]uint8, - descriptionsParam [][32]uint8, - workflowMetadatasParam []WorkflowMetadata, - - // Accounts: - stateAccount solanago.PublicKey, -) (solanago.Instruction, error) { - buf__ := new(bytes.Buffer) - enc__ := binary.NewBorshEncoder(buf__) - - // Encode the instruction discriminator. - err := enc__.WriteBytes(Instruction_PreviewDecimalFeedConfigs[:], false) - if err != nil { - return nil, fmt.Errorf("failed to write instruction discriminator: %w", err) - } - { - // Serialize `dataIdsParam`: - err = enc__.Encode(dataIdsParam) - if err != nil { - return nil, errors.NewField("dataIdsParam", err) - } - // Serialize `descriptionsParam`: - err = enc__.Encode(descriptionsParam) - if err != nil { - return nil, errors.NewField("descriptionsParam", err) - } - // Serialize `workflowMetadatasParam`: - err = enc__.Encode(workflowMetadatasParam) - if err != nil { - return nil, errors.NewField("workflowMetadatasParam", err) - } - } - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "state": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(stateAccount, false, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - buf__.Bytes(), - ), nil -} - -// Builds a "query_feed_metadata" instruction. -// Returns a feed's workflow metadata. Chunks return // values by `max_count`. // Can be used on-chain to verify a feed's configuration. // If `start_index` is out of bounds the function will return an // empty array. // If `max_count = 0` then function will return the entire // workflow metadata list. -func NewQueryFeedMetadataInstruction( - // Params: - dataIdParam [16]uint8, - startIndexParam uint8, - maxCountParam uint8, - - // Accounts: - cacheStateAccount solanago.PublicKey, - feedConfigAccount solanago.PublicKey, -) (solanago.Instruction, error) { - buf__ := new(bytes.Buffer) - enc__ := binary.NewBorshEncoder(buf__) - - // Encode the instruction discriminator. - err := enc__.WriteBytes(Instruction_QueryFeedMetadata[:], false) - if err != nil { - return nil, fmt.Errorf("failed to write instruction discriminator: %w", err) - } - { - // Serialize `dataIdParam`: - err = enc__.Encode(dataIdParam) - if err != nil { - return nil, errors.NewField("dataIdParam", err) - } - // Serialize `startIndexParam`: - err = enc__.Encode(startIndexParam) - if err != nil { - return nil, errors.NewField("startIndexParam", err) - } - // Serialize `maxCountParam`: - err = enc__.Encode(maxCountParam) - if err != nil { - return nil, errors.NewField("maxCountParam", err) - } - } - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "cache_state": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(cacheStateAccount, false, false)) - // Account 1 "feed_config": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(feedConfigAccount, false, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - buf__.Bytes(), - ), nil -} - -// Builds a "query_values" instruction. -// The data ids passed in must match the ordering of the decimal report accounts // passed into the remaining account context. -func NewQueryValuesInstruction( - // Params: - dataIdsParam [][16]uint8, - - // Accounts: - cacheStateAccount solanago.PublicKey, -) (solanago.Instruction, error) { - buf__ := new(bytes.Buffer) - enc__ := binary.NewBorshEncoder(buf__) - - // Encode the instruction discriminator. - err := enc__.WriteBytes(Instruction_QueryValues[:], false) - if err != nil { - return nil, fmt.Errorf("failed to write instruction discriminator: %w", err) - } - { - // Serialize `dataIdsParam`: - err = enc__.Encode(dataIdsParam) - if err != nil { - return nil, errors.NewField("dataIdsParam", err) - } - } - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "cache_state": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(cacheStateAccount, false, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - buf__.Bytes(), - ), nil -} - -// Builds a "set_decimal_feed_configs" instruction. -// Given N data ids and M workflows, configures N feed config accounts and N*M write permission accounts. // Creates feed config and permission accounts where they do not exist. // All feed config accounts and permission accounts are passed as ctx.remaining_accounts (see SetDecimalFeedConfigs context). // If you'd like to prepare the feed config account for closing by calling `close_decimal_report` you need to // set the data id's feed config to an empty workflow metadata and [0; 32] (empty) description. // Because there are two variables N and M which directly influence the size, the table in // docs/data-feeds-cache/README.md#L297 shows safe ranges for N and M as guidelines. -func NewSetDecimalFeedConfigsInstruction( - // Params: - dataIdsParam [][16]uint8, - descriptionsParam [][32]uint8, - workflowMetadatasParam []WorkflowMetadata, - - // Accounts: - feedAdminAccount solanago.PublicKey, - stateAccount solanago.PublicKey, - systemProgramAccount solanago.PublicKey, -) (solanago.Instruction, error) { - buf__ := new(bytes.Buffer) - enc__ := binary.NewBorshEncoder(buf__) - - // Encode the instruction discriminator. - err := enc__.WriteBytes(Instruction_SetDecimalFeedConfigs[:], false) - if err != nil { - return nil, fmt.Errorf("failed to write instruction discriminator: %w", err) - } - { - // Serialize `dataIdsParam`: - err = enc__.Encode(dataIdsParam) - if err != nil { - return nil, errors.NewField("dataIdsParam", err) - } - // Serialize `descriptionsParam`: - err = enc__.Encode(descriptionsParam) - if err != nil { - return nil, errors.NewField("descriptionsParam", err) - } - // Serialize `workflowMetadatasParam`: - err = enc__.Encode(workflowMetadatasParam) - if err != nil { - return nil, errors.NewField("workflowMetadatasParam", err) - } - } - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "feed_admin": Writable, Signer, Required - accounts__.Append(solanago.NewAccountMeta(feedAdminAccount, true, true)) - // Account 1 "state": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(stateAccount, false, false)) - // Account 2 "system_program": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(systemProgramAccount, false, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - buf__.Bytes(), - ), nil -} - -// Builds a "set_feed_admin" instruction. -// Add or remove a feed admin. // Feed Admins are highly priveleged roles who can unilaterally edit the configuration of feeds // and the authorization of workflows. -func NewSetFeedAdminInstruction( - // Params: - adminParam solanago.PublicKey, - isAdminParam bool, - - // Accounts: - ownerAccount solanago.PublicKey, - stateAccount solanago.PublicKey, -) (solanago.Instruction, error) { - buf__ := new(bytes.Buffer) - enc__ := binary.NewBorshEncoder(buf__) - - // Encode the instruction discriminator. - err := enc__.WriteBytes(Instruction_SetFeedAdmin[:], false) - if err != nil { - return nil, fmt.Errorf("failed to write instruction discriminator: %w", err) - } - { - // Serialize `adminParam`: - err = enc__.Encode(adminParam) - if err != nil { - return nil, errors.NewField("adminParam", err) - } - // Serialize `isAdminParam`: - err = enc__.Encode(isAdminParam) - if err != nil { - return nil, errors.NewField("isAdminParam", err) - } - } - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "owner": Read-only, Signer, Required - accounts__.Append(solanago.NewAccountMeta(ownerAccount, false, true)) - // Account 1 "state": Writable, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(stateAccount, true, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - buf__.Bytes(), - ), nil -} - -// Builds a "transfer_ownership" instruction. -// Step 1 of 2-step ownership process: propose a new owner -func NewTransferOwnershipInstruction( - // Params: - proposedOwnerParam solanago.PublicKey, - - // Accounts: - ownerAccount solanago.PublicKey, - stateAccount solanago.PublicKey, -) (solanago.Instruction, error) { - buf__ := new(bytes.Buffer) - enc__ := binary.NewBorshEncoder(buf__) - - // Encode the instruction discriminator. - err := enc__.WriteBytes(Instruction_TransferOwnership[:], false) - if err != nil { - return nil, fmt.Errorf("failed to write instruction discriminator: %w", err) - } - { - // Serialize `proposedOwnerParam`: - err = enc__.Encode(proposedOwnerParam) - if err != nil { - return nil, errors.NewField("proposedOwnerParam", err) - } - } - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "owner": Read-only, Signer, Required - accounts__.Append(solanago.NewAccountMeta(ownerAccount, false, true)) - // Account 1 "state": Writable, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(stateAccount, true, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - buf__.Bytes(), - ), nil -} - -// Builds a "update_forwarder_id" instruction. -// Not to be used in normal circumstances unless the original forwarder // undergoes maintenance. -func NewUpdateForwarderIdInstruction( - ownerAccount solanago.PublicKey, - stateAccount solanago.PublicKey, - forwarderProgramAccount solanago.PublicKey, -) (solanago.Instruction, error) { - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "owner": Read-only, Signer, Required - accounts__.Append(solanago.NewAccountMeta(ownerAccount, false, true)) - // Account 1 "state": Writable, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(stateAccount, true, false)) - // Account 2 "forwarder_program": Read-only, Non-signer, Required - // the actual program id on chain may have been generated through a different mechanism - accounts__.Append(solanago.NewAccountMeta(forwarderProgramAccount, false, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - nil, - ), nil -} - -// Builds a "update_legacy_feeds_config" instruction. -// Updates legacy feed config. // Recommended limit of 15 legacy feeds can be updated at once. // Instruction does not verify internally if data id and associated legacy feed account // are correct pairs or if aforementioned legacy feed account is owned by the legacy store. -func NewUpdateLegacyFeedsConfigInstruction( - // Params: - dataIdsParam [][16]uint8, - writeDisabledParam []bool, - - // Accounts: - ownerAccount solanago.PublicKey, - stateAccount solanago.PublicKey, - legacyStoreAccount solanago.PublicKey, - legacyFeedsConfigAccount solanago.PublicKey, -) (solanago.Instruction, error) { - buf__ := new(bytes.Buffer) - enc__ := binary.NewBorshEncoder(buf__) - - // Encode the instruction discriminator. - err := enc__.WriteBytes(Instruction_UpdateLegacyFeedsConfig[:], false) - if err != nil { - return nil, fmt.Errorf("failed to write instruction discriminator: %w", err) - } - { - // Serialize `dataIdsParam`: - err = enc__.Encode(dataIdsParam) - if err != nil { - return nil, errors.NewField("dataIdsParam", err) - } - // Serialize `writeDisabledParam`: - err = enc__.Encode(writeDisabledParam) - if err != nil { - return nil, errors.NewField("writeDisabledParam", err) - } - } - accounts__ := solanago.AccountMetaSlice{} - - // Add the accounts to the instruction. - { - // Account 0 "owner": Writable, Signer, Required - accounts__.Append(solanago.NewAccountMeta(ownerAccount, true, true)) - // Account 1 "state": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(stateAccount, false, false)) - // Account 2 "legacy_store": Read-only, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(legacyStoreAccount, false, false)) - // Account 3 "legacy_feeds_config": Writable, Non-signer, Required - accounts__.Append(solanago.NewAccountMeta(legacyFeedsConfigAccount, true, false)) - } - - // Create the instruction. - return solanago.NewInstruction( - ProgramID, - accounts__, - buf__.Bytes(), - ), nil -} - -type AcceptOwnershipInstruction struct { - - // Accounts: - NewOwner solanago.PublicKey `json:"new_owner"` - NewOwnerSigner bool `json:"new_owner_signer"` - State solanago.PublicKey `json:"state"` - StateWritable bool `json:"state_writable"` -} - -func (obj *AcceptOwnershipInstruction) GetDiscriminator() []byte { - return Instruction_AcceptOwnership[:] -} - -// UnmarshalWithDecoder unmarshals the AcceptOwnershipInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *AcceptOwnershipInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "AcceptOwnershipInstruction", err) - } - if discriminator != Instruction_AcceptOwnership { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "AcceptOwnershipInstruction", Instruction_AcceptOwnership, discriminator) - } - return nil -} - -func (obj *AcceptOwnershipInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from new_owner account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "new_owner", err) - } - indices = append(indices, index) - // Decode from state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "state", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *AcceptOwnershipInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 2 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 2, len(indices)) - } - indexOffset := 0 - // Set new_owner account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "new_owner", len(accountKeys)-1) - } - obj.NewOwner = accountKeys[indices[indexOffset]] - indexOffset++ - // Set state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "state", len(accountKeys)-1) - } - obj.State = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *AcceptOwnershipInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.NewOwner) - keys = append(keys, obj.State) - return keys -} - -// Unmarshal unmarshals the AcceptOwnershipInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *AcceptOwnershipInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling AcceptOwnershipInstruction: %w", err) - } - return nil -} - -// UnmarshalAcceptOwnershipInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalAcceptOwnershipInstruction(buf []byte) (*AcceptOwnershipInstruction, error) { - obj := new(AcceptOwnershipInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type CloseDecimalReportInstruction struct { - DataId [16]uint8 `json:"data_id"` - - // Accounts: - FeedAdmin solanago.PublicKey `json:"feed_admin"` - FeedAdminWritable bool `json:"feed_admin_writable"` - FeedAdminSigner bool `json:"feed_admin_signer"` - State solanago.PublicKey `json:"state"` - DecimalReport solanago.PublicKey `json:"decimal_report"` - DecimalReportWritable bool `json:"decimal_report_writable"` - FeedConfig solanago.PublicKey `json:"feed_config"` - FeedConfigWritable bool `json:"feed_config_writable"` -} - -func (obj *CloseDecimalReportInstruction) GetDiscriminator() []byte { - return Instruction_CloseDecimalReport[:] -} - -// UnmarshalWithDecoder unmarshals the CloseDecimalReportInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *CloseDecimalReportInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - var err error - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "CloseDecimalReportInstruction", err) - } - if discriminator != Instruction_CloseDecimalReport { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "CloseDecimalReportInstruction", Instruction_CloseDecimalReport, discriminator) - } - // Deserialize `DataId`: - err = decoder.Decode(&obj.DataId) - if err != nil { - return err - } - return nil -} - -func (obj *CloseDecimalReportInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from feed_admin account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "feed_admin", err) - } - indices = append(indices, index) - // Decode from state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "state", err) - } - indices = append(indices, index) - // Decode from decimal_report account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "decimal_report", err) - } - indices = append(indices, index) - // Decode from feed_config account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "feed_config", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *CloseDecimalReportInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 4 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 4, len(indices)) - } - indexOffset := 0 - // Set feed_admin account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "feed_admin", len(accountKeys)-1) - } - obj.FeedAdmin = accountKeys[indices[indexOffset]] - indexOffset++ - // Set state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "state", len(accountKeys)-1) - } - obj.State = accountKeys[indices[indexOffset]] - indexOffset++ - // Set decimal_report account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "decimal_report", len(accountKeys)-1) - } - obj.DecimalReport = accountKeys[indices[indexOffset]] - indexOffset++ - // Set feed_config account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "feed_config", len(accountKeys)-1) - } - obj.FeedConfig = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *CloseDecimalReportInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.FeedAdmin) - keys = append(keys, obj.State) - keys = append(keys, obj.DecimalReport) - keys = append(keys, obj.FeedConfig) - return keys -} - -// Unmarshal unmarshals the CloseDecimalReportInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *CloseDecimalReportInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling CloseDecimalReportInstruction: %w", err) - } - return nil -} - -// UnmarshalCloseDecimalReportInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalCloseDecimalReportInstruction(buf []byte) (*CloseDecimalReportInstruction, error) { - obj := new(CloseDecimalReportInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type CloseLegacyFeedsConfigInstruction struct { - - // Accounts: - Owner solanago.PublicKey `json:"owner"` - OwnerWritable bool `json:"owner_writable"` - OwnerSigner bool `json:"owner_signer"` - State solanago.PublicKey `json:"state"` - LegacyFeedsConfig solanago.PublicKey `json:"legacy_feeds_config"` - LegacyFeedsConfigWritable bool `json:"legacy_feeds_config_writable"` -} - -func (obj *CloseLegacyFeedsConfigInstruction) GetDiscriminator() []byte { - return Instruction_CloseLegacyFeedsConfig[:] -} - -// UnmarshalWithDecoder unmarshals the CloseLegacyFeedsConfigInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *CloseLegacyFeedsConfigInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "CloseLegacyFeedsConfigInstruction", err) - } - if discriminator != Instruction_CloseLegacyFeedsConfig { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "CloseLegacyFeedsConfigInstruction", Instruction_CloseLegacyFeedsConfig, discriminator) - } - return nil -} - -func (obj *CloseLegacyFeedsConfigInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from owner account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "owner", err) - } - indices = append(indices, index) - // Decode from state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "state", err) - } - indices = append(indices, index) - // Decode from legacy_feeds_config account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "legacy_feeds_config", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *CloseLegacyFeedsConfigInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 3 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 3, len(indices)) - } - indexOffset := 0 - // Set owner account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "owner", len(accountKeys)-1) - } - obj.Owner = accountKeys[indices[indexOffset]] - indexOffset++ - // Set state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "state", len(accountKeys)-1) - } - obj.State = accountKeys[indices[indexOffset]] - indexOffset++ - // Set legacy_feeds_config account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "legacy_feeds_config", len(accountKeys)-1) - } - obj.LegacyFeedsConfig = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *CloseLegacyFeedsConfigInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.Owner) - keys = append(keys, obj.State) - keys = append(keys, obj.LegacyFeedsConfig) - return keys -} - -// Unmarshal unmarshals the CloseLegacyFeedsConfigInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *CloseLegacyFeedsConfigInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling CloseLegacyFeedsConfigInstruction: %w", err) - } - return nil -} - -// UnmarshalCloseLegacyFeedsConfigInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalCloseLegacyFeedsConfigInstruction(buf []byte) (*CloseLegacyFeedsConfigInstruction, error) { - obj := new(CloseLegacyFeedsConfigInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type InitDecimalReportsInstruction struct { - DataIds [][16]uint8 `json:"data_ids"` - - // Accounts: - FeedAdmin solanago.PublicKey `json:"feed_admin"` - FeedAdminWritable bool `json:"feed_admin_writable"` - FeedAdminSigner bool `json:"feed_admin_signer"` - State solanago.PublicKey `json:"state"` - SystemProgram solanago.PublicKey `json:"system_program"` -} - -func (obj *InitDecimalReportsInstruction) GetDiscriminator() []byte { - return Instruction_InitDecimalReports[:] -} - -// UnmarshalWithDecoder unmarshals the InitDecimalReportsInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *InitDecimalReportsInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - var err error - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "InitDecimalReportsInstruction", err) - } - if discriminator != Instruction_InitDecimalReports { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "InitDecimalReportsInstruction", Instruction_InitDecimalReports, discriminator) - } - // Deserialize `DataIds`: - err = decoder.Decode(&obj.DataIds) - if err != nil { - return err - } - return nil -} - -func (obj *InitDecimalReportsInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from feed_admin account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "feed_admin", err) - } - indices = append(indices, index) - // Decode from state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "state", err) - } - indices = append(indices, index) - // Decode from system_program account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "system_program", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *InitDecimalReportsInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 3 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 3, len(indices)) - } - indexOffset := 0 - // Set feed_admin account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "feed_admin", len(accountKeys)-1) - } - obj.FeedAdmin = accountKeys[indices[indexOffset]] - indexOffset++ - // Set state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "state", len(accountKeys)-1) - } - obj.State = accountKeys[indices[indexOffset]] - indexOffset++ - // Set system_program account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "system_program", len(accountKeys)-1) - } - obj.SystemProgram = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *InitDecimalReportsInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.FeedAdmin) - keys = append(keys, obj.State) - keys = append(keys, obj.SystemProgram) - return keys -} - -// Unmarshal unmarshals the InitDecimalReportsInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *InitDecimalReportsInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling InitDecimalReportsInstruction: %w", err) - } - return nil -} - -// UnmarshalInitDecimalReportsInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalInitDecimalReportsInstruction(buf []byte) (*InitDecimalReportsInstruction, error) { - obj := new(InitDecimalReportsInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type InitLegacyFeedsConfigInstruction struct { - DataIds [][16]uint8 `json:"data_ids"` - - // Accounts: - Owner solanago.PublicKey `json:"owner"` - OwnerWritable bool `json:"owner_writable"` - OwnerSigner bool `json:"owner_signer"` - State solanago.PublicKey `json:"state"` - LegacyStore solanago.PublicKey `json:"legacy_store"` - LegacyFeedsConfig solanago.PublicKey `json:"legacy_feeds_config"` - LegacyFeedsConfigWritable bool `json:"legacy_feeds_config_writable"` - SystemProgram solanago.PublicKey `json:"system_program"` -} - -func (obj *InitLegacyFeedsConfigInstruction) GetDiscriminator() []byte { - return Instruction_InitLegacyFeedsConfig[:] -} - -// UnmarshalWithDecoder unmarshals the InitLegacyFeedsConfigInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *InitLegacyFeedsConfigInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - var err error - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "InitLegacyFeedsConfigInstruction", err) - } - if discriminator != Instruction_InitLegacyFeedsConfig { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "InitLegacyFeedsConfigInstruction", Instruction_InitLegacyFeedsConfig, discriminator) - } - // Deserialize `DataIds`: - err = decoder.Decode(&obj.DataIds) - if err != nil { - return err - } - return nil -} - -func (obj *InitLegacyFeedsConfigInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from owner account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "owner", err) - } - indices = append(indices, index) - // Decode from state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "state", err) - } - indices = append(indices, index) - // Decode from legacy_store account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "legacy_store", err) - } - indices = append(indices, index) - // Decode from legacy_feeds_config account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "legacy_feeds_config", err) - } - indices = append(indices, index) - // Decode from system_program account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "system_program", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *InitLegacyFeedsConfigInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 5 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 5, len(indices)) - } - indexOffset := 0 - // Set owner account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "owner", len(accountKeys)-1) - } - obj.Owner = accountKeys[indices[indexOffset]] - indexOffset++ - // Set state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "state", len(accountKeys)-1) - } - obj.State = accountKeys[indices[indexOffset]] - indexOffset++ - // Set legacy_store account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "legacy_store", len(accountKeys)-1) - } - obj.LegacyStore = accountKeys[indices[indexOffset]] - indexOffset++ - // Set legacy_feeds_config account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "legacy_feeds_config", len(accountKeys)-1) - } - obj.LegacyFeedsConfig = accountKeys[indices[indexOffset]] - indexOffset++ - // Set system_program account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "system_program", len(accountKeys)-1) - } - obj.SystemProgram = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *InitLegacyFeedsConfigInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.Owner) - keys = append(keys, obj.State) - keys = append(keys, obj.LegacyStore) - keys = append(keys, obj.LegacyFeedsConfig) - keys = append(keys, obj.SystemProgram) - return keys -} - -// Unmarshal unmarshals the InitLegacyFeedsConfigInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *InitLegacyFeedsConfigInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling InitLegacyFeedsConfigInstruction: %w", err) - } - return nil -} - -// UnmarshalInitLegacyFeedsConfigInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalInitLegacyFeedsConfigInstruction(buf []byte) (*InitLegacyFeedsConfigInstruction, error) { - obj := new(InitLegacyFeedsConfigInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type InitializeInstruction struct { - FeedAdmins []solanago.PublicKey `json:"feed_admins"` - - // Accounts: - Owner solanago.PublicKey `json:"owner"` - OwnerWritable bool `json:"owner_writable"` - OwnerSigner bool `json:"owner_signer"` - State solanago.PublicKey `json:"state"` - StateWritable bool `json:"state_writable"` - StateSigner bool `json:"state_signer"` - ForwarderProgram solanago.PublicKey `json:"forwarder_program"` - SystemProgram solanago.PublicKey `json:"system_program"` -} - -func (obj *InitializeInstruction) GetDiscriminator() []byte { - return Instruction_Initialize[:] -} - -// UnmarshalWithDecoder unmarshals the InitializeInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *InitializeInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - var err error - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "InitializeInstruction", err) - } - if discriminator != Instruction_Initialize { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "InitializeInstruction", Instruction_Initialize, discriminator) - } - // Deserialize `FeedAdmins`: - err = decoder.Decode(&obj.FeedAdmins) - if err != nil { - return err - } - return nil -} - -func (obj *InitializeInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from owner account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "owner", err) - } - indices = append(indices, index) - // Decode from state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "state", err) - } - indices = append(indices, index) - // Decode from forwarder_program account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "forwarder_program", err) - } - indices = append(indices, index) - // Decode from system_program account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "system_program", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *InitializeInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 4 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 4, len(indices)) - } - indexOffset := 0 - // Set owner account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "owner", len(accountKeys)-1) - } - obj.Owner = accountKeys[indices[indexOffset]] - indexOffset++ - // Set state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "state", len(accountKeys)-1) - } - obj.State = accountKeys[indices[indexOffset]] - indexOffset++ - // Set forwarder_program account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "forwarder_program", len(accountKeys)-1) - } - obj.ForwarderProgram = accountKeys[indices[indexOffset]] - indexOffset++ - // Set system_program account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "system_program", len(accountKeys)-1) - } - obj.SystemProgram = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *InitializeInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.Owner) - keys = append(keys, obj.State) - keys = append(keys, obj.ForwarderProgram) - keys = append(keys, obj.SystemProgram) - return keys -} - -// Unmarshal unmarshals the InitializeInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *InitializeInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling InitializeInstruction: %w", err) - } - return nil -} - -// UnmarshalInitializeInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalInitializeInstruction(buf []byte) (*InitializeInstruction, error) { - obj := new(InitializeInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type OnReportInstruction struct { - Metadata []byte `json:"metadata"` - Report []byte `json:"report"` - - // Accounts: - ForwarderState solanago.PublicKey `json:"forwarder_state"` - ForwarderAuthority solanago.PublicKey `json:"forwarder_authority"` - ForwarderAuthoritySigner bool `json:"forwarder_authority_signer"` - CacheState solanago.PublicKey `json:"cache_state"` - LegacyStore solanago.PublicKey `json:"legacy_store"` - LegacyStoreOptional bool `json:"legacy_store_optional"` - LegacyFeedsConfig solanago.PublicKey `json:"legacy_feeds_config"` - LegacyFeedsConfigOptional bool `json:"legacy_feeds_config_optional"` - LegacyWriter solanago.PublicKey `json:"legacy_writer"` - LegacyWriterOptional bool `json:"legacy_writer_optional"` -} - -func (obj *OnReportInstruction) GetDiscriminator() []byte { - return Instruction_OnReport[:] -} - -// UnmarshalWithDecoder unmarshals the OnReportInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *OnReportInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - var err error - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "OnReportInstruction", err) - } - if discriminator != Instruction_OnReport { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "OnReportInstruction", Instruction_OnReport, discriminator) - } - // Deserialize `Metadata`: - err = decoder.Decode(&obj.Metadata) - if err != nil { - return err - } - // Deserialize `Report`: - err = decoder.Decode(&obj.Report) - if err != nil { - return err - } - return nil -} - -func (obj *OnReportInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from forwarder_state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "forwarder_state", err) - } - indices = append(indices, index) - // Decode from forwarder_authority account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "forwarder_authority", err) - } - indices = append(indices, index) - // Decode from cache_state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "cache_state", err) - } - indices = append(indices, index) - // Decode from legacy_store account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "legacy_store", err) - } - indices = append(indices, index) - // Decode from legacy_feeds_config account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "legacy_feeds_config", err) - } - indices = append(indices, index) - // Decode from legacy_writer account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "legacy_writer", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *OnReportInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 6 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 6, len(indices)) - } - indexOffset := 0 - // Set forwarder_state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "forwarder_state", len(accountKeys)-1) - } - obj.ForwarderState = accountKeys[indices[indexOffset]] - indexOffset++ - // Set forwarder_authority account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "forwarder_authority", len(accountKeys)-1) - } - obj.ForwarderAuthority = accountKeys[indices[indexOffset]] - indexOffset++ - // Set cache_state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "cache_state", len(accountKeys)-1) - } - obj.CacheState = accountKeys[indices[indexOffset]] - indexOffset++ - // Set legacy_store account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "legacy_store", len(accountKeys)-1) - } - obj.LegacyStore = accountKeys[indices[indexOffset]] - indexOffset++ - // Set legacy_feeds_config account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "legacy_feeds_config", len(accountKeys)-1) - } - obj.LegacyFeedsConfig = accountKeys[indices[indexOffset]] - indexOffset++ - // Set legacy_writer account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "legacy_writer", len(accountKeys)-1) - } - obj.LegacyWriter = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *OnReportInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.ForwarderState) - keys = append(keys, obj.ForwarderAuthority) - keys = append(keys, obj.CacheState) - keys = append(keys, obj.LegacyStore) - keys = append(keys, obj.LegacyFeedsConfig) - keys = append(keys, obj.LegacyWriter) - return keys -} - -// Unmarshal unmarshals the OnReportInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *OnReportInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling OnReportInstruction: %w", err) - } - return nil -} - -// UnmarshalOnReportInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalOnReportInstruction(buf []byte) (*OnReportInstruction, error) { - obj := new(OnReportInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type PreviewDecimalFeedConfigsInstruction struct { - DataIds [][16]uint8 `json:"data_ids"` - Descriptions [][32]uint8 `json:"descriptions"` - WorkflowMetadatas []WorkflowMetadata `json:"workflow_metadatas"` - - // Accounts: - State solanago.PublicKey `json:"state"` -} - -func (obj *PreviewDecimalFeedConfigsInstruction) GetDiscriminator() []byte { - return Instruction_PreviewDecimalFeedConfigs[:] -} - -// UnmarshalWithDecoder unmarshals the PreviewDecimalFeedConfigsInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *PreviewDecimalFeedConfigsInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - var err error - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "PreviewDecimalFeedConfigsInstruction", err) - } - if discriminator != Instruction_PreviewDecimalFeedConfigs { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "PreviewDecimalFeedConfigsInstruction", Instruction_PreviewDecimalFeedConfigs, discriminator) - } - // Deserialize `DataIds`: - err = decoder.Decode(&obj.DataIds) - if err != nil { - return err - } - // Deserialize `Descriptions`: - err = decoder.Decode(&obj.Descriptions) - if err != nil { - return err - } - // Deserialize `WorkflowMetadatas`: - err = decoder.Decode(&obj.WorkflowMetadatas) - if err != nil { - return err - } - return nil -} - -func (obj *PreviewDecimalFeedConfigsInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "state", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *PreviewDecimalFeedConfigsInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 1 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 1, len(indices)) - } - indexOffset := 0 - // Set state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "state", len(accountKeys)-1) - } - obj.State = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *PreviewDecimalFeedConfigsInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.State) - return keys -} - -// Unmarshal unmarshals the PreviewDecimalFeedConfigsInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *PreviewDecimalFeedConfigsInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling PreviewDecimalFeedConfigsInstruction: %w", err) - } - return nil -} - -// UnmarshalPreviewDecimalFeedConfigsInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalPreviewDecimalFeedConfigsInstruction(buf []byte) (*PreviewDecimalFeedConfigsInstruction, error) { - obj := new(PreviewDecimalFeedConfigsInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type QueryFeedMetadataInstruction struct { - DataId [16]uint8 `json:"_data_id"` - StartIndex uint8 `json:"start_index"` - MaxCount uint8 `json:"max_count"` - - // Accounts: - CacheState solanago.PublicKey `json:"cache_state"` - FeedConfig solanago.PublicKey `json:"feed_config"` -} - -func (obj *QueryFeedMetadataInstruction) GetDiscriminator() []byte { - return Instruction_QueryFeedMetadata[:] -} - -// UnmarshalWithDecoder unmarshals the QueryFeedMetadataInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *QueryFeedMetadataInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - var err error - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "QueryFeedMetadataInstruction", err) - } - if discriminator != Instruction_QueryFeedMetadata { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "QueryFeedMetadataInstruction", Instruction_QueryFeedMetadata, discriminator) - } - // Deserialize `DataId`: - err = decoder.Decode(&obj.DataId) - if err != nil { - return err - } - // Deserialize `StartIndex`: - err = decoder.Decode(&obj.StartIndex) - if err != nil { - return err - } - // Deserialize `MaxCount`: - err = decoder.Decode(&obj.MaxCount) - if err != nil { - return err - } - return nil -} - -func (obj *QueryFeedMetadataInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from cache_state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "cache_state", err) - } - indices = append(indices, index) - // Decode from feed_config account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "feed_config", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *QueryFeedMetadataInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 2 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 2, len(indices)) - } - indexOffset := 0 - // Set cache_state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "cache_state", len(accountKeys)-1) - } - obj.CacheState = accountKeys[indices[indexOffset]] - indexOffset++ - // Set feed_config account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "feed_config", len(accountKeys)-1) - } - obj.FeedConfig = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *QueryFeedMetadataInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.CacheState) - keys = append(keys, obj.FeedConfig) - return keys -} - -// Unmarshal unmarshals the QueryFeedMetadataInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *QueryFeedMetadataInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling QueryFeedMetadataInstruction: %w", err) - } - return nil -} - -// UnmarshalQueryFeedMetadataInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalQueryFeedMetadataInstruction(buf []byte) (*QueryFeedMetadataInstruction, error) { - obj := new(QueryFeedMetadataInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type QueryValuesInstruction struct { - DataIds [][16]uint8 `json:"data_ids"` - - // Accounts: - CacheState solanago.PublicKey `json:"cache_state"` -} - -func (obj *QueryValuesInstruction) GetDiscriminator() []byte { - return Instruction_QueryValues[:] -} - -// UnmarshalWithDecoder unmarshals the QueryValuesInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *QueryValuesInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - var err error - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "QueryValuesInstruction", err) - } - if discriminator != Instruction_QueryValues { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "QueryValuesInstruction", Instruction_QueryValues, discriminator) - } - // Deserialize `DataIds`: - err = decoder.Decode(&obj.DataIds) - if err != nil { - return err - } - return nil -} - -func (obj *QueryValuesInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from cache_state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "cache_state", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *QueryValuesInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 1 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 1, len(indices)) - } - indexOffset := 0 - // Set cache_state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "cache_state", len(accountKeys)-1) - } - obj.CacheState = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *QueryValuesInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.CacheState) - return keys -} - -// Unmarshal unmarshals the QueryValuesInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *QueryValuesInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling QueryValuesInstruction: %w", err) - } - return nil -} - -// UnmarshalQueryValuesInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalQueryValuesInstruction(buf []byte) (*QueryValuesInstruction, error) { - obj := new(QueryValuesInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type SetDecimalFeedConfigsInstruction struct { - DataIds [][16]uint8 `json:"data_ids"` - Descriptions [][32]uint8 `json:"descriptions"` - WorkflowMetadatas []WorkflowMetadata `json:"workflow_metadatas"` - - // Accounts: - FeedAdmin solanago.PublicKey `json:"feed_admin"` - FeedAdminWritable bool `json:"feed_admin_writable"` - FeedAdminSigner bool `json:"feed_admin_signer"` - State solanago.PublicKey `json:"state"` - SystemProgram solanago.PublicKey `json:"system_program"` -} - -func (obj *SetDecimalFeedConfigsInstruction) GetDiscriminator() []byte { - return Instruction_SetDecimalFeedConfigs[:] -} - -// UnmarshalWithDecoder unmarshals the SetDecimalFeedConfigsInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *SetDecimalFeedConfigsInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - var err error - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "SetDecimalFeedConfigsInstruction", err) - } - if discriminator != Instruction_SetDecimalFeedConfigs { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "SetDecimalFeedConfigsInstruction", Instruction_SetDecimalFeedConfigs, discriminator) - } - // Deserialize `DataIds`: - err = decoder.Decode(&obj.DataIds) - if err != nil { - return err - } - // Deserialize `Descriptions`: - err = decoder.Decode(&obj.Descriptions) - if err != nil { - return err - } - // Deserialize `WorkflowMetadatas`: - err = decoder.Decode(&obj.WorkflowMetadatas) - if err != nil { - return err - } - return nil -} - -func (obj *SetDecimalFeedConfigsInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from feed_admin account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "feed_admin", err) - } - indices = append(indices, index) - // Decode from state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "state", err) - } - indices = append(indices, index) - // Decode from system_program account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "system_program", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *SetDecimalFeedConfigsInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 3 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 3, len(indices)) - } - indexOffset := 0 - // Set feed_admin account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "feed_admin", len(accountKeys)-1) - } - obj.FeedAdmin = accountKeys[indices[indexOffset]] - indexOffset++ - // Set state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "state", len(accountKeys)-1) - } - obj.State = accountKeys[indices[indexOffset]] - indexOffset++ - // Set system_program account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "system_program", len(accountKeys)-1) - } - obj.SystemProgram = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *SetDecimalFeedConfigsInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.FeedAdmin) - keys = append(keys, obj.State) - keys = append(keys, obj.SystemProgram) - return keys -} - -// Unmarshal unmarshals the SetDecimalFeedConfigsInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *SetDecimalFeedConfigsInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling SetDecimalFeedConfigsInstruction: %w", err) - } - return nil -} - -// UnmarshalSetDecimalFeedConfigsInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalSetDecimalFeedConfigsInstruction(buf []byte) (*SetDecimalFeedConfigsInstruction, error) { - obj := new(SetDecimalFeedConfigsInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type SetFeedAdminInstruction struct { - Admin solanago.PublicKey `json:"admin"` - IsAdmin bool `json:"is_admin"` - - // Accounts: - Owner solanago.PublicKey `json:"owner"` - OwnerSigner bool `json:"owner_signer"` - State solanago.PublicKey `json:"state"` - StateWritable bool `json:"state_writable"` -} - -func (obj *SetFeedAdminInstruction) GetDiscriminator() []byte { - return Instruction_SetFeedAdmin[:] -} - -// UnmarshalWithDecoder unmarshals the SetFeedAdminInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *SetFeedAdminInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - var err error - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "SetFeedAdminInstruction", err) - } - if discriminator != Instruction_SetFeedAdmin { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "SetFeedAdminInstruction", Instruction_SetFeedAdmin, discriminator) - } - // Deserialize `Admin`: - err = decoder.Decode(&obj.Admin) - if err != nil { - return err - } - // Deserialize `IsAdmin`: - err = decoder.Decode(&obj.IsAdmin) - if err != nil { - return err - } - return nil -} - -func (obj *SetFeedAdminInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from owner account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "owner", err) - } - indices = append(indices, index) - // Decode from state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "state", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *SetFeedAdminInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 2 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 2, len(indices)) - } - indexOffset := 0 - // Set owner account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "owner", len(accountKeys)-1) - } - obj.Owner = accountKeys[indices[indexOffset]] - indexOffset++ - // Set state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "state", len(accountKeys)-1) - } - obj.State = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *SetFeedAdminInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.Owner) - keys = append(keys, obj.State) - return keys -} - -// Unmarshal unmarshals the SetFeedAdminInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *SetFeedAdminInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling SetFeedAdminInstruction: %w", err) - } - return nil -} - -// UnmarshalSetFeedAdminInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalSetFeedAdminInstruction(buf []byte) (*SetFeedAdminInstruction, error) { - obj := new(SetFeedAdminInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type TransferOwnershipInstruction struct { - ProposedOwner solanago.PublicKey `json:"proposed_owner"` - - // Accounts: - Owner solanago.PublicKey `json:"owner"` - OwnerSigner bool `json:"owner_signer"` - State solanago.PublicKey `json:"state"` - StateWritable bool `json:"state_writable"` -} - -func (obj *TransferOwnershipInstruction) GetDiscriminator() []byte { - return Instruction_TransferOwnership[:] -} - -// UnmarshalWithDecoder unmarshals the TransferOwnershipInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *TransferOwnershipInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - var err error - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "TransferOwnershipInstruction", err) - } - if discriminator != Instruction_TransferOwnership { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "TransferOwnershipInstruction", Instruction_TransferOwnership, discriminator) - } - // Deserialize `ProposedOwner`: - err = decoder.Decode(&obj.ProposedOwner) - if err != nil { - return err - } - return nil -} - -func (obj *TransferOwnershipInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from owner account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "owner", err) - } - indices = append(indices, index) - // Decode from state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "state", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *TransferOwnershipInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 2 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 2, len(indices)) - } - indexOffset := 0 - // Set owner account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "owner", len(accountKeys)-1) - } - obj.Owner = accountKeys[indices[indexOffset]] - indexOffset++ - // Set state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "state", len(accountKeys)-1) - } - obj.State = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *TransferOwnershipInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.Owner) - keys = append(keys, obj.State) - return keys -} - -// Unmarshal unmarshals the TransferOwnershipInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *TransferOwnershipInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling TransferOwnershipInstruction: %w", err) - } - return nil -} - -// UnmarshalTransferOwnershipInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalTransferOwnershipInstruction(buf []byte) (*TransferOwnershipInstruction, error) { - obj := new(TransferOwnershipInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type UpdateForwarderIdInstruction struct { - - // Accounts: - Owner solanago.PublicKey `json:"owner"` - OwnerSigner bool `json:"owner_signer"` - State solanago.PublicKey `json:"state"` - StateWritable bool `json:"state_writable"` - ForwarderProgram solanago.PublicKey `json:"forwarder_program"` -} - -func (obj *UpdateForwarderIdInstruction) GetDiscriminator() []byte { - return Instruction_UpdateForwarderId[:] -} - -// UnmarshalWithDecoder unmarshals the UpdateForwarderIdInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *UpdateForwarderIdInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "UpdateForwarderIdInstruction", err) - } - if discriminator != Instruction_UpdateForwarderId { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "UpdateForwarderIdInstruction", Instruction_UpdateForwarderId, discriminator) - } - return nil -} - -func (obj *UpdateForwarderIdInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from owner account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "owner", err) - } - indices = append(indices, index) - // Decode from state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "state", err) - } - indices = append(indices, index) - // Decode from forwarder_program account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "forwarder_program", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *UpdateForwarderIdInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 3 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 3, len(indices)) - } - indexOffset := 0 - // Set owner account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "owner", len(accountKeys)-1) - } - obj.Owner = accountKeys[indices[indexOffset]] - indexOffset++ - // Set state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "state", len(accountKeys)-1) - } - obj.State = accountKeys[indices[indexOffset]] - indexOffset++ - // Set forwarder_program account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "forwarder_program", len(accountKeys)-1) - } - obj.ForwarderProgram = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *UpdateForwarderIdInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.Owner) - keys = append(keys, obj.State) - keys = append(keys, obj.ForwarderProgram) - return keys -} - -// Unmarshal unmarshals the UpdateForwarderIdInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *UpdateForwarderIdInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling UpdateForwarderIdInstruction: %w", err) - } - return nil -} - -// UnmarshalUpdateForwarderIdInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalUpdateForwarderIdInstruction(buf []byte) (*UpdateForwarderIdInstruction, error) { - obj := new(UpdateForwarderIdInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -type UpdateLegacyFeedsConfigInstruction struct { - DataIds [][16]uint8 `json:"data_ids"` - WriteDisabled []bool `json:"write_disabled"` - - // Accounts: - Owner solanago.PublicKey `json:"owner"` - OwnerWritable bool `json:"owner_writable"` - OwnerSigner bool `json:"owner_signer"` - State solanago.PublicKey `json:"state"` - LegacyStore solanago.PublicKey `json:"legacy_store"` - LegacyFeedsConfig solanago.PublicKey `json:"legacy_feeds_config"` - LegacyFeedsConfigWritable bool `json:"legacy_feeds_config_writable"` -} - -func (obj *UpdateLegacyFeedsConfigInstruction) GetDiscriminator() []byte { - return Instruction_UpdateLegacyFeedsConfig[:] -} - -// UnmarshalWithDecoder unmarshals the UpdateLegacyFeedsConfigInstruction from Borsh-encoded bytes prefixed with its discriminator. -func (obj *UpdateLegacyFeedsConfigInstruction) UnmarshalWithDecoder(decoder *binary.Decoder) error { - var err error - // Read the discriminator and check it against the expected value: - discriminator, err := decoder.ReadDiscriminator() - if err != nil { - return fmt.Errorf("failed to read instruction discriminator for %s: %w", "UpdateLegacyFeedsConfigInstruction", err) - } - if discriminator != Instruction_UpdateLegacyFeedsConfig { - return fmt.Errorf("instruction discriminator mismatch for %s: expected %s, got %s", "UpdateLegacyFeedsConfigInstruction", Instruction_UpdateLegacyFeedsConfig, discriminator) - } - // Deserialize `DataIds`: - err = decoder.Decode(&obj.DataIds) - if err != nil { - return err - } - // Deserialize `WriteDisabled`: - err = decoder.Decode(&obj.WriteDisabled) - if err != nil { - return err - } - return nil -} - -func (obj *UpdateLegacyFeedsConfigInstruction) UnmarshalAccountIndices(buf []byte) ([]uint8, error) { - // UnmarshalAccountIndices decodes account indices from Borsh-encoded bytes - decoder := binary.NewBorshDecoder(buf) - indices := make([]uint8, 0) - index := uint8(0) - var err error - // Decode from owner account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "owner", err) - } - indices = append(indices, index) - // Decode from state account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "state", err) - } - indices = append(indices, index) - // Decode from legacy_store account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "legacy_store", err) - } - indices = append(indices, index) - // Decode from legacy_feeds_config account index - index = uint8(0) - err = decoder.Decode(&index) - if err != nil { - return nil, fmt.Errorf("failed to decode %s account index: %w", "legacy_feeds_config", err) - } - indices = append(indices, index) - return indices, nil -} - -func (obj *UpdateLegacyFeedsConfigInstruction) PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error { - // PopulateFromAccountIndices sets account public keys from indices and account keys array - if len(indices) != 4 { - return fmt.Errorf("mismatch between expected accounts (%d) and provided indices (%d)", 4, len(indices)) - } - indexOffset := 0 - // Set owner account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "owner", len(accountKeys)-1) - } - obj.Owner = accountKeys[indices[indexOffset]] - indexOffset++ - // Set state account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "state", len(accountKeys)-1) - } - obj.State = accountKeys[indices[indexOffset]] - indexOffset++ - // Set legacy_store account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "legacy_store", len(accountKeys)-1) - } - obj.LegacyStore = accountKeys[indices[indexOffset]] - indexOffset++ - // Set legacy_feeds_config account from index - if indices[indexOffset] >= uint8(len(accountKeys)) { - return fmt.Errorf("account index %d for %s is out of bounds (max: %d)", indices[indexOffset], "legacy_feeds_config", len(accountKeys)-1) - } - obj.LegacyFeedsConfig = accountKeys[indices[indexOffset]] - indexOffset++ - return nil -} - -func (obj *UpdateLegacyFeedsConfigInstruction) GetAccountKeys() []solanago.PublicKey { - keys := make([]solanago.PublicKey, 0) - keys = append(keys, obj.Owner) - keys = append(keys, obj.State) - keys = append(keys, obj.LegacyStore) - keys = append(keys, obj.LegacyFeedsConfig) - return keys -} - -// Unmarshal unmarshals the UpdateLegacyFeedsConfigInstruction from Borsh-encoded bytes prefixed with the discriminator. -func (obj *UpdateLegacyFeedsConfigInstruction) Unmarshal(buf []byte) error { - var err error - err = obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling UpdateLegacyFeedsConfigInstruction: %w", err) - } - return nil -} - -// UnmarshalUpdateLegacyFeedsConfigInstruction unmarshals the instruction from Borsh-encoded bytes prefixed with the discriminator. -func UnmarshalUpdateLegacyFeedsConfigInstruction(buf []byte) (*UpdateLegacyFeedsConfigInstruction, error) { - obj := new(UpdateLegacyFeedsConfigInstruction) - var err error - err = obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -// Instruction interface defines common methods for all instruction types -type Instruction interface { - GetDiscriminator() []byte - - UnmarshalWithDecoder(decoder *binary.Decoder) error - - UnmarshalAccountIndices(buf []byte) ([]uint8, error) - - PopulateFromAccountIndices(indices []uint8, accountKeys []solanago.PublicKey) error - - GetAccountKeys() []solanago.PublicKey -} - -// ParseInstruction parses instruction data and optionally populates accounts -// If accountIndicesData is nil or empty, accounts will not be populated -func ParseInstruction(instructionData []byte, accountIndicesData []byte, accountKeys []solanago.PublicKey) (Instruction, error) { - // Validate inputs - if len(instructionData) < 8 { - return nil, fmt.Errorf("instruction data too short: expected at least 8 bytes, got %d", len(instructionData)) - } - // Extract discriminator (TypeID for consistent equality with generated constants) - discriminator := binary.TypeIDFromBytes(instructionData[0:8]) - // Parse based on discriminator - switch discriminator { - case Instruction_AcceptOwnership: - instruction := new(AcceptOwnershipInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as AcceptOwnershipInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_CloseDecimalReport: - instruction := new(CloseDecimalReportInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as CloseDecimalReportInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_CloseLegacyFeedsConfig: - instruction := new(CloseLegacyFeedsConfigInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as CloseLegacyFeedsConfigInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_InitDecimalReports: - instruction := new(InitDecimalReportsInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as InitDecimalReportsInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_InitLegacyFeedsConfig: - instruction := new(InitLegacyFeedsConfigInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as InitLegacyFeedsConfigInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_Initialize: - instruction := new(InitializeInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as InitializeInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_OnReport: - instruction := new(OnReportInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as OnReportInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_PreviewDecimalFeedConfigs: - instruction := new(PreviewDecimalFeedConfigsInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as PreviewDecimalFeedConfigsInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_QueryFeedMetadata: - instruction := new(QueryFeedMetadataInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as QueryFeedMetadataInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_QueryValues: - instruction := new(QueryValuesInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as QueryValuesInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_SetDecimalFeedConfigs: - instruction := new(SetDecimalFeedConfigsInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as SetDecimalFeedConfigsInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_SetFeedAdmin: - instruction := new(SetFeedAdminInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as SetFeedAdminInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_TransferOwnership: - instruction := new(TransferOwnershipInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as TransferOwnershipInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_UpdateForwarderId: - instruction := new(UpdateForwarderIdInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as UpdateForwarderIdInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - case Instruction_UpdateLegacyFeedsConfig: - instruction := new(UpdateLegacyFeedsConfigInstruction) - decoder := binary.NewBorshDecoder(instructionData) - err := instruction.UnmarshalWithDecoder(decoder) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal instruction as UpdateLegacyFeedsConfigInstruction: %w", err) - } - if accountIndicesData != nil && len(accountIndicesData) > 0 { - indices, err := instruction.UnmarshalAccountIndices(accountIndicesData) - if err != nil { - return nil, fmt.Errorf("failed to unmarshal account indices: %w", err) - } - err = instruction.PopulateFromAccountIndices(indices, accountKeys) - if err != nil { - return nil, fmt.Errorf("failed to populate accounts: %w", err) - } - } - return instruction, nil - default: - return nil, fmt.Errorf("unknown instruction discriminator: %s", binary.FormatDiscriminator(discriminator)) - } -} - -// ParseInstructionTyped parses instruction data and returns a specific instruction type // T must implement the Instruction interface -func ParseInstructionTyped[T Instruction](instructionData []byte, accountIndicesData []byte, accountKeys []solanago.PublicKey) (T, error) { - instruction, err := ParseInstruction(instructionData, accountIndicesData, accountKeys) - if err != nil { - return *new(T), err - } - typed, ok := instruction.(T) - if !ok { - return *new(T), fmt.Errorf("instruction is not of expected type") - } - return typed, nil -} - -// ParseInstructionWithoutAccounts parses instruction data without account information -func ParseInstructionWithoutAccounts(instructionData []byte) (Instruction, error) { - return ParseInstruction(instructionData, nil, []solanago.PublicKey{}) -} - -// ParseInstructionWithAccounts parses instruction data with account information -func ParseInstructionWithAccounts(instructionData []byte, accountIndicesData []byte, accountKeys []solanago.PublicKey) (Instruction, error) { - return ParseInstruction(instructionData, accountIndicesData, accountKeys) -} diff --git a/contracts/solana/src/generated/data_feeds_cache/program_id.go b/contracts/solana/src/generated/data_feeds_cache/program_id.go deleted file mode 100644 index 3e866499..00000000 --- a/contracts/solana/src/generated/data_feeds_cache/program_id.go +++ /dev/null @@ -1,8 +0,0 @@ -// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -// This file contains the program ID. - -package data_feeds_cache - -import solanago "github.com/gagliardetto/solana-go" - -var ProgramID = solanago.MustPublicKeyFromBase58("3kX63udXtYcsdj2737Wi2KGd2PhqiKPgAFAxstrjtRUa") diff --git a/contracts/solana/src/generated/data_feeds_cache/tests_test.go b/contracts/solana/src/generated/data_feeds_cache/tests_test.go deleted file mode 100644 index 6f4ac512..00000000 --- a/contracts/solana/src/generated/data_feeds_cache/tests_test.go +++ /dev/null @@ -1,4 +0,0 @@ -// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -// This file contains tests. - -package data_feeds_cache diff --git a/contracts/solana/src/generated/data_feeds_cache/types.go b/contracts/solana/src/generated/data_feeds_cache/types.go deleted file mode 100644 index e027bf9d..00000000 --- a/contracts/solana/src/generated/data_feeds_cache/types.go +++ /dev/null @@ -1,3401 +0,0 @@ -// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. -// This file contains parsers for the types defined in the IDL. - -package data_feeds_cache - -import ( - "bytes" - "fmt" - errors "github.com/gagliardetto/anchor-go/errors" - binary "github.com/gagliardetto/binary" - solanago "github.com/gagliardetto/solana-go" - sdk "github.com/smartcontractkit/chainlink-protos/cre/go/sdk" - solana "github.com/smartcontractkit/cre-sdk-go/capabilities/blockchain/solana" - bindings "github.com/smartcontractkit/cre-sdk-go/capabilities/blockchain/solana/bindings" - cre "github.com/smartcontractkit/cre-sdk-go/cre" -) - -// Fixed size struct which stores list of public keys -type AccountList struct { - Xs [64]solanago.PublicKey `json:"xs"` - Len uint64 `json:"len"` -} - -func (obj AccountList) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `Xs`: - err = encoder.Encode(obj.Xs) - if err != nil { - return errors.NewField("Xs", err) - } - // Serialize `Len`: - err = encoder.Encode(obj.Len) - if err != nil { - return errors.NewField("Len", err) - } - return nil -} - -func (obj AccountList) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding AccountList: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *AccountList) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `Xs`: - err = decoder.Decode(&obj.Xs) - if err != nil { - return errors.NewField("Xs", err) - } - // Deserialize `Len`: - err = decoder.Decode(&obj.Len) - if err != nil { - return errors.NewField("Len", err) - } - return nil -} - -func (obj *AccountList) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling AccountList: %w", err) - } - return nil -} - -func UnmarshalAccountList(buf []byte) (*AccountList, error) { - obj := new(AccountList) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeAccountListStruct(in AccountList) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromAccountList( - runtime cre.Runtime, - input AccountList, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeAccountListStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromAccountLists( - runtime cre.Runtime, - inputs []AccountList, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeAccountListStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type CacheInitialized struct { - State solanago.PublicKey `json:"state"` - ForwarderId solanago.PublicKey `json:"forwarder_id"` - LegacyWriterBump uint8 `json:"legacy_writer_bump"` -} - -func (obj CacheInitialized) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `State`: - err = encoder.Encode(obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Serialize `ForwarderId`: - err = encoder.Encode(obj.ForwarderId) - if err != nil { - return errors.NewField("ForwarderId", err) - } - // Serialize `LegacyWriterBump`: - err = encoder.Encode(obj.LegacyWriterBump) - if err != nil { - return errors.NewField("LegacyWriterBump", err) - } - return nil -} - -func (obj CacheInitialized) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding CacheInitialized: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *CacheInitialized) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `State`: - err = decoder.Decode(&obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Deserialize `ForwarderId`: - err = decoder.Decode(&obj.ForwarderId) - if err != nil { - return errors.NewField("ForwarderId", err) - } - // Deserialize `LegacyWriterBump`: - err = decoder.Decode(&obj.LegacyWriterBump) - if err != nil { - return errors.NewField("LegacyWriterBump", err) - } - return nil -} - -func (obj *CacheInitialized) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling CacheInitialized: %w", err) - } - return nil -} - -func UnmarshalCacheInitialized(buf []byte) (*CacheInitialized, error) { - obj := new(CacheInitialized) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeCacheInitializedStruct(in CacheInitialized) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromCacheInitialized( - runtime cre.Runtime, - input CacheInitialized, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeCacheInitializedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromCacheInitializeds( - runtime cre.Runtime, - inputs []CacheInitialized, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeCacheInitializedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -// Cache State account contains owners and admin -// information in addition to the bump/nonce for the -// PDA which writes to legacy data feeds -type CacheState struct { - Owner solanago.PublicKey `json:"owner"` - ProposedOwner solanago.PublicKey `json:"proposed_owner"` - FeedAdmins AccountList `json:"feed_admins"` - ForwarderId solanago.PublicKey `json:"forwarder_id"` - LegacyWriterBump uint8 `json:"legacy_writer_bump"` - Padding [7]uint8 `json:"_padding"` -} - -func (obj CacheState) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `Owner`: - err = encoder.Encode(obj.Owner) - if err != nil { - return errors.NewField("Owner", err) - } - // Serialize `ProposedOwner`: - err = encoder.Encode(obj.ProposedOwner) - if err != nil { - return errors.NewField("ProposedOwner", err) - } - // Serialize `FeedAdmins`: - err = encoder.Encode(obj.FeedAdmins) - if err != nil { - return errors.NewField("FeedAdmins", err) - } - // Serialize `ForwarderId`: - err = encoder.Encode(obj.ForwarderId) - if err != nil { - return errors.NewField("ForwarderId", err) - } - // Serialize `LegacyWriterBump`: - err = encoder.Encode(obj.LegacyWriterBump) - if err != nil { - return errors.NewField("LegacyWriterBump", err) - } - // Serialize `Padding`: - err = encoder.Encode(obj.Padding) - if err != nil { - return errors.NewField("Padding", err) - } - return nil -} - -func (obj CacheState) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding CacheState: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *CacheState) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `Owner`: - err = decoder.Decode(&obj.Owner) - if err != nil { - return errors.NewField("Owner", err) - } - // Deserialize `ProposedOwner`: - err = decoder.Decode(&obj.ProposedOwner) - if err != nil { - return errors.NewField("ProposedOwner", err) - } - // Deserialize `FeedAdmins`: - err = decoder.Decode(&obj.FeedAdmins) - if err != nil { - return errors.NewField("FeedAdmins", err) - } - // Deserialize `ForwarderId`: - err = decoder.Decode(&obj.ForwarderId) - if err != nil { - return errors.NewField("ForwarderId", err) - } - // Deserialize `LegacyWriterBump`: - err = decoder.Decode(&obj.LegacyWriterBump) - if err != nil { - return errors.NewField("LegacyWriterBump", err) - } - // Deserialize `Padding`: - err = decoder.Decode(&obj.Padding) - if err != nil { - return errors.NewField("Padding", err) - } - return nil -} - -func (obj *CacheState) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling CacheState: %w", err) - } - return nil -} - -func UnmarshalCacheState(buf []byte) (*CacheState, error) { - obj := new(CacheState) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeCacheStateStruct(in CacheState) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromCacheState( - runtime cre.Runtime, - input CacheState, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeCacheStateStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromCacheStates( - runtime cre.Runtime, - inputs []CacheState, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeCacheStateStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type DecimalFeedConfigSet struct { - State solanago.PublicKey `json:"state"` - DataId [16]uint8 `json:"data_id"` - Decimals uint8 `json:"decimals"` - Description [32]uint8 `json:"description"` - WorkflowMetadatas []WorkflowMetadata `json:"workflow_metadatas"` -} - -func (obj DecimalFeedConfigSet) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `State`: - err = encoder.Encode(obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Serialize `DataId`: - err = encoder.Encode(obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - // Serialize `Decimals`: - err = encoder.Encode(obj.Decimals) - if err != nil { - return errors.NewField("Decimals", err) - } - // Serialize `Description`: - err = encoder.Encode(obj.Description) - if err != nil { - return errors.NewField("Description", err) - } - // Serialize `WorkflowMetadatas`: - err = encoder.Encode(obj.WorkflowMetadatas) - if err != nil { - return errors.NewField("WorkflowMetadatas", err) - } - return nil -} - -func (obj DecimalFeedConfigSet) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding DecimalFeedConfigSet: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *DecimalFeedConfigSet) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `State`: - err = decoder.Decode(&obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Deserialize `DataId`: - err = decoder.Decode(&obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - // Deserialize `Decimals`: - err = decoder.Decode(&obj.Decimals) - if err != nil { - return errors.NewField("Decimals", err) - } - // Deserialize `Description`: - err = decoder.Decode(&obj.Description) - if err != nil { - return errors.NewField("Description", err) - } - // Deserialize `WorkflowMetadatas`: - err = decoder.Decode(&obj.WorkflowMetadatas) - if err != nil { - return errors.NewField("WorkflowMetadatas", err) - } - return nil -} - -func (obj *DecimalFeedConfigSet) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling DecimalFeedConfigSet: %w", err) - } - return nil -} - -func UnmarshalDecimalFeedConfigSet(buf []byte) (*DecimalFeedConfigSet, error) { - obj := new(DecimalFeedConfigSet) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeDecimalFeedConfigSetStruct(in DecimalFeedConfigSet) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromDecimalFeedConfigSet( - runtime cre.Runtime, - input DecimalFeedConfigSet, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeDecimalFeedConfigSetStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromDecimalFeedConfigSets( - runtime cre.Runtime, - inputs []DecimalFeedConfigSet, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeDecimalFeedConfigSetStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -// Decimal Report stored -type DecimalReport struct { - Timestamp uint32 `json:"timestamp"` - Answer binary.Uint128 `json:"answer"` -} - -func (obj DecimalReport) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `Timestamp`: - err = encoder.Encode(obj.Timestamp) - if err != nil { - return errors.NewField("Timestamp", err) - } - // Serialize `Answer`: - err = encoder.Encode(obj.Answer) - if err != nil { - return errors.NewField("Answer", err) - } - return nil -} - -func (obj DecimalReport) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding DecimalReport: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *DecimalReport) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `Timestamp`: - err = decoder.Decode(&obj.Timestamp) - if err != nil { - return errors.NewField("Timestamp", err) - } - // Deserialize `Answer`: - err = decoder.Decode(&obj.Answer) - if err != nil { - return errors.NewField("Answer", err) - } - return nil -} - -func (obj *DecimalReport) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling DecimalReport: %w", err) - } - return nil -} - -func UnmarshalDecimalReport(buf []byte) (*DecimalReport, error) { - obj := new(DecimalReport) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeDecimalReportStruct(in DecimalReport) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromDecimalReport( - runtime cre.Runtime, - input DecimalReport, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeDecimalReportStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromDecimalReports( - runtime cre.Runtime, - inputs []DecimalReport, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeDecimalReportStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type DecimalReportClosed struct { - State solanago.PublicKey `json:"state"` - DataId [16]uint8 `json:"data_id"` -} - -func (obj DecimalReportClosed) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `State`: - err = encoder.Encode(obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Serialize `DataId`: - err = encoder.Encode(obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - return nil -} - -func (obj DecimalReportClosed) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding DecimalReportClosed: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *DecimalReportClosed) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `State`: - err = decoder.Decode(&obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Deserialize `DataId`: - err = decoder.Decode(&obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - return nil -} - -func (obj *DecimalReportClosed) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling DecimalReportClosed: %w", err) - } - return nil -} - -func UnmarshalDecimalReportClosed(buf []byte) (*DecimalReportClosed, error) { - obj := new(DecimalReportClosed) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeDecimalReportClosedStruct(in DecimalReportClosed) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromDecimalReportClosed( - runtime cre.Runtime, - input DecimalReportClosed, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeDecimalReportClosedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromDecimalReportCloseds( - runtime cre.Runtime, - inputs []DecimalReportClosed, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeDecimalReportClosedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type DecimalReportInitialized struct { - State solanago.PublicKey `json:"state"` - DataId [16]uint8 `json:"data_id"` -} - -func (obj DecimalReportInitialized) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `State`: - err = encoder.Encode(obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Serialize `DataId`: - err = encoder.Encode(obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - return nil -} - -func (obj DecimalReportInitialized) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding DecimalReportInitialized: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *DecimalReportInitialized) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `State`: - err = decoder.Decode(&obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Deserialize `DataId`: - err = decoder.Decode(&obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - return nil -} - -func (obj *DecimalReportInitialized) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling DecimalReportInitialized: %w", err) - } - return nil -} - -func UnmarshalDecimalReportInitialized(buf []byte) (*DecimalReportInitialized, error) { - obj := new(DecimalReportInitialized) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeDecimalReportInitializedStruct(in DecimalReportInitialized) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromDecimalReportInitialized( - runtime cre.Runtime, - input DecimalReportInitialized, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeDecimalReportInitializedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromDecimalReportInitializeds( - runtime cre.Runtime, - inputs []DecimalReportInitialized, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeDecimalReportInitializedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type DecimalReportUpdated struct { - State solanago.PublicKey `json:"state"` - DataId [16]uint8 `json:"data_id"` - Timestamp uint32 `json:"timestamp"` - Answer binary.Uint128 `json:"answer"` -} - -func (obj DecimalReportUpdated) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `State`: - err = encoder.Encode(obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Serialize `DataId`: - err = encoder.Encode(obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - // Serialize `Timestamp`: - err = encoder.Encode(obj.Timestamp) - if err != nil { - return errors.NewField("Timestamp", err) - } - // Serialize `Answer`: - err = encoder.Encode(obj.Answer) - if err != nil { - return errors.NewField("Answer", err) - } - return nil -} - -func (obj DecimalReportUpdated) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding DecimalReportUpdated: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *DecimalReportUpdated) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `State`: - err = decoder.Decode(&obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Deserialize `DataId`: - err = decoder.Decode(&obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - // Deserialize `Timestamp`: - err = decoder.Decode(&obj.Timestamp) - if err != nil { - return errors.NewField("Timestamp", err) - } - // Deserialize `Answer`: - err = decoder.Decode(&obj.Answer) - if err != nil { - return errors.NewField("Answer", err) - } - return nil -} - -func (obj *DecimalReportUpdated) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling DecimalReportUpdated: %w", err) - } - return nil -} - -func UnmarshalDecimalReportUpdated(buf []byte) (*DecimalReportUpdated, error) { - obj := new(DecimalReportUpdated) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeDecimalReportUpdatedStruct(in DecimalReportUpdated) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromDecimalReportUpdated( - runtime cre.Runtime, - input DecimalReportUpdated, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeDecimalReportUpdatedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromDecimalReportUpdateds( - runtime cre.Runtime, - inputs []DecimalReportUpdated, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeDecimalReportUpdatedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type FeedAdminUpdated struct { - State solanago.PublicKey `json:"state"` - Admin solanago.PublicKey `json:"admin"` - IsAdmin bool `json:"is_admin"` -} - -func (obj FeedAdminUpdated) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `State`: - err = encoder.Encode(obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Serialize `Admin`: - err = encoder.Encode(obj.Admin) - if err != nil { - return errors.NewField("Admin", err) - } - // Serialize `IsAdmin`: - err = encoder.Encode(obj.IsAdmin) - if err != nil { - return errors.NewField("IsAdmin", err) - } - return nil -} - -func (obj FeedAdminUpdated) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding FeedAdminUpdated: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *FeedAdminUpdated) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `State`: - err = decoder.Decode(&obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Deserialize `Admin`: - err = decoder.Decode(&obj.Admin) - if err != nil { - return errors.NewField("Admin", err) - } - // Deserialize `IsAdmin`: - err = decoder.Decode(&obj.IsAdmin) - if err != nil { - return errors.NewField("IsAdmin", err) - } - return nil -} - -func (obj *FeedAdminUpdated) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling FeedAdminUpdated: %w", err) - } - return nil -} - -func UnmarshalFeedAdminUpdated(buf []byte) (*FeedAdminUpdated, error) { - obj := new(FeedAdminUpdated) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeFeedAdminUpdatedStruct(in FeedAdminUpdated) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromFeedAdminUpdated( - runtime cre.Runtime, - input FeedAdminUpdated, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeFeedAdminUpdatedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromFeedAdminUpdateds( - runtime cre.Runtime, - inputs []FeedAdminUpdated, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeFeedAdminUpdatedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -// Contains feed information such as description -// and the authorized workflows permitted to -// report on the data id. Account key is derived by the data id. -type FeedConfig struct { - Description [32]uint8 `json:"description"` - WorkflowMetadata WorkflowMetadataList `json:"workflow_metadata"` -} - -func (obj FeedConfig) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `Description`: - err = encoder.Encode(obj.Description) - if err != nil { - return errors.NewField("Description", err) - } - // Serialize `WorkflowMetadata`: - err = encoder.Encode(obj.WorkflowMetadata) - if err != nil { - return errors.NewField("WorkflowMetadata", err) - } - return nil -} - -func (obj FeedConfig) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding FeedConfig: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *FeedConfig) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `Description`: - err = decoder.Decode(&obj.Description) - if err != nil { - return errors.NewField("Description", err) - } - // Deserialize `WorkflowMetadata`: - err = decoder.Decode(&obj.WorkflowMetadata) - if err != nil { - return errors.NewField("WorkflowMetadata", err) - } - return nil -} - -func (obj *FeedConfig) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling FeedConfig: %w", err) - } - return nil -} - -func UnmarshalFeedConfig(buf []byte) (*FeedConfig, error) { - obj := new(FeedConfig) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeFeedConfigStruct(in FeedConfig) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromFeedConfig( - runtime cre.Runtime, - input FeedConfig, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeFeedConfigStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromFeedConfigs( - runtime cre.Runtime, - inputs []FeedConfig, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeFeedConfigStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -// Account which represents a distinct instance of a forwarder. -type ForwarderState struct { - Version uint8 `json:"version"` - Owner solanago.PublicKey `json:"owner"` - ProposedOwner solanago.PublicKey `json:"proposed_owner"` -} - -func (obj ForwarderState) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `Version`: - err = encoder.Encode(obj.Version) - if err != nil { - return errors.NewField("Version", err) - } - // Serialize `Owner`: - err = encoder.Encode(obj.Owner) - if err != nil { - return errors.NewField("Owner", err) - } - // Serialize `ProposedOwner`: - err = encoder.Encode(obj.ProposedOwner) - if err != nil { - return errors.NewField("ProposedOwner", err) - } - return nil -} - -func (obj ForwarderState) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding ForwarderState: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *ForwarderState) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `Version`: - err = decoder.Decode(&obj.Version) - if err != nil { - return errors.NewField("Version", err) - } - // Deserialize `Owner`: - err = decoder.Decode(&obj.Owner) - if err != nil { - return errors.NewField("Owner", err) - } - // Deserialize `ProposedOwner`: - err = decoder.Decode(&obj.ProposedOwner) - if err != nil { - return errors.NewField("ProposedOwner", err) - } - return nil -} - -func (obj *ForwarderState) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling ForwarderState: %w", err) - } - return nil -} - -func UnmarshalForwarderState(buf []byte) (*ForwarderState, error) { - obj := new(ForwarderState) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeForwarderStateStruct(in ForwarderState) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromForwarderState( - runtime cre.Runtime, - input ForwarderState, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeForwarderStateStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromForwarderStates( - runtime cre.Runtime, - inputs []ForwarderState, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeForwarderStateStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type ForwarderUpdated struct { - PreviousForwarder solanago.PublicKey `json:"previous_forwarder"` - NewForwarder solanago.PublicKey `json:"new_forwarder"` -} - -func (obj ForwarderUpdated) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `PreviousForwarder`: - err = encoder.Encode(obj.PreviousForwarder) - if err != nil { - return errors.NewField("PreviousForwarder", err) - } - // Serialize `NewForwarder`: - err = encoder.Encode(obj.NewForwarder) - if err != nil { - return errors.NewField("NewForwarder", err) - } - return nil -} - -func (obj ForwarderUpdated) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding ForwarderUpdated: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *ForwarderUpdated) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `PreviousForwarder`: - err = decoder.Decode(&obj.PreviousForwarder) - if err != nil { - return errors.NewField("PreviousForwarder", err) - } - // Deserialize `NewForwarder`: - err = decoder.Decode(&obj.NewForwarder) - if err != nil { - return errors.NewField("NewForwarder", err) - } - return nil -} - -func (obj *ForwarderUpdated) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling ForwarderUpdated: %w", err) - } - return nil -} - -func UnmarshalForwarderUpdated(buf []byte) (*ForwarderUpdated, error) { - obj := new(ForwarderUpdated) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeForwarderUpdatedStruct(in ForwarderUpdated) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromForwarderUpdated( - runtime cre.Runtime, - input ForwarderUpdated, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeForwarderUpdatedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromForwarderUpdateds( - runtime cre.Runtime, - inputs []ForwarderUpdated, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeForwarderUpdatedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type InvalidUpdatePermission struct { - State solanago.PublicKey `json:"state"` - DataId [16]uint8 `json:"data_id"` - Sender solanago.PublicKey `json:"sender"` - WorkflowOwner [20]uint8 `json:"workflow_owner"` - WorkflowName [10]uint8 `json:"workflow_name"` -} - -func (obj InvalidUpdatePermission) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `State`: - err = encoder.Encode(obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Serialize `DataId`: - err = encoder.Encode(obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - // Serialize `Sender`: - err = encoder.Encode(obj.Sender) - if err != nil { - return errors.NewField("Sender", err) - } - // Serialize `WorkflowOwner`: - err = encoder.Encode(obj.WorkflowOwner) - if err != nil { - return errors.NewField("WorkflowOwner", err) - } - // Serialize `WorkflowName`: - err = encoder.Encode(obj.WorkflowName) - if err != nil { - return errors.NewField("WorkflowName", err) - } - return nil -} - -func (obj InvalidUpdatePermission) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding InvalidUpdatePermission: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *InvalidUpdatePermission) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `State`: - err = decoder.Decode(&obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Deserialize `DataId`: - err = decoder.Decode(&obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - // Deserialize `Sender`: - err = decoder.Decode(&obj.Sender) - if err != nil { - return errors.NewField("Sender", err) - } - // Deserialize `WorkflowOwner`: - err = decoder.Decode(&obj.WorkflowOwner) - if err != nil { - return errors.NewField("WorkflowOwner", err) - } - // Deserialize `WorkflowName`: - err = decoder.Decode(&obj.WorkflowName) - if err != nil { - return errors.NewField("WorkflowName", err) - } - return nil -} - -func (obj *InvalidUpdatePermission) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling InvalidUpdatePermission: %w", err) - } - return nil -} - -func UnmarshalInvalidUpdatePermission(buf []byte) (*InvalidUpdatePermission, error) { - obj := new(InvalidUpdatePermission) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeInvalidUpdatePermissionStruct(in InvalidUpdatePermission) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromInvalidUpdatePermission( - runtime cre.Runtime, - input InvalidUpdatePermission, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeInvalidUpdatePermissionStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromInvalidUpdatePermissions( - runtime cre.Runtime, - inputs []InvalidUpdatePermission, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeInvalidUpdatePermissionStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -// Contains config information of a legacy feed -type LegacyFeedEntry struct { - DataId [16]uint8 `json:"data_id"` - LegacyFeed solanago.PublicKey `json:"legacy_feed"` - WriteDisabled uint8 `json:"write_disabled"` -} - -func (obj LegacyFeedEntry) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `DataId`: - err = encoder.Encode(obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - // Serialize `LegacyFeed`: - err = encoder.Encode(obj.LegacyFeed) - if err != nil { - return errors.NewField("LegacyFeed", err) - } - // Serialize `WriteDisabled`: - err = encoder.Encode(obj.WriteDisabled) - if err != nil { - return errors.NewField("WriteDisabled", err) - } - return nil -} - -func (obj LegacyFeedEntry) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding LegacyFeedEntry: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *LegacyFeedEntry) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `DataId`: - err = decoder.Decode(&obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - // Deserialize `LegacyFeed`: - err = decoder.Decode(&obj.LegacyFeed) - if err != nil { - return errors.NewField("LegacyFeed", err) - } - // Deserialize `WriteDisabled`: - err = decoder.Decode(&obj.WriteDisabled) - if err != nil { - return errors.NewField("WriteDisabled", err) - } - return nil -} - -func (obj *LegacyFeedEntry) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling LegacyFeedEntry: %w", err) - } - return nil -} - -func UnmarshalLegacyFeedEntry(buf []byte) (*LegacyFeedEntry, error) { - obj := new(LegacyFeedEntry) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeLegacyFeedEntryStruct(in LegacyFeedEntry) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromLegacyFeedEntry( - runtime cre.Runtime, - input LegacyFeedEntry, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeLegacyFeedEntryStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromLegacyFeedEntrys( - runtime cre.Runtime, - inputs []LegacyFeedEntry, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeLegacyFeedEntryStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -// Fixed size struct which stores list of legacy feed entries. -type LegacyFeedList struct { - Xs [64]LegacyFeedEntry `json:"xs"` - Len uint64 `json:"len"` -} - -func (obj LegacyFeedList) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `Xs`: - err = encoder.Encode(obj.Xs) - if err != nil { - return errors.NewField("Xs", err) - } - // Serialize `Len`: - err = encoder.Encode(obj.Len) - if err != nil { - return errors.NewField("Len", err) - } - return nil -} - -func (obj LegacyFeedList) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding LegacyFeedList: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *LegacyFeedList) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `Xs`: - err = decoder.Decode(&obj.Xs) - if err != nil { - return errors.NewField("Xs", err) - } - // Deserialize `Len`: - err = decoder.Decode(&obj.Len) - if err != nil { - return errors.NewField("Len", err) - } - return nil -} - -func (obj *LegacyFeedList) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling LegacyFeedList: %w", err) - } - return nil -} - -func UnmarshalLegacyFeedList(buf []byte) (*LegacyFeedList, error) { - obj := new(LegacyFeedList) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeLegacyFeedListStruct(in LegacyFeedList) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromLegacyFeedList( - runtime cre.Runtime, - input LegacyFeedList, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeLegacyFeedListStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromLegacyFeedLists( - runtime cre.Runtime, - inputs []LegacyFeedList, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeLegacyFeedListStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -// Stores data ids which are flagged to have their reports written to -// the legacy store program as well. -// We can assume there's only going to be a limited amount of legacy feeds to write to -type LegacyFeedsConfig struct { - IdToFeed LegacyFeedList `json:"id_to_feed"` - LegacyStore solanago.PublicKey `json:"legacy_store"` -} - -func (obj LegacyFeedsConfig) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `IdToFeed`: - err = encoder.Encode(obj.IdToFeed) - if err != nil { - return errors.NewField("IdToFeed", err) - } - // Serialize `LegacyStore`: - err = encoder.Encode(obj.LegacyStore) - if err != nil { - return errors.NewField("LegacyStore", err) - } - return nil -} - -func (obj LegacyFeedsConfig) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding LegacyFeedsConfig: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *LegacyFeedsConfig) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `IdToFeed`: - err = decoder.Decode(&obj.IdToFeed) - if err != nil { - return errors.NewField("IdToFeed", err) - } - // Deserialize `LegacyStore`: - err = decoder.Decode(&obj.LegacyStore) - if err != nil { - return errors.NewField("LegacyStore", err) - } - return nil -} - -func (obj *LegacyFeedsConfig) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling LegacyFeedsConfig: %w", err) - } - return nil -} - -func UnmarshalLegacyFeedsConfig(buf []byte) (*LegacyFeedsConfig, error) { - obj := new(LegacyFeedsConfig) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeLegacyFeedsConfigStruct(in LegacyFeedsConfig) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromLegacyFeedsConfig( - runtime cre.Runtime, - input LegacyFeedsConfig, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeLegacyFeedsConfigStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromLegacyFeedsConfigs( - runtime cre.Runtime, - inputs []LegacyFeedsConfig, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeLegacyFeedsConfigStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type LegacyFeedsConfigInitialized struct { - State solanago.PublicKey `json:"state"` - Config solanago.PublicKey `json:"config"` -} - -func (obj LegacyFeedsConfigInitialized) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `State`: - err = encoder.Encode(obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Serialize `Config`: - err = encoder.Encode(obj.Config) - if err != nil { - return errors.NewField("Config", err) - } - return nil -} - -func (obj LegacyFeedsConfigInitialized) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding LegacyFeedsConfigInitialized: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *LegacyFeedsConfigInitialized) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `State`: - err = decoder.Decode(&obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Deserialize `Config`: - err = decoder.Decode(&obj.Config) - if err != nil { - return errors.NewField("Config", err) - } - return nil -} - -func (obj *LegacyFeedsConfigInitialized) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling LegacyFeedsConfigInitialized: %w", err) - } - return nil -} - -func UnmarshalLegacyFeedsConfigInitialized(buf []byte) (*LegacyFeedsConfigInitialized, error) { - obj := new(LegacyFeedsConfigInitialized) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeLegacyFeedsConfigInitializedStruct(in LegacyFeedsConfigInitialized) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromLegacyFeedsConfigInitialized( - runtime cre.Runtime, - input LegacyFeedsConfigInitialized, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeLegacyFeedsConfigInitializedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromLegacyFeedsConfigInitializeds( - runtime cre.Runtime, - inputs []LegacyFeedsConfigInitialized, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeLegacyFeedsConfigInitializedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type LegacyFeedsConfigUpdated struct { - State solanago.PublicKey `json:"state"` - Config solanago.PublicKey `json:"config"` -} - -func (obj LegacyFeedsConfigUpdated) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `State`: - err = encoder.Encode(obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Serialize `Config`: - err = encoder.Encode(obj.Config) - if err != nil { - return errors.NewField("Config", err) - } - return nil -} - -func (obj LegacyFeedsConfigUpdated) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding LegacyFeedsConfigUpdated: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *LegacyFeedsConfigUpdated) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `State`: - err = decoder.Decode(&obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Deserialize `Config`: - err = decoder.Decode(&obj.Config) - if err != nil { - return errors.NewField("Config", err) - } - return nil -} - -func (obj *LegacyFeedsConfigUpdated) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling LegacyFeedsConfigUpdated: %w", err) - } - return nil -} - -func UnmarshalLegacyFeedsConfigUpdated(buf []byte) (*LegacyFeedsConfigUpdated, error) { - obj := new(LegacyFeedsConfigUpdated) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeLegacyFeedsConfigUpdatedStruct(in LegacyFeedsConfigUpdated) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromLegacyFeedsConfigUpdated( - runtime cre.Runtime, - input LegacyFeedsConfigUpdated, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeLegacyFeedsConfigUpdatedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromLegacyFeedsConfigUpdateds( - runtime cre.Runtime, - inputs []LegacyFeedsConfigUpdated, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeLegacyFeedsConfigUpdatedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type LegacyFeedsReported struct { - State solanago.PublicKey `json:"state"` - FeedsSkipped [][16]uint8 `json:"feeds_skipped"` - FeedsWritten [][16]uint8 `json:"feeds_written"` -} - -func (obj LegacyFeedsReported) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `State`: - err = encoder.Encode(obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Serialize `FeedsSkipped`: - err = encoder.Encode(obj.FeedsSkipped) - if err != nil { - return errors.NewField("FeedsSkipped", err) - } - // Serialize `FeedsWritten`: - err = encoder.Encode(obj.FeedsWritten) - if err != nil { - return errors.NewField("FeedsWritten", err) - } - return nil -} - -func (obj LegacyFeedsReported) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding LegacyFeedsReported: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *LegacyFeedsReported) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `State`: - err = decoder.Decode(&obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Deserialize `FeedsSkipped`: - err = decoder.Decode(&obj.FeedsSkipped) - if err != nil { - return errors.NewField("FeedsSkipped", err) - } - // Deserialize `FeedsWritten`: - err = decoder.Decode(&obj.FeedsWritten) - if err != nil { - return errors.NewField("FeedsWritten", err) - } - return nil -} - -func (obj *LegacyFeedsReported) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling LegacyFeedsReported: %w", err) - } - return nil -} - -func UnmarshalLegacyFeedsReported(buf []byte) (*LegacyFeedsReported, error) { - obj := new(LegacyFeedsReported) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeLegacyFeedsReportedStruct(in LegacyFeedsReported) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromLegacyFeedsReported( - runtime cre.Runtime, - input LegacyFeedsReported, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeLegacyFeedsReportedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromLegacyFeedsReporteds( - runtime cre.Runtime, - inputs []LegacyFeedsReported, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeLegacyFeedsReportedStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type OwnershipAcceptance struct { - State solanago.PublicKey `json:"state"` - PreviousOwner solanago.PublicKey `json:"previous_owner"` - NewOwner solanago.PublicKey `json:"new_owner"` -} - -func (obj OwnershipAcceptance) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `State`: - err = encoder.Encode(obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Serialize `PreviousOwner`: - err = encoder.Encode(obj.PreviousOwner) - if err != nil { - return errors.NewField("PreviousOwner", err) - } - // Serialize `NewOwner`: - err = encoder.Encode(obj.NewOwner) - if err != nil { - return errors.NewField("NewOwner", err) - } - return nil -} - -func (obj OwnershipAcceptance) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding OwnershipAcceptance: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *OwnershipAcceptance) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `State`: - err = decoder.Decode(&obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Deserialize `PreviousOwner`: - err = decoder.Decode(&obj.PreviousOwner) - if err != nil { - return errors.NewField("PreviousOwner", err) - } - // Deserialize `NewOwner`: - err = decoder.Decode(&obj.NewOwner) - if err != nil { - return errors.NewField("NewOwner", err) - } - return nil -} - -func (obj *OwnershipAcceptance) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling OwnershipAcceptance: %w", err) - } - return nil -} - -func UnmarshalOwnershipAcceptance(buf []byte) (*OwnershipAcceptance, error) { - obj := new(OwnershipAcceptance) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeOwnershipAcceptanceStruct(in OwnershipAcceptance) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromOwnershipAcceptance( - runtime cre.Runtime, - input OwnershipAcceptance, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeOwnershipAcceptanceStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromOwnershipAcceptances( - runtime cre.Runtime, - inputs []OwnershipAcceptance, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeOwnershipAcceptanceStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type OwnershipTransfer struct { - State solanago.PublicKey `json:"state"` - CurrentOwner solanago.PublicKey `json:"current_owner"` - ProposedOwner solanago.PublicKey `json:"proposed_owner"` -} - -func (obj OwnershipTransfer) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `State`: - err = encoder.Encode(obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Serialize `CurrentOwner`: - err = encoder.Encode(obj.CurrentOwner) - if err != nil { - return errors.NewField("CurrentOwner", err) - } - // Serialize `ProposedOwner`: - err = encoder.Encode(obj.ProposedOwner) - if err != nil { - return errors.NewField("ProposedOwner", err) - } - return nil -} - -func (obj OwnershipTransfer) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding OwnershipTransfer: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *OwnershipTransfer) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `State`: - err = decoder.Decode(&obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Deserialize `CurrentOwner`: - err = decoder.Decode(&obj.CurrentOwner) - if err != nil { - return errors.NewField("CurrentOwner", err) - } - // Deserialize `ProposedOwner`: - err = decoder.Decode(&obj.ProposedOwner) - if err != nil { - return errors.NewField("ProposedOwner", err) - } - return nil -} - -func (obj *OwnershipTransfer) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling OwnershipTransfer: %w", err) - } - return nil -} - -func UnmarshalOwnershipTransfer(buf []byte) (*OwnershipTransfer, error) { - obj := new(OwnershipTransfer) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeOwnershipTransferStruct(in OwnershipTransfer) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromOwnershipTransfer( - runtime cre.Runtime, - input OwnershipTransfer, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeOwnershipTransferStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromOwnershipTransfers( - runtime cre.Runtime, - inputs []OwnershipTransfer, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeOwnershipTransferStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -// Decimal report received by the cache from the forwarder -type ReceivedDecimalReport struct { - Timestamp uint32 `json:"timestamp"` - Answer binary.Uint128 `json:"answer"` - DataId [16]uint8 `json:"data_id"` -} - -func (obj ReceivedDecimalReport) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `Timestamp`: - err = encoder.Encode(obj.Timestamp) - if err != nil { - return errors.NewField("Timestamp", err) - } - // Serialize `Answer`: - err = encoder.Encode(obj.Answer) - if err != nil { - return errors.NewField("Answer", err) - } - // Serialize `DataId`: - err = encoder.Encode(obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - return nil -} - -func (obj ReceivedDecimalReport) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding ReceivedDecimalReport: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *ReceivedDecimalReport) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `Timestamp`: - err = decoder.Decode(&obj.Timestamp) - if err != nil { - return errors.NewField("Timestamp", err) - } - // Deserialize `Answer`: - err = decoder.Decode(&obj.Answer) - if err != nil { - return errors.NewField("Answer", err) - } - // Deserialize `DataId`: - err = decoder.Decode(&obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - return nil -} - -func (obj *ReceivedDecimalReport) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling ReceivedDecimalReport: %w", err) - } - return nil -} - -func UnmarshalReceivedDecimalReport(buf []byte) (*ReceivedDecimalReport, error) { - obj := new(ReceivedDecimalReport) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeReceivedDecimalReportStruct(in ReceivedDecimalReport) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromReceivedDecimalReport( - runtime cre.Runtime, - input ReceivedDecimalReport, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeReceivedDecimalReportStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromReceivedDecimalReports( - runtime cre.Runtime, - inputs []ReceivedDecimalReport, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeReceivedDecimalReportStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -// IDL exposure helper: surfaces `ReceivedDecimalReport` in the generated IDL -// so off-chain bindings can construct the `on_report` payload without -// re-declaring the wire schema. This event is intentionally never emitted -// by the program; declaring it is sufficient for Anchor's IDL generator to -// pull `ReceivedDecimalReport` into `types`. -type ReceivedDecimalReportsSchema struct { - Reports []ReceivedDecimalReport `json:"reports"` -} - -func (obj ReceivedDecimalReportsSchema) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `Reports`: - err = encoder.Encode(obj.Reports) - if err != nil { - return errors.NewField("Reports", err) - } - return nil -} - -func (obj ReceivedDecimalReportsSchema) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding ReceivedDecimalReportsSchema: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *ReceivedDecimalReportsSchema) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `Reports`: - err = decoder.Decode(&obj.Reports) - if err != nil { - return errors.NewField("Reports", err) - } - return nil -} - -func (obj *ReceivedDecimalReportsSchema) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling ReceivedDecimalReportsSchema: %w", err) - } - return nil -} - -func UnmarshalReceivedDecimalReportsSchema(buf []byte) (*ReceivedDecimalReportsSchema, error) { - obj := new(ReceivedDecimalReportsSchema) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeReceivedDecimalReportsSchemaStruct(in ReceivedDecimalReportsSchema) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromReceivedDecimalReportsSchema( - runtime cre.Runtime, - input ReceivedDecimalReportsSchema, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeReceivedDecimalReportsSchemaStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromReceivedDecimalReportsSchemas( - runtime cre.Runtime, - inputs []ReceivedDecimalReportsSchema, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeReceivedDecimalReportsSchemaStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -type StaleDecimalReport struct { - State solanago.PublicKey `json:"state"` - DataId [16]uint8 `json:"data_id"` - ReceivedTimestamp uint32 `json:"received_timestamp"` - LatestTimestamp uint32 `json:"latest_timestamp"` -} - -func (obj StaleDecimalReport) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `State`: - err = encoder.Encode(obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Serialize `DataId`: - err = encoder.Encode(obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - // Serialize `ReceivedTimestamp`: - err = encoder.Encode(obj.ReceivedTimestamp) - if err != nil { - return errors.NewField("ReceivedTimestamp", err) - } - // Serialize `LatestTimestamp`: - err = encoder.Encode(obj.LatestTimestamp) - if err != nil { - return errors.NewField("LatestTimestamp", err) - } - return nil -} - -func (obj StaleDecimalReport) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding StaleDecimalReport: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *StaleDecimalReport) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `State`: - err = decoder.Decode(&obj.State) - if err != nil { - return errors.NewField("State", err) - } - // Deserialize `DataId`: - err = decoder.Decode(&obj.DataId) - if err != nil { - return errors.NewField("DataId", err) - } - // Deserialize `ReceivedTimestamp`: - err = decoder.Decode(&obj.ReceivedTimestamp) - if err != nil { - return errors.NewField("ReceivedTimestamp", err) - } - // Deserialize `LatestTimestamp`: - err = decoder.Decode(&obj.LatestTimestamp) - if err != nil { - return errors.NewField("LatestTimestamp", err) - } - return nil -} - -func (obj *StaleDecimalReport) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling StaleDecimalReport: %w", err) - } - return nil -} - -func UnmarshalStaleDecimalReport(buf []byte) (*StaleDecimalReport, error) { - obj := new(StaleDecimalReport) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeStaleDecimalReportStruct(in StaleDecimalReport) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromStaleDecimalReport( - runtime cre.Runtime, - input StaleDecimalReport, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeStaleDecimalReportStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromStaleDecimalReports( - runtime cre.Runtime, - inputs []StaleDecimalReport, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeStaleDecimalReportStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -// Represents information about a workflow which can be used to authorize it -// for the reporting of a feed -type WorkflowMetadata struct { - AllowedSender solanago.PublicKey `json:"allowed_sender"` - AllowedWorkflowOwner [20]uint8 `json:"allowed_workflow_owner"` - AllowedWorkflowName [10]uint8 `json:"allowed_workflow_name"` -} - -func (obj WorkflowMetadata) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `AllowedSender`: - err = encoder.Encode(obj.AllowedSender) - if err != nil { - return errors.NewField("AllowedSender", err) - } - // Serialize `AllowedWorkflowOwner`: - err = encoder.Encode(obj.AllowedWorkflowOwner) - if err != nil { - return errors.NewField("AllowedWorkflowOwner", err) - } - // Serialize `AllowedWorkflowName`: - err = encoder.Encode(obj.AllowedWorkflowName) - if err != nil { - return errors.NewField("AllowedWorkflowName", err) - } - return nil -} - -func (obj WorkflowMetadata) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding WorkflowMetadata: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *WorkflowMetadata) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `AllowedSender`: - err = decoder.Decode(&obj.AllowedSender) - if err != nil { - return errors.NewField("AllowedSender", err) - } - // Deserialize `AllowedWorkflowOwner`: - err = decoder.Decode(&obj.AllowedWorkflowOwner) - if err != nil { - return errors.NewField("AllowedWorkflowOwner", err) - } - // Deserialize `AllowedWorkflowName`: - err = decoder.Decode(&obj.AllowedWorkflowName) - if err != nil { - return errors.NewField("AllowedWorkflowName", err) - } - return nil -} - -func (obj *WorkflowMetadata) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling WorkflowMetadata: %w", err) - } - return nil -} - -func UnmarshalWorkflowMetadata(buf []byte) (*WorkflowMetadata, error) { - obj := new(WorkflowMetadata) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeWorkflowMetadataStruct(in WorkflowMetadata) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromWorkflowMetadata( - runtime cre.Runtime, - input WorkflowMetadata, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeWorkflowMetadataStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromWorkflowMetadatas( - runtime cre.Runtime, - inputs []WorkflowMetadata, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeWorkflowMetadataStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -} - -// Fixed size struct which stores list of workflow metadatas -type WorkflowMetadataList struct { - Xs [16]WorkflowMetadata `json:"xs"` - Len uint64 `json:"len"` -} - -func (obj WorkflowMetadataList) MarshalWithEncoder(encoder *binary.Encoder) (err error) { - // Serialize `Xs`: - err = encoder.Encode(obj.Xs) - if err != nil { - return errors.NewField("Xs", err) - } - // Serialize `Len`: - err = encoder.Encode(obj.Len) - if err != nil { - return errors.NewField("Len", err) - } - return nil -} - -func (obj WorkflowMetadataList) Marshal() ([]byte, error) { - buf := bytes.NewBuffer(nil) - encoder := binary.NewBorshEncoder(buf) - err := obj.MarshalWithEncoder(encoder) - if err != nil { - return nil, fmt.Errorf("error while encoding WorkflowMetadataList: %w", err) - } - return buf.Bytes(), nil -} - -func (obj *WorkflowMetadataList) UnmarshalWithDecoder(decoder *binary.Decoder) (err error) { - // Deserialize `Xs`: - err = decoder.Decode(&obj.Xs) - if err != nil { - return errors.NewField("Xs", err) - } - // Deserialize `Len`: - err = decoder.Decode(&obj.Len) - if err != nil { - return errors.NewField("Len", err) - } - return nil -} - -func (obj *WorkflowMetadataList) Unmarshal(buf []byte) error { - err := obj.UnmarshalWithDecoder(binary.NewBorshDecoder(buf)) - if err != nil { - return fmt.Errorf("error while unmarshaling WorkflowMetadataList: %w", err) - } - return nil -} - -func UnmarshalWorkflowMetadataList(buf []byte) (*WorkflowMetadataList, error) { - obj := new(WorkflowMetadataList) - err := obj.Unmarshal(buf) - if err != nil { - return nil, err - } - return obj, nil -} - -func (c *Codec) EncodeWorkflowMetadataListStruct(in WorkflowMetadataList) ([]byte, error) { - return in.Marshal() -} - -func (c *DataFeedsCache) WriteReportFromWorkflowMetadataList( - runtime cre.Runtime, - input WorkflowMetadataList, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - encodedInput, err := c.Codec.EncodeWorkflowMetadataListStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - encodedAccountList := bindings.CalculateAccountsHash(remainingAccounts) - - fwdReport := bindings.ForwarderReport{ - AccountHash: encodedAccountList, - Payload: encodedInput, - } - encodedFwdReport, err := fwdReport.Marshal() - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - - promise := runtime.GenerateReport(&sdk.ReportRequest{ - EncodedPayload: encodedFwdReport, - EncoderName: "solana", - HashingAlgo: "keccak256", - SigningAlgo: "ecdsa", - }) - - return cre.ThenPromise(promise, func(report *cre.Report) cre.Promise[*solana.WriteReportReply] { - return c.client.WriteReport(runtime, &solana.WriteCreReportRequest{ - ComputeConfig: computeConfig, - Receiver: ProgramID.Bytes(), - RemainingAccounts: remainingAccounts, - Report: report, - }) - }) -} - -func (c *DataFeedsCache) WriteReportFromWorkflowMetadataLists( - runtime cre.Runtime, - inputs []WorkflowMetadataList, - remainingAccounts []*solana.AccountMeta, - computeConfig *solana.ComputeConfig, -) cre.Promise[*solana.WriteReportReply] { - elements := make([][]byte, len(inputs)) - for i, input := range inputs { - encoded, err := c.Codec.EncodeWorkflowMetadataListStruct(input) - if err != nil { - return cre.PromiseFromResult[*solana.WriteReportReply](nil, err) - } - elements[i] = encoded - } - return c.WriteReportFromBorshEncodedVec(runtime, elements, remainingAccounts, computeConfig) -}