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

Code Generation Produced Conflicts between Account and Instruction Struct #17

Open
sol-mocha opened this issue Feb 2, 2023 · 2 comments

Comments

@sol-mocha
Copy link

Currently, if the IDL lists the same name for an account and an instruction, this will produce go code in which the account name and the instruction name will be the same. For example the IDl for the token-swap program here will yield

type Swap struct {
	Version        uint8
	IsInitialized  bool
	BumpSeed       uint8
	TokenProgramId ag_solanago.PublicKey
	TokenA         ag_solanago.PublicKey
	TokenB         ag_solanago.PublicKey
	PoolMint       ag_solanago.PublicKey
	TokenAMint     ag_solanago.PublicKey
	TokenBMint     ag_solanago.PublicKey
	PoolFeeAccount ag_solanago.PublicKey
	Fees           Fees
	SwapCurve      SwapCurve
}

and

// Swap is the `swap` instruction.
type Swap struct {
	AmountIn         *uint64
	MinimumAmountOut *uint64

	// [0] = [] swap
	//
	// [1] = [] authority
	//
	// [2] = [SIGNER] userTransferAuthority
	//
	// [3] = [WRITE] source
	//
	// [4] = [WRITE] swapSource
	//
	// [5] = [WRITE] swapDestination
	//
	// [6] = [WRITE] destination
	//
	// [7] = [WRITE] poolMint
	//
	// [8] = [WRITE] poolFee
	//
	// [9] = [] tokenProgram
	ag_solanago.AccountMetaSlice `bin:"-"`
}

One Possible fix can be to introduce a flag to add a custom suffix to the account struct (or the instruction struct).

In this example with a custom account suffix of Account we would get

type SwapAccount struct {
	Version        uint8
	IsInitialized  bool
	BumpSeed       uint8
	TokenProgramId ag_solanago.PublicKey
	TokenA         ag_solanago.PublicKey
	TokenB         ag_solanago.PublicKey
	PoolMint       ag_solanago.PublicKey
	TokenAMint     ag_solanago.PublicKey
	TokenBMint     ag_solanago.PublicKey
	PoolFeeAccount ag_solanago.PublicKey
	Fees           Fees
	SwapCurve      SwapCurve
}

// Swap is the `swap` instruction.
type Swap struct {
	AmountIn         *uint64
	MinimumAmountOut *uint64

	// [0] = [] swap
	//
	// [1] = [] authority
	//
	// [2] = [SIGNER] userTransferAuthority
	//
	// [3] = [WRITE] source
	//
	// [4] = [WRITE] swapSource
	//
	// [5] = [WRITE] swapDestination
	//
	// [6] = [WRITE] destination
	//
	// [7] = [WRITE] poolMint
	//
	// [8] = [WRITE] poolFee
	//
	// [9] = [] tokenProgram
	ag_solanago.AccountMetaSlice `bin:"-"`
}
@sol-mocha sol-mocha changed the title Code Generation Produced Conflicts between Account State and Instruction Name Code Generation Produced Conflicts between Account and Instruction Struct Feb 2, 2023
@gagliardetto
Copy link
Owner

Yep, what you're describing is totally a bug.

The whole anchor-go package needs to be refactored from top to bottom 😅

I'll get to it (eventually).

And one of the things that would need to be done is to split the various generated stuff into separate folders (but even before that, there's a lot more).

@sol-mocha
Copy link
Author

Yep, what you're describing is totally a bug.

The whole anchor-go package needs to be refactored from top to bottom 😅

I'll get to it (eventually).

And one of the things that would need to be done is to split the various generated stuff into separate folders (but even before that, there's a lot more).

You might like what we're building for grizzlython 👀 dcaf labs is working on some code gen tooling, forked/refactored from anchor-go

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