4
4
error:: TokenError ,
5
5
extension:: {
6
6
confidential_transfer:: { instruction:: * , * } ,
7
- transfer_fee:: TransferFeeConfig ,
8
7
StateWithExtensions , StateWithExtensionsMut ,
9
8
} ,
10
9
processor:: Processor ,
11
10
state:: { Account , Mint } ,
12
11
} ,
13
12
solana_program:: {
14
13
account_info:: { next_account_info, AccountInfo } ,
15
- clock:: Clock ,
16
14
entrypoint:: ProgramResult ,
17
15
instruction:: Instruction ,
18
16
msg,
19
17
program_error:: ProgramError ,
20
18
pubkey:: Pubkey ,
21
- sysvar:: { instructions:: get_instruction_relative, Sysvar } ,
19
+ sysvar:: instructions:: get_instruction_relative,
22
20
} ,
23
- solana_zk_token_sdk:: { zk_token_elgamal:: ops, zk_token_proof_program} ,
21
+ solana_zk_token_sdk:: zk_token_proof_program,
22
+ } ;
23
+ // Remove feature once zk ops syscalls are enabled on all networks
24
+ #[ cfg( feature = "zk-ops" ) ]
25
+ use {
26
+ crate :: extension:: transfer_fee:: TransferFeeConfig ,
27
+ solana_program:: { clock:: Clock , sysvar:: Sysvar } ,
28
+ solana_zk_token_sdk:: zk_token_elgamal:: ops,
24
29
} ;
25
30
26
31
fn decode_proof_instruction < T : Pod > (
@@ -246,6 +251,7 @@ fn process_empty_account(
246
251
}
247
252
248
253
/// Processes a [Deposit] instruction.
254
+ #[ cfg( feature = "zk-ops" ) ]
249
255
fn process_deposit (
250
256
program_id : & Pubkey ,
251
257
accounts : & [ AccountInfo ] ,
@@ -345,6 +351,7 @@ fn process_deposit(
345
351
}
346
352
347
353
/// Processes a [Withdraw] instruction.
354
+ #[ cfg( feature = "zk-ops" ) ]
348
355
fn process_withdraw (
349
356
program_id : & Pubkey ,
350
357
accounts : & [ AccountInfo ] ,
@@ -449,6 +456,7 @@ fn process_withdraw(
449
456
}
450
457
451
458
/// Processes an [Transfer] instruction.
459
+ #[ cfg( feature = "zk-ops" ) ]
452
460
fn process_transfer (
453
461
program_id : & Pubkey ,
454
462
accounts : & [ AccountInfo ] ,
@@ -595,6 +603,7 @@ fn process_transfer(
595
603
}
596
604
597
605
#[ allow( clippy:: too_many_arguments) ]
606
+ #[ cfg( feature = "zk-ops" ) ]
598
607
fn process_source_for_transfer (
599
608
program_id : & Pubkey ,
600
609
token_account_info : & AccountInfo ,
@@ -650,6 +659,7 @@ fn process_source_for_transfer(
650
659
Ok ( ( ) )
651
660
}
652
661
662
+ #[ cfg( feature = "zk-ops" ) ]
653
663
fn process_destination_for_transfer (
654
664
destination_token_account_info : & AccountInfo ,
655
665
mint_info : & AccountInfo ,
@@ -730,6 +740,7 @@ fn process_destination_for_transfer(
730
740
}
731
741
732
742
/// Processes an [ApplyPendingBalance] instruction.
743
+ #[ cfg( feature = "zk-ops" ) ]
733
744
fn process_apply_pending_balance (
734
745
program_id : & Pubkey ,
735
746
accounts : & [ AccountInfo ] ,
@@ -806,6 +817,7 @@ fn process_allow_balance_credits(
806
817
}
807
818
808
819
/// Processes an [WithdrawWithheldTokensFromMint] instruction.
820
+ #[ cfg( feature = "zk-ops" ) ]
809
821
fn process_withdraw_withheld_tokens_from_mint (
810
822
program_id : & Pubkey ,
811
823
accounts : & [ AccountInfo ] ,
@@ -894,6 +906,7 @@ fn process_withdraw_withheld_tokens_from_mint(
894
906
Ok ( ( ) )
895
907
}
896
908
909
+ #[ cfg( feature = "zk-ops" ) ]
897
910
fn process_withdraw_withheld_tokens_from_accounts (
898
911
program_id : & Pubkey ,
899
912
accounts : & [ AccountInfo ] ,
@@ -1009,6 +1022,7 @@ fn process_withdraw_withheld_tokens_from_accounts(
1009
1022
Ok ( ( ) )
1010
1023
}
1011
1024
1025
+ #[ cfg( feature = "zk-ops" ) ]
1012
1026
fn harvest_from_account < ' a , ' b > (
1013
1027
mint_key : & ' b Pubkey ,
1014
1028
token_account_info : & ' b AccountInfo < ' a > ,
@@ -1032,6 +1046,7 @@ fn harvest_from_account<'a, 'b>(
1032
1046
}
1033
1047
1034
1048
/// Processes an [HarvestWithheldTokensToMint] instruction.
1049
+ #[ cfg( feature = "zk-ops" ) ]
1035
1050
fn process_harvest_withheld_tokens_to_mint ( accounts : & [ AccountInfo ] ) -> ProgramResult {
1036
1051
let account_info_iter = & mut accounts. iter ( ) ;
1037
1052
let mint_account_info = next_account_info ( account_info_iter) ?;
@@ -1061,6 +1076,7 @@ fn process_harvest_withheld_tokens_to_mint(accounts: &[AccountInfo]) -> ProgramR
1061
1076
Ok ( ( ) )
1062
1077
}
1063
1078
1079
+ #[ allow( dead_code) ]
1064
1080
pub ( crate ) fn process_instruction (
1065
1081
program_id : & Pubkey ,
1066
1082
accounts : & [ AccountInfo ] ,
@@ -1102,38 +1118,60 @@ pub(crate) fn process_instruction(
1102
1118
}
1103
1119
ConfidentialTransferInstruction :: Deposit => {
1104
1120
msg ! ( "ConfidentialTransferInstruction::Deposit" ) ;
1105
- let data = decode_instruction_data :: < DepositInstructionData > ( input) ?;
1106
- process_deposit ( program_id, accounts, data. amount . into ( ) , data. decimals )
1121
+ #[ cfg( feature = "zk-ops" ) ]
1122
+ {
1123
+ let data = decode_instruction_data :: < DepositInstructionData > ( input) ?;
1124
+ process_deposit ( program_id, accounts, data. amount . into ( ) , data. decimals )
1125
+ }
1126
+ #[ cfg( not( feature = "zk-ops" ) ) ]
1127
+ Err ( ProgramError :: InvalidInstructionData )
1107
1128
}
1108
1129
ConfidentialTransferInstruction :: Withdraw => {
1109
1130
msg ! ( "ConfidentialTransferInstruction::Withdraw" ) ;
1110
- let data = decode_instruction_data :: < WithdrawInstructionData > ( input) ?;
1111
- process_withdraw (
1112
- program_id,
1113
- accounts,
1114
- data. amount . into ( ) ,
1115
- data. decimals ,
1116
- data. new_decryptable_available_balance ,
1117
- data. proof_instruction_offset as i64 ,
1118
- )
1131
+ #[ cfg( feature = "zk-ops" ) ]
1132
+ {
1133
+ let data = decode_instruction_data :: < WithdrawInstructionData > ( input) ?;
1134
+ process_withdraw (
1135
+ program_id,
1136
+ accounts,
1137
+ data. amount . into ( ) ,
1138
+ data. decimals ,
1139
+ data. new_decryptable_available_balance ,
1140
+ data. proof_instruction_offset as i64 ,
1141
+ )
1142
+ }
1143
+ #[ cfg( not( feature = "zk-ops" ) ) ]
1144
+ Err ( ProgramError :: InvalidInstructionData )
1119
1145
}
1120
1146
ConfidentialTransferInstruction :: Transfer => {
1121
1147
msg ! ( "ConfidentialTransferInstruction::Transfer" ) ;
1122
- let data = decode_instruction_data :: < TransferInstructionData > ( input) ?;
1123
- process_transfer (
1124
- program_id,
1125
- accounts,
1126
- data. new_source_decryptable_available_balance ,
1127
- data. proof_instruction_offset as i64 ,
1128
- )
1148
+ #[ cfg( feature = "zk-ops" ) ]
1149
+ {
1150
+ let data = decode_instruction_data :: < TransferInstructionData > ( input) ?;
1151
+ process_transfer (
1152
+ program_id,
1153
+ accounts,
1154
+ data. new_source_decryptable_available_balance ,
1155
+ data. proof_instruction_offset as i64 ,
1156
+ )
1157
+ }
1158
+ #[ cfg( not( feature = "zk-ops" ) ) ]
1159
+ Err ( ProgramError :: InvalidInstructionData )
1129
1160
}
1130
1161
ConfidentialTransferInstruction :: ApplyPendingBalance => {
1131
1162
msg ! ( "ConfidentialTransferInstruction::ApplyPendingBalance" ) ;
1132
- process_apply_pending_balance (
1133
- program_id,
1134
- accounts,
1135
- decode_instruction_data :: < ApplyPendingBalanceData > ( input) ?,
1136
- )
1163
+ #[ cfg( feature = "zk-ops" ) ]
1164
+ {
1165
+ process_apply_pending_balance (
1166
+ program_id,
1167
+ accounts,
1168
+ decode_instruction_data :: < ApplyPendingBalanceData > ( input) ?,
1169
+ )
1170
+ }
1171
+ #[ cfg( not( feature = "zk-ops" ) ) ]
1172
+ {
1173
+ Err ( ProgramError :: InvalidInstructionData )
1174
+ }
1137
1175
}
1138
1176
ConfidentialTransferInstruction :: DisableBalanceCredits => {
1139
1177
msg ! ( "ConfidentialTransferInstruction::DisableBalanceCredits" ) ;
@@ -1145,26 +1183,44 @@ pub(crate) fn process_instruction(
1145
1183
}
1146
1184
ConfidentialTransferInstruction :: WithdrawWithheldTokensFromMint => {
1147
1185
msg ! ( "ConfidentialTransferInstruction::WithdrawWithheldTokensFromMint" ) ;
1148
- let data = decode_instruction_data :: < WithdrawWithheldTokensFromMintData > ( input) ?;
1149
- process_withdraw_withheld_tokens_from_mint (
1150
- program_id,
1151
- accounts,
1152
- data. proof_instruction_offset as i64 ,
1153
- )
1186
+ #[ cfg( feature = "zk-ops" ) ]
1187
+ {
1188
+ let data = decode_instruction_data :: < WithdrawWithheldTokensFromMintData > ( input) ?;
1189
+ process_withdraw_withheld_tokens_from_mint (
1190
+ program_id,
1191
+ accounts,
1192
+ data. proof_instruction_offset as i64 ,
1193
+ )
1194
+ }
1195
+ #[ cfg( not( feature = "zk-ops" ) ) ]
1196
+ Err ( ProgramError :: InvalidInstructionData )
1154
1197
}
1155
1198
ConfidentialTransferInstruction :: WithdrawWithheldTokensFromAccounts => {
1156
1199
msg ! ( "ConfidentialTransferInstruction::WithdrawWithheldTokensFromAccounts" ) ;
1157
- let data = decode_instruction_data :: < WithdrawWithheldTokensFromAccountsData > ( input) ?;
1158
- process_withdraw_withheld_tokens_from_accounts (
1159
- program_id,
1160
- accounts,
1161
- data. num_token_accounts ,
1162
- data. proof_instruction_offset as i64 ,
1163
- )
1200
+ #[ cfg( feature = "zk-ops" ) ]
1201
+ {
1202
+ let data =
1203
+ decode_instruction_data :: < WithdrawWithheldTokensFromAccountsData > ( input) ?;
1204
+ process_withdraw_withheld_tokens_from_accounts (
1205
+ program_id,
1206
+ accounts,
1207
+ data. num_token_accounts ,
1208
+ data. proof_instruction_offset as i64 ,
1209
+ )
1210
+ }
1211
+ #[ cfg( not( feature = "zk-ops" ) ) ]
1212
+ Err ( ProgramError :: InvalidInstructionData )
1164
1213
}
1165
1214
ConfidentialTransferInstruction :: HarvestWithheldTokensToMint => {
1166
1215
msg ! ( "ConfidentialTransferInstruction::HarvestWithheldTokensToMint" ) ;
1167
- process_harvest_withheld_tokens_to_mint ( accounts)
1216
+ #[ cfg( feature = "zk-ops" ) ]
1217
+ {
1218
+ process_harvest_withheld_tokens_to_mint ( accounts)
1219
+ }
1220
+ #[ cfg( not( feature = "zk-ops" ) ) ]
1221
+ {
1222
+ Err ( ProgramError :: InvalidInstructionData )
1223
+ }
1168
1224
}
1169
1225
}
1170
1226
}
0 commit comments