Skip to content

Commit

Permalink
Add TODO comments and make the rewardMultiplier public
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiascaricato committed Apr 19, 2023
1 parent b4c0173 commit edf66ad
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
25 changes: 10 additions & 15 deletions contracts/Token.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ contract Usdm is IERC20Upgradeable, OwnableUpgradeable, AccessControlUpgradeable

string private _name;
string private _symbol;
uint256 private _rewardMultiplier;
uint256 private _totalShares;
uint256 private constant BASE = 1e18;
uint256 public rewardMultiplier;

mapping (address => uint256) private _shares;
mapping(address => bool) private _blacklist;
Expand Down Expand Up @@ -53,7 +53,7 @@ contract Usdm is IERC20Upgradeable, OwnableUpgradeable, AccessControlUpgradeable
function initialize(string memory name_, string memory symbol_, uint256 initialShares) external initializer {
_name = name_;
_symbol = symbol_;
_rewardMultiplier = BASE;
rewardMultiplier = BASE;

__Ownable_init();
__AccessControl_init();
Expand Down Expand Up @@ -108,7 +108,7 @@ contract Usdm is IERC20Upgradeable, OwnableUpgradeable, AccessControlUpgradeable
* @return The equivalent amount of shares
*/
function amountToShares(uint256 amount) public view returns (uint256) {
return amount.mul(BASE).div(rewardMultiplier());
return amount.mul(BASE).div(rewardMultiplier);
}

/**
Expand All @@ -117,7 +117,7 @@ contract Usdm is IERC20Upgradeable, OwnableUpgradeable, AccessControlUpgradeable
* @return The equivalent amount of tokens
*/
function sharesToAmount(uint256 shares) public view returns (uint256) {
return shares.mul(rewardMultiplier()).div(BASE);
return shares.mul(rewardMultiplier).div(BASE);
}

/**
Expand Down Expand Up @@ -346,6 +346,7 @@ contract Usdm is IERC20Upgradeable, OwnableUpgradeable, AccessControlUpgradeable
}

function _afterTokenTransfer(address from, address to, uint256 amount) private {
// TODO: the event should be triggered with amount not shares
emit Transfer(from, to, amount);
}

Expand All @@ -365,26 +366,19 @@ contract Usdm is IERC20Upgradeable, OwnableUpgradeable, AccessControlUpgradeable
super._unpause();
}

/**
* @notice Returns the current reward multiplier
* @return The current reward multiplier
*/
function rewardMultiplier() public view returns (uint256) {
return _rewardMultiplier;
}

/**
* @notice Adds a new reward multiplier to the existing reward multiplier.
* @dev Only users with ORACLE_ROLE can call this function.
* @param rewardMultiplier_ The new reward multiplier to be added.
*/
function addRewardMultiplier(uint256 rewardMultiplier_) external onlyRole(ORACLE_ROLE) {
// TODO: change addrewardmultiplier to setrewardmultiplier
require(rewardMultiplier_ > 0, "Invalid RewardMultiplier");
require(rewardMultiplier_ < 500000000000000, "Invalid RewardMultiplier"); // 5bps

_rewardMultiplier = _rewardMultiplier.add(rewardMultiplier_);
rewardMultiplier = rewardMultiplier.add(rewardMultiplier_);

emit RewardMultiplier(_rewardMultiplier);
emit RewardMultiplier(rewardMultiplier);
}

/**
Expand Down Expand Up @@ -481,7 +475,8 @@ contract Usdm is IERC20Upgradeable, OwnableUpgradeable, AccessControlUpgradeable
function transferFrom(address from, address to, uint256 amount) external returns (bool) {
address spender = _msgSender();
uint256 shares = amountToShares(amount);
_spendAllowance(from, spender, shares);
// TODO: spendallowance should be in amount not in shares
_spendAllowance(from, spender, shares); // FIX
_transferShares(from, to, shares);

return true;
Expand Down
2 changes: 0 additions & 2 deletions test/Token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,6 @@ describe("USDM", () => {

const expected = amount.mul(totalInterest).div(toBaseUnit(1)).add(amount);

console.log(((1000+(1000/1.0004))*1.0004).toFixed(2))

expect(
await contract.balanceOf(acc1.address)
).to.equal(
Expand Down

0 comments on commit edf66ad

Please sign in to comment.