use anchor_lang::prelude::*;
use crate::{
internal,
states::{market::utils::ClosableMarket, Market, Oracle, Store, TokenMapHeader},
};
#[derive(Accounts)]
pub struct UpdateClosedState<'info> {
pub authority: Signer<'info>,
#[account(has_one = token_map)]
pub store: AccountLoader<'info, Store>,
#[account(has_one = store)]
pub token_map: AccountLoader<'info, TokenMapHeader>,
#[account(mut, has_one = store)]
pub oracle: AccountLoader<'info, Oracle>,
#[account(mut, has_one = store)]
pub market: AccountLoader<'info, Market>,
}
impl<'info> UpdateClosedState<'info> {
pub(crate) fn invoke_unchecked(ctx: Context<'_, '_, 'info, 'info, Self>) -> Result<()> {
let mut market = ctx.accounts.market.load_mut()?;
let tokens = market
.meta()
.ordered_tokens()
.into_iter()
.collect::<Vec<_>>();
ctx.accounts.oracle.load_mut()?.with_prices_opts(
&ctx.accounts.store,
&ctx.accounts.token_map,
&tokens,
ctx.remaining_accounts,
|oracle, _remaining_accounts| market.update_closed_state(oracle),
true,
)?;
Ok(())
}
}
impl<'info> internal::Authentication<'info> for UpdateClosedState<'info> {
fn authority(&self) -> &Signer<'info> {
&self.authority
}
fn store(&self) -> &AccountLoader<'info, Store> {
&self.store
}
}