Skip to content

Commit

Permalink
abstract the common DAI to NST route
Browse files Browse the repository at this point in the history
  • Loading branch information
hexonaut committed Jul 4, 2024
1 parent 2e5d9c0 commit 97efe84
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/MigrationActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ contract MigrationActions {
*/
function migrateDAIToNST(address receiver, uint256 assetsIn) external {
dai.transferFrom(msg.sender, address(this), assetsIn);
daiJoin.join(address(this), assetsIn);
nstJoin.exit(receiver, assetsIn);
_migrateDAIToNST(receiver, assetsIn);
}

/**
Expand All @@ -73,8 +72,7 @@ contract MigrationActions {
*/
function migrateDAIToSNST(address receiver, uint256 assetsIn) external returns (uint256 sharesOut) {
dai.transferFrom(msg.sender, address(this), assetsIn);
daiJoin.join(address(this), assetsIn);
nstJoin.exit(address(this), assetsIn);
_migrateDAIToNST(address(this), assetsIn);
sharesOut = snst.deposit(assetsIn, receiver);
}

Expand All @@ -85,8 +83,7 @@ contract MigrationActions {
*/
function migrateSDAIAssetsToNST(address receiver, uint256 assetsIn) external {
sdai.withdraw(assetsIn, address(this), msg.sender);
daiJoin.join(address(this), assetsIn);
nstJoin.exit(receiver, assetsIn);
_migrateDAIToNST(receiver, assetsIn);
}

/**
Expand All @@ -97,8 +94,7 @@ contract MigrationActions {
*/
function migrateSDAISharesToNST(address receiver, uint256 sharesIn) external returns (uint256 assetsOut) {
assetsOut = sdai.redeem(sharesIn, address(this), msg.sender);
daiJoin.join(address(this), assetsOut);
nstJoin.exit(receiver, assetsOut);
_migrateDAIToNST(receiver, assetsOut);
}

/**
Expand All @@ -109,8 +105,7 @@ contract MigrationActions {
*/
function migrateSDAIAssetsToSNST(address receiver, uint256 assetsIn) external returns (uint256 sharesOut) {
sdai.withdraw(assetsIn, address(this), msg.sender);
daiJoin.join(address(this), assetsIn);
nstJoin.exit(address(this), assetsIn);
_migrateDAIToNST(address(this), assetsIn);
sharesOut = snst.deposit(assetsIn, receiver);
}

Expand All @@ -122,8 +117,7 @@ contract MigrationActions {
*/
function migrateSDAISharesToSNST(address receiver, uint256 sharesIn) external returns (uint256 sharesOut) {
uint256 assets = sdai.redeem(sharesIn, address(this), msg.sender);
daiJoin.join(address(this), assets);
nstJoin.exit(address(this), assets);
_migrateDAIToNST(address(this), assets);
sharesOut = snst.deposit(assets, receiver);
}

Expand All @@ -138,4 +132,13 @@ contract MigrationActions {
daiJoin.exit(receiver, assetsIn);
}

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

function _migrateDAIToNST(address receiver, uint256 amount) internal {
daiJoin.join(address(this), amount);
nstJoin.exit(receiver, amount);
}

}

0 comments on commit 97efe84

Please sign in to comment.