1
1
//! Instruction types
2
+
2
3
use {
3
4
borsh:: { BorshDeserialize , BorshSchema , BorshSerialize } ,
4
5
solana_program:: {
5
6
instruction:: { AccountMeta , Instruction } ,
6
7
pubkey:: Pubkey ,
8
+ system_program,
7
9
} ,
8
10
} ;
9
11
@@ -24,6 +26,8 @@ pub enum StatelessOfferInstruction {
24
26
/// Bob (or anyone) executes AcceptOffer
25
27
///
26
28
AcceptOffer {
29
+ #[ allow( dead_code) ]
30
+ has_metadata : bool ,
27
31
#[ allow( dead_code) ]
28
32
maker_size : u64 ,
29
33
#[ allow( dead_code) ]
@@ -47,17 +51,69 @@ pub fn accept_offer(
47
51
taker_mint : & Pubkey ,
48
52
authority : & Pubkey ,
49
53
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 ,
50
105
maker_size : u64 ,
51
106
taker_size : u64 ,
52
107
bump_seed : u8 ,
53
108
) -> Instruction {
54
109
let init_data = StatelessOfferInstruction :: AcceptOffer {
110
+ has_metadata : true ,
55
111
maker_size,
56
112
taker_size,
57
113
bump_seed,
58
114
} ;
59
115
let data = init_data. try_to_vec ( ) . unwrap ( ) ;
60
- let accounts = vec ! [
116
+ let mut accounts = vec ! [
61
117
AccountMeta :: new_readonly( * maker_wallet, false ) ,
62
118
AccountMeta :: new_readonly( * taker_wallet, true ) ,
63
119
AccountMeta :: new( * maker_src_account, false ) ,
@@ -69,6 +125,13 @@ pub fn accept_offer(
69
125
AccountMeta :: new_readonly( * authority, false ) ,
70
126
AccountMeta :: new_readonly( * token_program_id, false ) ,
71
127
] ;
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
+ }
72
135
Instruction {
73
136
program_id : * program_id,
74
137
accounts,
0 commit comments