Skip to content
This repository has been archived by the owner on Jan 11, 2024. It is now read-only.

add deployment scripts and Makefile #86

Merged
merged 1 commit into from
Jun 16, 2023
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
4 changes: 2 additions & 2 deletions .env.template
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PRIVATE_KEY=
RPC_URL=https://filecoin-calibration.chainup.net/rpc/v1
export PRIVATE_KEY=
export RPC_URL=https://filecoin-calibration.chainup.net/rpc/v1
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,8 @@ solidity-files-cache.json

typechain

deployments.json
# Deploment assets
deployments.json
scripts/*.out
scripts/deploy-registry.ts
scripts/deploy-gateway.ts
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
NETWORK ?= localnet

deploy-ipc:
./ops/deploy.sh $(NETWORK)

.PHONY: deploy-ipc
58 changes: 36 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,26 @@

**‼️ The IPC Agent, the IPC actors, and eudico haven't been audited, tested in depth, or otherwise verified. Moreover, the system is missing critical recovery functionality in case of crashes. There are multiple ways in which you may lose funds moved into an IPC subnet, and we strongly advise against deploying IPC on mainnet and/or using it with tokens with real value.**

This repository includes the reference implementation of all the actors (i.e. smart contracts) responsible for the operation of the IPC (i.e. Inter-Planetary Consensus) protocol. These actors are written in Solidity and target FileCoin’s FEVM.
This repository includes the reference implementation of all the actors (i.e. smart contracts) responsible for the operation of the IPC (i.e. Inter-Planetary Consensus) protocol. These actors are written in Solidity and target Filecoin’s FEVM.

The project accommodates the following main contracts

- `Gateway.sol`: Implementation of the IPC gateway.
- `SubnetActor.sol`: Reference implementation of an IPC subnet actor.
- `SubnetRegistry.sol`: Registry contract for the seamless deployment of subnet actors.

# Building & Testing
# Deploying IPC Solidity contracts
Before deploying the contract you'll need to configure the `RPC_URL` and `PRIVATE_KEY` environmental variables to point to your network provider and the private key of the address you want to use for the deployment, respectively.

To build all contracts run
Alternatively, you can rename the `env.template` file included in the repo to `.env`, set your variables there, and run `source .env` before running the deployment scripts.

To deploy the the IPC Solidity contracts in an FEVM network, you can directly run:
```bash
forge build
make deploy-ipc
```

The build artifacts (contracts’ ABI `.json` files), can be found in the `out` directory.

To run all repo tests run

The scripts run by `make` make use of hardhat under the hood. The default network for the deployment is `localnet` as configured in `hardhat.config.ts`. To deploy the contracts in some other network configured in the Hardhat config you can run:
```bash
forge test
```

And to generate coverage report run

```bash
forge coverage
```

# Loading the bytecode into Lotus

```bash
TODO
make deploy-ipc NETWORK=<network-name>
```

# Actors overview
Expand All @@ -59,3 +46,30 @@ The purpose of the SubnetActor is to
4. manage the subnet’s status
5. allows validators to submit checkpoints and to commit them to the Gateway once majority is reached
6. distribute rewards, received from the Gateway, to validators

## SubnetRegistry
The purpose of the SubnetRegistry is to

1. deploy instances of the SubnetActor. Its role is to be the subnet actor factory in a subnet.

# Building & Testing with Forge

To build all contracts run

```bash
forge build
```

The build artifacts (contracts’ ABI `.json` files), can be found in the `out` directory.

To run all repo tests run

```bash
forge test
```

And to generate coverage report run

```bash
forge coverage
```
5 changes: 5 additions & 0 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ const config: HardhatUserConfig = {
chainId: 314159,
url: process.env.RPC_URL!,
accounts: [process.env.PRIVATE_KEY!],
},
localnet: {
chainId: 31415926,
url: process.env.RPC_URL!,
accounts: [process.env.PRIVATE_KEY!],
}
},
solidity: {
Expand Down
3 changes: 3 additions & 0 deletions ops/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# IPC deployment operations
This directory includes a set of scripts to ease the deployment of the IPC Solidity contracts to any network using hardhat.
- `deploy.sh`: Deploys the IPC solidity contracts into a specific network.
32 changes: 32 additions & 0 deletions ops/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
# Deploys IPC on an EVM-compatible subnet using hardhat
set -e

if [ $# -ne 1 ]
then
echo "Expected a single argument with the name of the network to deploy (localnet, calibrationet)"
exit 1
fi

LIB_OUTPUT="libraries.out"
GATEWAY_OUTPUT="gateway.out"
NETWORK=$1

echo "[*] Deploying libraries"
(npx hardhat deploy-libraries --network ${NETWORK} | sed -n '/{/,/}/p') > scripts/${LIB_OUTPUT}
echo "const LIBMAP =" | cat - scripts/${LIB_OUTPUT} > temp && mv temp scripts/${LIB_OUTPUT}
echo "[*] Output libraries available in $PWD/scripts/${LIB_OUTPUT}"

echo "[*] Populating deploy-gateway script"
cat scripts/${LIB_OUTPUT} | cat - scripts/deploy-gateway.template > temp && mv temp scripts/deploy-gateway.ts
echo "[*] Gateway script in $PWD/scripts/deploy-gateway.ts"
(npx hardhat deploy-gateway --network ${NETWORK} | sed -n '/{/,/}/p') > scripts/${GATEWAY_OUTPUT}
echo "const GATEWAY =" | cat - scripts/${GATEWAY_OUTPUT} > temp && mv temp scripts/${GATEWAY_OUTPUT}
echo "[*] Output gateway address in $PWD/scripts/${GATEWAY_OUTPUT}"

echo "[*] Populating deploy-registry script"
cat scripts/${LIB_OUTPUT} | sed '/StorableMsgHelper/d' | cat - scripts/deploy-registry.template > temp && mv temp scripts/deploy-registry.ts
cat scripts/${GATEWAY_OUTPUT} | cat - scripts/deploy-registry.ts > temp && mv temp scripts/deploy-registry.ts
echo "[*] Registry script in $PWD/scripts/deploy-registry.ts"
npx hardhat run scripts/deploy-registry.ts --network ${NETWORK}
echo "[*] IPC actors successfully deployed"
4 changes: 2 additions & 2 deletions scripts/deploy-gateway.ts → scripts/deploy-gateway.template
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export async function deploy(libs: { [key in string]: string }) {
const gatewayConstructorParams = {
networkName: {
root: 314159,
route: [ethers.constants.AddressZero]
route: []
},
bottomUpCheckPeriod: 10,
topDownCheckPeriod: 10,
msgFee: ethers.utils.parseUnits("10", "gwei"),
majorityPercentage: 66
}

const { address: gatewayAddress } = await deployContractWithDeployer(deployer, "Gateway", libs, gatewayConstructorParams, txArgs);
const { address: gatewayAddress } = await deployContractWithDeployer(deployer, "Gateway", LIBMAP, gatewayConstructorParams, txArgs);

return {
"Gateway": gatewayAddress
Expand Down
2 changes: 1 addition & 1 deletion scripts/deploy-libraries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export async function deploy() {
const txArgs = await getTransactionFees();

const { address: accountHelperAddress } = await deployContractWithDeployer(deployer, "AccountHelper", {}, txArgs);
const { address: checkpointHelperAddress } = await deployContractWithDeployer(deployer, "CheckpointHelper", {}, txArgs);
const { address: epochVoteSubmissionHelperAddress } = await deployContractWithDeployer(deployer, "EpochVoteSubmissionHelper", {}, txArgs);
const { address: executableQueueHelperAddress } = await deployContractWithDeployer(deployer, "ExecutableQueueHelper", {}, txArgs);
const { address: subnetIDHelperAddress } = await deployContractWithDeployer(deployer, "SubnetIDHelper", {}, txArgs);
// nested libs
const { address: crossMsgHelperAddress } = await deployContractWithDeployer(deployer, "CrossMsgHelper", { "SubnetIDHelper": subnetIDHelperAddress }, txArgs);
const { address: storableMsgHelperAddress } = await deployContractWithDeployer(deployer, "StorableMsgHelper", { "SubnetIDHelper": subnetIDHelperAddress }, txArgs);
const { address: checkpointHelperAddress } = await deployContractWithDeployer(deployer, "CheckpointHelper", { "SubnetIDHelper": subnetIDHelperAddress }, txArgs);

return {
"AccountHelper": accountHelperAddress,
Expand Down
31 changes: 31 additions & 0 deletions scripts/deploy-registry.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import hre, { ethers } from 'hardhat';
import { getTransactionFees } from './util';

async function main() {
try {

await hre.run('compile');

const [deployer] = await ethers.getSigners();
const balance = await deployer.getBalance();

console.log(`Deploying contracts with account: ${deployer.address} and balance: ${balance.toString()}`);

const gatewayAddress = GATEWAY.Gateway;
const txArgs = await getTransactionFees();

// deploy
const registry = await ethers.getContractFactory('SubnetRegistry', { signer: deployer, libraries: LIBMAP });
const contract = await registry.deploy(gatewayAddress, txArgs);

// FEVM:
console.log(`registry contract deployed to: ${contract.address}`);

process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
}
}

main();
37 changes: 0 additions & 37 deletions scripts/deploy-registry.ts

This file was deleted.