Skip to content

feat: replace admin_config keypair with deterministic PDA - #27

Open
0xRektified wants to merge 1 commit into
RareSkills:prodfrom
0xRektified:feat/spl-token-sale-admin-config-pda
Open

feat: replace admin_config keypair with deterministic PDA#27
0xRektified wants to merge 1 commit into
RareSkills:prodfrom
0xRektified:feat/spl-token-sale-admin-config-pda

Conversation

@0xRektified

Copy link
Copy Markdown

Feature Request: Use PDA for admin_config account

Current Implementation

The tutorial currently uses a generated keypair for the admin_config account:

const adminConfigKp = web3.Keypair.generate();

await program.methods.initialize()
  .accounts({
    adminConfig: adminConfigKp.publicKey,
    // ...
  })
  .signers([adminKp, adminConfigKp])  // Requires two signers
  .rpc();
Rust side:
#[account(
    init,
    payer = admin,
    space = 8+AdminConfig::INIT_SPACE,
)]
pub admin_config: Account<'info, AdminConfig>,

Proposed Implementation

Use a PDA with a deterministic seed for the admin_config account:

const [adminConfigPda] = web3.PublicKey.findProgramAddressSync(
  [Buffer.from("admin_config")],
  program.programId
);

await program.methods.initialize()
  .accounts({
    adminConfig: adminConfigPda,
    // ...
  })
  .signers([adminKp])  // Only one signer needed
  .rpc();

Solana program:

#[account(
    init,
    payer = admin,
    space = 8+AdminConfig::INIT_SPACE,
    seeds = [b"admin_config"],
    bump,
)]
pub admin_config: Account<'info, AdminConfig>,

Benefits

No off-chain storage required, simpler client code, no keypair generation needed only requires admin signer (not both admin and adminConfig). Better developer experience, users following the tutorial won't need to worry about storing or losing the admin config address

Changes Required

If this PR is accepted we ll need to update the following screenshot:

![A screenshot showing constraints for the admin_config account initialization](https://r2media.rareskills.io/SolanaSPLTokenSale/image8.png)

As i wasn't able to

Impact

This change improves the tutorial by teaching the industry standard pattern for program owned accounts, making it more aligned with real world production code.

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.

1 participant