Skip to content

Commit

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

cc @Hrushi20.

Continuing work on #2406.
  • Loading branch information
buffalojoec authored Apr 22, 2024
1 parent 8a8ce1e commit 107eec9
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
96 changes: 96 additions & 0 deletions packages/rpc-graphql/src/__tests__/transaction-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
]),
},
},
},
});
});
});
});
});
16 changes: 16 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'),
},
SplTokenInitializeMetadataPointerInstruction: {
authority: resolveAccount('authority'),
metadataAddress: resolveAccount('metadataAddress'),
mint: resolveAccount('mint'),
},
SplTokenInitializeMint2Instruction: {
freezeAuthority: resolveAccount('freezeAuthority'),
mint: resolveAccount('mint'),
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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') {
Expand Down
20 changes: 20 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,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!
# ...
Expand Down

0 comments on commit 107eec9

Please sign in to comment.