This repo contains the smart contracts for EVM CallService contracts in solidity.
-
Prerequisites:
- Install Foundry and Node.js (v21.1.1) on your machine.
-
Setup
git clone [email protected]:icon-project/xcall-multi.git cd xcall-multi/contracts/evm
-
Install the project dependencies
forge install
-
Compile your Solidity contracts
$ forge build
-
Testing Before deploying, it's recommended to run tests to ensure your contracts work as expected:
$ forge test -vv
-
Deployment Environment Setups
- Create a new
.env
file by copying the.env.example
file:
cp .env.example .env
- Open the .env file and update the following values:
PRIVATE_KEY: Your private key with the "0x" prefix. ADMIN: The address that should be set as the admin for the contracts.
When deploying adapters/mock_dapps
- _XCALL: xcall address of specific chains you are gonna deploy
- _CENTRALIZED_RELAYER: address of centralized relayer(only when ddeploying centralized adapter)
You can also set other environment variables as needed, such as RPC URLs, NID (Network IDs), and contract addresses.
Note: Have a complete look at the env once, you will understand the need to create and populate the
.env
file or set the required environment variables before deploying the contracts. - Create a new
-
Deployment
./deploy_script.sh --contract <contract> --<action> --env <environment> --chain <chain1> <chain2> ... --version <filename-version>
Adapter(Wormhole and Layerzero) Configuration between 2 chains
./deploy_script.sh --contract <contract> --configure --env <environment> --chain <chain1> <chain2>
Replace the placeholders with your specific values:
<contract>
: Contract to deploy or upgrade<action>
: Choose either "--deploy" to deploy contracts or "--upgrade" to upgrade existing contracts.<environment>
: Select the deployment environment ("mainnet," "testnet," or "local").<chain1>
,<chain2>
, ...: Specify one or more chains for deployment. Use "all" to deploy to all valid chains for the environment.filename-version
: filename of new contract to upgrade like, CallServiceV2.sol (only needed in upgrade)
Valid Options
- Actions: "deploy", "upgrade"
- Environments: "mainnet", "testnet", "local"
- Contract Types: "callservice" "wormhole" "layerzero" "centralized" "mock"
i. Local Deployment
-
Start a local Anvil node
anvil
-
Make sure you have
PRIVATE_KEY
andADMIN
addresses provided by Avnil -
In a new terminal window, navigate to your
xcall-multi/contracts/evm
and run the deployment script./deploy_script.sh --contract callservice --deploy --env local --chain local
ii. Testnet Deployment
-
Deploy the "callservice" contract to testnet on sepolia and optimism chains:
./deploy_script.sh --contract callservice --deploy --env testnet --chain sepolia optimism_sepolia
Testnet Chains Available: "sepolia" "bsctest" "fuji" "base_sepolia" "optimism_sepolia" "arbitrum_sepolia" "all"
iii. Mainnet Deployment
-
Deploy the "centralized" adapter contract to mainnet on Ethereum and Binance chains:
./deploy_script.sh --contract centralized --deploy --env mainnet --chain ethereum binance
Mainnet Chains Available: "ethereum" "binance" "avalanche" "base" "optimism" "arbitrum" "all"
To upgrade an existing contract, you need to create a new file with the updated changes and specify the previous contract version in the new contract file. Follow these steps:
- Rename the Old Contract File:
- Rename the old version of the contract file. For example, if you have a contract named
CallService.sol
, rename it toCallServiceV1.sol
.
- Create a New Contract File:
- Create a new file with the updated contract changes. For example, create a new file named
CallService.sol
.
- Add the Upgrade Annotation:
- In the new contract file (
CallService.sol
), add the following line just above the contract declaration:
/// @custom:oz-upgrades-from contracts/xcall/CallServiceV1.sol:CallServiceV1
contract CallService is IBSH, ICallService, IFeeManage, Initializable {
// Contract code goes here
}
This annotation specifies the previous contract version from which the upgrade is being performed.
- Ensure Proxy Contract Addresses:
- Make sure you have the proxy contract addresses for the chains and contracts you want to upgrade in your .env file.
- Run the Upgrade Script:
- With the admin account you provided during the initial deployment, run the following script:
./deploy_script.sh --contract <contract> --upgrade --env <environment> --chain <chain1> <chain2> ... --version <filename-version>
./deploy_script.sh --contract callservice --upgrade --env testnet --chain sepolia fuji --version CallService.sol
cast send <contract_address> "setProtocolFee(uint256 _value)" <value> --rpc-url <rpc_url> --private-key <private-key>
cast send <contract_address> "setProtocolFeeHandler(address _addr)" <addr> --rpc-url <rpc_url> --private-key <private-key>
cast send <contract_address> "setDefaultConnection(string memory _nid,address connection)" <nid> <connection> --rpc-url <rpc_url> --private-key <private-key>
Start by copying the .env.example
file to .env
:
cp .env.example .env
#deploy xcall
./deploy_script.sh --contract callservice --deploy --env testnet --chain <source_chain> <destination_chain>
#deploy adapter (wormhole layerzero centralized)
./deploy_script.sh --contract wormhole --deploy --env testnet --chain <source_chain> <destination_chain>
#deploy dapp
./deploy_script.sh --contract mock --deploy --env testnet --chain <source_chain> <destination_chain>
If you are using Wormhole or Layerzero for cross-chain communication, you will need to configure the connection. Execute the provided script to set up the connection.
./deploy_script.sh --contract <adapter> --configure --env testnet --chain <source_chain> <destination_chain>
- adapter: "layerzero", "wormhole", "centralized"
In your dapp, add the connections for cross-chain communication.
forge script DeployCallService -s "addConnection(string memory chain1, string memory chain2)" <source_chain> <destination_chain> --fork-url <source_chain> --broadcast
forge script DeployCallService -s "addConnection(string memory chain1, string memory chain2)" <destination_chain> <source_chain> --fork-url <destination_chain> --broadcast
$ ./test_xcall_flow.sh --src <source_chain> --dest <destination_chain> --fee <value>
--fee <value>
: Sets the transaction fee (in wei). The value must be a number.--src <source_chain>
: Sets the source chain for the transaction. Valid chain options arefuji
,bsctest
,arbitrum_sepolia
,optimism_sepolia
.--dest <destination_chain>
: Sets the destination chain for the transaction. Valid chain options arefuji
,bsctest
,base_sepolia
,optimism_sepolia
, andarbitrum_sepolia
.