-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multichain GLM #595
Closed
+191
−111
Closed
Multichain GLM #595
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[submodule "contracts-v1/lib/forge-std"] | ||
path = contracts-v1/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "contracts-v1/lib/openzeppelin-contracts"] | ||
path = contracts-v1/lib/openzeppelin-contracts | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts | ||
[submodule "contracts-v1/lib/layerzero-v2"] | ||
path = contracts-v1/lib/layerzero-v2 | ||
url = https://github.com/LayerZero-Labs/layerzero-v2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
env: | ||
FOUNDRY_PROFILE: ci | ||
|
||
jobs: | ||
check: | ||
strategy: | ||
fail-fast: true | ||
|
||
name: Foundry project | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
submodules: recursive | ||
|
||
- name: Install Foundry | ||
uses: foundry-rs/foundry-toolchain@v1 | ||
with: | ||
version: nightly | ||
|
||
- name: Show Forge version | ||
run: | | ||
forge --version | ||
|
||
- name: Run Forge fmt | ||
run: | | ||
forge fmt --check | ||
id: fmt | ||
|
||
- name: Run Forge build | ||
run: | | ||
forge build --sizes | ||
id: build | ||
|
||
- name: Run Forge tests | ||
run: | | ||
forge test -vvv | ||
id: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,140 +1,66 @@ | ||
## Introduction | ||
## Foundry | ||
|
||
Contracts-v1 is a part of gradual rollout of Octant. It contains a minimal set of contracts needed to make Octant work. Rest of functionality is currently implemented on the server (see $ROOT/backend). | ||
**Foundry is a blazing fast, portable and modular toolkit for Ethereum application development written in Rust.** | ||
|
||
## Deployments | ||
Foundry consists of: | ||
|
||
### Mainnet | ||
- **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. | ||
|
||
Auth: [0x287493F76b8A1833E9E0BF2dE0D972Fb16C6C8ae](https://etherscan.io/address/0x287493f76b8a1833e9e0bf2de0d972fb16c6c8ae) | ||
|
||
Deposits: [0x879133Fd79b7F48CE1c368b0fCA9ea168eaF117c](https://etherscan.io/address/0x879133fd79b7f48ce1c368b0fca9ea168eaf117c#code) | ||
|
||
Projects: [0x91B904e8B0F9133D0766059065C2A1F6c6CAfA27](https://etherscan.io/address/0x91b904e8b0f9133d0766059065c2a1f6c6cafa27) | ||
|
||
Epochs: [0xc292eBCa7855CB464755Aa638f9784c131F27D59](https://etherscan.io/address/0xc292eBCa7855CB464755Aa638f9784c131F27D59) | ||
|
||
Vault: [0xc64783f0BE60A81A716535287539a694403183ba](https://etherscan.io/address/0xc64783f0BE60A81A716535287539a694403183ba) | ||
|
||
GLM Token: [0x7DD9c5Cba05E151C895FDe1CF355C9A1D5DA6429](https://etherscan.io/address/0x7DD9c5Cba05E151C895FDe1CF355C9A1D5DA6429) | ||
|
||
GNT Token: [0xa74476443119A942dE498590Fe1f2454d7D4aC0d](https://etherscan.io/address/0xa74476443119A942dE498590Fe1f2454d7D4aC0d) | ||
|
||
Withdrawal Target: [0xba1951dF0C0A52af23857c5ab48B4C43A57E7ed1](https://etherscan.io/address/0xba1951df0c0a52af23857c5ab48b4c43a57e7ed1) | ||
|
||
|
||
### Sepolia | ||
|
||
Auth: [0xc64783f0BE60A81A716535287539a694403183ba](https://sepolia.etherscan.io/address/0xc64783f0BE60A81A716535287539a694403183ba) | ||
|
||
Deposits: [0x93ac82bdB106B515a2f6A83b6d3e8cC5d1d1CB9E](https://sepolia.etherscan.io/address/0x93ac82bdB106B515a2f6A83b6d3e8cC5d1d1CB9E#code) | ||
|
||
Projects: [0xB259fe6EC190cffF893b247AE688eFBF4261D2fc](https://sepolia.etherscan.io/address/0xB259fe6EC190cffF893b247AE688eFBF4261D2fc) | ||
|
||
Epochs: [0x37a32d673a96D73ccFb6f98bcA1f86d6aCCfCCb4](https://sepolia.etherscan.io/address/0x37a32d673a96D73ccFb6f98bcA1f86d6aCCfCCb4) | ||
## Documentation | ||
|
||
Vault: [0xdDF6e522CBE53e647908E0D27E54E7e873852939](https://sepolia.etherscan.io/address/0xdDF6e522CBE53e647908E0D27E54E7e873852939) | ||
https://book.getfoundry.sh/ | ||
|
||
## Configuration | ||
## Usage | ||
|
||
Ensure that the `.env` file is present. See `.env.template`. | ||
### Build | ||
|
||
## Clean | ||
```bash | ||
yarn clean | ||
```shell | ||
$ forge build | ||
``` | ||
|
||
## Compile | ||
```bash | ||
yarn compile | ||
``` | ||
### Test | ||
|
||
## Test | ||
```bash | ||
yarn test | ||
```shell | ||
$ forge test | ||
``` | ||
|
||
## Format and lint | ||
```bash | ||
yarn format | ||
yarn lint | ||
``` | ||
### Format | ||
|
||
## Documentation | ||
Generate contracts documentation: | ||
```bash | ||
yarn docs | ||
```shell | ||
$ forge fmt | ||
``` | ||
Go to `.docs` and open the `index.html` file in your browser. | ||
|
||
## Deployment | ||
|
||
--- | ||
|
||
**WARNING:** As of 2023-03-04 local environment runs into multiple issues when requesting data from contracts, making allocations or withdrawing funds. Please consider it as not stable. | ||
|
||
Tags description: | ||
* `testnet`: uses testnet specific GLM and faucet | ||
* `test`: used in local tests, deploys its own GLM and faucet | ||
* `local`: used for local environment, deploy's its own GLM and faucet | ||
* `epoch1`: Epoch.sol is not deployed, contracts that use Epoch handle this as a special case | ||
* `epoch2`: Epoch.sol is deployed | ||
|
||
--- | ||
### Local | ||
### Gas Snapshots | ||
|
||
1. In one terminal (continuous process): | ||
```bash | ||
yarn start-node | ||
```shell | ||
$ forge snapshot | ||
``` | ||
2. In second terminal: | ||
```bash | ||
yarn deploy:localhost | ||
yarn prepare-local-test-env | ||
``` | ||
`yarn prepare-local-test-env` outputs Alice's address, e.g.: | ||
> Alice's address is 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 | ||
|
||
This address can be used to retrieve account's private key from the beginning of `yarn start-node` output, search for e.g.: | ||
### Anvil | ||
|
||
```bash | ||
Account #1: 0x70997970C51812dc3A010C7d01b50e0d17dc79C8 (10000 ETH) | ||
Private Key: 0x59c6995e998f97a5a0044966f0945389dc9e86dae88c7a8412f4603b6b78690 | ||
```shell | ||
$ anvil | ||
``` | ||
|
||
3. Add default Hardhat wallet to the MetaMask account. To do so, create new account in the browser with MetaMask plugin installed. Then either use private key mentioned above or use default mnemonic phrase `test test test test test test test test test test test junk` (if you didn't previously) to add it. Alice, which is used locally, should be one of the accounts in this wallet, probably number 2. | ||
4. If needed, start frontend client by entering `client` directory and running `yarn dev:localcontracts`. | ||
|
||
### Goerli testnet | ||
```bash | ||
yarn deploy:goerli | ||
yarn verify:goerli | ||
``` | ||
### Deploy | ||
|
||
### Sepolia testnet | ||
```bash | ||
yarn deploy:sepolia | ||
yarn verify:sepolia | ||
```shell | ||
$ forge script script/Counter.s.sol:CounterScript --rpc-url <your_rpc_url> --private-key <your_private_key> | ||
``` | ||
|
||
## GLM Faucet | ||
Update `.env` with your private key: | ||
```bash | ||
TESTNET_DEPLOYER_PRIVATE_KEY=<your private key> | ||
``` | ||
Send Test GLM. | ||
```bash | ||
npx hardhat --network <network> send-glm --recipient <recipient address> | ||
``` | ||
### Cast | ||
|
||
## Publish typechain types | ||
Login to Octant npm account, update a version in `typechain/package.json` and run following commands: | ||
```bash | ||
yarn compile | ||
cd typechain | ||
npm publish | ||
```shell | ||
$ cast <subcommand> | ||
``` | ||
|
||
## Known technical problems | ||
### Help | ||
|
||
Root `package.json` `yarn postinstall` command replaces `@nomiclabs/hardhat-ethers` with `hardhat-deploy-ethers`. This is due to the fact that the first package, although essential declares different methods for `ethers` than the latter package, causing unexpected type collision. | ||
```shell | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I remember we spent quite some time before figuring it out. Is it not valid anymore? If it is, please leave it. |
||
$ forge --help | ||
$ anvil --help | ||
$ cast --help | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// SPDX-License-Identifier: agpl-3.0 | ||
|
||
pragma solidity ^0.8.22; | ||
|
||
import { OFTAdapter } from "@layerzerolabs/oft-evm/contracts/OFTAdapter.sol"; | ||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
|
||
contract GLMAdapter is OFTAdapter { | ||
constructor( | ||
address _token, | ||
address _lzEndpoint | ||
) OFTAdapter(_token, _lzEndpoint, address(0)) Ownable(address(0)) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.22; | ||
|
||
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; | ||
import { OFT } from "@layerzerolabs/oft-evm/contracts/OFT.sol"; | ||
|
||
/// @notice OFT is an ERC-20 token that extends the OFTCore contract. | ||
contract OGLM is OFT { | ||
constructor( | ||
string memory _name, | ||
string memory _symbol, | ||
address _lzEndpoint | ||
) OFT(_name, _symbol, _lzEndpoint, address(0)) Ownable(address(0)) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[profile.default] | ||
src = "src" | ||
out = "out" | ||
libs = ["lib"] | ||
|
||
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options |
Submodule layerzero-v2
added at
34321a
Submodule openzeppelin-contracts
added at
69c8de
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/ | ||
ds-test/=lib/openzeppelin-contracts/lib/forge-std/lib/ds-test/src/ | ||
erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/ | ||
forge-std/=lib/forge-std/src/ | ||
halmos-cheatcodes/=lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/ | ||
@layerzerolabs/oft-evm/=lib/layerzero-v2/packages/layerzero-v2/evm/oapp/contracts/oft/ | ||
openzeppelin-contracts/=lib/openzeppelin-contracts/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Script, console} from "forge-std/Script.sol"; | ||
import {Counter} from "../src/Counter.sol"; | ||
|
||
contract CounterScript is Script { | ||
Counter public counter; | ||
|
||
function setUp() public {} | ||
|
||
function run() public { | ||
vm.startBroadcast(); | ||
|
||
counter = new Counter(); | ||
|
||
vm.stopBroadcast(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
contract Counter { | ||
uint256 public number; | ||
|
||
function setNumber(uint256 newNumber) public { | ||
number = newNumber; | ||
} | ||
|
||
function increment() public { | ||
number++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Test, console} from "forge-std/Test.sol"; | ||
import {Counter} from "../src/Counter.sol"; | ||
|
||
contract CounterTest is Test { | ||
Counter public counter; | ||
|
||
function setUp() public { | ||
counter = new Counter(); | ||
counter.setNumber(0); | ||
} | ||
|
||
function test_Increment() public { | ||
counter.increment(); | ||
assertEq(counter.number(), 1); | ||
} | ||
|
||
function testFuzz_SetNumber(uint256 x) public { | ||
counter.setNumber(x); | ||
assertEq(counter.number(), x); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not valid anymore?