From bcda3e418b13399c66ce16ba51e17a1316599181 Mon Sep 17 00:00:00 2001 From: Naasir Jusab Date: Wed, 8 May 2024 12:01:51 -0400 Subject: [PATCH 1/2] refactor(experimental): graphql: token-2022 extensions: InitializeTokenGroup --- .../rpc-graphql/src/__tests__/__setup__.ts | 15 +++++ .../src/__tests__/transaction-tests.ts | 57 +++++++++++++++++++ .../rpc-graphql/src/resolvers/instruction.ts | 9 +++ .../rpc-graphql/src/schema/instruction.ts | 12 ++++ 4 files changed, 93 insertions(+) diff --git a/packages/rpc-graphql/src/__tests__/__setup__.ts b/packages/rpc-graphql/src/__tests__/__setup__.ts index bf2ca9df7c11..bd184f65d3bf 100644 --- a/packages/rpc-graphql/src/__tests__/__setup__.ts +++ b/packages/rpc-graphql/src/__tests__/__setup__.ts @@ -2586,6 +2586,21 @@ export const mockTransactionToken2022AllExtensions = { programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb', stackHeight: null, }, + { + parsed: { + info: { + group: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ', + maxSize: 22, + mintAuthority: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB', + updateAuthority: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ', + mint: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB', + }, + type: 'initializeTokenGroup', + }, + 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 0f0d7fa846fe..3c42f33ee2c5 100644 --- a/packages/rpc-graphql/src/__tests__/transaction-tests.ts +++ b/packages/rpc-graphql/src/__tests__/transaction-tests.ts @@ -3334,6 +3334,63 @@ describe('transaction', () => { }, }); }); + + it('initialize-token-group', async () => { + expect.assertions(1); + const source = /* GraphQL */ ` + query testQuery($signature: Signature!) { + transaction(signature: $signature) { + message { + instructions { + programId + ... on SplTokenInitializeTokenGroup { + group { + address + } + maxSize + mint { + address + } + mintAuthority { + address + } + updateAuthority { + address + } + } + } + } + } + } + `; + const result = await rpcGraphQL.query(source, { signature }); + expect(result).toMatchObject({ + data: { + transaction: { + message: { + instructions: expect.arrayContaining([ + { + group: { + address: expect.any(String), + }, + maxSize: expect.any(BigInt), + mint: { + address: expect.any(String), + }, + mintAuthority: { + address: expect.any(String), + }, + programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb', + updateAuthority: { + address: expect.any(String), + }, + }, + ]), + }, + }, + }, + }); + }); }); }); }); diff --git a/packages/rpc-graphql/src/resolvers/instruction.ts b/packages/rpc-graphql/src/resolvers/instruction.ts index cb7296817f4c..874a8c580d8f 100644 --- a/packages/rpc-graphql/src/resolvers/instruction.ts +++ b/packages/rpc-graphql/src/resolvers/instruction.ts @@ -369,6 +369,12 @@ export const instructionResolvers = { delegate: resolveAccount('delegate'), mint: resolveAccount('mint'), }, + SplTokenInitializeTokenGroup: { + group: resolveAccount('group'), + mint: resolveAccount('mint'), + mintAuthority: resolveAccount('mintAuthority'), + updateAuthority: resolveAccount('updateAuthority'), + }, SplTokenInitializeTransferFeeConfig: { mint: resolveAccount('mint'), transferFeeConfigAuthority: resolveAccount('transferFeeConfigAuthority'), @@ -882,6 +888,9 @@ export const instructionResolvers = { if (jsonParsedConfigs.instructionType === 'initializeConfidentialTransferFeeConfig') { return 'SplTokenInitializeConfidentialTransferFeeConfig'; } + if (jsonParsedConfigs.instructionType === 'initializeTokenGroup') { + return 'SplTokenInitializeTokenGroup'; + } } 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 8d1a60cf0dd0..0b96c38fb5c4 100644 --- a/packages/rpc-graphql/src/schema/instruction.ts +++ b/packages/rpc-graphql/src/schema/instruction.ts @@ -1014,6 +1014,18 @@ export const instructionTypeDefs = /* GraphQL */ ` withheldAmount: String } + """ + SplToken-2022: InitializeTokenGroup instruction + """ + type SplTokenInitializeTokenGroup implements TransactionInstruction { + programId: Address + group: Account + maxSize: BigInt + mint: Account + mintAuthority: Account + updateAuthority: Account + } + type Lockup { custodian: Account epoch: Epoch From 06a480d75d4862742b240268f86a9317785530b2 Mon Sep 17 00:00:00 2001 From: Naasir Jusab Date: Wed, 8 May 2024 13:34:18 -0400 Subject: [PATCH 2/2] refactor schema name --- .../rpc-graphql/src/__tests__/transaction-tests.ts | 2 +- packages/rpc-graphql/src/resolvers/instruction.ts | 14 +++++++------- packages/rpc-graphql/src/schema/instruction.ts | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/rpc-graphql/src/__tests__/transaction-tests.ts b/packages/rpc-graphql/src/__tests__/transaction-tests.ts index 3c42f33ee2c5..c0162865f14c 100644 --- a/packages/rpc-graphql/src/__tests__/transaction-tests.ts +++ b/packages/rpc-graphql/src/__tests__/transaction-tests.ts @@ -3343,7 +3343,7 @@ describe('transaction', () => { message { instructions { programId - ... on SplTokenInitializeTokenGroup { + ... on SplTokenGroupInitializeGroup { group { address } diff --git a/packages/rpc-graphql/src/resolvers/instruction.ts b/packages/rpc-graphql/src/resolvers/instruction.ts index 874a8c580d8f..aca2eb351974 100644 --- a/packages/rpc-graphql/src/resolvers/instruction.ts +++ b/packages/rpc-graphql/src/resolvers/instruction.ts @@ -290,6 +290,12 @@ export const instructionResolvers = { SplTokenGetAccountDataSizeInstruction: { mint: resolveAccount('mint'), }, + SplTokenGroupInitializeGroup: { + group: resolveAccount('group'), + mint: resolveAccount('mint'), + mintAuthority: resolveAccount('mintAuthority'), + updateAuthority: resolveAccount('updateAuthority'), + }, SplTokenHarvestWithheldConfidentialTransferTokensToMint: { mint: resolveAccount('mint'), }, @@ -369,12 +375,6 @@ export const instructionResolvers = { delegate: resolveAccount('delegate'), mint: resolveAccount('mint'), }, - SplTokenInitializeTokenGroup: { - group: resolveAccount('group'), - mint: resolveAccount('mint'), - mintAuthority: resolveAccount('mintAuthority'), - updateAuthority: resolveAccount('updateAuthority'), - }, SplTokenInitializeTransferFeeConfig: { mint: resolveAccount('mint'), transferFeeConfigAuthority: resolveAccount('transferFeeConfigAuthority'), @@ -889,7 +889,7 @@ export const instructionResolvers = { return 'SplTokenInitializeConfidentialTransferFeeConfig'; } if (jsonParsedConfigs.instructionType === 'initializeTokenGroup') { - return 'SplTokenInitializeTokenGroup'; + return 'SplTokenGroupInitializeGroup'; } } if (jsonParsedConfigs.programName === 'stake') { diff --git a/packages/rpc-graphql/src/schema/instruction.ts b/packages/rpc-graphql/src/schema/instruction.ts index 0b96c38fb5c4..9fa56f84c217 100644 --- a/packages/rpc-graphql/src/schema/instruction.ts +++ b/packages/rpc-graphql/src/schema/instruction.ts @@ -1015,9 +1015,9 @@ export const instructionTypeDefs = /* GraphQL */ ` } """ - SplToken-2022: InitializeTokenGroup instruction + Spl Token Group: InitializeGroup instruction """ - type SplTokenInitializeTokenGroup implements TransactionInstruction { + type SplTokenGroupInitializeGroup implements TransactionInstruction { programId: Address group: Account maxSize: BigInt