@@ -780,13 +780,6 @@ pub mod pallet {
780
780
who. clone ( ) ,
781
781
pool_info. basepool . pid ,
782
782
) ?;
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 ;
790
783
let in_queue_shares = match pool_info
791
784
. basepool
792
785
. withdraw_queue
@@ -803,10 +796,33 @@ pub mod pallet {
803
796
}
804
797
None => Zero :: zero ( ) ,
805
798
} ;
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 ;
806
816
ensure ! (
807
817
base_pool:: is_nondust_balance( shares) && ( shares <= nft. shares + in_queue_shares) ,
808
818
Error :: <T >:: InvalidWithdrawalAmount
809
819
) ;
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
+ }
810
826
base_pool:: Pallet :: < T > :: try_withdraw (
811
827
& mut pool_info. basepool ,
812
828
nft,
0 commit comments