Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
refactor(experimental): graphql: token-2022 extensions: group pointer
Browse files Browse the repository at this point in the history
This PR adds support for Token-2022's `GroupPointer` extension
in the GraphQL schema.

cc @Hrushi20.

Continuing work on #2406.
  • Loading branch information
buffalojoec authored May 2, 2024
1 parent 3ede209 commit 37b8e09
Show file tree
Hide file tree
Showing 4 changed files with 172 additions and 1 deletion.
17 changes: 17 additions & 0 deletions packages/rpc-graphql/src/__tests__/__setup__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,23 @@ export const mockTransactionToken2022AllExtensions = {
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
groupAddress: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
mint: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
multisigAuthority: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
signers: [
'2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
'2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
],
},
type: 'updateGroupPointer',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
Expand Down
117 changes: 116 additions & 1 deletion packages/rpc-graphql/src/__tests__/transaction-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,122 @@ describe('transaction', () => {
},
});
});
it('initialize-group-pointer', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
message {
instructions {
programId
... on SplTokenInitializeGroupPointerInstruction {
authority {
address
}
groupAddress {
address
}
mint {
address
}
}
}
}
}
}
`;
const result = await rpcGraphQL.query(source, { signature });
expect(result).toMatchObject({
data: {
transaction: {
message: {
instructions: expect.arrayContaining([
{
authority: {
address: expect.any(String),
},
groupAddress: {
address: expect.any(String),
},
mint: {
address: expect.any(String),
},
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
},
]),
},
},
},
});
});
it('update-group-pointer', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
message {
instructions {
programId
... on SplTokenUpdateGroupPointerInstruction {
authority {
address
}
groupAddress {
address
}
mint {
address
}
multisigAuthority {
address
}
signers
}
}
}
}
}
`;
const result = await rpcGraphQL.query(source, { signature });
expect(result).toMatchObject({
data: {
transaction: {
message: {
instructions: expect.arrayContaining([
{
authority: {
address: expect.any(String),
},
groupAddress: {
address: expect.any(String),
},
mint: {
address: expect.any(String),
},
multisigAuthority: null,
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
signers: null,
},
{
authority: null,
groupAddress: {
address: expect.any(String),
},
mint: {
address: expect.any(String),
},
multisigAuthority: {
address: expect.any(String),
},
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
signers: expect.arrayContaining([expect.any(String)]),
},
]),
},
},
},
});
});
it('initialize-metadata-pointer', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
Expand Down Expand Up @@ -861,7 +977,6 @@ describe('transaction', () => {
},
});
});

it('initialize-transferFee-config', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
Expand Down
17 changes: 17 additions & 0 deletions packages/rpc-graphql/src/resolvers/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ export const instructionResolvers = {
owner: resolveAccount('owner'),
rentSysvar: resolveAccount('rentSysvar'),
},
SplTokenInitializeGroupPointerInstruction: {
authority: resolveAccount('authority'),
groupAddress: resolveAccount('groupAddress'),
mint: resolveAccount('mint'),
},
SplTokenInitializeMetadataPointerInstruction: {
authority: resolveAccount('authority'),
metadataAddress: resolveAccount('metadataAddress'),
Expand Down Expand Up @@ -293,6 +298,12 @@ export const instructionResolvers = {
SplTokenUiAmountToAmountInstruction: {
mint: resolveAccount('mint'),
},
SplTokenUpdateGroupPointerInstruction: {
authority: resolveAccount('authority'),
groupAddress: resolveAccount('groupAddress'),
mint: resolveAccount('mint'),
multisigAuthority: resolveAccount('multisigAuthority'),
},
SplTokenUpdateMetadataPointerInstruction: {
authority: resolveAccount('authority'),
metadataAddress: resolveAccount('metadataAddress'),
Expand Down Expand Up @@ -547,6 +558,12 @@ export const instructionResolvers = {
if (jsonParsedConfigs.instructionType === 'initializePermanentDelegate') {
return 'SplTokenInitializePermanentDelegateInstruction';
}
if (jsonParsedConfigs.instructionType === 'initializeGroupPointer') {
return 'SplTokenInitializeGroupPointerInstruction';
}
if (jsonParsedConfigs.instructionType === 'updateGroupPointer') {
return 'SplTokenUpdateGroupPointerInstruction';
}
if (jsonParsedConfigs.instructionType === 'initializeMetadataPointer') {
return 'SplTokenInitializeMetadataPointerInstruction';
}
Expand Down
22 changes: 22 additions & 0 deletions packages/rpc-graphql/src/schema/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,28 @@ export const instructionTypeDefs = /* GraphQL */ `
mint: Account
}
"""
SplToken-2022: InitializeGroupPointer instruction
"""
type SplTokenInitializeGroupPointerInstruction implements TransactionInstruction {
programId: Address
authority: Account
groupAddress: Account
mint: Account
}
"""
SplToken-2022: UpdateGroupPointer instruction
"""
type SplTokenUpdateGroupPointerInstruction implements TransactionInstruction {
programId: Address
authority: Account
groupAddress: Account
mint: Account
multisigAuthority: Account
signers: [Address]
}
"""
SplToken-2022: InitializeMetadataPointer instruction
"""
Expand Down

0 comments on commit 37b8e09

Please sign in to comment.