Created
July 2, 2024 11:49
-
-
Save Jonsey/04717dbabc94e7c7d29d1ab36148d956 to your computer and use it in GitHub Desktop.
GetVaultFees With DIsabled Token Reverts with ErrorLibrary.TokenNotEnabled()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // SPDX-License-Identifier: BUSL-1.1 | |
| pragma solidity 0.8.17; | |
| import { IPortfolio } from "../../contracts/core/interfaces/IPortfolio.sol"; | |
| import { IPortfolioFactory } from "../../contracts/front-end-helpers/IPortfolioFactory.sol"; | |
| import { IAllowanceTransfer } from "../../contracts/core/interfaces/IAllowanceTransfer.sol"; | |
| import { IRebalancing } from "../../contracts/rebalance/IRebalancing.sol"; | |
| import { Addresses } from "../foundry/utils/Addresses.sol"; | |
| import { PortfolioDeployment } from "./utils/PortfolioDeployment.s.sol"; | |
| import { FunctionParameters } from "../../contracts/FunctionParameters.sol"; | |
| import { ErrorLibrary } from "../../contracts/library/ErrorLibrary.sol"; | |
| import "./utils/AssetUtils.sol"; | |
| import { IPermit2 } from "./interfaces/IPermit2.sol"; | |
| import { PortfolioOperations } from "./helpers/PortfolioOperations.sol"; | |
| import { IProtocolConfig } from "../../contracts/config/protocol/IProtocolConfig.sol"; | |
| import { IPriceOracle } from "../../contracts/oracle/IPriceOracle.sol"; | |
| import "forge-std/console.sol"; | |
| contract GetVaultFeesWithDIsabledToken is | |
| PortfolioOperations, | |
| AssetUtils, | |
| Addresses | |
| { | |
| address tokenA; | |
| address tokenB; | |
| address tokenC; | |
| IRebalancing rebalance; | |
| PortfolioDeployment portfolioDeployment; | |
| function setUp() public { | |
| ownerPrivateKey = 0x12341234; | |
| owner = vm.addr(ownerPrivateKey); | |
| nonOwnerPrivateKey = 0x56785678; | |
| nonOwner = vm.addr(nonOwnerPrivateKey); | |
| tokenA = address(generateTestTokenByName("TokenA", 18)); | |
| tokenB = address(generateTestTokenByName("TokenB", 10)); | |
| tokenC = address(generateTestTokenByName("TokenC", 8)); | |
| portfolioDeployment = new PortfolioDeployment(); | |
| address[] memory _whitelistedTokens = new address[](2); | |
| _whitelistedTokens[0] = tokenA; | |
| _whitelistedTokens[1] = tokenB; | |
| address assetManagerTreasury = makeAddr("assetManagerTreasury"); | |
| ( | |
| address portfolioAddress, | |
| IPortfolioFactory.PortfoliolInfo memory portfolioSwapInfo | |
| ) = portfolioDeployment.createNewPortfolio( | |
| FunctionParameters.PortfolioCreationInitData({ | |
| _name: "INDEXLY", | |
| _symbol: "IDX", | |
| _managementFee: 1, | |
| _performanceFee: 2500, | |
| _entryFee: 0, | |
| _exitFee: 0, | |
| _initialPortfolioAmount: 10000000000000000, | |
| _minPortfolioTokenHoldingAmount: 10000000000000000, | |
| _assetManagerTreasury: assetManagerTreasury, | |
| _whitelistedTokens: _whitelistedTokens, | |
| _public: true, | |
| _transferable: true, | |
| _transferableToPublic: true, | |
| _whitelistTokens: false | |
| }) | |
| ); | |
| portfolio = IPortfolio(portfolioAddress); | |
| rebalance = IRebalancing(portfolioSwapInfo.rebalancing); | |
| permit2 = IPermit2(UNISWAP_PERMIT2); | |
| DOMAIN_SEPARATOR = permit2.DOMAIN_SEPARATOR(); | |
| } | |
| function initTestToken() public { | |
| address[] memory tokens = new address[](3); | |
| tokens[0] = tokenA; | |
| tokens[1] = tokenB; | |
| tokens[2] = tokenC; | |
| portfolio.initToken(tokens); | |
| uint256 portfolioTokenLength = portfolio.getTokens().length; | |
| totalAmountDepositedOwner = new uint256[](portfolioTokenLength); | |
| totalAmountDepositedNonOwner = new uint256[](portfolioTokenLength); | |
| } | |
| function testGetVaultValueInUSD() public { | |
| initTestToken(); | |
| address depositor = owner; | |
| uint256 privateKey = ownerPrivateKey; | |
| approveAllPortfolioToken(depositor); | |
| address[] memory portfolioTokens = portfolio.getTokens(); | |
| uint256[] memory depositAmounts = new uint256[](3); | |
| depositAmounts[0] = 8 * getAssetUnit(portfolioTokens[0]); | |
| depositAmounts[1] = 9 * getAssetUnit(portfolioTokens[1]); | |
| depositAmounts[2] = 10 * getAssetUnit(portfolioTokens[2]); | |
| _deposit(depositor, privateKey, depositAmounts, 0); | |
| uint256 totalSupply = portfolio.totalSupply(); | |
| IProtocolConfig protocolConfig = IProtocolConfig( | |
| portfolioDeployment.protocolConfig() | |
| ); | |
| // @audit reverts due to disabled token | |
| uint256 vaultBalance = portfolio.getVaultValueInUSD( | |
| IPriceOracle(protocolConfig.oracle()), | |
| portfolio.getTokens(), | |
| totalSupply, | |
| portfolio.vault() | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment