Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Modernize the PSM and add negative fees #6

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/out
cache/
out/
15 changes: 6 additions & 9 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "lib/ds-test"]
path = lib/ds-test
url = https://github.com/dapphub/ds-test
[submodule "lib/dss-interfaces"]
path = lib/dss-interfaces
url = https://github.com/makerdao/dss-interfaces
[submodule "lib/dss"]
path = lib/dss
url = https://github.com/makerdao/dss
[submodule "lib/dss-test"]
path = lib/dss-test
url = https://github.com/makerdao/dss-test
[submodule "lib/ds-value"]
path = lib/ds-value
url = https://github.com/dapphub/ds-value
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
all :; dapp --use solc:0.6.12 build
clean :; dapp clean
all :; forge build --use solc:0.8.14
clean :; forge clean
test :; ./test.sh $(match)
30 changes: 10 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,28 @@
# DssPsm
# dss-psm

The official implementation of the [Peg Stability Module](https://forum.makerdao.com/t/mip29-peg-stability-module/5071). There are two main components to the PSM:
The official implementation of the [Peg Stability Module](https://forum.makerdao.com/t/mip29-peg-stability-module/5071).

### AuthGemJoinX
### Psm

This is an exact duplicate of the `GemJoinX` adapter for the given collateral type with two modifications.
`Psm` allows you to either call `sellGem()` or `buyGem()` to trade ERC20 DAI for the gem or vice versa. Upon calling one of these functions the PSM vault will either lock gems in the join adapter, take out a dai loan and issue ERC20 DAI to the specified user or do that process in reverse.

First the method signature of `join()` is changed to include the original message sender at the end as well as adding the `auth` modifier. This should look like:

`function join(address urn, uint256 wad) external note` -> `function join(address urn, uint256 wad, address _msgSender) external note auth`

Second, all instances of `msg.sender` are replaced with `_msgSender` in the `join()` function.

In this repository I have added [join-5-auth.sol](https://github.com/BellwoodStudios/dss-psm/blob/master/src/join-5-auth.sol) for the PSM-friendly version of [join-5.sol](https://github.com/makerdao/dss-gem-joins/blob/master/src/join-5.sol) which is used for USDC. This can be applied to any other gem join adapter.

### DssPsm

This is the actual PSM module which acts as a authed special vault sitting behind the `AuthGemJoinX` contract. `DssPsm` allows you to either call `sellGem()` or `buyGem()` to trade ERC20 DAI for the gem or vice versa. Upon calling one of these functions the PSM vault will either lock gems in the join adapter, take out a dai loan and issue ERC20 DAI to the specified user or do that process in reverse.
`Psm` can charge either a positive or negative fee in both directions. Positive fees correspond to the user paying the protocol for using the PSM. Negative fees correspond to the protocol paying the user for using the PSM.

#### Approvals

The PSM requires ERC20 approvals to pull in the tokens.

To use `sellGem(usr, amt)` you must first call `gem.approve(<gemJoinAddress>, amt)`. Example:
To use `sellGem(usr, amt)` you must first call `gem.approve(<psmAddress>, amt)`. Example:

// Trade 100 USDC for 100 DAI - fee
usdc.approve(0x0A59649758aa4d66E25f08Dd01271e891fe52199, 100 * (10 ** 6));
usdc.approve(<psmAddress>, 100 * (10 ** 6));
psm.sellGem(address(this), 100 * (10 ** 6));

To use `buyGem(usr, amt)` you must first call `dai.approve(<psmAddress>, amt + fee)`. Example:

// Trade DAI + fee for 100 USDC
uint256 WAD = 10 ** 18;
dai.approve(0x89B78CfA322F6C5dE0aBcEecab66Aee45393cC5A, 100 * (psm.tout() + WAD));
dai.approve(<psmAddress>, 100 * (psm.tout() + WAD));
psm.buyGem(address(this), 100 * (10 ** 6));

#### Notes on Fees
Expand All @@ -45,7 +35,7 @@ When calling `buyGem()`, you specify the amount of the gem you want to recieve.

Please note this was a conscious decision to avoid dealing with decimal division and rounding leftovers.

## Contracts
## Old Contracts [V1]

### Mainnet

Expand All @@ -57,4 +47,4 @@ USDP PSM: [0x961Ae24a1Ceba861D1FDf723794f6024Dc5485Cf](https://etherscan.io/addr
### Kovan

USDC GemJoin: [0x4BA159Ad37FD80D235b4a948A8682747c74fDc0E](https://kovan.etherscan.io/address/0x4BA159Ad37FD80D235b4a948A8682747c74fDc0E#code)
USDC PSM: [0xe4dC42e438879987e287A6d9519379936d7b065A](https://kovan.etherscan.io/address/0xe4dC42e438879987e287A6d9519379936d7b065A#code)
USDC PSM: [0xe4dC42e438879987e287A6d9519379936d7b065A](https://kovan.etherscan.io/address/0xe4dC42e438879987e287A6d9519379936d7b065A#code)
59 changes: 0 additions & 59 deletions deploy.sh

This file was deleted.

7 changes: 7 additions & 0 deletions foundry.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[profile.default]
src = 'src'
out = 'out'
libs = ['lib']
remappings = ['dss-test/=lib/dss-test/src/']

# See more config options https://github.com/gakonst/foundry/tree/master/config
1 change: 0 additions & 1 deletion lib/ds-test
Submodule ds-test deleted from 0a5da5
1 change: 1 addition & 0 deletions lib/ds-value
Submodule ds-value added at 4049ec
1 change: 0 additions & 1 deletion lib/dss
Submodule dss deleted from 814413
1 change: 0 additions & 1 deletion lib/dss-interfaces
Submodule dss-interfaces deleted from 4470bc
1 change: 1 addition & 0 deletions lib/dss-test
Submodule dss-test added at b98323
97 changes: 0 additions & 97 deletions src/join-5-auth.sol

This file was deleted.

111 changes: 0 additions & 111 deletions src/join-8-auth.sol

This file was deleted.

Loading