Skip to content

Commit

Permalink
solana-labs#2406: TransferCheckedWithFee instruction
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrushi20 committed Apr 27, 2024
1 parent 7151be6 commit 1811f1b
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 0 deletions.
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 @@ -1686,6 +1686,32 @@ export const mockTransactionToken2022AllExtensions = {
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
{
parsed: {
info: {
authority: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
destination: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
feeAmount: {
amount: '5000',
decimals: 9,
uiAmount: 0.000005,
uiAmountString: '0.000005',
},
mint: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ',
source: '2Pwe6Yahh5cbzvCwRMtTYFeboSwYiWeHhYJzZZBsU6eB',
tokenAmount: {
amount: '1000000000000000',
decimals: 9,
uiAmount: 1000000,
uiAmountString: '1000000',
},
},
type: 'transferCheckedWithFee',
},
program: 'spl-token',
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
stackHeight: null,
},
// TODO (more) ...
],
recentBlockhash: '6vRS7MoToVccMqfQecdVC6UbmARaT5mha91zhreqnce9',
Expand Down
80 changes: 80 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,86 @@ describe('transaction', () => {
},
});
});

it('transfer-checked-with-fee', async () => {
expect.assertions(1);
const source = /* GraphQL */ `
query testQuery($signature: Signature!) {
transaction(signature: $signature) {
message {
instructions {
programId
... on SplTokenTransferCheckedWithFee {
mint {
address
}
authority {
address
}
source {
address
}
destination {
address
}
feeAmount {
amount
decimals
uiAmount
uiAmountString
}
tokenAmount {
amount
decimals
uiAmount
uiAmountString
}
}
}
}
}
}
`;

const result = await rpcGraphQL.query(source, { signature });
expect(result).toMatchObject({
data: {
transaction: {
message: {
instructions: expect.arrayContaining([
{
authority: {
address: expect.any(String),
},
destination: {
address: expect.any(String),
},
feeAmount: {
amount: expect.any(String),
decimals: expect.any(Number),
uiAmount: null, // can't convert decimal to BigInt
uiAmountString: expect.any(String),
},
mint: {
address: expect.any(String),
},
programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb',
source: {
address: expect.any(String),
},
tokenAmount: {
amount: expect.any(String),
decimals: expect.any(Number),
uiAmount: expect.any(BigInt),
uiAmountString: 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 @@ -284,6 +284,12 @@ export const instructionResolvers = {
multisigAuthority: resolveAccount('multisigAuthority'),
source: resolveAccount('source'),
},
SplTokenTransferCheckedWithFee: {
authority: resolveAccount('authority'),
destination: resolveAccount('destination'),
mint: resolveAccount('mint'),
source: resolveAccount('source'),
},
SplTokenTransferInstruction: {
authority: resolveAccount('authority'),
destination: resolveAccount('destination'),
Expand Down Expand Up @@ -555,6 +561,9 @@ export const instructionResolvers = {
if (jsonParsedConfigs.instructionType === 'initializeTransferFeeConfig') {
return 'SplTokenInitializeTransferFeeConfig';
}
if (jsonParsedConfigs.instructionType === 'transferCheckedWithFee') {
return 'SplTokenTransferCheckedWithFee';
}
}
if (jsonParsedConfigs.programName === 'stake') {
if (jsonParsedConfigs.instructionType === 'initialize') {
Expand Down
13 changes: 13 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,19 @@ export const instructionTypeDefs = /* GraphQL */ `
maximumFee: Int
}
"""
SplToken-2022: TransferCheckedWithFee instruction
"""
type SplTokenTransferCheckedWithFee implements TransactionInstruction {
programId: Address
authority: Account
destination: Account
feeAmount: TokenAmount
mint: Account
source: Account
tokenAmount: TokenAmount
}
# TODO: Extensions!
# ...
Expand Down

0 comments on commit 1811f1b

Please sign in to comment.