crea8r / communify

Decaying tokens.
0 stars 0 forks source link

Decouple the data owner and the rent payer in all transaction #29

Closed 0xk2 closed 3 months ago

0xk2 commented 3 months ago

Problem

Take this Struct for example:

pub struct CreateCtx<'info> {
    #[account(init, payer = admin, 
        seeds=[CommunityAccount::SEED, random.key.as_ref()], bump,
        space = 8 + CommunityAccount::INIT_SPACE)]
    pub community_account: Account<'info, CommunityAccount>,
    #[account(mut)]
    pub admin: Signer<'info>,
        /// CHECK: this account is created randomly, no need to do anything
        pub random: AccountInfo<'info>,
        pub system_program: Program<'info, System>,
}

This design assume that the admin will pay rent for the CommunityAccount but it is not always the case. If I want to design a gas-less experience in Solana then this design block me from doing so.

Solution

Seperate the rent payer and data owner. The new data structure should be:

pub struct CreateCtx<'info> {
    #[account(init, payer = rent_payer, 
        seeds=[CommunityAccount::SEED, random.key.as_ref()], bump,
        space = 8 + CommunityAccount::INIT_SPACE)]
    pub community_account: Account<'info, CommunityAccount>,
    #[account(mut)]
    pub admin: Signer<'info>,
        #[account(mut)]
        pub rent_payer: Signer<'info>,
        /// CHECK: this account is created randomly, no need to do anything
        pub random: AccountInfo<'info>,
        pub system_program: Program<'info, System>,
}

Should apply this to all account creation and modification: