Skip to content

Commit

Permalink
Merge pull request #1272 from Giveth/fix_verifying_spl_tokens
Browse files Browse the repository at this point in the history
Hotfix - fix verifying spl token transfer donations
  • Loading branch information
aminlatifi authored Jan 28, 2024
2 parents f59a7d2 + 79a3be7 commit a70c811
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
23 changes: 21 additions & 2 deletions src/services/chains/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ function getTransactionDetailTestCases() {
);
});

it('should return transaction detail for spl-token transfer on Solana #1', async () => {
it('should return transaction detail for spl-token transfer on Solana devnet #1', async () => {
// https://solscan.io/tx/2tm14GVsDwXpMzxZzpEWyQnfzcUEv1DZQVQb6VdbsHcV8StoMbBtuQTkW1LJ8RhKKrAL18gbm181NgzuusiQfZ16?cluster=devnet
const amount = 7;
const transactionInfo = await getTransactionInfoFromNetwork({
Expand All @@ -953,7 +953,7 @@ function getTransactionDetailTestCases() {
assert.equal(transactionInfo.amount, amount);
});

it('should return transaction detail for spl-token transfer on Solana #2', async () => {
it('should return transaction detail for spl-token transfer on Solana devnet #2', async () => {
// https://solscan.io/tx/3m6f1g2YK6jtbfVfuYsfDbhVzNAqozF8JJyjp1VuFDduecojqeCVK4htKnLTSk3qBwSqYUvgLpBTVpeLJRvNmeTg?cluster=devnet
const amount = 0.00000005;
const transactionInfo = await getTransactionInfoFromNetwork({
Expand All @@ -972,6 +972,25 @@ function getTransactionDetailTestCases() {
assert.equal(transactionInfo.amount, amount);
});

it('should return transaction detail for RAY spl token transfer on Solana mainnet', async () => {
// https://solscan.io/tx/4ApdD7usYH5Cp7hsaWGKjnJW3mfyNpRw4S4NJbzwa2CQfnUkjY11sR2G1W3rvXmCzXwu3yNLz2CfkCHY5sQPdWzq
const amount = 0.005;
const transactionInfo = await getTransactionInfoFromNetwork({
txHash:
'4ApdD7usYH5Cp7hsaWGKjnJW3mfyNpRw4S4NJbzwa2CQfnUkjY11sR2G1W3rvXmCzXwu3yNLz2CfkCHY5sQPdWzq',
symbol: 'RAY',
chainType: ChainType.SOLANA,
networkId: NETWORK_IDS.SOLANA_MAINNET,
fromAddress: 'FAMREy7d73N5jPdoKowQ4QFm6DKPWuYxZh6cwjNAbpkY',
toAddress: '6U29tmuvaGsTQqamf9Vt4o15JHTNq5RdJxoRW6NJxRdx',
timestamp: 1706429516,
amount,
});
assert.isOk(transactionInfo);
assert.equal(transactionInfo.currency, 'RAY');
assert.equal(transactionInfo.amount, amount);
});

it('should return error when transaction time is newer than sent timestamp for spl-token transfer on Solana', async () => {
// https://explorer.solana.com/tx/2tm14GVsDwXpMzxZzpEWyQnfzcUEv1DZQVQb6VdbsHcV8StoMbBtuQTkW1LJ8RhKKrAL18gbm181NgzuusiQfZ16?cluster=devnet

Expand Down
6 changes: 4 additions & 2 deletions src/services/chains/solana/transactionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,14 @@ async function getTransactionDetailForSplTokenTransfer(
balance =>
balance.owner === params.toAddress && balance.mint === token?.address,
);
if (!data || !toAddressPostBalance || !toAddressPreBalance) {
if (!data || !toAddressPostBalance) {
return null;
}

// toAddressBalance might be null if this is first time that destination wallet receives this token
const amount =
toAddressPostBalance.uiTokenAmount?.uiAmount -
toAddressPreBalance.uiTokenAmount?.uiAmount;
(toAddressPreBalance?.uiTokenAmount?.uiAmount || 0);
const parsedData = data as ParsedInstruction;

const txInfo = parsedData.parsed.info;
Expand Down

0 comments on commit a70c811

Please sign in to comment.