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

Hotfix - fix verifying spl token transfer donations #1272

Merged
merged 1 commit into from
Jan 28, 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
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
Loading