diff --git a/src/services/chains/index.test.ts b/src/services/chains/index.test.ts index 625634137..0504ce2ef 100644 --- a/src/services/chains/index.test.ts +++ b/src/services/chains/index.test.ts @@ -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({ @@ -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({ @@ -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 diff --git a/src/services/chains/solana/transactionService.ts b/src/services/chains/solana/transactionService.ts index 4908928ff..ccb9e5921 100644 --- a/src/services/chains/solana/transactionService.ts +++ b/src/services/chains/solana/transactionService.ts @@ -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;