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

test: Use DSROracle in invariant tests (SC-484) #16

Merged
merged 119 commits into from
Jul 4, 2024
Merged
Changes from 1 commit
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
822694a
feat: first test working
lucas-manuel May 18, 2024
d6530e1
feat: use larger numbers:
lucas-manuel May 18, 2024
8f11df4
feat: test with initial burn amount passing
lucas-manuel May 18, 2024
78fb4ad
feat: update tests to work with updated burn logic, move conversion f…
lucas-manuel May 21, 2024
d32fd2f
feat: remove todos
lucas-manuel May 21, 2024
2290417
fix: update to remove console and update comment
lucas-manuel May 21, 2024
1fe351b
feat: get swap tests working
lucas-manuel May 22, 2024
cbea0ee
feat: get all swap tests working
lucas-manuel May 22, 2024
7d1101d
fix: update for three assets in logic
lucas-manuel May 22, 2024
80440e0
feat: all tests passing
lucas-manuel May 22, 2024
51b980d
fix: rm commented out test
lucas-manuel May 22, 2024
e6b67c6
feat: add preview swap tests
lucas-manuel May 22, 2024
ffa4513
feat: move logic out of single use internal and use conversion rate e…
lucas-manuel May 22, 2024
e9c519b
feat: move divRoundUp out of single use internal
lucas-manuel May 22, 2024
6ec2b23
feat: add full coverage for conversion tests
lucas-manuel May 22, 2024
2be5afc
feat: add more preview cases
lucas-manuel May 22, 2024
4299e03
feat: refactor PSM to use three assets
lucas-manuel May 22, 2024
64c9939
fix: rm comment
lucas-manuel May 22, 2024
2c43f92
feat: add interface, natspec, events, referral code, tests passing
lucas-manuel May 22, 2024
57c65d6
fix: update to rm consolegp
lucas-manuel May 22, 2024
c0616bf
Merge branch 'sc-447-build-threeway-swap' into sc-448-add-referral-code
lucas-manuel May 22, 2024
416034f
feat: add events testing
lucas-manuel May 23, 2024
114f92b
feat: make precisions internal and add state var natspec
lucas-manuel May 23, 2024
8c2f83b
feat: finish natspec
lucas-manuel May 23, 2024
61443c8
feat: add readme
lucas-manuel May 23, 2024
6ca25a8
feat: add referral code note
lucas-manuel May 23, 2024
c4f8c78
fix: update constructor test
lucas-manuel May 23, 2024
b070a44
fix: update links
lucas-manuel May 23, 2024
6947398
fix: reformatting
lucas-manuel May 23, 2024
9bdcfc5
fix: update testing section
lucas-manuel May 23, 2024
d69bc8b
fix: improve overview
lucas-manuel May 23, 2024
04cc6ac
feat: add emojis
lucas-manuel May 23, 2024
54a4afe
feat: remove all share burn logic, get all non inflation attack tests…
May 30, 2024
ce5653d
fix: cleanup diff
May 30, 2024
259cf16
fix: update to use initial deposit instead of burn
May 30, 2024
62ef5c2
feat: add readme section explaining attack
May 30, 2024
0720150
fix: minimize diff
May 30, 2024
5a03fde
feat: fix conflicts
May 30, 2024
c5f7cf0
feat: rm all references to initial burn, update tests
May 30, 2024
e6c654d
fix: address bartek comments
May 30, 2024
e540afa
feat: update all tests to work with new interfaces
May 30, 2024
c41b010
feat: add deposit failure mode tests
May 30, 2024
847a1db
feat: update to add assertions for return in deposit
May 30, 2024
ecbf99b
feat: add withdraw failure tests
May 30, 2024
44a5d52
feat: update to address comments outside sharesToBurn
Jun 3, 2024
9c3958e
feat: update inflation attack test and readme
Jun 3, 2024
4c9cf09
fix: update readme
Jun 3, 2024
cb9931a
feat: update test to constrain deposit/withdraw
Jun 3, 2024
e576672
feat: update to add both cases
Jun 3, 2024
e994287
fix: merge conflicts
Jun 3, 2024
9688892
fix: merge conflicts
Jun 3, 2024
b80ed6e
fix: merge conflicts
Jun 3, 2024
108624a
fix: merge conflicts
Jun 4, 2024
73d8c8c
feat: update per review
lucas-manuel Jun 4, 2024
d6c6f03
fix: merge conflicts
lucas-manuel Jun 4, 2024
5319255
Merge branch 'sc-448-add-referral-code' into sc-453-add-receiver-depo…
lucas-manuel Jun 4, 2024
0f182b2
feat: update to use underscore bound, fix test
lucas-manuel Jun 5, 2024
dfab7ec
Merge branch 'sc-447-build-threeway-swap' into sc-448-add-referral-code
lucas-manuel Jun 5, 2024
b288568
fix: merge conflicts
lucas-manuel Jun 5, 2024
ba44086
fix: typo
lucas-manuel Jun 5, 2024
62f5423
fix: merge conflicts
lucas-manuel Jun 5, 2024
9a243f9
feat: add overrides, remove referrals, update referral type
lucas-manuel Jun 10, 2024
cc68ed3
fix: update expect emit
lucas-manuel Jun 10, 2024
9862a53
feat: update name and remove todos
lucas-manuel Jun 10, 2024
376fa83
feat: move files and set up structure
lucas-manuel Jun 10, 2024
73cb854
feat: update to rename files, contracts, and errors
lucas-manuel Jun 10, 2024
f711954
fix: merge conflicts
lucas-manuel Jun 10, 2024
23c870d
fix: merge conflicts
lucas-manuel Jun 10, 2024
ce0949f
fix: merge conflicts
lucas-manuel Jun 10, 2024
81d2e37
fix: rm dup file, update toml
lucas-manuel Jun 10, 2024
fbff8d3
feat: get deposits working
lucas-manuel Jun 10, 2024
3e5a3eb
chore: refactor into proper inheritance structure
lucas-manuel Jun 10, 2024
2e60593
feat: get all functions working with reverts
lucas-manuel Jun 10, 2024
14fdf08
fix: cofnlicts
lucas-manuel Jun 13, 2024
defc84e
feat: update conversion
lucas-manuel Jun 13, 2024
bbc3e8e
feat: get swaps working without reverts
lucas-manuel Jun 13, 2024
4c04863
feat: add fully working deposit/withdraw/swaps, invariant_B failing
lucas-manuel Jun 13, 2024
d23bfbe
ci: update for ci
lucas-manuel Jun 13, 2024
7ba3e16
fix: update name
lucas-manuel Jun 13, 2024
499afae
chore: rm basly cased file
lucas-manuel Jun 13, 2024
d1daf4b
chore: re add
lucas-manuel Jun 13, 2024
84c3787
fix: re add invariant
lucas-manuel Jun 13, 2024
3814067
ci: experiment with 2 million total calls
lucas-manuel Jun 13, 2024
9215a29
ci: add show progress flag
lucas-manuel Jun 13, 2024
9caf3c6
fix: move file back
lucas-manuel Jun 13, 2024
094d613
ci: update verbosity
lucas-manuel Jun 13, 2024
2085360
ci: add PR profile
lucas-manuel Jun 13, 2024
0605586
fix: rm redundant files
lucas-manuel Jun 13, 2024
74dba88
feat: update from review changes
lucas-manuel Jun 14, 2024
fa3a232
feat: add afterInvariant hook
lucas-manuel Jun 19, 2024
ba9b5fe
Merge branch 'master' into sc-459-add-basic-invariant-testing
lucas-manuel Jun 20, 2024
608daf5
Merge branch 'master' into sc-459-add-basic-invariant-testing
lucas-manuel Jun 20, 2024
c4bf0cc
fix: update invariant
lucas-manuel Jun 20, 2024
df65c1b
fix: add fuzz failure
lucas-manuel Jun 20, 2024
42581aa
chore: rm indexing comment
lucas-manuel Jun 21, 2024
49fdc1f
Merge branch 'sc-459-add-basic-invariant-testing' into sc-481-add-inv…
lucas-manuel Jun 21, 2024
1b07d93
feat: refactor structure
lucas-manuel Jun 21, 2024
e5153a0
feat: both invariants working
lucas-manuel Jun 21, 2024
c664f2c
fix: update comment
lucas-manuel Jun 21, 2024
3bcb0d0
feat: add rate setting logic
lucas-manuel Jun 21, 2024
54e8ae9
fix: update toml
lucas-manuel Jun 21, 2024
f982ff3
fix: rm redundant files from merge
lucas-manuel Jun 21, 2024
1c3c450
Merge branch 'sc-459-add-basic-invariant-testing' into sc-481-add-inv…
lucas-manuel Jun 21, 2024
ffa6eee
fix: update tolerances
lucas-manuel Jun 21, 2024
a2e6f05
feat: update to add seeding as part of invariants
lucas-manuel Jun 21, 2024
68f41ab
fix: merge branch
lucas-manuel Jun 21, 2024
adf11a5
fix: update toml
lucas-manuel Jun 21, 2024
07d372e
fix: rm redundant files from merge
lucas-manuel Jun 21, 2024
7b1bf35
fix: update tolerances
lucas-manuel Jun 21, 2024
6ed0f85
Merge branch 'sc-481-add-invariant-hooks-more-suites' into sc-483-add…
lucas-manuel Jun 21, 2024
d78c024
fix: rm invariant logs
lucas-manuel Jun 21, 2024
e358437
fix: update tolerance
lucas-manuel Jun 24, 2024
da05a92
forge install: xchain-dsr-oracle
lucas-manuel Jun 24, 2024
62578bb
feat: setup timebased handler, refactor rate provider structure
lucas-manuel Jun 24, 2024
b1212b7
feat: tests passing
lucas-manuel Jun 24, 2024
c3503e0
fix: merge conflicts
lucas-manuel Jul 3, 2024
ae6c47b
chore: first cleanup
lucas-manuel Jul 3, 2024
5f1e228
fix: test names
lucas-manuel Jul 3, 2024
4a1e43d
fix: update dsr value, change chi approach
lucas-manuel Jul 4, 2024
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
Prev Previous commit
Next Next commit
feat: add readme
lucas-manuel committed May 23, 2024
commit 61443c80834b9aeac4fb1ba95a8985c7c0e6e861
73 changes: 66 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -7,21 +7,80 @@
[foundry]: https://getfoundry.sh/
[foundry-badge]: https://img.shields.io/badge/Built%20with-Foundry-FFDB1C.svg

PSM contracts to either:
- Convert between a tokenization of an asset (ex. USDC) and a yield-bearing version of the asset (ex. sDAI).
- Convert one to one between directly correlated assets (ex. USDC-DAI).
## Overview

## Usage
This repository contains the implementation of a Peg Stability Module (PSM) contract, which facilitates the swapping, depositing, and withdrawing of three given assets to maintain stability and ensure the peg of involved assets. The PSM supports both yield-bearing and non-yield-bearing assets.

```bash
forge build
```
This overview provides the essential information needed to understand and interact with the PSM contract. For detailed implementation, refer to the contract code and `IPSM` interface documentation.

## Test

```bash
forge test
```
## Usage

## Contracts

### PSM Contract

The core contract implementing the `IPSM` interface, providing functionality for swapping, depositing, and withdrawing assets.

### IPSM Interface

Defines the essential functions and events that the PSM contract implements.

### IRateProviderLike Interface

Defines the function to get the conversion rate between yield-bearing and non-yield-bearing assets.

## PSM Contract Details

### State Variables and Immutables

- **`asset0`**: Non-yield-bearing base asset (e.g., USDC).
- **`asset1`**: Another non-yield-bearing base asset that is directly correlated to `asset0` (e.g., DAI).
- **`asset2`**: Yield-bearing version of both `asset0` and `asset1` (e.g., sDAI).
- **`rateProvider`**: Contract that returns a conversion rate between and `asset2` and the base asset (e.g., sDAI to USD) in 1e27 precision.
- **`initialBurnAmount`**: Initial shares burned to prevent an inflation frontrunning attack (more info on this [here](https://mixbytes.io/blog/overview-of-the-inflation-attack)).
- **`totalShares`**: Total shares in the PSM. Shares represent the ownership of the underlying assets in the PSM.
- **`shares`**: Mapping of user addresses to their shares.

### Functions

#### Swap Functions

- **`swap`**: Allows swapping of assets based on current conversion rates. Ensures the output amount meets the minimum required before executing the transfer and emitting the swap event.

#### Liquidity Provision Functions

- **`deposit`**: Deposits assets into the PSM, minting new shares. Handles the initial burn amount for the first deposit to prevent inflation frontrunning.
- **`withdraw`**: Withdraws assets from the PSM by burning shares. Ensures the user has sufficient shares for the withdrawal and adjusts the total shares accordingly.

#### Preview Functions

- **`previewDeposit`**: Estimates the number of shares minted for a given deposit amount.
- **`previewWithdraw`**: Estimates the number of shares burned and the amount of assets withdrawn for a specified amount.
- **`previewSwap`**: Estimates the amount of one asset received for a given amount of another asset in a swap.

#### Conversion Functions

NOTE: These functions do not round in the same way as preview functions, so they are meant to be used for general quoting purposes.

- **`convertToAssets`**: Converts shares to the equivalent amount of a specified asset.
- **`convertToAssetValue`**: Converts shares to their equivalent value in base asset terms with 18 decimal precision (e.g., USD).
- **`convertToShares`**: Converts asset values to shares based on the current exchange rate.

#### Asset Value Functions

- **`getPsmTotalValue`**: Returns the total value of all assets held by the PSM denominated in the base asset with 18 decimal precision. (e.g., USD).

### Events

- **`Swap`**: Emitted on asset swaps.
- **`InitialSharesBurned`**: Emitted on the initial burn of shares.
- **`Deposit`**: Emitted on asset deposits.
- **`Withdraw`**: Emitted on asset withdrawals.

***
*The IP in this repository was assigned to Mars SPC Limited in respect of the MarsOne SP*