Skip to content

Commit

Permalink
[PDE-401] Yieldtoken and tests (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
ungaro authored Dec 23, 2024
1 parent 9be7723 commit 4279b90
Show file tree
Hide file tree
Showing 4 changed files with 493 additions and 29 deletions.
6 changes: 6 additions & 0 deletions smart-wallets/src/mocks/MockInvalidSmartWallet.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

contract MockInvalidSmartWallet {
// Empty contract that will fail when called
}
30 changes: 30 additions & 0 deletions smart-wallets/src/mocks/MockYieldToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import { IAssetToken } from "../interfaces/IAssetToken.sol";
import { YieldToken } from "../token/YieldToken.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract MockYieldToken is YieldToken {

constructor(
address owner,
string memory name,
string memory symbol,
IERC20 currencyToken,
uint8 decimals_,
string memory tokenURI_,
IAssetToken assetToken,
uint256 initialSupply
) YieldToken(owner, name, symbol, currencyToken, decimals_, tokenURI_, assetToken, initialSupply) { }

// Expose internal functions for testing
function notifyDeposit(uint256 assets, uint256 shares, address controller) external {
_notifyDeposit(assets, shares, controller);
}

function notifyRedeem(uint256 assets, uint256 shares, address controller) external {
_notifyRedeem(assets, shares, controller);
}

}
28 changes: 26 additions & 2 deletions smart-wallets/src/token/YieldToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ contract YieldToken is YieldDistributionToken, ERC4626, WalletUtils, IYieldToken

/// @notice All ComponentToken requests are fungible and all have ID = 0
uint256 private constant REQUEST_ID = 0;
/// @notice Base that is used to divide all price inputs in order to represent e.g. 1.000001 as 1000001e12
uint256 private constant _BASE = 1e18;

// Events

Expand Down Expand Up @@ -85,6 +83,10 @@ contract YieldToken is YieldDistributionToken, ERC4626, WalletUtils, IYieldToken
/// @notice Indicates a failure because the given amount is 0
error ZeroAmount();

/// @notice Indicates a failure because the given address is 0
/// @param what Description of which address was zero
error ZeroAddress(string what);

/**
* @notice Indicates a failure because the sender is not authorized to perform the action
* @param sender Address of the sender that is not authorized
Expand Down Expand Up @@ -151,6 +153,16 @@ contract YieldToken is YieldDistributionToken, ERC4626, WalletUtils, IYieldToken
IAssetToken assetToken,
uint256 initialSupply
) YieldDistributionToken(owner, name, symbol, currencyToken, decimals_, tokenURI_) ERC4626(currencyToken) {
if (owner == address(0)) {
revert ZeroAddress("owner");
}
if (address(currencyToken) == address(0)) {
revert ZeroAddress("currency token");
}
if (address(assetToken) == address(0)) {
revert ZeroAddress("asset token");
}

if (currencyToken != assetToken.getCurrencyToken()) {
revert InvalidCurrencyToken(currencyToken, assetToken.getCurrencyToken());
}
Expand Down Expand Up @@ -310,6 +322,9 @@ contract YieldToken is YieldDistributionToken, ERC4626, WalletUtils, IYieldToken
if (assets == 0) {
revert ZeroAmount();
}
if (receiver == address(0)) {
revert ZeroAddress("receiver");
}
if (msg.sender != controller) {
revert Unauthorized(msg.sender, controller);
}
Expand Down Expand Up @@ -337,6 +352,9 @@ contract YieldToken is YieldDistributionToken, ERC4626, WalletUtils, IYieldToken
if (shares == 0) {
revert ZeroAmount();
}
if (receiver == address(0)) {
revert ZeroAddress("receiver");
}
if (msg.sender != controller) {
revert Unauthorized(msg.sender, controller);
}
Expand Down Expand Up @@ -405,6 +423,9 @@ contract YieldToken is YieldDistributionToken, ERC4626, WalletUtils, IYieldToken
if (shares == 0) {
revert ZeroAmount();
}
if (receiver == address(0)) {
revert ZeroAddress("receiver");
}
if (msg.sender != controller) {
revert Unauthorized(msg.sender, controller);
}
Expand Down Expand Up @@ -433,6 +454,9 @@ contract YieldToken is YieldDistributionToken, ERC4626, WalletUtils, IYieldToken
if (assets == 0) {
revert ZeroAmount();
}
if (receiver == address(0)) {
revert ZeroAddress("receiver");
}
if (msg.sender != controller) {
revert Unauthorized(msg.sender, controller);
}
Expand Down
Loading

0 comments on commit 4279b90

Please sign in to comment.