@@ -1929,7 +1929,14 @@ async fn process_account_cost_basis(
1929
1929
}
1930
1930
1931
1931
fn print_current_holdings (
1932
- held_tokens : & BTreeMap :: < MaybeToken , ( /*price*/ Option < Decimal > , /*amount*/ u64 , RealizedGain ) > ,
1932
+ held_tokens : & BTreeMap <
1933
+ MaybeToken ,
1934
+ (
1935
+ /*price*/ Option < Decimal > ,
1936
+ /*amount*/ u64 ,
1937
+ RealizedGain ,
1938
+ ) ,
1939
+ > ,
1933
1940
tax_rate : Option < & TaxRate > ,
1934
1941
) {
1935
1942
println ! ( "Current Holdings" ) ;
@@ -1957,8 +1964,7 @@ fn print_current_holdings(
1957
1964
. collect :: < Vec < _ > > ( ) ;
1958
1965
1959
1966
// Order current holdings by `total_value`
1960
- held_tokens
1961
- . sort_unstable_by ( |a, b| b. 1 . partial_cmp ( & a. 1 ) . unwrap_or ( std:: cmp:: Ordering :: Equal ) ) ;
1967
+ held_tokens. sort_unstable_by ( |a, b| b. 1 . partial_cmp ( & a. 1 ) . unwrap_or ( std:: cmp:: Ordering :: Equal ) ) ;
1962
1968
1963
1969
for ( held_token, total_value, current_token_price, total_held_amount, unrealized_gain) in
1964
1970
held_tokens
@@ -2017,7 +2023,11 @@ fn print_current_holdings(
2017
2023
println ! ( ) ;
2018
2024
}
2019
2025
2020
- fn merge_lots ( db : & mut Db , account_filter : Option < Pubkey > , verbose : bool ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
2026
+ fn merge_lots (
2027
+ db : & mut Db ,
2028
+ account_filter : Option < Pubkey > ,
2029
+ verbose : bool ,
2030
+ ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
2021
2031
let mut accounts = db. get_accounts ( ) ;
2022
2032
accounts. sort_by ( |a, b| {
2023
2033
let mut result = a. last_update_balance . cmp ( & b. last_update_balance ) ;
@@ -2049,17 +2059,15 @@ fn merge_lots(db: &mut Db, account_filter: Option<Pubkey>, verbose: bool) -> Res
2049
2059
let this_lot = account. lots . get_mut ( lot_num) . unwrap ( ) ;
2050
2060
let this_price = this_lot. acquisition . price ( ) ;
2051
2061
let this_lot_number = this_lot. lot_number ;
2052
- if this_lot. acquisition . when == next_lot. acquisition . when
2053
- && this_price == next_price {
2054
- this_lot. amount += next_lot. amount ;
2055
- account. lots . remove ( lot_num + 1 ) ;
2056
- if verbose {
2057
- println ! (
2058
- "merged lot {} into lot {}" ,
2059
- next_lot_number,
2060
- this_lot_number,
2061
- ) ;
2062
- }
2062
+ if this_lot. acquisition . when == next_lot. acquisition . when && this_price == next_price {
2063
+ this_lot. amount += next_lot. amount ;
2064
+ account. lots . remove ( lot_num + 1 ) ;
2065
+ if verbose {
2066
+ println ! (
2067
+ "merged lot {} into lot {}" ,
2068
+ next_lot_number, this_lot_number,
2069
+ ) ;
2070
+ }
2063
2071
} else {
2064
2072
lot_num += 1 ;
2065
2073
}
@@ -2083,19 +2091,19 @@ fn merge_lots(db: &mut Db, account_filter: Option<Pubkey>, verbose: bool) -> Res
2083
2091
if this_lot. when == next_lot. when
2084
2092
&& this_price == next_price
2085
2093
&& this_lot_acq_when == next_lot_acq_when
2086
- && this_lot_acq_price == next_lot_acq_price {
2087
- this_lot. lot . amount += next_lot. lot . amount ;
2088
- disposed_lots. remove ( lot_num + 1 ) ;
2089
- if verbose {
2090
- println ! (
2091
- "merged disposed lot {} into disposed lot {}" ,
2092
- next_lot_number,
2093
- this_lot_number,
2094
- ) ;
2095
- }
2096
- } else {
2097
- lot_num += 1 ;
2094
+ && this_lot_acq_price == next_lot_acq_price
2095
+ {
2096
+ this_lot. lot . amount += next_lot. lot . amount ;
2097
+ disposed_lots. remove ( lot_num + 1 ) ;
2098
+ if verbose {
2099
+ println ! (
2100
+ "merged disposed lot {} into disposed lot {}" ,
2101
+ next_lot_number, this_lot_number,
2102
+ ) ;
2098
2103
}
2104
+ } else {
2105
+ lot_num += 1 ;
2106
+ }
2099
2107
}
2100
2108
db. update_disposed_lots ( disposed_lots) ?;
2101
2109
}
@@ -2215,10 +2223,10 @@ async fn process_account_list(
2215
2223
for lot in account. lots . iter ( ) {
2216
2224
let value = current_token_price. map ( |price| {
2217
2225
f64:: try_from (
2218
- Decimal :: from_f64 (
2219
- account . token . ui_amount ( lot . amount )
2220
- ) . unwrap ( ) * price
2221
- ) . unwrap ( )
2226
+ Decimal :: from_f64 ( account . token . ui_amount ( lot . amount ) ) . unwrap ( )
2227
+ * price ,
2228
+ )
2229
+ . unwrap ( )
2222
2230
} ) ;
2223
2231
account_basis += lot. basis ( account. token ) ;
2224
2232
account_value += value. unwrap_or_default ( ) ;
@@ -2402,7 +2410,7 @@ async fn process_account_list(
2402
2410
( ( ( total_current_value - total_current_fiat_value) - total_current_basis)
2403
2411
/ total_current_basis
2404
2412
* 100. )
2405
- . separated_string_with_fixed_place( 2 ) ,
2413
+ . separated_string_with_fixed_place( 2 ) ,
2406
2414
) ;
2407
2415
}
2408
2416
if account_filter. is_some ( ) || summary_only {
@@ -2856,7 +2864,7 @@ async fn process_account_csv(
2856
2864
// Exclude disposed lots that were neither acquired nor disposed of in the filter year
2857
2865
disposed_lots. retain ( |disposed_lot| {
2858
2866
( disposed_lot. lot . acquisition . when . year ( ) == year
2859
- && disposed_lot. lot . income ( disposed_lot. token ) > 0. )
2867
+ && disposed_lot. lot . income ( disposed_lot. token ) > 0. )
2860
2868
|| disposed_lot. when . year ( ) == year
2861
2869
} )
2862
2870
}
@@ -2870,7 +2878,7 @@ async fn process_account_csv(
2870
2878
"Sale Date" ,
2871
2879
"Sale Proceedings (USD)" ,
2872
2880
"Acquisition Description" ,
2873
- "Sale Description"
2881
+ "Sale Description" ,
2874
2882
] ) ?;
2875
2883
2876
2884
for disposed_lot in disposed_lots {
@@ -2881,20 +2889,30 @@ async fn process_account_csv(
2881
2889
}
2882
2890
}
2883
2891
let cost = Decimal :: from_u64 ( disposed_lot. lot . amount ) . unwrap ( )
2884
- * disposed_lot. lot . acquisition . price ( ) / Decimal :: from_f64 ( 1e9 ) . unwrap ( ) ;
2892
+ * disposed_lot. lot . acquisition . price ( )
2893
+ / Decimal :: from_f64 ( 1e9 ) . unwrap ( ) ;
2885
2894
let proceedings = Decimal :: from_u64 ( disposed_lot. lot . amount ) . unwrap ( )
2886
- * disposed_lot. price ( ) / Decimal :: from_f64 ( 1e9 ) . unwrap ( ) ;
2895
+ * disposed_lot. price ( )
2896
+ / Decimal :: from_f64 ( 1e9 ) . unwrap ( ) ;
2887
2897
wtr. write_record ( & [
2888
2898
disposed_lot. token . to_string ( ) ,
2889
- format ! ( "{:.9}" , disposed_lot. token. ui_amount( disposed_lot. lot. amount) ) ,
2899
+ format ! (
2900
+ "{:.9}" ,
2901
+ disposed_lot. token. ui_amount( disposed_lot. lot. amount)
2902
+ ) ,
2890
2903
format ! ( "{:.9}" , income) ,
2891
- format ! ( "{:.9}" , disposed_lot. lot. cap_gain( disposed_lot. token, disposed_lot. price( ) ) ) ,
2904
+ format ! (
2905
+ "{:.9}" ,
2906
+ disposed_lot
2907
+ . lot
2908
+ . cap_gain( disposed_lot. token, disposed_lot. price( ) )
2909
+ ) ,
2892
2910
disposed_lot. lot . acquisition . when . to_string ( ) ,
2893
2911
format ! ( "{:.9}" , cost) ,
2894
2912
disposed_lot. when . to_string ( ) ,
2895
2913
format ! ( "{:.9}" , proceedings) ,
2896
2914
disposed_lot. lot . acquisition . kind . to_string ( ) ,
2897
- disposed_lot. kind . to_string ( )
2915
+ disposed_lot. kind . to_string ( ) ,
2898
2916
] ) ?;
2899
2917
}
2900
2918
0 commit comments