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

Implement Tier-Based Rewards #29

Open
7 tasks
jdnichollsc opened this issue Dec 15, 2024 · 0 comments
Open
7 tasks

Implement Tier-Based Rewards #29

jdnichollsc opened this issue Dec 15, 2024 · 0 comments

Comments

@jdnichollsc
Copy link
Member

Add Tier-Based Reward Logic

Definition of Done:

  • Campaign creators can define tiers with price, limits, and rewards.
  • Contributions can be linked to specific tiers.
  • Validate tier limits before accepting contributions.

Tasks:

  • Define the Tier struct.
  • Add an instruction for creators to create tiers.
  • Update contribution logic to support tiers.
  • Validate tier limits during contributions.

Code Example:

#[account]
pub struct Tier {
    pub campaign: Pubkey,             // Associated campaign
    pub title: String,                // Tier title
    pub price: u64,                   // Tier price in lamports
    pub max_backers: u32,             // Maximum number of backers
    pub current_backers: u32,         // Current number of backers
}

#[derive(Accounts)]
pub struct CreateTier<'info> {
    #[account(mut)]
    pub campaign: Account<'info, Campaign>,
    #[account(init, payer = creator, space = 8 + Tier::MAX_SIZE, seeds = [b"tier", campaign.key().as_ref(), title.as_bytes()], bump)]
    pub tier: Account<'info, Tier>,
    #[account(mut)]
    pub creator: Signer<'info>,
    pub system_program: Program<'info, System>,
}

pub fn create_tier(
    ctx: Context<CreateTier>,
    title: String,
    price: u64,
    max_backers: u32,
) -> Result<()> {
    let tier = &mut ctx.accounts.tier;
    tier.campaign = ctx.accounts.campaign.key();
    tier.title = title;
    tier.price = price;
    tier.max_backers = max_backers;
    tier.current_backers = 0;
    Ok(())
}
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

No branches or pull requests

1 participant