lib.rs
Sablier Merkle Instant program for creating and managing Merkle tree-based airdrop campaigns.
State-changing Instructions
claim
Claims airdrop on behalf of eligible recipient and transfers it to the recipient ATA.
Accounts Expected
claimerThe transaction signer.campaignThe account that stores the campaign details.recipientThe address of the airdrop recipient.airdrop_token_mintThe mint of the airdropped token.airdrop_token_programThe Token Program of the airdropped token.chainlink_program: The Chainlink program used to retrieve on-chain price feeds.chainlink_sol_usd_feed: The account providing the SOL/USD price feed data.
Parameters
indexThe index of the recipient in the Merkle tree.amountThe amount allocated to the recipient.merkle_proofThe proof of inclusion in the Merkle tree.
Notes
- Emits a Claim event.
Requirements
- The current time must be greater than or equal to the campaign start time.
- The campaign must not have expired.
- The recipient's airdrop has not been claimed yet.
- The Merkle proof must be valid.
chainlink_programandchainlink_sol_usd_feedmust match the ones stored in the treasury.
pub fn claim(ctx: Context<Claim>, index: u32, amount: u64, merkle_proof: Vec<[u8; 32]>) -> Result<()>
clawback
Claws back the unclaimed tokens from the campaign.
Accounts Expected
campaignThe account that stores the campaign details.campaign_creatorThe transaction signer.airdrop_token_mintThe mint of the airdropped token.airdrop_token_programThe Token Program of the airdropped token.
Parameters
amountThe amount to claw back.
Notes
- Emits a Clawback event.
Requirements
- The signer must be the actual campaign creator.
- No claim must be made, OR the current timestamp must not exceed 7 days after the first claim, OR the campaign must be expired.
pub fn clawback(ctx: Context<Clawback>, amount: u64) -> Result<()>
collect_fees
Collects the fees accumulated in the treasury by transferring them to the fee recipient.
Accounts Expected
fee_collectorThe transaction signer and the fee collector.fee_recipientThe address receiving the collected fees.
Notes
- To calculate the "collectable amount", the rent-exempt minimum balance and a 0.001 SOL buffer are deducted from the treasury SOL balance.
- Emits a FeesCollected event.
Requirements
fee_collectormust be authorized for fee collection.- The "collectable amount" must be greater than zero.
pub fn collect_fees(ctx: Context<CollectFees>) -> Result<()>
create_campaign
Creates a Merkle Instant airdrop campaign.
Accounts Expected
creatorThe transaction signer and the campaign creator.airdrop_token_mintThe mint of the airdropped token.airdrop_token_programThe Token Program of the airdropped token.
Parameters
merkle_rootThe Merkle root of the claim data.campaign_start_timeThe time when the campaign starts, in seconds since the Unix epoch.expiration_timeThe time when the campaign expires, in seconds since the Unix epoch. A value of zero means the campaign does not expire.nameThe name of the campaign.ipfs_cidThe content identifier for indexing the campaign on IPFS. An empty value may break some UI features that depend upon the IPFS CID.aggregate_amountThe total amount of tokens to be distributed to all recipients.recipient_countThe total number of recipient addresses eligible for the airdrop.
Notes
- Emits a CreateCampaign event.
pub fn create_campaign(
ctx: Context<CreateCampaign>,
merkle_root: [u8; 32],
campaign_start_time: u64,
expiration_time: u64,
name: String,
ipfs_cid: String,
aggregate_amount: u64,
recipient_count: u32,
) -> Result<()>
initialize
Initializes the program with the provided fee collector address.
Accounts Expected
initializerThe transaction signer.
Parameters
fee_collectorThe address that will have the authority to collect fees.chainlink_program: The Chainlink program used to retrieve on-chain price feeds.chainlink_sol_usd_feed: The account providing the SOL/USD price feed data.
pub fn initialize(
ctx: Context<Initialize>,
fee_collector: Pubkey,
chainlink_program: Pubkey,
chainlink_sol_usd_feed: Pubkey,
) -> Result<()>
Read-only Instructions
campaign_view
Retrieves the campaign details.
Accounts Expected
campaignThe account that stores the campaign details.
pub fn campaign_view(ctx: Context<CampaignView>) -> Result<state::Campaign>
claim_fee_in_lamports
Calculates the claim fee in lamports.
Accounts Expected:
chainlink_program: The Chainlink program used to retrieve on-chain price feeds.chainlink_sol_usd_feed: The account providing the SOL/USD price feed data.
pub fn claim_fee_in_lamports(ctx: Context<ClaimFeeInLamports>) -> Result<u64>
has_claimed
Returns a flag indicating whether a claim has been made for the given index.
Accounts Expected
campaignThe account that stores the campaign details.
Parameters
_indexThe index of the recipient in the Merkle tree.
pub fn has_claimed(ctx: Context<HasClaimed>, _index: u32) -> Result<bool>
has_expired
Returns a flag indicating whether the campaign has expired.
Accounts Expected
campaignThe account that stores the campaign details.
pub fn has_expired(ctx: Context<CampaignView>) -> Result<bool>
has_grace_period_passed
Returns a flag indicating whether the grace period of the campaign has passed.
Accounts Expected
campaignThe account that stores the campaign details.
Notes
- A return value of
falseindicates: No claim has been made yet, OR the current timestamp does not exceed seven days after the first claim.
pub fn has_grace_period_passed(ctx: Context<CampaignView>) -> Result<bool>
has_campaign_started
Returns a flag indicating whether the campaign has started.
Accounts expected:
campaignThe account that stores the campaign details.
pub fn has_campaign_started(ctx: Context<CampaignView>) -> Result<bool>
treasury_view
Returns the treasury details.
pub fn treasury_view(ctx: Context<TreasuryView>) -> Result<state::Treasury>