fix: vault как ATA + фандинг беттора; E2E на localnet ok

This commit is contained in:
Caffeine
2026-09-10 02:12:07 +03:00
parent fb9a7f4e8b
commit f937c8993d
15 changed files with 267 additions and 148 deletions
@@ -30,16 +30,16 @@ pub struct CloseBet<'info> {
/// CHECK: recipient must be the bet's bettor and is validated in the handler.
pub bettor: SystemAccount<'info>,
pub clock: Sysvar<'info, Clock>,
/// Program-owned token vault: PDA([GLOBAL_SEED, VAULT_SEED]); payouts are paid out from here.
#[account(
mut,
seeds = [GLOBAL_SEED, VAULT_SEED],
bump
)]
/// Token vault ATA (owner = PDA([GLOBAL_SEED, VAULT_SEED])); payouts are paid out from here.
#[account(mut)]
pub vault_token: Account<'info, TokenAccount>,
/// Bettor's SPL-token account; the payout is sent here.
#[account(mut)]
pub bettor_token: Account<'info, TokenAccount>,
/// CHECK: vault owner PDA, address enforced by the seeds = [GLOBAL_SEED, VAULT_SEED] + bump above.
/// It only serves as the CPI signing authority for the vault ATA payout, so no owner/type check is needed.
#[account(seeds = [GLOBAL_SEED, VAULT_SEED], bump)]
pub vault_authority: UncheckedAccount<'info>,
pub token_program: Program<'info, Token>,
}
@@ -86,16 +86,16 @@ let payout;
payout = payout_amount;
{
// Pay the bettor: transfer the payout from the vault to the bettor's token account.
// The vault is owned by the `global` PDA, so the CPI is signed with its seeds.
// The vault ATA is owned by the vault PDA, so the CPI is signed with its seeds.
let cpi_accounts = anchor_spl::token::Transfer {
from: ctx.accounts.vault_token.to_account_info(),
to: ctx.accounts.bettor_token.to_account_info(),
authority: ctx.accounts.vault_token.to_account_info(),
authority: ctx.accounts.vault_authority.to_account_info(),
};
let signer_seeds: &[&[u8]] = &[
GLOBAL_SEED,
VAULT_SEED,
&[ctx.bumps.vault_token],
&[ctx.bumps.vault_authority],
];
let vault_signer_seeds = [signer_seeds];
let cpi_ctx = CpiContext::new_with_signer(
@@ -2,7 +2,7 @@ use anchor_lang::prelude::*;
use anchor_spl::token::{Token, TokenAccount};
use crate::{
constants::{BET_SEED, GLOBAL_SEED, SIDE_DOWN, SIDE_UP, STATUS_OPEN, VAULT_SEED},
constants::{BET_SEED, GLOBAL_SEED, SIDE_DOWN, SIDE_UP, STATUS_OPEN},
error::SmartUpdownError,
events::BetCreated,
state::{Bet, Global},
@@ -32,12 +32,8 @@ pub struct CreateBet<'info> {
/// Bettor's SPL-token account (our "fanti" mint); bet amount is pulled from here.
#[account(mut)]
pub bettor_token: Account<'info, TokenAccount>,
/// Program-owned token vault: PDA([GLOBAL_SEED, VAULT_SEED]); bet amounts are escrowed here.
#[account(
mut,
seeds = [GLOBAL_SEED, VAULT_SEED],
bump
)]
/// Token vault ATA (owner = PDA([GLOBAL_SEED, VAULT_SEED])); bet amounts are escrowed here.
#[account(mut)]
pub vault_token: Account<'info, TokenAccount>,
pub token_program: Program<'info, Token>,
}