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