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: Added support for transfer hook instructions #5096

Merged
merged 4 commits into from
Aug 24, 2023

Conversation

wjthieme
Copy link
Contributor

resolves: #4337

@mergify mergify bot added the community Community contribution label Aug 24, 2023
@wjthieme
Copy link
Contributor Author

@joncinque is it currently possible to update the transfer hook authority (optionally set it to null)? If so where would I find the spec for that?

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.

Really great work! Nothing big, just a few nits to sort out. After looking through this, I'm thinking the TransferHookAccount extension can get added separately, since this is very neatly contained.

Regarding your question:

is it currently possible to update the transfer hook authority (optionally set it to null)? If so where would I find the spec for that?

It certainly is, you can find the program source code doing it at

AuthorityType::TransferHookProgramId => {
let extension = mint.get_extension_mut::<TransferHook>()?;
let maybe_authority: Option<Pubkey> = extension.authority.into();
let authority = maybe_authority.ok_or(TokenError::AuthorityTypeNotSupported)?;
Self::validate_owner(
program_id,
&authority,
authority_info,
authority_info_data_len,
account_info_iter.as_slice(),
)?;
extension.authority = new_authority.try_into()?;
}

The concept is that you can reuse set-authority and pass in the correct authority. Given the disparity between the Rust side:

pub enum AuthorityType {
/// Authority to mint new tokens
MintTokens,
/// Authority to freeze any account associated with the Mint
FreezeAccount,
/// Owner of a given token account
AccountOwner,
/// Authority to close a token account
CloseAccount,
/// Authority to set the transfer fee
TransferFeeConfig,
/// Authority to withdraw withheld tokens from a mint
WithheldWithdraw,
/// Authority to close a mint account
CloseMint,
/// Authority to set the interest rate
InterestRate,
/// Authority to transfer or burn any tokens for a mint
PermanentDelegate,
/// Authority to update confidential transfer mint and aprove accounts for confidential
/// transfers
ConfidentialTransferMint,
/// Authority to set the transfer hook program id
TransferHookProgramId,
/// Authority to set the withdraw withheld authority encryption key
ConfidentialTransferFeeConfig,
/// Authority to set the metadata address
MetadataPointer,
}

and the JS side

export enum AuthorityType {
MintTokens = 0,
FreezeAccount = 1,
AccountOwner = 2,
CloseAccount = 3,
}

We have a bit of work to do there 😅 I put in #5100 to address that

docs/src/token-2022/extensions.mdx Outdated Show resolved Hide resolved
docs/src/token-2022/extensions.mdx Outdated Show resolved Hide resolved
token/js/examples/transferHook.ts Outdated Show resolved Hide resolved
token/js/src/extensions/extensionType.ts Show resolved Hide resolved
token/js/src/extensions/transferHook/actions.ts Outdated Show resolved Hide resolved
token/js/src/extensions/transferHook/actions.ts Outdated Show resolved Hide resolved
token/js/src/extensions/transferHook/instructions.ts Outdated Show resolved Hide resolved
token/js/src/extensions/transferHook/instructions.ts Outdated Show resolved Hide resolved
token/js/test/e2e-2022/transferHook.test.ts Outdated Show resolved Hide resolved
@wjthieme
Copy link
Contributor Author

Will do the changes!

The concept is that you can reuse set-authority and pass in the correct authority

That is what I figured. Just didn't see it for other extension authorities like the transfer fee extension.

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.

Great job, thanks for the contribution!

@joncinque joncinque merged commit 0b720f9 into solana-labs:master Aug 24, 2023
31 checks passed
@wjthieme wjthieme deleted the wjthieme-patch-1 branch August 24, 2023 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community Community contribution
Projects
Status: Closed
Development

Successfully merging this pull request may close these issues.

token-js: Support transfer hook interface
2 participants