Skip to content

Commit

Permalink
native decimals
Browse files Browse the repository at this point in the history
  • Loading branch information
todesstille committed Apr 22, 2024
1 parent dac37d0 commit ab85aba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
11 changes: 8 additions & 3 deletions contracts/gov/GovPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,12 @@ contract GovPool is

if (amount != 0) {
address token = _govUserKeeper.tokenAddress();
uint256 amountWithNativeDecimals = amount.from18Safe(token);

if (amount != msg.value) {
if (amountWithNativeDecimals != msg.value) {
IERC20(token).safeTransfer(
address(_govUserKeeper),
(amount - msg.value).from18Safe(token)
amountWithNativeDecimals - msg.value
);
}

Expand Down Expand Up @@ -632,6 +633,10 @@ contract GovPool is
}

function _checkValue(uint256 amount) internal view {
require(msg.value <= amount, "Gov: value is greater than amount to transfer");
address token = _govUserKeeper.tokenAddress();
require(
msg.value <= amount.from18Safe(token),
"Gov: value is greater than amount to transfer"
);
}
}
8 changes: 4 additions & 4 deletions contracts/gov/user-keeper/GovUserKeeper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,18 +93,18 @@ contract GovUserKeeper is IGovUserKeeper, OwnableUpgradeable, ERC721HolderUpgrad
uint256 amount
) external payable override onlyOwner withSupportedToken {
address token = tokenAddress;
uint256 fullAmount = amount;
uint256 amountWithNativeDecimals = amount.from18Safe(token);

if (msg.value != 0) {
_wrapNative(msg.value);
amount -= msg.value;
amountWithNativeDecimals -= msg.value;
}

if (amount > 0) {
IERC20(token).safeTransferFrom(payer, address(this), amount.from18Safe(token));
IERC20(token).safeTransferFrom(payer, address(this), amountWithNativeDecimals);
}

_usersInfo[receiver].balances[IGovPool.VoteType.PersonalVote].tokens += fullAmount;
_usersInfo[receiver].balances[IGovPool.VoteType.PersonalVote].tokens += amount;
}

function withdrawTokens(
Expand Down

0 comments on commit ab85aba

Please sign in to comment.