Skip to content
1 change: 1 addition & 0 deletions packages/tron-wallet-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Scope `bip44:discover` activity checks and account creation to the networks declared in the snap manifest, preventing unnecessary calls to testnet APIs during discovery ([#135](https://github.com/MetaMask/internal-snaps/pull/135))
- Fix SUN → USDT swaps routed through Rango and SunSwap displaying a zero SUN amount in transaction activity ([#134](https://github.com/MetaMask/internal-snaps/pull/134))

## [3.0.0]

Expand Down
2 changes: 1 addition & 1 deletion packages/tron-wallet-snap/snap.manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"url": "https://github.com/MetaMask/internal-snaps.git"
},
"source": {
"shasum": "C13HWdtafD3wHLxY5EH6CQlnUuu8RQoe1YcaTX+P+rE=",
"shasum": "YkMR0S5rmTx8sxFl0lw0zgciTNO55gtSrLdAsxNggWo=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,75 @@ describe('TransactionMapper', () => {
expect(result?.to[0]?.asset).toHaveProperty('unit', 'USDC');
expect(result?.to[0]?.asset).toHaveProperty('amount', '99.5');
});

it('ignores approval events when mapping TRC20 swap transfers', () => {
const mockTrc20Swap = {
...swapTransactionMock,
} as unknown as TransactionInfo;

const trc20Transfers: ContractTransactionInfo[] = [
{
transaction_id: mockTrc20Swap.txID,
token_info: {
symbol: 'USDT',
address: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
decimals: 6,
name: 'Tether USD',
},
block_timestamp: 1632825600000,
from: 'TContractAddress',
to: mockAccount.address,
type: 'Transfer',
value: '4891342',
},
{
transaction_id: mockTrc20Swap.txID,
token_info: {
symbol: 'SUN',
address: 'TSSMHYeV2uE9qYH95DqyoCuNCzEL1NvU3S',
decimals: 18,
name: 'SUN',
},
block_timestamp: 1632825600000,
from: mockAccount.address,
to: 'TContractAddress',
type: 'Approval',
value: '0',
},
{
transaction_id: mockTrc20Swap.txID,
token_info: {
symbol: 'SUN',
address: 'TSSMHYeV2uE9qYH95DqyoCuNCzEL1NvU3S',
decimals: 18,
name: 'SUN',
},
block_timestamp: 1632825600000,
from: mockAccount.address,
to: 'TContractAddress',
type: 'Transfer',
value: '276791363098075785381',
},
];

const result = TransactionMapper.mapTransaction({
scope: Network.Mainnet,
account: mockAccount,
trongridTransaction: mockTrc20Swap,
trc20Transfers,
});

expect(result).not.toBeNull();
expect(result?.type).toStrictEqual(TransactionType.Swap);
expect(result?.from[0]?.asset).toMatchObject({
unit: 'SUN',
amount: '276.791363098075785381',
});
expect(result?.to[0]?.asset).toMatchObject({
unit: 'USDT',
amount: '4.891342',
});
});
});

describe('Non-Swap Scenarios', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { sunToTrx, toUiAmount } from '../../utils/conversion';

// TRC20 transaction types from TronGrid API
const TRC20_APPROVAL_TYPE = 'Approval';
const TRC20_TRANSFER_TYPE = 'Transfer';

export class TransactionMapper {
/**
Expand Down Expand Up @@ -946,10 +947,14 @@ export class TransactionMapper {
// 2. TRX ↔ TRC20: account receives/sends TRC20 + TRX moves in opposite direction

const sentTrc20Transfer = trc20Transfers.find(
(transfer) => transfer.from === account.address,
(transfer) =>
transfer.type === TRC20_TRANSFER_TYPE &&
transfer.from === account.address,
);
const receivedTrc20Transfer = trc20Transfers.find(
(transfer) => transfer.to === account.address,
(transfer) =>
transfer.type === TRC20_TRANSFER_TYPE &&
transfer.to === account.address,
);

// Check for TRC20 ↔ TRC20 swap (different tokens)
Expand Down