10
10
keypair:: signer_from_path,
11
11
} ,
12
12
solana_client:: rpc_client:: RpcClient ,
13
- solana_program:: { native_token:: lamports_to_sol, program_pack:: Pack , pubkey:: Pubkey } ,
13
+ solana_program:: {
14
+ message:: Message , native_token:: lamports_to_sol, program_pack:: Pack , pubkey:: Pubkey ,
15
+ } ,
14
16
solana_sdk:: {
15
17
commitment_config:: CommitmentConfig ,
16
18
signature:: { Keypair , Signer } ,
@@ -824,7 +826,9 @@ fn command_create_lending_market(
824
826
. rpc_client
825
827
. get_minimum_balance_for_rent_exemption ( LendingMarket :: LEN ) ?;
826
828
827
- let mut transaction = Transaction :: new_with_payer (
829
+ let recent_blockhash = config. rpc_client . get_latest_blockhash ( ) ?;
830
+
831
+ let message = Message :: new_with_blockhash (
828
832
& [
829
833
// Account for the lending market
830
834
create_account (
@@ -845,15 +849,17 @@ fn command_create_lending_market(
845
849
) ,
846
850
] ,
847
851
Some ( & config. fee_payer . pubkey ( ) ) ,
852
+ & recent_blockhash,
848
853
) ;
849
854
850
- let ( recent_blockhash, fee_calculator) = config. rpc_client . get_recent_blockhash ( ) ?;
851
855
check_fee_payer_balance (
852
856
config,
853
- lending_market_balance + fee_calculator . calculate_fee ( transaction . message ( ) ) ,
857
+ lending_market_balance + config . rpc_client . get_fee_for_message ( & message ) ? ,
854
858
) ?;
855
- transaction. sign (
859
+
860
+ let transaction = Transaction :: new (
856
861
& vec ! [ config. fee_payer. as_ref( ) , & lending_market_keypair] ,
862
+ message,
857
863
recent_blockhash,
858
864
) ;
859
865
send_transaction ( config, transaction) ?;
@@ -939,8 +945,9 @@ fn command_add_reserve(
939
945
+ user_collateral_balance
940
946
+ liquidity_supply_balance
941
947
+ liquidity_fee_receiver_balance;
948
+ let recent_blockhash = config. rpc_client . get_latest_blockhash ( ) ?;
942
949
943
- let mut transaction_1 = Transaction :: new_with_payer (
950
+ let message_1 = Message :: new_with_blockhash (
944
951
& [
945
952
create_account (
946
953
& config. fee_payer . pubkey ( ) ,
@@ -972,9 +979,10 @@ fn command_add_reserve(
972
979
) ,
973
980
] ,
974
981
Some ( & config. fee_payer . pubkey ( ) ) ,
982
+ & recent_blockhash,
975
983
) ;
976
984
977
- let mut transaction_2 = Transaction :: new_with_payer (
985
+ let message_2 = Message :: new_with_blockhash (
978
986
& [
979
987
create_account (
980
988
& config. fee_payer . pubkey ( ) ,
@@ -992,9 +1000,10 @@ fn command_add_reserve(
992
1000
) ,
993
1001
] ,
994
1002
Some ( & config. fee_payer . pubkey ( ) ) ,
1003
+ & recent_blockhash,
995
1004
) ;
996
1005
997
- let mut transaction_3 = Transaction :: new_with_payer (
1006
+ let message_3 = Message :: new_with_blockhash (
998
1007
& [
999
1008
approve (
1000
1009
& spl_token:: id ( ) ,
@@ -1032,45 +1041,49 @@ fn command_add_reserve(
1032
1041
. unwrap ( ) ,
1033
1042
] ,
1034
1043
Some ( & config. fee_payer . pubkey ( ) ) ,
1044
+ & recent_blockhash,
1035
1045
) ;
1036
1046
1037
- let ( recent_blockhash, fee_calculator) = config. rpc_client . get_recent_blockhash ( ) ?;
1038
1047
check_fee_payer_balance (
1039
1048
config,
1040
1049
total_balance
1041
- + fee_calculator . calculate_fee ( transaction_1 . message ( ) )
1042
- + fee_calculator . calculate_fee ( transaction_2 . message ( ) )
1043
- + fee_calculator . calculate_fee ( transaction_3 . message ( ) ) ,
1050
+ + config . rpc_client . get_fee_for_message ( & message_1 ) ?
1051
+ + config . rpc_client . get_fee_for_message ( & message_2 ) ?
1052
+ + config . rpc_client . get_fee_for_message ( & message_3 ) ? ,
1044
1053
) ?;
1045
- transaction_1. sign (
1054
+
1055
+ let transaction_1 = Transaction :: new (
1046
1056
& vec ! [
1047
1057
config. fee_payer. as_ref( ) ,
1048
1058
& reserve_keypair,
1049
1059
& collateral_mint_keypair,
1050
1060
& collateral_supply_keypair,
1051
1061
& user_collateral_keypair,
1052
1062
] ,
1063
+ message_1,
1053
1064
recent_blockhash,
1054
1065
) ;
1055
- transaction_2. sign (
1066
+ send_transaction ( config, transaction_1) ?;
1067
+ let transaction_2 = Transaction :: new (
1056
1068
& vec ! [
1057
1069
config. fee_payer. as_ref( ) ,
1058
1070
& liquidity_supply_keypair,
1059
1071
& liquidity_fee_receiver_keypair,
1060
1072
] ,
1073
+ message_2,
1061
1074
recent_blockhash,
1062
1075
) ;
1063
- transaction_3. sign (
1076
+ send_transaction ( config, transaction_2) ?;
1077
+ let transaction_3 = Transaction :: new (
1064
1078
& vec ! [
1065
1079
config. fee_payer. as_ref( ) ,
1066
1080
& source_liquidity_owner_keypair,
1067
1081
& lending_market_owner_keypair,
1068
1082
& user_transfer_authority_keypair,
1069
1083
] ,
1084
+ message_3,
1070
1085
recent_blockhash,
1071
1086
) ;
1072
- send_transaction ( config, transaction_1) ?;
1073
- send_transaction ( config, transaction_2) ?;
1074
1087
send_transaction ( config, transaction_3) ?;
1075
1088
Ok ( ( ) )
1076
1089
}
@@ -1252,7 +1265,9 @@ fn command_update_reserve(
1252
1265
reserve. liquidity . switchboard_oracle_pubkey = switchboard_feed_pubkey. unwrap ( ) ;
1253
1266
}
1254
1267
1255
- let mut transaction = Transaction :: new_with_payer (
1268
+ let recent_blockhash = config. rpc_client . get_latest_blockhash ( ) ?;
1269
+
1270
+ let message = Message :: new_with_blockhash (
1256
1271
& [ update_reserve_config (
1257
1272
config. lending_program_id ,
1258
1273
reserve. config ,
@@ -1264,15 +1279,15 @@ fn command_update_reserve(
1264
1279
reserve. liquidity . switchboard_oracle_pubkey ,
1265
1280
) ] ,
1266
1281
Some ( & config. fee_payer . pubkey ( ) ) ,
1282
+ & recent_blockhash,
1267
1283
) ;
1268
1284
1269
- let ( recent_blockhash, fee_calculator) = config. rpc_client . get_recent_blockhash ( ) ?;
1270
- check_fee_payer_balance ( config, fee_calculator. calculate_fee ( transaction. message ( ) ) ) ?;
1271
-
1272
- transaction. sign (
1285
+ let transaction = Transaction :: new (
1273
1286
& vec ! [ config. fee_payer. as_ref( ) , & lending_market_owner_keypair] ,
1287
+ message,
1274
1288
recent_blockhash,
1275
1289
) ;
1290
+
1276
1291
send_transaction ( config, transaction) ?;
1277
1292
Ok ( ( ) )
1278
1293
}
0 commit comments