Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PDE-401] Yieldtoken and tests #135

Merged
merged 6 commits into from
Dec 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading