github.com/diadata-org/diadata@v1.4.593/pkg/dia/scraper/exchange-scrapers/orca/whirlpool/OpenPosition.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  // OpenPosition is the `openPosition` instruction.
    14  type OpenPosition struct {
    15  	Bumps          *OpenPositionBumps
    16  	TickLowerIndex *int32
    17  	TickUpperIndex *int32
    18  
    19  	// [0] = [WRITE, SIGNER] funder
    20  	//
    21  	// [1] = [] owner
    22  	//
    23  	// [2] = [WRITE] position
    24  	//
    25  	// [3] = [WRITE, SIGNER] positionMint
    26  	//
    27  	// [4] = [WRITE] positionTokenAccount
    28  	//
    29  	// [5] = [] whirlpool
    30  	//
    31  	// [6] = [] tokenProgram
    32  	//
    33  	// [7] = [] systemProgram
    34  	//
    35  	// [8] = [] rent
    36  	//
    37  	// [9] = [] associatedTokenProgram
    38  	ag_solanago.AccountMetaSlice `bin:"-"`
    39  }
    40  
    41  // NewOpenPositionInstructionBuilder creates a new `OpenPosition` instruction builder.
    42  func NewOpenPositionInstructionBuilder() *OpenPosition {
    43  	nd := &OpenPosition{
    44  		AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 10),
    45  	}
    46  	return nd
    47  }
    48  
    49  // SetBumps sets the "bumps" parameter.
    50  func (inst *OpenPosition) SetBumps(bumps OpenPositionBumps) *OpenPosition {
    51  	inst.Bumps = &bumps
    52  	return inst
    53  }
    54  
    55  // SetTickLowerIndex sets the "tickLowerIndex" parameter.
    56  func (inst *OpenPosition) SetTickLowerIndex(tickLowerIndex int32) *OpenPosition {
    57  	inst.TickLowerIndex = &tickLowerIndex
    58  	return inst
    59  }
    60  
    61  // SetTickUpperIndex sets the "tickUpperIndex" parameter.
    62  func (inst *OpenPosition) SetTickUpperIndex(tickUpperIndex int32) *OpenPosition {
    63  	inst.TickUpperIndex = &tickUpperIndex
    64  	return inst
    65  }
    66  
    67  // SetFunderAccount sets the "funder" account.
    68  func (inst *OpenPosition) SetFunderAccount(funder ag_solanago.PublicKey) *OpenPosition {
    69  	inst.AccountMetaSlice[0] = ag_solanago.Meta(funder).WRITE().SIGNER()
    70  	return inst
    71  }
    72  
    73  // GetFunderAccount gets the "funder" account.
    74  func (inst *OpenPosition) GetFunderAccount() *ag_solanago.AccountMeta {
    75  	return inst.AccountMetaSlice.Get(0)
    76  }
    77  
    78  // SetOwnerAccount sets the "owner" account.
    79  func (inst *OpenPosition) SetOwnerAccount(owner ag_solanago.PublicKey) *OpenPosition {
    80  	inst.AccountMetaSlice[1] = ag_solanago.Meta(owner)
    81  	return inst
    82  }
    83  
    84  // GetOwnerAccount gets the "owner" account.
    85  func (inst *OpenPosition) GetOwnerAccount() *ag_solanago.AccountMeta {
    86  	return inst.AccountMetaSlice.Get(1)
    87  }
    88  
    89  // SetPositionAccount sets the "position" account.
    90  func (inst *OpenPosition) SetPositionAccount(position ag_solanago.PublicKey) *OpenPosition {
    91  	inst.AccountMetaSlice[2] = ag_solanago.Meta(position).WRITE()
    92  	return inst
    93  }
    94  
    95  // GetPositionAccount gets the "position" account.
    96  func (inst *OpenPosition) GetPositionAccount() *ag_solanago.AccountMeta {
    97  	return inst.AccountMetaSlice.Get(2)
    98  }
    99  
   100  // SetPositionMintAccount sets the "positionMint" account.
   101  func (inst *OpenPosition) SetPositionMintAccount(positionMint ag_solanago.PublicKey) *OpenPosition {
   102  	inst.AccountMetaSlice[3] = ag_solanago.Meta(positionMint).WRITE().SIGNER()
   103  	return inst
   104  }
   105  
   106  // GetPositionMintAccount gets the "positionMint" account.
   107  func (inst *OpenPosition) GetPositionMintAccount() *ag_solanago.AccountMeta {
   108  	return inst.AccountMetaSlice.Get(3)
   109  }
   110  
   111  // SetPositionTokenAccountAccount sets the "positionTokenAccount" account.
   112  func (inst *OpenPosition) SetPositionTokenAccountAccount(positionTokenAccount ag_solanago.PublicKey) *OpenPosition {
   113  	inst.AccountMetaSlice[4] = ag_solanago.Meta(positionTokenAccount).WRITE()
   114  	return inst
   115  }
   116  
   117  // GetPositionTokenAccountAccount gets the "positionTokenAccount" account.
   118  func (inst *OpenPosition) GetPositionTokenAccountAccount() *ag_solanago.AccountMeta {
   119  	return inst.AccountMetaSlice.Get(4)
   120  }
   121  
   122  // SetWhirlpoolAccount sets the "whirlpool" account.
   123  func (inst *OpenPosition) SetWhirlpoolAccount(whirlpool ag_solanago.PublicKey) *OpenPosition {
   124  	inst.AccountMetaSlice[5] = ag_solanago.Meta(whirlpool)
   125  	return inst
   126  }
   127  
   128  // GetWhirlpoolAccount gets the "whirlpool" account.
   129  func (inst *OpenPosition) GetWhirlpoolAccount() *ag_solanago.AccountMeta {
   130  	return inst.AccountMetaSlice.Get(5)
   131  }
   132  
   133  // SetTokenProgramAccount sets the "tokenProgram" account.
   134  func (inst *OpenPosition) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *OpenPosition {
   135  	inst.AccountMetaSlice[6] = ag_solanago.Meta(tokenProgram)
   136  	return inst
   137  }
   138  
   139  // GetTokenProgramAccount gets the "tokenProgram" account.
   140  func (inst *OpenPosition) GetTokenProgramAccount() *ag_solanago.AccountMeta {
   141  	return inst.AccountMetaSlice.Get(6)
   142  }
   143  
   144  // SetSystemProgramAccount sets the "systemProgram" account.
   145  func (inst *OpenPosition) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *OpenPosition {
   146  	inst.AccountMetaSlice[7] = ag_solanago.Meta(systemProgram)
   147  	return inst
   148  }
   149  
   150  // GetSystemProgramAccount gets the "systemProgram" account.
   151  func (inst *OpenPosition) GetSystemProgramAccount() *ag_solanago.AccountMeta {
   152  	return inst.AccountMetaSlice.Get(7)
   153  }
   154  
   155  // SetRentAccount sets the "rent" account.
   156  func (inst *OpenPosition) SetRentAccount(rent ag_solanago.PublicKey) *OpenPosition {
   157  	inst.AccountMetaSlice[8] = ag_solanago.Meta(rent)
   158  	return inst
   159  }
   160  
   161  // GetRentAccount gets the "rent" account.
   162  func (inst *OpenPosition) GetRentAccount() *ag_solanago.AccountMeta {
   163  	return inst.AccountMetaSlice.Get(8)
   164  }
   165  
   166  // SetAssociatedTokenProgramAccount sets the "associatedTokenProgram" account.
   167  func (inst *OpenPosition) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *OpenPosition {
   168  	inst.AccountMetaSlice[9] = ag_solanago.Meta(associatedTokenProgram)
   169  	return inst
   170  }
   171  
   172  // GetAssociatedTokenProgramAccount gets the "associatedTokenProgram" account.
   173  func (inst *OpenPosition) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta {
   174  	return inst.AccountMetaSlice.Get(9)
   175  }
   176  
   177  func (inst OpenPosition) Build() *Instruction {
   178  	return &Instruction{BaseVariant: ag_binary.BaseVariant{
   179  		Impl:   inst,
   180  		TypeID: Instruction_OpenPosition,
   181  	}}
   182  }
   183  
   184  // ValidateAndBuild validates the instruction parameters and accounts;
   185  // if there is a validation error, it returns the error.
   186  // Otherwise, it builds and returns the instruction.
   187  func (inst OpenPosition) ValidateAndBuild() (*Instruction, error) {
   188  	if err := inst.Validate(); err != nil {
   189  		return nil, err
   190  	}
   191  	return inst.Build(), nil
   192  }
   193  
   194  func (inst *OpenPosition) Validate() error {
   195  	// Check whether all (required) parameters are set:
   196  	{
   197  		if inst.Bumps == nil {
   198  			return errors.New("Bumps parameter is not set")
   199  		}
   200  		if inst.TickLowerIndex == nil {
   201  			return errors.New("TickLowerIndex parameter is not set")
   202  		}
   203  		if inst.TickUpperIndex == nil {
   204  			return errors.New("TickUpperIndex parameter is not set")
   205  		}
   206  	}
   207  
   208  	// Check whether all (required) accounts are set:
   209  	{
   210  		if inst.AccountMetaSlice[0] == nil {
   211  			return errors.New("accounts.Funder is not set")
   212  		}
   213  		if inst.AccountMetaSlice[1] == nil {
   214  			return errors.New("accounts.Owner is not set")
   215  		}
   216  		if inst.AccountMetaSlice[2] == nil {
   217  			return errors.New("accounts.Position is not set")
   218  		}
   219  		if inst.AccountMetaSlice[3] == nil {
   220  			return errors.New("accounts.PositionMint is not set")
   221  		}
   222  		if inst.AccountMetaSlice[4] == nil {
   223  			return errors.New("accounts.PositionTokenAccount is not set")
   224  		}
   225  		if inst.AccountMetaSlice[5] == nil {
   226  			return errors.New("accounts.Whirlpool is not set")
   227  		}
   228  		if inst.AccountMetaSlice[6] == nil {
   229  			return errors.New("accounts.TokenProgram is not set")
   230  		}
   231  		if inst.AccountMetaSlice[7] == nil {
   232  			return errors.New("accounts.SystemProgram is not set")
   233  		}
   234  		if inst.AccountMetaSlice[8] == nil {
   235  			return errors.New("accounts.Rent is not set")
   236  		}
   237  		if inst.AccountMetaSlice[9] == nil {
   238  			return errors.New("accounts.AssociatedTokenProgram is not set")
   239  		}
   240  	}
   241  	return nil
   242  }
   243  
   244  func (inst *OpenPosition) EncodeToTree(parent ag_treeout.Branches) {
   245  	parent.Child(ag_format.Program(ProgramName, ProgramID)).
   246  		//
   247  		ParentFunc(func(programBranch ag_treeout.Branches) {
   248  			programBranch.Child(ag_format.Instruction("OpenPosition")).
   249  				//
   250  				ParentFunc(func(instructionBranch ag_treeout.Branches) {
   251  
   252  					// Parameters of the instruction:
   253  					instructionBranch.Child("Params[len=3]").ParentFunc(func(paramsBranch ag_treeout.Branches) {
   254  						paramsBranch.Child(ag_format.Param("         Bumps", *inst.Bumps))
   255  						paramsBranch.Child(ag_format.Param("TickLowerIndex", *inst.TickLowerIndex))
   256  						paramsBranch.Child(ag_format.Param("TickUpperIndex", *inst.TickUpperIndex))
   257  					})
   258  
   259  					// Accounts of the instruction:
   260  					instructionBranch.Child("Accounts[len=10]").ParentFunc(func(accountsBranch ag_treeout.Branches) {
   261  						accountsBranch.Child(ag_format.Meta("                funder", inst.AccountMetaSlice.Get(0)))
   262  						accountsBranch.Child(ag_format.Meta("                 owner", inst.AccountMetaSlice.Get(1)))
   263  						accountsBranch.Child(ag_format.Meta("              position", inst.AccountMetaSlice.Get(2)))
   264  						accountsBranch.Child(ag_format.Meta("          positionMint", inst.AccountMetaSlice.Get(3)))
   265  						accountsBranch.Child(ag_format.Meta("         positionToken", inst.AccountMetaSlice.Get(4)))
   266  						accountsBranch.Child(ag_format.Meta("             whirlpool", inst.AccountMetaSlice.Get(5)))
   267  						accountsBranch.Child(ag_format.Meta("          tokenProgram", inst.AccountMetaSlice.Get(6)))
   268  						accountsBranch.Child(ag_format.Meta("         systemProgram", inst.AccountMetaSlice.Get(7)))
   269  						accountsBranch.Child(ag_format.Meta("                  rent", inst.AccountMetaSlice.Get(8)))
   270  						accountsBranch.Child(ag_format.Meta("associatedTokenProgram", inst.AccountMetaSlice.Get(9)))
   271  					})
   272  				})
   273  		})
   274  }
   275  
   276  func (obj OpenPosition) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) {
   277  	// Serialize `Bumps` param:
   278  	err = encoder.Encode(obj.Bumps)
   279  	if err != nil {
   280  		return err
   281  	}
   282  	// Serialize `TickLowerIndex` param:
   283  	err = encoder.Encode(obj.TickLowerIndex)
   284  	if err != nil {
   285  		return err
   286  	}
   287  	// Serialize `TickUpperIndex` param:
   288  	err = encoder.Encode(obj.TickUpperIndex)
   289  	if err != nil {
   290  		return err
   291  	}
   292  	return nil
   293  }
   294  func (obj *OpenPosition) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) {
   295  	// Deserialize `Bumps`:
   296  	err = decoder.Decode(&obj.Bumps)
   297  	if err != nil {
   298  		return err
   299  	}
   300  	// Deserialize `TickLowerIndex`:
   301  	err = decoder.Decode(&obj.TickLowerIndex)
   302  	if err != nil {
   303  		return err
   304  	}
   305  	// Deserialize `TickUpperIndex`:
   306  	err = decoder.Decode(&obj.TickUpperIndex)
   307  	if err != nil {
   308  		return err
   309  	}
   310  	return nil
   311  }
   312  
   313  // NewOpenPositionInstruction declares a new OpenPosition instruction with the provided parameters and accounts.
   314  func NewOpenPositionInstruction(
   315  	// Parameters:
   316  	bumps OpenPositionBumps,
   317  	tickLowerIndex int32,
   318  	tickUpperIndex int32,
   319  	// Accounts:
   320  	funder ag_solanago.PublicKey,
   321  	owner ag_solanago.PublicKey,
   322  	position ag_solanago.PublicKey,
   323  	positionMint ag_solanago.PublicKey,
   324  	positionTokenAccount ag_solanago.PublicKey,
   325  	whirlpool ag_solanago.PublicKey,
   326  	tokenProgram ag_solanago.PublicKey,
   327  	systemProgram ag_solanago.PublicKey,
   328  	rent ag_solanago.PublicKey,
   329  	associatedTokenProgram ag_solanago.PublicKey) *OpenPosition {
   330  	return NewOpenPositionInstructionBuilder().
   331  		SetBumps(bumps).
   332  		SetTickLowerIndex(tickLowerIndex).
   333  		SetTickUpperIndex(tickUpperIndex).
   334  		SetFunderAccount(funder).
   335  		SetOwnerAccount(owner).
   336  		SetPositionAccount(position).
   337  		SetPositionMintAccount(positionMint).
   338  		SetPositionTokenAccountAccount(positionTokenAccount).
   339  		SetWhirlpoolAccount(whirlpool).
   340  		SetTokenProgramAccount(tokenProgram).
   341  		SetSystemProgramAccount(systemProgram).
   342  		SetRentAccount(rent).
   343  		SetAssociatedTokenProgramAccount(associatedTokenProgram)
   344  }