github.com/diadata-org/diadata@v1.4.593/pkg/dia/scraper/exchange-scrapers/orca/whirlpool/InitializeTickArray.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  // InitializeTickArray is the `initializeTickArray` instruction.
    14  type InitializeTickArray struct {
    15  	StartTickIndex *int32
    16  
    17  	// [0] = [] whirlpool
    18  	//
    19  	// [1] = [WRITE, SIGNER] funder
    20  	//
    21  	// [2] = [WRITE] tickArray
    22  	//
    23  	// [3] = [] systemProgram
    24  	ag_solanago.AccountMetaSlice `bin:"-"`
    25  }
    26  
    27  // NewInitializeTickArrayInstructionBuilder creates a new `InitializeTickArray` instruction builder.
    28  func NewInitializeTickArrayInstructionBuilder() *InitializeTickArray {
    29  	nd := &InitializeTickArray{
    30  		AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 4),
    31  	}
    32  	return nd
    33  }
    34  
    35  // SetStartTickIndex sets the "startTickIndex" parameter.
    36  func (inst *InitializeTickArray) SetStartTickIndex(startTickIndex int32) *InitializeTickArray {
    37  	inst.StartTickIndex = &startTickIndex
    38  	return inst
    39  }
    40  
    41  // SetWhirlpoolAccount sets the "whirlpool" account.
    42  func (inst *InitializeTickArray) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *InitializeTickArray {
    43  	inst.AccountMetaSlice[0] = ag_solanago.Meta(whirlpool)
    44  	return inst
    45  }
    46  
    47  // GetWhirlpoolAccount gets the "whirlpool" account.
    48  func (inst *InitializeTickArray) GetWhirlpoolAccount() *ag_solanago.AccountMeta {
    49  	return inst.AccountMetaSlice.Get(0)
    50  }
    51  
    52  // SetFunderAccount sets the "funder" account.
    53  func (inst *InitializeTickArray) SetFunderAccount(funder ag_solanago.PublicKey) *InitializeTickArray {
    54  	inst.AccountMetaSlice[1] = ag_solanago.Meta(funder).WRITE().SIGNER()
    55  	return inst
    56  }
    57  
    58  // GetFunderAccount gets the "funder" account.
    59  func (inst *InitializeTickArray) GetFunderAccount() *ag_solanago.AccountMeta {
    60  	return inst.AccountMetaSlice.Get(1)
    61  }
    62  
    63  // SetTickArrayAccount sets the "tickArray" account.
    64  func (inst *InitializeTickArray) SetTickArrayAccount(tickArray ag_solanago.PublicKey) *InitializeTickArray {
    65  	inst.AccountMetaSlice[2] = ag_solanago.Meta(tickArray).WRITE()
    66  	return inst
    67  }
    68  
    69  // GetTickArrayAccount gets the "tickArray" account.
    70  func (inst *InitializeTickArray) GetTickArrayAccount() *ag_solanago.AccountMeta {
    71  	return inst.AccountMetaSlice.Get(2)
    72  }
    73  
    74  // SetSystemProgramAccount sets the "systemProgram" account.
    75  func (inst *InitializeTickArray) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *InitializeTickArray {
    76  	inst.AccountMetaSlice[3] = ag_solanago.Meta(systemProgram)
    77  	return inst
    78  }
    79  
    80  // GetSystemProgramAccount gets the "systemProgram" account.
    81  func (inst *InitializeTickArray) GetSystemProgramAccount() *ag_solanago.AccountMeta {
    82  	return inst.AccountMetaSlice.Get(3)
    83  }
    84  
    85  func (inst InitializeTickArray) Build() *Instruction {
    86  	return &Instruction{BaseVariant: ag_binary.BaseVariant{
    87  		Impl:   inst,
    88  		TypeID: Instruction_InitializeTickArray,
    89  	}}
    90  }
    91  
    92  // ValidateAndBuild validates the instruction parameters and accounts;
    93  // if there is a validation error, it returns the error.
    94  // Otherwise, it builds and returns the instruction.
    95  func (inst InitializeTickArray) ValidateAndBuild() (*Instruction, error) {
    96  	if err := inst.Validate(); err != nil {
    97  		return nil, err
    98  	}
    99  	return inst.Build(), nil
   100  }
   101  
   102  func (inst *InitializeTickArray) Validate() error {
   103  	// Check whether all (required) parameters are set:
   104  	{
   105  		if inst.StartTickIndex == nil {
   106  			return errors.New("StartTickIndex parameter is not set")
   107  		}
   108  	}
   109  
   110  	// Check whether all (required) accounts are set:
   111  	{
   112  		if inst.AccountMetaSlice[0] == nil {
   113  			return errors.New("accounts.Whirlpool is not set")
   114  		}
   115  		if inst.AccountMetaSlice[1] == nil {
   116  			return errors.New("accounts.Funder is not set")
   117  		}
   118  		if inst.AccountMetaSlice[2] == nil {
   119  			return errors.New("accounts.TickArray is not set")
   120  		}
   121  		if inst.AccountMetaSlice[3] == nil {
   122  			return errors.New("accounts.SystemProgram is not set")
   123  		}
   124  	}
   125  	return nil
   126  }
   127  
   128  func (inst *InitializeTickArray) EncodeToTree(parent ag_treeout.Branches) {
   129  	parent.Child(ag_format.Program(ProgramName, ProgramID)).
   130  		//
   131  		ParentFunc(func(programBranch ag_treeout.Branches) {
   132  			programBranch.Child(ag_format.Instruction("InitializeTickArray")).
   133  				//
   134  				ParentFunc(func(instructionBranch ag_treeout.Branches) {
   135  
   136  					// Parameters of the instruction:
   137  					instructionBranch.Child("Params[len=1]").ParentFunc(func(paramsBranch ag_treeout.Branches) {
   138  						paramsBranch.Child(ag_format.Param("StartTickIndex", *inst.StartTickIndex))
   139  					})
   140  
   141  					// Accounts of the instruction:
   142  					instructionBranch.Child("Accounts[len=4]").ParentFunc(func(accountsBranch ag_treeout.Branches) {
   143  						accountsBranch.Child(ag_format.Meta("    whirlpool", inst.AccountMetaSlice.Get(0)))
   144  						accountsBranch.Child(ag_format.Meta("       funder", inst.AccountMetaSlice.Get(1)))
   145  						accountsBranch.Child(ag_format.Meta("    tickArray", inst.AccountMetaSlice.Get(2)))
   146  						accountsBranch.Child(ag_format.Meta("systemProgram", inst.AccountMetaSlice.Get(3)))
   147  					})
   148  				})
   149  		})
   150  }
   151  
   152  func (obj InitializeTickArray) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) {
   153  	// Serialize `StartTickIndex` param:
   154  	err = encoder.Encode(obj.StartTickIndex)
   155  	if err != nil {
   156  		return err
   157  	}
   158  	return nil
   159  }
   160  func (obj *InitializeTickArray) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) {
   161  	// Deserialize `StartTickIndex`:
   162  	err = decoder.Decode(&obj.StartTickIndex)
   163  	if err != nil {
   164  		return err
   165  	}
   166  	return nil
   167  }
   168  
   169  // NewInitializeTickArrayInstruction declares a new InitializeTickArray instruction with the provided parameters and accounts.
   170  func NewInitializeTickArrayInstruction(
   171  	// Parameters:
   172  	startTickIndex int32,
   173  	// Accounts:
   174  	whirlpool ag_solanago.PublicKey,
   175  	funder ag_solanago.PublicKey,
   176  	tickArray ag_solanago.PublicKey,
   177  	systemProgram ag_solanago.PublicKey) *InitializeTickArray {
   178  	return NewInitializeTickArrayInstructionBuilder().
   179  		SetStartTickIndex(startTickIndex).
   180  		SetWhirlpoolAccount(whirlpool).
   181  		SetFunderAccount(funder).
   182  		SetTickArrayAccount(tickArray).
   183  		SetSystemProgramAccount(systemProgram)
   184  }