Skip to content

Commit 5804609

Browse files
committed
implement collateral deposit/redemption accounting in ZToken
1 parent 2367365 commit 5804609

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/ZToken.sol

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,25 @@ abstract contract ZToken is IZToken, ERC20 {
148148
function _depositCollateral(uint256 _underlyingAmount) internal {
149149
if (_underlyingAmount == 0) revert ZeroAmountIsNotAllowed();
150150

151-
//
151+
_transferIn(_underlyingAmount);
152+
153+
uint256 newCollateralBalance = collateralAmount[msg.sender] + _underlyingAmount;
154+
collateralAmount[msg.sender] = newCollateralBalance;
152155

153-
emit CollateralDeposited(msg.sender, _underlyingAmount, _underlyingAmount);
156+
emit CollateralDeposited(msg.sender, _underlyingAmount, newCollateralBalance);
154157
}
155158

156159
function _redeemForCollateral(uint256 _zAmount) internal {
157160
if (_zAmount == 0) revert ZeroAmountIsNotAllowed();
161+
162+
uint256 underlyingAmount = _zAmount.mulWad(getExchangeRate());
163+
164+
_burn(msg.sender, _zAmount);
165+
166+
uint256 newCollateralBalance = collateralAmount[msg.sender] + underlyingAmount;
167+
collateralAmount[msg.sender] = newCollateralBalance;
168+
169+
emit CollateralRedeemed(msg.sender, _zAmount, underlyingAmount, newCollateralBalance);
158170
}
159171

160172
function _transferIn(uint256 _amount) internal virtual { }

0 commit comments

Comments
 (0)