Skip to content
This repository was archived by the owner on Mar 11, 2025. It is now read-only.

Commit 7330b17

Browse files
token-2022: add fee for confidential extension (#2897)
* token-2022: add fee for confidential extension * token-2022: change receiver to dest for consistency * token-2022: addressing readability review comments for confidential extension
1 parent 449a659 commit 7330b17

File tree

7 files changed

+306
-142
lines changed

7 files changed

+306
-142
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

token/program-2022/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ num-derive = "0.3"
1919
num-traits = "0.2"
2020
num_enum = "0.5.4"
2121
solana-program = "1.9.5"
22-
solana-zk-token-sdk = "0.4.0"
22+
solana-zk-token-sdk = "0.6.0"
2323
thiserror = "1.0"
2424

2525
[dev-dependencies]

token/program-2022/src/error.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,16 @@ pub enum TokenError {
121121
/// Calculated fee does not match expected fee
122122
#[error("Calculated fee does not match expected fee")]
123123
FeeMismatch,
124+
/// Fee parameters associated with confidential transfer zero-knowledge proofs do not match fee parameters in mint
125+
#[error(
126+
"Fee parameters associated with zero-knowledge proofs do not match fee parameters in mint"
127+
)]
128+
FeeParametersMismatch,
124129
/// The owner authority cannot be changed
125130
#[error("The owner authority cannot be changed")]
126131
ImmutableOwner,
132+
133+
// 35
127134
/// An account can only be closed if its withheld fee balance is zero, harvest fees to the
128135
/// mint and try again
129136
#[error("An account can only be closed if its withheld fee balance is zero, harvest fees to the mint and try again")]

token/program-2022/src/extension/confidential_transfer/instruction.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ pub enum ConfidentialTransferInstruction {
232232
#[repr(C)]
233233
pub struct ConfigureAccountInstructionData {
234234
/// The public key associated with the account
235-
pub elgamal_pk: pod::ElGamalPubkey,
235+
pub elgamal_pubkey: pod::ElGamalPubkey,
236236
/// The decryptable balance (always 0) once the configure account succeeds
237237
pub decryptable_zero_balance: pod::AeCiphertext,
238238
}
@@ -372,7 +372,7 @@ pub fn configure_account(
372372
token_program_id: &Pubkey,
373373
token_account: &Pubkey,
374374
mint: &Pubkey,
375-
elgamal_pk: ElGamalPubkey,
375+
elgamal_pubkey: ElGamalPubkey,
376376
decryptable_zero_balance: AeCiphertext,
377377
authority: &Pubkey,
378378
multisig_signers: &[&Pubkey],
@@ -393,7 +393,7 @@ pub fn configure_account(
393393
accounts,
394394
ConfidentialTransferInstruction::ConfigureAccount,
395395
&ConfigureAccountInstructionData {
396-
elgamal_pk: elgamal_pk.into(),
396+
elgamal_pubkey: elgamal_pubkey.into(),
397397
decryptable_zero_balance: decryptable_zero_balance.into(),
398398
},
399399
)])

token/program-2022/src/extension/confidential_transfer/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ pub struct ConfidentialTransferMint {
3838
/// * If non-zero, transfers must include ElGamal cypertext with this public key permitting the
3939
/// auditor to decode the transfer amount.
4040
/// * If all zero, auditing is currently disabled.
41-
pub auditor_pk: pod::ElGamalPubkey,
41+
pub auditor_pubkey: pod::ElGamalPubkey,
42+
43+
/// * If non-zero, transfers must include ElGamal cypertext of the transfer fee with this
44+
/// public key. If this is the case, but the base mint is not extended for fees, then any
45+
/// transfer will fail.
46+
/// * If all zero, transfer fee is disabled. If this is the case, but the base mint is extended
47+
/// for fees, then any transfer will fail.
48+
pub withdraw_withheld_authority_pubkey: pod::ElGamalPubkey,
4249
}
4350

4451
impl Extension for ConfidentialTransferMint {
@@ -54,12 +61,12 @@ pub struct ConfidentialTransferAccount {
5461
pub approved: PodBool,
5562

5663
/// The public key associated with ElGamal encryption
57-
pub elgamal_pk: pod::ElGamalPubkey,
64+
pub elgamal_pubkey: pod::ElGamalPubkey,
5865

59-
/// The pending balance (encrypted by `elgamal_pk`)
66+
/// The pending balance (encrypted by `elgamal_pubkey`)
6067
pub pending_balance: pod::ElGamalCiphertext,
6168

62-
/// The available balance (encrypted by `elgamal_pk`)
69+
/// The available balance (encrypted by `elgamal_pubkey`)
6370
pub available_balance: pod::ElGamalCiphertext,
6471

6572
/// The decryptable available balance
@@ -77,6 +84,9 @@ pub struct ConfidentialTransferAccount {
7784

7885
/// The actual `pending_balance_credit_counter` when the last `ApplyPendingBalance` instruction was executed
7986
pub actual_pending_balance_credit_counter: PodU64,
87+
88+
/// The withheld amount of fees. This will always be zero if fees are never enabled.
89+
pub withheld_amount: pod::ElGamalCiphertext,
8090
}
8191

8292
impl Extension for ConfidentialTransferAccount {

0 commit comments

Comments
 (0)