@@ -780,13 +780,6 @@ pub mod pallet {
780780 who. clone ( ) ,
781781 pool_info. basepool . pid ,
782782 ) ?;
783- let nft_id = maybe_nft_id. ok_or ( Error :: < T > :: NoNftToWithdraw ) ?;
784- // The nft instance must be wrote to Nft storage at the end of the function
785- // this nft's property shouldn't be accessed or wrote again from storage before set_nft_attr
786- // is called. Or the property of the nft will be overwrote incorrectly.
787- let mut nft_guard =
788- base_pool:: Pallet :: < T > :: get_nft_attr_guard ( pool_info. basepool . cid , nft_id) ?;
789- let nft = & mut nft_guard. attr ;
790783 let in_queue_shares = match pool_info
791784 . basepool
792785 . withdraw_queue
@@ -803,10 +796,33 @@ pub mod pallet {
803796 }
804797 None => Zero :: zero ( ) ,
805798 } ;
799+ ensure ! ( maybe_nft_id. is_some( ) || in_queue_shares > Zero :: zero( ) , Error :: <T >:: NoNftToWithdraw ) ;
800+ let nft_id = match maybe_nft_id {
801+ Some ( nft_id) => nft_id,
802+ // An nft is necessary to initiate a smaller withdrawal
803+ None => base_pool:: Pallet :: < T > :: mint_nft (
804+ pool_info. basepool . cid ,
805+ who. clone ( ) ,
806+ Zero :: zero ( ) ,
807+ pool_info. basepool . pid ,
808+ ) ?,
809+ } ;
810+ // The nft instance must be wrote to Nft storage at the end of the function
811+ // this nft's property shouldn't be accessed or wrote again from storage before set_nft_attr
812+ // is called. Or the property of the nft will be overwrote incorrectly.
813+ let mut nft_guard =
814+ base_pool:: Pallet :: < T > :: get_nft_attr_guard ( pool_info. basepool . cid , nft_id) ?;
815+ let nft = & mut nft_guard. attr ;
806816 ensure ! (
807817 base_pool:: is_nondust_balance( shares) && ( shares <= nft. shares + in_queue_shares) ,
808818 Error :: <T >:: InvalidWithdrawalAmount
809819 ) ;
820+ if let Some ( vault_pid) = as_vault {
821+ let mut vault_info = ensure_vault :: < T > ( vault_pid) ?;
822+ if !vault_info. invest_pools . contains ( & pid) {
823+ vault_info. invest_pools . push ( pid) ;
824+ }
825+ }
810826 base_pool:: Pallet :: < T > :: try_withdraw (
811827 & mut pool_info. basepool ,
812828 nft,
0 commit comments