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