Skip to content

Commit

Permalink
Merge branch 'main' into feat/wbeth-market
Browse files Browse the repository at this point in the history
  • Loading branch information
jr-alpaca authored Oct 11, 2023
2 parents a1d6866 + e4a0040 commit 5d98f61
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
19 changes: 19 additions & 0 deletions solidity/contracts/account-manager/MoneyMarketAccountManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,25 @@ contract MoneyMarketAccountManager is IMoneyMarketAccountManager, OwnableUpgrade
miniFL.deposit(msg.sender, moneyMarket.getMiniFLPoolIdOfToken(_ibToken), _amountReceived);
}

/// @notice Stake ibToken in miniFL on behalf of _account
/// @param _account Account to stake for.
/// @param _ibToken IbToken associate with miniFL pool.
/// @param _amount Amount to stake.
function stakeFor(
address _account,
address _ibToken,
uint256 _amount
) external {
// transfer _ibToken to accountManager
IERC20(_ibToken).safeTransferFrom(msg.sender, address(this), _amount);

// approve allowance for miniFL
IERC20(_ibToken).safeApprove(address(miniFL), _amount);

// stake _ibToken at miniFL on bahalf of the _account
miniFL.deposit(_account, moneyMarket.getMiniFLPoolIdOfToken(_ibToken), _amount);
}

/// @notice Unstake ibToken from miniFL and withdraw as native token from MoneyMarket
/// @param _ibTokenAmount The amount to withdraw
function unstakeAndWithdrawETH(uint256 _ibTokenAmount) external {
Expand Down
6 changes: 6 additions & 0 deletions solidity/contracts/interfaces/IMoneyMarketAccountManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ interface IMoneyMarketAccountManager {

function depositETHAndStake() external payable;

function stakeFor(
address _account,
address _ibToken,
uint256 _amount
) external;

function unstakeAndWithdrawETH(uint256 _amount) external;

function unstakeAndWithdraw(address _ibToken, uint256 _amount) external;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;

import { MoneyMarket_BaseTest } from "../MoneyMarket_BaseTest.t.sol";
import { MoneyMarket_BaseTest, ILendFacet } from "../MoneyMarket_BaseTest.t.sol";

// interfaces
import { IERC20 } from "../../../contracts/money-market/interfaces/IERC20.sol";
import { FixedInterestRateModel, IInterestRateModel } from "../../../contracts/money-market/interest-models/FixedInterestRateModel.sol";
import { IMoneyMarket } from "solidity/contracts/money-market/interfaces/IMoneyMarket.sol";

contract MoneyMarket_AccountManagerTest is MoneyMarket_BaseTest {
function setUp() public override {
Expand Down Expand Up @@ -61,4 +62,28 @@ contract MoneyMarket_AccountManagerTest is MoneyMarket_BaseTest {

assertEq(weth.balanceOf(ALICE), _nativeTokenBalance);
}

function testCorrectness_StakeFor_ShouldWork() external {
address vault = makeAddr("Vault");

uint256 depositAmount = 10 ether;
uint256 pid = IMoneyMarket(moneyMarketDiamond).getMiniFLPoolIdOfToken(address(ibWeth));

uint256 _stakeAmountBefore = miniFL.getUserAmountFundedBy(address(accountManager), ALICE, pid);

deal(address(weth), vault, depositAmount);
vm.startPrank(vault);
weth.approve(address(accountManager), depositAmount);
accountManager.deposit(address(weth), depositAmount);

uint256 ibReceived = ibWeth.balanceOf(vault);

ibWeth.approve(address(accountManager), ibReceived);
accountManager.stakeFor(ALICE, address(ibWeth), ibReceived);
vm.stopPrank();

uint256 _stakeAmountAfter = miniFL.getUserAmountFundedBy(address(accountManager), ALICE, pid);

assertEq(_stakeAmountAfter - _stakeAmountBefore, ibReceived);
}
}

0 comments on commit 5d98f61

Please sign in to comment.