Skip to content

Commit

Permalink
chore(contract): Add deploy scripts; update README
Browse files Browse the repository at this point in the history
  • Loading branch information
oyyblin committed Nov 4, 2024
1 parent 0131198 commit 90d5f8e
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 1 deletion.
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2024 Galxe.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Galxe Raffle 🎲

A raffle system powered by SP1 zero-knowledge proofs and Galxe Raffle smart contracts.

## 🏗️ Project Structure

- `zk/`: Contains the SP1 RISC-V program and proof generation scripts.
- `contracts/`: Contains the Galxe Raffle smart contracts.

## 🔑 ZK

For more information, see the [zk/README.md](zk/README.md).

## 📄 Contracts

For more information, see the [contracts/README.md](contracts/README.md).
31 changes: 31 additions & 0 deletions contracts/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
### Salt used to deploy the contracts. Recommended to use the same salt across different chains.
CREATE2_SALT=0x0000000000000000000000000000000000000000000000000000000000000000

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

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

### The SP1 verifier address.
VERIFIER=

### The verification key for the SP1 RISC-V program.
VKEY=

### The DrandOracle contract address.
DRAND_ORACLE=

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

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

# 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=
9 changes: 9 additions & 0 deletions contracts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# 🎲 Galxe Raffle Smart Contracts

## 📋 Requirements

- [Foundry](https://book.getfoundry.sh/getting-started/installation) for smart contract development

## 📄 Example Deployment

- Gravity Alpha Testnet Sepolia: [0xc0e9eb9299bd2349ca0bb711b4ba4a1d43b1524f](https://explorer-sepolia.gravity.xyz/address/0xc0e9eb9299bd2349ca0bb711b4ba4a1d43b1524f)
70 changes: 70 additions & 0 deletions contracts/broadcast/Raffle.s.sol/13505/run-1730752044.json

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

9 changes: 8 additions & 1 deletion contracts/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,12 @@ remappings = [
"@drand-oracle/=lib/drand-oracle/contracts/src/",
]

[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 = "", chain = "1625", url = "${ETHERSCAN_API_URL_GRAVITY}", verifier = "blockscout" }
gravity_sepolia = { key = "", chain = "13505", url = "${ETHERSCAN_API_URL_GRAVITY_SEPOLIA}", verifier = "blockscout" }
anvil = { key = "", chain = "31337", url = "http://127.0.0.1:8545" }
27 changes: 27 additions & 0 deletions contracts/script/deploy/Raffle.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

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

contract RaffleScript is BaseScript {
function run() external chain broadcaster {
bytes32 CREATE2_SALT = vm.envBytes32("CREATE2_SALT");
address owner = vm.envAddress("OWNER");
address signer = vm.envAddress("SIGNER");
address verifier = vm.envAddress("VERIFIER");
bytes32 vkey = vm.envBytes32("VKEY");
address drandOracle = vm.envAddress("DRAND_ORACLE");

console.log("Owner:", owner);
console.log("Signer:", signer);
console.log("Verifier:", verifier);
console.log("VKey:");
console.logBytes32(vkey);
console.log("DrandOracle:", drandOracle);

Raffle raffle = new Raffle{salt: CREATE2_SALT}(owner, signer, verifier, vkey, drandOracle);
console.log("Raffle deployed at:", address(raffle));
}
}
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.24;

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 90d5f8e

Please sign in to comment.