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

[SC-623] Rename all instances of nst to usds #12

Merged
merged 6 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

# Overview

Common user actions in the Maker ecosystem related to DAI, sDAI, NST, sNST, and USDC. USDT is unsupported because of a lack of first-class support in Maker at this time. USDT can be supported if Maker infrastructure is added in the future. Users wanting to enter or exit via USDT need to use DEX aggregators such as Cowswap.
Common user actions in the Maker ecosystem related to DAI, sDAI, USDS, sUSDS, and USDC. USDT is unsupported because of a lack of first-class support in Maker at this time. USDT can be supported if Maker infrastructure is added in the future. Users wanting to enter or exit via USDT need to use DEX aggregators such as Cowswap.

These contracts are not meant to exhaustively cover all use cases, but group common actions where there is more than 1 transaction required. For example, swapping from USDC to sDAI is covered, but not DAI to sDAI because there is already a `deposit(...)` function on the sDAI contract.

Expand Down Expand Up @@ -39,38 +39,38 @@ Below is a diagram that outlines the top-level actions that can be taken by a us

## Ethereum (PSM Wrapper - Variant 3)

- `NST <-> sNST`: sNST ERC-4626 interface
- `USDC <-> NST`: [NstPsmWrapper](https://github.com/makerdao/nst-wrappers/blob/dev/src/NstPsmWrapper.sol)
- `USDC <-> sNST`: PSMVariant1Actions
- `NST <-> Farms`: Directly deposit/withdraw
- `USDS <-> sUSDS`: sUSDS ERC-4626 interface
- `USDC <-> USDS`: [UsdsPsmWrapper](https://github.com/makerdao/usds-wrappers/blob/dev/src/UsdsPsmWrapper.sol)
- `USDC <-> sUSDS`: PSMVariant1Actions
- `USDS <-> Farms`: Directly deposit/withdraw

## Ethereum (Migration Actions)

- `DAI <-> NST`: MigrationActions
- `sDAI -> NST`: MigrationActions
- `DAI -> sNST`: MigrationActions
- `sDAI -> sNST`: MigrationActions
- `DAI <-> USDS`: MigrationActions
- `sDAI -> USDS`: MigrationActions
- `DAI -> sUSDS`: MigrationActions
- `sDAI -> sUSDS`: MigrationActions

## Non-Ethereum chains

A three-way PSM will be provided here: https://github.com/marsfoundation/spark-psm. This can be used directly by UIs.

- `NST <-> sNST`: Swap in PSM
- `USDC <-> NST`: Swap in PSM
- `USDC <-> sNST`: Swap in PSM
- `NST <-> Farms`: Directly deposit/withdraw
- `USDS <-> sUSDS`: Swap in PSM
- `USDC <-> USDS`: Swap in PSM
- `USDC <-> sUSDS`: Swap in PSM
- `USDS <-> Farms`: Directly deposit/withdraw

# Contracts

## PSMVariant1Actions

Intended to be used with the first version of the USDC PSM at `0x89B78CfA322F6C5dE0aBcEecab66Aee45393cC5A` and sDAI, but also compatible with the newer lite psm and NST wrapper.
Intended to be used with the first version of the USDC PSM at `0x89B78CfA322F6C5dE0aBcEecab66Aee45393cC5A` and sDAI, but also compatible with the newer lite psm and USDS wrapper.

The code is written in a general way, but it is expected for this to be used with the USDC PSM and sDAI. Please note that all values are measured in either USDC or DAI and not sDAI shares. This keeps the UI simple in that you can specify `100e18` of sDAI to mean "100 DAI worth of sDAI" instead of doing the share conversion.

Deployed at (Original PSM): [0x52d298ff9e77e71c2eb1992260520e7b15257d99](https://etherscan.io/address/0x52d298ff9e77e71c2eb1992260520e7b15257d99)
Deployed at (PSM Lite): [0x5803199F1085d52D1Bb527f24Dc1A2744e80A979](https://etherscan.io/address/0x5803199F1085d52D1Bb527f24Dc1A2744e80A979)
Deployed at (NST PSM Wrapper): TBD
Deployed at (USDS PSM Wrapper): TBD

### swapAndDeposit

Expand Down Expand Up @@ -143,9 +143,9 @@ actions.redeemAndSwap(address(this), bal, sDAI.convertToAssets(bal));

## MigrationActions

This contract is used to upgrade from DAI, sDAI to NST, sNST. Also contains a downgrade path for NST -> DAI for backwards compatibility.
This contract is used to upgrade from DAI, sDAI to USDS, sUSDS. Also contains a downgrade path for USDS -> DAI for backwards compatibility.

Below is a diagram that outlines the migration path from sDAI to sNST. This migration path is the most complex and all other paths are subsets of this one.
Below is a diagram that outlines the migration path from sDAI to sUSDS. This migration path is the most complex and all other paths are subsets of this one.

![sDai to sNst](https://github.com/user-attachments/assets/a7b74251-f7bb-46e1-ac77-88a1e1c452b5)
hexonaut marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
112 changes: 56 additions & 56 deletions src/MigrationActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,128 +15,128 @@ interface VatLike {
}

/**
* @notice Actions for migrating from DAI/sDAI to NST/sNST.
* @dev Also contains 1 downgrade path from NST to DAI for convenience.
* @notice Actions for migrating from DAI/sDAI to USDS/sUSDS.
* @dev Also contains 1 downgrade path from USDS to DAI for convenience.
*/
contract MigrationActions {

IERC20 public immutable dai;
IERC20 public immutable nst;
IERC20 public immutable usds;
IERC4626 public immutable sdai;
IERC4626 public immutable snst;
IERC4626 public immutable susds;

VatLike public immutable vat;
JoinLike public immutable daiJoin;
JoinLike public immutable nstJoin;
JoinLike public immutable usdsJoin;

constructor(
address _sdai,
address _snst,
address _susds,
address _daiJoin,
address _nstJoin
address _usdsJoin
) {
sdai = IERC4626(_sdai);
snst = IERC4626(_snst);
sdai = IERC4626(_sdai);
susds = IERC4626(_susds);

dai = IERC20(sdai.asset());
nst = IERC20(snst.asset());
dai = IERC20(sdai.asset());
usds = IERC20(susds.asset());

daiJoin = JoinLike(_daiJoin);
nstJoin = JoinLike(_nstJoin);
vat = daiJoin.vat();
daiJoin = JoinLike(_daiJoin);
usdsJoin = JoinLike(_usdsJoin);
vat = daiJoin.vat();

// Infinite approvals
dai.approve(_daiJoin, type(uint256).max);
nst.approve(_nstJoin, type(uint256).max);
nst.approve(_snst, type(uint256).max);
dai.approve(_daiJoin, type(uint256).max);
usds.approve(_usdsJoin, type(uint256).max);
usds.approve(_susds, type(uint256).max);
lucas-manuel marked this conversation as resolved.
Show resolved Hide resolved

// Vat permissioning
vat.hope(_daiJoin);
vat.hope(_nstJoin);
vat.hope(_usdsJoin);
}

/**
* @notice Migrate `assetsIn` of `dai` to `nst`.
* @param receiver The receiver of `nst`.
* @notice Migrate `assetsIn` of `dai` to `usds`.
* @param receiver The receiver of `usds`.
* @param assetsIn The amount of `dai` to migrate.
*/
function migrateDAIToNST(address receiver, uint256 assetsIn) public {
function migrateDAIToUSDS(address receiver, uint256 assetsIn) public {
dai.transferFrom(msg.sender, address(this), assetsIn);
_migrateDAIToNST(receiver, assetsIn);
_migrateDAIToUSDS(receiver, assetsIn);
}

/**
* @notice Migrate `assetsIn` of `dai` to `snst`.
* @param receiver The receiver of `snst`.
* @notice Migrate `assetsIn` of `dai` to `susds`.
* @param receiver The receiver of `susds`.
* @param assetsIn The amount of `dai` to migrate.
* @return sharesOut The amount of `snst` shares received.
* @return sharesOut The amount of `susds` shares received.
*/
function migrateDAIToSNST(address receiver, uint256 assetsIn) external returns (uint256 sharesOut) {
migrateDAIToNST(address(this), assetsIn);
sharesOut = snst.deposit(assetsIn, receiver);
function migrateDAIToSUSDS(address receiver, uint256 assetsIn) external returns (uint256 sharesOut) {
migrateDAIToUSDS(address(this), assetsIn);
sharesOut = susds.deposit(assetsIn, receiver);
}

/**
* @notice Migrate `assetsIn` of `sdai` to `nst`.
* @param receiver The receiver of `nst`.
* @notice Migrate `assetsIn` of `sdai` to `usds`.
* @param receiver The receiver of `usds`.
* @param assetsIn The amount of `sdai` to migrate in assets.
*/
function migrateSDAIAssetsToNST(address receiver, uint256 assetsIn) public {
function migrateSDAIAssetsToUSDS(address receiver, uint256 assetsIn) public {
sdai.withdraw(assetsIn, address(this), msg.sender);
_migrateDAIToNST(receiver, assetsIn);
_migrateDAIToUSDS(receiver, assetsIn);
}

/**
* @notice Migrate `sharesIn` of `sdai` to `nst`.
* @param receiver The receiver of `nst`.
* @notice Migrate `sharesIn` of `sdai` to `usds`.
* @param receiver The receiver of `usds`.
* @param sharesIn The amount of `sdai` to migrate in shares.
* @return assetsOut The amount of `nst` assets received.
* @return assetsOut The amount of `usds` assets received.
*/
function migrateSDAISharesToNST(address receiver, uint256 sharesIn) public returns (uint256 assetsOut) {
function migrateSDAISharesToUSDS(address receiver, uint256 sharesIn) public returns (uint256 assetsOut) {
assetsOut = sdai.redeem(sharesIn, address(this), msg.sender);
_migrateDAIToNST(receiver, assetsOut);
_migrateDAIToUSDS(receiver, assetsOut);
}

/**
* @notice Migrate `assetsIn` of `sdai` (denominated in `dai`) to `snst`.
* @param receiver The receiver of `snst`.
* @notice Migrate `assetsIn` of `sdai` (denominated in `dai`) to `susds`.
* @param receiver The receiver of `susds`.
* @param assetsIn The amount of `sdai` to migrate (denominated in `dai`).
* @return sharesOut The amount of `snst` shares received.
* @return sharesOut The amount of `susds` shares received.
*/
function migrateSDAIAssetsToSNST(address receiver, uint256 assetsIn) external returns (uint256 sharesOut) {
migrateSDAIAssetsToNST(address(this), assetsIn);
sharesOut = snst.deposit(assetsIn, receiver);
function migrateSDAIAssetsToSUSDS(address receiver, uint256 assetsIn) external returns (uint256 sharesOut) {
migrateSDAIAssetsToUSDS(address(this), assetsIn);
sharesOut = susds.deposit(assetsIn, receiver);
}

/**
* @notice Migrate `sharesIn` of `sdai` to `snst`.
* @param receiver The receiver of `snst`.
* @notice Migrate `sharesIn` of `sdai` to `susds`.
* @param receiver The receiver of `susds`.
* @param sharesIn The amount of `sdai` to migrate in shares.
* @return sharesOut The amount of `snst` shares received.
* @return sharesOut The amount of `susds` shares received.
*/
function migrateSDAISharesToSNST(address receiver, uint256 sharesIn) external returns (uint256 sharesOut) {
uint256 assets = migrateSDAISharesToNST(address(this), sharesIn);
sharesOut = snst.deposit(assets, receiver);
function migrateSDAISharesToSUSDS(address receiver, uint256 sharesIn) external returns (uint256 sharesOut) {
uint256 assets = migrateSDAISharesToUSDS(address(this), sharesIn);
sharesOut = susds.deposit(assets, receiver);
}

/**
* @notice Downgrade `assetsIn` of `nst` to `dai`.
* @notice Downgrade `assetsIn` of `usds` to `dai`.
* @param receiver The receiver of `dai`.
* @param assetsIn The amount of `nst` to downgrade.
* @param assetsIn The amount of `usds` to downgrade.
*/
function downgradeNSTToDAI(address receiver, uint256 assetsIn) external {
nst.transferFrom(msg.sender, address(this), assetsIn);
nstJoin.join(address(this), assetsIn);
function downgradeUSDSToDAI(address receiver, uint256 assetsIn) external {
usds.transferFrom(msg.sender, address(this), assetsIn);
usdsJoin.join(address(this), assetsIn);
lucas-manuel marked this conversation as resolved.
Show resolved Hide resolved
daiJoin.exit(receiver, assetsIn);
}

/**********************************************************************************************/
/*** Internal helper functions ***/
/**********************************************************************************************/

function _migrateDAIToNST(address receiver, uint256 amount) internal {
function _migrateDAIToUSDS(address receiver, uint256 amount) internal {
daiJoin.join(address(this), amount);
nstJoin.exit(receiver, amount);
usdsJoin.exit(receiver, amount);
lucas-manuel marked this conversation as resolved.
Show resolved Hide resolved
}

}
Loading
Loading