Skip to content

Commit ee2efe2

Browse files
authored
Add token (#1604)
1 parent 3094722 commit ee2efe2

File tree

13 files changed

+431
-0
lines changed

13 files changed

+431
-0
lines changed

.gitmodules

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@
2222
[submodule "contracts/lib/openzeppelin-contracts-upgradeable"]
2323
path = contracts/lib/openzeppelin-contracts-upgradeable
2424
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
25+
[submodule "claim_contracts/lib/forge-std"]
26+
path = claim_contracts/lib/forge-std
27+
url = https://github.com/foundry-rs/forge-std
28+
[submodule "claim_contracts/lib/openzeppelin-contracts-upgradeable"]
29+
path = claim_contracts/lib/openzeppelin-contracts-upgradeable
30+
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable
31+
[submodule "claim_contracts/lib/openzeppelin-contracts"]
32+
path = claim_contracts/lib/openzeppelin-contracts
33+
url = https://github.com/OpenZeppelin/openzeppelin-contracts

claim_contracts/.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Compiler files
2+
cache/
3+
out/
4+
5+
# Ignores development broadcast logs
6+
!/broadcast
7+
/broadcast/*/31337/
8+
/broadcast/**/dry-run/
9+
10+
# Docs
11+
docs/
12+
13+
# Dotenv file
14+
.env

claim_contracts/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
## AlignedToken
2+
3+
## Requirements
4+
5+
- Foundry
6+
7+
## Local deploying
8+
9+
To deploy the contracts, set the following environment variables:
10+
11+
- `DEPLOYER_PRIVATE_KEY`: The private key of the account that's going to deploy the contracts.
12+
- `SAFE_ADDRESS`: The address of the safe that's going to own the Proxy admin that in turn owns the token and airdrop contracts.
13+
- `OWNER1_ADDRESS`, `OWNER2_ADDRESS`, and `OWNER3_ADDRESS`: The three owners of the token.
14+
- `MINT_AMOUNT`: The amount to mint to each account (the contract actually supports minting different amounts of the token to each owner, but in the deploy script we simplified it).
15+
- `RPC_URL`: The url of the network to deploy to.
16+
- `CLAIM_TIME_LIMIT`: The claim time limit timestamp.
17+
- `MERKLE_ROOT`: The merkle root of all valid token claims.
18+
19+
Example:
20+
```
21+
export DEPLOYER_PRIVATE_KEY=<deployer_private_key>
22+
export SAFE_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
23+
export OWNER1_ADDRESS=0x70997970C51812dc3A010C7d01b50e0d17dc79C8
24+
export OWNER2_ADDRESS=0x3C44CdDdB6a900fa2b585dd299e03d12FA4293BC
25+
export OWNER3_ADDRESS=0x90F79bf6EB2c4f870365E785982E1f101E93b906
26+
export MINT_AMOUNT=100
27+
export RPC_URL=http://localhost:8545
28+
export CLAIM_TIME_LIMIT=2733247661
29+
export MERKLE_ROOT=0x90076b5fb9a6c81d9fce83dfd51760987b8c49e7c861ea25b328e6e63d2cd3df
30+
```
31+
32+
Then run the following script:
33+
34+
```
35+
./deployClaim.sh
36+
```

claim_contracts/deployClaim.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
forge --version >/dev/null 2>&1
4+
if [ $? != 0 ]; then
5+
echo "Error: Please make sure you have forge installed and in your PATH"
6+
exit 2
7+
fi
8+
9+
safe=${SAFE_ADDRESS:-$1}
10+
owner1=${OWNER1_ADDRESS:-$2}
11+
owner2=${OWNER2_ADDRESS:-$3}
12+
owner3=${OWNER3_ADDRESS:-$4}
13+
mint_amount=${MINT_AMOUNT:-$5}
14+
rpc_url=${RPC_URL:-$6}
15+
claim_time_limit=${CLAIM_TIME_LIMIT:-2733247661}
16+
merkle_root=${MERKLE_ROOT:-$7}
17+
18+
cd script && forge script DeployScript $safe $owner1 $owner2 $owner3 $mint_amount $claim_time_limit $merkle_root --sig "run(address,address,address,address,uint256,uint256,bytes32)" --fork-url $rpc_url --broadcast

claim_contracts/foundry.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[profile.default]
2+
src = "src"
3+
out = "out"
4+
libs = ["lib"]
5+
6+
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options

claim_contracts/lib/forge-std

Submodule forge-std added at 1eea5ba
Submodule openzeppelin-contracts added at 69c8def

claim_contracts/remappings.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@openzeppelin/contracts/=lib/openzeppelin-contracts-upgradeable/lib/openzeppelin-contracts/contracts/
2+
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/

claim_contracts/script/Utils.sol

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.13;
3+
4+
import {Vm} from "forge-std/Vm.sol";
5+
6+
library Utils {
7+
// Cheatcodes address, 0x7109709ECfa91a80626fF3989D68f67F5b1DD12D.
8+
address internal constant VM_ADDRESS =
9+
address(uint160(uint256(keccak256("hevm cheat code"))));
10+
Vm internal constant vm = Vm(VM_ADDRESS);
11+
12+
/// @notice Address of the deterministic create2 factory.
13+
/// @dev This address corresponds to a contracts that is set in the storage
14+
/// in the genesis file. The same contract with the same address is deployed
15+
/// in every testnet, so if this script is run in a testnet instead of in a
16+
/// local environment, it should work.
17+
address constant DETERMINISTIC_CREATE2_ADDRESS =
18+
0x4e59b44847b379578588920cA78FbF26c0B4956C;
19+
20+
function deployWithCreate2(
21+
bytes memory bytecode,
22+
bytes32 salt,
23+
address create2Factory,
24+
uint256 signerPrivateKey
25+
) internal returns (address) {
26+
if (bytecode.length == 0) {
27+
revert("Bytecode is not set");
28+
}
29+
address contractAddress = vm.computeCreate2Address(
30+
salt,
31+
keccak256(bytecode),
32+
create2Factory
33+
);
34+
if (contractAddress.code.length != 0) {
35+
revert("Contract already deployed");
36+
}
37+
38+
vm.broadcast(signerPrivateKey);
39+
(bool success, bytes memory data) = create2Factory.call(
40+
abi.encodePacked(salt, bytecode)
41+
);
42+
contractAddress = bytesToAddress(data);
43+
44+
if (!success) {
45+
revert(
46+
"Failed to deploy contract via create2: create2Factory call failed"
47+
);
48+
}
49+
50+
if (contractAddress == address(0)) {
51+
revert(
52+
"Failed to deploy contract via create2: contract address is zero"
53+
);
54+
}
55+
56+
if (contractAddress.code.length == 0) {
57+
revert(
58+
"Failed to deploy contract via create2: contract code is empty"
59+
);
60+
}
61+
62+
return contractAddress;
63+
}
64+
65+
function bytesToAddress(
66+
bytes memory addressOffset
67+
) internal pure returns (address addr) {
68+
assembly {
69+
addr := mload(add(addressOffset, 20))
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)