Skip to content

Commit

Permalink
Merge pull request #95 from GenerationSoftware/gen-1223-m-172-assets-…
Browse files Browse the repository at this point in the history
…without-decimals-can-cause-ux-issues

Revert when asset does not have decimals
  • Loading branch information
trmid committed Mar 22, 2024
2 parents c23db70 + 3556d22 commit f262082
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/PrizeVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,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 @@ -316,7 +320,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
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f262082

Please sign in to comment.