Skip to content

Commit

Permalink
feat(ramps): introduces dynamic support for rampable networks (#24041)
Browse files Browse the repository at this point in the history
## **Description**

This PR introduces a new reducer for Ramps to store an array of
"buyable" networks. A "buyable chain" is one that the native token has
onramp support for. This BUYABLE_CHAINS_MAP list is currently
hard-coded, and this PR fetches a dynamic network list from the Ramps
API instead. The list of supported networks by the MetMask onramp team
is dynamic and is based on provider support among other things.

There are several fallback protections in place. Buyable chains will
default to the current hard-coded list before loading and will default
to that same list if there are any errors. There is no need for loading
or error states.

The ramps base API url has been added as a new environment variable,
defaulted to production. example:
METAMASK_RAMP_API_BASE_URL=https://on-ramp-content.metaswap.codefi.network

Here's screenshot to show the issue this PR will fix. Base network is
supported as a buyable network. but because the hard-coded array of
networks does not include base we do not enable the buy CTAs:



![image](https://github.com/MetaMask/metamask-extension/assets/15269424/76023685-06a5-4ff7-9f59-8beda3dd9593)


[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/24041?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

1. Go to this page...
2.
3.

## **Screenshots/Recordings**

**Video Description of the changes in the PR (5 min)**
https://www.loom.com/share/973960816e7e497aae51ed1cdc3cebf5

### **Before**

<!-- [screenshots/recordings] -->

### **After**

<!-- [screenshots/recordings] -->

## **Pre-merge author checklist**

- [x] I’ve followed [MetaMask Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x] I've completed the PR template to the best of my ability
- [x] I’ve included tests if applicable
- [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format
if applicable
- [x] I’ve applied the right labels on the PR (see [labeling
guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)).
Not required for external contributors.

## **Pre-merge reviewer checklist**

- [x] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [x] I confirm that this PR addresses all acceptance criteria described
in the ticket it closes and includes the necessary testing evidence such
as recordings and or screenshots.

---------

Co-authored-by: Nicolas Ferro <nicolaspatricioferro@gmail.com>
Co-authored-by: Pedro Pablo Aste Kompen <wachunei@gmail.com>
  • Loading branch information
3 people authored Jun 27, 2024
1 parent a32cbb8 commit a166147
Show file tree
Hide file tree
Showing 40 changed files with 812 additions and 194 deletions.
2 changes: 2 additions & 0 deletions builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ env:
# Enables the notifications feature within the build:
- NOTIFICATIONS: ''

- METAMASK_RAMP_API_CONTENT_BASE_URL: https://on-ramp-content.api.cx.metamask.io

###
# Meta variables
###
Expand Down
2 changes: 2 additions & 0 deletions privacy-snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
"phishing-detection.api.cx.metamask.io",
"portfolio.metamask.io",
"price.api.cx.metamask.io",
"on-ramp-content.api.cx.metamask.io",
"on-ramp-content.uat-api.cx.metamask.io",
"proxy.api.cx.metamask.io",
"raw.githubusercontent.com",
"registry.npmjs.org",
Expand Down
118 changes: 0 additions & 118 deletions shared/constants/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,6 @@ export type RPCDefinition = {
rpcPrefs: RPCPreferences;
};

/**
* For each chain that we support fiat onramps for, we provide a set of
* configuration options that help for initializing the connectiong to the
* onramp providers.
*/
type BuyableChainSettings = {
/**
* The native currency for the given chain
*/
nativeCurrency: CurrencySymbol | TestNetworkCurrencySymbol;
/**
* The network name or identifier
*/
network: string;
};

/**
* Throughout the extension we set the current provider by referencing its
* "type", which can be any of the values in the below object. These values
Expand Down Expand Up @@ -908,108 +892,6 @@ export const UNSUPPORTED_RPC_METHODS = new Set([

export const IPFS_DEFAULT_GATEWAY_URL = 'dweb.link';

// The first item in transakCurrencies must be the
// default crypto currency for the network
const BUYABLE_CHAIN_ETHEREUM_NETWORK_NAME = 'ethereum';

export const BUYABLE_CHAINS_MAP: {
[K in Exclude<
ChainId,
| typeof CHAIN_IDS.LOCALHOST
| typeof CHAIN_IDS.OPTIMISM_TESTNET
| typeof CHAIN_IDS.OPTIMISM_GOERLI
| typeof CHAIN_IDS.BASE_TESTNET
| typeof CHAIN_IDS.OPBNB_TESTNET
| typeof CHAIN_IDS.OPBNB
| typeof CHAIN_IDS.BSC_TESTNET
| typeof CHAIN_IDS.POLYGON_TESTNET
| typeof CHAIN_IDS.AVALANCHE_TESTNET
| typeof CHAIN_IDS.FANTOM_TESTNET
| typeof CHAIN_IDS.MOONBEAM_TESTNET
| typeof CHAIN_IDS.LINEA_GOERLI
| typeof CHAIN_IDS.LINEA_SEPOLIA
| typeof CHAIN_IDS.GOERLI
| typeof CHAIN_IDS.SEPOLIA
| typeof CHAIN_IDS.GNOSIS
| typeof CHAIN_IDS.AURORA
| typeof CHAIN_IDS.ARBITRUM_GOERLI
| typeof CHAIN_IDS.BLAST
| typeof CHAIN_IDS.FILECOIN
| typeof CHAIN_IDS.POLYGON_ZKEVM
| typeof CHAIN_IDS.SCROLL
| typeof CHAIN_IDS.SCROLL_SEPOLIA
| typeof CHAIN_IDS.WETHIO
| typeof CHAIN_IDS.CHZ
| typeof CHAIN_IDS.NUMBERS
| typeof CHAIN_IDS.SEI
>]: BuyableChainSettings;
} = {
[CHAIN_IDS.MAINNET]: {
nativeCurrency: CURRENCY_SYMBOLS.ETH,
network: BUYABLE_CHAIN_ETHEREUM_NETWORK_NAME,
},
[CHAIN_IDS.BSC]: {
nativeCurrency: CURRENCY_SYMBOLS.BNB,
network: 'bsc',
},
[CHAIN_IDS.POLYGON]: {
nativeCurrency: CURRENCY_SYMBOLS.MATIC,
network: 'polygon',
},
[CHAIN_IDS.AVALANCHE]: {
nativeCurrency: CURRENCY_SYMBOLS.AVALANCHE,
network: 'avaxcchain',
},
[CHAIN_IDS.FANTOM]: {
nativeCurrency: CURRENCY_SYMBOLS.FANTOM,
network: 'fantom',
},
[CHAIN_IDS.CELO]: {
nativeCurrency: CURRENCY_SYMBOLS.CELO,
network: 'celo',
},
[CHAIN_IDS.OPTIMISM]: {
nativeCurrency: CURRENCY_SYMBOLS.ETH,
network: 'optimism',
},
[CHAIN_IDS.ARBITRUM]: {
nativeCurrency: CURRENCY_SYMBOLS.ARBITRUM,
network: 'arbitrum',
},
[CHAIN_IDS.CRONOS]: {
nativeCurrency: CURRENCY_SYMBOLS.CRONOS,
network: 'cronos',
},
[CHAIN_IDS.MOONBEAM]: {
nativeCurrency: CURRENCY_SYMBOLS.GLIMMER,
network: 'moonbeam',
},
[CHAIN_IDS.MOONRIVER]: {
nativeCurrency: CURRENCY_SYMBOLS.MOONRIVER,
network: 'moonriver',
},
[CHAIN_IDS.HARMONY]: {
nativeCurrency: CURRENCY_SYMBOLS.ONE,
network: 'harmony',
},
[CHAIN_IDS.PALM]: {
nativeCurrency: CURRENCY_SYMBOLS.PALM,
network: 'palm',
},
[CHAIN_IDS.LINEA_MAINNET]: {
nativeCurrency: CURRENCY_SYMBOLS.ETH,
network: 'linea',
},
[CHAIN_IDS.ZKSYNC_ERA]: {
nativeCurrency: CURRENCY_SYMBOLS.ETH,
network: 'zksync',
},
[CHAIN_IDS.BASE]: {
nativeCurrency: CURRENCY_SYMBOLS.ETH,
network: 'base',
},
};

export const FEATURED_RPCS: RPCDefinition[] = [
{
chainId: CHAIN_IDS.ARBITRUM,
Expand Down
137 changes: 137 additions & 0 deletions test/data/mock-send-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,143 @@
],
"swapsState": {}
},
"ramps": {
"buyableChains": [
{
"active": true,
"chainId": 1,
"chainName": "Ethereum Mainnet",
"shortName": "Ethereum",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 10,
"chainName": "Optimism Mainnet",
"shortName": "Optimism",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 25,
"chainName": "Cronos Mainnet",
"shortName": "Cronos",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 56,
"chainName": "BNB Chain Mainnet",
"shortName": "BNB Chain",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 100,
"chainName": "Gnosis Mainnet",
"shortName": "Gnosis",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 137,
"chainName": "Polygon Mainnet",
"shortName": "Polygon",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 250,
"chainName": "Fantom Mainnet",
"shortName": "Fantom",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 324,
"chainName": "zkSync Era Mainnet",
"shortName": "zkSync Era",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 1101,
"chainName": "Polygon zkEVM",
"shortName": "Polygon zkEVM",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 1284,
"chainName": "Moonbeam Mainnet",
"shortName": "Moonbeam",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 1285,
"chainName": "Moonriver Mainnet",
"shortName": "Moonriver",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 8453,
"chainName": "Base Mainnet",
"shortName": "Base",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 42161,
"chainName": "Arbitrum Mainnet",
"shortName": "Arbitrum",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 42220,
"chainName": "Celo Mainnet",
"shortName": "Celo",
"nativeTokenSupported": false
},
{
"active": true,
"chainId": 43114,
"chainName": "Avalanche C-Chain Mainnet",
"shortName": "Avalanche C-Chain",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 59144,
"chainName": "Linea",
"shortName": "Linea",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 1313161554,
"chainName": "Aurora Mainnet",
"shortName": "Aurora",
"nativeTokenSupported": false
},
{
"active": true,
"chainId": 1666600000,
"chainName": "Harmony Mainnet (Shard 0)",
"shortName": "Harmony (Shard 0)",
"nativeTokenSupported": true
},
{
"active": true,
"chainId": 11297108109,
"chainName": "Palm Mainnet",
"shortName": "Palm",
"nativeTokenSupported": false
}
]
},
"send": {
"amountMode": "INPUT",
"currentTransactionUUID": "1-tx",
Expand Down
Loading

0 comments on commit a166147

Please sign in to comment.