Created
June 30, 2024 17:20
-
-
Save Jonsey/96cc9d42847ac5edfc7823eb6ecfa1a6 to your computer and use it in GitHub Desktop.
POC Proving slippage is checked before fees are applied
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 "forge-std/console.sol"; | |
| contract PortfolioFactory is PortfolioOperations, AssetUtils, Addresses { | |
| address tokenA; | |
| address tokenB; | |
| address tokenC; | |
| IRebalancing rebalance; | |
| 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 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: 500, | |
| _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 testMultiTokenDeposit() 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); | |
| } | |
| function testMultiTokenDepositForNonOwnerSlippage() public { | |
| testMultiTokenDeposit(); | |
| address depositor = owner; | |
| address depositFor = nonOwner; | |
| approveAllPortfolioToken(depositor); | |
| address[] memory portfolioTokens = portfolio.getTokens(); | |
| uint256[] memory depositAmounts = new uint256[](3); | |
| depositAmounts[0] = 16 * getAssetUnit(portfolioTokens[0]); | |
| depositAmounts[1] = 18 * getAssetUnit(portfolioTokens[1]); | |
| depositAmounts[2] = 20 * getAssetUnit(portfolioTokens[2]); | |
| _depositFor(depositor, depositFor, depositAmounts, 19999999999999999); @audit this is the value minted with Zero entry fee | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment