This repository was archived by the owner on Mar 11, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -280,6 +280,27 @@ async fn test_cpi_guard_transfer() {
280
280
let alice_state = token_obj. get_account_info ( & alice. pubkey ( ) ) . await . unwrap ( ) ;
281
281
assert_eq ! ( alice_state. base. amount, amount) ;
282
282
283
+ // delegate-auth cpi transfer to self does not work
284
+ token_obj
285
+ . approve (
286
+ & alice. pubkey ( ) ,
287
+ & alice. pubkey ( ) ,
288
+ & alice. pubkey ( ) ,
289
+ 1 ,
290
+ & [ & alice] ,
291
+ )
292
+ . await
293
+ . unwrap ( ) ;
294
+
295
+ let error = token_obj
296
+ . process_ixs ( & [ mk_transfer ( alice. pubkey ( ) , do_checked) ] , & [ & alice] )
297
+ . await
298
+ . unwrap_err ( ) ;
299
+ assert_eq ! ( error, client_error( TokenError :: CpiGuardTransferBlocked ) ) ;
300
+
301
+ let alice_state = token_obj. get_account_info ( & alice. pubkey ( ) ) . await . unwrap ( ) ;
302
+ assert_eq ! ( alice_state. base. amount, amount) ;
303
+
283
304
// delegate-auth cpi transfer with cpi guard works
284
305
token_obj
285
306
. approve (
Original file line number Diff line number Diff line change @@ -402,6 +402,15 @@ impl Processor {
402
402
authority_info_data_len,
403
403
account_info_iter. as_slice ( ) ,
404
404
) ?;
405
+ if let Ok ( cpi_guard) = source_account. get_extension :: < CpiGuard > ( ) {
406
+ // If delegated to self, don't allow a transfer with CPI Guard
407
+ if delegate == source_account. base . owner
408
+ && cpi_guard. lock_cpi . into ( )
409
+ && in_cpi ( )
410
+ {
411
+ return Err ( TokenError :: CpiGuardTransferBlocked . into ( ) ) ;
412
+ }
413
+ }
405
414
let delegated_amount = u64:: from ( source_account. base . delegated_amount ) ;
406
415
if delegated_amount < amount {
407
416
return Err ( TokenError :: InsufficientFunds . into ( ) ) ;
You can’t perform that action at this time.
0 commit comments