-
-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
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(())
}
Metadata
Metadata
Assignees
Labels
No labels