Skip to content

Commit 3ddcbdd

Browse files
authored
solana: deprecate auction history (#207)
Co-authored-by: A5 Pickle <a5-pickle@users.noreply.github.com>
1 parent fe2dcd1 commit 3ddcbdd

File tree

13 files changed

+447
-945
lines changed

13 files changed

+447
-945
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
use anchor_lang::prelude::*;
2+
3+
use crate::state::Auction;
4+
5+
#[event]
6+
#[derive(Debug)]
7+
pub struct AuctionClosed {
8+
pub auction: Auction,
9+
}

solana/programs/matching-engine/src/events/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
mod auction_closed;
2+
pub use auction_closed::*;
3+
14
mod auction_settled;
25
pub use auction_settled::*;
36

solana/programs/matching-engine/src/lib.rs

+67-40
Original file line numberDiff line numberDiff line change
@@ -354,46 +354,6 @@ pub mod matching_engine {
354354
processor::settle_auction_none_local(ctx)
355355
}
356356

357-
/// This instruction is used to create the first `AuctionHistory` account, whose PDA is derived
358-
/// using ID == 0.
359-
///
360-
/// # Arguments
361-
///
362-
/// * `ctx` - `CreateFirstAuctionHistory` context.
363-
pub fn create_first_auction_history(ctx: Context<CreateFirstAuctionHistory>) -> Result<()> {
364-
processor::create_first_auction_history(ctx)
365-
}
366-
367-
/// This instruction is used to create a new `AuctionHistory` account. The PDA is derived using
368-
/// its ID. A new history account can be created only when the current one is full (number of
369-
/// entries equals the hard-coded max entries).
370-
///
371-
/// # Arguments
372-
///
373-
/// * `ctx` - `CreateNewAuctionHistory` context.
374-
pub fn create_new_auction_history(ctx: Context<CreateNewAuctionHistory>) -> Result<()> {
375-
processor::create_new_auction_history(ctx)
376-
}
377-
378-
/// This instruction is used to add a new entry to the `AuctionHistory` account if there is an
379-
/// `Auction` with some info. Regardless of whether there is info in this account, the
380-
/// instruction finishes its operation by closing this auction account. If the history account
381-
/// is full, this instruction will revert and `create_new_auction_history`` will have to be
382-
/// called to initialize another history account.
383-
///
384-
/// This mechanism is important for auction participants. The initial offer participant will
385-
/// pay lamports to create the `Auction` account. This instruction allows him to reclaim some
386-
/// lamports by closing that account. And the protocol's fee recipient will be able to claim
387-
/// lamports by closing the empty `Auction` account it creates when he calls any of the
388-
/// `settle_auction_none_*` instructions.
389-
///
390-
/// # Arguments
391-
///
392-
/// * `ctx` - `AddAuctionHistoryEntry` context.
393-
pub fn add_auction_history_entry(ctx: Context<AddAuctionHistoryEntry>) -> Result<()> {
394-
processor::add_auction_history_entry(ctx)
395-
}
396-
397357
/// This instruction is used to reserve a sequence number for a fast fill. Fast fills are orders
398358
/// that have been fulfilled and are destined for Solana and are seeded by source chain, order
399359
/// sender and sequence number (similar to how Wormhole VAAs are identified by emitter chain,
@@ -415,6 +375,7 @@ pub mod matching_engine {
415375
) -> Result<()> {
416376
processor::reserve_fast_fill_sequence_active_auction(ctx)
417377
}
378+
418379
/// This instruction is used to reserve a sequence number for a fast fill. Fast fills are orders
419380
/// that have been fulfilled and are destined for Solana and are seeded by source chain, order
420381
/// sender and sequence number (similar to how Wormhole VAAs are identified by emitter chain,
@@ -452,6 +413,72 @@ pub mod matching_engine {
452413
pub fn close_redeemed_fast_fill(ctx: Context<CloseRedeemedFastFill>) -> Result<()> {
453414
processor::close_redeemed_fast_fill(ctx)
454415
}
416+
417+
/// This instruction is used to close an auction account after the auction has been settled and
418+
/// the VAA's timestamp indicates the order has expired. This instruction can be called by
419+
/// anyone to return the auction's preparer lamports from the rent required to keep this account
420+
/// alive. The auction data will be serialized as Anchor event CPI instruction data.
421+
///
422+
/// # Arguments
423+
///
424+
/// * `ctx` - `CloseAuction` context.
425+
pub fn close_auction(ctx: Context<CloseAuction>) -> Result<()> {
426+
processor::close_auction(ctx)
427+
}
428+
429+
// Deprecated instructions. These instructions will revert with `ErrorCode::InstructionMissing`.
430+
431+
/// DEPRECATED. This instruction does not exist anymore.
432+
///
433+
/// This instruction is used to create the first `AuctionHistory` account, whose PDA is derived
434+
/// using ID == 0.
435+
///
436+
/// # Arguments
437+
///
438+
/// * `ctx` - `CreateFirstAuctionHistory` context.
439+
pub fn create_first_auction_history(_ctx: Context<DeprecatedInstruction>) -> Result<()> {
440+
err!(ErrorCode::Deprecated)
441+
}
442+
443+
/// DEPRECATED. This instruction does not exist anymore.
444+
///
445+
/// This instruction is used to create a new `AuctionHistory` account. The PDA is derived using
446+
/// its ID. A new history account can be created only when the current one is full (number of
447+
/// entries equals the hard-coded max entries).
448+
///
449+
/// # Arguments
450+
///
451+
/// * `ctx` - `CreateNewAuctionHistory` context.
452+
pub fn create_new_auction_history(_ctx: Context<DeprecatedInstruction>) -> Result<()> {
453+
err!(ErrorCode::Deprecated)
454+
}
455+
456+
/// DEPRECATED. This instruction does not exist anymore.
457+
///
458+
/// This instruction is used to add a new entry to the `AuctionHistory` account if there is an
459+
/// `Auction` with some info. Regardless of whether there is info in this account, the
460+
/// instruction finishes its operation by closing this auction account. If the history account
461+
/// is full, this instruction will revert and `create_new_auction_history`` will have to be
462+
/// called to initialize another history account.
463+
///
464+
/// This mechanism is important for auction participants. The initial offer participant will
465+
/// pay lamports to create the `Auction` account. This instruction allows him to reclaim some
466+
/// lamports by closing that account. And the protocol's fee recipient will be able to claim
467+
/// lamports by closing the empty `Auction` account it creates when he calls any of the
468+
/// `settle_auction_none_*` instructions.
469+
///
470+
/// # Arguments
471+
///
472+
/// * `ctx` - `AddAuctionHistoryEntry` context.
473+
pub fn add_auction_history_entry(_ctx: Context<DeprecatedInstruction>) -> Result<()> {
474+
err!(ErrorCode::Deprecated)
475+
}
476+
}
477+
478+
#[derive(Accounts)]
479+
pub struct DeprecatedInstruction<'info> {
480+
/// CHECK: This account is here to avoid program macro compilation errors.
481+
_dummy: UncheckedAccount<'info>,
455482
}
456483

457484
#[cfg(test)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
use std::ops::Deref;
2+
3+
use crate::{
4+
error::MatchingEngineError,
5+
state::{Auction, AuctionStatus},
6+
};
7+
use anchor_lang::prelude::*;
8+
9+
#[derive(Accounts)]
10+
#[event_cpi]
11+
pub struct CloseAuction<'info> {
12+
#[account(
13+
mut,
14+
close = beneficiary,
15+
constraint = {
16+
require!(
17+
matches!(auction.status, AuctionStatus::Settled {..}),
18+
MatchingEngineError::AuctionNotSettled,
19+
);
20+
21+
let expiration =
22+
i64::from(auction.vaa_timestamp).saturating_add(crate::VAA_AUCTION_EXPIRATION_TIME);
23+
require!(
24+
Clock::get().unwrap().unix_timestamp >= expiration,
25+
MatchingEngineError::CannotCloseAuctionYet,
26+
);
27+
28+
true
29+
}
30+
)]
31+
auction: Account<'info, Auction>,
32+
33+
/// CHECK: This account is whoever originally created the auction account (see
34+
/// [Auction::prepared_by].
35+
#[account(
36+
mut,
37+
address = auction.prepared_by,
38+
)]
39+
beneficiary: UncheckedAccount<'info>,
40+
}
41+
42+
pub fn close_auction(ctx: Context<CloseAuction>) -> Result<()> {
43+
emit_cpi!(crate::events::AuctionClosed {
44+
auction: ctx.accounts.auction.deref().clone(),
45+
});
46+
47+
Ok(())
48+
}

solana/programs/matching-engine/src/processor/auction/history/add_entry.rs

-156
This file was deleted.

solana/programs/matching-engine/src/processor/auction/history/create_first.rs

-29
This file was deleted.

0 commit comments

Comments
 (0)