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

## [Unreleased]

### Added

- Add RWA (Real World Assets) data support for token metadata endpoint ([#7595](https://github.com/MetaMask/core/pull/7595))
- Update token service to include RWA data in API requests by appending `includeRwaData=true` parameter to token list API calls
- `TokenListController` now includes `rwaData` optional field in `TokenListToken` type to support RWA data in token list retrieval
- Reduced `TokenListController` cache time from 24hrs to 4hrs.

### Changed

- Bump `@metamask/multichain-account-service` from `^4.1.0` to `^5.0.0` ([#7594](https://github.com/MetaMask/core/pull/7594))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1366,5 +1366,5 @@ describe('TokenListController', () => {
function getTokensPath(chainId: Hex) {
return `/tokens/${convertHexToDecimal(
chainId,
)}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`;
)}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false&includeRwaData=true`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a PR to update to the new endpoint #7572
However this is postponed to reduce the scope of changes for the RWA feature launch.

}
8 changes: 5 additions & 3 deletions packages/assets-controllers/src/TokenListController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ import {
formatAggregatorNames,
formatIconUrlWithProxy,
} from './assetsUtil';
import { fetchTokenListByChainId } from './token-service';
import { TokenRwaData, fetchTokenListByChainId } from './token-service';

const DEFAULT_INTERVAL = 24 * 60 * 60 * 1000;
const DEFAULT_THRESHOLD = 24 * 60 * 60 * 1000;
// 4 Hour Interval Cache Refresh Threshold
const DEFAULT_INTERVAL = 4 * 60 * 60 * 1000;
const DEFAULT_THRESHOLD = 4 * 60 * 60 * 1000;
Comment on lines +24 to +26
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in slack - we have modified the cache interval from 24 hours to 4 hours.

We should monitor if this causes any performance hits - (mostly from the large writes to state)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we wanted to pass this in constructor client side instead of updating the controller's default values?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meeeeh I don't mind either or... But this would minimise client changes required. Open to options on this :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm agree, tbh doing it on constructor seems to be the proper way to go about this.
Doing it in this controller is less changes for sure;
I don't mind tbh, if you feel like you prefer this one, happy to approve 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, lets do it inside the controller for now -- less changes that devs need to make. We can treat the ones inside the constructor as "overrides" if it needs to be overridden.


const name = 'TokenListController';

Expand All @@ -34,6 +35,7 @@ export type TokenListToken = {
occurrences: number;
aggregators: string[];
iconUrl: string;
rwaData?: TokenRwaData;
};

export type TokenListMap = Record<string, TokenListToken>;
Expand Down
12 changes: 6 additions & 6 deletions packages/assets-controllers/src/token-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ describe('Token service', () => {
const { signal } = new AbortController();
nock(TOKEN_END_POINT_API)
.get(
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`,
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false&includeRwaData=true`,
)
.reply(200, sampleTokenList)
.persist();
Expand All @@ -310,7 +310,7 @@ describe('Token service', () => {

nock(TOKEN_END_POINT_API)
.get(
`/tokens/${lineaChainId}?occurrenceFloor=1&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`,
`/tokens/${lineaChainId}?occurrenceFloor=1&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false&includeRwaData=true`,
)
.reply(200, sampleTokenListLinea)
.persist();
Expand All @@ -324,7 +324,7 @@ describe('Token service', () => {
const abortController = new AbortController();
nock(TOKEN_END_POINT_API)
.get(
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`,
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false&includeRwaData=true`,
)
// well beyond time it will take to abort
.delay(ONE_SECOND_IN_MILLISECONDS)
Expand All @@ -344,7 +344,7 @@ describe('Token service', () => {
const { signal } = new AbortController();
nock(TOKEN_END_POINT_API)
.get(
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`,
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false&includeRwaData=true`,
)
.replyWithError('Example network error')
.persist();
Expand All @@ -358,7 +358,7 @@ describe('Token service', () => {
const { signal } = new AbortController();
nock(TOKEN_END_POINT_API)
.get(
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`,
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false&includeRwaData=true`,
)
.reply(500)
.persist();
Expand All @@ -372,7 +372,7 @@ describe('Token service', () => {
const { signal } = new AbortController();
nock(TOKEN_END_POINT_API)
.get(
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`,
`/tokens/${sampleDecimalChainId}?occurrenceFloor=3&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false&includeRwaData=true`,
)
// well beyond timeout
.delay(ONE_SECOND_IN_MILLISECONDS)
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/token-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function getTokensURL(chainId: Hex): string {

return `${TOKEN_END_POINT_API}/tokens/${convertHexToDecimal(
chainId,
)}?occurrenceFloor=${occurrenceFloor}&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false`;
)}?occurrenceFloor=${occurrenceFloor}&includeNativeAssets=false&includeTokenFees=false&includeAssetType=false&includeERC20Permit=false&includeStorage=false&includeRwaData=true`;
}

/**
Expand Down
Loading