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-198] Add custom code for ComponentToken in supportsInterface #117

Merged
merged 6 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
43 changes: 43 additions & 0 deletions nest/script/helpers/CalculateAggregateTokenInterfaceId.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import { IAggregateToken } from "../../src/interfaces/IAggregateToken.sol";
import { Script } from "forge-std/Script.sol";
import { console2 } from "forge-std/console2.sol";

contract CalculateAggregateTokenInterfaceId is Script {

function run() public view {
bytes4 interfaceId = type(IAggregateToken).interfaceId;

// Log results
console2.log("\nIAggregateToken Interface ID Calculation Results:");
console2.log("----------------------------------------");
console2.log("Interface ID: ", vm.toString(interfaceId));

// Log individual function selectors
console2.log("\nFunction Selectors:");
console2.log("----------------------------------------");
// Admin Functions
console2.log("addComponentToken: ", vm.toString(IAggregateToken.addComponentToken.selector));
console2.log("approveComponentToken: ", vm.toString(IAggregateToken.approveComponentToken.selector));
console2.log("setAskPrice: ", vm.toString(IAggregateToken.setAskPrice.selector));
console2.log("setBidPrice: ", vm.toString(IAggregateToken.setBidPrice.selector));
console2.log("pause: ", vm.toString(IAggregateToken.pause.selector));
console2.log("unpause: ", vm.toString(IAggregateToken.unpause.selector));

// Trading Functions
console2.log("buyComponentToken: ", vm.toString(IAggregateToken.buyComponentToken.selector));
console2.log("sellComponentToken: ", vm.toString(IAggregateToken.sellComponentToken.selector));
console2.log("requestBuyComponentToken: ", vm.toString(IAggregateToken.requestBuyComponentToken.selector));
console2.log("requestSellComponentToken:", vm.toString(IAggregateToken.requestSellComponentToken.selector));

// View Functions
console2.log("getComponentTokenList: ", vm.toString(IAggregateToken.getComponentTokenList.selector));
console2.log("getComponentToken: ", vm.toString(IAggregateToken.getComponentToken.selector));
console2.log("getAskPrice: ", vm.toString(IAggregateToken.getAskPrice.selector));
console2.log("getBidPrice: ", vm.toString(IAggregateToken.getBidPrice.selector));
console2.log("isPaused: ", vm.toString(IAggregateToken.isPaused.selector));
}

}
37 changes: 37 additions & 0 deletions nest/script/helpers/CalculateBoringVaultAdapterInterfaceId.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import { IBoringVaultAdapter } from "../../src/interfaces/IBoringVaultAdapter.sol";
import { Script } from "forge-std/Script.sol";
import { console2 } from "forge-std/console2.sol";

contract CalculateBoringVaultAdapterInterfaceId is Script {

function run() public view {
bytes4 interfaceId = type(IBoringVaultAdapter).interfaceId;

// Log results
console2.log("\nIBoringVaultAdapter Interface ID Calculation Results:");
console2.log("----------------------------------------");
console2.log("Interface ID: ", vm.toString(interfaceId));

// Log individual function selectors for verification
console2.log("\nFunction Selectors:");
console2.log("----------------------------------------");
console2.log("getVault: ", vm.toString(IBoringVaultAdapter.getVault.selector));
console2.log("getTeller: ", vm.toString(IBoringVaultAdapter.getTeller.selector));
console2.log("getAtomicQueue: ", vm.toString(IBoringVaultAdapter.getAtomicQueue.selector));
console2.log("version: ", vm.toString(IBoringVaultAdapter.version.selector));
console2.log("deposit: ", vm.toString(IBoringVaultAdapter.deposit.selector));
console2.log("requestRedeem: ", vm.toString(IBoringVaultAdapter.requestRedeem.selector));
console2.log("notifyRedeem: ", vm.toString(IBoringVaultAdapter.notifyRedeem.selector));
console2.log("redeem: ", vm.toString(IBoringVaultAdapter.redeem.selector));
console2.log("previewDeposit: ", vm.toString(IBoringVaultAdapter.previewDeposit.selector));
console2.log("previewRedeem: ", vm.toString(IBoringVaultAdapter.previewRedeem.selector));
console2.log("convertToShares: ", vm.toString(IBoringVaultAdapter.convertToShares.selector));
console2.log("convertToAssets: ", vm.toString(IBoringVaultAdapter.convertToAssets.selector));
console2.log("balanceOf: ", vm.toString(IBoringVaultAdapter.balanceOf.selector));
console2.log("assetsOf: ", vm.toString(IBoringVaultAdapter.assetsOf.selector));
}

}
36 changes: 36 additions & 0 deletions nest/script/helpers/CalculateComponentTokenInterfaceId.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import { IComponentToken } from "../../src/interfaces/IComponentToken.sol";
import { Script } from "forge-std/Script.sol";
import { console2 } from "forge-std/console2.sol";

contract CalculateComponentTokenInterfaceId is Script {

function run() public view {
bytes4 interfaceId = type(IComponentToken).interfaceId;

// Log results
console2.log("\nIComponentToken Interface ID Calculation Results:");
console2.log("----------------------------------------");
console2.log("Interface ID: ", vm.toString(interfaceId));

// Log individual function selectors
console2.log("\nFunction Selectors:");
console2.log("----------------------------------------");
console2.log("requestDeposit: ", vm.toString(IComponentToken.requestDeposit.selector));
console2.log("deposit: ", vm.toString(IComponentToken.deposit.selector));
console2.log("requestRedeem: ", vm.toString(IComponentToken.requestRedeem.selector));
console2.log("redeem: ", vm.toString(IComponentToken.redeem.selector));
console2.log("asset: ", vm.toString(IComponentToken.asset.selector));
console2.log("totalAssets: ", vm.toString(IComponentToken.totalAssets.selector));
console2.log("assetsOf: ", vm.toString(IComponentToken.assetsOf.selector));
console2.log("convertToShares: ", vm.toString(IComponentToken.convertToShares.selector));
console2.log("convertToAssets: ", vm.toString(IComponentToken.convertToAssets.selector));
console2.log("pendingDepositRequest: ", vm.toString(IComponentToken.pendingDepositRequest.selector));
console2.log("claimableDepositRequest: ", vm.toString(IComponentToken.claimableDepositRequest.selector));
console2.log("pendingRedeemRequest: ", vm.toString(IComponentToken.pendingRedeemRequest.selector));
console2.log("claimableRedeemRequest: ", vm.toString(IComponentToken.claimableRedeemRequest.selector));
}

}
2 changes: 1 addition & 1 deletion nest/src/AggregateToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ contract AggregateToken is ComponentToken, IAggregateToken, ERC1155Holder {
function supportsInterface(
bytes4 interfaceId
) public view virtual override(ComponentToken, ERC1155Holder) returns (bool) {
return super.supportsInterface(interfaceId);
return super.supportsInterface(interfaceId) || interfaceId == type(IAggregateToken).interfaceId;
}

}
4 changes: 2 additions & 2 deletions nest/src/ComponentToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ abstract contract ComponentToken is
ComponentTokenStorage storage $ = _getComponentTokenStorage();
return super.supportsInterface(interfaceId) || interfaceId == type(IERC20).interfaceId
|| interfaceId == type(IAccessControl).interfaceId || interfaceId == type(IERC7575).interfaceId
|| interfaceId == 0xe3bc4e65 || ($.asyncDeposit && interfaceId == 0xce3bbe50)
|| ($.asyncRedeem && interfaceId == 0x620ee8e4);
|| interfaceId == type(IComponentToken).interfaceId || interfaceId == 0xe3bc4e65
|| ($.asyncDeposit && interfaceId == 0xce3bbe50) || ($.asyncRedeem && interfaceId == 0x620ee8e4);
}

/// @inheritdoc IERC4626
Expand Down
116 changes: 116 additions & 0 deletions nest/src/interfaces/IAggregateToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,122 @@ import { IComponentToken } from "./IComponentToken.sol";

interface IAggregateToken is IComponentToken {

// ========== PUBLIC VIEW FUNCTIONS ==========

/**
* @notice Get the current ask price for buying the AggregateToken
* @return uint256 Current ask price
*/
function getAskPrice() external view returns (uint256);

/**
* @notice Get the current bid price for selling the AggregateToken
* @return uint256 Current bid price
*/
function getBidPrice() external view returns (uint256);

/**
* @notice Get the list of all component tokens ever added
* @return IComponentToken[] Array of component token addresses
*/
function getComponentTokenList() external view returns (IComponentToken[] memory);

/**
* @notice Check if an address is a registered component token
* @param componentToken ComponentToken to check
* @return bool indicating whether the address is a component token
*/
function getComponentToken(
IComponentToken componentToken
) external view returns (bool);

/**
* @notice Check if trading operations are paused
* @return bool indicating whether trading is paused
*/
function isPaused() external view returns (bool);

// ========== ADMIN FUNCTIONS ==========

/**
* @notice Add a new component token to the aggregate token
* @dev Only callable by ADMIN_ROLE
* @param componentToken Address of the component token to add
*/
function addComponentToken(
IComponentToken componentToken
) external;

/**
* @notice Approve a component token to spend aggregate token's assets
* @dev Only callable by ADMIN_ROLE
* @param componentToken Address of the component token to approve
* @param amount Amount of assets to approve
*/
function approveComponentToken(IComponentToken componentToken, uint256 amount) external;

/**
* @notice Buy component tokens using the aggregate token's assets
* @dev Only callable by ADMIN_ROLE
* @param componentToken Address of the component token to buy
* @param assets Amount of assets to spend
*/
function buyComponentToken(IComponentToken componentToken, uint256 assets) external;

/**
* @notice Sell component tokens to receive aggregate token's assets
* @dev Only callable by ADMIN_ROLE
* @param componentToken Address of the component token to sell
* @param componentTokenAmount Amount of component tokens to sell
*/
function sellComponentToken(IComponentToken componentToken, uint256 componentTokenAmount) external;

/**
* @notice Request to buy component tokens (for async operations)
* @dev Only callable by ADMIN_ROLE
* @param componentToken Address of the component token to buy
* @param assets Amount of assets to spend
*/
function requestBuyComponentToken(IComponentToken componentToken, uint256 assets) external;

/**
* @notice Request to sell component tokens (for async operations)
* @dev Only callable by ADMIN_ROLE
* @param componentToken Address of the component token to sell
* @param componentTokenAmount Amount of component tokens to sell
*/
function requestSellComponentToken(IComponentToken componentToken, uint256 componentTokenAmount) external;

/**
* @notice Set the ask price for the aggregate token
* @dev Only callable by PRICE_UPDATER_ROLE
* @param newAskPrice New ask price to set
*/
function setAskPrice(
uint256 newAskPrice
) external;

/**
* @notice Set the bid price for the aggregate token
* @dev Only callable by PRICE_UPDATER_ROLE
* @param newBidPrice New bid price to set
*/
function setBidPrice(
uint256 newBidPrice
) external;

/**
* @notice Pause all trading operations
* @dev Only callable by ADMIN_ROLE
*/
function pause() external;

/**
* @notice Unpause all trading operations
* @dev Only callable by ADMIN_ROLE
*/
function unpause() external;

// Events

/**
Expand Down
60 changes: 60 additions & 0 deletions nest/src/interfaces/IBoringVaultAdapter.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.25;

import { IERC20 } from "@openzeppelin/contracts/interfaces/IERC20.sol";

interface IBoringVaultAdapter {

// View Functions
function getVault() external view returns (address);
function getTeller() external view returns (address);
function getAtomicQueue() external view returns (address);
function version() external view returns (uint256);

// Core Functions
function deposit(
uint256 assets,
address receiver,
address controller,
uint256 minimumMint
) external returns (uint256 shares);

function requestRedeem(
uint256 shares,
address receiver,
address controller,
uint256 price,
uint64 deadline
) external returns (uint256);

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

function redeem(uint256 shares, address receiver, address controller) external returns (uint256 assets);

// Preview Functions
function previewDeposit(
uint256 assets
) external view returns (uint256);
function previewRedeem(
uint256 shares
) external view returns (uint256 assets);
function convertToShares(
uint256 assets
) external view returns (uint256 shares);
function convertToAssets(
uint256 shares
) external view returns (uint256 assets);

// Balance Functions
function balanceOf(
address account
) external view returns (uint256);
function assetsOf(
address account
) external view returns (uint256);

// Events
event VaultChanged(address oldVault, address newVault);
event Reinitialized(uint256 version);

}
3 changes: 2 additions & 1 deletion nest/src/token/BoringVaultAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { FixedPointMathLib } from "@solmate/utils/FixedPointMathLib.sol";
import { IAccountantWithRateProviders } from "../interfaces/IAccountantWithRateProviders.sol";
import { IAtomicQueue } from "../interfaces/IAtomicQueue.sol";
import { IBoringVault } from "../interfaces/IBoringVault.sol";
import { IBoringVaultAdapter } from "../interfaces/IBoringVaultAdapter.sol";
import { IComponentToken } from "../interfaces/IComponentToken.sol";
import { ILens } from "../interfaces/ILens.sol";
import { ITeller } from "../interfaces/ITeller.sol";
Expand Down Expand Up @@ -487,7 +488,7 @@ abstract contract BoringVaultAdapter is
function supportsInterface(
bytes4 interfaceId
) public view virtual override(ComponentToken, AccessControlUpgradeable) returns (bool) {
return super.supportsInterface(interfaceId);
return super.supportsInterface(interfaceId) || interfaceId == type(IBoringVaultAdapter).interfaceId;
}

}
Loading