Skip to content

Commit

Permalink
chore(contract): Add deployment info; update base script; use .env
Browse files Browse the repository at this point in the history
  • Loading branch information
oyyblin committed Oct 31, 2024
1 parent eba27f9 commit 34d95e4
Show file tree
Hide file tree
Showing 9 changed files with 266 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ cache/
out/

# Ignores development broadcast logs
!/broadcast
/broadcast/*/31337/
/broadcast/**/dry-run/
!contracts/broadcast
contracts/broadcast/*/31337/
contracts/broadcast/**/dry-run/

# Docs
docs/
Expand Down
29 changes: 29 additions & 0 deletions contracts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
### Salt used to deploy the contract. Recommended to use the same salt across different chains.
CREATE2_SALT=0x0000000000000000000000000000000000000000000000000000000000000000

### The owner of the DrandOracle contract.
OWNER=

### The signer of the DrandOracle contract.
SIGNER=

### The chain hash of the DrandOracle contract.
CHAIN_HASH=

### The chain to deploy to, specified by chain name (e.g. CHAIN=gravity_sepolia)
CHAIN=

### RPCs for each chain ID
RPC_GRAVITY=https://rpc.gravity.xyz
RPC_GRAVITY_SEPOLIA=https://rpc-sepolia.gravity.xyz

# Etherscan API keys for each chain
ETHERSCAN_API_KEY_GRAVITY=123
ETHERSCAN_API_KEY_GRAVITY_SEPOLIA=123

# Etherscan API URLs for each chain
ETHERSCAN_API_URL_GRAVITY=https://explorer.gravity.xyz/api
ETHERSCAN_API_URL_GRAVITY_SEPOLIA=https://explorer-sepolia.gravity.xyz/api

## Contract Deployer Private Key
PRIVATE_KEY=
14 changes: 6 additions & 8 deletions contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ clean-go:

# Deploy anvil using default anvil private key
deploy-anvil:
export PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
OWNER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
SIGNER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
CHAIN_HASH=0x8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce && \
forge script ./script/deploy/DrandOracle.s.sol:DrandOracleScript \
--rpc-url 127.0.0.1:8545 \
--broadcast \
--verify
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
OWNER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
SIGNER=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 \
CHAIN_HASH=0x8990e7a9aaed2ffed73dbd7092123d6f289930540d7651336225dc172e51b2ce \
CHAIN=anvil \
forge script ./script/deploy/DrandOracle.s.sol:DrandOracleScript --private-key $(PRIVATE_KEY) --broadcast
14 changes: 14 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,17 @@ anvil
forge build
make deploy-anvil
```

### 🚀 Deploy

Edit the `.env` file to set the correct environment variables for the chain you want to deploy to. Then run:

```bash
FOUNDRY_PROFILE=deploy forge script ./script/deploy/DrandOracle.s.sol:DrandOracleScript --broadcast --verify --verifier etherscan
```

Note that for some testnets, `--gas-estimate-multiplier x` is required to avoid out-of-gas errors.

#### 🌍 Deployments

- Gravity Alpha Testnet Sepolia - [0x64147A2414EeD1E28E3e8468094E619D09d5b7e9](https://explorer-sepolia.gravity.xyz/address/0x64147A2414EeD1E28E3e8468094E619D09d5b7e9)
81 changes: 81 additions & 0 deletions contracts/broadcast/DrandOracle.s.sol/13505/run-1730411681.json

Large diffs are not rendered by default.

81 changes: 81 additions & 0 deletions contracts/broadcast/DrandOracle.s.sol/13505/run-latest.json

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ libs = ["lib"]

remappings = ["@openzeppelin/=lib/openzeppelin-contracts/"]

[rpc_endpoints]
gravity = "${RPC_GRAVITY}"
gravity_sepolia = "${RPC_GRAVITY_SEPOLIA}"
anvil = "http://127.0.0.1:8545"

[etherscan]
gravity_testnet = { key = "", chain = "13505", url = "https://explorer-sepolia.gravity.xyz/api" }
gravity = { key = "${ETHERSCAN_API_KEY_GRAVITY}", chain = "1625", url = "${ETHERSCAN_API_URL_GRAVITY}" }
gravity_sepolia = { key = "${ETHERSCAN_API_KEY_GRAVITY_SEPOLIA}", chain = "13505", url = "${ETHERSCAN_API_URL_GRAVITY_SEPOLIA}" }
anvil = { key = "", chain = "31337", url = "http://127.0.0.1:8545" }
17 changes: 10 additions & 7 deletions contracts/script/deploy/DrandOracle.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@
pragma solidity ^0.8.24;

import "forge-std/Script.sol";
import {BaseScript} from "../utils/Base.s.sol";
import {DrandOracle} from "../../src/DrandOracle.sol";

contract DrandOracleScript is Script {
function run() public {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
contract DrandOracleScript is BaseScript {
function run() external chain broadcaster {
bytes32 CREATE2_SALT = vm.envBytes32("CREATE2_SALT");
address owner = vm.envAddress("OWNER");
address signer = vm.envAddress("SIGNER");
bytes32 chainHash = vm.envBytes32("CHAIN_HASH");
vm.startBroadcast(deployerPrivateKey);

DrandOracle oracle = new DrandOracle{salt: "DrandOracle"}(owner, signer, chainHash);
console.log("DrandOracle deployed at:", address(oracle));
console.log("Owner:", owner);
console.log("Signer:", signer);
console.log("Chain hash:");
console.logBytes32(chainHash);

vm.stopBroadcast();
DrandOracle oracle = new DrandOracle{salt: CREATE2_SALT}(owner, signer, chainHash);
console.log("DrandOracle deployed at:", address(oracle));
}
}
35 changes: 35 additions & 0 deletions contracts/script/utils/Base.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "forge-std/Vm.sol";
import "forge-std/console.sol";
import {stdJson} from "forge-std/StdJson.sol";
import {Script} from "forge-std/Script.sol";

/// @notice Script to inherit from to get access to helper functions for deployments.
abstract contract BaseScript is Script {
using stdJson for string;

/// @notice Run the command with the `--broadcast` flag to send the transaction to the chain,
/// otherwise just simulate the transaction execution.
modifier broadcaster() {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");
console.log("Deployer: %s", vm.addr(deployerPrivateKey));
vm.startBroadcast(deployerPrivateKey);
_;
vm.stopBroadcast();
}

/// @notice Runs the script on the chain specified in the `CHAIN` env variable.
/// Must have a `RPC_${CHAIN}` env variable set for the chain (e.g. RPC_MAINNET).
modifier chain() {
string memory c = vm.envString("CHAIN");

// Switch to the chain using the RPC
vm.createSelectFork(c);

console.log("Running script on %s", c);

_;
}
}

0 comments on commit 34d95e4

Please sign in to comment.