Skip to content

Commit

Permalink
update decimals and added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Robsonsjre committed Aug 9, 2021
1 parent e8f4487 commit f1b6984
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
11 changes: 9 additions & 2 deletions contracts/amm/FeePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ contract FeePool is IFeePool, Ownable {
uint8 private _feeDecimals;
address private immutable _token;
uint256 private constant _DYNAMIC_FEE_ALPHA = 2000;
uint256 private constant _MAX_FEE_DECIMALS = 38;

event FeeUpdated(address token, uint256 newBaseFee, uint8 newFeeDecimals);
event FeeWithdrawn(address token, address to, uint256 amountWithdrawn, uint256 sharesBurned);
Expand All @@ -38,7 +39,10 @@ contract FeePool is IFeePool, Ownable {
uint8 feeDecimals
) public {
require(token != address(0), "FeePool: Invalid token");
require(feeDecimals <= 77 && feeBaseValue <= uint256(10)**feeDecimals, "FeePool: Invalid Fee data");
require(
feeDecimals <= _MAX_FEE_DECIMALS && feeBaseValue <= uint256(10)**feeDecimals,
"FeePool: Invalid Fee data"
);

_token = token;
_feeBaseValue = feeBaseValue;
Expand All @@ -52,7 +56,10 @@ contract FeePool is IFeePool, Ownable {
* @param feeDecimals Fee decimals
*/
function setFee(uint256 feeBaseValue, uint8 feeDecimals) external override onlyOwner {
require(feeDecimals <= 77 && feeBaseValue <= uint256(10)**feeDecimals, "FeePool: Invalid Fee data");
require(
feeDecimals <= _MAX_FEE_DECIMALS && feeBaseValue <= uint256(10)**feeDecimals,
"FeePool: Invalid Fee data"
);
_feeBaseValue = feeBaseValue;
_feeDecimals = feeDecimals;
emit FeeUpdated(_token, _feeBaseValue, _feeDecimals);
Expand Down
4 changes: 3 additions & 1 deletion contracts/lib/RequiredDecimals.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ pragma solidity 0.6.12;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

contract RequiredDecimals {
uint256 private constant _MAX_TOKEN_DECIMALS = 38;

/**
* Tries to fetch the decimals of a token, if not existent, fails with a require statement
*
Expand All @@ -19,7 +21,7 @@ contract RequiredDecimals {

require(success, "RequiredDecimals: required decimals");
uint8 decimals = abi.decode(returnData, (uint8));
require(decimals < 38, "RequiredDecimals: token decimals should be lower than 38");
require(decimals < _MAX_TOKEN_DECIMALS, "RequiredDecimals: token decimals should be lower than 38");

return decimals;
}
Expand Down
11 changes: 11 additions & 0 deletions test/amm/FeePool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ describe('FeePool', () => {
await expect(tx).to.be.revertedWith('FeePool: Invalid Fee data')
})

it('cannot crete a FeePool with feeDecimals more than 38', async () => {
const decimals = await usdc.decimals()
const tx = FeePool.connect(poolOwner).deploy(usdc.address, 10 ** decimals + 1, 39)
await expect(tx).to.be.revertedWith('FeePool: Invalid Fee data')
})

it('cannot create a pool with a zero-address token', async () => {
const tx = FeePool.connect(poolOwner).deploy(ethers.constants.AddressZero, baseFee, initialDecimals)
await expect(tx).to.be.revertedWith('FeePool: Invalid token')
Expand Down Expand Up @@ -70,6 +76,11 @@ describe('FeePool', () => {
const tx = pool.setFee(10 ** decimals + 1, decimals)
await expect(tx).to.be.revertedWith('FeePool: Invalid Fee data')
})

it('cannot accept feeDecimals bigger than 38', async () => {
const tx = pool.setFee(toBigNumber(10).pow(39) + 1, 39)
await expect(tx).to.be.revertedWith('FeePool: Invalid Fee data')
})
})

describe('Fee collection', () => {
Expand Down

0 comments on commit f1b6984

Please sign in to comment.