Skip to content

Commit

Permalink
refactor(experimental): graphql: token-2022 extensions: InitializeMet…
Browse files Browse the repository at this point in the history
…adata (#2692)

* refactor(experimental): graphql: token-2022 extensions: InitializeMetadata

* refactor schema name
  • Loading branch information
nasjuice authored May 9, 2024
1 parent 499f2a4 commit d525f91
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
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 @@ -2642,6 +2642,23 @@ export const mockTransactionToken2022AllExtensions = {
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
metadata: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
updateAuthority: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
mint: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
mintAuthority: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
name: 'Test',
symbol: 'tst',
uri: 'http://test.test',
},
type: 'initializeTokenMetadata',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
// TODO (more) ...
],
recentBlockhash: '6vRS7MoToVccMqfQecdVC6UbmARaT5mha91zhreqnce9',
Expand Down
61 changes: 61 additions & 0 deletions packages/rpc-graphql/src/__tests__/transaction-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3546,6 +3546,67 @@ describe('transaction', () => {
},
});
});

it('initialize-token-metadata', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
message {
instructions {
programId
... on SplTokenMetadataInitialize {
metadata {
address
}
mint {
address
}
mintAuthority {
address
}
name
symbol
updateAuthority {
address
}
uri
}
}
}
}
}
`;
const result = await rpcGraphQL.query(source, { signature });
expect(result).toMatchObject({
data: {
transaction: {
message: {
instructions: expect.arrayContaining([
{
metadata: {
address: expect.any(String),
},
mint: {
address: expect.any(String),
},
mintAuthority: {
address: expect.any(String),
},
name: expect.any(String),
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
symbol: expect.any(String),
updateAuthority: {
address: expect.any(String),
},
uri: expect.any(String),
},
]),
},
},
},
});
});
});
});
});
9 changes: 9 additions & 0 deletions packages/rpc-graphql/src/resolvers/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ export const instructionResolvers = {
hookProgramId: resolveAccount('programId'),
mint: resolveAccount('mint'),
},
SplTokenMetadataInitialize: {
metadata: resolveAccount('metadata'),
mint: resolveAccount('mint'),
mintAuthority: resolveAccount('mintAuthority'),
updateAuthority: resolveAccount('updateAuthority'),
},
SplTokenMintToCheckedInstruction: {
account: resolveAccount('account'),
authority: resolveAccount('authority'),
Expand Down Expand Up @@ -916,6 +922,9 @@ export const instructionResolvers = {
if (jsonParsedConfigs.instructionType === 'initializeTokenGroupMember') {
return 'SplTokenGroupInitializeMember';
}
if (jsonParsedConfigs.instructionType === 'initializeTokenMetadata') {
return 'SplTokenMetadataInitialize';
}
}
if (jsonParsedConfigs.programName === 'stake') {
if (jsonParsedConfigs.instructionType === 'initialize') {
Expand Down
14 changes: 14 additions & 0 deletions packages/rpc-graphql/src/schema/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,20 @@ export const instructionTypeDefs = /* GraphQL */ `
memberMintAuthority: Account
}
"""
Spl Token Metadata: InitializeMetadata instruction
"""
type SplTokenMetadataInitialize implements TransactionInstruction {
programId: Address
metadata: Account
mint: Account
mintAuthority: Account
name: String
symbol: String
updateAuthority: Account
uri: String
}
type Lockup {
custodian: Account
epoch: Epoch
Expand Down

0 comments on commit d525f91

Please sign in to comment.