Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(experimental): graphql: token-2022 extensions: UpdateAuthority Emit #2700

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/rpc-graphql/src/__tests__/__setup__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2687,6 +2687,32 @@ export const mockTransactionToken2022AllExtensions = {
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
metadata: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
updateAuthority: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
newAuthority: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
},
type: 'updateTokenMetadataAuthority',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
metadata: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
start: 0,
end: 100,
},
type: 'emitTokenMetadata',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
// TODO (more) ...
],
recentBlockhash: '6vRS7MoToVccMqfQecdVC6UbmARaT5mha91zhreqnce9',
Expand Down
90 changes: 90 additions & 0 deletions packages/rpc-graphql/src/__tests__/transaction-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3701,6 +3701,96 @@ describe('transaction', () => {
},
});
});

it('update-token-metadata-authority', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
message {
instructions {
programId
... on SplTokenMetadataUpdateAuthority {
metadata {
address
}
newAuthority {
address
}
updateAuthority {
address
}
}
}
}
}
}
`;
const result = await rpcGraphQL.query(source, { signature });
expect(result).toMatchObject({
data: {
transaction: {
message: {
instructions: expect.arrayContaining([
{
metadata: {
address: expect.any(String),
},
newAuthority: {
address: expect.any(String),
},
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
updateAuthority: {
address: expect.any(String),
},
},
]),
},
},
},
});
});

it('emit-token-metadata', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
message {
instructions {
programId
... on SplTokenMetadataEmit {
end
metadata {
address
}
start
}
}
}
}
}
`;
const result = await rpcGraphQL.query(source, { signature });
expect(result).toMatchObject({
data: {
transaction: {
message: {
instructions: expect.arrayContaining([
{
end: expect.any(BigInt),
metadata: {
address: expect.any(String),
},
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
start: expect.any(BigInt),
},
]),
},
},
},
});
});
});
});
});
14 changes: 14 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,9 @@ export const instructionResolvers = {
hookProgramId: resolveAccount('programId'),
mint: resolveAccount('mint'),
},
SplTokenMetadataEmit: {
metadata: resolveAccount('metadata'),
},
SplTokenMetadataInitialize: {
metadata: resolveAccount('metadata'),
mint: resolveAccount('mint'),
Expand All @@ -411,6 +414,11 @@ export const instructionResolvers = {
metadata: resolveAccount('metadata'),
updateAuthority: resolveAccount('updateAuthority'),
},
SplTokenMetadataUpdateAuthority: {
metadata: resolveAccount('metadata'),
newAuthority: resolveAccount('newAuthority'),
updateAuthority: resolveAccount('updateAuthority'),
},
SplTokenMetadataUpdateField: {
metadata: resolveAccount('metadata'),
updateAuthority: resolveAccount('updateAuthority'),
Expand Down Expand Up @@ -939,6 +947,12 @@ export const instructionResolvers = {
if (jsonParsedConfigs.instructionType === 'removeTokenMetadataKey') {
return 'SplTokenMetadataRemoveKey';
}
if (jsonParsedConfigs.instructionType === 'updateTokenMetadataAuthority') {
return 'SplTokenMetadataUpdateAuthority';
}
if (jsonParsedConfigs.instructionType === 'emitTokenMetadata') {
return 'SplTokenMetadataEmit';
}
}
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 @@ -1094,6 +1094,26 @@ export const instructionTypeDefs = /* GraphQL */ `
updateAuthority: Account
}

"""
Spl Token Metadata: UpdateAuthority instruction
"""
type SplTokenMetadataUpdateAuthority implements TransactionInstruction {
programId: Address
metadata: Account
newAuthority: Account
updateAuthority: Account
}

"""
Spl Token Metadata: Emit instruction
"""
type SplTokenMetadataEmit implements TransactionInstruction {
programId: Address
metadata: Account
end: BigInt
start: BigInt
}

type Lockup {
custodian: Account
epoch: Epoch
Expand Down