diff --git a/lib/v4-core b/lib/v4-core index bd6cce2..bf1e7d0 160000 --- a/lib/v4-core +++ b/lib/v4-core @@ -1 +1 @@ -Subproject commit bd6cce29aec544aeb015cb9ce595266712854782 +Subproject commit bf1e7d0681d3d8eaaaa8b291cb6835569fa0c924 diff --git a/src/TtcVault.sol b/src/TtcVault.sol index f23e93a..a89cc19 100644 --- a/src/TtcVault.sol +++ b/src/TtcVault.sol @@ -511,17 +511,11 @@ contract TtcVault is ITtcVault, ReentrancyGuard { // get a token/wETH pool's address - address pool = getPoolWithFee(tokenAddress, wEthAddress, UNISWAP_PRIMARY_POOL_FEE); - if (pool == address(0)) { - revert PoolDoesNotExist(); - } - - // convert to IUniswapV3PoolState to get access to sqrtPriceX96 - IUniswapV3PoolState _pool = IUniswapV3PoolState(pool); - - uint24[3] memory feeTiers = [UNISWAP_SECONDARY_POOL_FEE, UNISWAP_TERTIARY_POOL_FEE, UNISWAP_QUATERNARY_POOL_FEE]; + uint24[4] memory feeTiers = [UNISWAP_PRIMARY_POOL_FEE, UNISWAP_SECONDARY_POOL_FEE, UNISWAP_TERTIARY_POOL_FEE, UNISWAP_QUATERNARY_POOL_FEE]; + address pool; + IUniswapV3PoolState _pool; - for (uint8 i; i < 3; i++) { + for (uint8 i; i < 4; i++) { pool = getPoolWithFee(tokenAddress, wEthAddress, feeTiers[i]); if (pool == address(0)) { continue; diff --git a/test/TtcVaultTest.t.sol b/test/TtcVaultTest.t.sol index dab40e8..10f56a4 100644 --- a/test/TtcVaultTest.t.sol +++ b/test/TtcVaultTest.t.sol @@ -492,6 +492,57 @@ contract VaultTest is TtcTestContext { } } + function testDifferenceOfPricesPostMint() public { + uint96 weiAmount = 100 ether; + address user = makeAddr("user"); + vm.deal(user, weiAmount); + + address[10] memory allTokens = [ + RETH_ADDRESS, + SHIB_ADDRESS, + OKB_ADDRESS, + LINK_ADDRESS, + WBTC_ADDRESS, + UNI_ADDRESS, + MATIC_ADDRESS, + ARB_ADDRESS, + MANTLE_ADDRESS, + MKR_ADDRESS + ]; + + uint256[10] memory pricesBefore; + + for (uint8 i = 0; i < 9; i++) { + uint256 price = vault.getLatestPriceInEthOf(allTokens[i]); + pricesBefore[i] = price; + console.log("Price of ", ERC20(allTokens[i]).name(), " before mint: ", price); + } + + vm.startPrank(user); + vault.mint{value: weiAmount}(); + vm.stopPrank(); + + uint256 h = vm.getBlockNumber(); + vm.roll(h + 100); + + console.log(); + console.log("Block number: ", vm.getBlockNumber()); + console.log(); + + for (uint8 i = 0; i < 9; i++) { + uint256 price = vault.getLatestPriceInEthOf(allTokens[i]); + console.log("Price of ", ERC20(allTokens[i]).name(), " after mint: ", price); + } + + // get fractions + for (uint8 i = 0; i < 9; i++) { + uint256 priceBefore = pricesBefore[i] * 100000000; + uint256 priceAfter = vault.getLatestPriceInEthOf(allTokens[i]); + uint256 diff = priceBefore / priceAfter; + console.log("Fraction ", ERC20(allTokens[i]).name(), ": ", diff); + } + } + // Returns the amount of tokens that is x% of the balance of the vault function xPercentFromBalance(uint8 percent, address tokenAddress) private