-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[token-cli] Add confidential transfer mint commands #5335
[token-cli] Add confidential transfer mint commands #5335
Conversation
9d42d1b
to
7e52fc5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Mostly tiny nits
@@ -288,6 +297,7 @@ pub(crate) struct CliMint { | |||
pub(crate) epoch: u64, | |||
#[serde(flatten)] | |||
pub(crate) mint: UiMint, | |||
pub(crate) ui_confidential_transfer_extension: Option<UiConfidentialTransferExtension>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Can you put a note to remove it here too?
token/cli/src/output.rs
Outdated
{ | ||
auditor_pubkey | ||
} else { | ||
"audits are not enabled" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should we just say "disabled" here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, good idea!
token/cli/src/output.rs
Outdated
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] | ||
pub(crate) enum UiConfidentialTransferExtension { | ||
ConfidentialTransferMint(UiConfidentialTransferMint), | ||
// TODO: add `ConfidentialTransferAccount` | ||
} | ||
|
||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq)] | ||
pub(crate) struct UiConfidentialTransferMint { | ||
pub authority: Option<String>, | ||
pub auto_approve_new_accounts: bool, | ||
pub auditor_encryption_pubkey: Option<String>, | ||
} | ||
|
||
pub(crate) fn has_confidential_transfer(data: &[u8]) -> Option<UiConfidentialTransferExtension> { | ||
if let Ok(mint) = StateWithExtensions::<Mint>::unpack(data) { | ||
if let Some(confidential_transfer_mint) = | ||
mint.get_extension::<ConfidentialTransferMint>().ok() | ||
{ | ||
let authority: Option<Pubkey> = confidential_transfer_mint.authority.into(); | ||
let auditor_encryption_pubkey: Option<ElGamalPubkey> = | ||
confidential_transfer_mint.auditor_elgamal_pubkey.into(); | ||
return Some(UiConfidentialTransferExtension::ConfidentialTransferMint( | ||
UiConfidentialTransferMint { | ||
authority: authority.map(|pubkey| pubkey.to_string()), | ||
auto_approve_new_accounts: confidential_transfer_mint | ||
.auto_approve_new_accounts | ||
.into(), | ||
auditor_encryption_pubkey: auditor_encryption_pubkey | ||
.map(|pubkey| pubkey.to_string()), | ||
}, | ||
)); | ||
} | ||
} | ||
None | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should all get removed too, right? If so, please put a comment about it
token/cli/Cargo.toml
Outdated
spl-token = { version = "4.0", path = "../program", features = [ | ||
"no-entrypoint", | ||
] } | ||
spl-token-2022 = { version = "0.8", path = "../program-2022", features = [ | ||
"no-entrypoint", | ||
] } | ||
spl-token-client = { version = "0.6", path = "../client" } | ||
spl-token-metadata-interface = { version = "0.2", path = "../../token-metadata/interface" } | ||
spl-associated-token-account = { version = "2.0", path = "../../associated-token-account/program", features = [ | ||
"no-entrypoint", | ||
] } | ||
spl-memo = { version = "4.0.0", path = "../../memo/program", features = [ | ||
"no-entrypoint", | ||
] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did your formatter pick these up? I haven't seen this before!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I recently updated my neovim config (I now use lazyvim) to enable lsp-server with taplo and it automatically validates cargo files as in an IDE, which is pretty cool. I also enabled auto-format on save as well. I guess should have filtered these format changes since it is orthogonal to this PR, sorry 😅.
token/cli/src/encryption_keypair.rs
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment here too to remove and use the proper parsers from clap-v3-utils
?
token/cli/src/main.rs
Outdated
.long("approve-policy") | ||
.value_name("APPROVE_POLICY") | ||
.takes_value(true) | ||
.index(2) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than setting these by index, which can be annoying if you just want to update one parameter, how about making them optional? That is, unless sign-only
is present, in which case you'll always need it
token/cli/src/main.rs
Outdated
.long("auditor-pubkey") | ||
.value_name("AUDITOR_PUBKEY") | ||
.takes_value(true) | ||
.index(3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, how about making it optional? Then you only set the specified params. Unless sign-only
is present, of course
Co-authored-by: Jon Cinque <[email protected]>
Co-authored-by: Jon Cinque <[email protected]>
7ed0096
to
dd18895
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one last nit, but otherwise looks great!
Co-authored-by: Jon Cinque <[email protected]>
Pull request has been modified.
Problem
There are no cli support for confidential transfers yet.
Summary of changes
Updated/added cli commands regarding the mint. The
create-token
with--enable-confidential-transfers
flag should already be supported.f616231: Updated the
display
command to support the confidential transfer mint extension. Unfortunately, thesolana-account-decoder
is still using the older version of token-2022 before the confidential transfer and confidential transfer fee extensions were split, which means we can't use theUiConfidentialTransferMint
type fromsolana-account-decoder
. I hard-coded a temporaryUiConfidentialTransferMint
type inoutput.rs
to account for this. This part can be removed in the next monorepo upgrade.09ad0d9: ElGamal keys are supported in
solana-clap-v3-utils
, but an upgrade to clap-v3 for token-cli is blocked until 1.17 due to a new panicking behavior that was introduced with clap-v3 (solana-labs/solana#33184). So I added temporary functions to read ElGamal keypairs and pubkeys to unblock work on the token-cli. These functions only support either reading from ElGamal keypair files or reading form base64-encoded pubkey string. Once we upgrade tosolana-clap-v3-utils
, we can support a more variety of ways to take ElGamal arguments.I didn't write tests for these hard-coded functions since they will eventually be replaced anyway, but I can add them in if suggested.
7e52fc5: Added
update-confidential-transfer-settings
, which allows updating the confidential transfer mint configuration.To try out the new commands:
To generate an arbitrary ElGamal public key, I just did
Once the issues in
solana-clap-v3-utils
are resolved and we publishsolana-zk-keygen
, then we can use that instead to generate ElGamal keypairs/pubkeys.