Skip to content

Commit

Permalink
Merge pull request #15 from defi-wonderland/dev
Browse files Browse the repository at this point in the history
feat: v1.0.0 (pre-release)
  • Loading branch information
piesrtasty authored Nov 21, 2023
2 parents 398b793 + 04e09a3 commit 1162b34
Show file tree
Hide file tree
Showing 267 changed files with 3,368 additions and 3,063 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/export-abis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
branches:
- main
- dev
workflow_dispatch:

jobs:
generate_interfaces:
Expand Down Expand Up @@ -43,7 +44,7 @@ jobs:
destination_dir: 'abis-package'

- name: Generate canary tag
if: github.ref_name == 'dev'
if: github.ref_name != 'main'
run: cd abis-package && yarn version --new-version "0.0.0-${GITHUB_SHA::8}" --no-git-tag-version

- name: Publish
Expand Down
50 changes: 50 additions & 0 deletions .github/workflows/export-interfaces.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: Interface Exporter Action

on:
push:
branches:
- main
- dev
workflow_dispatch:

jobs:
generate_interfaces:
if: github.repository == 'hai-on-op/hai'
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Use Node.js
uses: actions/setup-node@v3
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'

- name: Install dependencies
run: yarn --frozen-lockfile --network-concurrency 1

- name: Build project and generate out directory
run: yarn build

- name: Run Interface Exporter Action
uses: defi-wonderland/[email protected]
with:
out_dir: 'out'
typing_type: 'contracts'
package_name: '@hai-on-op/interfaces'
destination_dir: 'interfaces-package'

- name: Generate canary tag
if: github.ref_name != 'main'
run: cd interfaces-package && yarn version --new-version "0.0.0-${GITHUB_SHA::8}" --no-git-tag-version

- name: Publish
run: cd interfaces-package && npm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
1 change: 0 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/brockelmore/forge-std
branch = chore/v1.5.4
[submodule "lib/isolmate"]
path = lib/isolmate
url = https://github.com/defi-wonderland/isolmate
Expand Down
6 changes: 3 additions & 3 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Copyright (C) 2017 DappHub, LLC
Copyright (C) 2017 DappHub, LLC
Copyright (C) 2018 Rain <[email protected]>
Copyright (C) 2018 Lev Livnev <[email protected]>
Copyright (C) 2020 Maker Ecosystem Growth Holdings, INC.
Copyright (C) 2020 Reflexer Labs, INC.
Copyright (C) 2015-2020 DappHub, LLC
Copyright (C) 2023 Wonderland
Copyright (C) 2015-2020 DappHub, LLC
Copyright (C) 2023 Reflexer Labs, INC.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
Expand Down
6 changes: 3 additions & 3 deletions docs/src/detailed/auctions/dah.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ This system ensures that bad debts are efficiently cleared from the protocol, wh

**Public**

- `restartAuction`: Allows for the resumption of an expired auction that has received no bids. This restarts the auction and increases the initial quantity of protocol tokens to be minted as an incentive for participation.
- `decreaseSoldAmount`: Enables users to participate in the auction by bidding. System coins are transferred during this operation.
- `settleAuction`: Finalizes an auction, distributing the protocol tokens to the winning bidder.
- `terminateAuctionPrematurely`: Ends an auction before its scheduled completion. This method creates an unbacked debt entry in the Accounting Engine and returns the system coins to the highest bidder. Note that this action can only be performed when the contract is disabled.

**Authorized**

- `restartAuction`: Allows for the resumption of an expired auction that has received no bids. This restarts the auction and increases the initial quantity of protocol tokens to be minted as an incentive for participation.

- `terminateAuctionPrematurely`: Ends an auction before its scheduled completion. This method creates an unbacked debt entry in the Accounting Engine and returns the system coins to the highest bidder. Note that this action can only be performed when the contract is disabled.
- `startAuction`: Initiates a new debt auction.

### Contract Parameters:

Expand Down
2 changes: 1 addition & 1 deletion docs/src/detailed/intro/protocol.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
### What is HAI?

- **Low-Cost**: The HAI protocol is deployed on the Optimism network, offering significantly low gas fees for transactions.
- **Dollar-Denominated**: Both the system coin and the collaterals are pegged to the US Dollar.
- **Dollar-Denominated**: Both the system coin and the collaterals are denominated in US Dollar.
- **Collateral-Backed**: A diverse basket of collateral types backs the minting of the system coin.
- **Control-Pegged**: A PID controller dynamically adjusts the funding rate to balance value transfer between minters (debtors) and holders (creditors).
- **Settleable**: The system can undergo a Global Settlement, during which all debts are squared and HAI holders can redeem tokens for a share of the collateral pool, regardless of whether they have outstanding debts.
Expand Down
4 changes: 2 additions & 2 deletions docs/src/detailed/modules/acc_engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ The Accounting Engine serves as the system's financial management hub, overseein

**Public**

- `popDebtFromQueue`: Removes a certain amount of debt from the time-sensitive queue after the `popDebtDelay` duration has elapsed, for either settlement or auction.
- `settleDebt`: Utilizes coin balance to settle debt.
- `cancelAuctionedDebtWithSurplus`: Utilizes coins to settle debt that's in the queue.
- `auctionDebt`: Triggers an auction to liquidate portions of unsettled debt.
- `auctionSurplus`: Triggers an auction to liquidate surplus once all debt has been settled.
- `transferExtraSurplus`: Allocates (instead of auctioning it) excess surplus following debt settlement.
Expand All @@ -26,8 +28,6 @@ The Accounting Engine serves as the system's financial management hub, overseein
**Authorized**

- `pushDebtToQueue`: Adds a specified amount of debt to a time-sensitive queue.
- `popDebtFromQueue`: Removes a certain amount of debt from the time-sensitive queue after the `popDebtDelay` duration has elapsed, for either settlement or auction.
- `cancelAuctionedDebtWithSurplus`: Utilizes coins to settle debt that's in the queue.
- `disableContract`: Deactivates both Debt and Surplus Auction Houses, clears as much debt as possible, and transfers (after `disableCooldown` delay) any leftover surplus to a designated drain address.

### Required Authorities:
Expand Down
4 changes: 2 additions & 2 deletions docs/src/detailed/modules/liq_engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ debtToAuction = debtToCover * liquidationPenalty

The quantity of collateral and debt seized from a SAFE during liquidation is decided based on the following criteria:

- If the SAFE's debt is smaller than `liquidationVolume`, the SAFE undergoes full liquidation.
- If the SAFE's debt surpasses `liquidationVolume`, the SAFE is only partially liquidated, and residual debt remains.
- If the SAFE's debt is smaller than `liquidationQuantity`, the SAFE undergoes full liquidation.
- If the SAFE's debt surpasses `liquidationQuantity`, the SAFE is only partially liquidated, and residual debt remains.
- If the SAFE's outstanding debt crosses the `onAuctionSystemCoinLimit`, partial liquidation occurs, and any remaining debt stays in the SAFE.
- In cases of partial liquidation, a corresponding slice of collateral is seized, leaving the remaining collateral intact within the SAFE.

Expand Down
19 changes: 19 additions & 0 deletions docs/src/detailed/modules/safe_engine.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ Users have the ability to alter the status of their SAFEs via the SAFE Engine, p
- `debtCeiling`: The max amount of debt that can be generated globally by the collateral type.
- `debtFloor`: The min amount of debt that can be generated by a SAFE of that collateral type.

### Contract Data:

**Global**

- `globalDebt`: The amount of debt that was generated by the system.
- `globalUnbackedDebt`: The amount of debt that was generated by the system and is not backed by collateral.

**Per Collateral Type**

- `debtAmount`: The amount of debt that was generated by the collateral type.
- `lockedAmount`: The amount of collateral that is locked in all SAFEs using the collateral type.
- `accumulatedRate`: A value that represents the accumulated interest rate.
- `safetyPrice`: The price of the collateral type (vs HAI) at which the SAFE is considered unsafe.
- `liquidationPrice`: The price of the collateral type (vs HAI) at which the SAFE is considered liquidatable.

> A user action should never be able to modify the SAFE collateralization resulting in an unsafe state. When an update the `safetyPrice` leaves the SAFE in an unsafe state, the user may only add collateral and/or repay debt in order to restore the SAFE's collateralization to a safe state.
>
> **Notice**: The `lockedAmount` is a storage variable used to visibilize the total amount of collateral that backs the `debtAmount`. However, this value can be artificially increased, by creating a SAFE without debt and locking collateral in it: on the event of Global Settlement, this user would be allowed to withdraw all of his collateral and it would not be accounted for the redemptions.
## 3. Key Mechanisms & Concepts

### ACCOUNTs vs SAFEs
Expand Down
10 changes: 9 additions & 1 deletion docs/src/detailed/proxies/hai_safe_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ The SAFE Manager Contract serves as an interface for interacting with the SAFE E
### Key Methods:

- `openSAFE`: Deploys a new SAFE Handler contract and registers it in the SAFE Manager.
- `transferSAFEOwnership`: Transfers ownership of a SAFE to another address.
- `transferSAFEOwnership`: Initiates the ownership transfer of a SAFE to another address (doesn't reset SAFE protection).
- `acceptSAFEOwnership`: Commits to the ownership transfer of a SAFE to another address (needs to be called by the new SAFE owner).
- `modifySAFECollateralization`: Modifies the collateralization ratio of a SAFE (lock/free collateral and/or generate/repay debt).
- `transferCollateral`: Transfers collateral from one account to another.
- `transferInternalCoins`: Transfers internal coins from one account to another.
- `quitSystem`: Closes a SAFE and transfers all remaining collateral and debt to the user's address.
- `enterSystem`: Migrates collateral and debt from a source SAFE Handler to a destination SAFE.
- `moveSAFE`: Migrates a SAFE from one SAFE to another.
- `protectSAFE`: Protects a SAFE from being liquidated, using a SafeSaviour position to improve the SAFE health when it falls below the liquidation ratio.

## 3. Key Mechanisms & Concepts

Expand All @@ -39,6 +41,12 @@ One unique feature is the ability to transfer ownership of a SAFE to another add

By providing a more accessible interface to the underlying SAFE Engine, the SAFE Manager Contract is an essential tool for anyone looking to interact with SAFEs in the HAI ecosystem.

### SAFE Protection

SAFE owners can choose to connect a SafeSaviour position in order to improve the SAFE health and protect it from liquidation. When the SAFE is on the process of being liquidated, the SafeSaviour contract will unwind the user's position, in order to either reduce the SAFE debt, or increase its collateral, to improve the SAFE health and try to prevent liquidation.

SAFE owners need to account that the SafeSaviour position is connected to the SAFE id, so when transferring ownership to another account, it is responsibility of the previous owner to disconnect any liquidity deposited in the SafeSaviour contract.

## 4. Gotchas

## 5. Failure Modes
7 changes: 4 additions & 3 deletions docs/src/detailed/utils/disableable.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ This abstract contract introduces a fundamental disable mechanism for contracts.
### Key Methods:

**Authorized**

- `disableContract`: Disables the contract.
**Internal**

**Internal**
- `_onContractDisable`: Hook to be called when the contract is disabled.
- `_isEnabled`: Checks if the contract is enabled.
**Modifiers**

**Modifiers**
- `whenEnabled`: Restricts access to the method to when the contract is enabled.
- `whenDisabled`: Restricts access to the method to when the contract is disabled.

Expand Down
3 changes: 2 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ title = 'HAI docs'
src ='src' # root_path variable in build-docs.sh

[profile.default]
solc = '0.8.19'
solc = '0.8.20'
evm_version = 'paris'
src = 'src'
test = 'test'
out = 'out'
Expand Down
2 changes: 1 addition & 1 deletion lib/forge-std
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hai",
"version": "0.1.3",
"version": "1.0.0",
"description": "Multicollateral debt backed stablecoin",
"homepage": "https://github.com/hai-on-op/hai#readme",
"repository": {
Expand Down Expand Up @@ -28,7 +28,7 @@
"prepare": "husky install",
"script:goerli": "bash -c 'source .env && forge script GoerliScript --with-gas-price 2000000000 -vvvvv --rpc-url $OP_GOERLI_RPC --broadcast --private-key $OP_GOERLI_GOVERNOR_PK --verify --etherscan-api-key $OP_ETHERSCAN_API_KEY'",
"script:goerli:delegate": "bash -c 'source .env && forge script GoerliDelegate --with-gas-price 2000000000 -vvvvv --rpc-url $OP_GOERLI_RPC --broadcast --private-key $OP_GOERLI_GOVERNOR_PK --verify --etherscan-api-key $OP_ETHERSCAN_API_KEY'",
"test": "FOUNDRY_FUZZ_RUNS=128 FOUNDRY_FUZZ_MAX_TEST_REJECTS=1000000 forge test -vvv",
"test": "FOUNDRY_FUZZ_RUNS=128 FOUNDRY_FUZZ_MAX_TEST_REJECTS=10000000 FOUNDRY_FUZZ_SEED=69 forge test -vvv",
"test:e2e": "forge test --match-contract E2E -vvv",
"test:local": "FOUNDRY_FUZZ_RUNS=32 FOUNDRY_FUZZ_MAX_TEST_REJECTS=1000000 forge test -vvv",
"test:simulation": "forge test --match-contract Simulation --ffi",
Expand All @@ -42,9 +42,9 @@
},
"dependencies": {
"@defi-wonderland/solidity-utils": "0.0.0-4298c6c6",
"@openzeppelin/contracts": "4.8.2",
"@openzeppelin/contracts": "5.0.0",
"@uniswap/v3-periphery": "https://github.com/Uniswap/v3-periphery.git#0.8",
"forge-std": "https://github.com/foundry-rs/forge-std.git#e8a047e3f40f13fa37af6fe14e6e06283d9a060e"
"forge-std": "https://github.com/foundry-rs/forge-std.git#f73c73d2018eb6a111f35e4dae7b4f27401e9421"
},
"devDependencies": {
"@commitlint/cli": "17.0.3",
Expand Down
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@defi-wonderland/solidity-utils/=node_modules/@defi-wonderland/solidity-utils/solidity/
@openzeppelin/=node_modules/@openzeppelin/contracts/
@openzeppelin/=node_modules/@openzeppelin/
@uniswap/=node_modules/@uniswap/

@contracts/=src/contracts/
Expand Down
Loading

0 comments on commit 1162b34

Please sign in to comment.