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

Revert when asset does not have decimals #95

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/PrizeVault.sol
Expand Up @@ -259,6 +259,10 @@ contract PrizeVault is TwabERC20, Claimable, IERC4626, ILiquidationSource, Ownab
/// @param minAssets The min asset threshold requested
error MinAssetsNotReached(uint256 assets, uint256 minAssets);

/// @notice Thrown when the underlying asset does not specify it's number of decimals.
/// @param asset The underlying asset that was checked
error FailedToGetAssetDecimals(address asset);

////////////////////////////////////////////////////////////////////////////////
// Modifiers
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -309,7 +313,11 @@ contract PrizeVault is TwabERC20, Claimable, IERC4626, ILiquidationSource, Ownab

IERC20 asset_ = IERC20(yieldVault_.asset());
(bool success, uint8 assetDecimals) = _tryGetAssetDecimals(asset_);
_underlyingDecimals = success ? assetDecimals : 18;
if (success) {
_underlyingDecimals = assetDecimals;
} else {
revert FailedToGetAssetDecimals(address(asset_));
}
_asset = asset_;

yieldVault = yieldVault_;
Expand Down
23 changes: 22 additions & 1 deletion test/unit/PrizeVault/PrizeVault.t.sol
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

import { UnitBaseSetup, PrizePool, TwabController, ERC20, IERC20, IERC4626 } from "./UnitBaseSetup.t.sol";
import { UnitBaseSetup, PrizePool, TwabController, ERC20, IERC20, IERC4626, YieldVault } from "./UnitBaseSetup.t.sol";
import { IVaultHooks, VaultHooks } from "../../../src/interfaces/IVaultHooks.sol";
import { ERC20BrokenDecimalMock } from "../../contracts/mock/ERC20BrokenDecimalMock.sol";

Expand Down Expand Up @@ -180,6 +180,27 @@ contract PrizeVaultTest is UnitBaseSetup {
assertEq(decimals, 0);
}

function testConstructorFailsWhenDecimalFails() public {
IERC20 brokenDecimalToken = new ERC20BrokenDecimalMock();
YieldVault brokenDecimalYieldVault = new YieldVault(
address(brokenDecimalToken),
"Test Yield Vault",
"yvTest"
);
vm.expectRevert(abi.encodeWithSelector(PrizeVault.FailedToGetAssetDecimals.selector, address(brokenDecimalToken)));
new PrizeVault(
"PoolTogether Decimal Fail",
"pDecFail",
brokenDecimalYieldVault,
PrizePool(address(prizePool)),
address(this),
address(this),
YIELD_FEE_PERCENTAGE,
1e6,
address(this)
);
}

/* ============ maxDeposit / maxMint ============ */

function testMaxDeposit_SubtractsLatentBalance() public {
Expand Down