Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit c8963e8

Browse files
authored
Updating Stateless Offer to Optionally Include Fees (#2507)
* 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)
1 parent ef72e56 commit c8963e8

File tree

5 files changed

+328
-49
lines changed

5 files changed

+328
-49
lines changed

Cargo.lock

Lines changed: 31 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

stateless-asks/program/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ borsh = "0.9.1"
1515
solana-program = "1.8.0"
1616
spl-token = { version = "3.2", path = "../../token/program", features = ["no-entrypoint"] }
1717
spl-associated-token-account = {version = "1.0.3", features = ["no-entrypoint"]}
18+
metaplex-token-metadata = { version = "0.0.1", features = ["no-entrypoint"] }
1819
thiserror = "1.0"
1920

2021
[dev-dependencies]

stateless-asks/program/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ pub enum UtilError {
1818
StatementFalse,
1919
#[error("NotRentExempt")]
2020
NotRentExempt,
21+
#[error("NumericalOverflow")]
22+
NumericalOverflow,
2123
}
2224

2325
impl From<UtilError> for ProgramError {

stateless-asks/program/src/instruction.rs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
//! Instruction types
2+
23
use {
34
borsh::{BorshDeserialize, BorshSchema, BorshSerialize},
45
solana_program::{
56
instruction::{AccountMeta, Instruction},
67
pubkey::Pubkey,
8+
system_program,
79
},
810
};
911

@@ -24,6 +26,8 @@ pub enum StatelessOfferInstruction {
2426
/// Bob (or anyone) executes AcceptOffer
2527
///
2628
AcceptOffer {
29+
#[allow(dead_code)]
30+
has_metadata: bool,
2731
#[allow(dead_code)]
2832
maker_size: u64,
2933
#[allow(dead_code)]
@@ -47,17 +51,69 @@ pub fn accept_offer(
4751
taker_mint: &Pubkey,
4852
authority: &Pubkey,
4953
token_program_id: &Pubkey,
54+
is_native: bool,
55+
maker_size: u64,
56+
taker_size: u64,
57+
bump_seed: u8,
58+
) -> Instruction {
59+
let init_data = StatelessOfferInstruction::AcceptOffer {
60+
has_metadata: false,
61+
maker_size,
62+
taker_size,
63+
bump_seed,
64+
};
65+
let data = init_data.try_to_vec().unwrap();
66+
let mut accounts = vec![
67+
AccountMeta::new_readonly(*maker_wallet, false),
68+
AccountMeta::new_readonly(*taker_wallet, true),
69+
AccountMeta::new(*maker_src_account, false),
70+
AccountMeta::new(*maker_dst_account, false),
71+
AccountMeta::new(*taker_src_account, false),
72+
AccountMeta::new(*taker_dst_account, false),
73+
AccountMeta::new_readonly(*maker_mint, false),
74+
AccountMeta::new_readonly(*taker_mint, false),
75+
AccountMeta::new_readonly(*authority, false),
76+
AccountMeta::new_readonly(*token_program_id, false),
77+
];
78+
if is_native {
79+
accounts.push(AccountMeta::new_readonly(system_program::id(), false));
80+
}
81+
Instruction {
82+
program_id: *program_id,
83+
accounts,
84+
data,
85+
}
86+
}
87+
88+
/// Creates an 'initialize' instruction.
89+
#[allow(clippy::too_many_arguments)]
90+
pub fn accept_offer_with_metadata(
91+
program_id: &Pubkey,
92+
maker_wallet: &Pubkey,
93+
taker_wallet: &Pubkey,
94+
maker_src_account: &Pubkey,
95+
maker_dst_account: &Pubkey,
96+
taker_src_account: &Pubkey,
97+
taker_dst_account: &Pubkey,
98+
maker_mint: &Pubkey,
99+
taker_mint: &Pubkey,
100+
authority: &Pubkey,
101+
token_program_id: &Pubkey,
102+
metadata: &Pubkey,
103+
creators: &[&Pubkey],
104+
is_native: bool,
50105
maker_size: u64,
51106
taker_size: u64,
52107
bump_seed: u8,
53108
) -> Instruction {
54109
let init_data = StatelessOfferInstruction::AcceptOffer {
110+
has_metadata: true,
55111
maker_size,
56112
taker_size,
57113
bump_seed,
58114
};
59115
let data = init_data.try_to_vec().unwrap();
60-
let accounts = vec![
116+
let mut accounts = vec![
61117
AccountMeta::new_readonly(*maker_wallet, false),
62118
AccountMeta::new_readonly(*taker_wallet, true),
63119
AccountMeta::new(*maker_src_account, false),
@@ -69,6 +125,13 @@ pub fn accept_offer(
69125
AccountMeta::new_readonly(*authority, false),
70126
AccountMeta::new_readonly(*token_program_id, false),
71127
];
128+
if is_native {
129+
accounts.push(AccountMeta::new_readonly(system_program::id(), false));
130+
}
131+
accounts.push(AccountMeta::new_readonly(*metadata, false));
132+
for creator in creators.iter() {
133+
accounts.push(AccountMeta::new(**creator, false));
134+
}
72135
Instruction {
73136
program_id: *program_id,
74137
accounts,

0 commit comments

Comments
 (0)