Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions js/compressed-token/src/v3/actions/mint-to-compressed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ export async function mintToCompressed(
splMint: mintInfo.mintContext!.splMint,
cmintDecompressed: mintInfo.mintContext!.cmintDecompressed,
version: mintInfo.mintContext!.version,
mintSigner: mintInfo.mintContext!.mintSigner,
bump: mintInfo.mintContext!.bump,
metadata: mintInfo.tokenMetadata
? {
updateAuthority:
Expand Down
2 changes: 2 additions & 0 deletions js/compressed-token/src/v3/actions/mint-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ export async function mintTo(
splMint: mintInfo.mintContext!.splMint,
cmintDecompressed: mintInfo.mintContext!.cmintDecompressed,
version: mintInfo.mintContext!.version,
mintSigner: mintInfo.mintContext!.mintSigner,
bump: mintInfo.mintContext!.bump,
metadata: mintInfo.tokenMetadata
? {
updateAuthority:
Expand Down
11 changes: 3 additions & 8 deletions js/compressed-token/src/v3/instructions/create-mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
CTOKEN_PROGRAM_ID,
LightSystemProgram,
defaultStaticAccountsStruct,
deriveAddressV2,
TreeInfo,
AddressTreeInfo,
ValidityProof,
Expand Down Expand Up @@ -95,12 +94,7 @@ function validateProofArrays(
export function encodeCreateMintInstructionData(
params: EncodeCreateMintInstructionParams,
): Buffer {
const [splMintPda] = findMintAddress(params.mintSigner);
const compressedAddress = deriveAddressV2(
splMintPda.toBytes(),
params.addressTree,
CTOKEN_PROGRAM_ID,
);
const [splMintPda, bump] = findMintAddress(params.mintSigner);

// Build extensions if metadata present
let extensions: { tokenMetadata: TokenMetadataBorshData }[] | null = null;
Expand Down Expand Up @@ -141,7 +135,8 @@ export function encodeCreateMintInstructionData(
version: TokenDataVersion.ShaFlat,
cmintDecompressed: false,
mint: splMintPda,
compressedAddress: Array.from(compressedAddress.toBytes()),
mintSigner: Array.from(params.mintSigner.toBytes()),
bump,
},
mintAuthority: params.mintAuthority,
freezeAuthority: params.freezeAuthority,
Expand Down
10 changes: 2 additions & 8 deletions js/compressed-token/src/v3/instructions/mint-to-compressed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
CTOKEN_PROGRAM_ID,
LightSystemProgram,
defaultStaticAccountsStruct,
deriveAddressV2,
getDefaultAddressTreeInfo,
MerkleContext,
TreeInfo,
Expand All @@ -36,12 +35,6 @@ interface EncodeCompressedMintToInstructionParams {
function encodeCompressedMintToInstructionData(
params: EncodeCompressedMintToInstructionParams,
): Buffer {
const compressedAddress = deriveAddressV2(
params.mintData.splMint.toBytes(),
params.addressTree,
CTOKEN_PROGRAM_ID,
);

// TokenMetadata extension not supported in mintTo instruction
if (params.mintData.metadata) {
throw new Error(
Expand Down Expand Up @@ -75,7 +68,8 @@ function encodeCompressedMintToInstructionData(
version: params.mintData.version,
cmintDecompressed: params.mintData.cmintDecompressed,
mint: params.mintData.splMint,
compressedAddress: Array.from(compressedAddress.toBytes()),
mintSigner: Array.from(params.mintData.mintSigner),
bump: params.mintData.bump,
},
mintAuthority: params.mintData.mintAuthority,
freezeAuthority: params.mintData.freezeAuthority,
Expand Down
2 changes: 2 additions & 0 deletions js/compressed-token/src/v3/instructions/mint-to-interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export function createMintToInterfaceInstruction(
splMint: mintInterface.mintContext.splMint,
cmintDecompressed: mintInterface.mintContext.cmintDecompressed,
version: mintInterface.mintContext.version,
mintSigner: mintInterface.mintContext.mintSigner,
bump: mintInterface.mintContext.bump,
metadata: mintInterface.tokenMetadata
? {
updateAuthority:
Expand Down
10 changes: 2 additions & 8 deletions js/compressed-token/src/v3/instructions/mint-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
CTOKEN_PROGRAM_ID,
LightSystemProgram,
defaultStaticAccountsStruct,
deriveAddressV2,
getDefaultAddressTreeInfo,
MerkleContext,
TreeInfo,
Expand All @@ -34,12 +33,6 @@ interface EncodeMintToCTokenInstructionParams {
function encodeMintToCTokenInstructionData(
params: EncodeMintToCTokenInstructionParams,
): Buffer {
const compressedAddress = deriveAddressV2(
params.mintData.splMint.toBytes(),
params.addressTree,
CTOKEN_PROGRAM_ID,
);

// TokenMetadata extension not supported in mintTo instruction
if (params.mintData.metadata) {
throw new Error(
Expand Down Expand Up @@ -70,7 +63,8 @@ function encodeMintToCTokenInstructionData(
version: params.mintData.version,
cmintDecompressed: params.mintData.cmintDecompressed,
mint: params.mintData.splMint,
compressedAddress: Array.from(compressedAddress.toBytes()),
mintSigner: Array.from(params.mintData.mintSigner),
bump: params.mintData.bump,
},
mintAuthority: params.mintData.mintAuthority,
freezeAuthority: params.mintData.freezeAuthority,
Expand Down
10 changes: 2 additions & 8 deletions js/compressed-token/src/v3/instructions/update-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
CTOKEN_PROGRAM_ID,
LightSystemProgram,
defaultStaticAccountsStruct,
deriveAddressV2,
getDefaultAddressTreeInfo,
getOutputQueue,
} from '@lightprotocol/stateless.js';
Expand Down Expand Up @@ -82,12 +81,6 @@ function convertActionToBorsh(action: UpdateMetadataAction): Action {
function encodeUpdateMetadataInstructionData(
params: EncodeUpdateMetadataInstructionParams,
): Buffer {
const compressedAddress = deriveAddressV2(
params.splMint.toBytes(),
params.addressTree,
CTOKEN_PROGRAM_ID,
);

const mintInterface = params.mintInterface;

if (!mintInterface.tokenMetadata) {
Expand All @@ -112,7 +105,8 @@ function encodeUpdateMetadataInstructionData(
version: mintInterface.mintContext!.version,
cmintDecompressed: mintInterface.mintContext!.cmintDecompressed,
mint: mintInterface.mintContext!.splMint,
compressedAddress: Array.from(compressedAddress.toBytes()),
mintSigner: Array.from(mintInterface.mintContext!.mintSigner),
bump: mintInterface.mintContext!.bump,
},
mintAuthority: mintInterface.mint.mintAuthority,
freezeAuthority: mintInterface.mint.freezeAuthority,
Expand Down
12 changes: 4 additions & 8 deletions js/compressed-token/src/v3/instructions/update-mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
CTOKEN_PROGRAM_ID,
LightSystemProgram,
defaultStaticAccountsStruct,
deriveAddressV2,
getDefaultAddressTreeInfo,
getOutputQueue,
} from '@lightprotocol/stateless.js';
Expand Down Expand Up @@ -37,12 +36,6 @@ interface EncodeUpdateMintInstructionParams {
function encodeUpdateMintInstructionData(
params: EncodeUpdateMintInstructionParams,
): Buffer {
const compressedAddress = deriveAddressV2(
params.splMint.toBytes(),
params.addressTree,
CTOKEN_PROGRAM_ID,
);

// Build action
const action: Action =
params.actionType === 'mintAuthority'
Expand Down Expand Up @@ -86,7 +79,10 @@ function encodeUpdateMintInstructionData(
cmintDecompressed:
params.mintInterface.mintContext!.cmintDecompressed,
mint: params.mintInterface.mintContext!.splMint,
compressedAddress: Array.from(compressedAddress.toBytes()),
mintSigner: Array.from(
params.mintInterface.mintContext!.mintSigner,
),
bump: params.mintInterface.mintContext!.bump,
},
mintAuthority: params.mintInterface.mint.mintAuthority,
freezeAuthority: params.mintInterface.mint.freezeAuthority,
Expand Down
6 changes: 4 additions & 2 deletions js/compressed-token/src/v3/layout/layout-mint-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ export const CompressedMintMetadataLayout = struct([
u8('version'),
bool('cmintDecompressed'),
publicKey('mint'),
array(u8(), 32, 'compressedAddress'),
array(u8(), 32, 'mintSigner'),
u8('bump'),
]);

export const CompressedMintInstructionDataLayout = struct([
Expand Down Expand Up @@ -309,7 +310,8 @@ export interface CompressedMintMetadata {
version: number;
cmintDecompressed: boolean;
mint: PublicKey;
compressedAddress: number[];
mintSigner: number[];
bump: number;
}

export interface CompressedMintInstructionData {
Expand Down
35 changes: 32 additions & 3 deletions js/compressed-token/src/v3/layout/layout-mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export interface MintContext {
cmintDecompressed: boolean;
/** PDA of the associated SPL mint */
splMint: PublicKey;
/** Signer pubkey used to derive the mint PDA */
mintSigner: Uint8Array;
/** Bump seed for the mint PDA */
bump: number;
}

/**
Expand Down Expand Up @@ -95,6 +99,9 @@ export interface CompressedMint {
}

/** MintContext as stored by the program */
/**
* Raw mint context for layout encoding (mintSigner and bump are encoded separately)
*/
export interface RawMintContext {
version: number;
cmintDecompressed: number; // bool as u8
Expand All @@ -108,11 +115,15 @@ export const MintContextLayout = struct<RawMintContext>([
publicKey('splMint'),
]);

/** Byte length of MintContext */
/** Byte length of MintContext (excluding mintSigner and bump which are read separately) */
export const MINT_CONTEXT_SIZE = MintContextLayout.span; // 34 bytes

/** Reserved bytes for T22 layout compatibility */
export const RESERVED_SIZE = 49;
/** Additional bytes for mintSigner (32) + bump (1) */
export const MINT_SIGNER_SIZE = 32;
export const BUMP_SIZE = 1;

/** Reserved bytes for T22 layout compatibility (padding to reach byte 165) */
export const RESERVED_SIZE = 16;

/** Account type discriminator size */
export const ACCOUNT_TYPE_SIZE = 1;
Expand Down Expand Up @@ -323,6 +334,12 @@ export function deserializeMint(data: Buffer | Uint8Array): CompressedMint {
);
offset += MINT_CONTEXT_SIZE;

// 2b. Read mintSigner (32 bytes) and bump (1 byte)
const mintSigner = buffer.slice(offset, offset + MINT_SIGNER_SIZE);
offset += MINT_SIGNER_SIZE;
const bump = buffer.readUInt8(offset);
offset += BUMP_SIZE;

// 3. Read reserved bytes (49 bytes) for T22 compatibility
const reserved = buffer.slice(offset, offset + RESERVED_SIZE);
offset += RESERVED_SIZE;
Expand Down Expand Up @@ -386,6 +403,8 @@ export function deserializeMint(data: Buffer | Uint8Array): CompressedMint {
version: rawContext.version,
cmintDecompressed: rawContext.cmintDecompressed !== 0,
splMint: rawContext.splMint,
mintSigner,
bump,
};

const mint: CompressedMint = {
Expand Down Expand Up @@ -487,6 +506,10 @@ export function serializeMint(mint: CompressedMint): Buffer {
);
buffers.push(contextBuffer);

// 2b. Encode mintSigner (32 bytes) and bump (1 byte)
buffers.push(Buffer.from(mint.mintContext.mintSigner));
buffers.push(Buffer.from([mint.mintContext.bump]));

// 3. Encode reserved bytes (49 bytes) - default to zeros
const reserved = mint.reserved ?? new Uint8Array(RESERVED_SIZE);
buffers.push(Buffer.from(reserved));
Expand Down Expand Up @@ -663,6 +686,10 @@ export interface MintInstructionData {
splMint: PublicKey;
cmintDecompressed: boolean;
version: number;
/** Signer pubkey used to derive the mint PDA */
mintSigner: Uint8Array;
/** Bump seed for the mint PDA */
bump: number;
metadata?: MintMetadataField;
}

Expand Down Expand Up @@ -705,6 +732,8 @@ export function toMintInstructionData(
splMint: mintContext.splMint,
cmintDecompressed: mintContext.cmintDecompressed,
version: mintContext.version,
mintSigner: mintContext.mintSigner,
bump: mintContext.bump,
metadata,
};
}
Expand Down
Loading
Loading