github.com/diadata-org/diadata@v1.4.593/pkg/dia/scraper/exchange-scrapers/orca/whirlpool/SetFeeRate.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  // SetFeeRate is the `setFeeRate` instruction.
    14  type SetFeeRate struct {
    15  	FeeRate *uint16
    16  
    17  	// [0] = [] whirlpoolsConfig
    18  	//
    19  	// [1] = [WRITE] whirlpool
    20  	//
    21  	// [2] = [SIGNER] feeAuthority
    22  	ag_solanago.AccountMetaSlice `bin:"-"`
    23  }
    24  
    25  // NewSetFeeRateInstructionBuilder creates a new `SetFeeRate` instruction builder.
    26  func NewSetFeeRateInstructionBuilder() *SetFeeRate {
    27  	nd := &SetFeeRate{
    28  		AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 3),
    29  	}
    30  	return nd
    31  }
    32  
    33  // SetFeeRate sets the "feeRate" parameter.
    34  func (inst *SetFeeRate) SetFeeRate(feeRate uint16) *SetFeeRate {
    35  	inst.FeeRate = &feeRate
    36  	return inst
    37  }
    38  
    39  // SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account.
    40  func (inst *SetFeeRate) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *SetFeeRate {
    41  	inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig)
    42  	return inst
    43  }
    44  
    45  // GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account.
    46  func (inst *SetFeeRate) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta {
    47  	return inst.AccountMetaSlice.Get(0)
    48  }
    49  
    50  // SetWhirlpoolAccount sets the "whirlpool" account.
    51  func (inst *SetFeeRate) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *SetFeeRate {
    52  	inst.AccountMetaSlice[1] = ag_solanago.Meta(whirlpool).WRITE()
    53  	return inst
    54  }
    55  
    56  // GetWhirlpoolAccount gets the "whirlpool" account.
    57  func (inst *SetFeeRate) GetWhirlpoolAccount() *ag_solanago.AccountMeta {
    58  	return inst.AccountMetaSlice.Get(1)
    59  }
    60  
    61  // SetFeeAuthorityAccount sets the "feeAuthority" account.
    62  func (inst *SetFeeRate) SetFeeAuthorityAccount(feeAuthority ag_solanago.PublicKey) *SetFeeRate {
    63  	inst.AccountMetaSlice[2] = ag_solanago.Meta(feeAuthority).SIGNER()
    64  	return inst
    65  }
    66  
    67  // GetFeeAuthorityAccount gets the "feeAuthority" account.
    68  func (inst *SetFeeRate) GetFeeAuthorityAccount() *ag_solanago.AccountMeta {
    69  	return inst.AccountMetaSlice.Get(2)
    70  }
    71  
    72  func (inst SetFeeRate) Build() *Instruction {
    73  	return &Instruction{BaseVariant: ag_binary.BaseVariant{
    74  		Impl:   inst,
    75  		TypeID: Instruction_SetFeeRate,
    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 SetFeeRate) 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 *SetFeeRate) Validate() error {
    90  	// Check whether all (required) parameters are set:
    91  	{
    92  		if inst.FeeRate == nil {
    93  			return errors.New("FeeRate 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.WhirlpoolsConfig is not set")
   101  		}
   102  		if inst.AccountMetaSlice[1] == nil {
   103  			return errors.New("accounts.Whirlpool is not set")
   104  		}
   105  		if inst.AccountMetaSlice[2] == nil {
   106  			return errors.New("accounts.FeeAuthority is not set")
   107  		}
   108  	}
   109  	return nil
   110  }
   111  
   112  func (inst *SetFeeRate) 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("SetFeeRate")).
   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("FeeRate", *inst.FeeRate))
   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("whirlpoolsConfig", inst.AccountMetaSlice.Get(0)))
   128  						accountsBranch.Child(ag_format.Meta("       whirlpool", inst.AccountMetaSlice.Get(1)))
   129  						accountsBranch.Child(ag_format.Meta("    feeAuthority", inst.AccountMetaSlice.Get(2)))
   130  					})
   131  				})
   132  		})
   133  }
   134  
   135  func (obj SetFeeRate) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) {
   136  	// Serialize `FeeRate` param:
   137  	err = encoder.Encode(obj.FeeRate)
   138  	if err != nil {
   139  		return err
   140  	}
   141  	return nil
   142  }
   143  func (obj *SetFeeRate) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) {
   144  	// Deserialize `FeeRate`:
   145  	err = decoder.Decode(&obj.FeeRate)
   146  	if err != nil {
   147  		return err
   148  	}
   149  	return nil
   150  }
   151  
   152  // NewSetFeeRateInstruction declares a new SetFeeRate instruction with the provided parameters and accounts.
   153  func NewSetFeeRateInstruction(
   154  	// Parameters:
   155  	feeRate uint16,
   156  	// Accounts:
   157  	whirlpoolsConfig ag_solanago.PublicKey,
   158  	whirlpool ag_solanago.PublicKey,
   159  	feeAuthority ag_solanago.PublicKey) *SetFeeRate {
   160  	return NewSetFeeRateInstructionBuilder().
   161  		SetFeeRate(feeRate).
   162  		SetWhirlpoolsConfigAccount(whirlpoolsConfig).
   163  		SetWhirlpoolAccount(whirlpool).
   164  		SetFeeAuthorityAccount(feeAuthority)
   165  }