Skip to content

Open Dollar stablecoin contracts

License

Unknown, AGPL-3.0 licenses found

Licenses found

Unknown
LICENSE.md
AGPL-3.0
COPYING
Notifications You must be signed in to change notification settings

open-dollar/od-contracts

Repository files navigation

Open Dollar Contracts

Twitter: open_dollar

codecov

This repository contains the core smart contract code for Open Dollar.

Resources

Documentation

Contract Deployments

Addresses for can be found in the app: https://app.opendollar.com/stats

Tools

Audits

Audit Date Auditor Commit Changes Since Audit Report
contracts October, 2023 Cod4rena f401eb5 View Changes View Report
app March, 2024 Quantstamp 7c9b18c View Changes View Report
contracts April, 2024 Quantstamp 6cdc848 View Changes View Report
relayer April, 2024 Pashov Audit Group 453222d View Changes View Report

A Security Scan was performed by Pessimistic April, 2024 at a0b7640. (View Report)

Additional audits completed prior to forking this codebase can be found here: https://github.com/hai-on-op/audit-reports

Usage

Basic Setup for Cloned Repo

Run: yarn install, yarn build, yarn test

Selecting a Foundry profile

When running forge, you can specify the profile to use using the FOUNDRY_PROFILE environment variable. e.g. export FOUNDRY_PROFILE=test && forge test. Alternatively, you can add FOUNDRY_PROFILE=test to .env and run source .env.

Development

Anvil

Start Anvil:

anvil

Next, copy the private key from anvil terminal output into your .env

ANVIL_RPC=http://127.0.0.1:8545
ANVIL_ONE=0x....

Deploy the contracts locally:

yarn deploy:anvil

You now have a local anvil test environment with a locally deployed and instantiated version of the Open Dollar Protocol.

NOTE: You may need to manually verify that all required addresses were updated in AnvilContracts.t.sol. The script parseAnvilDeployments.js is not perfect.

Anvil Testing

The following scripts are used to simulate various states of the protocol. The scripts can be found in script/states and are described below:

DebtState.s.sol

  • DebtState.s.sol puts every SAFE in jeopardy of liquidation by driving the non-wstETH collateral prices down. After running DebtState any SAFEs can be liquidated freely for testing.
forge script script/states/DebtState.s.sol:DebtState --fork-url http://localhost:8545 -vvvvv

LiquidationAuction.s.sol

  • LiquidationAuction.s.sol takes DebtState a step further and liquidates every SAFE on the platform. It then initiates and completes a single collateral auction. We also create a chunk of unbacked debt in the accounting engine which enables launching a debt auction. This state can be used to test liquidations, launching collateral auctions, launching a debt auction or viewing a completed collateral auction.
forge script script/states/DebtAuction.s.sol:DebtAuction --fork-url http://localhost:8545 -vvvvv

DebtAuction.s.sol

DebtAuction.s.sol takes LiquidationAuction a step further and creates a large amount of unbacked debt in the AccountingEngine; which allows us to then create a debt auction. The debt auction is then bid on and settled. This allows testing of viewing a completed debt auction.

forge script script/states/DebtAuction.s.sol:DebtAuction --fork-url http://localhost:8545 -vvvvv`

SurplusState.s.sol

SurplusState.s.sol pushes the clock forward so that the protocol accrues surplus. It can be used to test launching a SurplusAuction.

forge script script/states/SurplusState.s.sol:SurplusState --fork-url http://localhost:8545 -vvvvv

SurplusAuction.s.sol

SurplusAuction.s.sol takes SurplusState a step farther, and initiates a surplus auction, bids on it and settles it. It can be used to test viewing a completed surplus auction.`

forge script script/states/SurplusAuction.s.sol:SurplusAuction --fork-url http://localhost:8545 -vvvvv

Tests

Forge test

yarn test will run all tests in the test folder. These tests are pranked on a fork Arbitrum mainnet. Additionally, there are Sepolia deployment tests.

Coverage Reports with Anvil

Coverage testing is performed using lcov and a local Anvil fork of the contracts. First install lcov for mac/linx.

  1. Start Anvil using the instructions above.

  2. To generate a report, run the command:

yarn test:coverage
  1. Open coverage-report/index.html to view the report.