From d3e318f3c45d744bfa2dbadfa1abe998fa49d4b5 Mon Sep 17 00:00:00 2001 From: Walid Date: Wed, 26 Jun 2024 21:29:56 -0700 Subject: [PATCH] adds decimals() override (#10) --- mainnet-contracts/src/PufToken.sol | 8 ++++++-- mainnet-contracts/test/unit/PufferL2Staking.t.sol | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mainnet-contracts/src/PufToken.sol b/mainnet-contracts/src/PufToken.sol index 99dffde..8e2de3f 100644 --- a/mainnet-contracts/src/PufToken.sol +++ b/mainnet-contracts/src/PufToken.sol @@ -29,7 +29,7 @@ contract PufToken is IPufStakingPool, ERC20, ERC20Permit { /** * @notice The underlying token decimals */ - uint256 internal immutable _TOKEN_DECIMALS; + uint8 internal immutable _TOKEN_DECIMALS; /** * @notice Puffer Token factory @@ -54,7 +54,7 @@ contract PufToken is IPufStakingPool, ERC20, ERC20Permit { // The Factory is the deployer of the contract PUFFER_FACTORY = PufferL2Depositor(msg.sender); TOKEN = ERC20(token); - _TOKEN_DECIMALS = uint256(TOKEN.decimals()); + _TOKEN_DECIMALS = TOKEN.decimals(); totalDepositCap = depositCap; } @@ -214,4 +214,8 @@ contract PufToken is IPufStakingPool, ERC20, ERC20Permit { IMigrator(migratorContract).migrate({ depositor: depositor, destination: destination, amount: amount }); } + + function decimals() public view override returns (uint8 _decimals) { + return _TOKEN_DECIMALS; + } } diff --git a/mainnet-contracts/test/unit/PufferL2Staking.t.sol b/mainnet-contracts/test/unit/PufferL2Staking.t.sol index c6aaf2c..77163ac 100644 --- a/mainnet-contracts/test/unit/PufferL2Staking.t.sol +++ b/mainnet-contracts/test/unit/PufferL2Staking.t.sol @@ -180,6 +180,7 @@ contract PufferL2Staking is UnitTestHelper { pufToken.withdraw(bob, amount); assertEq(sixDecimal.balanceOf(bob), amount, "bob got same amount"); + assertEq(sixDecimal.decimals(), 6, "decimals matches orginal token"); } // Deposit & withdraw 22 decimal token @@ -209,6 +210,7 @@ contract PufferL2Staking is UnitTestHelper { pufToken.withdraw(bob, amount); assertEq(twentyTwoDecimal.balanceOf(bob), amount, "bob got same amount"); + assertEq(twentyTwoDecimal.decimals(), 22, "decimals matches orginal token"); } // Good Permit signature signature