Skip to content

Commit

Permalink
added CreateNativeMint instruction , idl ,corrected discriminator , a…
Browse files Browse the repository at this point in the history
…dded multisginer support
  • Loading branch information
adpthegreat committed Nov 13, 2024
1 parent 4bc93aa commit d8c556a
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 84 deletions.
5 changes: 2 additions & 3 deletions clients/js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@
"rewritePaths": {
"test/": "dist/test/"
}
},
"timeout": "60s"
}
},
"packageManager": "[email protected]"
}
}
17 changes: 16 additions & 1 deletion clients/js/src/generated/instructions/createNativeMint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import {
AccountRole,
combineCodec,
getStructDecoder,
getStructEncoder,
Expand All @@ -30,7 +31,7 @@ import {
import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory, type ResolvedAccount } from '../shared';

export const CREATE_NATIVE_MINT_DISCRIMINATOR = 27;
export const CREATE_NATIVE_MINT_DISCRIMINATOR = 31;

export function getCreateNativeMintDiscriminatorBytes() {
return getU8Encoder().encode(CREATE_NATIVE_MINT_DISCRIMINATOR);
Expand Down Expand Up @@ -98,6 +99,7 @@ export type CreateNativeMintInput<
nativeMint: Address<TAccountNativeMint>;
/** System program for mint account funding */
systemProgram?: Address<TAccountSystemProgram>;
multiSigners?: Array<TransactionSigner>;
};

export function getCreateNativeMintInstruction<
Expand Down Expand Up @@ -132,18 +134,31 @@ export function getCreateNativeMintInstruction<
ResolvedAccount
>;

// Original args.
const args = { ...input };

// Resolve default values.
if (!accounts.systemProgram.value) {
accounts.systemProgram.value =
'11111111111111111111111111111111' as Address<'11111111111111111111111111111111'>;
}

// 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.payer),
getAccountMeta(accounts.nativeMint),
getAccountMeta(accounts.systemProgram),
...remainingAccounts,
],
programAddress,
data: getCreateNativeMintInstructionDataEncoder().encode({}),
Expand Down
14 changes: 7 additions & 7 deletions clients/js/src/generated/programs/token2022.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ export function identifyToken2022Account(

export enum Token2022Instruction {
InitializeMint,
CreateNativeMint,
InitializeAccount,
InitializeMultisig,
Transfer,
Expand Down Expand Up @@ -165,6 +164,7 @@ export enum Token2022Instruction {
Reallocate,
EnableMemoTransfers,
DisableMemoTransfers,
CreateNativeMint,
InitializeNonTransferableMint,
EnableCpiGuard,
DisableCpiGuard,
Expand Down Expand Up @@ -192,9 +192,6 @@ export function identifyToken2022Instruction(
if (containsBytes(data, getU8Encoder().encode(0), 0)) {
return Token2022Instruction.InitializeMint;
}
if (containsBytes(data, getU8Encoder().encode(27), 0)) {
return Token2022Instruction.CreateNativeMint;
}
if (containsBytes(data, getU8Encoder().encode(1), 0)) {
return Token2022Instruction.InitializeAccount;
}
Expand Down Expand Up @@ -417,6 +414,9 @@ export function identifyToken2022Instruction(
) {
return Token2022Instruction.DisableMemoTransfers;
}
if (containsBytes(data, getU8Encoder().encode(31), 0)) {
return Token2022Instruction.CreateNativeMint;
}
if (containsBytes(data, getU8Encoder().encode(32), 0)) {
return Token2022Instruction.InitializeNonTransferableMint;
}
Expand Down Expand Up @@ -552,9 +552,6 @@ export type ParsedToken2022Instruction<
| ({
instructionType: Token2022Instruction.InitializeMint;
} & ParsedInitializeMintInstruction<TProgram>)
| ({
instructionType: Token2022Instruction.CreateNativeMint;
} & ParsedCreateNativeMintInstruction<TProgram>)
| ({
instructionType: Token2022Instruction.InitializeAccount;
} & ParsedInitializeAccountInstruction<TProgram>)
Expand Down Expand Up @@ -705,6 +702,9 @@ export type ParsedToken2022Instruction<
| ({
instructionType: Token2022Instruction.DisableMemoTransfers;
} & ParsedDisableMemoTransfersInstruction<TProgram>)
| ({
instructionType: Token2022Instruction.CreateNativeMint;
} & ParsedCreateNativeMintInstruction<TProgram>)
| ({
instructionType: Token2022Instruction.InitializeNonTransferableMint;
} & ParsedInitializeNonTransferableMintInstruction<TProgram>)
Expand Down
2 changes: 1 addition & 1 deletion clients/js/test/createNativeMint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test('it creates a native mint account', async (t) => {

// When we create a native mint account.
await sendAndConfirmInstructions(client, payer, [
getCreateNativeMintInstruction({
getCreateNativeMintInstruction({
payer: payer,
nativeMint: NATIVE_MINT,
})
Expand Down
150 changes: 78 additions & 72 deletions program/idl.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,78 +461,6 @@
}
]
},
{
"kind": "instructionNode",
"name": "createNativeMint",
"docs": [
"Creates the native mint.",
"",
"This instruction only needs to be invoked once after deployment and is",
"permissionless. Wrapped SOL (`native_mint::id()`) will not be",
"available until this instruction is successfully executed."
],
"optionalAccountStrategy": "programId",
"accounts": [
{
"kind": "instructionAccountNode",
"name": "payer",
"isWritable": true,
"isSigner": true,
"isOptional": false,
"docs": [
"Funding account (must be a system account)"
]
},
{
"kind": "instructionAccountNode",
"name": "nativeMint",
"isWritable": true,
"isSigner": false,
"isOptional": false,
"docs": [
"The native mint address"
]
},
{
"kind": "instructionAccountNode",
"name": "systemProgram",
"isWritable": false,
"isSigner": false,
"isOptional": false,
"docs": [
"System program for mint account funding"
],
"defaultValue": {
"kind": "publicKeyValueNode",
"publicKey": "11111111111111111111111111111111"
}
}
],
"arguments": [
{
"kind": "instructionArgumentNode",
"name": "discriminator",
"defaultValueStrategy": "omitted",
"docs": [],
"type": {
"kind": "numberTypeNode",
"format": "u8",
"endian": "le"
},
"defaultValue": {
"kind": "numberValueNode",
"number": 27
}
}
],
"discriminators": [
{
"kind": "fieldDiscriminatorNode",
"name": "discriminator",
"offset": 0
}
]
},
{
"kind": "instructionNode",
"name": "initializeAccount",
Expand Down Expand Up @@ -5417,6 +5345,84 @@
}
]
},
{
"kind": "instructionNode",
"name": "createNativeMint",
"docs": [
"Creates the native mint.",
"",
"This instruction only needs to be invoked once after deployment and is",
"permissionless. Wrapped SOL (`native_mint::id()`) will not be",
"available until this instruction is successfully executed."
],
"optionalAccountStrategy": "programId",
"accounts": [
{
"kind": "instructionAccountNode",
"name": "payer",
"isWritable": true,
"isSigner": true,
"isOptional": false,
"docs": ["Funding account (must be a system account)"]
},
{
"kind": "instructionAccountNode",
"name": "nativeMint",
"isWritable": true,
"isSigner": false,
"isOptional": false,
"docs": ["The native mint address"]
},
{
"kind": "instructionAccountNode",
"name": "systemProgram",
"isWritable": false,
"isSigner": false,
"isOptional": false,
"docs": ["System program for mint account funding"],
"defaultValue": {
"kind": "publicKeyValueNode",
"publicKey": "11111111111111111111111111111111"
}
}
],
"arguments": [
{
"kind": "instructionArgumentNode",
"name": "discriminator",
"defaultValueStrategy": "omitted",
"docs": [],
"type": {
"kind": "numberTypeNode",
"format": "u8",
"endian": "le"
},
"defaultValue": {
"kind": "numberValueNode",
"number": 31
}
}
],
"remainingAccounts": [
{
"kind": "instructionRemainingAccountsNode",
"isOptional": true,
"isSigner": true,
"docs": [],
"value": {
"kind": "argumentValueNode",
"name": "multiSigners"
}
}
],
"discriminators": [
{
"kind": "fieldDiscriminatorNode",
"name": "discriminator",
"offset": 0
}
]
},
{
"kind": "instructionNode",
"name": "initializeNonTransferableMint",
Expand Down

0 comments on commit d8c556a

Please sign in to comment.