Skip to content

[JS] Add Scaled UI Amount Extension Support #267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 11, 2025
Merged
Show file tree
Hide file tree
Changes from 5 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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
2 changes: 2 additions & 0 deletions clients/js/src/generated/instructions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';
Expand Down
212 changes: 212 additions & 0 deletions clients/js/src/generated/instructions/initializeScaledUiAmountMint.ts
Original file line number Diff line number Diff line change
@@ -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/web3.js';
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> = string,
TRemainingAccounts extends readonly IAccountMeta<string>[] = [],
> = IInstruction<TProgram> &
IInstructionWithData<Uint8Array> &
IInstructionWithAccounts<
[
TAccountMint extends string
? WritableAccount<TAccountMint>
: TAccountMint,
...TRemainingAccounts,
]
>;

export type InitializeScaledUiAmountMintInstructionData = {
discriminator: number;
scaledUiAmountMintDiscriminator: number;
/** The authority that can update the multiplier */
authority: Option<Address>;
/** The initial multiplier for the scaled UI extension */
multiplier: number;
};

export type InitializeScaledUiAmountMintInstructionDataArgs = {
/** The authority that can update the multiplier */
authority: OptionOrNullable<Address>;
/** The initial multiplier for the scaled UI extension */
multiplier: number;
};

export function getInitializeScaledUiAmountMintInstructionDataEncoder(): Encoder<InitializeScaledUiAmountMintInstructionDataArgs> {
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<InitializeScaledUiAmountMintInstructionData> {
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<TAccountMint>;
authority: InitializeScaledUiAmountMintInstructionDataArgs['authority'];
multiplier: InitializeScaledUiAmountMintInstructionDataArgs['multiplier'];
};

export function getInitializeScaledUiAmountMintInstruction<
TAccountMint extends string,
TProgramAddress extends Address = typeof TOKEN_2022_PROGRAM_ADDRESS,
>(
input: InitializeScaledUiAmountMintInput<TAccountMint>,
config?: { programAddress?: TProgramAddress }
): InitializeScaledUiAmountMintInstruction<TProgramAddress, TAccountMint> {
// 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<TProgramAddress, TAccountMint>;

return instruction;
}

export type ParsedInitializeScaledUiAmountMintInstruction<
TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS,
TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[],
> = {
programAddress: Address<TProgram>;
accounts: {
/** The mint to initialize. */
mint: TAccountMetas[0];
};
data: InitializeScaledUiAmountMintInstructionData;
};

export function parseInitializeScaledUiAmountMintInstruction<
TProgram extends string,
TAccountMetas extends readonly IAccountMeta[],
>(
instruction: IInstruction<TProgram> &
IInstructionWithAccounts<TAccountMetas> &
IInstructionWithData<Uint8Array>
): ParsedInitializeScaledUiAmountMintInstruction<TProgram, TAccountMetas> {
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
),
};
}
Loading
Loading