Skip to content

Commit

Permalink
maint(core): Simplify network integration
Browse files Browse the repository at this point in the history
  • Loading branch information
RPate97 committed Jan 13, 2024
1 parent 9bc3cd0 commit 9b987df
Show file tree
Hide file tree
Showing 19 changed files with 876 additions and 785 deletions.
7 changes: 7 additions & 0 deletions .changeset/silent-oranges-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@sphinx-labs/contracts': patch
'@sphinx-labs/plugins': patch
'@sphinx-labs/core': patch
---

Simplify network integration interface
173 changes: 173 additions & 0 deletions packages/contracts/contracts/foundry/SphinxConstants.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.6.2 <0.9.0;

import { NetworkInfo, NetworkType } from "./SphinxPluginTypes.sol";

contract SphinxConstants {
address public constant compatibilityFallbackHandlerAddress = 0xf48f2B2d2a534e402487b3ee7C18c33Aec0Fe5e4;
address public constant multiSendAddress = 0xA238CBeb142c10Ef7Ad8442C6D1f9E89e07e7761;
Expand All @@ -9,4 +11,175 @@ contract SphinxConstants {
address public constant safeFactoryAddress = 0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2;
address public constant safeSingletonAddress = 0xd9Db270c1B5E3Bd161E8c8503c55cEABeE709552;
address public constant sphinxModuleImplAddress = 0x8f4E4d51B8050B0ff713eff1F88f3dD8b5e8a530;

uint8 internal constant numSupportedNetworks = 23;

function getNetworkInfoArray() public pure returns (NetworkInfo[] memory) {
NetworkInfo[] memory all = new NetworkInfo[](numSupportedNetworks);
all[0] = NetworkInfo({
network: Network.anvil,
name: "anvil",
chainId: 31337,
networkType: NetworkType.Local
});
all[1] = NetworkInfo({
network: Network.ethereum,
name: "ethereum",
chainId: 1,
networkType: NetworkType.Mainnet
});
all[2] = NetworkInfo({
network: Network.sepolia,
name: "sepolia",
chainId: 11155111,
networkType: NetworkType.Testnet
});
all[3] = NetworkInfo({
network: Network.optimism,
name: "optimism",
chainId: 10,
networkType: NetworkType.Mainnet
});
all[4] = NetworkInfo({
network: Network.optimism_sepolia,
name: "optimism_sepolia",
chainId: 11155420,
networkType: NetworkType.Testnet
});
all[5] = NetworkInfo({
network: Network.arbitrum,
name: "arbitrum",
chainId: 42161,
networkType: NetworkType.Mainnet
});
all[6] = NetworkInfo({
network: Network.arbitrum_sepolia,
name: "arbitrum_sepolia",
chainId: 421614,
networkType: NetworkType.Testnet
});
all[7] = NetworkInfo({
network: Network.polygon,
name: "polygon",
chainId: 137,
networkType: NetworkType.Mainnet
});
all[8] = NetworkInfo({
network: Network.polygon_mumbai,
name: "polygon_mumbai",
chainId: 80001,
networkType: NetworkType.Testnet
});
all[9] = NetworkInfo({
network: Network.bnb,
name: "bnb",
chainId: 56,
networkType: NetworkType.Mainnet
});
all[10] = NetworkInfo({
network: Network.bnb_testnet,
name: "bnb_testnet",
chainId: 97,
networkType: NetworkType.Testnet
});
all[11] = NetworkInfo({
network: Network.gnosis,
name: "gnosis",
chainId: 100,
networkType: NetworkType.Mainnet
});
all[12] = NetworkInfo({
network: Network.gnosis_chiado,
name: "gnosis_chiado",
chainId: 10200,
networkType: NetworkType.Testnet
});
all[13] = NetworkInfo({
network: Network.linea,
name: "linea",
chainId: 59144,
networkType: NetworkType.Mainnet
});
all[14] = NetworkInfo({
network: Network.linea_goerli,
name: "linea_goerli",
chainId: 59140,
networkType: NetworkType.Testnet
});
all[15] = NetworkInfo({
network: Network.polygon_zkevm,
name: "polygon_zkevm",
chainId: 1101,
networkType: NetworkType.Mainnet
});
all[16] = NetworkInfo({
network: Network.polygon_zkevm_goerli,
name: "polygon_zkevm_goerli",
chainId: 1442,
networkType: NetworkType.Testnet
});
all[17] = NetworkInfo({
network: Network.avalanche,
name: "avalanche",
chainId: 43114,
networkType: NetworkType.Mainnet
});
all[18] = NetworkInfo({
network: Network.avalanche_fuji,
name: "avalanche_fuji",
chainId: 43113,
networkType: NetworkType.Testnet
});
all[19] = NetworkInfo({
network: Network.fantom,
name: "fantom",
chainId: 250,
networkType: NetworkType.Mainnet
});
all[20] = NetworkInfo({
network: Network.fantom_testnet,
name: "fantom_testnet",
chainId: 4002,
networkType: NetworkType.Testnet
});
all[21] = NetworkInfo({
network: Network.base,
name: "base",
chainId: 8453,
networkType: NetworkType.Mainnet
});
all[22] = NetworkInfo({
network: Network.base_sepolia,
name: "base_sepolia",
chainId: 84532,
networkType: NetworkType.Testnet
});
return all;
}
}

enum Network {
anvil,
ethereum,
sepolia,
optimism,
optimism_sepolia,
arbitrum,
arbitrum_sepolia,
polygon,
polygon_mumbai,
bnb,
bnb_testnet,
gnosis,
gnosis_chiado,
linea,
linea_goerli,
polygon_zkevm,
polygon_zkevm_goerli,
avalanche,
avalanche_fuji,
fantom,
fantom_testnet,
base,
base_sepolia
}
29 changes: 1 addition & 28 deletions packages/contracts/contracts/foundry/SphinxPluginTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.0;

import { SphinxLeafType, SphinxLeaf, SphinxLeafWithProof } from "../core/SphinxDataTypes.sol";
import { Network } from "./SphinxConstants.sol";
import { IEnum } from "./interfaces/IEnum.sol";

struct HumanReadableAction {
Expand Down Expand Up @@ -128,34 +129,6 @@ struct Label {
string fullyQualifiedName;
}

enum Network {
anvil,
// production networks (i.e. mainnets)
ethereum,
optimism,
arbitrum,
polygon,
bnb,
gnosis,
linea,
polygon_zkevm,
avalanche,
fantom,
base,
// testnets
sepolia,
optimism_sepolia,
arbitrum_sepolia,
polygon_mumbai,
bnb_testnet,
gnosis_chiado,
linea_goerli,
polygon_zkevm_goerli,
avalanche_fuji,
fantom_testnet,
base_sepolia
}

struct DeployOptions {
bytes32 salt;
string referenceName;
Expand Down
149 changes: 0 additions & 149 deletions packages/contracts/contracts/foundry/SphinxUtils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ contract SphinxUtils is SphinxConstants, StdUtils {
address public constant DETERMINISTIC_DEPLOYMENT_PROXY =
0x4e59b44847b379578588920cA78FbF26c0B4956C;

// Number of networks that Sphinx supports, i.e. the number of networks in the `Networks` enum
// in SphinxPluginTypes.sol. Unfortunately, we can't retrieve this value using type(Network).max
// because Solidity v0.8.0 doesn't support this operation. The test file `SphinxUtils.t.sol`
// contains a test that ensures this value is correct.
uint8 internal constant numSupportedNetworks = 23;

function slice(
bytes calldata _data,
uint256 _start,
Expand Down Expand Up @@ -321,149 +315,6 @@ contract SphinxUtils is SphinxConstants, StdUtils {
);
}

function getNetworkInfoArray() public pure returns (NetworkInfo[] memory) {
NetworkInfo[] memory all = new NetworkInfo[](numSupportedNetworks);
all[0] = NetworkInfo({
network: Network.anvil,
name: "anvil",
chainId: 31337,
networkType: NetworkType.Local
});
all[1] = NetworkInfo({
network: Network.ethereum,
name: "ethereum",
chainId: 1,
networkType: NetworkType.Mainnet
});
all[2] = NetworkInfo({
network: Network.optimism,
name: "optimism",
chainId: 10,
networkType: NetworkType.Mainnet
});
all[3] = NetworkInfo({
network: Network.arbitrum,
name: "arbitrum",
chainId: 42161,
networkType: NetworkType.Mainnet
});
all[4] = NetworkInfo({
network: Network.polygon,
name: "polygon",
chainId: 137,
networkType: NetworkType.Mainnet
});
all[5] = NetworkInfo({
network: Network.bnb,
name: "bnb",
chainId: 56,
networkType: NetworkType.Mainnet
});
all[6] = NetworkInfo({
network: Network.gnosis,
name: "gnosis",
chainId: 100,
networkType: NetworkType.Mainnet
});
all[7] = NetworkInfo({
network: Network.linea,
name: "linea",
chainId: 59144,
networkType: NetworkType.Mainnet
});
all[8] = NetworkInfo({
network: Network.polygon_zkevm,
name: "polygon_zkevm",
chainId: 1101,
networkType: NetworkType.Mainnet
});
all[9] = NetworkInfo({
network: Network.avalanche,
name: "avalanche",
chainId: 43114,
networkType: NetworkType.Mainnet
});
all[10] = NetworkInfo({
network: Network.fantom,
name: "fantom",
chainId: 250,
networkType: NetworkType.Mainnet
});
all[11] = NetworkInfo({
network: Network.base,
name: "base",
chainId: 8453,
networkType: NetworkType.Mainnet
});
all[12] = NetworkInfo({
network: Network.sepolia,
name: "sepolia",
chainId: 11155111,
networkType: NetworkType.Testnet
});
all[13] = NetworkInfo({
network: Network.optimism_sepolia,
name: "optimism_sepolia",
chainId: 11155420,
networkType: NetworkType.Testnet
});
all[14] = NetworkInfo({
network: Network.arbitrum_sepolia,
name: "arbitrum_sepolia",
chainId: 421614,
networkType: NetworkType.Testnet
});
all[15] = NetworkInfo({
network: Network.polygon_mumbai,
name: "polygon_mumbai",
chainId: 80001,
networkType: NetworkType.Testnet
});
all[16] = NetworkInfo({
network: Network.bnb_testnet,
name: "bnb_testnet",
chainId: 97,
networkType: NetworkType.Testnet
});
all[17] = NetworkInfo({
network: Network.gnosis_chiado,
name: "gnosis_chiado",
chainId: 10200,
networkType: NetworkType.Testnet
});
all[18] = NetworkInfo({
network: Network.linea_goerli,
name: "linea_goerli",
chainId: 59140,
networkType: NetworkType.Testnet
});
all[19] = NetworkInfo({
network: Network.polygon_zkevm_goerli,
name: "polygon_zkevm_goerli",
chainId: 1442,
networkType: NetworkType.Testnet
});
all[20] = NetworkInfo({
network: Network.avalanche_fuji,
name: "avalanche_fuji",
chainId: 43113,
networkType: NetworkType.Testnet
});
all[21] = NetworkInfo({
network: Network.fantom_testnet,
name: "fantom_testnet",
chainId: 4002,
networkType: NetworkType.Testnet
});
all[22] = NetworkInfo({
network: Network.base_sepolia,
name: "base_sepolia",
chainId: 84532,
networkType: NetworkType.Testnet
});
return all;
}

function getNetworkInfo(Network _network) public pure returns (NetworkInfo memory) {
NetworkInfo[] memory all = getNetworkInfoArray();
for (uint256 i = 0; i < all.length; i++) {
Expand Down
Loading

0 comments on commit 9b987df

Please sign in to comment.