0

I have a game that requires players to "buy in", that transfers their lamports to a PDA.

My question is, whats the best way to hardcode a transfer (of % buyin amount) to a specific address?

The intended behavior is like Degencoinflip where they extract the fee via another program. Im not really sure how this would work at a high level.

My current approach is to add the logic, and add my wallet to the account validation struct for buyin, and then to subsequently give that to clients before submitting the TX. But uh, this doesnt seem like its best practice. Im a total noob.

Any help would be so appreciated!

1 Answer 1

0

You'll probably a want a fee account, something like this:

    #[account(
        init,
        seeds = [
            b"fee-vault".as_ref(),
        ],
        bump,
        payer = payer,
        token::mint = whatever,
        token::authority = probably_a_program_owned_pda
    )]
    pub fee_vault: Box<Account<'info, TokenAccount>>,

In the ix that transfers lamports to the PDA, simply transfer some to the fee account as well.

If fees are part of another program entirely and the buy in is in another program and for some reason you can't do a CPI, have that program mint notes that prove the deposit, and have them burn those notes as proof that fees have been paid.

2
  • Also, is the way Im getting the env variable bad practice?
    – TLS
    Dec 18, 2022 at 0:56
  • I see I see, thank you for the swift response! So since many games are running in parralel, just do the usual business logic, and in addition, transfer relative # of lamports to fee account pda. To actually cash out that fee account, and send to my wallet, would that require a dedicated IX to handler? If so, Im able to pass my pubkey as an env variable with std::option_env. But its just a string. Is there a constructor I can use to get a pubkey type? I believe Pubkey::new() is what Im looking for, but how can I cast my base58 string into a [&u8]? Thank you so much again!
    – TLS
    Dec 18, 2022 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.