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

token-js: add COption<Pubkey> support to InitializeTransferFeeConfig instruction #6164

Merged
merged 1 commit into from
Jan 23, 2024

Conversation

buffalojoec
Copy link
Contributor

The InitializeTransferFeeConfig instruction in Token2022's Rust crate expects a COption<Pubkey>, which denotes None with a single 0 and Some(Pubkey) with a 1 followed by the public key bytes.

The layout for this instruction in Token JS - initializeTransferFeeConfigInstructionData - was incorrectly using 32 all-zero bytes for None, as one might do with an OptionalNonZeroPubkey. This was causing incorrect instruction data when one of the two authorities was set to null.

Here I've introduced a COptionPublicKeyLayout serialization layout to use for this kind of case. It will handle the proper COption<Pubkey>. encoding and decoding, so we encode and decode instructions properly!

Closes #6113

@buffalojoec buffalojoec requested a review from joncinque January 23, 2024 03:29
expect(transferFeeConfig.withdrawWithheldAuthority).to.eql(PublicKey.default);
}

describe('with null authorities', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff for the tests looks really funky, but I've simply just refactored the setup function to be re-used down here with the provided authorities, and then just added this whole with null authorities section.

const fee = calculateFee(transferFee, preFeeAmount);
expect(fee).to.eql(0n);
describe('transferFee', () => {
describe('encoding/decoding `InitializeTransferFeeConfig` instructions', () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test diff here looks awful as well, but here I've just added the encoding/decoding section above the existing tests.

Copy link
Contributor

@joncinque joncinque left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for fixing this up!

@buffalojoec buffalojoec merged commit 8b22d75 into master Jan 23, 2024
17 checks passed
@buffalojoec buffalojoec deleted the token-js-option-pubkey branch January 23, 2024 16:14
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

Successfully merging this pull request may close these issues.

Unexpected behavior of createInitializeTransferFeeConfigInstruction
2 participants