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