Skip to content
Closed
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
4 changes: 4 additions & 0 deletions packages/tron-wallet-snap/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Route fungible asset reads (TRX, TRC10, TRC20) through AssetsController via the Snap messenger endowment. Protocol assets (energy, bandwidth, staking, lock/withdrawal, rewards) remain Snap-owned. Account sync and persistence no longer fetch or store fungibles in Snap state.

## [2.0.0]

### Changed
Expand Down
2 changes: 2 additions & 0 deletions packages/tron-wallet-snap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"devDependencies": {
"@metamask/assets-controller": "11.2.0",
"@metamask/auto-changelog": "^6.1.1",
"@metamask/key-tree": "^10.1.1",
"@metamask/keyring-api": "^23.7.0",
"@metamask/keyring-snap-sdk": "^9.2.1",
"@metamask/messenger": "^2.0.0",
"@metamask/snaps-cli": "^8.4.1",
"@metamask/snaps-jest": "^10.2.0",
"@metamask/snaps-sdk": "^11.2.0",
Expand Down
26 changes: 21 additions & 5 deletions 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": "0TZh63x04Gncx8UgHBoWnQ4RmX6kmTL6RmJTyqgJ7G8=",
"shasum": "AKoQWoE0egZjeSKDZ5PHQcfN4sXinCBhhYmgTo/xfOA=",
"location": {
"npm": {
"filePath": "dist/bundle.js",
Expand All @@ -16,18 +16,26 @@
"registry": "https://registry.npmjs.org/"
}
},
"locales": ["locales/en.json"]
"locales": [
"locales/en.json"
]
},
"initialConnections": {
"https://portfolio.metamask.io": {}
},
"initialPermissions": {
"endowment:keyring": {
"allowedOrigins": ["https://portfolio.metamask.io"]
"allowedOrigins": [
"https://portfolio.metamask.io"
]
},
"snap_getBip32Entropy": [
{
"path": ["m", "44'", "195'"],
"path": [
"m",
"44'",
"195'"
],
"curve": "secp256k1"
}
],
Expand All @@ -47,7 +55,15 @@
]
},
"endowment:assets": {
"scopes": ["tron:728126428"]
"scopes": [
"tron:728126428"
]
},
"endowment:messenger": {
"actions": [
"AssetsController:getAsset",
"AssetsController:getAssets"
]
}
},
"platformVersion": "11.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { mapKeys } from 'lodash';

import type { ICache } from '../../caching/ICache';
import { useCache } from '../../caching/useCache';
import { SPECIAL_ASSETS } from '../../constants';
import { SNAP_OWNED_ASSETS } from '../../constants';
import type { ConfigProvider } from '../../services/config';
import { buildUrl } from '../../utils/buildUrl';
import type { ILogger } from '../../utils/logger';
Expand Down Expand Up @@ -257,7 +257,7 @@ export class PriceApiClient {
assert(vsCurrency, VsCurrencyParamStruct);

const filteredTokens = tokenCaip19Types.filter(
(tokenCaip19Type) => !SPECIAL_ASSETS.includes(tokenCaip19Type),
(tokenCaip19Type) => !SNAP_OWNED_ASSETS.includes(tokenCaip19Type),
);

return this.#getMultipleSpotPrices_CACHE(filteredTokens, vsCurrency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { array, assert } from '@metamask/superstruct';
import type { Infer } from '@metamask/superstruct';
import { CaipAssetTypeStruct, parseCaipAssetType } from '@metamask/utils';

import { Network, SPECIAL_ASSETS } from '../../constants';
import { Network, SNAP_OWNED_ASSETS } from '../../constants';
import type { TokenCaipAssetType } from '../../services/assets/types';
import { TokenCaipAssetTypeStruct } from '../../services/assets/types';
import type { ConfigProvider } from '../../services/config';
Expand Down Expand Up @@ -94,7 +94,7 @@ export class TokenApiClient {
* Exclude TRON resource tokens (energy and bandwidth), staked tokens, and tokens not from supported networks.
*/
const supportedAssetTypes = assetTypes.filter((assetType) => {
if (SPECIAL_ASSETS.includes(assetType)) {
if (SNAP_OWNED_ASSETS.includes(assetType)) {
return false;
}
const { chainId } = parseCaipAssetType(assetType);
Expand Down
7 changes: 5 additions & 2 deletions packages/tron-wallet-snap/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export const Networks = {
},
} as const;

export const SPECIAL_ASSETS: string[] = [
export const SNAP_OWNED_ASSETS: string[] = [
KnownCaip19Id.TrxStakedForBandwidthMainnet,
KnownCaip19Id.TrxStakedForBandwidthNile,
KnownCaip19Id.TrxStakedForBandwidthShasta,
Expand Down Expand Up @@ -419,9 +419,12 @@ export const SPECIAL_ASSETS: string[] = [
KnownCaip19Id.MaximumEnergyShasta,
];

/** @deprecated Use {@link SNAP_OWNED_ASSETS} instead. */
export const SPECIAL_ASSETS = SNAP_OWNED_ASSETS;

export const ESSENTIAL_ASSETS: string[] = [
KnownCaip19Id.TrxMainnet,
KnownCaip19Id.TrxNile,
KnownCaip19Id.TrxShasta,
...SPECIAL_ASSETS,
...SNAP_OWNED_ASSETS,
];
6 changes: 6 additions & 0 deletions packages/tron-wallet-snap/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { getMessenger } from '@metamask/snaps-sdk';

import { InMemoryCache } from './caching/InMemoryCache';
import { StateCache } from './caching/StateCache';
import { PriceApiClient } from './clients/price-api/PriceApiClient';
Expand Down Expand Up @@ -29,6 +31,7 @@ import { TransactionScanService } from './services/transaction-scan/TransactionS
import { TransactionsRepository } from './services/transactions/TransactionsRepository';
import { TransactionsService } from './services/transactions/TransactionsService';
import { WalletService } from './services/wallet/WalletService';
import type { CoreMessenger } from './types/core-messenger';
import logger, { noOpLogger } from './utils/logger';

/**
Expand Down Expand Up @@ -82,6 +85,8 @@ const priceApiClient = new PriceApiClient(configProvider, priceCache);
// Token API client
const tokenApiClient = new TokenApiClient(configProvider);

const coreMessenger = getMessenger<CoreMessenger>();

// Security Alerts API client
const securityAlertsApiClient = new SecurityAlertsApiClient(
configProvider,
Expand All @@ -98,6 +103,7 @@ const assetsService = new AssetsService({
priceApiClient,
tokenApiClient,
snapClient,
coreMessenger,
});

const transactionsService = new TransactionsService({
Expand Down
Loading
Loading