Skip to content
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
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitmodules
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
45 changes: 45 additions & 0 deletions contracts-v1/.github/workflows/test.yml
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
148 changes: 37 additions & 111 deletions contracts-v1/README.md
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
Comment on lines -130 to -135
Copy link
Member

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?

$ 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
Copy link
Member

Choose a reason for hiding this comment

The 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
```
13 changes: 13 additions & 0 deletions contracts-v1/contracts/GLMAdapter.sol
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)) {}
}
14 changes: 14 additions & 0 deletions contracts-v1/contracts/OGLM.sol
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)) {}
}
6 changes: 6 additions & 0 deletions contracts-v1/foundry.toml
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
1 change: 1 addition & 0 deletions contracts-v1/lib/forge-std
Submodule forge-std added at 1eea5b
1 change: 1 addition & 0 deletions contracts-v1/lib/layerzero-v2
Submodule layerzero-v2 added at 34321a
1 change: 1 addition & 0 deletions contracts-v1/lib/openzeppelin-contracts
Submodule openzeppelin-contracts added at 69c8de
7 changes: 7 additions & 0 deletions contracts-v1/remappings.txt
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/
19 changes: 19 additions & 0 deletions contracts-v1/script/Counter.s.sol
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();
}
}
14 changes: 14 additions & 0 deletions contracts-v1/src/Counter.sol
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++;
}
}
24 changes: 24 additions & 0 deletions contracts-v1/test/Counter.t.sol
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);
}
}
Loading