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