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

revert: feat(swaps): enable Base for swaps (#9286) #9612

Merged
merged 1 commit into from
May 10, 2024
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
2 changes: 0 additions & 2 deletions app/components/UI/Swaps/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const {
OPTIMISM_CHAIN_ID,
ZKSYNC_ERA_CHAIN_ID,
LINEA_CHAIN_ID,
BASE_CHAIN_ID,
} = swapsUtils;

const allowedChainIds = [
Expand All @@ -26,7 +25,6 @@ const allowedChainIds = [
OPTIMISM_CHAIN_ID,
ZKSYNC_ERA_CHAIN_ID,
LINEA_CHAIN_ID,
BASE_CHAIN_ID,
SWAPS_TESTNET_CHAIN_ID,
];

Expand Down
2 changes: 1 addition & 1 deletion app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,7 @@ class Engine {
}),
new SwapsController(
{
// @ts-expect-error TODO: Resolve mismatch between gas fee and swaps controller types
fetchGasFeeEstimates: () => gasFeeController.fetchGasFeeEstimates(),
// @ts-expect-error TODO: Resolve mismatch between gas fee and swaps controller types
fetchEstimatedMultiLayerL1Fee,
Expand All @@ -1186,7 +1187,6 @@ class Engine {
swapsUtils.OPTIMISM_CHAIN_ID,
swapsUtils.ZKSYNC_ERA_CHAIN_ID,
swapsUtils.LINEA_CHAIN_ID,
swapsUtils.BASE_CHAIN_ID,
],
},
),
Expand Down
1 change: 0 additions & 1 deletion app/declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ declare module 'react-native-fade-in-image';

declare module 'react-native-minimizer';

declare module 'xhr2';
declare module 'react-native-scrollable-tab-view/DefaultTabBar' {
const content: React.FC<any>;
export default content;
Expand Down
5 changes: 0 additions & 5 deletions app/store/sagas/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ import Engine from '../../core/Engine';
import Logger from '../../util/Logger';
import LockManagerService from '../../core/LockManagerService';
import AppConstants from '../../../app/core/AppConstants';
import { XMLHttpRequest as _XMLHttpRequest } from 'xhr2';

if (typeof global.XMLHttpRequest === 'undefined') {
global.XMLHttpRequest = _XMLHttpRequest;
}

const originalSend = XMLHttpRequest.prototype.send;
const originalOpen = XMLHttpRequest.prototype.open;
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
"@metamask/snaps-sdk": "^2.0.0",
"@metamask/snaps-utils": "^6.0.0",
"@metamask/swappable-obj-proxy": "^2.1.0",
"@metamask/swaps-controller": "^8.0.0",
"@metamask/swaps-controller": "^6.9.3",
"@metamask/transaction-controller": "^13.0.0",
"@metamask/utils": "^8.1.0",
"@ngraveio/bc-ur": "^1.1.6",
Expand Down Expand Up @@ -468,7 +468,6 @@
"wdio-cucumberjs-json-reporter": "^4.4.3",
"webpack": "^5.88.2",
"webpack-cli": "^5.1.4",
"xhr2": "^0.2.1",
"xml2js": "^0.5.0",
"yarn-deduplicate": "^6.0.2"
},
Expand Down
208 changes: 208 additions & 0 deletions patches/@metamask+swaps-controller+6.9.3.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
diff --git a/node_modules/@metamask/swaps-controller/dist/SwapsController.d.ts b/node_modules/@metamask/swaps-controller/dist/SwapsController.d.ts
index 682efcb..7aa7cf0 100644
--- a/node_modules/@metamask/swaps-controller/dist/SwapsController.d.ts
+++ b/node_modules/@metamask/swaps-controller/dist/SwapsController.d.ts
@@ -1,4 +1,5 @@
import { BaseConfig, BaseController, BaseState, EthGasPriceEstimate, GasFeeEstimates, GasFeeState, Transaction } from '@metamask/controllers';
+import { Hex } from '@metamask/utils';
import { SwapsError } from './swapsUtil';
import { APIAggregatorMetadata, APIFetchQuotesMetadata, APIFetchQuotesParams, ChainData, ChainCache, Quote, QuoteSavings, QuoteValues, SwapsAsset, SwapsToken } from './swapsInterfaces';
interface CustomEthGasPriceEstimate {
@@ -19,8 +20,8 @@ export interface SwapsConfig extends BaseConfig {
fetchTokensThreshold: number;
fetchTopAssetsThreshold: number;
provider: any;
- chainId: string;
- supportedChainIds: string[];
+ chainId: Hex;
+ supportedChainIds: Hex[];
}
export interface SwapsState extends BaseState {
quotes: {
@@ -120,11 +121,11 @@ export default class SwapsController extends BaseController<SwapsConfig, SwapsSt
fetchGasFeeEstimates?: () => Promise<GasFeeState | undefined>;
fetchEstimatedMultiLayerL1Fee?: (eth: any, options: {
txParams: Transaction;
- chainId: string;
+ chainId: Hex;
}) => Promise<string | undefined>;
}, config?: Partial<SwapsConfig>, state?: Partial<SwapsState>);
set provider(provider: any);
- set chainId(chainId: string);
+ set chainId(chainId: Hex);
/**
* Updates all quotes with a new custom gas price
*
diff --git a/node_modules/@metamask/swaps-controller/dist/SwapsController.js b/node_modules/@metamask/swaps-controller/dist/SwapsController.js
index 3ad23f0..50fc0a2 100644
--- a/node_modules/@metamask/swaps-controller/dist/SwapsController.js
+++ b/node_modules/@metamask/swaps-controller/dist/SwapsController.js
@@ -83,7 +83,7 @@ class SwapsController extends controllers_1.BaseController {
fetchTokensThreshold: 1000 * 60 * 60 * 24,
fetchTopAssetsThreshold: 1000 * 60 * 30,
provider: undefined,
- chainId: '1',
+ chainId: '0x1',
supportedChainIds: [
swapsUtil_1.ETH_CHAIN_ID,
swapsUtil_1.BSC_CHAIN_ID,
@@ -132,7 +132,7 @@ class SwapsController extends controllers_1.BaseController {
usedGasEstimate: null,
usedCustomGas: null,
chainCache: {
- '1': exports.INITIAL_CHAIN_DATA,
+ '0x1': exports.INITIAL_CHAIN_DATA,
},
};
this.fetchGasFeeEstimates = fetchGasFeeEstimates;
diff --git a/node_modules/@metamask/swaps-controller/dist/constants.d.ts b/node_modules/@metamask/swaps-controller/dist/constants.d.ts
index 99f1c9c..db732d9 100644
--- a/node_modules/@metamask/swaps-controller/dist/constants.d.ts
+++ b/node_modules/@metamask/swaps-controller/dist/constants.d.ts
@@ -1,13 +1,13 @@
import { SwapsToken } from './swapsInterfaces';
-export declare const ETH_CHAIN_ID = "1";
-export declare const BSC_CHAIN_ID = "56";
-export declare const POLYGON_CHAIN_ID = "137";
-export declare const AVALANCHE_CHAIN_ID = "43114";
-export declare const ARBITRUM_CHAIN_ID = "42161";
-export declare const OPTIMISM_CHAIN_ID = "10";
-export declare const ZKSYNC_ERA_CHAIN_ID = "324";
-export declare const LINEA_CHAIN_ID = "59144";
-export declare const SWAPS_TESTNET_CHAIN_ID = "1337";
+export declare const ETH_CHAIN_ID: `0x${string}`;
+export declare const BSC_CHAIN_ID: `0x${string}`;
+export declare const POLYGON_CHAIN_ID: `0x${string}`;
+export declare const AVALANCHE_CHAIN_ID: `0x${string}`;
+export declare const ARBITRUM_CHAIN_ID: `0x${string}`;
+export declare const OPTIMISM_CHAIN_ID: `0x${string}`;
+export declare const ZKSYNC_ERA_CHAIN_ID: `0x${string}`;
+export declare const LINEA_CHAIN_ID: `0x${string}`;
+export declare const SWAPS_TESTNET_CHAIN_ID: `0x${string}`;
export declare const CHAIN_ID_TO_NAME_MAP: {
[key: string]: string;
};
diff --git a/node_modules/@metamask/swaps-controller/dist/constants.js b/node_modules/@metamask/swaps-controller/dist/constants.js
index 9d8a521..601fd18 100644
--- a/node_modules/@metamask/swaps-controller/dist/constants.js
+++ b/node_modules/@metamask/swaps-controller/dist/constants.js
@@ -1,16 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MAX_GAS_LIMIT = exports.DEFAULT_ERC20_APPROVE_GAS = exports.TOKEN_TRANSFER_LOG_TOPIC_HASH = exports.SWAPS_NATIVE_TOKEN_OBJECTS = exports.LINEA_SWAPS_TOKEN_OBJECT = exports.ZKSYNC_ERA_SWAPS_TOKEN_OBJECT = exports.OPTIMISM_SWAPS_TOKEN_OBJECT = exports.ARBITRUM_SWAPS_TOKEN_OBJECT = exports.AVALANCHE_SWAPS_TOKEN_OBJECT = exports.POLYGON_SWAPS_TOKEN_OBJECT = exports.BSC_SWAPS_TOKEN_OBJECT = exports.ETH_SWAPS_TOKEN_OBJECT = exports.NATIVE_SWAPS_TOKEN_ADDRESS = exports.ALLOWED_CONTRACT_ADDRESSES = exports.SWAPS_CONTRACT_ADDRESSES = exports.SWAPS_WRAPPED_TOKENS_ADDRESSES = exports.WETH_LINEA_CONTRACT_ADDRESS = exports.WETH_ZKSYNC_ERA_CONTRACT_ADDRESS = exports.WETH_OPTIMISM_CONTRACT_ADDRESS = exports.WETH_ARBITRUM_CONTRACT_ADDRESS = exports.WAVAX_CONTRACT_ADDRESS = exports.WMATIC_CONTRACT_ADDRESS = exports.WBNB_CONTRACT_ADDRESS = exports.WETH_CONTRACT_ADDRESS = exports.LINEA_SWAPS_CONTRACT_ADDRESS = exports.ZKSYNC_ERA_SWAPS_CONTRACT_ADDRESS = exports.OPTIMISM_SWAPS_CONTRACT_ADDRESS = exports.ARBITRUM_SWAPS_CONTRACT_ADDRESS = exports.AVALANCHE_SWAPS_CONTRACT_ADDRESS = exports.POLYGON_SWAPS_CONTRACT_ADDRESS = exports.BSC_SWAPS_CONTRACT_ADDRESS = exports.ETH_SWAPS_CONTRACT_ADDRESS = exports.GAS_API_BASE_URL = exports.DEV_BASE_URL = exports.API_BASE_URL = exports.CHAIN_ID_TO_NAME_MAP = exports.SWAPS_TESTNET_CHAIN_ID = exports.LINEA_CHAIN_ID = exports.ZKSYNC_ERA_CHAIN_ID = exports.OPTIMISM_CHAIN_ID = exports.ARBITRUM_CHAIN_ID = exports.AVALANCHE_CHAIN_ID = exports.POLYGON_CHAIN_ID = exports.BSC_CHAIN_ID = exports.ETH_CHAIN_ID = void 0;
+const controller_utils_1 = require("@metamask/controller-utils");
//* Chain IDs and names
-exports.ETH_CHAIN_ID = '1';
-exports.BSC_CHAIN_ID = '56';
-exports.POLYGON_CHAIN_ID = '137';
-exports.AVALANCHE_CHAIN_ID = '43114';
-exports.ARBITRUM_CHAIN_ID = '42161';
-exports.OPTIMISM_CHAIN_ID = '10';
-exports.ZKSYNC_ERA_CHAIN_ID = '324';
-exports.LINEA_CHAIN_ID = '59144';
-exports.SWAPS_TESTNET_CHAIN_ID = '1337';
+exports.ETH_CHAIN_ID = controller_utils_1.toHex('1');
+exports.BSC_CHAIN_ID = controller_utils_1.toHex('56');
+exports.POLYGON_CHAIN_ID = controller_utils_1.toHex('137');
+exports.AVALANCHE_CHAIN_ID = controller_utils_1.toHex('43114');
+exports.ARBITRUM_CHAIN_ID = controller_utils_1.toHex('42161');
+exports.OPTIMISM_CHAIN_ID = controller_utils_1.toHex('10');
+exports.ZKSYNC_ERA_CHAIN_ID = controller_utils_1.toHex('324');
+exports.LINEA_CHAIN_ID = controller_utils_1.toHex('59144');
+exports.SWAPS_TESTNET_CHAIN_ID = controller_utils_1.toHex('1337');
exports.CHAIN_ID_TO_NAME_MAP = {
[exports.ETH_CHAIN_ID]: 'ethereum',
[exports.BSC_CHAIN_ID]: 'bsc',
diff --git a/node_modules/@metamask/swaps-controller/dist/swapsUtil.d.ts b/node_modules/@metamask/swaps-controller/dist/swapsUtil.d.ts
index 0204cab..b2f7c19 100644
--- a/node_modules/@metamask/swaps-controller/dist/swapsUtil.d.ts
+++ b/node_modules/@metamask/swaps-controller/dist/swapsUtil.d.ts
@@ -1,6 +1,7 @@
import { Transaction } from '@metamask/controllers';
import { AbortSignal } from 'abort-controller';
import { BigNumber } from 'bignumber.js';
+import { Hex } from '@metamask/utils';
import { APIAggregatorMetadata, SwapsAsset, SwapsToken, APIType, Quote, APIFetchQuotesParams, QuoteValues, TransactionReceipt, NetworkFeatureFlags } from './swapsInterfaces';
export * from './constants';
export declare enum SwapsError {
@@ -14,27 +15,27 @@ export declare enum SwapsError {
SWAPS_ALLOWANCE_TIMEOUT = "swaps-allowance-timeout",
SWAPS_ALLOWANCE_ERROR = "swaps-allowance-error"
}
-export declare function getNativeSwapsToken(chainId: string): SwapsToken;
-export declare function getSwapsContractAddress(chainId: string): string;
-export declare function isValidContractAddress(chainId: string, contract: string | undefined): boolean;
-export declare function shouldEnableDirectWrapping(chainId: string, sourceToken: string, destinationToken: string): boolean;
-export declare const getBaseApiURL: (type: APIType, chainId: string) => string;
-export declare function getTokenMetadataURL(chainId: string): string;
-export declare function fetchTradesInfo({ slippage, sourceToken, sourceAmount, destinationToken, walletAddress, }: APIFetchQuotesParams, abortSignal: AbortSignal | null, chainId: string, clientId?: string): Promise<{
+export declare function getNativeSwapsToken(chainId: Hex): SwapsToken;
+export declare function getSwapsContractAddress(chainId: Hex): string;
+export declare function isValidContractAddress(chainId: Hex, contract: string | undefined): boolean;
+export declare function shouldEnableDirectWrapping(chainId: Hex, sourceToken: string, destinationToken: string): boolean;
+export declare const getBaseApiURL: (type: APIType, chainId: Hex) => string;
+export declare function getTokenMetadataURL(chainId: Hex): string;
+export declare function fetchTradesInfo({ slippage, sourceToken, sourceAmount, destinationToken, walletAddress, }: APIFetchQuotesParams, abortSignal: AbortSignal | null, chainId: Hex, clientId?: string): Promise<{
[key: string]: Quote;
}>;
-export declare function fetchTokens(chainId: string, clientId?: string): Promise<SwapsToken[]>;
-export declare function fetchAggregatorMetadata(chainId: string, clientId?: string): Promise<{
+export declare function fetchTokens(chainId: Hex, clientId?: string): Promise<SwapsToken[]>;
+export declare function fetchAggregatorMetadata(chainId: Hex, clientId?: string): Promise<{
[key: string]: APIAggregatorMetadata;
}>;
-export declare function fetchTopAssets(chainId: string, clientId?: string): Promise<SwapsAsset[]>;
-export declare function fetchSwapsFeatureLiveness(chainId: string, clientId?: string): Promise<NetworkFeatureFlags | undefined>;
+export declare function fetchTopAssets(chainId: Hex, clientId?: string): Promise<SwapsAsset[]>;
+export declare function fetchSwapsFeatureLiveness(chainId: Hex, clientId?: string): Promise<NetworkFeatureFlags | undefined>;
/**
* Fetches gas prices from API URL
* @param chainId Current chainId
* @returns Gas prices represented as decimal GWEI strings
*/
-export declare function fetchGasPrices(chainId: string, clientId?: string): Promise<{
+export declare function fetchGasPrices(chainId: Hex, clientId?: string): Promise<{
safeGasPrice: string;
proposedGasPrice: string;
fastGasPrice: string;
diff --git a/node_modules/@metamask/swaps-controller/dist/swapsUtil.js b/node_modules/@metamask/swaps-controller/dist/swapsUtil.js
index 54a32d5..3fa4343 100644
--- a/node_modules/@metamask/swaps-controller/dist/swapsUtil.js
+++ b/node_modules/@metamask/swaps-controller/dist/swapsUtil.js
@@ -14,6 +14,7 @@ exports.constructTxParams = exports.estimateGas = exports.calcTokenAmount = expo
const controllers_1 = require("@metamask/controllers");
const bignumber_js_1 = require("bignumber.js");
const ethereumjs_util_1 = require("ethereumjs-util");
+const controller_utils_1 = require("@metamask/controller-utils");
const constants_1 = require("./constants");
const swapsInterfaces_1 = require("./swapsInterfaces");
__exportStar(require("./constants"), exports);
@@ -70,21 +71,22 @@ const getBaseApiURL = function (type, chainId) {
const [apiChainId, apiBaseUrl] = chainId === constants_1.SWAPS_TESTNET_CHAIN_ID
? [constants_1.ETH_CHAIN_ID, constants_1.DEV_BASE_URL]
: [chainId, constants_1.API_BASE_URL];
+ const apiDecimalChainId = controller_utils_1.convertHexToDecimal(apiChainId);
switch (type) {
case swapsInterfaces_1.APIType.TRADES:
- return `${apiBaseUrl}/networks/${apiChainId}/trades`;
+ return `${apiBaseUrl}/networks/${apiDecimalChainId}/trades`;
case swapsInterfaces_1.APIType.TOKENS:
- return `${apiBaseUrl}/networks/${apiChainId}/tokens`;
+ return `${apiBaseUrl}/networks/${apiDecimalChainId}/tokens`;
case swapsInterfaces_1.APIType.TOKEN:
- return `${apiBaseUrl}/networks/${apiChainId}/token`;
+ return `${apiBaseUrl}/networks/${apiDecimalChainId}/token`;
case swapsInterfaces_1.APIType.TOP_ASSETS:
- return `${apiBaseUrl}/networks/${apiChainId}/topAssets`;
+ return `${apiBaseUrl}/networks/${apiDecimalChainId}/topAssets`;
case swapsInterfaces_1.APIType.FEATURE_FLAG:
return `${apiBaseUrl}/featureFlags`;
case swapsInterfaces_1.APIType.AGGREGATOR_METADATA:
- return `${apiBaseUrl}/networks/${apiChainId}/aggregatorMetadata`;
+ return `${apiBaseUrl}/networks/${apiDecimalChainId}/aggregatorMetadata`;
case swapsInterfaces_1.APIType.GAS_PRICES:
- return `${constants_1.GAS_API_BASE_URL}/networks/${apiChainId}/gasPrices`;
+ return `${constants_1.GAS_API_BASE_URL}/networks/${apiDecimalChainId}/gasPrices`;
default:
throw new Error('getBaseApiURL requires an api call type');
}
32 changes: 32 additions & 0 deletions patches/bip39+2.6.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/node_modules/bip39/index.js b/node_modules/bip39/index.js
index efed68c..d487227 100644
--- a/node_modules/bip39/index.js
+++ b/node_modules/bip39/index.js
@@ -4,6 +4,8 @@ var _pbkdf2 = require('pbkdf2')
var pbkdf2 = _pbkdf2.pbkdf2Sync
var pbkdf2Async = _pbkdf2.pbkdf2
var randomBytes = require('randombytes')
+const { NativeModules } = require('react-native')
+const Aes = NativeModules.Aes

// use unorm until String.prototype.normalize gets better browser support
var unorm = require('unorm')
@@ -49,11 +51,15 @@ function salt (password) {
return 'mnemonic' + (password || '')
}

-function mnemonicToSeed (mnemonic, password) {
+function mnemonicToSeed(mnemonic, password) {
var mnemonicBuffer = Buffer.from(unorm.nfkd(mnemonic), 'utf8')
var saltBuffer = Buffer.from(salt(unorm.nfkd(password)), 'utf8')
-
- return pbkdf2(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512')
+ // For chrome environments use the javascript version of pbkdf2
+ if (__DEV__ && (!!global.__REMOTEDEV__ || (global.location && global.location.pathname.includes('/debugger-ui'))))
+ return pbkdf2(mnemonicBuffer, saltBuffer, 2048, 64, 'sha512')
+ const seed = Aes.pbkdf2Sync(mnemonicBuffer.toString('utf8'), saltBuffer.toString('utf8'), 2048, 512);
+ const seedBuffer = global.Buffer.from(seed, "hex")
+ return seedBuffer
}

function mnemonicToSeedHex (mnemonic, password) {
Loading
Loading