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

Commit ab8cad1

Browse files
committed
add confidential transfer UpdateMint
1 parent fd54300 commit ab8cad1

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import type { ConfirmOptions, Connection, PublicKey, Signer, TransactionSignature } from '@solana/web3.js';
2+
import { sendAndConfirmTransaction, Transaction } from '@solana/web3.js';
3+
import { TOKEN_2022_PROGRAM_ID } from '../../constants.js';
4+
import { createConfidentialTransferUpdateMintInstruction } from './instructions.js';
5+
import { PodElGamalPubkey } from 'solana-zk-token-sdk-experimental';
6+
7+
export async function updateMint(
8+
connection: Connection,
9+
payer: Signer,
10+
mint: PublicKey,
11+
autoApproveNewAccounts: boolean,
12+
auditorElGamalPubkey: PodElGamalPubkey | null,
13+
authority: Signer,
14+
confirmOptions?: ConfirmOptions,
15+
programId = TOKEN_2022_PROGRAM_ID
16+
): Promise<TransactionSignature> {
17+
const transaction = new Transaction().add(
18+
createConfidentialTransferUpdateMintInstruction(
19+
mint,
20+
authority.publicKey,
21+
autoApproveNewAccounts,
22+
auditorElGamalPubkey,
23+
programId
24+
)
25+
);
26+
27+
return await sendAndConfirmTransaction(connection, transaction, [payer, authority], confirmOptions);
28+
}
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from './actions.js';
12
export * from './state.js';
23
export * from './instructions.js';

token/js/src/extensions/confidentialTransfer/instructions.ts

+44
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { elgamalPublicKey } from './elgamal.js';
99

1010
export enum ConfidentialTransferInstruction {
1111
InitializeMint = 0,
12+
UpdateMint = 1,
1213
}
1314

1415
export interface InitializeMintData {
@@ -54,3 +55,46 @@ export function createConfidentialTransferInitializeMintInstruction(
5455

5556
return new TransactionInstruction({ keys, programId, data });
5657
}
58+
59+
export interface UpdateMintData {
60+
instruction: TokenInstruction.ConfidentialTransferExtension;
61+
confidentialTransferInstruction: ConfidentialTransferInstruction.UpdateMint;
62+
autoApproveNewAccounts: boolean;
63+
auditorElGamalPubkey: PodElGamalPubkey | null;
64+
}
65+
66+
export const updateMintData = struct<UpdateMintData>([
67+
u8('instruction'),
68+
u8('confidentialTransferInstruction'),
69+
bool('autoApproveNewAccounts'),
70+
elgamalPublicKey('auditorElGamalPubkey'),
71+
]);
72+
73+
export function createConfidentialTransferUpdateMintInstruction(
74+
mint: PublicKey,
75+
confidentialTransferMintAuthority: PublicKey,
76+
autoApproveNewAccounts: boolean,
77+
auditorElGamalPubkey: PodElGamalPubkey | null,
78+
programId = TOKEN_2022_PROGRAM_ID
79+
): TransactionInstruction {
80+
if (!programSupportsExtensions(programId)) {
81+
throw new TokenUnsupportedInstructionError();
82+
}
83+
const keys = [
84+
{ pubkey: mint, isSigner: false, isWritable: true },
85+
{ pubkey: confidentialTransferMintAuthority, isSigner: true, isWritable: false },
86+
];
87+
88+
const data = Buffer.alloc(updateMintData.span);
89+
updateMintData.encode(
90+
{
91+
instruction: TokenInstruction.ConfidentialTransferExtension,
92+
confidentialTransferInstruction: ConfidentialTransferInstruction.UpdateMint,
93+
autoApproveNewAccounts: autoApproveNewAccounts,
94+
auditorElGamalPubkey: auditorElGamalPubkey ?? PodElGamalPubkey.default(),
95+
},
96+
data
97+
);
98+
99+
return new TransactionInstruction({ keys, programId, data });
100+
}

token/js/test/e2e-2022/confidentialTransfer.test.ts

+24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { TEST_PROGRAM_ID, newAccountWithLamports, getConnection } from '../commo
99
import {
1010
createConfidentialTransferInitializeMintInstruction,
1111
getConfidentialTransferMint,
12+
updateMint,
1213
} from '../../src/extensions/confidentialTransfer/index';
1314

1415
const TEST_TOKEN_DECIMALS = 2;
@@ -85,5 +86,28 @@ describe('confidentialTransfer', () => {
8586
expect(confidentialTransferMint.auditorElGamalPubkey.equals(auditorPubkey)); // TODO: equals?
8687
}
8788
});
89+
90+
it('mint updates', async () => {
91+
const newAutoApproveNewAccounts = false;
92+
const newAuditorElGamalKeypair = ElGamalKeypair.new_rand();
93+
const newAuditorElGamalPubkey = PodElGamalPubkey.encoded(newAuditorElGamalKeypair.pubkey_owned());
94+
95+
await updateMint(
96+
connection,
97+
payer,
98+
mint,
99+
newAutoApproveNewAccounts,
100+
newAuditorElGamalPubkey,
101+
confidentialTransferMintAuthority
102+
);
103+
104+
const mintInfo = await getMint(connection, mint, undefined, TEST_PROGRAM_ID);
105+
const confidentialTransferMint = getConfidentialTransferMint(mintInfo);
106+
expect(confidentialTransferMint).to.not.be.null;
107+
if (confidentialTransferMint !== null) {
108+
expect(confidentialTransferMint.autoApproveNewAccounts).to.eql(newAutoApproveNewAccounts);
109+
expect(confidentialTransferMint.auditorElGamalPubkey.equals(newAuditorElGamalPubkey));
110+
}
111+
});
88112
});
89113
});

0 commit comments

Comments
 (0)