Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bump assets controller to 30.0.0 #24913

Merged
merged 42 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
d089168
deps: @metamask/network-controller@^18.1.1->^18.1.2
legobeat May 28, 2024
dce3d43
fix(deps): @metamask/transaction-controller@^29.1.0->^30.0.0
legobeat May 29, 2024
fc950be
fix: force @metamask/transaction-controller to ^30.0.0
legobeat May 29, 2024
cda63c9
update lavamoat policies
legobeat May 29, 2024
c339ffd
fix: bump assets controller
salimtb May 30, 2024
6c845db
fix nft controllers accessing `getNetworkClientById`
bergeron May 30, 2024
a5f795d
remove unused patches
bergeron May 30, 2024
dbab437
fix: fix getTokenExchangeRates selectors
salimtb May 30, 2024
c4ec3b2
fix: update yarn after rebase
salimtb May 31, 2024
c4ebdf0
fix unit tests
bergeron May 31, 2024
c8e6385
Update LavaMoat policies
metamaskbot May 31, 2024
f4a05df
add metamask.io domains to privacy snapshot
bergeron May 31, 2024
efa27ad
Merge branch 'bump-assets-controller-version' of github.com:MetaMask/…
bergeron May 31, 2024
85c97fa
Merge branch 'develop' into bump-assets-controller-version
bergeron May 31, 2024
fe6df70
move more api endpoints to new metamask.io domain
bergeron May 31, 2024
c036089
Merge branch 'bump-assets-controller-version' of github.com:MetaMask/…
bergeron May 31, 2024
5cb151c
fix e2e test
bergeron May 31, 2024
52b931d
merge develop
bergeron May 31, 2024
0807328
yarn
bergeron May 31, 2024
ae14fda
case insensitive symbol compare
bergeron May 31, 2024
71ef082
fix: fix e2e tests
salimtb Jun 2, 2024
005fabd
Merge branch 'bump-assets-controller-version' of github.com:MetaMask/…
bergeron Jun 3, 2024
8546015
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
bergeron Jun 3, 2024
e1d50ff
yarn lavamoat:webapp:auto
bergeron Jun 3, 2024
fea8c66
Update LavaMoat policies
metamaskbot Jun 3, 2024
c57b688
Merge branch 'develop' into bump-assets-controller-version
salimtb Jun 3, 2024
9ecb112
Merge branch 'develop' into bump-assets-controller-version
legobeat Jun 3, 2024
ce42d97
Merge branch 'develop' of github.com:MetaMask/metamask-extension into…
bergeron Jun 3, 2024
6b4e655
add migration to remove deprecated fields
bergeron Jun 3, 2024
2e80f49
patch https://github.com/MetaMask/core/pull/4361
bergeron Jun 3, 2024
807e617
use `price` instead of `value`
bergeron Jun 3, 2024
fc06899
Merge branch 'develop' into bump-assets-controller-version
bergeron Jun 3, 2024
0bb5711
empty
bergeron Jun 4, 2024
05f6638
Merge branch 'bump-assets-controller-version' of github.com:MetaMask/…
bergeron Jun 4, 2024
dc6af6d
empty commit
bergeron Jun 4, 2024
babe108
.
bergeron Jun 4, 2024
00b3917
Merge branch 'develop' into bump-assets-controller-version
bergeron Jun 4, 2024
87dd240
Merge branch 'develop' into bump-assets-controller-version
salimtb Jun 4, 2024
9fb556f
Merge branch 'develop' into bump-assets-controller-version
legobeat Jun 4, 2024
d40c703
Merge branch 'develop' into bump-assets-controller-version
salimtb Jun 5, 2024
1ee4a84
Merge branch 'develop' into bump-assets-controller-version
salimtb Jun 5, 2024
83a317d
fix: fix conflict with PR #24947
salimtb Jun 5, 2024
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
24 changes: 22 additions & 2 deletions .storybook/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,28 @@ const state = {
isEns: true,
},
],
contractExchangeRates: {
'0xaD6D458402F60fD3Bd25163575031ACDce07538D': 0,
marketData: {
'0xaa36a7': {
'0xaD6D458402F60fD3Bd25163575031ACDce07538D': {
price: 0,
contractPercentChange1d: 0.004,
priceChange1d: 0.00004,
},
},
'0x1': {
'0xaD6D458402F60fD3Bd25163575031ACDce07538D': {
price: 0,
contractPercentChange1d: 0.004,
priceChange1d: 0.00004,
},
},
'0x5': {
'0xaD6D458402F60fD3Bd25163575031ACDce07538D': {
price: 0,
contractPercentChange1d: 0.004,
priceChange1d: 0.00004,
},
},
},
tokens: [
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/dist/chunk-Z6TBQQE5.js b/dist/chunk-Z6TBQQE5.js
Copy link
Contributor

@legobeat legobeat Jun 4, 2024

Choose a reason for hiding this comment

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

Let's not forget to follow-up ASAP after release of https://github.com/MetaMackask/metamask-extension/core/4364 so that patching won't be needed for this package

index 2f1b66f2c39794d660553bbdc395697775f90e1d..18d7d5620d827419100c75736f6ec809161da212 100644
--- a/dist/chunk-Z6TBQQE5.js
+++ b/dist/chunk-Z6TBQQE5.js
@@ -295,7 +295,7 @@ var CodefiTokenPricesServiceV2 = class {
(obj, tokenAddress) => {
const lowercasedTokenAddress = tokenAddress.toLowerCase();
const marketData = addressCryptoDataMap[lowercasedTokenAddress];
- if (marketData === void 0) {
+ if (!marketData) {
return obj;
}
const { price } = marketData;

This file was deleted.

This file was deleted.

3 changes: 1 addition & 2 deletions app/scripts/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,7 @@ function saveTimestamp() {
* @property {object} identities - An object matching lower-case hex addresses to Identity objects with "address" and "name" (nickname) keys.
* @property {object} networkConfigurations - A list of network configurations, containing RPC provider details (eg chainId, rpcUrl, rpcPreferences).
* @property {Array} addressBook - A list of previously sent to addresses.
* @property {object} contractExchangeRatesByChainId - Info about current token prices keyed by chainId.
* @property {object} contractExchangeRates - Info about current token prices on current chain.
* @property {object} marketData - A map from chain ID -> contract address -> an object containing the token's market data.
* @property {Array} tokens - Tokens held by the current user, including their balances.
* @property {object} send - TODO: Document
* @property {boolean} useBlockie - Indicates preferred user identicon format. True for blockie, false for Jazzicon.
Expand Down
10 changes: 6 additions & 4 deletions app/scripts/controllers/swaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -706,12 +706,14 @@ export default class SwapsController {
}

async _findTopQuoteAndCalculateSavings(quotes = {}) {
const { contractExchangeRates: tokenConversionRates } =
this.getTokenRatesState();
const { marketData } = this.getTokenRatesState();
const chainId = this._getCurrentChainId();

const tokenConversionRates = marketData[chainId];

const {
swapsState: { customGasPrice, customMaxPriorityFeePerGas },
} = this.store.getState();
const chainId = this._getCurrentChainId();

const numQuotes = Object.keys(quotes).length;
if (!numQuotes) {
Expand Down Expand Up @@ -836,7 +838,7 @@ export default class SwapsController {
Object.keys(tokenConversionRates).find((tokenAddress) =>
isEqualCaseInsensitive(tokenAddress, destinationToken),
)
];
]?.price;
const conversionRateForSorting = tokenConversionRate || 1;

const ethValueOfTokens = decimalAdjustedDestinationAmount.times(
Expand Down
12 changes: 8 additions & 4 deletions app/scripts/controllers/swaps.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ const MOCK_FETCH_METADATA = {
};

const MOCK_TOKEN_RATES_STORE = () => ({
contractExchangeRates: {
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': 2,
'0x1111111111111111111111111111111111111111': 0.1,
marketData: {
'0x1': {
'0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48': { price: 2 },
'0x1111111111111111111111111111111111111111': { price: 0.1 },
},
},
});

Expand Down Expand Up @@ -794,7 +796,9 @@ describe('SwapsController', function () {
.resolves(BigNumber.from(1));

swapsController.getTokenRatesState = () => ({
contractExchangeRates: {},
marketData: {
'0x1': {},
},
});

const [newQuotes, topAggId] = await swapsController.fetchAndSetQuotes(
Expand Down
3 changes: 1 addition & 2 deletions app/scripts/lib/setupSentry.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ export const SENTRY_BACKGROUND_STATE = {
},
},
TokenRatesController: {
contractExchangeRates: false,
contractExchangeRatesByChainId: false,
marketData: false,
},
TokensController: {
allDetectedTokens: {
Expand Down
8 changes: 7 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,10 @@ export default class MetamaskController extends EventEmitter {

const nftControllerMessenger = this.controllerMessenger.getRestricted({
name: 'NftController',
allowedActions: [`${this.approvalController.name}:addRequest`],
allowedActions: [
`${this.approvalController.name}:addRequest`,
`${this.networkController.name}:getNetworkClientById`,
],
});
this.nftController = new NftController(
{
Expand Down Expand Up @@ -742,6 +745,9 @@ export default class MetamaskController extends EventEmitter {
: !this.preferencesController.store.getState().useNftDetection,
selectedAddress:
this.preferencesController.store.getState().selectedAddress,
getNetworkClientById: this.networkController.getNetworkClientById.bind(
this.networkController,
),
});

this.metaMetricsController = new MetaMetricsController({
Expand Down
42 changes: 42 additions & 0 deletions app/scripts/migrations/120.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { migrate, version } from './120';

const oldVersion = 119;

describe('migration #120', () => {
afterEach(() => jest.resetAllMocks());

it('updates the version metadata', async () => {
const oldStorage = {
meta: { version: oldVersion },
data: {},
};

const newStorage = await migrate(oldStorage);
expect(newStorage.meta).toStrictEqual({ version });
});

it('deletes the deprecated token rates controller fields', async () => {
const oldStorage = {
meta: { version: oldVersion },
data: {
TokenRatesController: {
contractExchangeRates: {
'0x8290333ceF9e6D528dD5618Fb97a76f268f3EDD4': 0.00001142055192565137,
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2': 1.000125,
},
contractExchangeRatesByChainId: {
'0x1': {
ETH: {
'0x8290333ceF9e6D528dD5618Fb97a76f268f3EDD4': 0.00001142055192565137,
'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2': 1.000125,
},
},
},
},
},
};

const newStorage = await migrate(oldStorage);
expect(newStorage.data.TokenRatesController).toStrictEqual({});
});
});
37 changes: 37 additions & 0 deletions app/scripts/migrations/120.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { cloneDeep } from 'lodash';
import { hasProperty } from '@metamask/utils';

type VersionedData = {
meta: { version: number };
data: Record<string, unknown>;
};

export const version = 120;

/**
* This migration removes the deprecated fields `contractExchangeRates`
* and `contractExchangeRatesByChainId` from the TokenRatesController.
*
* @param originalVersionedData - Versioned MetaMask extension state, exactly what we persist to dist.
* @param originalVersionedData.meta - State metadata.
* @param originalVersionedData.meta.version - The current state version.
* @param originalVersionedData.data - The persisted MetaMask state, keyed by controller.
* @returns Updated versioned MetaMask extension state.
*/
export async function migrate(
originalVersionedData: VersionedData,
): Promise<VersionedData> {
const versionedData = cloneDeep(originalVersionedData);
versionedData.meta.version = version;
transformState(versionedData.data);
return versionedData;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function transformState(state: Record<string, any>) {
if (hasProperty(state, 'TokenRatesController')) {
delete state.TokenRatesController.contractExchangeRates;
delete state.TokenRatesController.contractExchangeRatesByChainId;
}
return state;
}
1 change: 1 addition & 0 deletions app/scripts/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ const migrations = [
require('./117'),
require('./118'),
require('./119'),
require('./120'),
];

export default migrations;
20 changes: 19 additions & 1 deletion lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -834,11 +834,11 @@
"@ethersproject/providers": true,
"@metamask/abi-utils": true,
"@metamask/assets-controllers>@metamask/base-controller": true,
"@metamask/assets-controllers>@metamask/controller-utils": true,
"@metamask/assets-controllers>@metamask/polling-controller": true,
"@metamask/assets-controllers>cockatiel": true,
"@metamask/assets-controllers>multiformats": true,
"@metamask/contract-metadata": true,
"@metamask/controller-utils": true,
"@metamask/eth-query": true,
"@metamask/metamask-eth-abis": true,
"@metamask/name-controller>async-mutex": true,
Expand All @@ -859,6 +859,24 @@
"immer": true
}
},
"@metamask/assets-controllers>@metamask/controller-utils": {
"globals": {
"URL": true,
"console.error": true,
"fetch": true,
"setTimeout": true
},
"packages": {
"@ethereumjs/tx>@ethereumjs/util": true,
"@metamask/controller-utils>@spruceid/siwe-parser": true,
"@metamask/ethjs>@metamask/ethjs-unit": true,
"@metamask/utils": true,
"bn.js": true,
"browserify>buffer": true,
"eslint>fast-deep-equal": true,
"eth-ens-namehash": true
}
},
"@metamask/assets-controllers>@metamask/polling-controller": {
"globals": {
"clearTimeout": true,
Expand Down
Loading