Skip to content

Commit

Permalink
solana-labs#2406: init withdrawWithheldTokensFromMint instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrushi20 committed Apr 28, 2024
1 parent 7151be6 commit 1a9ca99
Show file tree
Hide file tree
Showing 4 changed files with 154 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 @@ -1686,6 +1686,36 @@ export const mockTransactionToken2022AllExtensions = {
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
feeRecipient: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
mint: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
withdrawWithheldAuthority: '6muXBR8kTs1UEbATDkFzEf61HPeEHrCvdBNciVoxic8d',
},
type: 'withdrawWithheldTokensFromMint',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
feeRecipient: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
mint: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
multisigWithdrawWithheldAuthority: '6muXBR8kTs1UEbATDkFzEf61HPeEHrCvdBNciVoxic8d',
signers: [
'2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
'2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
],
},
type: 'withdrawWithheldTokensFromMint',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
// TODO (more) ...
],
recentBlockhash: '6vRS7MoToVccMqfQecdVC6UbmARaT5mha91zhreqnce9',
Expand Down
103 changes: 103 additions & 0 deletions packages/rpc-graphql/src/__tests__/transaction-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,109 @@ describe('transaction', () => {
},
});
});

it('withdraw-withheld-tokens-from-mint', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
message {
instructions {
programId
... on SplTokenWithdrawWithheldTokensFromMint {
mint {
address
}
feeRecipient {
address
}
withdrawWithheldAuthority {
address
}
}
}
}
}
}
`;

const result = await rpcGraphQL.query(source, { signature });
expect(result).toMatchObject({
data: {
transaction: {
message: {
instructions: expect.arrayContaining([
{
feeRecipient: {
address: expect.any(String),
},
mint: {
address: expect.any(String),
},
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
withdrawWithheldAuthority: {
address: expect.any(String),
},
},
]),
},
},
},
});
});

it('withdraw-withheld-tokens-from-mint-with-multisigWithdrawWithheldAuthority', async () => {
// expect.assertions(1);
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
message {
instructions {
programId
... on SplTokenWithdrawWithheldTokensFromMint {
mint {
address
}
feeRecipient {
address
}
multisigWithdrawWithheldAuthority {
address
}
signers
}
}
}
}
}
`;

const result = await rpcGraphQL.query(source, { signature });
console.log(result.data);
expect(result).toMatchObject({
data: {
transaction: {
message: {
instructions: expect.arrayContaining([
{
feeRecipient: {
address: expect.any(String),
},
mint: {
address: expect.any(String),
},
multisigWithdrawWithheldAuthority: {
address: expect.any(String),
},
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
signers: [expect.any(String), 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 @@ -298,6 +298,12 @@ export const instructionResolvers = {
metadataAddress: resolveAccount('metadataAddress'),
mint: resolveAccount('mint'),
},
SplTokenWithdrawWithheldTokensFromMint: {
feeRecipient: resolveAccount('feeRecipient'),
mint: resolveAccount('mint'),
multisigWithdrawWithheldAuthority: resolveAccount('multisigWithdrawWithheldAuthority'),
withdrawWithheldAuthority: resolveAccount('withdrawWithheldAuthority'),
},
StakeAuthorizeCheckedInstruction: {
authority: resolveAccount('authority'),
clockSysvar: resolveAccount('clockSysvar'),
Expand Down Expand Up @@ -555,6 +561,9 @@ export const instructionResolvers = {
if (jsonParsedConfigs.instructionType === 'initializeTransferFeeConfig') {
return 'SplTokenInitializeTransferFeeConfig';
}
if (jsonParsedConfigs.instructionType === 'withdrawWithheldTokensFromMint') {
return 'SplTokenWithdrawWithheldTokensFromMint';
}
}
if (jsonParsedConfigs.programName === 'stake') {
if (jsonParsedConfigs.instructionType === 'initialize') {
Expand Down
12 changes: 12 additions & 0 deletions packages/rpc-graphql/src/schema/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,18 @@ export const instructionTypeDefs = /* GraphQL */ `
maximumFee: Int
}
"""
SplToken-2022: WithdrawWithheldTokensFromMint instruction
"""
type SplTokenWithdrawWithheldTokensFromMint implements TransactionInstruction {
programId: Address
feeRecipient: Account
mint: Account
withdrawWithheldAuthority: Account
multisigWithdrawWithheldAuthority: Account
signers: [Address]
}
# TODO: Extensions!
# ...
Expand Down

0 comments on commit 1a9ca99

Please sign in to comment.