@@ -34,13 +34,16 @@ pub fn delegate(args: TokenStream, input: TokenStream) -> TokenStream {
34
34
fn modify_component_module ( mut module : ItemMod , component_type : & Type ) -> ItemMod {
35
35
let ( delegate_fn, delegate_struct) = generate_delegate ( component_type) ;
36
36
let ( undelegate_fn, undelegate_struct) = generate_undelegate ( ) ;
37
+ let ( allow_undelegate_fn, allow_undelegate_struct) = generate_allow_undelegate ( ) ;
37
38
module. content = module. content . map ( |( brace, mut items) | {
38
39
items. extend (
39
40
vec ! [
40
41
delegate_fn,
41
42
delegate_struct,
42
43
undelegate_fn,
43
44
undelegate_struct,
45
+ allow_undelegate_fn,
46
+ allow_undelegate_struct,
44
47
]
45
48
. into_iter ( )
46
49
. map ( |item| syn:: parse2 ( item) . unwrap ( ) )
@@ -51,6 +54,47 @@ fn modify_component_module(mut module: ItemMod, component_type: &Type) -> ItemMo
51
54
module
52
55
}
53
56
57
+ /// Generates the allow_undelegate function and struct.
58
+ fn generate_allow_undelegate ( ) -> ( TokenStream2 , TokenStream2 ) {
59
+ (
60
+ quote ! {
61
+ #[ automatically_derived]
62
+ pub fn allow_undelegation( ctx: Context <AllowUndelegation >) -> Result <( ) > {
63
+ :: bolt_lang:: allow_undelegation(
64
+ & ctx. accounts. base_account,
65
+ & ctx. accounts. delegation_record,
66
+ & ctx. accounts. delegation_metadata,
67
+ & ctx. accounts. buffer,
68
+ & ctx. accounts. delegation_program,
69
+ & id( ) ,
70
+ ) ?;
71
+ Ok ( ( ) )
72
+ }
73
+ } ,
74
+ quote ! {
75
+ #[ automatically_derived]
76
+ #[ derive( Accounts ) ]
77
+ pub struct AllowUndelegation <' info> {
78
+ #[ account( ) ]
79
+ /// CHECK: The delegated component
80
+ pub base_account: AccountInfo <' info>,
81
+ #[ account( ) ]
82
+ /// CHECK: delegation record
83
+ pub delegation_record: AccountInfo <' info>,
84
+ #[ account( mut ) ]
85
+ /// CHECK: delegation metadata
86
+ pub delegation_metadata: AccountInfo <' info>,
87
+ #[ account( ) ]
88
+ /// CHECK: singer buffer to enforce CPI
89
+ pub buffer: AccountInfo <' info>,
90
+ #[ account( ) ]
91
+ /// CHECK:`
92
+ pub delegation_program: AccountInfo <' info>,
93
+ }
94
+ } ,
95
+ )
96
+ }
97
+
54
98
/// Generates the undelegate function and struct.
55
99
fn generate_undelegate ( ) -> ( TokenStream2 , TokenStream2 ) {
56
100
(
@@ -63,7 +107,7 @@ fn generate_undelegate() -> (TokenStream2, TokenStream2) {
63
107
& ctx. accounts. payer,
64
108
& ctx. accounts. system_program,
65
109
] ;
66
- undelegate_account(
110
+ :: bolt_lang :: undelegate_account(
67
111
delegated_account,
68
112
& id( ) ,
69
113
buffer,
@@ -77,7 +121,7 @@ fn generate_undelegate() -> (TokenStream2, TokenStream2) {
77
121
quote ! {
78
122
#[ automatically_derived]
79
123
#[ derive( Accounts ) ]
80
- pub struct InitializeAfterUndelegation <' info> {
124
+ pub struct InitializeAfterUndelegation <' info> {
81
125
/// CHECK:`
82
126
#[ account( mut ) ]
83
127
pub base_account: AccountInfo <' info>,
@@ -115,7 +159,7 @@ fn generate_delegate(component_type: &Type) -> (TokenStream2, TokenStream2) {
115
159
116
160
let pda_seeds: & [ & [ u8 ] ] = & [ <#component_type>:: seed( ) , & entity. key. to_bytes( ) ] ;
117
161
118
- delegate_account(
162
+ :: bolt_lang :: delegate_account(
119
163
payer,
120
164
account,
121
165
owner_program,
0 commit comments