Skip to content

Commit

Permalink
update interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
eyqs committed Sep 26, 2024
1 parent 7a208ee commit a29143b
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 30 deletions.
21 changes: 21 additions & 0 deletions nest/src/interfaces/IAggregateToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,29 @@ import { IComponentToken } from "./IComponentToken.sol";

interface IAggregateToken is IComponentToken {

/**
* @notice Buy ComponentToken using CurrencyToken
* @dev Only the owner can call this function, will revert if
* the AggregateToken does not have enough CurrencyToken to buy the ComponentToken
* @param componentToken ComponentToken to buy
* @param currencyTokenAmount Amount of CurrencyToken to pay to receive the ComponentToken
*/
function buyComponentToken(IComponentToken componentToken, uint256 currencyTokenAmount) external;

/**
* @notice Sell ComponentToken to receive CurrencyToken
* @dev Only the owner can call this function, will revert if
* the ComponentToken does not have enough CurrencyToken to sell to the AggregateToken
* @param componentToken ComponentToken to sell
* @param currencyTokenAmount Amount of CurrencyToken to receive in exchange for the ComponentToken
*/
function sellComponentToken(IComponentToken componentToken, uint256 currencyTokenAmount) external;

/**
* @notice Claim yield for all ComponentTokens into the AggregateToken
* @dev Anyone can call this function to claim yield for all ComponentTokens
*/
function claimComponentsYield() external returns (uint256 amount);
function requestYield(address from) external;

}
73 changes: 64 additions & 9 deletions nest/src/interfaces/IComponentToken.sol
Original file line number Diff line number Diff line change
@@ -1,21 +1,76 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import { IComponentToken } from "./IComponentToken.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IComponentToken is IERC20 {
interface IYieldDistributionToken is IERC20 {
/// @notice CurrencyToken in which yield is denominated and distributed
function getCurrencyToken() external returns (IERC20 currencyToken);

/**
* @notice Claim yield for the given user
* @dev Anyone can call this function to claim yield for any user
* @param user Address of the user for which to claim yield
* @return currencyToken CurrencyToken in which yield is denominated and distributed
* @return currencyTokenAmount Amount of yield claimed by the user
*/
function claimYield(address user) external returns (IERC20 currencyToken, uint256 currencyTokenAmount);

function accrueYield(address user) external;
function requestYield(address from) external;
}

interface IComponentToken is IYieldDistributionToken {

/**
* @notice Buy FakeComponentToken using CurrencyToken
* @dev The user must approve the contract to spend the CurrencyToken
* @param currencyToken CurrencyToken used to buy the FakeComponentToken
* @param currencyTokenAmount Amount of CurrencyToken to pay to receive the same amount of FakeComponentToken
* @return componentTokenAmount Amount of FakeComponentToken received
*/
function buy(IERC20 currencyToken, uint256 currencyTokenAmount) external returns (uint256 componentTokenAmount);

/**
* @notice Sell FakeComponentToken to receive CurrencyToken
* @param currencyToken CurrencyToken received in exchange for the FakeComponentToken
* @param currencyTokenAmount Amount of CurrencyToken to receive in exchange for the FakeComponentToken
* @return componentTokenAmount Amount of FakeComponentToken sold
*/
function sell(IERC20 currencyToken, uint256 currencyTokenAmount) external returns (uint256 componentTokenAmount);
function claimYield(address user) external returns (uint256 amount);

/// @notice Version of the FakeComponentToken
function getVersion() external view returns (uint256 version);
function getCurrencyToken() external view returns (IERC20 currencyToken);
function totalYield() external view returns (uint256 amount);
function claimedYield() external view returns (uint256 amount);
function unclaimedYield() external view returns (uint256 amount);
function totalYield(address user) external view returns (uint256 amount);
function claimedYield(address user) external view returns (uint256 amount);
function unclaimedYield(address user) external view returns (uint256 amount);

/// @notice Total yield distributed to all FakeComponentTokens for all users
function totalYield() external view returns (uint256 currencyTokenAmount);

/// @notice Claimed yield across all FakeComponentTokens for all users
function claimedYield() external view returns (uint256 currencyTokenAmount);

/// @notice Unclaimed yield across all FakeComponentTokens for all users
function unclaimedYield() external view returns (uint256 currencyTokenAmount);

/**
* @notice Total yield distributed to a specific user
* @param user Address of the user for which to get the total yield
* @return currencyTokenAmount Total yield distributed to the user
*/
function totalYield(address user) external view returns (uint256 currencyTokenAmount);

/**
* @notice Amount of yield that a specific user has claimed
* @param user Address of the user for which to get the claimed yield
* @return currencyTokenAmount Amount of yield that the user has claimed
*/
function claimedYield(address user) external view returns (uint256 currencyTokenAmount);

/**
* @notice Amount of yield that a specific user has not yet claimed
* @param user Address of the user for which to get the unclaimed yield
* @return currencyTokenAmount Amount of yield that the user has not yet claimed
*/
function unclaimedYield(address user) external view returns (uint256 currencyTokenAmount);

}
20 changes: 9 additions & 11 deletions smart-wallets/src/token/AssetToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken {
super._update(from, to, value);
}

/**
* @notice Make the SmartWallet redistribute yield from this token
* @param from Address of the SmartWallet to request the yield from
*/
function requestYield(address from) external override(YieldDistributionToken, IYieldDistributionToken) {
// Have to override both until updated in https://github.com/ethereum/solidity/issues/12665
ISmartWallet(payable(from)).claimAndRedistributeYield(this);
}

// Admin Functions

/**
Expand Down Expand Up @@ -241,17 +250,6 @@ contract AssetToken is WalletUtils, YieldDistributionToken, IAssetToken {
_depositYield(timestamp, currencyTokenAmount);
}

// Permissionless Functions

/**
* @notice Make the SmartWallet redistribute yield from this token
* @param from Address of the SmartWallet to request the yield from
*/
function requestYield(address from) external override(YieldDistributionToken, IYieldDistributionToken) {
// Have to override both until updated in https://github.com/ethereum/solidity/issues/12665
ISmartWallet(payable(from)).claimAndRedistributeYield(this);
}

// Getter View Functions

/// @notice Total value of all circulating AssetTokens
Expand Down
2 changes: 1 addition & 1 deletion smart-wallets/src/token/YieldDistributionToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ abstract contract YieldDistributionToken is ERC20, Ownable, IYieldDistributionTo
// Virtual Functions

/// @notice Request to receive yield from the given SmartWallet
function requestYield(address from) external virtual override(IYieldDistributionToken);
function requestYield(address from) external virtual;

// Override Functions

Expand Down
18 changes: 9 additions & 9 deletions smart-wallets/src/token/YieldToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ contract YieldToken is YieldDistributionToken, IYieldToken {
_mint(user, yieldTokenAmount);
}

/**
* @notice Make the SmartWallet redistribute yield from their AssetToken into this YieldToken
* @param from Address of the SmartWallet to request the yield from
*/
function requestYield(address from) external override(YieldDistributionToken, IYieldDistributionToken) {
// Have to override both until updated in https://github.com/ethereum/solidity/issues/12665
ISmartWallet(payable(from)).claimAndRedistributeYield(_getYieldTokenStorage().assetToken);
}

/**
* @notice Receive yield into the YieldToken
* @dev Anyone can call this function to deposit yield from their AssetToken into the YieldToken
Expand All @@ -113,13 +122,4 @@ contract YieldToken is YieldDistributionToken, IYieldToken {
_depositYield(block.timestamp, currencyTokenAmount);
}

/**
* @notice Make the SmartWallet redistribute yield from their AssetToken into this YieldToken
* @param from Address of the SmartWallet to request the yield from
*/
function requestYield(address from) external override(YieldDistributionToken, IYieldDistributionToken) {
// Have to override both until updated in https://github.com/ethereum/solidity/issues/12665
ISmartWallet(payable(from)).claimAndRedistributeYield(_getYieldTokenStorage().assetToken);
}

}

0 comments on commit a29143b

Please sign in to comment.