Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Commit

Permalink
fix: accept bid (#12)
Browse files Browse the repository at this point in the history
* fix: accept bid

* chore: run linter
  • Loading branch information
jim4067 authored Jan 20, 2024
1 parent 0e14579 commit 21fba50
Show file tree
Hide file tree
Showing 17 changed files with 301 additions and 419 deletions.
200 changes: 12 additions & 188 deletions Cargo.lock

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

9 changes: 3 additions & 6 deletions programs/soundwork-bid/src/instructions/accept_bid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ pub struct AcceptBid<'info> {
}

pub fn accept_bid_handler(ctx: Context<AcceptBid>) -> Result<()> {
let listing_data = &ctx.accounts.listing_data_acc;
let bidding_data = &ctx.accounts.bidding_data_acc;

// todo(Jimii): Expiry
// - time it expires

// transfer nft bidder and send fees to buyer
soundwork_list::cpi::buy_listing(ctx.accounts.buy_listing_ctx())?;
Expand All @@ -77,8 +73,9 @@ impl<'info> AcceptBid<'info> {
pub fn buy_listing_ctx(&self) -> CpiContext<'_, '_, '_, 'info, BuyListing<'info>> {
let cpi_program = self.soundwork_list.to_account_info();
let cpi_accounts = BuyListing {
buyer: self.seller.to_account_info(), // ! because he is paying for the tx
escrow_wallet_as_buyer: self.buyer_sol_escrow.to_account_info(),
payer: self.seller.to_account_info(), // ! because he is paying for thetx
buyer: self.buyer.to_account_info(),
escrow_wallet_as_buyer: self.buyer_sol_escrow.to_account_info().into(),
og_owner: self.seller.to_account_info(),
asset_manager: self.asset_manager.to_account_info(),
vault_token_account: self.vault_token_acc.to_account_info(),
Expand Down
26 changes: 9 additions & 17 deletions programs/soundwork-bid/src/instructions/create_bid.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
use anchor_lang::prelude::*;
use anchor_spl::token::Mint ;
use anchor_spl::token::Mint;

use crate::state::bid::BiddingDataV1;
use soundwork_list::{
self,
cpi::accounts::DepositSol,
program::SoundworkList,
state::listing::ListingDataV1,
error::CustomError,
self, cpi::accounts::DepositSol, program::SoundworkList, state::listing::ListingDataV1,
};

#[derive(Accounts)]
pub struct
CreateBid<'info> {
pub struct CreateBid<'info> {
#[account(
mut,
constraint = bidder.lamports() > listing_data_acc.lamports @CustomError::InsufficientFunds
// constraint = bidder.lamports() > listing_data_acc.lamports @CustomError::InsufficientFunds
)]
pub bidder: Signer<'info>,

Expand Down Expand Up @@ -52,23 +47,20 @@ pub fn create_bid_handler(ctx: Context<CreateBid>, lamports: u64, expires_ts: i6
**bidding_data_acc = BiddingDataV1::new(lamports, expires_ts, ctx.accounts.bidder.key());

// todo (Jimii) : check the 1000 extra
soundwork_list::cpi::deposit_sol(
ctx.accounts.initialize_escrow_ctx(), ctx.accounts.listing_data_acc.lamports + 1000
)?;
soundwork_list::cpi::deposit_sol(ctx.accounts.initialize_escrow_ctx(), lamports + 1000)?;

Ok(())
}

impl <'info> CreateBid <'info> {
pub fn initialize_escrow_ctx(&self) -> CpiContext<'_, '_, '_, 'info, DepositSol<'info>> {
impl<'info> CreateBid<'info> {
pub fn initialize_escrow_ctx(&self) -> CpiContext<'_, '_, '_, 'info, DepositSol<'info>> {
let cpi_program = self.soundwork_list.to_account_info();
let cpi_accounts = DepositSol {
owner: self.bidder.to_account_info(),
sol_escrow_wallet: self.sol_escrow_wallet.to_account_info(),
system_program: self.system_program.to_account_info()
system_program: self.system_program.to_account_info(),
};

CpiContext::new(cpi_program, cpi_accounts)

}
}
}
6 changes: 5 additions & 1 deletion programs/soundwork-bid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ pub mod soundwork_bid {
instructions::create_bid_handler(ctx, lamports, expires_ts)
}

pub fn edit_bid(ctx: Context<EditBid>, new_lamports: Option<u64>, new_expires: Option<i64>) -> Result<()> {
pub fn edit_bid(
ctx: Context<EditBid>,
new_lamports: Option<u64>,
new_expires: Option<i64>,
) -> Result<()> {
instructions::edit_bid_handler(ctx, new_expires, new_lamports)
}

Expand Down
Loading

0 comments on commit 21fba50

Please sign in to comment.