Skip to content

Commit

Permalink
minor fix for the voting power exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
thurendous committed Sep 30, 2024
1 parent 52eaa1f commit 6fab322
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/VotingPowerExchange.sol
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ contract VotingPowerExchange is AccessControl, EIP712 {
uint256 private constant PRECISION_FIX = 1e9;
uint256 private constant PRECISION_FACTOR = 10;
uint256 private constant PRECISION = 1e18;
uint256 private constant ALLOWED_EXCHANGING_MINIMUM_AMOUNT = 1e18;

// token instances
IGovToken private immutable govToken;
Expand Down Expand Up @@ -99,7 +100,7 @@ contract VotingPowerExchange is AccessControl, EIP712 {
onlyRole(EXCHANGER_ROLE)
{
if (sender == address(0)) revert VotingPowerExchange__AddressIsZero();
if (amount < 1e18) revert VotingPowerExchange__AmountIsTooSmall(); // not allow to exchange less than 1 utility token
if (amount < ALLOWED_EXCHANGING_MINIMUM_AMOUNT) revert VotingPowerExchange__AmountIsTooSmall(); // not allow to exchange less than 1 utility token
if (authorizationState(sender, nonce)) revert VotingPowerExchange__InvalidNonce();
if (block.timestamp > expiration) revert VotingPowerExchange__SignatureExpired();
// check the current gove token balance of the sender
Expand Down Expand Up @@ -254,12 +255,19 @@ contract VotingPowerExchange is AccessControl, EIP712 {
function getConstants()
external
pure
returns (bytes32 __EXCHANGE_TYPEHASH, uint256 _PRECISION_FIX, uint256 _PRECISION_FACTOR, uint256 _PRECISION)
returns (
bytes32 __EXCHANGE_TYPEHASH,
uint256 _PRECISION_FIX,
uint256 _PRECISION_FACTOR,
uint256 _PRECISION,
uint256 _ALLOWED_EXCHANGING_MINIMUM_AMOUNT
)
{
__EXCHANGE_TYPEHASH = _EXCHANGE_TYPEHASH;
_PRECISION_FIX = PRECISION_FIX;
_PRECISION_FACTOR = PRECISION_FACTOR;
_PRECISION = PRECISION;
_ALLOWED_EXCHANGING_MINIMUM_AMOUNT = ALLOWED_EXCHANGING_MINIMUM_AMOUNT;
}

/**
Expand Down
10 changes: 8 additions & 2 deletions test/integration/VotingPowerExchange.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -222,15 +222,21 @@ contract VotingPowerExchangeTest is Test {
}

function testConstantValues() public view {
(bytes32 __EXCHANGE_TYPEHASH, uint256 _PRICISION_FIX, uint256 _PRICISION_FACTOR, uint256 _PRICISION) =
votingPowerExchange.getConstants();
(
bytes32 __EXCHANGE_TYPEHASH,
uint256 _PRICISION_FIX,
uint256 _PRICISION_FACTOR,
uint256 _PRICISION,
uint256 _ALLOWED_EXCHANGING_MINIMUM_AMOUNT
) = votingPowerExchange.getConstants();

assertEq(
__EXCHANGE_TYPEHASH, keccak256("Exchange(address sender,uint256 amount,bytes32 nonce,uint256 expiration)")
);
assertEq(_PRICISION, 1e18);
assertEq(_PRICISION_FACTOR, 10);
assertEq(_PRICISION_FIX, 1e9);
assertEq(_ALLOWED_EXCHANGING_MINIMUM_AMOUNT, 1e18);
}

function testVotingPowerCap() public view {
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/ERC20UpgradeableTokenV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "src/ERC20UpgradeableTokenV1.sol";
contract ERC20UpgradeableTokenV2 is ERC20UpgradeableTokenV1 {
bytes32 public constant TREASURY_ROLE = keccak256("TREASURY_ROLE");

address private _treasury;
address private _treasury; // dummy state variable for testing

/// @dev Initializes the V2 version of the contract.
function initializeV2(address treasury, address newAdmin) public reinitializer(2) {
Expand Down
4 changes: 4 additions & 0 deletions test/onChain/testBaseSepolia.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ contract TestBaseSepolia is Test {
}

function testExchangeOnChain01() public {
if (block.chainid != 84532) {
console.log("Not on Base Sepolia");
return;
}
// Set up the state required for the test (if needed)
// For example, simulate a user address
uint256 balanceBefore = utilityToken.balanceOf(0x588A7E62547CB573084C8608486d60E567c573d0);
Expand Down

0 comments on commit 6fab322

Please sign in to comment.