@@ -818,19 +818,35 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
818
818
unreachable ! ( ) ;
819
819
} ;
820
820
821
- if maybe_token. is_sol ( ) && op == Operation :: Deposit {
822
- // Wrap SOL into wSOL
823
- instructions. extend ( vec ! [
824
- spl_associated_token_account:: instruction:: create_associated_token_account_idempotent(
825
- & address,
826
- & address,
827
- & token. mint( ) ,
828
- & spl_token:: id( ) ,
829
- ) ,
830
- system_instruction:: transfer( & address, & token. ata( & address) , amount) ,
831
- spl_token:: instruction:: sync_native( & spl_token:: id( ) , & token. ata( & address) ) . unwrap( ) ,
832
- ] ) ;
833
- required_compute_units += 20_000 ;
821
+ match op {
822
+ Operation :: Deposit => {
823
+ if maybe_token. is_sol ( ) {
824
+ // Wrap SOL into wSOL
825
+ instructions. extend ( vec ! [
826
+ spl_associated_token_account:: instruction:: create_associated_token_account_idempotent(
827
+ & address,
828
+ & address,
829
+ & token. mint( ) ,
830
+ & spl_token:: id( ) ,
831
+ ) ,
832
+ system_instruction:: transfer( & address, & token. ata( & address) , amount) ,
833
+ spl_token:: instruction:: sync_native( & spl_token:: id( ) , & token. ata( & address) ) . unwrap( ) ,
834
+ ] ) ;
835
+ required_compute_units += 20_000 ;
836
+ }
837
+ }
838
+ Operation :: Withdraw => {
839
+ // Ensure the destination token account exists
840
+ instructions. push (
841
+ spl_associated_token_account:: instruction:: create_associated_token_account_idempotent (
842
+ & address,
843
+ & address,
844
+ & token. mint ( ) ,
845
+ & spl_token:: id ( ) ,
846
+ ) ,
847
+ ) ;
848
+ required_compute_units += 25_000 ;
849
+ }
834
850
}
835
851
836
852
instructions. extend ( result. instructions ) ;
@@ -960,6 +976,14 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
960
976
return Err ( format ! ( "Simulation failure: {simulation_result:?}" ) . into ( ) ) ;
961
977
}
962
978
979
+ /*
980
+ println!(
981
+ "Transaction paid for {} extra additional compute units",
982
+ required_compute_units as u64
983
+ - simulation_result.units_consumed.unwrap_or_default()
984
+ );
985
+ */
986
+
963
987
let signature = transaction. signatures [ 0 ] ;
964
988
965
989
let msg = match cmd {
0 commit comments