Skip to content

Commit

Permalink
Updating Stateless Offer to Optionally Include Fees (solana-labs#2507)
Browse files Browse the repository at this point in the history
* Updating Stateless Offer PDA seeds to only require main wallet and mint types

* Added optional payment of creator fees for NFTs

* Addressed formatting issues

* Fixed bugs in fee paying code, removed logs to lower compute limit

* Add in check to make sure the proper metadata is passed in

* Added workflow for taker posting NFT (maker pays fees)
  • Loading branch information
jarry-xiao authored Oct 21, 2021
1 parent ef72e56 commit c8963e8
Show file tree
Hide file tree
Showing 5 changed files with 328 additions and 49 deletions.
31 changes: 31 additions & 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 stateless-asks/program/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ borsh = "0.9.1"
solana-program = "1.8.0"
spl-token = { version = "3.2", path = "../../token/program", features = ["no-entrypoint"] }
spl-associated-token-account = {version = "1.0.3", features = ["no-entrypoint"]}
metaplex-token-metadata = { version = "0.0.1", features = ["no-entrypoint"] }
thiserror = "1.0"

[dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions stateless-asks/program/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ pub enum UtilError {
StatementFalse,
#[error("NotRentExempt")]
NotRentExempt,
#[error("NumericalOverflow")]
NumericalOverflow,
}

impl From<UtilError> for ProgramError {
Expand Down
65 changes: 64 additions & 1 deletion stateless-asks/program/src/instruction.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
//! Instruction types
use {
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
solana_program::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
system_program,
},
};

Expand All @@ -24,6 +26,8 @@ pub enum StatelessOfferInstruction {
/// Bob (or anyone) executes AcceptOffer
///
AcceptOffer {
#[allow(dead_code)]
has_metadata: bool,
#[allow(dead_code)]
maker_size: u64,
#[allow(dead_code)]
Expand All @@ -47,17 +51,69 @@ pub fn accept_offer(
taker_mint: &Pubkey,
authority: &Pubkey,
token_program_id: &Pubkey,
is_native: bool,
maker_size: u64,
taker_size: u64,
bump_seed: u8,
) -> Instruction {
let init_data = StatelessOfferInstruction::AcceptOffer {
has_metadata: false,
maker_size,
taker_size,
bump_seed,
};
let data = init_data.try_to_vec().unwrap();
let mut accounts = vec![
AccountMeta::new_readonly(*maker_wallet, false),
AccountMeta::new_readonly(*taker_wallet, true),
AccountMeta::new(*maker_src_account, false),
AccountMeta::new(*maker_dst_account, false),
AccountMeta::new(*taker_src_account, false),
AccountMeta::new(*taker_dst_account, false),
AccountMeta::new_readonly(*maker_mint, false),
AccountMeta::new_readonly(*taker_mint, false),
AccountMeta::new_readonly(*authority, false),
AccountMeta::new_readonly(*token_program_id, false),
];
if is_native {
accounts.push(AccountMeta::new_readonly(system_program::id(), false));
}
Instruction {
program_id: *program_id,
accounts,
data,
}
}

/// Creates an 'initialize' instruction.
#[allow(clippy::too_many_arguments)]
pub fn accept_offer_with_metadata(
program_id: &Pubkey,
maker_wallet: &Pubkey,
taker_wallet: &Pubkey,
maker_src_account: &Pubkey,
maker_dst_account: &Pubkey,
taker_src_account: &Pubkey,
taker_dst_account: &Pubkey,
maker_mint: &Pubkey,
taker_mint: &Pubkey,
authority: &Pubkey,
token_program_id: &Pubkey,
metadata: &Pubkey,
creators: &[&Pubkey],
is_native: bool,
maker_size: u64,
taker_size: u64,
bump_seed: u8,
) -> Instruction {
let init_data = StatelessOfferInstruction::AcceptOffer {
has_metadata: true,
maker_size,
taker_size,
bump_seed,
};
let data = init_data.try_to_vec().unwrap();
let accounts = vec![
let mut accounts = vec![
AccountMeta::new_readonly(*maker_wallet, false),
AccountMeta::new_readonly(*taker_wallet, true),
AccountMeta::new(*maker_src_account, false),
Expand All @@ -69,6 +125,13 @@ pub fn accept_offer(
AccountMeta::new_readonly(*authority, false),
AccountMeta::new_readonly(*token_program_id, false),
];
if is_native {
accounts.push(AccountMeta::new_readonly(system_program::id(), false));
}
accounts.push(AccountMeta::new_readonly(*metadata, false));
for creator in creators.iter() {
accounts.push(AccountMeta::new(**creator, false));
}
Instruction {
program_id: *program_id,
accounts,
Expand Down
Loading

0 comments on commit c8963e8

Please sign in to comment.