From e851b7b8762c312e2f8f6b9ae0a253cde3248567 Mon Sep 17 00:00:00 2001 From: Loris Leiva Date: Thu, 10 Oct 2024 16:46:33 +0100 Subject: [PATCH] Define IDL instructions for group member pointer extension (#18) * Add instructions * Add tests --- .../js/src/generated/instructions/index.ts | 2 + .../initializeGroupMemberPointer.ts | 222 +++++++++++++++ .../instructions/updateGroupMemberPointer.ts | 258 ++++++++++++++++++ .../js/src/generated/programs/token2022.ts | 24 +- .../getInitializeInstructionsForExtensions.ts | 9 + .../initializeGroupMemberPointer.test.ts | 60 ++++ .../updateGroupMemberPointer.test.ts | 61 +++++ program/idl.json | 189 +++++++++++++ 8 files changed, 824 insertions(+), 1 deletion(-) create mode 100644 clients/js/src/generated/instructions/initializeGroupMemberPointer.ts create mode 100644 clients/js/src/generated/instructions/updateGroupMemberPointer.ts create mode 100644 clients/js/test/extensions/groupMemberPointer/initializeGroupMemberPointer.test.ts create mode 100644 clients/js/test/extensions/groupMemberPointer/updateGroupMemberPointer.test.ts diff --git a/clients/js/src/generated/instructions/index.ts b/clients/js/src/generated/instructions/index.ts index 6543bef..cd9e13a 100644 --- a/clients/js/src/generated/instructions/index.ts +++ b/clients/js/src/generated/instructions/index.ts @@ -36,6 +36,7 @@ export * from './initializeAccount2'; export * from './initializeAccount3'; export * from './initializeConfidentialTransferMint'; export * from './initializeDefaultAccountState'; +export * from './initializeGroupMemberPointer'; export * from './initializeGroupPointer'; export * from './initializeImmutableOwner'; export * from './initializeMetadataPointer'; @@ -60,6 +61,7 @@ export * from './transferCheckedWithFee'; export * from './uiAmountToAmount'; export * from './updateConfidentialTransferMint'; export * from './updateDefaultAccountState'; +export * from './updateGroupMemberPointer'; export * from './updateGroupPointer'; export * from './updateMetadataPointer'; export * from './withdrawWithheldTokensFromAccounts'; diff --git a/clients/js/src/generated/instructions/initializeGroupMemberPointer.ts b/clients/js/src/generated/instructions/initializeGroupMemberPointer.ts new file mode 100644 index 0000000..7d6ece4 --- /dev/null +++ b/clients/js/src/generated/instructions/initializeGroupMemberPointer.ts @@ -0,0 +1,222 @@ +/** + * 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, + 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_GROUP_MEMBER_POINTER_DISCRIMINATOR = 41; + +export function getInitializeGroupMemberPointerDiscriminatorBytes() { + return getU8Encoder().encode(INITIALIZE_GROUP_MEMBER_POINTER_DISCRIMINATOR); +} + +export const INITIALIZE_GROUP_MEMBER_POINTER_GROUP_MEMBER_POINTER_DISCRIMINATOR = 0; + +export function getInitializeGroupMemberPointerGroupMemberPointerDiscriminatorBytes() { + return getU8Encoder().encode( + INITIALIZE_GROUP_MEMBER_POINTER_GROUP_MEMBER_POINTER_DISCRIMINATOR + ); +} + +export type InitializeGroupMemberPointerInstruction< + 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 InitializeGroupMemberPointerInstructionData = { + discriminator: number; + groupMemberPointerDiscriminator: number; + /** The public key for the account that can update the group member address. */ + authority: Option
; + /** The account address that holds the member. */ + memberAddress: Option
; +}; + +export type InitializeGroupMemberPointerInstructionDataArgs = { + /** The public key for the account that can update the group member address. */ + authority: OptionOrNullable
; + /** The account address that holds the member. */ + memberAddress: OptionOrNullable
; +}; + +export function getInitializeGroupMemberPointerInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['groupMemberPointerDiscriminator', getU8Encoder()], + [ + 'authority', + getOptionEncoder(getAddressEncoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + [ + 'memberAddress', + getOptionEncoder(getAddressEncoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ]), + (value) => ({ + ...value, + discriminator: INITIALIZE_GROUP_MEMBER_POINTER_DISCRIMINATOR, + groupMemberPointerDiscriminator: + INITIALIZE_GROUP_MEMBER_POINTER_GROUP_MEMBER_POINTER_DISCRIMINATOR, + }) + ); +} + +export function getInitializeGroupMemberPointerInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['groupMemberPointerDiscriminator', getU8Decoder()], + [ + 'authority', + getOptionDecoder(getAddressDecoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + [ + 'memberAddress', + getOptionDecoder(getAddressDecoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ]); +} + +export function getInitializeGroupMemberPointerInstructionDataCodec(): Codec< + InitializeGroupMemberPointerInstructionDataArgs, + InitializeGroupMemberPointerInstructionData +> { + return combineCodec( + getInitializeGroupMemberPointerInstructionDataEncoder(), + getInitializeGroupMemberPointerInstructionDataDecoder() + ); +} + +export type InitializeGroupMemberPointerInput< + TAccountMint extends string = string, +> = { + /** The mint to initialize. */ + mint: Address; + authority: InitializeGroupMemberPointerInstructionDataArgs['authority']; + memberAddress: InitializeGroupMemberPointerInstructionDataArgs['memberAddress']; +}; + +export function getInitializeGroupMemberPointerInstruction< + TAccountMint extends string, + TProgramAddress extends Address = typeof TOKEN_2022_PROGRAM_ADDRESS, +>( + input: InitializeGroupMemberPointerInput, + config?: { programAddress?: TProgramAddress } +): InitializeGroupMemberPointerInstruction { + // 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: getInitializeGroupMemberPointerInstructionDataEncoder().encode( + args as InitializeGroupMemberPointerInstructionDataArgs + ), + } as InitializeGroupMemberPointerInstruction; + + return instruction; +} + +export type ParsedInitializeGroupMemberPointerInstruction< + 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: InitializeGroupMemberPointerInstructionData; +}; + +export function parseInitializeGroupMemberPointerInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedInitializeGroupMemberPointerInstruction { + 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: getInitializeGroupMemberPointerInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/instructions/updateGroupMemberPointer.ts b/clients/js/src/generated/instructions/updateGroupMemberPointer.ts new file mode 100644 index 0000000..133e84a --- /dev/null +++ b/clients/js/src/generated/instructions/updateGroupMemberPointer.ts @@ -0,0 +1,258 @@ +/** + * 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, + getAddressDecoder, + getAddressEncoder, + getOptionDecoder, + getOptionEncoder, + getStructDecoder, + getStructEncoder, + getU8Decoder, + getU8Encoder, + transformEncoder, + type Address, + type Codec, + type Decoder, + type Encoder, + type IAccountMeta, + type IAccountSignerMeta, + type IInstruction, + type IInstructionWithAccounts, + type IInstructionWithData, + type Option, + type OptionOrNullable, + type ReadonlyAccount, + type ReadonlySignerAccount, + type TransactionSigner, + type WritableAccount, +} from '@solana/web3.js'; +import { TOKEN_2022_PROGRAM_ADDRESS } from '../programs'; +import { getAccountMetaFactory, type ResolvedAccount } from '../shared'; + +export const UPDATE_GROUP_MEMBER_POINTER_DISCRIMINATOR = 41; + +export function getUpdateGroupMemberPointerDiscriminatorBytes() { + return getU8Encoder().encode(UPDATE_GROUP_MEMBER_POINTER_DISCRIMINATOR); +} + +export const UPDATE_GROUP_MEMBER_POINTER_GROUP_MEMBER_POINTER_DISCRIMINATOR = 1; + +export function getUpdateGroupMemberPointerGroupMemberPointerDiscriminatorBytes() { + return getU8Encoder().encode( + UPDATE_GROUP_MEMBER_POINTER_GROUP_MEMBER_POINTER_DISCRIMINATOR + ); +} + +export type UpdateGroupMemberPointerInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMint extends string | IAccountMeta = string, + TAccountGroupMemberPointerAuthority extends + | string + | IAccountMeta = string, + TRemainingAccounts extends readonly IAccountMeta[] = [], +> = IInstruction & + IInstructionWithData & + IInstructionWithAccounts< + [ + TAccountMint extends string + ? WritableAccount + : TAccountMint, + TAccountGroupMemberPointerAuthority extends string + ? ReadonlyAccount + : TAccountGroupMemberPointerAuthority, + ...TRemainingAccounts, + ] + >; + +export type UpdateGroupMemberPointerInstructionData = { + discriminator: number; + groupMemberPointerDiscriminator: number; + /** The new account address that holds the member. */ + memberAddress: Option
; +}; + +export type UpdateGroupMemberPointerInstructionDataArgs = { + /** The new account address that holds the member. */ + memberAddress: OptionOrNullable
; +}; + +export function getUpdateGroupMemberPointerInstructionDataEncoder(): Encoder { + return transformEncoder( + getStructEncoder([ + ['discriminator', getU8Encoder()], + ['groupMemberPointerDiscriminator', getU8Encoder()], + [ + 'memberAddress', + getOptionEncoder(getAddressEncoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ]), + (value) => ({ + ...value, + discriminator: UPDATE_GROUP_MEMBER_POINTER_DISCRIMINATOR, + groupMemberPointerDiscriminator: + UPDATE_GROUP_MEMBER_POINTER_GROUP_MEMBER_POINTER_DISCRIMINATOR, + }) + ); +} + +export function getUpdateGroupMemberPointerInstructionDataDecoder(): Decoder { + return getStructDecoder([ + ['discriminator', getU8Decoder()], + ['groupMemberPointerDiscriminator', getU8Decoder()], + [ + 'memberAddress', + getOptionDecoder(getAddressDecoder(), { + prefix: null, + noneValue: 'zeroes', + }), + ], + ]); +} + +export function getUpdateGroupMemberPointerInstructionDataCodec(): Codec< + UpdateGroupMemberPointerInstructionDataArgs, + UpdateGroupMemberPointerInstructionData +> { + return combineCodec( + getUpdateGroupMemberPointerInstructionDataEncoder(), + getUpdateGroupMemberPointerInstructionDataDecoder() + ); +} + +export type UpdateGroupMemberPointerInput< + TAccountMint extends string = string, + TAccountGroupMemberPointerAuthority extends string = string, +> = { + /** The mint to initialize. */ + mint: Address; + /** The group member pointer authority or its multisignature account. */ + groupMemberPointerAuthority: + | Address + | TransactionSigner; + memberAddress: UpdateGroupMemberPointerInstructionDataArgs['memberAddress']; + multiSigners?: Array; +}; + +export function getUpdateGroupMemberPointerInstruction< + TAccountMint extends string, + TAccountGroupMemberPointerAuthority extends string, + TProgramAddress extends Address = typeof TOKEN_2022_PROGRAM_ADDRESS, +>( + input: UpdateGroupMemberPointerInput< + TAccountMint, + TAccountGroupMemberPointerAuthority + >, + config?: { programAddress?: TProgramAddress } +): UpdateGroupMemberPointerInstruction< + TProgramAddress, + TAccountMint, + (typeof input)['groupMemberPointerAuthority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountGroupMemberPointerAuthority +> { + // Program address. + const programAddress = config?.programAddress ?? TOKEN_2022_PROGRAM_ADDRESS; + + // Original accounts. + const originalAccounts = { + mint: { value: input.mint ?? null, isWritable: true }, + groupMemberPointerAuthority: { + value: input.groupMemberPointerAuthority ?? null, + isWritable: false, + }, + }; + 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.groupMemberPointerAuthority), + ...remainingAccounts, + ], + programAddress, + data: getUpdateGroupMemberPointerInstructionDataEncoder().encode( + args as UpdateGroupMemberPointerInstructionDataArgs + ), + } as UpdateGroupMemberPointerInstruction< + TProgramAddress, + TAccountMint, + (typeof input)['groupMemberPointerAuthority'] extends TransactionSigner + ? ReadonlySignerAccount & + IAccountSignerMeta + : TAccountGroupMemberPointerAuthority + >; + + return instruction; +} + +export type ParsedUpdateGroupMemberPointerInstruction< + TProgram extends string = typeof TOKEN_2022_PROGRAM_ADDRESS, + TAccountMetas extends readonly IAccountMeta[] = readonly IAccountMeta[], +> = { + programAddress: Address; + accounts: { + /** The mint to initialize. */ + mint: TAccountMetas[0]; + /** The group member pointer authority or its multisignature account. */ + groupMemberPointerAuthority: TAccountMetas[1]; + }; + data: UpdateGroupMemberPointerInstructionData; +}; + +export function parseUpdateGroupMemberPointerInstruction< + TProgram extends string, + TAccountMetas extends readonly IAccountMeta[], +>( + instruction: IInstruction & + IInstructionWithAccounts & + IInstructionWithData +): ParsedUpdateGroupMemberPointerInstruction { + 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(), + groupMemberPointerAuthority: getNextAccount(), + }, + data: getUpdateGroupMemberPointerInstructionDataDecoder().decode( + instruction.data + ), + }; +} diff --git a/clients/js/src/generated/programs/token2022.ts b/clients/js/src/generated/programs/token2022.ts index 6872076..1bf9a5d 100644 --- a/clients/js/src/generated/programs/token2022.ts +++ b/clients/js/src/generated/programs/token2022.ts @@ -41,6 +41,7 @@ import { type ParsedInitializeAccountInstruction, type ParsedInitializeConfidentialTransferMintInstruction, type ParsedInitializeDefaultAccountStateInstruction, + type ParsedInitializeGroupMemberPointerInstruction, type ParsedInitializeGroupPointerInstruction, type ParsedInitializeImmutableOwnerInstruction, type ParsedInitializeMetadataPointerInstruction, @@ -64,6 +65,7 @@ import { type ParsedUiAmountToAmountInstruction, type ParsedUpdateConfidentialTransferMintInstruction, type ParsedUpdateDefaultAccountStateInstruction, + type ParsedUpdateGroupMemberPointerInstruction, type ParsedUpdateGroupPointerInstruction, type ParsedUpdateMetadataPointerInstruction, type ParsedWithdrawWithheldTokensFromAccountsInstruction, @@ -153,6 +155,8 @@ export enum Token2022Instruction { UpdateMetadataPointer, InitializeGroupPointer, UpdateGroupPointer, + InitializeGroupMemberPointer, + UpdateGroupMemberPointer, } export function identifyToken2022Instruction( @@ -408,6 +412,18 @@ export function identifyToken2022Instruction( ) { return Token2022Instruction.UpdateGroupPointer; } + if ( + containsBytes(data, getU8Encoder().encode(41), 0) && + containsBytes(data, getU8Encoder().encode(0), 1) + ) { + return Token2022Instruction.InitializeGroupMemberPointer; + } + if ( + containsBytes(data, getU8Encoder().encode(41), 0) && + containsBytes(data, getU8Encoder().encode(1), 1) + ) { + return Token2022Instruction.UpdateGroupMemberPointer; + } throw new Error( 'The provided instruction could not be identified as a token-2022 instruction.' ); @@ -580,4 +596,10 @@ export type ParsedToken2022Instruction< } & ParsedInitializeGroupPointerInstruction) | ({ instructionType: Token2022Instruction.UpdateGroupPointer; - } & ParsedUpdateGroupPointerInstruction); + } & ParsedUpdateGroupPointerInstruction) + | ({ + instructionType: Token2022Instruction.InitializeGroupMemberPointer; + } & ParsedInitializeGroupMemberPointerInstruction) + | ({ + instructionType: Token2022Instruction.UpdateGroupMemberPointer; + } & ParsedUpdateGroupMemberPointerInstruction); diff --git a/clients/js/src/getInitializeInstructionsForExtensions.ts b/clients/js/src/getInitializeInstructionsForExtensions.ts index 1b5d9f5..91eb840 100644 --- a/clients/js/src/getInitializeInstructionsForExtensions.ts +++ b/clients/js/src/getInitializeInstructionsForExtensions.ts @@ -5,6 +5,7 @@ import { getEnableMemoTransfersInstruction, getInitializeConfidentialTransferMintInstruction, getInitializeDefaultAccountStateInstruction, + getInitializeGroupMemberPointerInstruction, getInitializeGroupPointerInstruction, getInitializeMetadataPointerInstruction, getInitializeTransferFeeConfigInstruction, @@ -62,6 +63,14 @@ export function getPreInitializeInstructionsForMintExtensions( groupAddress: extension.groupAddress, }), ]; + case 'GroupMemberPointer': + return [ + getInitializeGroupMemberPointerInstruction({ + mint, + authority: extension.authority, + memberAddress: extension.memberAddress, + }), + ]; default: return []; } diff --git a/clients/js/test/extensions/groupMemberPointer/initializeGroupMemberPointer.test.ts b/clients/js/test/extensions/groupMemberPointer/initializeGroupMemberPointer.test.ts new file mode 100644 index 0000000..bc72193 --- /dev/null +++ b/clients/js/test/extensions/groupMemberPointer/initializeGroupMemberPointer.test.ts @@ -0,0 +1,60 @@ +import { Account, generateKeyPairSigner, some } from '@solana/web3.js'; +import test from 'ava'; +import { + Mint, + extension, + fetchMint, + getInitializeGroupMemberPointerInstruction, +} from '../../../src'; +import { + createDefaultSolanaClient, + generateKeyPairSignerWithSol, + getCreateMintInstructions, + sendAndConfirmInstructions, +} from '../../_setup'; + +test('it initializes a mint account with a group member pointer extension', async (t) => { + // Given some signer accounts. + const client = createDefaultSolanaClient(); + const [authority, mint, groupMember, groupMemberPointerAuthority] = + await Promise.all([ + generateKeyPairSignerWithSol(client), + generateKeyPairSigner(), + generateKeyPairSigner(), + generateKeyPairSigner(), + ]); + + // And a group member pointer extension. + const groupMemberPointerExtension = extension('GroupMemberPointer', { + authority: some(groupMemberPointerAuthority.address), + memberAddress: some(groupMember.address), + }); + + // When we create and initialize a mint account with this extension. + const [createMintInstruction, initMintInstruction] = + await getCreateMintInstructions({ + authority: authority.address, + client, + extensions: [groupMemberPointerExtension], + mint, + payer: authority, + }); + await sendAndConfirmInstructions(client, authority, [ + createMintInstruction, + getInitializeGroupMemberPointerInstruction({ + mint: mint.address, + authority: groupMemberPointerExtension.authority, + memberAddress: groupMemberPointerExtension.memberAddress, + }), + initMintInstruction, + ]); + + // Then we expect the mint account to exist and have the following extension. + const mintAccount = await fetchMint(client.rpc, mint.address); + t.like(mintAccount, >{ + address: mint.address, + data: { + extensions: some([groupMemberPointerExtension]), + }, + }); +}); diff --git a/clients/js/test/extensions/groupMemberPointer/updateGroupMemberPointer.test.ts b/clients/js/test/extensions/groupMemberPointer/updateGroupMemberPointer.test.ts new file mode 100644 index 0000000..9071640 --- /dev/null +++ b/clients/js/test/extensions/groupMemberPointer/updateGroupMemberPointer.test.ts @@ -0,0 +1,61 @@ +import { Account, address, generateKeyPairSigner, some } from '@solana/web3.js'; +import test from 'ava'; +import { + Mint, + extension, + fetchMint, + getUpdateGroupMemberPointerInstruction, +} from '../../../src'; +import { + createDefaultSolanaClient, + createMint, + generateKeyPairSignerWithSol, + sendAndConfirmInstructions, +} from '../../_setup'; + +test('it updates the group member pointer extension on a mint account', async (t) => { + // Given some signer accounts. + const client = createDefaultSolanaClient(); + const [authority, groupMemberPointerAuthority] = await Promise.all([ + generateKeyPairSignerWithSol(client), + generateKeyPairSigner(), + ]); + const oldMember = address('8dtp4b6tB8EhLpSG1jgg4swSQtUKRst2f7rJYSwE2Me3'); + const newMember = address('88F35KbnWKPeMnKFJDxZVjvEWmGms1FxW6wP52VABCVt'); + + // And a mint account initialized with a group member pointer extension. + const mint = await createMint({ + authority: authority.address, + client, + extensions: [ + extension('GroupMemberPointer', { + authority: groupMemberPointerAuthority.address, + memberAddress: oldMember, + }), + ], + payer: authority, + }); + + // When we update the group member pointer on the mint account. + await sendAndConfirmInstructions(client, authority, [ + getUpdateGroupMemberPointerInstruction({ + mint, + groupMemberPointerAuthority, + memberAddress: newMember, + }), + ]); + + // Then we expect the mint account to have the following updated data. + const mintAccount = await fetchMint(client.rpc, mint); + t.like(mintAccount, >{ + address: mint, + data: { + extensions: some([ + extension('GroupMemberPointer', { + authority: some(groupMemberPointerAuthority.address), + memberAddress: some(newMember), + }), + ]), + }, + }); +}); diff --git a/program/idl.json b/program/idl.json index 74bddf6..7528614 100644 --- a/program/idl.json +++ b/program/idl.json @@ -5724,6 +5724,195 @@ "offset": 1 } ] + }, + { + "kind": "instructionNode", + "name": "initializeGroupMemberPointer", + "docs": [ + "Initialize a new mint with a group member pointer", + "", + "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": 41 + } + }, + { + "kind": "instructionArgumentNode", + "name": "groupMemberPointerDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 0 + } + }, + { + "kind": "instructionArgumentNode", + "name": "authority", + "docs": [ + "The public key for the account that can update the group member address." + ], + "type": { + "kind": "zeroableOptionTypeNode", + "item": { + "kind": "publicKeyTypeNode" + } + } + }, + { + "kind": "instructionArgumentNode", + "name": "memberAddress", + "docs": ["The account address that holds the member."], + "type": { + "kind": "zeroableOptionTypeNode", + "item": { + "kind": "publicKeyTypeNode" + } + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "groupMemberPointerDiscriminator", + "offset": 1 + } + ] + }, + { + "kind": "instructionNode", + "name": "updateGroupMemberPointer", + "docs": [ + "Update the group member pointer address. Only supported for mints that", + "include the `GroupMemberPointer` extension." + ], + "optionalAccountStrategy": "programId", + "accounts": [ + { + "kind": "instructionAccountNode", + "name": "mint", + "isWritable": true, + "isSigner": false, + "isOptional": false, + "docs": ["The mint to initialize."] + }, + { + "kind": "instructionAccountNode", + "name": "groupMemberPointerAuthority", + "isWritable": false, + "isSigner": "either", + "isOptional": false, + "docs": [ + "The group member pointer authority or its multisignature account." + ] + } + ], + "arguments": [ + { + "kind": "instructionArgumentNode", + "name": "discriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 41 + } + }, + { + "kind": "instructionArgumentNode", + "name": "groupMemberPointerDiscriminator", + "defaultValueStrategy": "omitted", + "docs": [], + "type": { + "kind": "numberTypeNode", + "format": "u8", + "endian": "le" + }, + "defaultValue": { + "kind": "numberValueNode", + "number": 1 + } + }, + { + "kind": "instructionArgumentNode", + "name": "memberAddress", + "docs": ["The new account address that holds the member."], + "type": { + "kind": "zeroableOptionTypeNode", + "item": { + "kind": "publicKeyTypeNode" + } + } + } + ], + "remainingAccounts": [ + { + "kind": "instructionRemainingAccountsNode", + "isOptional": true, + "isSigner": true, + "docs": [], + "value": { + "kind": "argumentValueNode", + "name": "multiSigners" + } + } + ], + "discriminators": [ + { + "kind": "fieldDiscriminatorNode", + "name": "discriminator", + "offset": 0 + }, + { + "kind": "fieldDiscriminatorNode", + "name": "groupMemberPointerDiscriminator", + "offset": 1 + } + ] } ], "definedTypes": [