@@ -357,7 +357,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
357
357
. help ( "Wallet" ) ,
358
358
)
359
359
. arg (
360
- Arg :: with_name ( "amount " )
360
+ Arg :: with_name ( "ui_amount " )
361
361
. value_name ( "AMOUNT" )
362
362
. takes_value ( true )
363
363
. validator ( is_amount_or_all)
@@ -410,7 +410,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
410
410
. help ( "Wallet" ) ,
411
411
)
412
412
. arg (
413
- Arg :: with_name ( "amount " )
413
+ Arg :: with_name ( "ui_amount " )
414
414
. value_name ( "AMOUNT" )
415
415
. takes_value ( true )
416
416
. validator ( is_amount_or_all)
@@ -456,7 +456,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
456
456
. help ( "Wallet" ) ,
457
457
)
458
458
. arg (
459
- Arg :: with_name ( "amount " )
459
+ Arg :: with_name ( "ui_amount " )
460
460
. value_name ( "AMOUNT" )
461
461
. takes_value ( true )
462
462
. validator ( is_amount_or_all)
@@ -792,7 +792,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
792
792
let minimum_apy_bps = value_t ! ( matches, "minimum_apy" , u16 ) . unwrap_or ( 0 ) ;
793
793
794
794
let token_balance = maybe_token. balance ( rpc_client, & address) ?;
795
- let amount = match matches. value_of ( "amount " ) . unwrap ( ) {
795
+ let requested_amount = match matches. value_of ( "ui_amount " ) . unwrap ( ) {
796
796
"ALL" => {
797
797
if cmd == Command :: Deposit {
798
798
token_balance. saturating_sub ( if maybe_token. is_sol ( ) {
@@ -804,24 +804,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
804
804
u64:: MAX
805
805
}
806
806
}
807
- amount => token. amount ( amount . parse :: < f64 > ( ) . unwrap ( ) ) ,
807
+ ui_amount => token. amount ( ui_amount . parse :: < f64 > ( ) . unwrap ( ) ) ,
808
808
} ;
809
809
810
- if cmd == Command :: Deposit {
811
- if amount > token_balance {
812
- return Err ( format ! (
813
- "Deposit amount of {} is greater than current balance of {}" ,
814
- maybe_token. format_amount( amount) ,
815
- maybe_token. format_amount( token_balance) ,
816
- )
817
- . into ( ) ) ;
818
- }
819
- if amount == 0 {
820
- println ! ( "Nothing to deposit" ) ;
821
- return Ok ( ( ) ) ;
822
- }
823
- }
824
-
825
810
is_token_supported ( & token, & pools) ?;
826
811
827
812
let supply_balance = pools
@@ -872,48 +857,66 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
872
857
// Deposit pool has the highest APR
873
858
let deposit_pool = pools. last ( ) . ok_or ( "No available pool" ) ?;
874
859
875
- // Withdraw pool has the lowest APR and a balance >= the requested `amount `
860
+ // Withdraw pool has the lowest APR and a balance >= `requested_amount `
876
861
let withdraw_pool = pools
877
862
. iter ( )
878
863
. find ( |pool| {
879
864
let balance = * supply_balance. get ( * pool) . unwrap ( ) ;
880
865
881
- if amount == u64:: MAX {
866
+ if requested_amount == u64:: MAX {
882
867
balance > 1 // Solend/Kamino leave 1 in sometimes :-/
883
868
} else {
884
- balance >= amount
869
+ balance >= requested_amount
885
870
}
886
871
} )
887
872
. unwrap_or ( deposit_pool) ;
888
873
889
- let ops = match cmd {
874
+ let ( ops, mut amount ) = match cmd {
890
875
Command :: Deposit => {
891
- vec ! [ ( Operation :: Deposit , deposit_pool) ]
876
+ if requested_amount > token_balance {
877
+ return Err ( format ! (
878
+ "Deposit amount of {} is greater than current balance of {}" ,
879
+ maybe_token. format_amount( requested_amount) ,
880
+ maybe_token. format_amount( token_balance) ,
881
+ )
882
+ . into ( ) ) ;
883
+ }
884
+ if requested_amount == 0 {
885
+ println ! ( "Nothing to deposit" ) ;
886
+ return Ok ( ( ) ) ;
887
+ }
888
+
889
+ ( vec ! [ ( Operation :: Deposit , deposit_pool) ] , requested_amount)
892
890
}
893
- Command :: Withdraw => vec ! [ ( Operation :: Withdraw , withdraw_pool) ] ,
894
- Command :: Rebalance => {
895
- if withdraw_pool == deposit_pool {
896
- println ! ( "Nothing to rebalance" ) ;
891
+ Command :: Withdraw | Command :: Rebalance => {
892
+ let mut requested_amount = requested_amount;
893
+ if requested_amount == u64:: MAX {
894
+ requested_amount = * supply_balance. get ( withdraw_pool) . unwrap ( ) ;
895
+ }
896
+
897
+ if requested_amount == 0 {
898
+ println ! ( "Nothing to withdraw" ) ;
897
899
return Ok ( ( ) ) ;
898
900
}
899
901
900
- vec ! [
901
- ( Operation :: Withdraw , withdraw_pool) ,
902
- ( Operation :: Deposit , deposit_pool) ,
903
- ]
902
+ (
903
+ if cmd == Command :: Withdraw {
904
+ vec ! [ ( Operation :: Withdraw , withdraw_pool) ]
905
+ } else {
906
+ vec ! [
907
+ ( Operation :: Withdraw , withdraw_pool) ,
908
+ ( Operation :: Deposit , deposit_pool) ,
909
+ ]
910
+ } ,
911
+ requested_amount,
912
+ )
904
913
}
905
914
} ;
906
915
907
916
let mut instructions = vec ! [ ] ;
908
917
let mut address_lookup_tables = vec ! [ ] ;
909
918
let mut required_compute_units = 0 ;
910
- let mut amount = amount;
911
919
for ( op, pool) in ops {
912
- if amount == u64:: MAX {
913
- assert_eq ! ( op, Operation :: Withdraw ) ;
914
- amount = * supply_balance. get ( withdraw_pool) . unwrap ( ) ;
915
- }
916
-
917
920
let result = if pool. starts_with ( "kamino-" ) {
918
921
kamino_deposit_or_withdraw (
919
922
op,
0 commit comments