@@ -34,13 +34,16 @@ pub fn delegate(args: TokenStream, input: TokenStream) -> TokenStream {
3434fn modify_component_module ( mut module : ItemMod , component_type : & Type ) -> ItemMod {
3535 let ( delegate_fn, delegate_struct) = generate_delegate ( component_type) ;
3636 let ( undelegate_fn, undelegate_struct) = generate_undelegate ( ) ;
37+ let ( allow_undelegate_fn, allow_undelegate_struct) = generate_allow_undelegate ( ) ;
3738 module. content = module. content . map ( |( brace, mut items) | {
3839 items. extend (
3940 vec ! [
4041 delegate_fn,
4142 delegate_struct,
4243 undelegate_fn,
4344 undelegate_struct,
45+ allow_undelegate_fn,
46+ allow_undelegate_struct,
4447 ]
4548 . into_iter ( )
4649 . map ( |item| syn:: parse2 ( item) . unwrap ( ) )
@@ -51,6 +54,47 @@ fn modify_component_module(mut module: ItemMod, component_type: &Type) -> ItemMo
5154 module
5255}
5356
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+
5498/// Generates the undelegate function and struct.
5599fn generate_undelegate ( ) -> ( TokenStream2 , TokenStream2 ) {
56100 (
@@ -63,7 +107,7 @@ fn generate_undelegate() -> (TokenStream2, TokenStream2) {
63107 & ctx. accounts. payer,
64108 & ctx. accounts. system_program,
65109 ] ;
66- undelegate_account(
110+ :: bolt_lang :: undelegate_account(
67111 delegated_account,
68112 & id( ) ,
69113 buffer,
@@ -77,7 +121,7 @@ fn generate_undelegate() -> (TokenStream2, TokenStream2) {
77121 quote ! {
78122 #[ automatically_derived]
79123 #[ derive( Accounts ) ]
80- pub struct InitializeAfterUndelegation <' info> {
124+ pub struct InitializeAfterUndelegation <' info> {
81125 /// CHECK:`
82126 #[ account( mut ) ]
83127 pub base_account: AccountInfo <' info>,
@@ -115,7 +159,7 @@ fn generate_delegate(component_type: &Type) -> (TokenStream2, TokenStream2) {
115159
116160 let pda_seeds: & [ & [ u8 ] ] = & [ <#component_type>:: seed( ) , & entity. key. to_bytes( ) ] ;
117161
118- delegate_account(
162+ :: bolt_lang :: delegate_account(
119163 payer,
120164 account,
121165 owner_program,
0 commit comments