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

Add Base networks #3378

Merged
merged 2 commits into from
Apr 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ else if (chainId == GOERLI_ID || etherscanAPI.startsWith(ARBISCAN_API))
{
return new TransferFetchType[]{TransferFetchType.ERC_20, TransferFetchType.ERC_721};
}
else if (etherscanAPI.contains(MATIC_API) || etherscanAPI.contains(ETHERSCAN_API) || etherscanAPI.contains(OKX_API))
else if (etherscanAPI.contains(MATIC_API) || etherscanAPI.contains(ETHERSCAN_API) || etherscanAPI.contains(OKX_API) || etherscanAPI.contains("basescan.org"))
{
return new TransferFetchType[]{TransferFetchType.ERC_20, TransferFetchType.ERC_721, TransferFetchType.ERC_1155};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
import static com.alphawallet.ethereum.EthereumNetworkBase.AURORA_TESTNET_RPC_URL;
import static com.alphawallet.ethereum.EthereumNetworkBase.AVALANCHE_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.AVALANCHE_RPC_URL;
import static com.alphawallet.ethereum.EthereumNetworkBase.BASE_FREE_MAINNET_RPC;
import static com.alphawallet.ethereum.EthereumNetworkBase.BASE_FREE_TESTNET_RPC;
import static com.alphawallet.ethereum.EthereumNetworkBase.BASE_MAINNET_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.BASE_TESTNET_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.BINANCE_MAIN_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.BINANCE_TEST_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.CLASSIC_ID;
Expand Down Expand Up @@ -160,6 +164,8 @@ public abstract class EthereumNetworkBase implements EthereumNetworkRepositoryTy

public static final String AMOY_RPC_FALLBACK = usesProductionKey ? AMOY_TEST_RPC_URL : "https://polygon-amoy-bor-rpc.publicnode.com";



public static final String USE_KLAYTN_RPC = !TextUtils.isEmpty(keyProvider.getBlockPiCypressKey()) ? "https://klaytn.blockpi.network/v1/rpc/" + keyProvider.getBlockPiCypressKey()
: KLAYTN_RPC;
public static final String USE_KLAYTN_BAOBAB_RPC = !TextUtils.isEmpty(keyProvider.getBlockPiBaobabKey()) ? "https://klaytn-baobab.blockpi.network/v1/rpc/" + keyProvider.getBlockPiBaobabKey()
Expand All @@ -175,6 +181,10 @@ public abstract class EthereumNetworkBase implements EthereumNetworkRepositoryTy
public static final String LINEA_FALLBACK_RPC = usesProductionKey ? LINEA_FREE_RPC : "https://linea.drpc.org";
public static final String LINEA_RPC = usesProductionKey ? "https://linea-mainnet.infura.io/v3/" + keyProvider.getInfuraKey() : LINEA_FALLBACK_RPC;
public static final String LINEA_TEST_RPC = usesProductionKey ? "https://linea-goerli.infura.io/v3/" + keyProvider.getInfuraKey() : LINEA_TEST_FREE_RPC;
public static final String BASE_RPC = usesProductionKey ? "https://base-mainnet.infura.io/v3/" + keyProvider.getInfuraKey() : BASE_FREE_MAINNET_RPC;
public static final String BASE_FALLBACK_RPC = usesProductionKey ? BASE_FREE_MAINNET_RPC : "https://base-mainnet.public.blastapi.io";
public static final String BASE_TEST_RPC = usesProductionKey ? "https://base-sepolia.infura.io/v3/" + keyProvider.getInfuraKey() : BASE_FREE_TESTNET_RPC;
public static final String BASE_TEST_FALLBACK_RPC = usesProductionKey ? BASE_FREE_TESTNET_RPC : "https://sepolia.base.org";

//Note that AlphaWallet now uses a double node configuration. See class AWHttpService comment 'try primary node'.
//If you supply a main RPC and secondary it will try the secondary if the primary node times out after 10 seconds.
Expand All @@ -199,17 +209,18 @@ public abstract class EthereumNetworkBase implements EthereumNetworkRepositoryTy
//If your wallet prioritises xDai for example, you may want to move the XDAI_ID to the front of this list,
//Then xDai would appear as the first token at the top of the wallet
private static final List<Long> hasValue = new ArrayList<>(Arrays.asList(
MAINNET_ID, GNOSIS_ID, POLYGON_ID, ROOTSTOCK_MAINNET_ID, CLASSIC_ID, LINEA_ID, BINANCE_MAIN_ID, HECO_ID, AVALANCHE_ID,
MAINNET_ID, GNOSIS_ID, POLYGON_ID, ROOTSTOCK_MAINNET_ID, CLASSIC_ID, LINEA_ID, BASE_MAINNET_ID, BINANCE_MAIN_ID, HECO_ID, AVALANCHE_ID,
FANTOM_ID, OPTIMISTIC_MAIN_ID, CRONOS_MAIN_ID, ARBITRUM_MAIN_ID, PALM_ID, KLAYTN_ID, IOTEX_MAINNET_ID, AURORA_MAINNET_ID, MILKOMEDA_C1_ID, OKX_ID));

private static final List<Long> testnetList = new ArrayList<>(Arrays.asList(
SEPOLIA_TESTNET_ID, POLYGON_AMOY_ID, HOLESKY_ID, GOERLI_ID, BINANCE_TEST_ID,
SEPOLIA_TESTNET_ID, POLYGON_AMOY_ID, HOLESKY_ID, BASE_TESTNET_ID, GOERLI_ID, BINANCE_TEST_ID,
ROOTSTOCK_TESTNET_ID, CRONOS_TEST_ID, OPTIMISM_GOERLI_TEST_ID, POLYGON_TEST_ID, ARBITRUM_GOERLI_TEST_ID, LINEA_TEST_ID, KLAYTN_BAOBAB_ID,
FANTOM_TEST_ID, IOTEX_TESTNET_ID, FUJI_TEST_ID, MILKOMEDA_C1_TEST_ID,
AURORA_TESTNET_ID, PALM_TEST_ID));

private static final List<Long> deprecatedNetworkList = new ArrayList<>(Arrays.asList(
// Add deprecated testnet IDs here
POLYGON_TEST_ID, GOERLI_ID
));

private static final String INFURA_ENDPOINT = ".infura.io/v3/";
Expand Down Expand Up @@ -374,6 +385,14 @@ public static boolean isOKX(NetworkInfo networkInfo)
HOLESKY_RPC_URL,
"https://holesky.etherscan.io/tx/", HOLESKY_ID, HOLESKY_BACKUP_RPC_URL,
"https://api-holesky.etherscan.io/api?"));
put(BASE_MAINNET_ID, new NetworkInfo(C.BASE_MAINNET_NAME, C.ETH_SYMBOL,
BASE_RPC,
"https://basescan.org/tx/", BASE_MAINNET_ID, BASE_FALLBACK_RPC,
"https://api.basescan.org/api?"));
put(BASE_TESTNET_ID, new NetworkInfo(C.BASE_TESTNET_NAME, C.ETH_SYMBOL,
BASE_TEST_RPC,
"https://sepolia.basescan.org/tx/", BASE_TESTNET_ID, BASE_TEST_FALLBACK_RPC,
"https://api-sepolia.basescan.org/api?"));

// Add deprecated networks after this line
}
Expand Down Expand Up @@ -423,6 +442,8 @@ public static boolean isOKX(NetworkInfo networkInfo)
put(LINEA_TEST_ID, R.drawable.ic_icons_linea_testnet);
put(HOLESKY_ID, R.drawable.ic_icons_holesky);
put(POLYGON_TEST_ID, R.drawable.ic_icons_tokens_mumbai);
put(BASE_MAINNET_ID, R.drawable.ic_base_logo);
put(BASE_TESTNET_ID, R.drawable.ic_base_test_logo);
}
};

Expand Down Expand Up @@ -466,6 +487,8 @@ public static boolean isOKX(NetworkInfo networkInfo)
put(LINEA_ID, R.drawable.ic_icons_linea);
put(LINEA_TEST_ID, R.drawable.ic_icons_linea_testnet);
put(HOLESKY_ID, R.drawable.ic_icons_holesky);
put(BASE_MAINNET_ID, R.drawable.ic_base_logo);
put(BASE_TESTNET_ID, R.drawable.ic_base_test_logo);
}
};

Expand Down Expand Up @@ -509,6 +532,8 @@ public static boolean isOKX(NetworkInfo networkInfo)
put(LINEA_ID, R.color.black);
put(LINEA_TEST_ID, R.color.pinkish_grey);
put(HOLESKY_ID, R.color.azure);
put(BASE_MAINNET_ID, R.color.base_logo);
put(BASE_TESTNET_ID, R.color.base_logo);
}
};

Expand All @@ -517,7 +542,7 @@ public static boolean isOKX(NetworkInfo networkInfo)
// <etherscanAPI from the above list> + GAS_API
//If the gas oracle you're adding doesn't follow this spec then you'll have to change the getGasOracle method
private static final List<Long> hasGasOracleAPI = Arrays.asList(MAINNET_ID, POLYGON_ID, ARBITRUM_MAIN_ID, AVALANCHE_ID, BINANCE_MAIN_ID, CRONOS_MAIN_ID, GOERLI_ID,
SEPOLIA_TESTNET_ID, FANTOM_ID, LINEA_ID, OPTIMISTIC_MAIN_ID, POLYGON_TEST_ID, POLYGON_AMOY_ID);
SEPOLIA_TESTNET_ID, FANTOM_ID, LINEA_ID, OPTIMISTIC_MAIN_ID, POLYGON_TEST_ID, POLYGON_AMOY_ID, BASE_MAINNET_ID, BASE_TESTNET_ID);
private static final List<Long> hasEtherscanGasOracleAPI = Arrays.asList(MAINNET_ID, HECO_ID, BINANCE_MAIN_ID, POLYGON_ID);
private static final List<Long> hasBlockNativeGasOracleAPI = Arrays.asList(MAINNET_ID, POLYGON_ID);
//These chains don't allow custom gas
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/com/alphawallet/app/service/GasService.java
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ public Single<GasEstimate> calculateGasEstimateInternal(byte[] transactionBytes,
updateChainId(chainId);
String finalTxData = txData;

BigInteger useGasLimit = defaultLimit.equals(BigInteger.ZERO) ? EthereumNetworkBase.getMaxGasLimit(chainId) : defaultLimit;

if ((toAddress.equals("") || toAddress.equals(ZERO_ADDRESS)) && txData.length() > 0) //Check gas for constructor
{
return networkRepository.getLastTransactionNonce(web3j, wallet.address)
Expand All @@ -389,7 +391,7 @@ public Single<GasEstimate> calculateGasEstimateInternal(byte[] transactionBytes,
else
{
return networkRepository.getLastTransactionNonce(web3j, wallet.address)
.flatMap(nonce -> ethEstimateGas(chainId, wallet.address, nonce, toAddress, amount, finalTxData))
.flatMap(nonce -> ethEstimateGas(chainId, wallet.address, useGasLimit, nonce, toAddress, amount, finalTxData))
.flatMap(estimate -> handleOutOfGasError(estimate, chainId, toAddress, amount, finalTxData))
.map(estimate -> convertToGasLimit(estimate, defaultLimit));
}
Expand Down Expand Up @@ -427,7 +429,7 @@ private Single<EthEstimateGas> handleOutOfGasError(@NonNull EthEstimateGas estim
{
if (!estimate.hasError() || chainId != 1) return Single.fromCallable(() -> estimate);
else return networkRepository.getLastTransactionNonce(web3j, WHALE_ACCOUNT)
.flatMap(nonce -> ethEstimateGas(chainId, WHALE_ACCOUNT, nonce, toAddress, amount, finalTxData));
.flatMap(nonce -> ethEstimateGas(chainId, WHALE_ACCOUNT, EthereumNetworkBase.getMaxGasLimit(chainId), nonce, toAddress, amount, finalTxData));
}

private BigInteger getLowGasPrice()
Expand All @@ -443,14 +445,14 @@ private Single<EthEstimateGas> ethEstimateGas(String fromAddress, BigInteger non
return Single.fromCallable(() -> web3j.ethEstimateGas(transaction).send());
}

private Single<EthEstimateGas> ethEstimateGas(long chainId, String fromAddress, BigInteger nonce, String toAddress,
private Single<EthEstimateGas> ethEstimateGas(long chainId, String fromAddress, BigInteger limit, BigInteger nonce, String toAddress,
BigInteger amount, String txData)
{
final Transaction transaction = new Transaction (
fromAddress,
nonce,
currentGasPrice,
EthereumNetworkBase.getMaxGasLimit(chainId),
limit,
toAddress,
amount,
txData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.alphawallet.ethereum.EthereumNetworkBase.ARBITRUM_MAIN_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.AURORA_MAINNET_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.AVALANCHE_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.BASE_MAINNET_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.BINANCE_MAIN_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.CLASSIC_ID;
import static com.alphawallet.ethereum.EthereumNetworkBase.CRONOS_MAIN_ID;
Expand Down Expand Up @@ -837,6 +838,7 @@ private void resetTickerUpdate()
put(CRONOS_MAIN_ID, "cronos");
put(ROOTSTOCK_MAINNET_ID, "rootstock");
put(LINEA_ID, "linea");
put(BASE_MAINNET_ID, "base");
}};

// For now, don't use Dexguru unless we obtain API key
Expand Down Expand Up @@ -875,6 +877,7 @@ public void deleteTickers()
put(OKX_ID, "okb");
put(ROOTSTOCK_MAINNET_ID, "rootstock");
put(LINEA_ID, "ethereum");
put(BASE_MAINNET_ID, "base");
}};

public static boolean validateCoinGeckoAPI(Token token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ private String readNextTxBatch(String walletAddress, NetworkInfo networkInfo, lo

private String getNetworkAPIToken(NetworkInfo networkInfo)
{
if (networkInfo.etherscanAPI.contains("etherscan"))
if (networkInfo.etherscanAPI.contains("etherscan") /*|| networkInfo.etherscanAPI.contains("basescan.org")*/)
{
return ETHERSCAN_API_KEY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public interface GasWidgetInterface
BigInteger getPriorityFee();
BigInteger getGasPrice();
void setGasEstimate(BigInteger estimate);
void setGasEstimateExact(BigInteger estimate);
void onDestroy();
boolean checkSufficientGas();
void setupResendSettings(ActionSheetMode mode, BigInteger gasPrice);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ public Web3Transaction(
public Web3Transaction(WCEthereumTransaction wcTx, long callbackId, SignType signType)
{
String gasPrice = wcTx.getGasPrice() != null ? wcTx.getGasPrice() : "0";
String gasLimit = wcTx.getGasLimit() != null ? wcTx.getGasLimit() : "0";
//WC2 uses "gas" for gas limit
String gasLimit = wcTx.getGas() != null ? wcTx.getGas() : "0";
String nonce = wcTx.getNonce() != null ? wcTx.getNonce() : "";

this.recipient = TextUtils.isEmpty(wcTx.getTo()) ? Address.EMPTY : new Address(wcTx.getTo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public ActionSheetDialog(@NonNull Activity activity, Web3Transaction tx, Token t

if (!tx.gasLimit.equals(BigInteger.ZERO))
{
setGasEstimate(new GasEstimate(tx.gasLimit));
gasWidgetInterface.setGasEstimateExact(tx.gasLimit);
functionBar.setPrimaryButtonEnabled(true);
}

updateAmount();
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/alphawallet/app/widget/GasWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,12 @@ public void setGasEstimate(BigInteger estimate)
estimate = estimate.multiply(BigInteger.valueOf(6)).divide(BigInteger.valueOf(5)); // increase estimate by 20% to be safe
}

setGasEstimateExact(estimate);
}

@Override
public void setGasEstimateExact(BigInteger estimate)
{
//Override custom gas limit
if (customGasLimit.equals(baseLineGasLimit))
{
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/com/alphawallet/app/widget/GasWidget2.java
Original file line number Diff line number Diff line change
Expand Up @@ -534,12 +534,17 @@ public long getExpectedTransactionTime()
*/
public void setGasEstimate(BigInteger estimate)
{
if (estimate.longValue() > C.GAS_LIMIT_MIN) //some kind of contract interaction
if (!customGasLimit.equals(estimate) && estimate.longValue() > C.GAS_LIMIT_MIN) //some kind of contract interaction
{
estimate = estimate.multiply(BigInteger.valueOf(6)).divide(BigInteger.valueOf(5)); // increase estimate by 20% to be safe
}

//Override custom gas limit if required
setGasEstimateExact(estimate);
}

@Override
public void setGasEstimateExact(BigInteger estimate)
{
if (customGasLimit.equals(presetGasLimit))
{
customGasLimit = estimate;
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_base_logo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:pathData="M16,32C19.164,32 22.258,31.062 24.889,29.303C27.52,27.545 29.571,25.047 30.782,22.123C31.993,19.199 32.31,15.982 31.693,12.879C31.075,9.775 29.551,6.924 27.314,4.686C25.076,2.449 22.225,0.925 19.121,0.307C16.018,-0.31 12.801,0.007 9.877,1.218C6.953,2.429 4.455,4.48 2.696,7.111C0.938,9.742 0,12.835 0,16C0,20.243 1.686,24.313 4.686,27.314C7.687,30.314 11.757,32 16,32Z"
android:fillColor="#0052FF"/>
<path
android:pathData="M15.962,27.268C22.185,27.268 27.23,22.223 27.23,16C27.23,9.777 22.185,4.732 15.962,4.732C10.059,4.732 5.216,9.273 4.734,15.052H21.454V16.928H4.732C5.204,22.717 10.052,27.268 15.962,27.268Z"
android:fillColor="#ffffff"/>
</vector>
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/ic_base_test_logo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="32dp"
android:height="32dp"
android:viewportWidth="32"
android:viewportHeight="32">
<path
android:pathData="M16,32C19.164,32 22.258,31.062 24.889,29.303C27.52,27.545 29.571,25.047 30.782,22.123C31.993,19.199 32.31,15.982 31.693,12.879C31.075,9.775 29.551,6.924 27.314,4.686C25.076,2.449 22.225,0.925 19.121,0.307C16.018,-0.31 12.801,0.007 9.877,1.218C6.953,2.429 4.455,4.48 2.696,7.111C0.938,9.742 0,12.835 0,16C0,20.243 1.686,24.313 4.686,27.314C7.687,30.314 11.757,32 16,32Z"
android:fillColor="#B2C6D8"/>
<path
android:pathData="M15.962,27.268C22.185,27.268 27.23,22.223 27.23,16C27.23,9.777 22.185,4.732 15.962,4.732C10.059,4.732 5.216,9.273 4.734,15.052H21.454V16.928H4.732C5.204,22.717 10.052,27.268 15.962,27.268Z"
android:fillColor="#ffffff"/>
</vector>
1 change: 1 addition & 0 deletions app/src/main/res/values/palette.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@
<color name="shark">#232325</color>
<color name="atlantis">#7cca42</color>
<color name="yellow">#FDD835</color>

Choose a reason for hiding this comment

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

Warning ⚠️  
📚 The resource R.color.yellow appears to be unused
🛠️ UnusedResources

by Android Lint 🤖

<color name="base_logo">#0052FF</color>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ public abstract class EthereumNetworkBase
public static final String LINEA_FREE_RPC = "https://linea.drpc.org";
public static final String LINEA_TEST_FREE_RPC = "https://rpc.goerli.linea.build";

public static final String BASE_FREE_MAINNET_RPC = "https://base-rpc.publicnode.com";
public static final String BASE_FREE_TESTNET_RPC = "https://base-sepolia-rpc.publicnode.com";


static Map<Long, NetworkInfo> networkMap = new LinkedHashMap<Long, NetworkInfo>()
{
{
Expand Down Expand Up @@ -170,6 +174,11 @@ public abstract class EthereumNetworkBase
LINEA_TEST_ID, false));
put(HOLESKY_ID, new NetworkInfo("Rootstock (Test)", "HolETH", HOLESKY_RPC_URL, "https://holesky.etherscan.io/tx/",
HOLESKY_ID, false));

put(BASE_MAINNET_ID, new NetworkInfo("Base", "ETH", BASE_FREE_MAINNET_RPC, "https://basescan.org/tx/",
BASE_MAINNET_ID, false));
put(BASE_TESTNET_ID, new NetworkInfo("Base (Test)", "ETH", BASE_FREE_TESTNET_RPC, "https://sepolia.basescan.org/tx/",
BASE_TESTNET_ID, false));
}
};

Expand Down
Loading