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: cpi guard
Browse files Browse the repository at this point in the history
This PR adds support for Token-2022's `CpiGuard` extension
in the GraphQL schema.

cc @Hrushi20.

Continuing work on #2406.
  • Loading branch information
buffalojoec authored May 2, 2024
1 parent 7c9a91e commit 3554a13
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 0 deletions.
44 changes: 44 additions & 0 deletions packages/rpc-graphql/src/__tests__/__setup__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,50 @@ export const mockTransactionToken2022AllExtensions = {
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
account: '6muXBR8kTs1UEbATDkFzEf61HPeEHrCvdBNciVoxic8d',
multisigOwner: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
signers: [
'2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
'2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
],
},
type: 'enableCpiGuard',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
account: '6muXBR8kTs1UEbATDkFzEf61HPeEHrCvdBNciVoxic8d',
owner: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
},
type: 'disableCpiGuard',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
account: '6muXBR8kTs1UEbATDkFzEf61HPeEHrCvdBNciVoxic8d',
multisigOwner: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
signers: [
'2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
'2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
],
},
type: 'disableCpiGuard',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
Expand Down
118 changes: 118 additions & 0 deletions packages/rpc-graphql/src/__tests__/transaction-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,124 @@ describe('transaction', () => {
},
});
});
it('enable-cpi-guard', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
message {
instructions {
programId
... on SplTokenEnableCpiGuardInstruction {
account {
address
}
multisigOwner {
address
}
owner {
address
}
signers
}
}
}
}
}
`;
const result = await rpcGraphQL.query(source, { signature });
expect(result).toMatchObject({
data: {
transaction: {
message: {
instructions: expect.arrayContaining([
{
account: {
address: expect.any(String),
},
multisigOwner: null,
owner: {
address: expect.any(String),
},
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
signers: null,
},
{
account: {
address: expect.any(String),
},
multisigOwner: {
address: expect.any(String),
},
owner: null,
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
signers: expect.arrayContaining([expect.any(String)]),
},
]),
},
},
},
});
});
it('disable-cpi-guard', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
message {
instructions {
programId
... on SplTokenDisableCpiGuardInstruction {
account {
address
}
multisigOwner {
address
}
owner {
address
}
signers
}
}
}
}
}
`;
const result = await rpcGraphQL.query(source, { signature });
expect(result).toMatchObject({
data: {
transaction: {
message: {
instructions: expect.arrayContaining([
{
account: {
address: expect.any(String),
},
multisigOwner: null,
owner: {
address: expect.any(String),
},
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
signers: null,
},
{
account: {
address: expect.any(String),
},
multisigOwner: {
address: expect.any(String),
},
owner: null,
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
signers: expect.arrayContaining([expect.any(String)]),
},
]),
},
},
},
});
});
});
});
});
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 @@ -187,6 +187,16 @@ export const instructionResolvers = {
INITIALIZED: 'initialized',
UNINITIALIZED: 'uninitialized',
},
SplTokenDisableCpiGuardInstruction: {
account: resolveAccount('account'),
multisigOwner: resolveAccount('multisigOwner'),
owner: resolveAccount('owner'),
},
SplTokenEnableCpiGuardInstruction: {
account: resolveAccount('account'),
multisigOwner: resolveAccount('multisigOwner'),
owner: resolveAccount('owner'),
},
SplTokenFreezeAccountInstruction: {
account: resolveAccount('account'),
freezeAuthority: resolveAccount('freezeAuthority'),
Expand Down Expand Up @@ -626,6 +636,12 @@ export const instructionResolvers = {
if (jsonParsedConfigs.instructionType === 'updateDefaultAccountState') {
return 'SplTokenUpdateDefaultAccountStateInstruction';
}
if (jsonParsedConfigs.instructionType === 'disableCpiGuard') {
return 'SplTokenDisableCpiGuardInstruction';
}
if (jsonParsedConfigs.instructionType === 'enableCpiGuard') {
return 'SplTokenEnableCpiGuardInstruction';
}
}
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 @@ -648,6 +648,28 @@ export const instructionTypeDefs = /* GraphQL */ `
signers: [Address]
}
"""
SplToken-2022: EnableCpiGuard instruction
"""
type SplTokenEnableCpiGuardInstruction implements TransactionInstruction {
programId: Address
account: Account
multisigOwner: Account
owner: Account
signers: [Address]
}
"""
SplToken-2022: DisableCpiGuard instruction
"""
type SplTokenDisableCpiGuardInstruction implements TransactionInstruction {
programId: Address
account: Account
multisigOwner: Account
owner: Account
signers: [Address]
}
# TODO: Extensions!
# ...
Expand Down

0 comments on commit 3554a13

Please sign in to comment.