Skip to content

Commit

Permalink
Auctioneer scopes (#402)
Browse files Browse the repository at this point in the history
* chore(auction-house): bump versions to anchor 0.24.2

* refactor(auction-house): add auctioneer module; refactor bid

* refactor(auction-house): add cancel & deposit modules

* refactor(auction-house): add execute_sale mod; refactor receipts

* refactor(auction-house): add sell & withdraw mods

* test(auction-house): refactor tests for auctioneer

* refactor(auction-house): box various accounts to reduce stack size

* style(auction-house): update Anchor CHECK comments

* fix(auction-house): add better rent checks to auction_bid_logic

* fix(auction-house): add shortfall check for rent migration to execute_sale logic

* fix(auction-house): apply sec fix and test from GHSA-27g6-cw44-x825

* chore(auction-house): bump version to match master

* chore(auction-house) remove redundant test file

* refactor(auction-house) remove update auctioneer handler; fix some naming

* refactor(auction-house): rename auctioneer items
  • Loading branch information
samuelvanderwaal authored May 17, 2022
1 parent 3f5b7ee commit 1363c4a
Show file tree
Hide file tree
Showing 29 changed files with 7,612 additions and 2,407 deletions.
52 changes: 26 additions & 26 deletions auction-house/program/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions auction-house/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ default = []

[dependencies]
solana-program = "~1.9.15"
anchor-lang = "~0.24.1"
anchor-spl = "~0.24.1"
anchor-lang = "~0.24.2"
anchor-spl = "~0.24.2"
spl-token = { version = "~3.2", features = ["no-entrypoint"] }
spl-associated-token-account = {version = "~1.0.3", features = ["no-entrypoint"]}
mpl-token-metadata = { version="~1.2.7", features = [ "no-entrypoint" ], path="../../token-metadata/program" }
Expand All @@ -32,7 +32,7 @@ thiserror = "~1.0"
arrayref = "~0.3.6"

[dev-dependencies]
anchor-client = "~0.24.1"
anchor-client = "~0.24.2"
shellexpand = "~2.1.0"
serde_json = "~1.0"
solana-program = "~1.9.15"
Expand Down
52 changes: 52 additions & 0 deletions auction-house/program/src/auctioneer/delegate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use anchor_lang::prelude::*;

use crate::{constants::*, errors::AuctionHouseError, AuctionHouse, Auctioneer, AuthorityScope};

/// Accounts for the [`delegate_auctioneer` handler](auction_house/fn.delegate_auctioneer.html).
#[derive(Accounts)]
pub struct DelegateAuctioneer<'info> {
// Auction House instance PDA account.
#[account(mut, seeds=[PREFIX.as_bytes(), auction_house.creator.as_ref(), auction_house.treasury_mint.as_ref()], bump=auction_house.bump, has_one=authority)]
pub auction_house: Account<'info, AuctionHouse>,

#[account(mut)]
pub authority: Signer<'info>,

/// CHECK: The auction house authority can set this to whatever external address they wish.
/// The auctioneer program PDA running this auction.
pub auctioneer_authority: UncheckedAccount<'info>,

/// The auctioneer PDA owned by Auction House storing scopes.
#[account(init, payer = authority, space = AUCTIONEER_SIZE, seeds = [AUCTIONEER.as_bytes(), auction_house.key().as_ref(), auctioneer_authority.key().as_ref()], bump)]
pub ah_auctioneer_pda: Account<'info, Auctioneer>,

pub system_program: Program<'info, System>,
}

pub fn delegate_auctioneer<'info>(
ctx: Context<'_, '_, '_, 'info, DelegateAuctioneer<'info>>,
scopes: Box<Vec<AuthorityScope>>,
) -> Result<()> {
if scopes.len() > MAX_NUM_SCOPES {
return Err(AuctionHouseError::TooManyScopes.into());
}

let auction_house = &mut ctx.accounts.auction_house;
auction_house.has_auctioneer = true;
auction_house.auctioneer_pda_bump = *ctx
.bumps
.get("ah_auctioneer_pda")
.ok_or(AuctionHouseError::BumpSeedNotInHashMap)?;

let auctioneer = &mut ctx.accounts.ah_auctioneer_pda;
auctioneer.auctioneer_authority = ctx.accounts.auctioneer_authority.key();
auctioneer.auction_house = ctx.accounts.auction_house.key();

// Set all scopes false and then update as true the ones passed into the handler.
auctioneer.scopes = [false; 7];
for scope in *scopes {
auctioneer.scopes[scope as usize] = true;
}

Ok(())
}
2 changes: 2 additions & 0 deletions auction-house/program/src/auctioneer/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub mod delegate;
pub use delegate::*;
Loading

0 comments on commit 1363c4a

Please sign in to comment.