From ec0ba2a7e68eecd1907ab6cbc64661ddf045349c Mon Sep 17 00:00:00 2001 From: Naasir Jusab Date: Wed, 8 May 2024 17:57:02 -0400 Subject: [PATCH] refactor(experimental): graphql: token-2022 extensions: InitializeTokenGroupMember --- .../rpc-graphql/src/__tests__/__setup__.ts | 15 +++++ .../src/__tests__/transaction-tests.ts | 61 +++++++++++++++++++ .../rpc-graphql/src/resolvers/instruction.ts | 10 +++ .../rpc-graphql/src/schema/instruction.ts | 12 ++++ 4 files changed, 98 insertions(+) diff --git a/packages/rpc-graphql/src/__tests__/__setup__.ts b/packages/rpc-graphql/src/__tests__/__setup__.ts index 3c6040fccc58..44316cd43178 100644 --- a/packages/rpc-graphql/src/__tests__/__setup__.ts +++ b/packages/rpc-graphql/src/__tests__/__setup__.ts @@ -2627,6 +2627,21 @@ export const mockTransactionToken2022AllExtensions = { programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb', stackHeight: null, }, + { + parsed: { + info: { + member: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ', + memberMint: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ', + memberMintAuthority: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ', + group: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ', + groupUpdateAuthority: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ', + }, + type: 'initializeTokenGroupMember', + }, + program: 'spl-token', + programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb', + stackHeight: null, + }, // TODO (more) ... ], recentBlockhash: '6vRS7MoToVccMqfQecdVC6UbmARaT5mha91zhreqnce9', diff --git a/packages/rpc-graphql/src/__tests__/transaction-tests.ts b/packages/rpc-graphql/src/__tests__/transaction-tests.ts index a30f6f7d1516..434afd854251 100644 --- a/packages/rpc-graphql/src/__tests__/transaction-tests.ts +++ b/packages/rpc-graphql/src/__tests__/transaction-tests.ts @@ -3485,6 +3485,67 @@ describe('transaction', () => { }, }); }); + + it('initialize-token-group-member', async () => { + expect.assertions(1); + const source = /* GraphQL */ ` + query testQuery($signature: Signature!) { + transaction(signature: $signature) { + message { + instructions { + programId + ... on SplTokenGroupInitializeMember { + group { + address + } + groupUpdateAuthority { + address + } + member { + address + } + memberMint { + address + } + memberMintAuthority { + address + } + } + } + } + } + } + `; + const result = await rpcGraphQL.query(source, { signature }); + expect(result).toMatchObject({ + data: { + transaction: { + message: { + instructions: expect.arrayContaining([ + { + group: { + address: expect.any(String), + }, + groupUpdateAuthority: { + address: expect.any(String), + }, + member: { + address: expect.any(String), + }, + memberMint: { + address: expect.any(String), + }, + memberMintAuthority: { + 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 5f4ea975df94..62d23f71da5f 100644 --- a/packages/rpc-graphql/src/resolvers/instruction.ts +++ b/packages/rpc-graphql/src/resolvers/instruction.ts @@ -296,6 +296,13 @@ export const instructionResolvers = { mintAuthority: resolveAccount('mintAuthority'), updateAuthority: resolveAccount('updateAuthority'), }, + SplTokenGroupInitializeMember: { + group: resolveAccount('group'), + groupUpdateAuthority: resolveAccount('groupUpdateAuthority'), + member: resolveAccount('member'), + memberMint: resolveAccount('memberMint'), + memberMintAuthority: resolveAccount('memberMintAuthority'), + }, SplTokenGroupUpdateGroupAuthority: { group: resolveAccount('group'), newAuthority: resolveAccount('newAuthority'), @@ -906,6 +913,9 @@ export const instructionResolvers = { if (jsonParsedConfigs.instructionType === 'updateTokenGroupAuthority') { return 'SplTokenGroupUpdateGroupAuthority'; } + if (jsonParsedConfigs.instructionType === 'initializeTokenGroupMember') { + return 'SplTokenGroupInitializeMember'; + } } 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 6e317c41c6af..fdb687b7c8cd 100644 --- a/packages/rpc-graphql/src/schema/instruction.ts +++ b/packages/rpc-graphql/src/schema/instruction.ts @@ -1046,6 +1046,18 @@ export const instructionTypeDefs = /* GraphQL */ ` updateAuthority: Account } + """ + Spl Token Group: InitializeMember instruction + """ + type SplTokenGroupInitializeMember implements TransactionInstruction { + programId: Address + group: Account + groupUpdateAuthority: Account + member: Account + memberMint: Account + memberMintAuthority: Account + } + type Lockup { custodian: Account epoch: Epoch