Skip to content
Draft

DNM #18

Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion lib/v4-core
14 changes: 4 additions & 10 deletions src/TtcVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
51 changes: 51 additions & 0 deletions test/TtcVaultTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down