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

[spl-token-2022-js]: Add SetTransferFee instruction #5451

Closed
iMrDJAi opened this issue Oct 7, 2023 · 7 comments · Fixed by #6678
Closed

[spl-token-2022-js]: Add SetTransferFee instruction #5451

iMrDJAi opened this issue Oct 7, 2023 · 7 comments · Fixed by #6678
Labels

Comments

@iMrDJAi
Copy link

iMrDJAi commented Oct 7, 2023

While it's possible to create a Mint with a transfer fee in TypeScript with createInitializeTransferFeeConfigInstruction(), there seem to be no way to update the fee later.

@buffalojoec buffalojoec changed the title [spl-token-2022]: Support updating transfer fees in TS binding [spl-token-2022-js]: Add SetTransferFee instruction Oct 9, 2023
@buffalojoec
Copy link
Contributor

Ah, thanks for calling this out, looks like we just need to add the functions to support SetTransferFee in a similar fashion to the others!

@sam41306061
Copy link

sam41306061 commented Oct 17, 2023

Hello @buffalojoec , Is this issue still open at the moment?

@buffalojoec
Copy link
Contributor

Hello @buffalojoec , Is this issue still open at the moment?

Yes, appears so! Would you like to work on it?

@sam41306061
Copy link

@buffalojoec Yeah, I would like to take a crack at it. For context, do you have a repo or project where you are using this where I can see exactly what you outlined above?

@buffalojoec
Copy link
Contributor

@buffalojoec Yeah, I would like to take a crack at it. For context, do you have a repo or project where you are using this where I can see exactly what you outlined above?

export function createInitializeTransferFeeConfigInstruction(
mint: PublicKey,
transferFeeConfigAuthority: PublicKey | null,
withdrawWithheldAuthority: PublicKey | null,
transferFeeBasisPoints: number,
maximumFee: bigint,
programId = TOKEN_2022_PROGRAM_ID
): TransactionInstruction {
if (!programSupportsExtensions(programId)) {
throw new TokenUnsupportedInstructionError();
}
const keys = [{ pubkey: mint, isSigner: false, isWritable: true }];
const data = Buffer.alloc(initializeTransferFeeConfigInstructionData.span);
initializeTransferFeeConfigInstructionData.encode(
{
instruction: TokenInstruction.TransferFeeExtension,
transferFeeInstruction: TransferFeeInstruction.InitializeTransferFeeConfig,
transferFeeConfigAuthorityOption: transferFeeConfigAuthority ? 1 : 0,
transferFeeConfigAuthority: transferFeeConfigAuthority || new PublicKey(0),
withdrawWithheldAuthorityOption: withdrawWithheldAuthority ? 1 : 0,
withdrawWithheldAuthority: withdrawWithheldAuthority || new PublicKey(0),
transferFeeBasisPoints: transferFeeBasisPoints,
maximumFee: maximumFee,
},
data
);

We're missing a function like this for SetTransferFee.

@buffalojoec
Copy link
Contributor

Rust side:

pub fn set_transfer_fee(
token_program_id: &Pubkey,
mint: &Pubkey,
authority: &Pubkey,
signers: &[&Pubkey],
transfer_fee_basis_points: u16,
maximum_fee: u64,
) -> Result<Instruction, ProgramError> {
check_program_account(token_program_id)?;
let mut accounts = Vec::with_capacity(2 + signers.len());
accounts.push(AccountMeta::new(*mint, false));
accounts.push(AccountMeta::new_readonly(*authority, signers.is_empty()));
for signer in signers.iter() {
accounts.push(AccountMeta::new_readonly(**signer, true));
}
Ok(Instruction {
program_id: *token_program_id,
accounts,
data: TokenInstruction::TransferFeeExtension(TransferFeeInstruction::SetTransferFee {
transfer_fee_basis_points,
maximum_fee,
})
.pack(),
})
}

@nasjuice
Copy link
Contributor

nasjuice commented May 3, 2024

Hello,

I added a PR for this here
#6678

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

Successfully merging a pull request may close this issue.

4 participants