github.com/diadata-org/diadata@v1.4.593/pkg/dia/scraper/exchange-scrapers/orca/whirlpool/CollectReward.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  // CollectReward is the `collectReward` instruction.
    14  type CollectReward struct {
    15  	RewardIndex *uint8
    16  
    17  	// [0] = [] whirlpool
    18  	//
    19  	// [1] = [SIGNER] positionAuthority
    20  	//
    21  	// [2] = [WRITE] position
    22  	//
    23  	// [3] = [] positionTokenAccount
    24  	//
    25  	// [4] = [WRITE] rewardOwnerAccount
    26  	//
    27  	// [5] = [WRITE] rewardVault
    28  	//
    29  	// [6] = [] tokenProgram
    30  	ag_solanago.AccountMetaSlice `bin:"-"`
    31  }
    32  
    33  // NewCollectRewardInstructionBuilder creates a new `CollectReward` instruction builder.
    34  func NewCollectRewardInstructionBuilder() *CollectReward {
    35  	nd := &CollectReward{
    36  		AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 7),
    37  	}
    38  	return nd
    39  }
    40  
    41  // SetRewardIndex sets the "rewardIndex" parameter.
    42  func (inst *CollectReward) SetRewardIndex(rewardIndex uint8) *CollectReward {
    43  	inst.RewardIndex = &rewardIndex
    44  	return inst
    45  }
    46  
    47  // SetWhirlpoolAccount sets the "whirlpool" account.
    48  func (inst *CollectReward) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *CollectReward {
    49  	inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool)
    50  	return inst
    51  }
    52  
    53  // GetWhirlpoolAccount gets the "whirlpool" account.
    54  func (inst *CollectReward) GetWhirlpoolAccount() *ag_solanago.AccountMeta {
    55  	return inst.AccountMetaSlice.Get(0)
    56  }
    57  
    58  // SetPositionAuthorityAccount sets the "positionAuthority" account.
    59  func (inst *CollectReward) SetPositionAuthorityAccount(positionAuthority ag_solanago.PublicKey) *CollectReward {
    60  	inst.AccountMetaSlice[1] = ag_solanago.Meta(positionAuthority).SIGNER()
    61  	return inst
    62  }
    63  
    64  // GetPositionAuthorityAccount gets the "positionAuthority" account.
    65  func (inst *CollectReward) GetPositionAuthorityAccount() *ag_solanago.AccountMeta {
    66  	return inst.AccountMetaSlice.Get(1)
    67  }
    68  
    69  // SetPositionAccount sets the "position" account.
    70  func (inst *CollectReward) SetPositionAccount(position ag_solanago.PublicKey) *CollectReward {
    71  	inst.AccountMetaSlice[2] = ag_solanago.Meta(position).WRITE()
    72  	return inst
    73  }
    74  
    75  // GetPositionAccount gets the "position" account.
    76  func (inst *CollectReward) GetPositionAccount() *ag_solanago.AccountMeta {
    77  	return inst.AccountMetaSlice.Get(2)
    78  }
    79  
    80  // SetPositionTokenAccountAccount sets the "positionTokenAccount" account.
    81  func (inst *CollectReward) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *CollectReward {
    82  	inst.AccountMetaSlice[3] = ag_solanago.Meta(positionTokenAccount)
    83  	return inst
    84  }
    85  
    86  // GetPositionTokenAccountAccount gets the "positionTokenAccount" account.
    87  func (inst *CollectReward) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta {
    88  	return inst.AccountMetaSlice.Get(3)
    89  }
    90  
    91  // SetRewardOwnerAccountAccount sets the "rewardOwnerAccount" account.
    92  func (inst *CollectReward) SetRewardOwnerAccountAccount(rewardOwnerAccount ag_solanago.PublicKey) *CollectReward {
    93  	inst.AccountMetaSlice[4] = ag_solanago.Meta(rewardOwnerAccount).WRITE()
    94  	return inst
    95  }
    96  
    97  // GetRewardOwnerAccountAccount gets the "rewardOwnerAccount" account.
    98  func (inst *CollectReward) GetRewardOwnerAccountAccount() *ag_solanago.AccountMeta {
    99  	return inst.AccountMetaSlice.Get(4)
   100  }
   101  
   102  // SetRewardVaultAccount sets the "rewardVault" account.
   103  func (inst *CollectReward) SetRewardVaultAccount(rewardVault ag_solanago.PublicKey) *CollectReward {
   104  	inst.AccountMetaSlice[5] = ag_solanago.Meta(rewardVault).WRITE()
   105  	return inst
   106  }
   107  
   108  // GetRewardVaultAccount gets the "rewardVault" account.
   109  func (inst *CollectReward) GetRewardVaultAccount() *ag_solanago.AccountMeta {
   110  	return inst.AccountMetaSlice.Get(5)
   111  }
   112  
   113  // SetTokenProgramAccount sets the "tokenProgram" account.
   114  func (inst *CollectReward) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *CollectReward {
   115  	inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenProgram)
   116  	return inst
   117  }
   118  
   119  // GetTokenProgramAccount gets the "tokenProgram" account.
   120  func (inst *CollectReward) GetTokenProgramAccount() *ag_solanago.AccountMeta {
   121  	return inst.AccountMetaSlice.Get(6)
   122  }
   123  
   124  func (inst CollectReward) Build() *Instruction {
   125  	return &Instruction{BaseVariant: ag_binary.BaseVariant{
   126  		Impl:   inst,
   127  		TypeID: Instruction_CollectReward,
   128  	}}
   129  }
   130  
   131  // ValidateAndBuild validates the instruction parameters and accounts;
   132  // if there is a validation error, it returns the error.
   133  // Otherwise, it builds and returns the instruction.
   134  func (inst CollectReward) ValidateAndBuild() (*Instruction, error) {
   135  	if err := inst.Validate(); err != nil {
   136  		return nil, err
   137  	}
   138  	return inst.Build(), nil
   139  }
   140  
   141  func (inst *CollectReward) Validate() error {
   142  	// Check whether all (required) parameters are set:
   143  	{
   144  		if inst.RewardIndex == nil {
   145  			return errors.New("RewardIndex parameter is not set")
   146  		}
   147  	}
   148  
   149  	// Check whether all (required) accounts are set:
   150  	{
   151  		if inst.AccountMetaSlice[0] == nil {
   152  			return errors.New("accounts.Whirlpool is not set")
   153  		}
   154  		if inst.AccountMetaSlice[1] == nil {
   155  			return errors.New("accounts.PositionAuthority is not set")
   156  		}
   157  		if inst.AccountMetaSlice[2] == nil {
   158  			return errors.New("accounts.Position is not set")
   159  		}
   160  		if inst.AccountMetaSlice[3] == nil {
   161  			return errors.New("accounts.PositionTokenAccount is not set")
   162  		}
   163  		if inst.AccountMetaSlice[4] == nil {
   164  			return errors.New("accounts.RewardOwnerAccount is not set")
   165  		}
   166  		if inst.AccountMetaSlice[5] == nil {
   167  			return errors.New("accounts.RewardVault is not set")
   168  		}
   169  		if inst.AccountMetaSlice[6] == nil {
   170  			return errors.New("accounts.TokenProgram is not set")
   171  		}
   172  	}
   173  	return nil
   174  }
   175  
   176  func (inst *CollectReward) EncodeToTree(parent ag_treeout.Branches) {
   177  	parent.Child(ag_format.Program(ProgramName, ProgramID)).
   178  		//
   179  		ParentFunc(func(programBranch ag_treeout.Branches) {
   180  			programBranch.Child(ag_format.Instruction("CollectReward")).
   181  				//
   182  				ParentFunc(func(instructionBranch ag_treeout.Branches) {
   183  
   184  					// Parameters of the instruction:
   185  					instructionBranch.Child("Params[len=1]").ParentFunc(func(paramsBranch ag_treeout.Branches) {
   186  						paramsBranch.Child(ag_format.Param("RewardIndex", *inst.RewardIndex))
   187  					})
   188  
   189  					// Accounts of the instruction:
   190  					instructionBranch.Child("Accounts[len=7]").ParentFunc(func(accountsBranch ag_treeout.Branches) {
   191  						accountsBranch.Child(ag_format.Meta("        whirlpool", inst.AccountMetaSlice.Get(0)))
   192  						accountsBranch.Child(ag_format.Meta("positionAuthority", inst.AccountMetaSlice.Get(1)))
   193  						accountsBranch.Child(ag_format.Meta("         position", inst.AccountMetaSlice.Get(2)))
   194  						accountsBranch.Child(ag_format.Meta("    positionToken", inst.AccountMetaSlice.Get(3)))
   195  						accountsBranch.Child(ag_format.Meta("      rewardOwner", inst.AccountMetaSlice.Get(4)))
   196  						accountsBranch.Child(ag_format.Meta("      rewardVault", inst.AccountMetaSlice.Get(5)))
   197  						accountsBranch.Child(ag_format.Meta("     tokenProgram", inst.AccountMetaSlice.Get(6)))
   198  					})
   199  				})
   200  		})
   201  }
   202  
   203  func (obj CollectReward) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) {
   204  	// Serialize `RewardIndex` param:
   205  	err = encoder.Encode(obj.RewardIndex)
   206  	if err != nil {
   207  		return err
   208  	}
   209  	return nil
   210  }
   211  func (obj *CollectReward) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) {
   212  	// Deserialize `RewardIndex`:
   213  	err = decoder.Decode(&obj.RewardIndex)
   214  	if err != nil {
   215  		return err
   216  	}
   217  	return nil
   218  }
   219  
   220  // NewCollectRewardInstruction declares a new CollectReward instruction with the provided parameters and accounts.
   221  func NewCollectRewardInstruction(
   222  	// Parameters:
   223  	rewardIndex uint8,
   224  	// Accounts:
   225  	whirlpool ag_solanago.PublicKey,
   226  	positionAuthority ag_solanago.PublicKey,
   227  	position ag_solanago.PublicKey,
   228  	positionTokenAccount ag_solanago.PublicKey,
   229  	rewardOwnerAccount ag_solanago.PublicKey,
   230  	rewardVault ag_solanago.PublicKey,
   231  	tokenProgram ag_solanago.PublicKey) *CollectReward {
   232  	return NewCollectRewardInstructionBuilder().
   233  		SetRewardIndex(rewardIndex).
   234  		SetWhirlpoolAccount(whirlpool).
   235  		SetPositionAuthorityAccount(positionAuthority).
   236  		SetPositionAccount(position).
   237  		SetPositionTokenAccountAccount(positionTokenAccount).
   238  		SetRewardOwnerAccountAccount(rewardOwnerAccount).
   239  		SetRewardVaultAccount(rewardVault).
   240  		SetTokenProgramAccount(tokenProgram)
   241  }