Skip to content

Commit

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

cc @Hrushi20.

Continuing work on #2406.
  • Loading branch information
buffalojoec authored May 2, 2024
1 parent 4d84c7b commit 8f5af23
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 0 deletions.
30 changes: 30 additions & 0 deletions packages/rpc-graphql/src/__tests__/__setup__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,36 @@ export const mockTransactionToken2022AllExtensions = {
stackHeight: null,
},
// Updating Mint Extension pointers.
{
parsed: {
info: {
authority: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
mint: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
programId: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
},
type: 'updateTransferHook',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
mint: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
programId: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
multisigAuthority: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
signers: [
'2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
'2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
],
},
type: 'updateTransferHook',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
Expand Down
116 changes: 116 additions & 0 deletions packages/rpc-graphql/src/__tests__/transaction-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,122 @@ describe('transaction', () => {
},
});
});
it('initialize-transfer-hook', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
message {
instructions {
programId
... on SplTokenInitializeTransferHookInstruction {
authority {
address
}
hookProgramId {
address
}
mint {
address
}
}
}
}
}
}
`;
const result = await rpcGraphQL.query(source, { signature });
expect(result).toMatchObject({
data: {
transaction: {
message: {
instructions: expect.arrayContaining([
{
authority: {
address: expect.any(String),
},
hookProgramId: {
address: expect.any(String),
},
mint: {
address: expect.any(String),
},
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
},
]),
},
},
},
});
});
it('update-transfer-hook', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
message {
instructions {
programId
... on SplTokenUpdateTransferHookInstruction {
authority {
address
}
hookProgramId {
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),
},
hookProgramId: {
address: expect.any(String),
},
mint: {
address: expect.any(String),
},
multisigAuthority: null,
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
signers: null,
},
{
authority: null,
hookProgramId: {
address: expect.any(String),
},
mint: {
address: expect.any(String),
},
multisigAuthority: {
address: expect.any(String),
},
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
signers: expect.arrayContaining([expect.any(String)]),
},
]),
},
},
},
});
});
});
});
});
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 @@ -254,6 +254,11 @@ export const instructionResolvers = {
transferFeeConfigAuthority: resolveAccount('transferFeeConfigAuthority'),
withdrawWithheldAuthority: resolveAccount('withdrawWithheldAuthority'),
},
SplTokenInitializeTransferHookInstruction: {
authority: resolveAccount('authority'),
hookProgramId: resolveAccount('programId'),
mint: resolveAccount('mint'),
},
SplTokenMintToCheckedInstruction: {
account: resolveAccount('account'),
authority: resolveAccount('authority'),
Expand Down Expand Up @@ -321,6 +326,12 @@ export const instructionResolvers = {
mint: resolveAccount('mint'),
multisigAuthority: resolveAccount('multisigAuthority'),
},
SplTokenUpdateTransferHookInstruction: {
authority: resolveAccount('authority'),
hookProgramId: resolveAccount('programId'),
mint: resolveAccount('mint'),
multisigAuthority: resolveAccount('multisigAuthority'),
},
StakeAuthorizeCheckedInstruction: {
authority: resolveAccount('authority'),
clockSysvar: resolveAccount('clockSysvar'),
Expand Down Expand Up @@ -590,6 +601,12 @@ export const instructionResolvers = {
if (jsonParsedConfigs.instructionType === 'initializeTransferFeeConfig') {
return 'SplTokenInitializeTransferFeeConfig';
}
if (jsonParsedConfigs.instructionType === 'initializeTransferHook') {
return 'SplTokenInitializeTransferHookInstruction';
}
if (jsonParsedConfigs.instructionType === 'updateTransferHook') {
return 'SplTokenUpdateTransferHookInstruction';
}
}
if (jsonParsedConfigs.programName === 'stake') {
if (jsonParsedConfigs.instructionType === 'initialize') {
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 @@ -599,6 +599,28 @@ export const instructionTypeDefs = /* GraphQL */ `
maximumFee: Int
}
"""
SplToken-2022: InitializeTransferHook instruction
"""
type SplTokenInitializeTransferHookInstruction implements TransactionInstruction {
programId: Address
authority: Account
hookProgramId: Account
mint: Account
}
"""
SplToken-2022: UpdateTransferHook instruction
"""
type SplTokenUpdateTransferHookInstruction implements TransactionInstruction {
programId: Address
authority: Account
hookProgramId: Account
mint: Account
multisigAuthority: Account
signers: [Address]
}
# TODO: Extensions!
# ...
Expand Down

0 comments on commit 8f5af23

Please sign in to comment.