github.com/diadata-org/diadata@v1.4.593/pkg/dia/scraper/exchange-scrapers/orca/whirlpool/SetRewardAuthority.go (about) 1 // Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT. 2 3 package whirlpool 4 5 import ( 6 "errors" 7 ag_binary "github.com/gagliardetto/binary" 8 ag_solanago "github.com/gagliardetto/solana-go" 9 ag_format "github.com/gagliardetto/solana-go/text/format" 10 ag_treeout "github.com/gagliardetto/treeout" 11 ) 12 13 // SetRewardAuthority is the `setRewardAuthority` instruction. 14 type SetRewardAuthority struct { 15 RewardIndex *uint8 16 17 // [0] = [WRITE] whirlpool 18 // 19 // [1] = [SIGNER] rewardAuthority 20 // 21 // [2] = [] newRewardAuthority 22 ag_solanago.AccountMetaSlice `bin:"-"` 23 } 24 25 // NewSetRewardAuthorityInstructionBuilder creates a new `SetRewardAuthority` instruction builder. 26 func NewSetRewardAuthorityInstructionBuilder() *SetRewardAuthority { 27 nd := &SetRewardAuthority{ 28 AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3), 29 } 30 return nd 31 } 32 33 // SetRewardIndex sets the "rewardIndex" parameter. 34 func (inst *SetRewardAuthority) SetRewardIndex(rewardIndex uint8) *SetRewardAuthority { 35 inst.RewardIndex = &rewardIndex 36 return inst 37 } 38 39 // SetWhirlpoolAccount sets the "whirlpool" account. 40 func (inst *SetRewardAuthority) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *SetRewardAuthority { 41 inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool).WRITE() 42 return inst 43 } 44 45 // GetWhirlpoolAccount gets the "whirlpool" account. 46 func (inst *SetRewardAuthority) GetWhirlpoolAccount() *ag_solanago.AccountMeta { 47 return inst.AccountMetaSlice.Get(0) 48 } 49 50 // SetRewardAuthorityAccount sets the "rewardAuthority" account. 51 func (inst *SetRewardAuthority) SetRewardAuthorityAccount(rewardAuthority ag_solanago.PublicKey) *SetRewardAuthority { 52 inst.AccountMetaSlice[1] = ag_solanago.Meta(rewardAuthority).SIGNER() 53 return inst 54 } 55 56 // GetRewardAuthorityAccount gets the "rewardAuthority" account. 57 func (inst *SetRewardAuthority) GetRewardAuthorityAccount() *ag_solanago.AccountMeta { 58 return inst.AccountMetaSlice.Get(1) 59 } 60 61 // SetNewRewardAuthorityAccount sets the "newRewardAuthority" account. 62 func (inst *SetRewardAuthority) SetNewRewardAuthorityAccount(newRewardAuthority ag_solanago.PublicKey) *SetRewardAuthority { 63 inst.AccountMetaSlice[2] = ag_solanago.Meta(newRewardAuthority) 64 return inst 65 } 66 67 // GetNewRewardAuthorityAccount gets the "newRewardAuthority" account. 68 func (inst *SetRewardAuthority) GetNewRewardAuthorityAccount() *ag_solanago.AccountMeta { 69 return inst.AccountMetaSlice.Get(2) 70 } 71 72 func (inst SetRewardAuthority) Build() *Instruction { 73 return &Instruction{BaseVariant: ag_binary.BaseVariant{ 74 Impl: inst, 75 TypeID: Instruction_SetRewardAuthority, 76 }} 77 } 78 79 // ValidateAndBuild validates the instruction parameters and accounts; 80 // if there is a validation error, it returns the error. 81 // Otherwise, it builds and returns the instruction. 82 func (inst SetRewardAuthority) ValidateAndBuild() (*Instruction, error) { 83 if err := inst.Validate(); err != nil { 84 return nil, err 85 } 86 return inst.Build(), nil 87 } 88 89 func (inst *SetRewardAuthority) Validate() error { 90 // Check whether all (required) parameters are set: 91 { 92 if inst.RewardIndex == nil { 93 return errors.New("RewardIndex parameter is not set") 94 } 95 } 96 97 // Check whether all (required) accounts are set: 98 { 99 if inst.AccountMetaSlice[0] == nil { 100 return errors.New("accounts.Whirlpool is not set") 101 } 102 if inst.AccountMetaSlice[1] == nil { 103 return errors.New("accounts.RewardAuthority is not set") 104 } 105 if inst.AccountMetaSlice[2] == nil { 106 return errors.New("accounts.NewRewardAuthority is not set") 107 } 108 } 109 return nil 110 } 111 112 func (inst *SetRewardAuthority) EncodeToTree(parent ag_treeout.Branches) { 113 parent.Child(ag_format.Program(ProgramName, ProgramID)). 114 // 115 ParentFunc(func(programBranch ag_treeout.Branches) { 116 programBranch.Child(ag_format.Instruction("SetRewardAuthority")). 117 // 118 ParentFunc(func(instructionBranch ag_treeout.Branches) { 119 120 // Parameters of the instruction: 121 instructionBranch.Child("Params[len=1]").ParentFunc(func(paramsBranch ag_treeout.Branches) { 122 paramsBranch.Child(ag_format.Param("RewardIndex", *inst.RewardIndex)) 123 }) 124 125 // Accounts of the instruction: 126 instructionBranch.Child("Accounts[len=3]").ParentFunc(func(accountsBranch ag_treeout.Branches) { 127 accountsBranch.Child(ag_format.Meta(" whirlpool", inst.AccountMetaSlice.Get(0))) 128 accountsBranch.Child(ag_format.Meta(" rewardAuthority", inst.AccountMetaSlice.Get(1))) 129 accountsBranch.Child(ag_format.Meta("newRewardAuthority", inst.AccountMetaSlice.Get(2))) 130 }) 131 }) 132 }) 133 } 134 135 func (obj SetRewardAuthority) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) { 136 // Serialize `RewardIndex` param: 137 err = encoder.Encode(obj.RewardIndex) 138 if err != nil { 139 return err 140 } 141 return nil 142 } 143 func (obj *SetRewardAuthority) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) { 144 // Deserialize `RewardIndex`: 145 err = decoder.Decode(&obj.RewardIndex) 146 if err != nil { 147 return err 148 } 149 return nil 150 } 151 152 // NewSetRewardAuthorityInstruction declares a new SetRewardAuthority instruction with the provided parameters and accounts. 153 func NewSetRewardAuthorityInstruction( 154 // Parameters: 155 rewardIndex uint8, 156 // Accounts: 157 whirlpool ag_solanago.PublicKey, 158 rewardAuthority ag_solanago.PublicKey, 159 newRewardAuthority ag_solanago.PublicKey) *SetRewardAuthority { 160 return NewSetRewardAuthorityInstructionBuilder(). 161 SetRewardIndex(rewardIndex). 162 SetWhirlpoolAccount(whirlpool). 163 SetRewardAuthorityAccount(rewardAuthority). 164 SetNewRewardAuthorityAccount(newRewardAuthority) 165 }