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

createInitializeTransferFeeConfig failing when combined with other token extenstions #6410

Closed
kasuba97 opened this issue Mar 12, 2024 · 5 comments
Labels
question Further information is requested

Comments

@kasuba97
Copy link

    'Program 11111111111111111111111111111111 invoke [1]',
    'Program 11111111111111111111111111111111 success',
    'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]',
    'Program log: MetadataPointerInstruction::Initialize',
    'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 2441 of 1399850 compute units',
    'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb success',
    'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]',
    'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 3545 of 1397409 compute units',
    'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb success',
    'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]',
    'Program log: Instruction: InitializePermanentDelegate',
    'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 2522 of 1393864 compute units',
    'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb success',
    'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb invoke [1]',
    'Program log: Instruction: InitializeMint2',
    'Program log: Error: InvalidAccountData',
    'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb consumed 3953 of 1391342 compute units',
    'Program TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb failed: invalid account data for instruction'
  ]```
@buffalojoec
Copy link
Contributor

You'll need to provide some more information in order to determine if this is a bug with any SPL libraries!
Please provide your code to reproduce the issue.

@kasuba97
Copy link
Author

kasuba97 commented Mar 12, 2024

// type spaces
const mintSpace =
  getMintLen([ExtensionType.MetadataPointer]) +
  getMintLen([ExtensionType.TransferFeeConfig]) +
  getMintLen([ExtensionType.PermanentDelegate]);

const metadataSpace = TYPE_SIZE + LENGTH_SIZE + pack(metadata).length;

const lamports = await connection.getMinimumBalanceForRentExemption(
  mintSpace + metadataSpace,
  "confirmed"
);

const createAccountIx = SystemProgram.createAccount({
  fromPubkey: payer.publicKey,
  newAccountPubkey: mint.publicKey,
  space: mintSpace,
  lamports,
  programId: TOKEN_2022_PROGRAM_ID,
});

const initializeMetadataPointerIx = createInitializeMetadataPointerInstruction(
  mint.publicKey,
  mintAuthority.publicKey,
  mint.publicKey,
  TOKEN_2022_PROGRAM_ID
);

const initializeTransferFeesConfigIx =
  createInitializeTransferFeeConfigInstruction(
    mint.publicKey,
    transferFeeConfigAuthority.publicKey,
    withdrawWithheldAuthority.publicKey,
    50,
    BigInt(5000),
    TOKEN_2022_PROGRAM_ID
  );

const initializePermanentDelegationIx =
  createInitializePermanentDelegateInstruction(
    mint.publicKey,
    permanentDelegationAuthority.publicKey,
    TOKEN_2022_PROGRAM_ID
  );
const initializeMintIx = createInitializeMintInstruction(
  mint.publicKey,
  6,
  mintAuthority.publicKey,
  subzero.publicKey,
  TOKEN_2022_PROGRAM_ID
);

const initializeMetadataIx = createInitializeInstruction({
  programId: TOKEN_2022_PROGRAM_ID,
  metadata: mint.publicKey,
  updateAuthority: updataMetadataAuthority.publicKey,
  name: metadata.name,
  mint: mint.publicKey,
  mintAuthority: mintAuthority.publicKey,
  symbol: metadata.symbol,
  uri: metadata.uri,
});

const updateMetadataIx = createUpdateFieldInstruction({
  updateAuthority: updataMetadataAuthority.publicKey,
  metadata: mint.publicKey,
  programId: TOKEN_2022_PROGRAM_ID,
  field: metadata.additionalMetadata[0][0],
  value: metadata.additionalMetadata[0][1],
});

const transaction = new Transaction().add(
  createAccountIx,
  initializeMetadataPointerIx,
  initializeTransferFeesConfigIx,
  initializePermanentDelegationIx,
  initializeMintIx,
  //
  initializeMetadataIx,
  updateMetadataIx
);

try {
  const txHash = await sendAndConfirmTransaction(connection, transaction, [
    payer,
    updataMetadataAuthority,
    mint,
    mintAuthority,
  ]);
  console.log(`https://solscan.io/tx/${txHash}?cluster=devnet`);
} catch (err) {
  console.log("error: ", err);
}

@kasuba97
Copy link
Author

@buffalojoec
this the code that recreates the error

@buffalojoec
Copy link
Contributor

buffalojoec commented Mar 12, 2024

You're allocating too much data before initializing the mint. Calling getMintLen three times will allocate space for the base mint three times, as well as the extensions.

const mintSpace = getMintLen([
    ExtensionType.MetadataPointer,
    ExtensionType.TransferFeeConfig,
    ExtensionType.PermanentDelegate,
]);

@buffalojoec buffalojoec added the question Further information is requested label Mar 12, 2024
Copy link
Contributor

Hi @kasuba97,

Thanks for your question!

We want to make sure to keep signal strong in the GitHub issue tracker – to make sure that it remains the best place to track issues that affect the development of Solana itself.

Questions like yours deserve a purpose-built Q&A forum. Unless there exists evidence that this is a bug with Solana itself, please post your question to the Solana Stack Exchange using this link: https://solana.stackexchange.com/questions/ask


This automated message is a result of having added the ‘question’ tag.

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

No branches or pull requests

3 participants
@buffalojoec @kasuba97 and others