From 107eec97b27c53b9055fc5f85718a31fe80c4890 Mon Sep 17 00:00:00 2001 From: Joe C Date: Mon, 22 Apr 2024 16:10:37 -0500 Subject: [PATCH] refactor(experimental): graphql: token-2022 extensions: metadata pointer This PR adds support for Token-2022's `MetadataPointer` extension in the GraphQL schema. cc @Hrushi20. Continuing work on #2406. --- .../src/__tests__/transaction-tests.ts | 96 +++++++++++++++++++ .../rpc-graphql/src/resolvers/instruction.ts | 16 ++++ .../rpc-graphql/src/schema/instruction.ts | 20 ++++ 3 files changed, 132 insertions(+) diff --git a/packages/rpc-graphql/src/__tests__/transaction-tests.ts b/packages/rpc-graphql/src/__tests__/transaction-tests.ts index 0bc9455140f4..842311b277b3 100644 --- a/packages/rpc-graphql/src/__tests__/transaction-tests.ts +++ b/packages/rpc-graphql/src/__tests__/transaction-tests.ts @@ -745,6 +745,102 @@ describe('transaction', () => { }, }); }); + it('initialize-metadata-pointer', async () => { + expect.assertions(1); + const source = /* GraphQL */ ` + query testQuery($signature: Signature!) { + transaction(signature: $signature) { + message { + instructions { + programId + ... on SplTokenInitializeMetadataPointerInstruction { + authority { + address + } + metadataAddress { + address + } + mint { + address + } + } + } + } + } + } + `; + const result = await rpcGraphQL.query(source, { signature }); + expect(result).toMatchObject({ + data: { + transaction: { + message: { + instructions: expect.arrayContaining([ + { + authority: { + address: expect.any(String), + }, + metadataAddress: { + address: expect.any(String), + }, + mint: { + address: expect.any(String), + }, + programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb', + }, + ]), + }, + }, + }, + }); + }); + it('update-metadata-pointer', async () => { + expect.assertions(1); + const source = /* GraphQL */ ` + query testQuery($signature: Signature!) { + transaction(signature: $signature) { + message { + instructions { + programId + ... on SplTokenUpdateMetadataPointerInstruction { + authority { + address + } + metadataAddress { + address + } + mint { + address + } + } + } + } + } + } + `; + const result = await rpcGraphQL.query(source, { signature }); + expect(result).toMatchObject({ + data: { + transaction: { + message: { + instructions: expect.arrayContaining([ + { + authority: { + address: expect.any(String), + }, + metadataAddress: { + address: expect.any(String), + }, + mint: { + address: expect.any(String), + }, + programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb', + }, + ]), + }, + }, + }, + }); + }); }); }); }); diff --git a/packages/rpc-graphql/src/resolvers/instruction.ts b/packages/rpc-graphql/src/resolvers/instruction.ts index d4d708b24d85..1906be5a0d82 100644 --- a/packages/rpc-graphql/src/resolvers/instruction.ts +++ b/packages/rpc-graphql/src/resolvers/instruction.ts @@ -208,6 +208,11 @@ export const instructionResolvers = { owner: resolveAccount('owner'), rentSysvar: resolveAccount('rentSysvar'), }, + SplTokenInitializeMetadataPointerInstruction: { + authority: resolveAccount('authority'), + metadataAddress: resolveAccount('metadataAddress'), + mint: resolveAccount('mint'), + }, SplTokenInitializeMint2Instruction: { freezeAuthority: resolveAccount('freezeAuthority'), mint: resolveAccount('mint'), @@ -283,6 +288,11 @@ export const instructionResolvers = { SplTokenUiAmountToAmountInstruction: { mint: resolveAccount('mint'), }, + SplTokenUpdateMetadataPointerInstruction: { + authority: resolveAccount('authority'), + metadataAddress: resolveAccount('metadataAddress'), + mint: resolveAccount('mint'), + }, StakeAuthorizeCheckedInstruction: { authority: resolveAccount('authority'), clockSysvar: resolveAccount('clockSysvar'), @@ -531,6 +541,12 @@ export const instructionResolvers = { if (jsonParsedConfigs.instructionType === 'initializePermanentDelegate') { return 'SplTokenInitializePermanentDelegateInstruction'; } + if (jsonParsedConfigs.instructionType === 'initializeMetadataPointer') { + return 'SplTokenInitializeMetadataPointerInstruction'; + } + if (jsonParsedConfigs.instructionType === 'updateMetadataPointer') { + return 'SplTokenUpdateMetadataPointerInstruction'; + } } if (jsonParsedConfigs.programName === 'stake') { if (jsonParsedConfigs.instructionType === 'initialize') { diff --git a/packages/rpc-graphql/src/schema/instruction.ts b/packages/rpc-graphql/src/schema/instruction.ts index 252283013256..b3d8865027a0 100644 --- a/packages/rpc-graphql/src/schema/instruction.ts +++ b/packages/rpc-graphql/src/schema/instruction.ts @@ -521,6 +521,26 @@ export const instructionTypeDefs = /* GraphQL */ ` mint: Account } + """ + SplToken-2022: InitializeMetadataPointer instruction + """ + type SplTokenInitializeMetadataPointerInstruction implements TransactionInstruction { + programId: Address + authority: Account + metadataAddress: Account + mint: Account + } + + """ + SplToken-2022: UpdateMetadataPointer instruction + """ + type SplTokenUpdateMetadataPointerInstruction implements TransactionInstruction { + programId: Address + authority: Account + metadataAddress: Account + mint: Account + } + # TODO: Extensions! # ...