Skip to content
This repository was archived by the owner on Jul 31, 2026. It is now read-only.
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
5 changes: 3 additions & 2 deletions packages/snap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Disable simulation for unsupported transactions ([#186](https://github.com/MetaMask/snap-tron-wallet/pull/186))
- Supported transactions are those single-contract interaction transactions of the following types: `TransferContract`, `TriggerSmartContract`, `TransferAssetContract`.
- Improve simulation accuracy for contract transactions ([#186](https://github.com/MetaMask/snap-tron-wallet/pull/186))
- Supported transactions are those single-contract interaction transactions of the following types: `TransferContract`, `CreateSmartContract`, `TriggerSmartContract`.
- Unsupported transactions will show empty estimated changes and allow the user to proceed without blocking the confirmation.

## [1.20.0]

Expand Down
2 changes: 1 addition & 1 deletion packages/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/snap-tron-wallet.git"
},
"source": {
"shasum": "Izxk79sRDjnS3yUNx8TV9c9D7azOJxTwVSchsbEToXU=",
"shasum": "j+g3RqXwctphEFRvdLZ5BnLpW02TivcjJ8FnVegxOm8=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand Down
39 changes: 2 additions & 37 deletions packages/snap/src/clients/security-alerts-api/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,10 @@ import {
isTransactionSupported,
SUPPORTED_CONTRACT_TYPES,
} from './utils';
import type {
TransferAssetContractParameter,
TransferContractParameter,
} from '../trongrid/types';
import type { TransferContractParameter } from '../trongrid/types';

describe('SecurityAlertsApiClient utils', () => {
describe('extractScanParametersFromTransactionData', () => {
it('extracts scan parameters from a TransferAssetContractParameter', () => {
const contractInteraction: TransferAssetContractParameter = {
type_url: 'type.googleapis.com/protocol.TransferAssetContract',
value: {
asset_name: 'MyToken',
owner_address: '41a614f803b6fd780986a42c78ec9c7f77e6ded13c',
to_address: '4191bba2f3f6e1c4d5c8e8f5b6a7c8d9e0f1a2b3c4',
amount: 1000000,
},
};
const rawData: Types.Transaction['raw_data'] = {
contract: [
{
type: Types.ContractType.TransferAssetContract,
parameter: contractInteraction,
},
],
ref_block_bytes: '',
ref_block_hash: '',
expiration: 0,
timestamp: 0,
};

const result = extractScanParametersFromTransactionData(rawData);

expect(result).toStrictEqual({
from: 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t',
to: 'TPFmm695uHPTn8wNmQbF8yMiZxfCeUdXkJ',
data: null,
value: 1000000,
});
});

it('extracts scan parameters from a TransferContractParameter', () => {
const contractInteraction: TransferContractParameter = {
type_url: 'type.googleapis.com/protocol.TransferContract',
Expand Down Expand Up @@ -179,6 +143,7 @@ describe('SecurityAlertsApiClient utils', () => {
Types.ContractType.ExchangeInjectContract,
Types.ContractType.ExchangeWithdrawContract,
Types.ContractType.ExchangeTransactionContract,
Types.ContractType.TransferAssetContract,
])(
'returns false for transactions with unsupported contract types',
(contractType) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/snap/src/clients/security-alerts-api/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type { SecurityScanPayload } from './types';

export const SUPPORTED_CONTRACT_TYPES: Types.ContractType[] = [
Types.ContractType.TransferContract,
Types.ContractType.TransferAssetContract,
Types.ContractType.CreateSmartContract,
Types.ContractType.TriggerSmartContract,
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { TransactionScanResult, TransactionScanValidation } from './types';
import { ScanStatus, SecurityAlertResponse } from './types';
import type { SecurityAlertsApiClient } from '../../clients/security-alerts-api/SecurityAlertsApiClient';
import type { SecurityAlertSimulationValidationResponse } from '../../clients/security-alerts-api/types';
import { isTransactionSupported } from '../../clients/security-alerts-api/utils';
import type { SnapClient } from '../../clients/snap/SnapClient';
import type { Network } from '../../constants';
import type { TronKeyringAccount } from '../../entities';
Expand Down Expand Up @@ -57,6 +58,22 @@ export class TransactionScanService {
options?: string[] | undefined;
account?: TronKeyringAccount;
}): Promise<TransactionScanResult | null> {
const simulationAccurate = isTransactionSupported(transactionRawData);

if (!simulationAccurate) {
this.#logger.info(
'Transaction is not supported for scanning, returning inaccurate simulation result',
);

return {
status: 'SUCCESS',
estimatedChanges: { assets: [] },
validation: { type: null, reason: null },
error: null,
simulationAccurate: false,
};
}

try {
const result = await this.#securityAlertsApiClient.scanTransaction({
accountAddress,
Expand Down Expand Up @@ -239,6 +256,7 @@ export class TransactionScanService {
message: result.simulation?.error ?? null,
}
: null,
simulationAccurate: true,
};
}
}
1 change: 1 addition & 0 deletions packages/snap/src/services/transaction-scan/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type TransactionScanResult = {
estimatedChanges: TransactionScanEstimatedChanges;
validation: TransactionScanValidation;
error: TransactionScanError | null;
simulationAccurate: boolean;
};

export enum SecurityAlertResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export const ConfirmSignTransaction = ({
} = context;

const shouldDisableConfirmButton =
scanFetchStatus === 'fetching' || scan?.status === 'ERROR';
scanFetchStatus === 'fetching' ||
(scan?.status === 'ERROR' && scan?.simulationAccurate);

const addressCaip10 = account ? `${scope}:${account.address}` : null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ describe('ConfirmSignTransaction render', () => {
reason: null,
},
error: null,
simulationAccurate: true,
};

let mockSnapClient: jest.Mocked<SnapClient>;
Expand Down
Loading