Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into sparrowDom/balancer…
Browse files Browse the repository at this point in the history
…_profitability_check
  • Loading branch information
sparrowDom committed Jan 30, 2024
2 parents c1e1cf2 + 3d51434 commit 23b8570
Show file tree
Hide file tree
Showing 1,318 changed files with 26,553 additions and 347,072 deletions.
73 changes: 18 additions & 55 deletions .github/workflows/defi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,19 @@ jobs:
retention-days: 1

contracts-forktest:
name: "Contracts Fork Tests"
name: "Contracts Fork Tests ${{ matrix.chunk_id }}"
runs-on: ubuntu-latest
strategy:
matrix:
chunk_id: [0,1,2,3]
continue-on-error: true
env:
HARDHAT_CACHE_DIR: ./cache
PROVIDER_URL: ${{ secrets.PROVIDER_URL }}
ONEINCH_API: ${{ secrets.ONEINCH_API }}
ONEINCH_API_KEY: ${{ secrets.ONEINCH_API_KEY }}
CHUNK_ID: "${{matrix.chunk_id}}"
MAX_CHUNKS: "4"
steps:
- uses: actions/checkout@v3

Expand All @@ -126,7 +133,7 @@ jobs:

- uses: actions/upload-artifact@v3
with:
name: fork-test-coverage-${{ github.sha }}
name: fork-test-coverage-${{ github.sha }}-runner${{ matrix.chunk_id }}
path: |
./contracts/coverage.json
./contracts/coverage/**/*
Expand Down Expand Up @@ -158,78 +165,34 @@ jobs:
- run: yarn install --frozen-lockfile
working-directory: ./contracts

- uses: actions/download-artifact@v3
with:
name: fork-test-coverage-${{ github.sha }}
path: ./fork-coverage
- uses: actions/download-artifact@v3
with:
name: unit-test-coverage-${{ github.sha }}
path: ./unit-coverage

- name: Download all reports
uses: actions/download-artifact@v3

- uses: codecov/codecov-action@v3
with:
fail_ci_if_error: true

dapp-lint:
name: "OUSD DApp Linter"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "16.x"
cache: "yarn"
cache-dependency-path: dapp/yarn.lock

- run: yarn install --frozen-lockfile
working-directory: ./dapp

- run: yarn prettier:check
working-directory: ./dapp

dapp-oeth-lint:
name: "OETH DApp Linter"
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: "16.x"
cache: "yarn"
cache-dependency-path: dapp-oeth/yarn.lock

- run: yarn install --frozen-lockfile
working-directory: ./dapp-oeth

- run: yarn prettier:check
working-directory: ./dapp-oeth

slither:
name: "Slither"
# As long as we need Python 3.6 here in the test, we can only use up to Ubuntu 20.
# https://github.com/rwth-i6/returnn/issues/1226
runs-on: ubuntu-20.04
runs-on: ubuntu-latest


steps:
- uses: actions/checkout@v3

- name: Set up Python 3.6
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.6
python-version: '3.10'

- name: Install dependencies
run: |
wget https://github.com/ethereum/solidity/releases/download/v0.5.11/solc-static-linux
wget https://github.com/ethereum/solidity/releases/download/v0.8.7/solc-static-linux
chmod +x solc-static-linux
sudo mv solc-static-linux /usr/local/bin/solc
pip3 install slither-analyzer
pip3 inspect
- name: Use Node.js
uses: actions/setup-node@v3
Expand Down
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,12 @@ contracts/coverage/
contracts/coverage.json
contracts/build/
contracts/dist/
dapp/network.json
dapp/keys/
dapp/ganache-network.json
website/network.json
/playground/public/build/

todo.txt
brownie/env-brownie/

crytic-export
contracts/echidna-corpus

contracts/.certora_*
contracts/.last_confs
Expand All @@ -79,3 +75,5 @@ coverage
coverage.json
fork-coverage
unit-coverage

.VSCodeCounter
25 changes: 25 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

RED='\033[0;31m'
NC='\033[0m'
GREEN='\033[0;32m'
files=""
# find all file ending with test.js that are not in node_modules
for file in $(find . -type d -name node_modules -prune -o -name '*test.js' -print); do
# uncomment below to debug which files match
# echo "$file"
# search if any contain it.only or describe.only
match=$(grep -E "(describe|it)\.only[[:space:]]*\(" "$file")

# add together the files containing .only
if [[ -n "${match}" ]]; then
files=${files}${file}'\n'
fi
done
if [[ -n "${files}" ]]; then
# fail pre-commit if
echo "${RED}Git pre-commit hook failed! Remove \".only\" from the following test file(s):${GREEN}"
echo ${files}
echo "${NC}"
exit 1
fi
4 changes: 1 addition & 3 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
/dapp @smitch88 @sparrowDom @shahthepro @rafaelugolini
/dapp-oeth @smitch88 @sparrowDom @shahthepro @rafaelugolini
/contracts @sparrowDom @DanielVF @naddison36 @shahthepro
/brownie @sparrowDom @DanielVF @naddison36 @shahthepro
/brownie @sparrowDom @DanielVF @naddison36 @shahthepro
22 changes: 0 additions & 22 deletions Dockerfile

This file was deleted.

1 change: 0 additions & 1 deletion Procfile

This file was deleted.

150 changes: 22 additions & 128 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Origin Dollar
# Origin DeFi's OTokens: Origin Dollar (OUSD) and Origin Ether (OETH)

For more details about the product, checkout [our docs](https://docs.oeth.com).

OUSD is a new kind of stablecoin that passively accrues yield while you are holding it.
Checkout our [docs](https://docs.ousd.com) for more details about the product.
---

| Branch | CI/CD Status |
| --------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `master` | [![Origin DeFi](https://github.com/OriginProtocol/origin-dollar/actions/workflows/defi.yml/badge.svg)](https://github.com/OriginProtocol/origin-dollar/actions/workflows/defi.yml) |
| `staging` | [![Origin DeFi](https://github.com/OriginProtocol/origin-dollar/actions/workflows/defi.yml/badge.svg?branch=staging)](https://github.com/OriginProtocol/origin-dollar/actions/workflows/defi.yml?query=branch%3Astaging) |
| `stable` | [![Origin DeFi](https://github.com/OriginProtocol/origin-dollar/actions/workflows/defi.yml/badge.svg?branch=stable)](https://github.com/OriginProtocol/origin-dollar/actions/workflows/defi.yml?query=branch%3Astable) |


## Requirements

Expand All @@ -31,7 +31,7 @@ cd origin-dollar

## Description

The `origin-dollar` project is a mono repo that hosts both the `smart contracts` and `dapp` code bases. In order to run this project locally, you will need to run both the `Eth node` and the `dapp` in separate processes or terminals.
The `origin-dollar` project is a repo that hosts the smart contracts of some Origin DeFi projects including OUSD and OETH. For Governance related contracts, head over to (origin-dollar-governance)[https://github.com/OriginProtocol/ousd-governance]. In order to run this project locally, you will need to run the `Eth node`.

### Eth Node

Expand All @@ -40,11 +40,6 @@ The `smart contracts` and all of their associated code are located in the `<proj
A variety of Hardhat [tasks](https://hardhat.org/guides/create-task.html) are available to interact with the contracts. Additional information can be found by running `npx hardhat` from the `contracts/` directory.
<br/><br/>

### dapp (Decentralized Application)

The code for `dapp` is located under the `/dapp` directory.
<br/><br/>

---

## Running the node
Expand Down Expand Up @@ -77,123 +72,6 @@ This is an option, but a simpler way is to use the `ACCOUNTS_TO_FUND` setting de
npx hardhat fund --amount 1000 --network localhost
```

##### Requirements

- You will need your web3 wallet configured before you can interact with the dapp. Make sure that you have one - refer to [this section](#configure-web3-wallet) for `Metamask` instructions.
- You will also need the dapp to be running. Refer to [this section](#running-the-dapp-locally) for instructions.

### Configure Web3 Wallet

You will need a web3 wallet to interact with the dapp and sign transactions. Below are the instructions to setup `Metamask` to interact with the dapp running locally.

- Install `Metamask` Chrome extension [HERE](https://metamask.io/)
- Create/Open `Metamask` wallet
- Add a custom RPC endpoint
- Name: `origin` - just an example
- URL: `http://localhost:8545`
- Chain ID: `1337`
<br/><br/>

#### Add Accounts to Metamask

##### Forked mode

Just use the account(s) you normally use on mainnet.

##### Standalone mode

You can get all the accounts for the locally running node and their associated private keys by running the command

```bash
# For Standalone mode
npx hardhat accounts --network localhost
```

Choose a test account past index 3 (accounts 0-3 are reserved).
Copy the private key and import it into Metamask as follows:

- Click the current account icon in the upper right corner of `Metamask`
- Select `Import Account` => paste private key => Click `Import`

Make sure that you select your newly created RPC endpoint in the networks dropdown and use your newly imported account in `Metamask`. You should now be setup to use `Metamask` to interact with the dApp.

Note:
If you want to add all the accounts via a new `Metamask` wallet and import the `mnemonic` it is located in `contracts/hardhat.config.js`. Make sure that you use Account 4 and up for test accounts as 0-3 are reserved.
<br/><br/>

### Running the dapp

Open a separate terminal to run the dapp in.

```bash
# Enter the smart dapp dir (or oeth-dapp)
cd dapp

# Install the dependencies
yarn install

# Start the dapp
yarn run start
```

- Open http://localhost:3000 in your browser and connect your `Metamask` account. See [this section](#configure-web3-wallet) for instructions if you have not done that yet.
- Open http://localhost:3000/swap and verify that you have stablecoins in your account. See [this section](#minting-stablecoins-via-hardhat-task) for instructions if you don't see a balance.

If you see a `Runtime Error: underlying network changed`, then rename `dapp/dev.env` to `.env` and restart `yarn`

If you see an error resembling `digital envelope routines::unsupported`, you are likely using an incompatible Node.js version. At last check, v16.20.2 is good.

### Troubleshooting

When freshly starting a node it is usually necessary to also reset Metamask Account being used:

- `Metamask` => `Settings` => `Advanced` => `Reset Account`
<br/><br/>
This will reset the nonce number that is incorrect if you have submitted any transactions in previous runs of the ethereum node. (Wallet has a too high nonce number comparing to the nonce state on the node)

If you get an `error Command "husky-run" not found.` type of error:
Go to root of the project and run `npx husky install`

---

## (Core Contributors) Running dapp in Production/Staging Mode Locally

There may be a time that you will need to run the dapp in production/staging mode to test out a certain feature or do verification before a deploy. In this case there is no need for a local node as you will connect directly to the mainnet/testnet.

### Requirements

- `Google Cloud` CLI tool installed as explained [HERE](https://cloud.google.com/sdk/docs/quickstart)
- Permission to the Origin GCP Account to decrypt `*.secrets.enc` and deploy infrastructure

#### Login to Google Cloud

```
# Login to GCP
gcloud auth login
```

#### Staging

```
# Decrypt staging secrets to local
yarn run decrypt-secrets:staging
# Start local dapp in Staging mode
yarn run start:staging
```

#### Production

```
# Decrypt staging secrets to local
yarn run decrypt-secrets:production
# Start local dapp in Production mode
yarn run start:production
```

---

## Running Smoke Tests

Smoke tests can be run in 2 modes:
Expand Down Expand Up @@ -221,3 +99,19 @@ Want to contribute to OUSD? Awesome!
OUSD is an Open Source project and we welcome contributions of all sorts. There are many ways to help, from reporting issues, contributing to the code, and helping us improve our community.

The best way to get involved is to join the Origin Protocol [discord server](https://discord.gg/jyxpUSe) and head over to the channel named ORIGIN DOLLAR & DEFI

# Utils

## Git pre-commit hooks (using Husky)

### Setup
```
# install Husky
npx install husky
# from project root folder install Husky hooks
npx husky install
```

If the script in .husky/pre-commit returns non 0 exit the pre-commit hook will fail. Currently the script prevents a commit if there is an ".only" in the test scripts. Use "git commit --no-verify" if you have the hook enabled and you'd like to skip pre-commit check.
Loading

0 comments on commit 23b8570

Please sign in to comment.