// 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"
)

// Sells tokens into a bonding curve.
type Sell struct {
	Amount       *uint64
	MinSolOutput *uint64

	// [0] = [] global
	//
	// [1] = [WRITE] fee_recipient
	//
	// [2] = [] mint
	//
	// [3] = [WRITE] bonding_curve
	//
	// [4] = [WRITE] associated_bonding_curve
	//
	// [5] = [WRITE] associated_user
	//
	// [6] = [WRITE, SIGNER] user
	//
	// [7] = [] system_program
	//
	// [8] = [WRITE] creator_vault
	//
	// [9] = [] token_program
	//
	// [10] = [] event_authority
	//
	// [11] = [] program
	ag_solanago.AccountMetaSlice `bin:"-"`
}

// NewSellInstructionBuilder creates a new `Sell` instruction builder.
func NewSellInstructionBuilder() *Sell {
	nd := &Sell{
		AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 12),
	}
	nd.AccountMetaSlice[7] = ag_solanago.Meta(Addresses["11111111111111111111111111111111"])
	nd.AccountMetaSlice[9] = ag_solanago.Meta(Addresses["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"])
	return nd
}

// NewSellInstructionBuilderExt creates a new `Sell` instruction builder.
func NewSellInstructionBuilderExt(remainingAccounts int) *Sell {
	nd := &Sell{
		AccountMetaSlice: make(ag_solanago.AccountMetaSlice, 12+remainingAccounts),
	}
	nd.AccountMetaSlice[7] = ag_solanago.Meta(Addresses["11111111111111111111111111111111"])
	nd.AccountMetaSlice[9] = ag_solanago.Meta(Addresses["TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"])
	return nd
}

// SetAmount sets the "amount" parameter.
func (inst *Sell) SetAmount(amount uint64) *Sell {
	inst.Amount = &amount
	return inst
}

// SetMinSolOutput sets the "min_sol_output" parameter.
func (inst *Sell) SetMinSolOutput(min_sol_output uint64) *Sell {
	inst.MinSolOutput = &min_sol_output
	return inst
}

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

func (inst *Sell) 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 *Sell) FindGlobalAddressWithBumpSeed(bumpSeed uint8) (pda ag_solanago.PublicKey, err error) {
	pda, _, err = inst.findFindGlobalAddress(bumpSeed)
	return
}

func (inst *Sell) 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 *Sell) FindGlobalAddress() (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	pda, bumpSeed, err = inst.findFindGlobalAddress(0)
	return
}

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

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

// SetFeeRecipientAccount sets the "fee_recipient" account.
func (inst *Sell) SetFeeRecipientAccount(feeRecipient ag_solanago.PublicKey) *Sell {
	inst.AccountMetaSlice[1] = ag_solanago.Meta(feeRecipient).WRITE()
	return inst
}

// GetFeeRecipientAccount gets the "fee_recipient" account.
func (inst *Sell) GetFeeRecipientAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(1)
}

// SetMintAccount sets the "mint" account.
func (inst *Sell) SetMintAccount(mint ag_solanago.PublicKey) *Sell {
	inst.AccountMetaSlice[2] = ag_solanago.Meta(mint)
	return inst
}

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

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

func (inst *Sell) 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 *Sell) FindBondingCurveAddressWithBumpSeed(mint ag_solanago.PublicKey, bumpSeed uint8) (pda ag_solanago.PublicKey, err error) {
	pda, _, err = inst.findFindBondingCurveAddress(mint, bumpSeed)
	return
}

func (inst *Sell) 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 *Sell) FindBondingCurveAddress(mint ag_solanago.PublicKey) (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	pda, bumpSeed, err = inst.findFindBondingCurveAddress(mint, 0)
	return
}

func (inst *Sell) 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 *Sell) GetBondingCurveAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(3)
}

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

func (inst *Sell) 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 *Sell) 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 *Sell) 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 *Sell) 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 *Sell) 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 *Sell) GetAssociatedBondingCurveAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(4)
}

// SetAssociatedUserAccount sets the "associated_user" account.
func (inst *Sell) SetAssociatedUserAccount(associatedUser ag_solanago.PublicKey) *Sell {
	inst.AccountMetaSlice[5] = ag_solanago.Meta(associatedUser).WRITE()
	return inst
}

// GetAssociatedUserAccount gets the "associated_user" account.
func (inst *Sell) GetAssociatedUserAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(5)
}

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

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

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

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

// SetCreatorVaultAccount sets the "creator_vault" account.
func (inst *Sell) SetCreatorVaultAccount(creatorVault ag_solanago.PublicKey) *Sell {
	inst.AccountMetaSlice[8] = ag_solanago.Meta(creatorVault).WRITE()
	return inst
}

func (inst *Sell) findFindCreatorVaultAddress(bondingCurveCreator ag_solanago.PublicKey, knownBumpSeed uint8) (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	var seeds [][]byte
	// const: 0x63726561746f722d7661756c74
	seeds = append(seeds, []byte{byte(0x63), byte(0x72), byte(0x65), byte(0x61), byte(0x74), byte(0x6f), byte(0x72), byte(0x2d), byte(0x76), byte(0x61), byte(0x75), byte(0x6c), byte(0x74)})
	// path: bondingCurveCreator
	seeds = append(seeds, bondingCurveCreator.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
}

// FindCreatorVaultAddressWithBumpSeed calculates CreatorVault account address with given seeds and a known bump seed.
func (inst *Sell) FindCreatorVaultAddressWithBumpSeed(bondingCurveCreator ag_solanago.PublicKey, bumpSeed uint8) (pda ag_solanago.PublicKey, err error) {
	pda, _, err = inst.findFindCreatorVaultAddress(bondingCurveCreator, bumpSeed)
	return
}

func (inst *Sell) MustFindCreatorVaultAddressWithBumpSeed(bondingCurveCreator ag_solanago.PublicKey, bumpSeed uint8) (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindCreatorVaultAddress(bondingCurveCreator, bumpSeed)
	if err != nil {
		panic(err)
	}
	return
}

// FindCreatorVaultAddress finds CreatorVault account address with given seeds.
func (inst *Sell) FindCreatorVaultAddress(bondingCurveCreator ag_solanago.PublicKey) (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	pda, bumpSeed, err = inst.findFindCreatorVaultAddress(bondingCurveCreator, 0)
	return
}

func (inst *Sell) MustFindCreatorVaultAddress(bondingCurveCreator ag_solanago.PublicKey) (pda ag_solanago.PublicKey) {
	pda, _, err := inst.findFindCreatorVaultAddress(bondingCurveCreator, 0)
	if err != nil {
		panic(err)
	}
	return
}

// GetCreatorVaultAccount gets the "creator_vault" account.
func (inst *Sell) GetCreatorVaultAccount() *ag_solanago.AccountMeta {
	return inst.AccountMetaSlice.Get(8)
}

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

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

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

func (inst *Sell) 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 *Sell) FindEventAuthorityAddressWithBumpSeed(bumpSeed uint8) (pda ag_solanago.PublicKey, err error) {
	pda, _, err = inst.findFindEventAuthorityAddress(bumpSeed)
	return
}

func (inst *Sell) 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 *Sell) FindEventAuthorityAddress() (pda ag_solanago.PublicKey, bumpSeed uint8, err error) {
	pda, bumpSeed, err = inst.findFindEventAuthorityAddress(0)
	return
}

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

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

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

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

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

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

// 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 Sell) ValidateAndBuild() (*Instruction, error) {
	if err := inst.Validate(); err != nil {
		return nil, err
	}
	return inst.Build(), nil
}

func (inst *Sell) Validate() error {
	// Check whether all (required) parameters are set:
	{
		if inst.Amount == nil {
			return errors.New("Amount parameter is not set")
		}
		if inst.MinSolOutput == nil {
			return errors.New("MinSolOutput parameter is not set")
		}
	}

	// Check whether all (required) accounts are set:
	{
		if inst.AccountMetaSlice[0] == nil {
			return errors.New("accounts.Global is not set")
		}
		if inst.AccountMetaSlice[1] == nil {
			return errors.New("accounts.FeeRecipient is not set")
		}
		if inst.AccountMetaSlice[2] == nil {
			return errors.New("accounts.Mint is not set")
		}
		if inst.AccountMetaSlice[3] == nil {
			return errors.New("accounts.BondingCurve is not set")
		}
		if inst.AccountMetaSlice[4] == nil {
			return errors.New("accounts.AssociatedBondingCurve is not set")
		}
		if inst.AccountMetaSlice[5] == nil {
			return errors.New("accounts.AssociatedUser is not set")
		}
		if inst.AccountMetaSlice[6] == nil {
			return errors.New("accounts.User is not set")
		}
		if inst.AccountMetaSlice[7] == nil {
			return errors.New("accounts.SystemProgram is not set")
		}
		if inst.AccountMetaSlice[8] == nil {
			return errors.New("accounts.CreatorVault 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.EventAuthority is not set")
		}
		if inst.AccountMetaSlice[11] == nil {
			return errors.New("accounts.Program is not set")
		}
	}
	return nil
}

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

					// Parameters of the instruction:
					instructionBranch.Child("Params[len=2]").ParentFunc(func(paramsBranch ag_treeout.Branches) {
						paramsBranch.Child(ag_format.Param("        Amount", *inst.Amount))
						paramsBranch.Child(ag_format.Param("  MinSolOutput", *inst.MinSolOutput))
					})

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

func (obj Sell) MarshalWithEncoder(encoder *ag_binary.Encoder) (err error) {
	// Serialize `Amount` param:
	err = encoder.Encode(obj.Amount)
	if err != nil {
		return err
	}
	// Serialize `MinSolOutput` param:
	err = encoder.Encode(obj.MinSolOutput)
	if err != nil {
		return err
	}
	return nil
}
func (obj *Sell) UnmarshalWithDecoder(decoder *ag_binary.Decoder) (err error) {
	// Deserialize `Amount`:
	err = decoder.Decode(&obj.Amount)
	if err != nil {
		return err
	}
	// Deserialize `MinSolOutput`:
	err = decoder.Decode(&obj.MinSolOutput)
	if err != nil {
		return err
	}
	return nil
}

// NewSellInstruction declares a new Sell instruction with the provided parameters and accounts.
func NewSellInstruction(
	// Parameters:
	amount uint64,
	min_sol_output uint64,
	// Accounts:
	global ag_solanago.PublicKey,
	feeRecipient ag_solanago.PublicKey,
	mint ag_solanago.PublicKey,
	bondingCurve ag_solanago.PublicKey,
	associatedBondingCurve ag_solanago.PublicKey,
	associatedUser ag_solanago.PublicKey,
	user ag_solanago.PublicKey,
	systemProgram ag_solanago.PublicKey,
	creatorVault ag_solanago.PublicKey,
	tokenProgram ag_solanago.PublicKey,
	eventAuthority ag_solanago.PublicKey,
	program ag_solanago.PublicKey) *Sell {
	return NewSellInstructionBuilder().
		SetAmount(amount).
		SetMinSolOutput(min_sol_output).
		SetGlobalAccount(global).
		SetFeeRecipientAccount(feeRecipient).
		SetMintAccount(mint).
		SetBondingCurveAccount(bondingCurve).
		SetAssociatedBondingCurveAccount(associatedBondingCurve).
		SetAssociatedUserAccount(associatedUser).
		SetUserAccount(user).
		SetSystemProgramAccount(systemProgram).
		SetCreatorVaultAccount(creatorVault).
		SetTokenProgramAccount(tokenProgram).
		SetEventAuthorityAccount(eventAuthority).
		SetProgramAccount(program)
}
