Skip to content
Draft
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
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,
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { KnownCaip19Id, SNAP_OWNED_ASSETS } from '../../constants';
import { isSnapOwnedAsset } from './snapOwnedAssets';

describe('isSnapOwnedAsset', () => {
it.each(SNAP_OWNED_ASSETS)(
'returns true for snap-owned asset %s',
(assetId) => {
expect(isSnapOwnedAsset(assetId)).toBe(true);
},
);

it('returns false for native TRX', () => {
expect(isSnapOwnedAsset(KnownCaip19Id.TrxMainnet)).toBe(false);
expect(isSnapOwnedAsset(KnownCaip19Id.TrxNile)).toBe(false);
expect(isSnapOwnedAsset(KnownCaip19Id.TrxShasta)).toBe(false);
});

it('returns false for TRC20 tokens', () => {
expect(isSnapOwnedAsset(KnownCaip19Id.UsdtMainnet)).toBe(false);
expect(
isSnapOwnedAsset(
`${KnownCaip19Id.TrxMainnet.split('/')[0]}/trc20:TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t`,
),
).toBe(false);
});

it('returns false for TRC10 tokens', () => {
expect(
isSnapOwnedAsset(
`${KnownCaip19Id.TrxMainnet.split('/')[0]}/trc10:1002000`,
),
).toBe(false);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { SNAP_OWNED_ASSETS } from '../../constants';

const SNAP_OWNED_ASSET_IDS = new Set<string>(SNAP_OWNED_ASSETS);

/**
* Returns whether an asset remains exclusively managed by the Snap.
*
* AssetsController does not persist certain Tron protocol assets, including
* staking positions and account resources. These assets must always be read,
* synchronized, persisted, and published by the Snap, regardless of the
* assets migration stage.
*
* @param assetId - CAIP-19 asset ID.
* @returns Whether the asset is exclusively managed by the Snap.
*/
export function isSnapOwnedAsset(assetId: string): boolean {
return SNAP_OWNED_ASSET_IDS.has(assetId);
}
Loading