Skip to content

Commit b65917a

Browse files
dawnseeker8oscarwrochePrithpal-Sooriya
authored
feat: update asset endpoints to include RWA data (#7548)
This is a PR to add RWA data to asset endpoints. ## Explanation <!-- Thanks for your contribution! Take a moment to answer these questions so that reviewers have the information they need to properly understand your changes: * What is the current state of things and why does it need to change? * What is the solution your changes offer and how does it work? * Are there any changes whose purpose might not obvious to those unfamiliar with the domain? * If your primary goal was to update one package but you found you had to update another one along the way, why did you do so? * If you had to upgrade a dependency, why did you do so? --> CHANGELOG entry: fetch the rwaData from token API endpoints and then pass to frontend to render. ## References <!-- Are there any issues that this pull request is tied to? Are there other links that reviewers should consult to understand these changes better? Are there client or consumer pull requests to adopt any breaking changes? For example: * Fixes #12345 * Related to #67890 --> ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs) - [x] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Adds RWA metadata end-to-end in asset flows. > > - Fetches RWA via `includeRwaData=true` on `token`, `tokens`, `tokens/search`, and `v3/tokens/trending` endpoints; defaults `includeRwaData` to true in `searchTokens` and `getTrendingTokens` > - Extends `Token` and asset item shapes to include optional `rwaData`; propagates through `TokensController`, `TokenDetectionController`, `TokenRatesController`, and `token-selectors` > - Updates tests to expect RWA inclusion and adds Linea token filtering case; updates CHANGELOG > - Minor: adds explicit return types in `TokenListController` methods > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 3891eeb. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Oscar Roche <[email protected]> Co-authored-by: Prithpal Sooriya <[email protected]>
1 parent a76be1a commit b65917a

File tree

10 files changed

+114
-32
lines changed

10 files changed

+114
-32
lines changed

eslint-suppressions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@
359359
},
360360
"packages/assets-controllers/src/TokenListController.ts": {
361361
"@typescript-eslint/explicit-function-return-type": {
362-
"count": 6
362+
"count": 1
363363
},
364364
"no-restricted-syntax": {
365365
"count": 7

packages/assets-controllers/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Add RWA data to asset fetching endpoints ([#7548](https://github.com/MetaMask/core/pull/7548))
1213
- Add Rootstock (0x1e) mapping to eip155:30/erc20:0x542fda317318ebf1d3deaf76e0b632741a7e677d for RBTC ([#7601](https://github.com/MetaMask/core/pull/7601))
1314

1415
### Changed

packages/assets-controllers/src/TokenDetectionController.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
752752
const tokensWithBalance: Token[] = [];
753753
const eventTokensDetails: string[] = [];
754754
for (const nonZeroTokenAddress of Object.keys(balances)) {
755-
const { decimals, symbol, aggregators, iconUrl, name } =
755+
const { decimals, symbol, aggregators, iconUrl, name, rwaData } =
756756
this.#tokensChainsCache[chainId].data[nonZeroTokenAddress];
757757
eventTokensDetails.push(`${symbol} - ${nonZeroTokenAddress}`);
758758
tokensWithBalance.push({
@@ -763,6 +763,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
763763
image: iconUrl,
764764
isERC721: false,
765765
name,
766+
...(rwaData && { rwaData }),
766767
});
767768
}
768769

@@ -843,7 +844,8 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
843844
continue;
844845
}
845846

846-
const { decimals, symbol, aggregators, iconUrl, name } = tokenData;
847+
const { decimals, symbol, aggregators, iconUrl, name, rwaData } =
848+
tokenData;
847849

848850
// Push to lists with checksummed address (for allTokens storage)
849851
eventTokensDetails.push(`${symbol} - ${checksummedTokenAddress}`);
@@ -855,6 +857,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
855857
image: iconUrl,
856858
isERC721: false,
857859
name,
860+
...(rwaData && { rwaData }),
858861
});
859862
}
860863

@@ -964,7 +967,8 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
964967
continue;
965968
}
966969

967-
const { decimals, symbol, aggregators, iconUrl, name } = tokenData;
970+
const { decimals, symbol, aggregators, iconUrl, name, rwaData } =
971+
tokenData;
968972

969973
eventTokensDetails.push(`${symbol} - ${checksummedTokenAddress}`);
970974
tokensWithBalance.push({
@@ -975,6 +979,7 @@ export class TokenDetectionController extends StaticIntervalPollingController<To
975979
image: iconUrl,
976980
isERC721: false,
977981
name,
982+
...(rwaData && { rwaData }),
978983
});
979984
}
980985

packages/assets-controllers/src/TokenListController.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ export class TokenListController extends StaticIntervalPollingController<TokenLi
191191
*
192192
* @param networkControllerState - The updated network controller state.
193193
*/
194-
async #onNetworkControllerStateChange(networkControllerState: NetworkState) {
194+
async #onNetworkControllerStateChange(
195+
networkControllerState: NetworkState,
196+
): Promise<void> {
195197
const selectedNetworkClient = this.messenger.call(
196198
'NetworkController:getNetworkClientById',
197199
networkControllerState.selectedNetworkClientId,
@@ -216,7 +218,7 @@ export class TokenListController extends StaticIntervalPollingController<TokenLi
216218
* @deprecated This method is deprecated and will be removed in the future.
217219
* Consider using the new polling approach instead
218220
*/
219-
async start() {
221+
async start(): Promise<void> {
220222
if (!isTokenListSupportedForNetwork(this.chainId)) {
221223
return;
222224
}
@@ -229,7 +231,7 @@ export class TokenListController extends StaticIntervalPollingController<TokenLi
229231
* @deprecated This method is deprecated and will be removed in the future.
230232
* Consider using the new polling approach instead
231233
*/
232-
async restart() {
234+
async restart(): Promise<void> {
233235
this.stopPolling();
234236
await this.#startDeprecatedPolling();
235237
}
@@ -240,7 +242,7 @@ export class TokenListController extends StaticIntervalPollingController<TokenLi
240242
* @deprecated This method is deprecated and will be removed in the future.
241243
* Consider using the new polling approach instead
242244
*/
243-
stop() {
245+
stop(): void {
244246
this.stopPolling();
245247
}
246248

@@ -250,7 +252,7 @@ export class TokenListController extends StaticIntervalPollingController<TokenLi
250252
* @deprecated This method is deprecated and will be removed in the future.
251253
* Consider using the new polling approach instead
252254
*/
253-
override destroy() {
255+
override destroy(): void {
254256
super.destroy();
255257
this.stopPolling();
256258
}

packages/assets-controllers/src/TokenRatesController.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { isEqual } from 'lodash';
1616
import { reduceInBatchesSerially, TOKEN_PRICES_BATCH_SIZE } from './assetsUtil';
1717
import type { AbstractTokenPricesService } from './token-prices-service/abstract-token-prices-service';
1818
import { getNativeTokenAddress } from './token-prices-service/codefi-v2';
19+
import { TokenRwaData } from './token-service';
1920
import type {
2021
TokensControllerGetStateAction,
2122
TokensControllerStateChangeEvent,
@@ -45,6 +46,7 @@ export type Token = {
4546
hasBalanceError?: boolean;
4647
isERC721?: boolean;
4748
name?: string;
49+
rwaData?: TokenRwaData;
4850
};
4951

5052
const DEFAULT_INTERVAL = 180000;

packages/assets-controllers/src/TokensController.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ describe('TokensController', () => {
16211621
.get(
16221622
`/token/${convertHexToDecimal(
16231623
chainId,
1624-
)}?address=${dummyTokenAddress}`,
1624+
)}?address=${dummyTokenAddress}&includeRwaData=true`,
16251625
)
16261626
.reply(200, { error })
16271627
.persist();

packages/assets-controllers/src/TokensController.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,7 @@ export class TokensController extends BaseController<
457457
isERC721,
458458
aggregators: formatAggregatorNames(tokenMetadata?.aggregators || []),
459459
name,
460+
...(tokenMetadata?.rwaData && { rwaData: tokenMetadata.rwaData }),
460461
};
461462
const previousIndex = newTokens.findIndex(
462463
(token) => token.address.toLowerCase() === address.toLowerCase(),
@@ -525,7 +526,7 @@ export class TokensController extends BaseController<
525526
}, {});
526527
try {
527528
tokensToImport.forEach((tokenToAdd) => {
528-
const { address, symbol, decimals, image, aggregators, name } =
529+
const { address, symbol, decimals, image, aggregators, name, rwaData } =
529530
tokenToAdd;
530531
const checksumAddress = toChecksumHexAddress(address);
531532
const formattedToken: Token = {
@@ -535,6 +536,7 @@ export class TokensController extends BaseController<
535536
image,
536537
aggregators,
537538
name,
539+
...(rwaData && { rwaData }),
538540
};
539541
newTokensMap[checksumAddress] = formattedToken;
540542
importedTokensMap[address.toLowerCase()] = true;
@@ -664,6 +666,7 @@ export class TokensController extends BaseController<
664666
aggregators,
665667
isERC721,
666668
name,
669+
rwaData,
667670
} = tokenToAdd;
668671
const checksumAddress = toChecksumHexAddress(address);
669672
const newEntry: Token = {
@@ -674,6 +677,7 @@ export class TokensController extends BaseController<
674677
isERC721,
675678
aggregators,
676679
name,
680+
...(rwaData && { rwaData }),
677681
};
678682

679683
const previousImportedIndex = newTokens.findIndex(

packages/assets-controllers/src/selectors/token-selectors.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type { NetworkState } from '@metamask/network-controller';
88
import { hexToBigInt, parseCaipAssetType } from '@metamask/utils';
99
import type { Hex } from '@metamask/utils';
1010
import { createSelector, weakMapMemoize } from 'reselect';
11+
import { TokenRwaData } from 'src/token-service';
1112

1213
import {
1314
parseBalanceWithDecimals,
@@ -84,6 +85,7 @@ export type Asset = (
8485
conversionRate: number;
8586
}
8687
| undefined;
88+
rwaData?: TokenRwaData;
8789
};
8890

8991
export type AssetListState = {
@@ -325,6 +327,7 @@ const selectAllEvmAssets = createAssetListSelector(
325327
}
326328
: undefined,
327329
chainId,
330+
...(token.rwaData && { rwaData: token.rwaData }),
328331
});
329332
}
330333
}

0 commit comments

Comments
 (0)