diff --git a/README.md b/README.md index 21030169..8bb73da3 100644 --- a/README.md +++ b/README.md @@ -65,8 +65,10 @@ The following clients are available for your programs. You may use the following ## Starting and stopping the local validator The following script is available to start your local validator. +In order to run the local validator you must also have the spl-elgamal-registry program built. ```sh +pnpm confidential-transfer:elgamal-registry:build # you only need to run this once pnpm validator:start ``` diff --git a/clients/js/src/generated/instructions/index.ts b/clients/js/src/generated/instructions/index.ts index c44ba678..a079c572 100644 --- a/clients/js/src/generated/instructions/index.ts +++ b/clients/js/src/generated/instructions/index.ts @@ -56,6 +56,7 @@ export * from './initializeMultisig'; export * from './initializeMultisig2'; export * from './initializeNonTransferableMint'; export * from './initializePermanentDelegate'; +export * from './initializeScaledUiAmountMint'; export * from './initializeTokenGroup'; export * from './initializeTokenGroupMember'; export * from './initializeTokenMetadata'; @@ -80,6 +81,7 @@ export * from './updateDefaultAccountState'; export * from './updateGroupMemberPointer'; export * from './updateGroupPointer'; export * from './updateMetadataPointer'; +export * from './updateMultiplierScaledUiMint'; export * from './updateRateInterestBearingMint'; export * from './updateTokenGroupMaxSize'; export * from './updateTokenGroupUpdateAuthority'; diff --git a/clients/js/src/generated/instructions/initializeScaledUiAmountMint.ts b/clients/js/src/generated/instructions/initializeScaledUiAmountMint.ts new file mode 100644 index 00000000..10dc7c13 --- /dev/null +++ b/clients/js/src/generated/instructions/initializeScaledUiAmountMint.ts @@ -0,0 +1,212 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + combineCodec, + getAddressDecoder, + getAddressEncoder, + getF64Decoder, + getF64Encoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type Option, + type OptionOrNullable, + type WritableAccount, +} from '@solana/kit'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const INITIALIZE_SCALED_UI_AMOUNT_MINT_DISCRIMINATOR = 43; + +export function getInitializeScaledUiAmountMintDiscriminatorBytes() { + return getU8Encoder().encode(INITIALIZE_SCALED_UI_AMOUNT_MINT_DISCRIMINATOR); +} + +export const INITIALIZE_SCALED_UI_AMOUNT_MINT_SCALED_UI_AMOUNT_MINT_DISCRIMINATOR = 0; + +export function getInitializeScaledUiAmountMintScaledUiAmountMintDiscriminatorBytes() { + return getU8Encoder().encode( + INITIALIZE_SCALED_UI_AMOUNT_MINT_SCALED_UI_AMOUNT_MINT_DISCRIMINATOR + ); +} + +export type InitializeScaledUiAmountMintInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMint extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountMint extends string + ? WritableAccount + : TAccountMint, + ...TRemainingAccounts, + ] + >; + +export type InitializeScaledUiAmountMintInstructionData = { + discriminator: number; + scaledUiAmountMintDiscriminator: number; + /** The authority that can update the multiplier */ + authority: Option
; + /** The initial multiplier for the scaled UI extension */ + multiplier: number; +}; + +export type InitializeScaledUiAmountMintInstructionDataArgs = { + /** The authority that can update the multiplier */ + authority: OptionOrNullable
; + /** The initial multiplier for the scaled UI extension */ + multiplier: number; +}; + +export function getInitializeScaledUiAmountMintInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['scaledUiAmountMintDiscriminator', getU8Encoder()], + [ + 'authority', + getOptionEncoder(getAddressEncoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ['multiplier', getF64Encoder()], + ]), + (value) => ({ + ...value, + discriminator: INITIALIZE_SCALED_UI_AMOUNT_MINT_DISCRIMINATOR, + scaledUiAmountMintDiscriminator: + INITIALIZE_SCALED_UI_AMOUNT_MINT_SCALED_UI_AMOUNT_MINT_DISCRIMINATOR, + }) + ); +} + +export function getInitializeScaledUiAmountMintInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['scaledUiAmountMintDiscriminator', getU8Decoder()], + [ + 'authority', + getOptionDecoder(getAddressDecoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ['multiplier', getF64Decoder()], + ]); +} + +export function getInitializeScaledUiAmountMintInstructionDataCodec(): Codec< + InitializeScaledUiAmountMintInstructionDataArgs, + InitializeScaledUiAmountMintInstructionData +> { + return combineCodec( + getInitializeScaledUiAmountMintInstructionDataEncoder(), + getInitializeScaledUiAmountMintInstructionDataDecoder() + ); +} + +export type InitializeScaledUiAmountMintInput< + TAccountMint extends string = string, +> = { + /** The mint to initialize. */ + mint: Address; + authority: InitializeScaledUiAmountMintInstructionDataArgs['authority']; + multiplier: InitializeScaledUiAmountMintInstructionDataArgs['multiplier']; +}; + +export function getInitializeScaledUiAmountMintInstruction< + TAccountMint extends string, + TProgramAddress extends Address = typeof TOKEN_2022_PROGRAM_ADDRESS, +>( + input: InitializeScaledUiAmountMintInput, + config?: { programAddress?: TProgramAddress } +): InitializeScaledUiAmountMintInstruction { + // Program address. + const programAddress = config?.programAddress ?? TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + mint: { value: input.mint ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [getAccountMeta(accounts.mint)], + programAddress, + data: getInitializeScaledUiAmountMintInstructionDataEncoder().encode( + args as InitializeScaledUiAmountMintInstructionDataArgs + ), + } as InitializeScaledUiAmountMintInstruction; + + return instruction; +} + +export type ParsedInitializeScaledUiAmountMintInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The mint to initialize. */ + mint: TAccountMetas[0]; + }; + data: InitializeScaledUiAmountMintInstructionData; +}; + +export function parseInitializeScaledUiAmountMintInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedInitializeScaledUiAmountMintInstruction { + if (instruction.accounts.length < 1) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = instruction.accounts![accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + mint: getNextAccount(), + }, + data: getInitializeScaledUiAmountMintInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/updateMultiplierScaledUiMint.ts b/clients/js/src/generated/instructions/updateMultiplierScaledUiMint.ts new file mode 100644 index 00000000..da13f146 --- /dev/null +++ b/clients/js/src/generated/instructions/updateMultiplierScaledUiMint.ts @@ -0,0 +1,240 @@ +/** + * This code was AUTOGENERATED using the codama library. + * Please DO NOT EDIT THIS FILE, instead use visitors + * to add features, then rerun codama to update it. + * + * @see https://github.com/codama-idl/codama + */ + +import { + AccountRole, + combineCodec, + getF64Decoder, + getF64Encoder, + getI64Decoder, + getI64Encoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type TransactionSigner, + type WritableAccount, + type WritableSignerAccount, +} from '@solana/kit'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const UPDATE_MULTIPLIER_SCALED_UI_MINT_DISCRIMINATOR = 43; + +export function getUpdateMultiplierScaledUiMintDiscriminatorBytes() { + return getU8Encoder().encode(UPDATE_MULTIPLIER_SCALED_UI_MINT_DISCRIMINATOR); +} + +export const UPDATE_MULTIPLIER_SCALED_UI_MINT_SCALED_UI_AMOUNT_MINT_DISCRIMINATOR = 1; + +export function getUpdateMultiplierScaledUiMintScaledUiAmountMintDiscriminatorBytes() { + return getU8Encoder().encode( + UPDATE_MULTIPLIER_SCALED_UI_MINT_SCALED_UI_AMOUNT_MINT_DISCRIMINATOR + ); +} + +export type UpdateMultiplierScaledUiMintInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMint extends string | IAccountMeta = string, + TAccountAuthority extends string | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountMint extends string + ? WritableAccount + : TAccountMint, + TAccountAuthority extends string + ? WritableAccount + : TAccountAuthority, + ...TRemainingAccounts, + ] + >; + +export type UpdateMultiplierScaledUiMintInstructionData = { + discriminator: number; + scaledUiAmountMintDiscriminator: number; + /** The new multiplier for the scaled UI extension */ + multiplier: number; + /** The timestamp at which the new multiplier will take effect */ + effectiveTimestamp: bigint; +}; + +export type UpdateMultiplierScaledUiMintInstructionDataArgs = { + /** The new multiplier for the scaled UI extension */ + multiplier: number; + /** The timestamp at which the new multiplier will take effect */ + effectiveTimestamp: number | bigint; +}; + +export function getUpdateMultiplierScaledUiMintInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['scaledUiAmountMintDiscriminator', getU8Encoder()], + ['multiplier', getF64Encoder()], + ['effectiveTimestamp', getI64Encoder()], + ]), + (value) => ({ + ...value, + discriminator: UPDATE_MULTIPLIER_SCALED_UI_MINT_DISCRIMINATOR, + scaledUiAmountMintDiscriminator: + UPDATE_MULTIPLIER_SCALED_UI_MINT_SCALED_UI_AMOUNT_MINT_DISCRIMINATOR, + }) + ); +} + +export function getUpdateMultiplierScaledUiMintInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['scaledUiAmountMintDiscriminator', getU8Decoder()], + ['multiplier', getF64Decoder()], + ['effectiveTimestamp', getI64Decoder()], + ]); +} + +export function getUpdateMultiplierScaledUiMintInstructionDataCodec(): Codec< + UpdateMultiplierScaledUiMintInstructionDataArgs, + UpdateMultiplierScaledUiMintInstructionData +> { + return combineCodec( + getUpdateMultiplierScaledUiMintInstructionDataEncoder(), + getUpdateMultiplierScaledUiMintInstructionDataDecoder() + ); +} + +export type UpdateMultiplierScaledUiMintInput< + TAccountMint extends string = string, + TAccountAuthority extends string = string, +> = { + /** The mint. */ + mint: Address; + /** The multiplier authority. */ + authority: Address | TransactionSigner; + multiplier: UpdateMultiplierScaledUiMintInstructionDataArgs['multiplier']; + effectiveTimestamp: UpdateMultiplierScaledUiMintInstructionDataArgs['effectiveTimestamp']; + multiSigners?: Array; +}; + +export function getUpdateMultiplierScaledUiMintInstruction< + TAccountMint extends string, + TAccountAuthority extends string, + TProgramAddress extends Address = typeof TOKEN_2022_PROGRAM_ADDRESS, +>( + input: UpdateMultiplierScaledUiMintInput, + config?: { programAddress?: TProgramAddress } +): UpdateMultiplierScaledUiMintInstruction< + TProgramAddress, + TAccountMint, + (typeof input)['authority'] extends TransactionSigner + ? WritableSignerAccount & + IAccountSignerMeta + : TAccountAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + mint: { value: input.mint ?? null, isWritable: true }, + authority: { value: input.authority ?? null, isWritable: true }, + }; + const accounts = originalAccounts as Record< + keyof typeof originalAccounts, + ResolvedAccount + >; + + // Original args. + const args = { ...input }; + + // Remaining accounts. + const remainingAccounts: IAccountMeta[] = (args.multiSigners ?? []).map( + (signer) => ({ + address: signer.address, + role: AccountRole.READONLY_SIGNER, + signer, + }) + ); + + const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); + const instruction = { + accounts: [ + getAccountMeta(accounts.mint), + getAccountMeta(accounts.authority), + ...remainingAccounts, + ], + programAddress, + data: getUpdateMultiplierScaledUiMintInstructionDataEncoder().encode( + args as UpdateMultiplierScaledUiMintInstructionDataArgs + ), + } as UpdateMultiplierScaledUiMintInstruction< + TProgramAddress, + TAccountMint, + (typeof input)['authority'] extends TransactionSigner + ? WritableSignerAccount & + IAccountSignerMeta + : TAccountAuthority + >; + + return instruction; +} + +export type ParsedUpdateMultiplierScaledUiMintInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The mint. */ + mint: TAccountMetas[0]; + /** The multiplier authority. */ + authority: TAccountMetas[1]; + }; + data: UpdateMultiplierScaledUiMintInstructionData; +}; + +export function parseUpdateMultiplierScaledUiMintInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedUpdateMultiplierScaledUiMintInstruction { + if (instruction.accounts.length < 2) { + // TODO: Coded error. + throw new Error('Not enough accounts'); + } + let accountIndex = 0; + const getNextAccount = () => { + const accountMeta = instruction.accounts![accountIndex]!; + accountIndex += 1; + return accountMeta; + }; + return { + programAddress: instruction.programAddress, + accounts: { + mint: getNextAccount(), + authority: getNextAccount(), + }, + data: getUpdateMultiplierScaledUiMintInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/programs/token2022.ts b/clients/js/src/generated/programs/token2022.ts index 1ba1d617..e3f41374 100644 --- a/clients/js/src/generated/programs/token2022.ts +++ b/clients/js/src/generated/programs/token2022.ts @@ -61,6 +61,7 @@ import { type ParsedInitializeMultisigInstruction, type ParsedInitializeNonTransferableMintInstruction, type ParsedInitializePermanentDelegateInstruction, + type ParsedInitializeScaledUiAmountMintInstruction, type ParsedInitializeTokenGroupInstruction, type ParsedInitializeTokenGroupMemberInstruction, type ParsedInitializeTokenMetadataInstruction, @@ -84,6 +85,7 @@ import { type ParsedUpdateGroupMemberPointerInstruction, type ParsedUpdateGroupPointerInstruction, type ParsedUpdateMetadataPointerInstruction, + type ParsedUpdateMultiplierScaledUiMintInstruction, type ParsedUpdateRateInterestBearingMintInstruction, type ParsedUpdateTokenGroupMaxSizeInstruction, type ParsedUpdateTokenGroupUpdateAuthorityInstruction, @@ -198,6 +200,8 @@ export enum Token2022Instruction { UpdateGroupPointer, InitializeGroupMemberPointer, UpdateGroupMemberPointer, + InitializeScaledUiAmountMint, + UpdateMultiplierScaledUiMint, InitializeTokenMetadata, UpdateTokenMetadataField, RemoveTokenMetadataKey, @@ -558,6 +562,18 @@ export function identifyToken2022Instruction( ) { return Token2022Instruction.UpdateGroupMemberPointer; } + if ( + containsBytes(data, getU8Encoder().encode(43), 0) && + containsBytes(data, getU8Encoder().encode(0), 1) + ) { + return Token2022Instruction.InitializeScaledUiAmountMint; + } + if ( + containsBytes(data, getU8Encoder().encode(43), 0) && + containsBytes(data, getU8Encoder().encode(1), 1) + ) { + return Token2022Instruction.UpdateMultiplierScaledUiMint; + } if ( containsBytes( data, @@ -858,6 +874,12 @@ export type ParsedToken2022Instruction< | ({ instructionType: Token2022Instruction.UpdateGroupMemberPointer; } & ParsedUpdateGroupMemberPointerInstruction) + | ({ + instructionType: Token2022Instruction.InitializeScaledUiAmountMint; + } & ParsedInitializeScaledUiAmountMintInstruction) + | ({ + instructionType: Token2022Instruction.UpdateMultiplierScaledUiMint; + } & ParsedUpdateMultiplierScaledUiMintInstruction) | ({ instructionType: Token2022Instruction.InitializeTokenMetadata; } & ParsedInitializeTokenMetadataInstruction) diff --git a/clients/js/src/generated/types/extension.ts b/clients/js/src/generated/types/extension.ts index 437cc5b2..e9190fc8 100644 --- a/clients/js/src/generated/types/extension.ts +++ b/clients/js/src/generated/types/extension.ts @@ -16,6 +16,8 @@ import { getBooleanEncoder, getDiscriminatedUnionDecoder, getDiscriminatedUnionEncoder, + getF64Decoder, + getF64Encoder, getI16Decoder, getI16Encoder, getMapDecoder, @@ -263,6 +265,14 @@ export type Extension = group: Address; /** The member number. */ memberNumber: bigint; + } + | { __kind: 'ConfidentialMintBurn' } + | { + __kind: 'ScaledUiAmountConfig'; + authority: Address; + multiplier: number; + newMultiplierEffectiveTimestamp: bigint; + newMultiplier: number; }; export type ExtensionArgs = @@ -466,6 +476,14 @@ export type ExtensionArgs = group: Address; /** The member number. */ memberNumber: number | bigint; + } + | { __kind: 'ConfidentialMintBurn' } + | { + __kind: 'ScaledUiAmountConfig'; + authority: Address; + multiplier: number; + newMultiplierEffectiveTimestamp: number | bigint; + newMultiplier: number; }; export function getExtensionEncoder(): Encoder { @@ -760,6 +778,19 @@ export function getExtensionEncoder(): Encoder { getU16Encoder() ), ], + ['ConfidentialMintBurn', getUnitEncoder()], + [ + 'ScaledUiAmountConfig', + addEncoderSizePrefix( + getStructEncoder([ + ['authority', getAddressEncoder()], + ['multiplier', getF64Encoder()], + ['newMultiplierEffectiveTimestamp', getU64Encoder()], + ['newMultiplier', getF64Encoder()], + ]), + getU16Encoder() + ), + ], ], { size: getU16Encoder() } ); @@ -1057,6 +1088,19 @@ export function getExtensionDecoder(): Decoder { getU16Decoder() ), ], + ['ConfidentialMintBurn', getUnitDecoder()], + [ + 'ScaledUiAmountConfig', + addDecoderSizePrefix( + getStructDecoder([ + ['authority', getAddressDecoder()], + ['multiplier', getF64Decoder()], + ['newMultiplierEffectiveTimestamp', getU64Decoder()], + ['newMultiplier', getF64Decoder()], + ]), + getU16Decoder() + ), + ], ], { size: getU16Decoder() } ); @@ -1274,6 +1318,25 @@ export function extension( 'TokenGroupMember' > ): GetDiscriminatedUnionVariant; +export function extension( + kind: 'ConfidentialMintBurn' +): GetDiscriminatedUnionVariant< + ExtensionArgs, + '__kind', + 'ConfidentialMintBurn' +>; +export function extension( + kind: 'ScaledUiAmountConfig', + data: GetDiscriminatedUnionVariantContent< + ExtensionArgs, + '__kind', + 'ScaledUiAmountConfig' + > +): GetDiscriminatedUnionVariant< + ExtensionArgs, + '__kind', + 'ScaledUiAmountConfig' +>; export function extension( kind: K, data?: Data diff --git a/clients/js/src/generated/types/extensionType.ts b/clients/js/src/generated/types/extensionType.ts index c441808d..2acc0f72 100644 --- a/clients/js/src/generated/types/extensionType.ts +++ b/clients/js/src/generated/types/extensionType.ts @@ -42,6 +42,7 @@ export enum ExtensionType { TransferHookAccount, ConfidentialTransferFee, ConfidentialTransferFeeAmount, + ScaledUiAmountConfig, MetadataPointer, TokenMetadata, GroupPointer, diff --git a/clients/js/src/getInitializeInstructionsForExtensions.ts b/clients/js/src/getInitializeInstructionsForExtensions.ts index ed46b029..f7d28fe4 100644 --- a/clients/js/src/getInitializeInstructionsForExtensions.ts +++ b/clients/js/src/getInitializeInstructionsForExtensions.ts @@ -25,6 +25,7 @@ import { getInitializeNonTransferableMintInstruction, getInitializeTransferHookInstruction, getInitializePermanentDelegateInstruction, + getInitializeScaledUiAmountMintInstruction, getInitializeConfidentialTransferFeeInstruction, } from './generated'; @@ -80,6 +81,14 @@ export function getPreInitializeInstructionsForMintExtensions( rate: extension.currentRate, }), ]; + case 'ScaledUiAmountConfig': + return [ + getInitializeScaledUiAmountMintInstruction({ + mint, + authority: extension.authority, + multiplier: extension.multiplier, + }), + ]; case 'GroupPointer': return [ getInitializeGroupPointerInstruction({ diff --git a/clients/js/test/extensions/interestBearingMint/initializeInterestBearingMint.test.ts b/clients/js/test/extensions/interestBearingMint/initializeInterestBearingMint.test.ts index d7af55f1..640943b8 100644 --- a/clients/js/test/extensions/interestBearingMint/initializeInterestBearingMint.test.ts +++ b/clients/js/test/extensions/interestBearingMint/initializeInterestBearingMint.test.ts @@ -14,6 +14,7 @@ import { } from '../../../src'; test('it initialize a mint account with an interest bearing mint extension', async (t) => { + // Given a fresh client with no state the test cares about. const client = createDefaultSolanaClient(); const [rateAuthority, mint] = await Promise.all([ generateKeyPairSignerWithSol(client), @@ -28,7 +29,7 @@ test('it initialize a mint account with an interest bearing mint extension', asy rateAuthority: rateAuthority.address, initializationTimestamp: BigInt(Math.floor(new Date().getTime() / 1000)), lastUpdateTimestamp: BigInt(Math.floor(new Date().getTime() / 1000)), - preUpdateAverageRate: 10000, + preUpdateAverageRate: rate, currentRate: rate, }); @@ -52,27 +53,32 @@ test('it initialize a mint account with an interest bearing mint extension', asy ]); const mintAccount = await fetchMint(client.rpc, mint.address); + // Then the mint account exists. + t.like(mintAccount, >{ + address: mint.address, + }); const extensions = mintAccount.data.extensions; + // And the mint account has an interest bearing mint extension. t.true(isSome(extensions)); t.true( isSome(extensions) && extensions.value[0].__kind === 'InterestBearingConfig' ); - // check without need to check timestamp specifically if ( isSome(extensions) && extensions.value[0].__kind === 'InterestBearingConfig' ) { + // And the extension has the correct rate authority. t.is(extensions.value[0].rateAuthority, rateAuthority.address); + // And the extension has the correct initialization timestamp. t.true(typeof extensions.value[0].initializationTimestamp === 'bigint'); + // And the extension has the correct last update timestamp. t.true(typeof extensions.value[0].lastUpdateTimestamp === 'bigint'); + // And the extension has the correct pre update average rate. t.is(extensions.value[0].preUpdateAverageRate, rate); + // And the extension has the correct current rate. t.is(extensions.value[0].currentRate, rate); } - - t.like(mintAccount, >{ - address: mint.address, - }); }); diff --git a/clients/js/test/extensions/interestBearingMint/updateInterestBearingMint.test.ts b/clients/js/test/extensions/interestBearingMint/updateInterestBearingMint.test.ts index e38b9704..a62ac184 100644 --- a/clients/js/test/extensions/interestBearingMint/updateInterestBearingMint.test.ts +++ b/clients/js/test/extensions/interestBearingMint/updateInterestBearingMint.test.ts @@ -23,7 +23,7 @@ test('it updates the interest bearing mint extension on a mint account', async ( const oldRate = 10000; const newRate = 20000; - // initialize mint with interest bearing mint extension + // And a mint with an interest bearing mint extension. const mint = await createMint({ authority: rateAuthority, client, @@ -41,7 +41,7 @@ test('it updates the interest bearing mint extension on a mint account', async ( payer: rateAuthority, }); - // then we update the interest bearing mint extension on the mint account + // When we update the interest bearing mint extension on the mint account await sendAndConfirmInstructions(client, rateAuthority, [ getUpdateRateInterestBearingMintInstruction({ rateAuthority: rateAuthority, @@ -51,10 +51,12 @@ test('it updates the interest bearing mint extension on a mint account', async ( ]); const mintAccount = await fetchMint(client.rpc, mint); + t.like(mintAccount, >{ + address: mint, + }); - // check without need to check timestamp specifically + // Then the mint account has an interest bearing mint extension. const extensions = mintAccount.data.extensions; - t.true(isSome(extensions)); t.true( isSome(extensions) && extensions.value[0].__kind === 'InterestBearingConfig' @@ -64,14 +66,15 @@ test('it updates the interest bearing mint extension on a mint account', async ( isSome(extensions) && extensions.value[0].__kind === 'InterestBearingConfig' ) { + // And the extension has the correct rate authority. t.is(extensions.value[0].rateAuthority, rateAuthority.address); + // And the extension has the correct initialization timestamp. t.true(typeof extensions.value[0].initializationTimestamp === 'bigint'); + // And the extension has the correct last update timestamp. t.true(typeof extensions.value[0].lastUpdateTimestamp === 'bigint'); + // And the extension has the correct pre update average rate. t.is(extensions.value[0].preUpdateAverageRate, oldRate); + // And the extension has the correct new current rate. t.is(extensions.value[0].currentRate, newRate); } - - t.like(mintAccount, >{ - address: mint, - }); }); diff --git a/clients/js/test/extensions/scaledUiAmountMint/initializeScaledUiAmountMint.test.ts b/clients/js/test/extensions/scaledUiAmountMint/initializeScaledUiAmountMint.test.ts new file mode 100644 index 00000000..19d8a9e2 --- /dev/null +++ b/clients/js/test/extensions/scaledUiAmountMint/initializeScaledUiAmountMint.test.ts @@ -0,0 +1,86 @@ +import test from 'ava'; +import { + createDefaultSolanaClient, + generateKeyPairSignerWithSol, + getCreateMintInstructions, + sendAndConfirmInstructions, +} from '../../_setup'; +import { Account, generateKeyPairSigner, isSome } from '@solana/kit'; +import { + extension, + fetchMint, + getInitializeScaledUiAmountMintInstruction, + Mint, +} from '../../../src'; + +test('it initialize a mint account with a scaled ui amount mint extension', async (t) => { + // Given a fresh client with no state the test cares about. + const client = createDefaultSolanaClient(); + const [authority, mint] = await Promise.all([ + generateKeyPairSignerWithSol(client), + generateKeyPairSigner(), + ]); + + const multiplier = 1; + const newMultiplier = 2; + + // And a scaled ui amount mint extension. + const scaledUiAmountMintExtension = extension('ScaledUiAmountConfig', { + authority: authority.address, + multiplier, + newMultiplierEffectiveTimestamp: BigInt( + Math.floor(new Date().getTime() / 1000) + ), + newMultiplier, + }); + + // When we initialize the mint account with the scaled ui amount mint extension. + const [createMintInstruction, initMintInstruction] = + await getCreateMintInstructions({ + authority: authority.address, + client, + decimals: 2, + extensions: [scaledUiAmountMintExtension], + mint, + payer: authority, + }); + await sendAndConfirmInstructions(client, authority, [ + createMintInstruction, + getInitializeScaledUiAmountMintInstruction({ + mint: mint.address, + authority: authority.address, + multiplier, + }), + initMintInstruction, + ]); + + const mintAccount = await fetchMint(client.rpc, mint.address); + // Then the mint account exists. + t.like(mintAccount, >{ + address: mint.address, + }); + + const extensions = mintAccount.data.extensions; + + // And the mint account has a scaled ui amount mint extension. + t.true(isSome(extensions)); + t.true( + isSome(extensions) && extensions.value[0].__kind === 'ScaledUiAmountConfig' + ); + + if ( + isSome(extensions) && + extensions.value[0].__kind === 'ScaledUiAmountConfig' + ) { + // And the extension has the correct authority. + t.is(extensions.value[0].authority, authority.address); + // And the extension has the correct multiplier. + t.is(extensions.value[0].multiplier, multiplier); + // And the extension has the correct new multiplier effective timestamp. + t.true( + typeof extensions.value[0].newMultiplierEffectiveTimestamp === 'bigint' + ); + // And the extension has the correct new multiplier which is not changed due to how the extension is initialized. + t.is(extensions.value[0].newMultiplier, multiplier); + } +}); diff --git a/clients/js/test/extensions/scaledUiAmountMint/updateScaledUiAmountMint.test.ts b/clients/js/test/extensions/scaledUiAmountMint/updateScaledUiAmountMint.test.ts new file mode 100644 index 00000000..56bc319e --- /dev/null +++ b/clients/js/test/extensions/scaledUiAmountMint/updateScaledUiAmountMint.test.ts @@ -0,0 +1,76 @@ +import test from 'ava'; +import { + createDefaultSolanaClient, + createMint, + generateKeyPairSignerWithSol, + sendAndConfirmInstructions, +} from '../../_setup'; +import { isSome } from '@solana/kit'; +import { + extension, + fetchMint, + getUpdateMultiplierScaledUiMintInstruction, +} from '../../../src'; + +test('it updates the multiplier of the scaled ui amount mint extension on a mint account', async (t) => { + // Given some signer accounts. + const client = createDefaultSolanaClient(); + const [multiplierAuthority] = await Promise.all([ + generateKeyPairSignerWithSol(client), + ]); + + const oldMultiplier = 1; + const newMultiplier = 2; + + // And a mint with a scaled ui amount mint extension. + const mint = await createMint({ + authority: multiplierAuthority, + client, + extensions: [ + extension('ScaledUiAmountConfig', { + authority: multiplierAuthority.address, + multiplier: oldMultiplier, + newMultiplierEffectiveTimestamp: BigInt( + Math.floor(new Date().getTime() * 2) + ), + newMultiplier: oldMultiplier, + }), + ], + payer: multiplierAuthority, + }); + + // When we update the scaled ui amount mint extension on the mint account + await sendAndConfirmInstructions(client, multiplierAuthority, [ + getUpdateMultiplierScaledUiMintInstruction({ + mint, + authority: multiplierAuthority.address, + multiplier: newMultiplier, + effectiveTimestamp: BigInt(Math.floor(new Date().getTime() / 1000)), + }), + ]); + + const mintAccount = await fetchMint(client.rpc, mint); + + // Then the mint account has a scaled ui amount mint extension. + const extensions = mintAccount.data.extensions; + t.true(isSome(extensions)); + t.true( + isSome(extensions) && extensions.value[0].__kind === 'ScaledUiAmountConfig' + ); + + if ( + isSome(extensions) && + extensions.value[0].__kind === 'ScaledUiAmountConfig' + ) { + // And the extension has the correct authority. + t.is(extensions.value[0].authority, multiplierAuthority.address); + // And the extension has the correct multiplier. + t.true(typeof extensions.value[0].multiplier === 'number'); + // And the extension has the correct new multiplier effective timestamp. + t.true( + typeof extensions.value[0].newMultiplierEffectiveTimestamp === 'bigint' + ); + // And the extension has the correct new multiplier. + t.is(extensions.value[0].newMultiplier, newMultiplier); + } +}); diff --git a/program/idl.json b/program/idl.json index 8557094f..e9b1c48f 100644 --- a/program/idl.json +++ b/program/idl.json @@ -7322,6 +7322,199 @@ } ] }, + { + "kind": "instructionNode", + "name": "initializeScaledUiAmountMint", + "docs": [ + "Initialize a new mint with the `ScaledUiAmount` extension.", + "", + "Fails if the mint has already been initialized, so must be called before `InitializeMint`.", + "", + "The mint must have exactly enough space allocated for the base mint (82 bytes),", + "plus 83 bytes of padding, 1 byte reserved for the account type,", + "then space required for this extension, plus any others." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "mint", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The mint to initialize."] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 43 + } + }, + { + "kind": "instructionArgumentNode", + "name": "scaledUiAmountMintDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 0 + } + }, + { + "kind": "instructionArgumentNode", + "name": "authority", + "docs": ["The authority that can update the multiplier"], + "type": { + "kind": "zeroableOptionTypeNode", + "item": { + "kind": "publicKeyTypeNode" + } + } + }, + { + "kind": "instructionArgumentNode", + "name": "multiplier", + "docs": ["The initial multiplier for the scaled UI extension"], + "type": { + "kind": "numberTypeNode", + "format": "f64", + "endian": "le" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "scaledUiAmountMintDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "updateMultiplierScaledUiMint", + "docs": [ + "Update the multiplier. Only supported for mints that include the", + "`ScaledUiAmountConfig` extension.", + "You can set a specific timestamp for the multiplier to take effect." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "mint", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The mint."] + }, + { + "kind": "instructionAccountNode", + "name": "authority", + "isWritable": true, + "isSigner": "either", + "isOptional": false, + "docs": ["The multiplier authority."] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 43 + } + }, + { + "kind": "instructionArgumentNode", + "name": "scaledUiAmountMintDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 1 + } + }, + { + "kind": "instructionArgumentNode", + "name": "multiplier", + "docs": ["The new multiplier for the scaled UI extension"], + "type": { + "kind": "numberTypeNode", + "format": "f64", + "endian": "le" + } + }, + { + "kind": "instructionArgumentNode", + "name": "effectiveTimestamp", + "docs": ["The timestamp at which the new multiplier will take effect"], + "type": { + "kind": "numberTypeNode", + "format": "i64", + "endian": "le" + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "scaledUiAmountMintDiscriminator", + "offset": 1 + } + ] + }, { "kind": "instructionNode", "name": "initializeTokenMetadata", @@ -9303,6 +9496,65 @@ "endian": "le" } } + }, + { + "kind": "enumEmptyVariantTypeNode", + "name": "confidentialMintBurn" + }, + { + "kind": "enumStructVariantTypeNode", + "name": "scaledUiAmountConfig", + "struct": { + "kind": "sizePrefixTypeNode", + "type": { + "kind": "structTypeNode", + "fields": [ + { + "kind": "structFieldTypeNode", + "name": "authority", + "docs": [], + "type": { + "kind": "publicKeyTypeNode" + } + }, + { + "kind": "structFieldTypeNode", + "name": "multiplier", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "f64", + "endian": "le" + } + }, + { + "kind": "structFieldTypeNode", + "name": "newMultiplierEffectiveTimestamp", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u64", + "endian": "le" + } + }, + { + "kind": "structFieldTypeNode", + "name": "newMultiplier", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "f64", + "endian": "le" + } + } + ] + }, + "prefix": { + "kind": "numberTypeNode", + "format": "u16", + "endian": "le" + } + } } ], "size": { @@ -9436,6 +9688,11 @@ "name": "confidentialTransferFeeAmount", "docs": ["Includes confidential withheld transfer fees"] }, + { + "kind": "enumEmptyVariantTypeNode", + "name": "scaledUiAmountConfig", + "docs": ["Tokens have a scaled UI amount"] + }, { "kind": "enumEmptyVariantTypeNode", "name": "metadataPointer",