// Code generated by https://github.com/daog1/solana-anchor-go. DO NOT EDIT.

package pump

import (
	"errors"
	ag_binary "github.com/gagliardetto/binary"
	ag_solanago "github.com/gagliardetto/solana-go"
	ag_format "github.com/gagliardetto/solana-go/text/format"
	ag_treeout "github.com/gagliardetto/treeout"
)

// Creates a new coin and bonding curve.
type Create struct {
	Name    *string
	Symbol  *string
	Uri     *string
	Creator *ag_solanago.PublicKey

	// [0] = [WRITE, SIGNER] mint
	//
	// [1] = [] mint_authority
	//
	// [2] = [WRITE] bonding_curve
	//
	// [3] = [WRITE] associated_bonding_curve
	//
	// [4] = [] global
	//
	// [5] = [] mpl_token_metadata
	//
	// [6] = [WRITE] metadata
	//
	// [7] = [WRITE, SIGNER] user
	//
	// [8] = [] system_program
	//
	// [9] = [] token_program
	//
	// [10] = [] associated_token_program
	//
	// [11] = [] rent
	//
	// [12] = [] event_authority
	//
	// [13] = [] program
	ag_solanago.AccountMetaSlice `bin:"-"`
}

// NewCreateInstructionBuilder creates a new `Create` instruction builder.
func NewCreateInstructionBuilder() *Create {
	nd := &Create{
		AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 14),
	}
	nd.AccountMetaSlice[5] = ag_solanago.Meta(Addresses["metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"])
	nd.AccountMetaSlice[8] = ag_solanago.Meta(Addresses["11111111111111111111111111111111"])
	nd.AccountMetaSlice[9] = ag_solanago.Meta(Addresses["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"])
	nd.AccountMetaSlice[10] = ag_solanago.Meta(Addresses["ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"])
	nd.AccountMetaSlice[11] = ag_solanago.Meta(Addresses["SysvarRent111111111111111111111111111111111"])
	return nd
}

// NewCreateInstructionBuilderExt creates a new `Create` instruction builder.
func NewCreateInstructionBuilderExt(remainingAccounts int) *Create {
	nd := &Create{
		AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 14+remainingAccounts),
	}
	nd.AccountMetaSlice[5] = ag_solanago.Meta(Addresses["metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"])
	nd.AccountMetaSlice[8] = ag_solanago.Meta(Addresses["11111111111111111111111111111111"])
	nd.AccountMetaSlice[9] = ag_solanago.Meta(Addresses["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"])
	nd.AccountMetaSlice[10] = ag_solanago.Meta(Addresses["ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"])
	nd.AccountMetaSlice[11] = ag_solanago.Meta(Addresses["SysvarRent111111111111111111111111111111111"])
	return nd
}

// SetName sets the "name" parameter.
func (inst *Create) SetName(name string) *Create {
	inst.Name = &name
	return inst
}

// SetSymbol sets the "symbol" parameter.
func (inst *Create) SetSymbol(symbol string) *Create {
	inst.Symbol = &symbol
	return inst
}

// SetUri sets the "uri" parameter.
func (inst *Create) SetUri(uri string) *Create {
	inst.Uri = &uri
	return inst
}

// SetCreator sets the "creator" parameter.
func (inst *Create) SetCreator(creator ag_solanago.PublicKey) *Create {
	inst.Creator = &creator
	return inst
}

// SetMintAccount sets the "mint" account.
func (inst *Create) SetMintAccount(mint ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[0] = ag_solanago.Meta(mint).WRITE().SIGNER()
	return inst
}

// GetMintAccount gets the "mint" account.
func (inst *Create) GetMintAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(0)
}

// SetMintAuthorityAccount sets the "mint_authority" account.
func (inst *Create) SetMintAuthorityAccount(mintAuthority ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[1] = ag_solanago.Meta(mintAuthority)
	return inst
}

func (inst *Create) findFindMintAuthorityAddress(knownBumpSeed uint8) (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	var seeds [][]byte
	// const: 0x6d696e742d617574686f72697479
	seeds = append(seeds, []byte{byte(0x6d), byte(0x69), byte(0x6e), byte(0x74), byte(0x2d), byte(0x61), byte(0x75), byte(0x74), byte(0x68), byte(0x6f), byte(0x72), byte(0x69), byte(0x74), byte(0x79)})

	if knownBumpSeed != 0 {
		seeds = append(seeds, []byte{byte(bumpSeed)})
		pda, err = ag_solanago.CreateProgramAddress(seeds, ProgramID)
	} else {
		pda, bumpSeed, err = ag_solanago.FindProgramAddress(seeds, ProgramID)
	}
	return
}

// FindMintAuthorityAddressWithBumpSeed calculates MintAuthority account address with given seeds and a known bump seed.
func (inst *Create) FindMintAuthorityAddressWithBumpSeed(bumpSeed uint8) (pda ag_solanago.PublicKey, err error) {
	pda, _, err = inst.findFindMintAuthorityAddress(bumpSeed)
	return
}

func (inst *Create) MustFindMintAuthorityAddressWithBumpSeed(bumpSeed uint8) (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindMintAuthorityAddress(bumpSeed)
	if err != nil {
		panic(err)
	}
	return
}

// FindMintAuthorityAddress finds MintAuthority account address with given seeds.
func (inst *Create) FindMintAuthorityAddress() (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	pda, bumpSeed, err = inst.findFindMintAuthorityAddress(0)
	return
}

func (inst *Create) MustFindMintAuthorityAddress() (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindMintAuthorityAddress(0)
	if err != nil {
		panic(err)
	}
	return
}

// GetMintAuthorityAccount gets the "mint_authority" account.
func (inst *Create) GetMintAuthorityAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(1)
}

// SetBondingCurveAccount sets the "bonding_curve" account.
func (inst *Create) SetBondingCurveAccount(bondingCurve ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[2] = ag_solanago.Meta(bondingCurve).WRITE()
	return inst
}

func (inst *Create) findFindBondingCurveAddress(mint ag_solanago.PublicKey, knownBumpSeed uint8) (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	var seeds [][]byte
	// const: 0x626f6e64696e672d6375727665
	seeds = append(seeds, []byte{byte(0x62), byte(0x6f), byte(0x6e), byte(0x64), byte(0x69), byte(0x6e), byte(0x67), byte(0x2d), byte(0x63), byte(0x75), byte(0x72), byte(0x76), byte(0x65)})
	// path: mint
	seeds = append(seeds, mint.Bytes())

	if knownBumpSeed != 0 {
		seeds = append(seeds, []byte{byte(bumpSeed)})
		pda, err = ag_solanago.CreateProgramAddress(seeds, ProgramID)
	} else {
		pda, bumpSeed, err = ag_solanago.FindProgramAddress(seeds, ProgramID)
	}
	return
}

// FindBondingCurveAddressWithBumpSeed calculates BondingCurve account address with given seeds and a known bump seed.
func (inst *Create) FindBondingCurveAddressWithBumpSeed(mint ag_solanago.PublicKey, bumpSeed uint8) (pda ag_solanago.PublicKey, err error) {
	pda, _, err = inst.findFindBondingCurveAddress(mint, bumpSeed)
	return
}

func (inst *Create) MustFindBondingCurveAddressWithBumpSeed(mint ag_solanago.PublicKey, bumpSeed uint8) (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindBondingCurveAddress(mint, bumpSeed)
	if err != nil {
		panic(err)
	}
	return
}

// FindBondingCurveAddress finds BondingCurve account address with given seeds.
func (inst *Create) FindBondingCurveAddress(mint ag_solanago.PublicKey) (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	pda, bumpSeed, err = inst.findFindBondingCurveAddress(mint, 0)
	return
}

func (inst *Create) MustFindBondingCurveAddress(mint ag_solanago.PublicKey) (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindBondingCurveAddress(mint, 0)
	if err != nil {
		panic(err)
	}
	return
}

// GetBondingCurveAccount gets the "bonding_curve" account.
func (inst *Create) GetBondingCurveAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(2)
}

// SetAssociatedBondingCurveAccount sets the "associated_bonding_curve" account.
func (inst *Create) SetAssociatedBondingCurveAccount(associatedBondingCurve ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[3] = ag_solanago.Meta(associatedBondingCurve).WRITE()
	return inst
}

func (inst *Create) findFindAssociatedBondingCurveAddress(bondingCurve ag_solanago.PublicKey, mint ag_solanago.PublicKey, knownBumpSeed uint8) (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	var seeds [][]byte
	// path: bondingCurve
	seeds = append(seeds, bondingCurve.Bytes())
	// const: 0x06ddf6e1d765a193d9cbe146ceeb79ac1cb485ed5f5b37913a8cf5857eff00a9
	seeds = append(seeds, []byte{byte(0x6), byte(0xdd), byte(0xf6), byte(0xe1), byte(0xd7), byte(0x65), byte(0xa1), byte(0x93), byte(0xd9), byte(0xcb), byte(0xe1), byte(0x46), byte(0xce), byte(0xeb), byte(0x79), byte(0xac), byte(0x1c), byte(0xb4), byte(0x85), byte(0xed), byte(0x5f), byte(0x5b), byte(0x37), byte(0x91), byte(0x3a), byte(0x8c), byte(0xf5), byte(0x85), byte(0x7e), byte(0xff), byte(0x0), byte(0xa9)})
	// path: mint
	seeds = append(seeds, mint.Bytes())

	programID := Addresses["ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"]

	if knownBumpSeed != 0 {
		seeds = append(seeds, []byte{byte(bumpSeed)})
		pda, err = ag_solanago.CreateProgramAddress(seeds, programID)
	} else {
		pda, bumpSeed, err = ag_solanago.FindProgramAddress(seeds, programID)
	}
	return
}

// FindAssociatedBondingCurveAddressWithBumpSeed calculates AssociatedBondingCurve account address with given seeds and a known bump seed.
func (inst *Create) FindAssociatedBondingCurveAddressWithBumpSeed(bondingCurve ag_solanago.PublicKey, mint ag_solanago.PublicKey, bumpSeed uint8) (pda ag_solanago.PublicKey, err error) {
	pda, _, err = inst.findFindAssociatedBondingCurveAddress(bondingCurve, mint, bumpSeed)
	return
}

func (inst *Create) MustFindAssociatedBondingCurveAddressWithBumpSeed(bondingCurve ag_solanago.PublicKey, mint ag_solanago.PublicKey, bumpSeed uint8) (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindAssociatedBondingCurveAddress(bondingCurve, mint, bumpSeed)
	if err != nil {
		panic(err)
	}
	return
}

// FindAssociatedBondingCurveAddress finds AssociatedBondingCurve account address with given seeds.
func (inst *Create) FindAssociatedBondingCurveAddress(bondingCurve ag_solanago.PublicKey, mint ag_solanago.PublicKey) (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	pda, bumpSeed, err = inst.findFindAssociatedBondingCurveAddress(bondingCurve, mint, 0)
	return
}

func (inst *Create) MustFindAssociatedBondingCurveAddress(bondingCurve ag_solanago.PublicKey, mint ag_solanago.PublicKey) (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindAssociatedBondingCurveAddress(bondingCurve, mint, 0)
	if err != nil {
		panic(err)
	}
	return
}

// GetAssociatedBondingCurveAccount gets the "associated_bonding_curve" account.
func (inst *Create) GetAssociatedBondingCurveAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(3)
}

// SetGlobalAccount sets the "global" account.
func (inst *Create) SetGlobalAccount(global ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[4] = ag_solanago.Meta(global)
	return inst
}

func (inst *Create) findFindGlobalAddress(knownBumpSeed uint8) (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	var seeds [][]byte
	// const: 0x676c6f62616c
	seeds = append(seeds, []byte{byte(0x67), byte(0x6c), byte(0x6f), byte(0x62), byte(0x61), byte(0x6c)})

	if knownBumpSeed != 0 {
		seeds = append(seeds, []byte{byte(bumpSeed)})
		pda, err = ag_solanago.CreateProgramAddress(seeds, ProgramID)
	} else {
		pda, bumpSeed, err = ag_solanago.FindProgramAddress(seeds, ProgramID)
	}
	return
}

// FindGlobalAddressWithBumpSeed calculates Global account address with given seeds and a known bump seed.
func (inst *Create) FindGlobalAddressWithBumpSeed(bumpSeed uint8) (pda ag_solanago.PublicKey, err error) {
	pda, _, err = inst.findFindGlobalAddress(bumpSeed)
	return
}

func (inst *Create) MustFindGlobalAddressWithBumpSeed(bumpSeed uint8) (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindGlobalAddress(bumpSeed)
	if err != nil {
		panic(err)
	}
	return
}

// FindGlobalAddress finds Global account address with given seeds.
func (inst *Create) FindGlobalAddress() (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	pda, bumpSeed, err = inst.findFindGlobalAddress(0)
	return
}

func (inst *Create) MustFindGlobalAddress() (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindGlobalAddress(0)
	if err != nil {
		panic(err)
	}
	return
}

// GetGlobalAccount gets the "global" account.
func (inst *Create) GetGlobalAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(4)
}

// SetMplTokenMetadataAccount sets the "mpl_token_metadata" account.
func (inst *Create) SetMplTokenMetadataAccount(mplTokenMetadata ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[5] = ag_solanago.Meta(mplTokenMetadata)
	return inst
}

// GetMplTokenMetadataAccount gets the "mpl_token_metadata" account.
func (inst *Create) GetMplTokenMetadataAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(5)
}

// SetMetadataAccount sets the "metadata" account.
func (inst *Create) SetMetadataAccount(metadata ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[6] = ag_solanago.Meta(metadata).WRITE()
	return inst
}

func (inst *Create) findFindMetadataAddress(mint ag_solanago.PublicKey, knownBumpSeed uint8) (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	var seeds [][]byte
	// const: 0x6d65746164617461
	seeds = append(seeds, []byte{byte(0x6d), byte(0x65), byte(0x74), byte(0x61), byte(0x64), byte(0x61), byte(0x74), byte(0x61)})
	// const: 0x0b7065b1e3d17c45389d527f6b04c3cd58b86c731aa0fdb549b6d1bc03f82946
	seeds = append(seeds, []byte{byte(0xb), byte(0x70), byte(0x65), byte(0xb1), byte(0xe3), byte(0xd1), byte(0x7c), byte(0x45), byte(0x38), byte(0x9d), byte(0x52), byte(0x7f), byte(0x6b), byte(0x4), byte(0xc3), byte(0xcd), byte(0x58), byte(0xb8), byte(0x6c), byte(0x73), byte(0x1a), byte(0xa0), byte(0xfd), byte(0xb5), byte(0x49), byte(0xb6), byte(0xd1), byte(0xbc), byte(0x3), byte(0xf8), byte(0x29), byte(0x46)})
	// path: mint
	seeds = append(seeds, mint.Bytes())

	programID := Addresses["metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"]

	if knownBumpSeed != 0 {
		seeds = append(seeds, []byte{byte(bumpSeed)})
		pda, err = ag_solanago.CreateProgramAddress(seeds, programID)
	} else {
		pda, bumpSeed, err = ag_solanago.FindProgramAddress(seeds, programID)
	}
	return
}

// FindMetadataAddressWithBumpSeed calculates Metadata account address with given seeds and a known bump seed.
func (inst *Create) FindMetadataAddressWithBumpSeed(mint ag_solanago.PublicKey, bumpSeed uint8) (pda ag_solanago.PublicKey, err error) {
	pda, _, err = inst.findFindMetadataAddress(mint, bumpSeed)
	return
}

func (inst *Create) MustFindMetadataAddressWithBumpSeed(mint ag_solanago.PublicKey, bumpSeed uint8) (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindMetadataAddress(mint, bumpSeed)
	if err != nil {
		panic(err)
	}
	return
}

// FindMetadataAddress finds Metadata account address with given seeds.
func (inst *Create) FindMetadataAddress(mint ag_solanago.PublicKey) (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	pda, bumpSeed, err = inst.findFindMetadataAddress(mint, 0)
	return
}

func (inst *Create) MustFindMetadataAddress(mint ag_solanago.PublicKey) (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindMetadataAddress(mint, 0)
	if err != nil {
		panic(err)
	}
	return
}

// GetMetadataAccount gets the "metadata" account.
func (inst *Create) GetMetadataAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(6)
}

// SetUserAccount sets the "user" account.
func (inst *Create) SetUserAccount(user ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[7] = ag_solanago.Meta(user).WRITE().SIGNER()
	return inst
}

// GetUserAccount gets the "user" account.
func (inst *Create) GetUserAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(7)
}

// SetSystemProgramAccount sets the "system_program" account.
func (inst *Create) SetSystemProgramAccount(systemProgram ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[8] = ag_solanago.Meta(systemProgram)
	return inst
}

// GetSystemProgramAccount gets the "system_program" account.
func (inst *Create) GetSystemProgramAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(8)
}

// SetTokenProgramAccount sets the "token_program" account.
func (inst *Create) SetTokenProgramAccount(tokenProgram ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[9] = ag_solanago.Meta(tokenProgram)
	return inst
}

// GetTokenProgramAccount gets the "token_program" account.
func (inst *Create) GetTokenProgramAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(9)
}

// SetAssociatedTokenProgramAccount sets the "associated_token_program" account.
func (inst *Create) SetAssociatedTokenProgramAccount(associatedTokenProgram ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[10] = ag_solanago.Meta(associatedTokenProgram)
	return inst
}

// GetAssociatedTokenProgramAccount gets the "associated_token_program" account.
func (inst *Create) GetAssociatedTokenProgramAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(10)
}

// SetRentAccount sets the "rent" account.
func (inst *Create) SetRentAccount(rent ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[11] = ag_solanago.Meta(rent)
	return inst
}

// GetRentAccount gets the "rent" account.
func (inst *Create) GetRentAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(11)
}

// SetEventAuthorityAccount sets the "event_authority" account.
func (inst *Create) SetEventAuthorityAccount(eventAuthority ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[12] = ag_solanago.Meta(eventAuthority)
	return inst
}

func (inst *Create) findFindEventAuthorityAddress(knownBumpSeed uint8) (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	var seeds [][]byte
	// const: 0x5f5f6576656e745f617574686f72697479
	seeds = append(seeds, []byte{byte(0x5f), byte(0x5f), byte(0x65), byte(0x76), byte(0x65), byte(0x6e), byte(0x74), byte(0x5f), byte(0x61), byte(0x75), byte(0x74), byte(0x68), byte(0x6f), byte(0x72), byte(0x69), byte(0x74), byte(0x79)})

	if knownBumpSeed != 0 {
		seeds = append(seeds, []byte{byte(bumpSeed)})
		pda, err = ag_solanago.CreateProgramAddress(seeds, ProgramID)
	} else {
		pda, bumpSeed, err = ag_solanago.FindProgramAddress(seeds, ProgramID)
	}
	return
}

// FindEventAuthorityAddressWithBumpSeed calculates EventAuthority account address with given seeds and a known bump seed.
func (inst *Create) FindEventAuthorityAddressWithBumpSeed(bumpSeed uint8) (pda ag_solanago.PublicKey, err error) {
	pda, _, err = inst.findFindEventAuthorityAddress(bumpSeed)
	return
}

func (inst *Create) MustFindEventAuthorityAddressWithBumpSeed(bumpSeed uint8) (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindEventAuthorityAddress(bumpSeed)
	if err != nil {
		panic(err)
	}
	return
}

// FindEventAuthorityAddress finds EventAuthority account address with given seeds.
func (inst *Create) FindEventAuthorityAddress() (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	pda, bumpSeed, err = inst.findFindEventAuthorityAddress(0)
	return
}

func (inst *Create) MustFindEventAuthorityAddress() (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindEventAuthorityAddress(0)
	if err != nil {
		panic(err)
	}
	return
}

// GetEventAuthorityAccount gets the "event_authority" account.
func (inst *Create) GetEventAuthorityAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(12)
}

// SetProgramAccount sets the "program" account.
func (inst *Create) SetProgramAccount(program ag_solanago.PublicKey) *Create {
	inst.AccountMetaSlice[13] = ag_solanago.Meta(program)
	return inst
}

// GetProgramAccount gets the "program" account.
func (inst *Create) GetProgramAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(13)
}

func (inst *Create) AddRemainingAccounts(remainingAccounts []ag_solanago.PublicKey) *Create {
	accounts := 14
	for i, _ := range remainingAccounts {
		index := accounts + i
		inst.AccountMetaSlice[index] = ag_solanago.Meta(remainingAccounts[i]).WRITE()
	}
	return inst
}

func (inst Create) Build() *Instruction {
	return &Instruction{BaseVariant: ag_binary.BaseVariant{
		Impl:   inst,
		TypeID: Instruction_Create,
	}}
}

// ValidateAndBuild validates the instruction parameters and accounts;
// if there is a validation error, it returns the error.
// Otherwise, it builds and returns the instruction.
func (inst Create) ValidateAndBuild() (*Instruction, error) {
	if err := inst.Validate(); err != nil {
		return nil, err
	}
	return inst.Build(), nil
}

func (inst *Create) Validate() error {
	// Check whether all (required) parameters are set:
	{
		if inst.Name == nil {
			return errors.New("Name parameter is not set")
		}
		if inst.Symbol == nil {
			return errors.New("Symbol parameter is not set")
		}
		if inst.Uri == nil {
			return errors.New("Uri parameter is not set")
		}
		if inst.Creator == nil {
			return errors.New("Creator parameter is not set")
		}
	}

	// Check whether all (required) accounts are set:
	{
		if inst.AccountMetaSlice[0] == nil {
			return errors.New("accounts.Mint is not set")
		}
		if inst.AccountMetaSlice[1] == nil {
			return errors.New("accounts.MintAuthority is not set")
		}
		if inst.AccountMetaSlice[2] == nil {
			return errors.New("accounts.BondingCurve is not set")
		}
		if inst.AccountMetaSlice[3] == nil {
			return errors.New("accounts.AssociatedBondingCurve is not set")
		}
		if inst.AccountMetaSlice[4] == nil {
			return errors.New("accounts.Global is not set")
		}
		if inst.AccountMetaSlice[5] == nil {
			return errors.New("accounts.MplTokenMetadata is not set")
		}
		if inst.AccountMetaSlice[6] == nil {
			return errors.New("accounts.Metadata is not set")
		}
		if inst.AccountMetaSlice[7] == nil {
			return errors.New("accounts.User is not set")
		}
		if inst.AccountMetaSlice[8] == nil {
			return errors.New("accounts.SystemProgram is not set")
		}
		if inst.AccountMetaSlice[9] == nil {
			return errors.New("accounts.TokenProgram is not set")
		}
		if inst.AccountMetaSlice[10] == nil {
			return errors.New("accounts.AssociatedTokenProgram is not set")
		}
		if inst.AccountMetaSlice[11] == nil {
			return errors.New("accounts.Rent is not set")
		}
		if inst.AccountMetaSlice[12] == nil {
			return errors.New("accounts.EventAuthority is not set")
		}
		if inst.AccountMetaSlice[13] == nil {
			return errors.New("accounts.Program is not set")
		}
	}
	return nil
}

func (inst *Create) EncodeToTree(parent ag_treeout.Branches) {
	parent.Child(ag_format.Program(ProgramName, ProgramID)).
		//
		ParentFunc(func(programBranch ag_treeout.Branches) {
			programBranch.Child(ag_format.Instruction("Create")).
				//
				ParentFunc(func(instructionBranch ag_treeout.Branches) {

					// Parameters of the instruction:
					instructionBranch.Child("Params[len=4]").ParentFunc(func(paramsBranch ag_treeout.Branches) {
						paramsBranch.Child(ag_format.Param("   Name", *inst.Name))
						paramsBranch.Child(ag_format.Param(" Symbol", *inst.Symbol))
						paramsBranch.Child(ag_format.Param("    Uri", *inst.Uri))
						paramsBranch.Child(ag_format.Param("Creator", *inst.Creator))
					})

					// Accounts of the instruction:
					instructionBranch.Child("Accounts[len=14]").ParentFunc(func(accountsBranch ag_treeout.Branches) {
						accountsBranch.Child(ag_format.Meta("                    mint", inst.AccountMetaSlice.Get(0)))
						accountsBranch.Child(ag_format.Meta("          mint_authority", inst.AccountMetaSlice.Get(1)))
						accountsBranch.Child(ag_format.Meta("           bonding_curve", inst.AccountMetaSlice.Get(2)))
						accountsBranch.Child(ag_format.Meta("associated_bonding_curve", inst.AccountMetaSlice.Get(3)))
						accountsBranch.Child(ag_format.Meta("                  global", inst.AccountMetaSlice.Get(4)))
						accountsBranch.Child(ag_format.Meta("      mpl_token_metadata", inst.AccountMetaSlice.Get(5)))
						accountsBranch.Child(ag_format.Meta("                metadata", inst.AccountMetaSlice.Get(6)))
						accountsBranch.Child(ag_format.Meta("                    user", inst.AccountMetaSlice.Get(7)))
						accountsBranch.Child(ag_format.Meta("          system_program", inst.AccountMetaSlice.Get(8)))
						accountsBranch.Child(ag_format.Meta("           token_program", inst.AccountMetaSlice.Get(9)))
						accountsBranch.Child(ag_format.Meta("associated_token_program", inst.AccountMetaSlice.Get(10)))
						accountsBranch.Child(ag_format.Meta("                    rent", inst.AccountMetaSlice.Get(11)))
						accountsBranch.Child(ag_format.Meta("         event_authority", inst.AccountMetaSlice.Get(12)))
						accountsBranch.Child(ag_format.Meta("                 program", inst.AccountMetaSlice.Get(13)))
					})
				})
		})
}

func (obj Create) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) {
	// Serialize `Name` param:
	err = encoder.Encode(obj.Name)
	if err != nil {
		return err
	}
	// Serialize `Symbol` param:
	err = encoder.Encode(obj.Symbol)
	if err != nil {
		return err
	}
	// Serialize `Uri` param:
	err = encoder.Encode(obj.Uri)
	if err != nil {
		return err
	}
	// Serialize `Creator` param:
	err = encoder.Encode(obj.Creator)
	if err != nil {
		return err
	}
	return nil
}
func (obj *Create) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) {
	// Deserialize `Name`:
	err = decoder.Decode(&obj.Name)
	if err != nil {
		return err
	}
	// Deserialize `Symbol`:
	err = decoder.Decode(&obj.Symbol)
	if err != nil {
		return err
	}
	// Deserialize `Uri`:
	err = decoder.Decode(&obj.Uri)
	if err != nil {
		return err
	}
	// Deserialize `Creator`:
	err = decoder.Decode(&obj.Creator)
	if err != nil {
		return err
	}
	return nil
}

// NewCreateInstruction declares a new Create instruction with the provided parameters and accounts.
func NewCreateInstruction(
	// Parameters:
	name string,
	symbol string,
	uri string,
	creator ag_solanago.PublicKey,
	// Accounts:
	mint ag_solanago.PublicKey,
	mintAuthority ag_solanago.PublicKey,
	bondingCurve ag_solanago.PublicKey,
	associatedBondingCurve ag_solanago.PublicKey,
	global ag_solanago.PublicKey,
	mplTokenMetadata ag_solanago.PublicKey,
	metadata ag_solanago.PublicKey,
	user ag_solanago.PublicKey,
	systemProgram ag_solanago.PublicKey,
	tokenProgram ag_solanago.PublicKey,
	associatedTokenProgram ag_solanago.PublicKey,
	rent ag_solanago.PublicKey,
	eventAuthority ag_solanago.PublicKey,
	program ag_solanago.PublicKey) *Create {
	return NewCreateInstructionBuilder().
		SetName(name).
		SetSymbol(symbol).
		SetUri(uri).
		SetCreator(creator).
		SetMintAccount(mint).
		SetMintAuthorityAccount(mintAuthority).
		SetBondingCurveAccount(bondingCurve).
		SetAssociatedBondingCurveAccount(associatedBondingCurve).
		SetGlobalAccount(global).
		SetMplTokenMetadataAccount(mplTokenMetadata).
		SetMetadataAccount(metadata).
		SetUserAccount(user).
		SetSystemProgramAccount(systemProgram).
		SetTokenProgramAccount(tokenProgram).
		SetAssociatedTokenProgramAccount(associatedTokenProgram).
		SetRentAccount(rent).
		SetEventAuthorityAccount(eventAuthority).
		SetProgramAccount(program)
}
