← Program logic

programs/bond_servicing/src/instructions/confirm_funding.rs

Source at revision e5ff2b3cb157, the source of the program deployed on devnet. SHA-256 of this file 203e61b1368b3a182caa2206f79b25ba906342fa0a0735a8eb995ccc120a40b9

1//! The issuer has put cash into the event's vault (a plain token transfer). Anyone may confirm that the vault
2//! covers the event's budget; payments start only after that, so no holder is paid from an event that cannot
3//! pay all of them.
4
5use anchor_lang::prelude::*;
6use anchor_spl::token_interface::TokenAccount;
7
8use crate::constants::*;
9use crate::error::BondError;
10use crate::events::EventFunded;
11use crate::state::Event;
12
13#[derive(Accounts)]
14pub struct ConfirmFunding<'info> {
15    #[account(mut, has_one = vault, seeds = [EVENT_SEED, event.bond.as_ref(), &event.index.to_le_bytes()], bump = event.bump)]
16    pub event: Box<Account<'info, Event>>,
17
18    pub vault: Box<InterfaceAccount<'info, TokenAccount>>,
19}
20
21pub fn handle_confirm_funding(ctx: Context<ConfirmFunding>) -> Result<()> {
22    let event = &mut ctx.accounts.event;
23    require!(!event.funded, BondError::AlreadyFunded);
24    let vault_balance = ctx.accounts.vault.amount;
25    require!(vault_balance >= event.budget, BondError::InsufficientFunding);
26    event.funded = true;
27    emit!(EventFunded { bond: event.bond, event: event.index, vault_balance, budget: event.budget });
28    Ok(())
29}