Skip to content

Commit

Permalink
feat: add mint functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
sogipec committed May 10, 2024
1 parent ebd0a41 commit 717d233
Showing 1 changed file with 70 additions and 1 deletion.
71 changes: 70 additions & 1 deletion contracts/BaseRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ enum ActionType {
// Deprecated
addToPerpetual,
veANGLEDeposit,
claimRewardsWithPerps
claimRewardsWithPerps,
deposit4626Referral,
mint4626Referral
}

/// @notice Data needed to get permits
Expand Down Expand Up @@ -136,6 +138,14 @@ abstract contract BaseRouter is Initializable {
error TransferFailed();
error ZeroAddress();

event ReferredDeposit(
address indexed caller,
address indexed owner,
uint256 assets,
uint256 shares,
address indexed referrer
);

/// @notice Deploys the router contract on a chain
function initializeRouter(address _core, address _uniswapRouter, address _oneInch) public initializer {
if (_core == address(0)) revert ZeroAddress();
Expand Down Expand Up @@ -254,6 +264,28 @@ abstract contract BaseRouter is Initializable {
);
_changeAllowance(token, address(savingsRate), type(uint256).max);
_deposit4626(savingsRate, amount, to, minSharesOut);
} else if (actions[i] == ActionType.mint4626Referral) {
(
IERC20 token,
IERC4626 savingsRate,
uint256 shares,
address to,
uint256 maxAmountIn,
address referrer
) = abi.decode(data[i], (IERC20, IERC4626, uint256, address, uint256, address));
_changeAllowance(token, address(savingsRate), type(uint256).max);
_mint4626Referral(savingsRate, shares, to, maxAmountIn, referrer);
} else if (actions[i] == ActionType.deposit4626Referral) {
(
IERC20 token,
IERC4626 savingsRate,
uint256 amount,
address to,
uint256 minSharesOut,
address referrer
) = abi.decode(data[i], (IERC20, IERC4626, uint256, address, uint256, address));
_changeAllowance(token, address(savingsRate), type(uint256).max);
_deposit4626Referral(savingsRate, amount, to, minSharesOut, referrer);
} else if (actions[i] == ActionType.redeem4626) {
(IERC4626 savingsRate, uint256 shares, address to, uint256 minAmountOut) = abi.decode(
data[i],
Expand All @@ -272,6 +304,19 @@ abstract contract BaseRouter is Initializable {
}
}

function deposit4626WithReferral(
IERC20 token,
IERC4626 savings,
uint256 amount,
address to,
uint256 minSharesOut,
address referrer
) external {
token.safeTransferFrom(msg.sender, address(this), amount);
_changeAllowance(token, address(savings), type(uint256).max);
_deposit4626Referral(savings, amount, to, minSharesOut, referrer);
}

/// @notice Wrapper built on top of the base `mixer` function to grant approval to a `VaultManager` contract before performing
/// actions and then revoking this approval after these actions
/// @param paramsPermitVaultManager Parameters to sign permit to give allowance to the router for a `VaultManager` contract
Expand Down Expand Up @@ -488,6 +533,30 @@ abstract contract BaseRouter is Initializable {
_slippageCheck(sharesOut = savingsRate.deposit(amount, to), minSharesOut);
}

/// @notice Same as _deposit4626 but with the ability to specify a referring address
function _mint4626Referral(
IERC4626 savingsRate,
uint256 shares,
address to,
uint256 maxAmountIn,
address referrer
) internal returns (uint256 amountIn) {
amountIn = _mint4626(savingsRate, shares, to, maxAmountIn);
emit ReferredDeposit(msg.sender, to, amountIn, shares, referrer);
}

/// @notice Same as _deposit4626 but with the ability to specify a referring address
function _deposit4626Referral(
IERC4626 savingsRate,
uint256 amount,
address to,
uint256 minSharesOut,
address referrer
) internal returns (uint256 sharesOut) {
sharesOut = _deposit4626(savingsRate, amount, to, minSharesOut);
emit ReferredDeposit(msg.sender, to, amount, sharesOut, referrer);
}

/// @notice Withdraws `amount` from an ERC4626 contract
/// @param savingsRate ERC4626 to withdraw assets from
/// @param amount Amount of assets to withdraw
Expand Down

0 comments on commit 717d233

Please sign in to comment.