Merge branch 'instant-sale' of https://github.com/metaplex-foundation/metaplex into instant-sale

This commit is contained in:
shotgunofdeath 2021-09-21 15:02:25 +03:00
commit be726649de
2 changed files with 47 additions and 36 deletions

View File

@ -374,6 +374,7 @@ pub fn claim_bid_instruction(
bidder_pubkey: Pubkey,
bidder_pot_token_pubkey: Pubkey,
token_mint_pubkey: Pubkey,
auction_extended_pubkey: Option<Pubkey>,
args: ClaimBidArgs,
) -> Instruction {
// Derive Auction Key
@ -393,28 +394,25 @@ pub fn claim_bid_instruction(
];
let (bidder_pot_pubkey, _) = Pubkey::find_program_address(seeds, &program_id);
let seeds = &[
PREFIX.as_bytes(),
program_id.as_ref(),
args.resource.as_ref(),
EXTENDED.as_bytes(),
let mut accounts = vec![
AccountMeta::new(destination_pubkey, false),
AccountMeta::new(bidder_pot_token_pubkey, false),
AccountMeta::new(bidder_pot_pubkey, false),
AccountMeta::new_readonly(authority_pubkey, true),
AccountMeta::new_readonly(auction_pubkey, false),
AccountMeta::new_readonly(bidder_pubkey, false),
AccountMeta::new_readonly(token_mint_pubkey, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(spl_token::id(), false),
];
let (auction_extended_pubkey, _) = Pubkey::find_program_address(seeds, &program_id);
if let Some(auction_extended) = auction_extended_pubkey {
accounts.push(AccountMeta::new_readonly(auction_extended, false));
}
Instruction {
program_id,
accounts: vec![
AccountMeta::new(destination_pubkey, false),
AccountMeta::new(bidder_pot_token_pubkey, false),
AccountMeta::new(bidder_pot_pubkey, false),
AccountMeta::new_readonly(authority_pubkey, true),
AccountMeta::new_readonly(auction_pubkey, false),
AccountMeta::new_readonly(bidder_pubkey, false),
AccountMeta::new_readonly(token_mint_pubkey, false),
AccountMeta::new_readonly(sysvar::clock::id(), false),
AccountMeta::new_readonly(spl_token::id(), false),
AccountMeta::new_readonly(auction_extended_pubkey, false),
],
accounts,
data: AuctionInstruction::ClaimBid(args).try_to_vec().unwrap(),
}
}

View File

@ -20,7 +20,7 @@ use {
pub fn issue_claim_bid<'a>(
auction_program: AccountInfo<'a>,
auction: AccountInfo<'a>,
auction_extended: AccountInfo<'a>,
auction_extended: Option<AccountInfo<'a>>,
accept_payment: AccountInfo<'a>,
authority: AccountInfo<'a>,
bidder: AccountInfo<'a>,
@ -32,6 +32,24 @@ pub fn issue_claim_bid<'a>(
vault: Pubkey,
signer_seeds: &[&[u8]],
) -> ProgramResult {
let mut account_infos = vec![
auction_program.clone(),
authority.clone(),
auction,
clock,
token_mint.clone(),
bidder.clone(),
bidder_pot_token_acct.clone(),
bidder_pot,
accept_payment.clone(),
token_program,
];
let mut auction_extended_key: Option<Pubkey> = None;
if let Some(auction_extended_account) = auction_extended {
auction_extended_key = Some(*auction_extended_account.key);
account_infos.push(auction_extended_account);
}
invoke_signed(
&claim_bid_instruction(
*auction_program.key,
@ -40,21 +58,10 @@ pub fn issue_claim_bid<'a>(
*bidder.key,
*bidder_pot_token_acct.key,
*token_mint.key,
auction_extended_key,
ClaimBidArgs { resource: vault },
),
&[
auction_program,
authority,
auction,
auction_extended,
clock,
token_mint,
bidder,
bidder_pot_token_acct,
bidder_pot,
accept_payment,
token_program,
],
account_infos.as_ref(),
&[&signer_seeds],
)?;
@ -68,7 +75,6 @@ pub fn process_claim_bid(program_id: &Pubkey, accounts: &[AccountInfo]) -> Progr
let bidder_pot_info = next_account_info(account_info_iter)?;
let mut auction_manager_info = next_account_info(account_info_iter)?;
let auction_info = next_account_info(account_info_iter)?;
let auction_extended_info = next_account_info(account_info_iter)?;
let bidder_info = next_account_info(account_info_iter)?;
let token_mint_info = next_account_info(account_info_iter)?;
let vault_info = next_account_info(account_info_iter)?;
@ -76,6 +82,7 @@ pub fn process_claim_bid(program_id: &Pubkey, accounts: &[AccountInfo]) -> Progr
let auction_program_info = next_account_info(account_info_iter)?;
let clock_info = next_account_info(account_info_iter)?;
let token_program_info = next_account_info(account_info_iter)?;
let auction_extended_info = next_account_info(account_info_iter).ok();
let mut auction_manager = get_auction_manager(auction_manager_info)?;
let store = Store::from_account_info(store_info)?;
@ -83,7 +90,6 @@ pub fn process_claim_bid(program_id: &Pubkey, accounts: &[AccountInfo]) -> Progr
let token_pot_info = BidderPot::from_account_info(bidder_pot_info)?;
assert_owned_by(auction_info, &store.auction_program)?;
assert_owned_by(auction_extended_info, &store.auction_program)?;
assert_owned_by(auction_manager_info, program_id)?;
assert_owned_by(accept_payment_info, &spl_token::id())?;
assert_owned_by(bidder_pot_token_info, &spl_token::id())?;
@ -91,6 +97,9 @@ pub fn process_claim_bid(program_id: &Pubkey, accounts: &[AccountInfo]) -> Progr
assert_owned_by(token_mint_info, &spl_token::id())?;
assert_owned_by(vault_info, &store.token_vault_program)?;
assert_owned_by(store_info, program_id)?;
if let Some(auction_extended) = auction_extended_info {
assert_owned_by(auction_extended, &store.auction_program)?;
}
if auction_manager.store() != *store_info.key {
return Err(MetaplexError::AuctionManagerStoreMismatch.into());
@ -115,7 +124,11 @@ pub fn process_claim_bid(program_id: &Pubkey, accounts: &[AccountInfo]) -> Progr
if auction_manager.vault() != *vault_info.key {
return Err(MetaplexError::AuctionManagerVaultMismatch.into());
}
let instant_sale_price = AuctionDataExtended::get_instant_sale_price(&auction_extended_info.data.borrow());
let mut instant_sale_price: Option<u64> = None;
if let Some(auction_extended) = auction_extended_info {
instant_sale_price = AuctionDataExtended::get_instant_sale_price(&auction_extended.data.borrow());
}
if !instant_sale_price.is_some() {
if auction.state != AuctionState::Ended {
return Err(MetaplexError::AuctionHasNotEnded.into());
@ -145,7 +158,7 @@ pub fn process_claim_bid(program_id: &Pubkey, accounts: &[AccountInfo]) -> Progr
issue_claim_bid(
auction_program_info.clone(),
auction_info.clone(),
auction_extended_info.clone(),
auction_extended_info.map_or(None, |acc| Some(acc.clone())),
accept_payment_info.clone(),
auction_manager_info.clone(),
bidder_info.clone(),