github.com/diadata-org/diadata@v1.4.593/pkg/dia/scraper/exchange-scrapers/orca/whirlpool/SetDefaultProtocolFeeRate.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  // SetDefaultProtocolFeeRate is the `setDefaultProtocolFeeRate` instruction.
    14  type SetDefaultProtocolFeeRate struct {
    15  	DefaultProtocolFeeRate *uint16
    16  
    17  	// [0] = [WRITE] whirlpoolsConfig
    18  	//
    19  	// [1] = [SIGNER] feeAuthority
    20  	ag_solanago.AccountMetaSlice `bin:"-"`
    21  }
    22  
    23  // NewSetDefaultProtocolFeeRateInstructionBuilder creates a new `SetDefaultProtocolFeeRate` instruction builder.
    24  func NewSetDefaultProtocolFeeRateInstructionBuilder() *SetDefaultProtocolFeeRate {
    25  	nd := &SetDefaultProtocolFeeRate{
    26  		AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 2),
    27  	}
    28  	return nd
    29  }
    30  
    31  // SetDefaultProtocolFeeRate sets the "defaultProtocolFeeRate" parameter.
    32  func (inst *SetDefaultProtocolFeeRate) SetDefaultProtocolFeeRate(defaultProtocolFeeRate uint16) *SetDefaultProtocolFeeRate {
    33  	inst.DefaultProtocolFeeRate = &defaultProtocolFeeRate
    34  	return inst
    35  }
    36  
    37  // SetWhirlpoolsConfigAccount sets the "whirlpoolsConfig" account.
    38  func (inst *SetDefaultProtocolFeeRate) SetWhirlpoolsConfigAccount(whirlpoolsConfig ag_solanago.PublicKey) *SetDefaultProtocolFeeRate {
    39  	inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpoolsConfig).WRITE()
    40  	return inst
    41  }
    42  
    43  // GetWhirlpoolsConfigAccount gets the "whirlpoolsConfig" account.
    44  func (inst *SetDefaultProtocolFeeRate) GetWhirlpoolsConfigAccount() *ag_solanago.AccountMeta {
    45  	return inst.AccountMetaSlice.Get(0)
    46  }
    47  
    48  // SetFeeAuthorityAccount sets the "feeAuthority" account.
    49  func (inst *SetDefaultProtocolFeeRate) SetFeeAuthorityAccount(feeAuthority ag_solanago.PublicKey) *SetDefaultProtocolFeeRate {
    50  	inst.AccountMetaSlice[1] = ag_solanago.Meta(feeAuthority).SIGNER()
    51  	return inst
    52  }
    53  
    54  // GetFeeAuthorityAccount gets the "feeAuthority" account.
    55  func (inst *SetDefaultProtocolFeeRate) GetFeeAuthorityAccount() *ag_solanago.AccountMeta {
    56  	return inst.AccountMetaSlice.Get(1)
    57  }
    58  
    59  func (inst SetDefaultProtocolFeeRate) Build() *Instruction {
    60  	return &Instruction{BaseVariant: ag_binary.BaseVariant{
    61  		Impl:   inst,
    62  		TypeID: Instruction_SetDefaultProtocolFeeRate,
    63  	}}
    64  }
    65  
    66  // ValidateAndBuild validates the instruction parameters and accounts;
    67  // if there is a validation error, it returns the error.
    68  // Otherwise, it builds and returns the instruction.
    69  func (inst SetDefaultProtocolFeeRate) ValidateAndBuild() (*Instruction, error) {
    70  	if err := inst.Validate(); err != nil {
    71  		return nil, err
    72  	}
    73  	return inst.Build(), nil
    74  }
    75  
    76  func (inst *SetDefaultProtocolFeeRate) Validate() error {
    77  	// Check whether all (required) parameters are set:
    78  	{
    79  		if inst.DefaultProtocolFeeRate == nil {
    80  			return errors.New("DefaultProtocolFeeRate parameter is not set")
    81  		}
    82  	}
    83  
    84  	// Check whether all (required) accounts are set:
    85  	{
    86  		if inst.AccountMetaSlice[0] == nil {
    87  			return errors.New("accounts.WhirlpoolsConfig is not set")
    88  		}
    89  		if inst.AccountMetaSlice[1] == nil {
    90  			return errors.New("accounts.FeeAuthority is not set")
    91  		}
    92  	}
    93  	return nil
    94  }
    95  
    96  func (inst *SetDefaultProtocolFeeRate) EncodeToTree(parent ag_treeout.Branches) {
    97  	parent.Child(ag_format.Program(ProgramName, ProgramID)).
    98  		//
    99  		ParentFunc(func(programBranch ag_treeout.Branches) {
   100  			programBranch.Child(ag_format.Instruction("SetDefaultProtocolFeeRate")).
   101  				//
   102  				ParentFunc(func(instructionBranch ag_treeout.Branches) {
   103  
   104  					// Parameters of the instruction:
   105  					instructionBranch.Child("Params[len=1]").ParentFunc(func(paramsBranch ag_treeout.Branches) {
   106  						paramsBranch.Child(ag_format.Param("DefaultProtocolFeeRate", *inst.DefaultProtocolFeeRate))
   107  					})
   108  
   109  					// Accounts of the instruction:
   110  					instructionBranch.Child("Accounts[len=2]").ParentFunc(func(accountsBranch ag_treeout.Branches) {
   111  						accountsBranch.Child(ag_format.Meta("whirlpoolsConfig", inst.AccountMetaSlice.Get(0)))
   112  						accountsBranch.Child(ag_format.Meta("    feeAuthority", inst.AccountMetaSlice.Get(1)))
   113  					})
   114  				})
   115  		})
   116  }
   117  
   118  func (obj SetDefaultProtocolFeeRate) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) {
   119  	// Serialize `DefaultProtocolFeeRate` param:
   120  	err = encoder.Encode(obj.DefaultProtocolFeeRate)
   121  	if err != nil {
   122  		return err
   123  	}
   124  	return nil
   125  }
   126  func (obj *SetDefaultProtocolFeeRate) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) {
   127  	// Deserialize `DefaultProtocolFeeRate`:
   128  	err = decoder.Decode(&obj.DefaultProtocolFeeRate)
   129  	if err != nil {
   130  		return err
   131  	}
   132  	return nil
   133  }
   134  
   135  // NewSetDefaultProtocolFeeRateInstruction declares a new SetDefaultProtocolFeeRate instruction with the provided parameters and accounts.
   136  func NewSetDefaultProtocolFeeRateInstruction(
   137  	// Parameters:
   138  	defaultProtocolFeeRate uint16,
   139  	// Accounts:
   140  	whirlpoolsConfig ag_solanago.PublicKey,
   141  	feeAuthority ag_solanago.PublicKey) *SetDefaultProtocolFeeRate {
   142  	return NewSetDefaultProtocolFeeRateInstructionBuilder().
   143  		SetDefaultProtocolFeeRate(defaultProtocolFeeRate).
   144  		SetWhirlpoolsConfigAccount(whirlpoolsConfig).
   145  		SetFeeAuthorityAccount(feeAuthority)
   146  }