Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CancelOrder program #61

Open
rafaelvanoni opened this issue Apr 27, 2022 · 1 comment
Open

CancelOrder program #61

rafaelvanoni opened this issue Apr 27, 2022 · 1 comment

Comments

@rafaelvanoni
Copy link
Contributor

rafaelvanoni commented Apr 27, 2022

Hi folks, I'm trying to write a client that issues CancelOrder transactions and it seems that program hasn't been implemented yet. Is that correct? If so, I'd be happy to propose a PR with it.

To clarify, the problem I'm trying to solve is that I can't create a solana.NewTransaction() with a InstructionCancelOrder{} because the latter doesn't fully implement solana.Instruction. It seems that "fully" implementing CancelOrder similarly to what's done in programs/system/CreateAccount.go for example, would solve that.

@aspin
Copy link
Contributor

aspin commented May 13, 2022

Just as a follow up for anyone else experiencing this issue: we figured out that the usage is like this:

	// create the CancelOrder instruction
	cancelInstruction := serum.InstructionCancelOrderByClientIdV2{
		ClientID: clientID,
		Accounts: &serum.CancelOrderByClientIdV2Accounts{
			Market:     solana.Meta(marketPk).WRITE(),
			Bids:       solana.Meta(bidsPk).WRITE(),
			Asks:       solana.Meta(asksPk).WRITE(),
			OpenOrders: solana.Meta(openOrdersPk).WRITE(),
			Owner:      solana.Meta(ownerPk).SIGNER(),
			EventQueue: solana.Meta(eventQueuePk).WRITE(),
		},
	}

	serumInstruction := serum.Instruction{
		BaseVariant: bin.BaseVariant{
			TypeID: serum.InstructionDefVariant.TypeID("cancel_order_by_client_id_v2"),
			Impl:   cancelInstruction,
		},
		Version: serumInstructionVersion,
	}

	buf := new(bytes.Buffer)
	err := bin.NewBinEncoder(buf).Encode(serumInstruction)
	if err != nil {
		return nil, fmt.Errorf("failed to encode CancelOrder instruction (%w)", err)
	}
	

	serumV3Dex, _ := solana.PublicKeyFromBase58("9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin")
	instruction := &solana.GenericInstruction{
		AccountValues: []*solana.AccountMeta{
			cancelInstruction.Accounts.Market,
			cancelInstruction.Accounts.Bids,
			cancelInstruction.Accounts.Asks,
			cancelInstruction.Accounts.OpenOrders,
			cancelInstruction.Accounts.Owner,
			cancelInstruction.Accounts.EventQueue,
		},
		ProgID:    serumV3Dex,
		DataBytes: buf.Bytes(),
	}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants