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

Jimii/refactor #16

Merged
merged 2 commits into from
Feb 22, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions programs/soundwork-bid/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ default = []
[dependencies]
anchor-lang = { version = "0.29.0", features = ["init-if-needed"] }
anchor-spl = { version = "0.29.0", features = ["metadata"] }
solana-security-txt = "1.1.1"
soundwork-list = { path = "../soundwork-list", features = ["cpi"] }
10 changes: 10 additions & 0 deletions programs/soundwork-bid/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ use instructions::*;

declare_id!("CVuoapcC1RG8y1m86eChkXmynPi4FaykDC8jM8soMZ4j");

#[cfg(not(feature = "no-entrypoint"))]
security_txt! {
name: "Soundwork Bid Program",
project_url: "https://soundwork.io",
contacts: "email:info@soundwork.io, twitter:@soundworkio",
policy: "https://github.com/SoundWorkLabs/market-contracts/blob/master/SECURITY.md",
preferred_languages: "en",
source_code: "https://github.com/SoundWorkLabs/market-contracts"
}

#[program]
pub mod soundwork_bid {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion programs/soundwork-list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ anchor-lang = { version = "0.29.0", features = ["init-if-needed"] }
anchor-spl = { version = "0.29.0", features = ["metadata"] }
mpl-token-metadata = "4.0.0"
serde = { version = "1.0", optional = true }
solana-security-txt = "1.1"
solana-security-txt = "1.1"
87 changes: 48 additions & 39 deletions programs/soundwork-list/src/instructions/create_listing.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use anchor_lang::prelude::*;
use anchor_spl::{
associated_token::AssociatedToken,
token::{Mint, Token, TokenAccount},
token::{self, Mint, Token, TokenAccount, TransferChecked},
};

use crate::{
helpers::{delegate_nft, transfer_nft},
state::listing::{AssetManagerV1, ListingDataV1},
};
use crate::state::listing::{AssetManagerV1, ListingDataV1};

#[derive(Accounts)]
pub struct CreateListing<'info> {
Expand Down Expand Up @@ -61,40 +58,52 @@ pub struct CreateListing<'info> {
pub system_program: Program<'info, System>,
}

pub fn create_listing_handler(ctx: Context<CreateListing>, lamports: u64) -> Result<()> {
// insert data into listing data account
let listing_data_acc = &mut ctx.accounts.listing_data;
**listing_data_acc = ListingDataV1::new(
lamports,
ctx.accounts.authority.key(),
ctx.accounts.mint.key(),
);

// signer seeds
let (_, bump) = Pubkey::find_program_address(&[b"soundwork".as_ref()], ctx.program_id);
let asset_manager_seeds = &[b"soundwork".as_ref(), &[bump]];
let asset_manager_signer = &[&asset_manager_seeds[..]];

// delegate authority to asset manager
delegate_nft(
ctx.accounts.authority.to_account_info(),
ctx.accounts.asset_manager.to_account_info(),
ctx.accounts.authority_token_account.to_account_info(),
ctx.accounts.mint.clone(),
ctx.accounts.token_program.clone(),
)?;

// we transfer the NFT to asset manager
transfer_nft(
ctx.accounts.authority_token_account.to_account_info(),
ctx.accounts.vault_token_account.to_account_info(),
ctx.accounts.mint.clone(),
ctx.accounts.authority.to_account_info(),
ctx.accounts.token_program.clone(),
asset_manager_signer,
)?;

Ok(())
impl<'info> CreateListing<'info> {
pub fn validate(&self) -> Result<()> {
Ok(())
}

/// creates a listing
#[access_control(ctx.accounts.validate())]
pub fn create_listing(ctx: Context<CreateListing>, lamports: u64) -> Result<()> {
// insert data into listing data account
let listing_data_acc = &mut ctx.accounts.listing_data;
**listing_data_acc = ListingDataV1::new(
lamports,
ctx.accounts.authority.key(),
ctx.accounts.mint.key(),
);

// signer seeds
let (_, bump) = Pubkey::find_program_address(&[b"soundwork".as_ref()], ctx.program_id);
let asset_manager_seeds = &[b"soundwork".as_ref(), &[bump]];
let asset_manager_signer = &[&asset_manager_seeds[..]];

// // delegate authority to asset manager
// delegate_nft(
// ctx.accounts.authority.to_account_info(),
// ctx.accounts.asset_manager.to_account_info(),
// ctx.accounts.authority_token_account.to_account_info(),
// ctx.accounts.mint.clone(),
// ctx.accounts.token_program.clone(),
// )?;

// transfer token to asset manager vault
let cpi_accounts = TransferChecked {
from: ctx.accounts.authority_token_account.to_account_info(),
mint: ctx.accounts.mint.to_account_info(),
to: ctx.accounts.vault_token_account.to_account_info(),
authority: ctx.accounts.authority.to_account_info(),
};

let cpi_program = ctx.accounts.token_program.to_account_info();
let cpi_context: CpiContext<'_, '_, '_, '_, TransferChecked<'_>> =
CpiContext::new(cpi_program, cpi_accounts);

token::transfer_checked(cpi_context, 1, 0)?;

Ok(())
}
}

//
46 changes: 28 additions & 18 deletions programs/soundwork-list/src/instructions/delete_listing.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use anchor_lang::prelude::*;
use anchor_spl::token::{Mint, Token, TokenAccount};
use anchor_spl::token::{self, Mint, Token, TokenAccount, TransferChecked};

use crate::{
helpers::transfer_nft,
error::CustomError,
state::listing::{AssetManagerV1, ListingDataV1},
};

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

#[account(
Expand Down Expand Up @@ -37,22 +37,32 @@ pub struct DeleteListing<'info> {
pub system_program: Program<'info, System>,
}

pub fn delete_listing_handler(ctx: Context<DeleteListing>) -> Result<()> {
// signer seeds
let (_, bump) = Pubkey::find_program_address(&[b"soundwork".as_ref()], ctx.program_id);
let asset_manager_seeds = &[b"soundwork".as_ref(), &[bump]];
let asset_manager_signer = &[&asset_manager_seeds[..]];
impl DeleteListing<'_> {
pub fn validate(&self) -> Result<()> {
return Ok(());
}

transfer_nft(
ctx.accounts.vault_token_account.to_account_info(),
ctx.accounts.authority_token_account.to_account_info(),
ctx.accounts.mint.clone(),
ctx.accounts.asset_manager.to_account_info(),
ctx.accounts.token_program.clone(),
asset_manager_signer,
)?;
/// Deletes a listing
#[access_control(ctx.accounts.validate())]
pub fn delete_listing(ctx: Context<DeleteListing>) -> Result<()> {
// signer seeds
let (_, bump) = Pubkey::find_program_address(&[b"soundwork".as_ref()], ctx.program_id);
let asset_manager_seeds = &[b"soundwork".as_ref(), &[bump]];
let asset_manager_signer = &[&asset_manager_seeds[..]];

// todo (Jimi) remove delegation ?
let cpi_accounts = TransferChecked {
from: ctx.accounts.vault_token_account.to_account_info(),
mint: ctx.accounts.mint.to_account_info(),
to: ctx.accounts.authority_token_account.to_account_info(),
authority: ctx.accounts.asset_manager.to_account_info(),
};

Ok(())
let cpi_program = ctx.accounts.token_program.to_account_info();
let cpi_context: CpiContext<'_, '_, '_, '_, TransferChecked<'_>> =
CpiContext::new(cpi_program, cpi_accounts).with_signer(asset_manager_signer);

token::transfer_checked(cpi_context, 1, 0)?;

Ok(())
}
}
21 changes: 14 additions & 7 deletions programs/soundwork-list/src/instructions/edit_listing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use anchor_lang::prelude::*;
use anchor_spl::token::{Mint, Token, TokenAccount};

use crate::{
// helpers::transfer_nft,
error::CustomError,
state::listing::{AssetManagerV1, ListingDataV1},
};

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

#[account(
Expand Down Expand Up @@ -38,10 +38,17 @@ pub struct EditListing<'info> {
pub system_program: Program<'info, System>,
}

pub fn edit_listing_handler(ctx: Context<EditListing>, lamports: u64) -> Result<()> {
// signer seeds
let listing_data_acc = &mut ctx.accounts.listing_data;
listing_data_acc.lamports = lamports;
impl EditListing<'_> {
pub fn validate(&self) -> Result<()> {
Ok(())
}

Ok(())
/// Edits a listing
#[access_control(ctx.accounts.validate())]
pub fn edit_listing(ctx: Context<EditListing>, lamports: u64) -> Result<()> {
let listing_data_acc = &mut ctx.accounts.listing_data;
listing_data_acc.lamports = lamports;

Ok(())
}
}
10 changes: 10 additions & 0 deletions programs/soundwork-list/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ use instructions::*;

declare_id!("EUmBNHvFqhkA6Uaqv6pDup5ESHKCqoAweQ4kzAMjNZhX");

#[cfg(not(feature = "no-entrypoint"))]
security_txt! {
name: "Soundwork List Program",
project_url: "https://soundwork.io",
contacts: "email:info@soundwork.io, twitter:@soundworkio",
policy: "https://github.com/SoundWorkLabs/market-contracts/blob/master/SECURITY.md",
preferred_languages: "en",
source_code: "https://github.com/SoundWorkLabs/market-contracts"
}

#[program]
pub mod soundwork_list {

Expand Down
Loading