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

feat: add edit listing ix #8

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions programs/soundwork-bid/src/instructions/accept_bid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@ use soundwork_list::{
},
};

use crate::state::bid::BiddingDataV1;

#[derive(Accounts)]
pub struct AcceptBid<'info> {
// he will pay for the tx when he accepts a bid
#[account(
mut,
address = listing_data.owner.key()
address = listing_data_acc.owner.key()
)]
pub seller: Signer<'info>,

#[account(mut)]
pub listing_data_acc: Account<'info, ListingDataV1>,

#[account(
mut,
close = buyer
)]
pub listing_data: Account<'info, ListingDataV1>,
pub bidding_data_acc: Account<'info, BiddingDataV1>,

/// CHECK: checked when passing from PDA
#[account(mut)]
Expand All @@ -35,14 +40,12 @@ pub struct AcceptBid<'info> {
#[account(mut)]
pub mint: Account<'info, Mint>,

// this will pay for the listing
// pass system program to not use as signer
#[account(mut)]
pub buyer_sol_escrow: Account<'info, SolEscrowWallet>,

#[account(
init_if_needed,
payer = seller, // ! check if this can be made to be the bidding wallet
payer = seller,
associated_token::authority = buyer,
associated_token::mint = mint
)]
Expand All @@ -61,7 +64,8 @@ pub struct AcceptBid<'info> {
}

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

// todo(Jimii): Expiry
// - time it expires
Expand All @@ -84,7 +88,7 @@ impl<'info> AcceptBid<'info> {
vault_token_account: self.vault_token_acc.to_account_info(),
buyer_token_account: self.buyer_token_acc.to_account_info(),
mint: self.mint.to_account_info(),
listing_data: self.listing_data.to_account_info(),
listing_data: self.listing_data_acc.to_account_info(),
token_program: self.token_program.to_account_info(),
system_program: self.system_program.to_account_info(),
};
Expand Down
37 changes: 36 additions & 1 deletion programs/soundwork-bid/src/instructions/edit_bid.rs
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
// todo(Jimii)
use anchor_lang::prelude::*;

use crate::state::bid::BiddingDataV1;
use soundwork_list::error::CustomError;

#[derive(Accounts)]
pub struct EditBid<'info> {
#[account(
mut,
address = bidding_data_acc.owner @ CustomError::UnrecognizedSigner
)]
pub bidder: Signer<'info>,

#[account(mut)]
pub bidding_data_acc: Account<'info, BiddingDataV1>,

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

pub fn edit_bid_handler(
ctx: Context<EditBid>,
new_expiry: Option<i64>,
new_lamports: Option<u64>,
) -> Result<()> {
let bidding_data_acc = &mut ctx.accounts.bidding_data_acc;

if let Some(expire_ts) = new_expiry {
bidding_data_acc.expires_ts = expire_ts;
}

if let Some(lamports) = new_lamports {
bidding_data_acc.lamports = lamports;
}

Ok(())
}
4 changes: 2 additions & 2 deletions programs/soundwork-bid/src/instructions/reject_bid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ pub struct RejectBid<'info> {
// he will pay for the tx when he accepts a bid
#[account(
mut,
address = listing_data.owner.key() @ CustomError::UnrecognizedSigner
address = listing_data_acc.owner.key() @ CustomError::UnrecognizedSigner
)]
pub seller: Signer<'info>,

#[account(mut)]
pub listing_data: Account<'info, ListingDataV1>,
pub listing_data_acc: Account<'info, ListingDataV1>,

/// CHECK: checked when passing from PDA
#[account(mut)]
Expand Down
4 changes: 4 additions & 0 deletions programs/soundwork-bid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ 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<()> {
instructions::edit_bid_handler(ctx, new_expires, new_lamports)
}

/// deletes a bid for an nft
pub fn delete_bid(ctx: Context<DeleteBid>) -> Result<()> {
instructions::delete_bid_handler(ctx)
Expand Down
2 changes: 1 addition & 1 deletion programs/soundwork-list/src/instructions/buy_listing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct BuyListing<'info> {

#[account(mut)]
pub vault_token_account: Account<'info, TokenAccount>, // asset manager ATA that will hold all nfts

#[account(mut)]
pub buyer_token_account: Account<'info, TokenAccount>, // buyer ATA

Expand Down
47 changes: 24 additions & 23 deletions tests/soundwork-bid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ describe("SOUNDWORK BID", async () => {
// .acceptBid()
// .accounts({
// seller: signerOneKp.publicKey,
// listingData: listingDataAcc,
// biddingDataAcc,
// listingDataAcc,
// buyer: signerTwoKp.publicKey,
// mint: nftMint,
// // biddingWallet: findBiddingWallet(signerTwoKp.publicKey),
Expand Down Expand Up @@ -88,18 +89,18 @@ describe("SOUNDWORK BID", async () => {
// });

// it("rejects bid!", async () => {
// let ix = await bidProgram.methods
// .rejectBid()
// .accounts({
// seller: signerOneKp.publicKey,
// listingData: listingDataAcc,
// buyer: signerTwoKp.publicKey,
// buyerSolEscrow: findUserEscrowWallet(signerTwoKp.publicKey),
// biddingDataAcc,
// soundworkList: listProgram.programId,
// systemProgram: anchor.web3.SystemProgram.programId,
// })
// .instruction();
// let ix = await bidProgram.methods
// .rejectBid()
// .accounts({
// seller: signerOneKp.publicKey,
// listingDataAcc,
// buyer: signerTwoKp.publicKey,
// buyerSolEscrow: findUserEscrowWallet(signerTwoKp.publicKey),
// biddingDataAcc,
// soundworkList: listProgram.programId,
// systemProgram: anchor.web3.SystemProgram.programId,
// })
// .instruction();

// let tx = new anchor.web3.Transaction().add(ix);

Expand All @@ -115,16 +116,16 @@ describe("SOUNDWORK BID", async () => {
// });

// it("deletes a bid!", async () => {
// let ix = await bidProgram.methods
// .deleteBid()
// .accounts({
// bidder: signerTwoKp.publicKey,
// biddingDataAcc,
// solEscrowWallet: findUserEscrowWallet(signerTwoKp.publicKey),
// soundworkList: listProgram.programId,
// systemProgram: anchor.web3.SystemProgram.programId,
// })
// .instruction();
// let ix = await bidProgram.methods
// .deleteBid()
// .accounts({
// bidder: signerTwoKp.publicKey,
// biddingDataAcc,
// solEscrowWallet: findUserEscrowWallet(signerTwoKp.publicKey),
// soundworkList: listProgram.programId,
// systemProgram: anchor.web3.SystemProgram.programId,
// })
// .instruction();

// let tx = new anchor.web3.Transaction().add(ix);

Expand Down
Loading