Skip to content

Commit

Permalink
add scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
xyzseer committed Oct 28, 2024
1 parent 47d5386 commit d90eac8
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 53 deletions.
3 changes: 3 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PRIVATE_KEY=
GOVERNED_RECIPIENT_ADDRESS=
GNOSISSCAN_API_KEY=
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ docs/

# Dotenv file
.env

recipients.json
68 changes: 16 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,30 @@
## Foundry
# Seer Airdrop contracts

**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.**
This repository contains smart contracts and scripts for distributing Seer credits to participants.

Foundry consists of:
## Prerequisites

- **Forge**: Ethereum testing framework (like Truffle, Hardhat and DappTools).
- **Cast**: Swiss army knife for interacting with EVM smart contracts, sending transactions and getting chain data.
- **Anvil**: Local Ethereum node, akin to Ganache, Hardhat Network.
- **Chisel**: Fast, utilitarian, and verbose solidity REPL.
- [Foundry](https://book.getfoundry.sh/getting-started/installation) installed

## Documentation
## Environment Setup

https://book.getfoundry.sh/
1. Clone this repository
2. Create a `.env` file in the root directory with the following variables:

## Usage

### Build

```shell
$ forge build
```

### Test

```shell
$ forge test
```

### Format

```shell
$ forge fmt
```

### Gas Snapshots

```shell
$ forge snapshot
```

### Anvil

```shell
$ anvil
PRIVATE_KEY= # Your wallet's private key for deploying contracts
GOVERNED_RECIPIENT_ADDRESS= # Address of the deployed GovernedRecipient contract (needed for adding recipients)
GNOSISSCAN_API_KEY= # API key from https://gnosisscan.io to verify contracts
```

### Deploy
## Deploy contracts

```shell
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key>
```
`forge script script/Deploy.s.sol:Deploy --rpc-url gnosis --broadcast --verify -vvvv --etherscan-api-key gnosis`

### Cast
## Create recipients.json

```shell
$ cast <subcommand>
```
Use the `recipients.json.dist` file as template.

### Help
## Add recipients

```shell
$ forge --help
$ anvil --help
$ cast --help
```
`forge script script/AddRecipients.s.sol:AddRecipients --rpc-url gnosis --broadcast -vvvv --via-ir`
7 changes: 6 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,10 @@
src = "src"
out = "out"
libs = ["lib"]
fs_permissions = [{ access = "read", path = "./" }]

# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
[rpc_endpoints]
gnosis = "https://rpc.gnosischain.com"

[etherscan]
gnosis = { key = "${GNOSISSCAN_API_KEY}", url = "https://api.gnosisscan.io/api" }
6 changes: 6 additions & 0 deletions recipients.json.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
"0x0000000000000000000000000000000000000000",
"0x0000000000000000000000000000000000000001",
"0x0000000000000000000000000000000000000002",
"0x0000000000000000000000000000000000000003"
]
40 changes: 40 additions & 0 deletions script/AddRecipients.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;

import "../src/GovernedRecipient.sol";
import "../src/MultiDrop.sol";
import "forge-std/Script.sol";

interface Disperse {
function disperseEther(address[] memory recipients, uint256[] memory values) external payable;
}

contract AddRecipients is Script {
address disperse = address(0xD152f549545093347A162Dce210e7293f1452150); // gnosis chain address
uint256 amount = 0.02 ether;

function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");

GovernedRecipient governedRecipient = GovernedRecipient(vm.envAddress("GOVERNED_RECIPIENT_ADDRESS"));

vm.startBroadcast(deployerPrivateKey);

string memory root = vm.projectRoot();
string memory path = string.concat(root, "/recipients.json");
string memory json = vm.readFile(path);
address[] memory recipients = abi.decode(vm.parseJson(json), (address[]));

uint256[] memory amounts = new uint256[](recipients.length);
for(uint256 i = 0; i < recipients.length; i++) {
amounts[i] = amount;
}
Disperse(disperse).disperseEther{value: amount * recipients.length}(recipients, amounts);

governedRecipient.addRecipients(recipients);

vm.stopBroadcast();

console.log("Added recipients:", recipients.length);
}
}
22 changes: 22 additions & 0 deletions script/Deploy.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import "../src/GovernedRecipient.sol";
import "../src/MultiDrop.sol";
import "forge-std/Script.sol";

contract Deploy is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");

vm.startBroadcast(deployerPrivateKey);

GovernedRecipient governedRecipient = new GovernedRecipient();
MultiDrop multiDrop = new MultiDrop(governedRecipient);

vm.stopBroadcast();

console.log("GovernedRecipient deployed to:", address(governedRecipient));
console.log("MultiDrop deployed to:", address(multiDrop));
}
}

0 comments on commit d90eac8

Please sign in to comment.