Skip to content

Commit

Permalink
fix: Add events to track issuance state changes (SC-5719) (#67)
Browse files Browse the repository at this point in the history
* fix: add events to track issuance state changes

* fix: use remote submodules

* fix: add all params

* fix: update to use two events in uvs

* chore: rm lastUpdated

* chore rm space
  • Loading branch information
lucas-manuel authored Apr 12, 2022
1 parent af79926 commit 0fb7a68
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
17 changes: 10 additions & 7 deletions contracts/RevenueDistributionToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ contract RevenueDistributionToken is IRevenueDistributionToken, ERC20 {
// Update timestamp and period finish.
vestingPeriodFinish = (lastUpdated = block.timestamp) + vestingPeriod_;

emit VestingScheduleUpdated(msg.sender, vestingPeriodFinish, issuanceRate);
emit IssuanceParamsUpdated(freeAssets_, issuanceRate_);
emit VestingScheduleUpdated(msg.sender, vestingPeriodFinish);
}

/************************/
Expand Down Expand Up @@ -153,11 +154,12 @@ contract RevenueDistributionToken is IRevenueDistributionToken, ERC20 {

_mint(receiver_, shares_);

freeAssets = totalAssets() + assets_;
uint256 freeAssetsCache = freeAssets = totalAssets() + assets_;

_updateIssuanceParams();
uint256 issuanceRate_ = _updateIssuanceParams();

emit Deposit(caller_, receiver_, assets_, shares_);
emit IssuanceParamsUpdated(freeAssetsCache, issuanceRate_);

require(ERC20Helper.transferFrom(asset, caller_, address(this), assets_), "RDT:M:TRANSFER_FROM");
}
Expand All @@ -173,17 +175,18 @@ contract RevenueDistributionToken is IRevenueDistributionToken, ERC20 {

_burn(owner_, shares_);

freeAssets = totalAssets() - assets_;
uint256 freeAssetsCache = freeAssets = totalAssets() - assets_;

_updateIssuanceParams();
uint256 issuanceRate_ = _updateIssuanceParams();

emit Withdraw(caller_, receiver_, owner_, assets_, shares_);
emit IssuanceParamsUpdated(freeAssetsCache, issuanceRate_);

require(ERC20Helper.transfer(asset, receiver_, assets_), "RDT:B:TRANSFER");
}

function _updateIssuanceParams() internal {
issuanceRate = (lastUpdated = block.timestamp) > vestingPeriodFinish ? 0 : issuanceRate;
function _updateIssuanceParams() internal returns (uint256 issuanceRate_) {
return issuanceRate = (lastUpdated = block.timestamp) > vestingPeriodFinish ? 0 : issuanceRate;
}

/**********************/
Expand Down
12 changes: 9 additions & 3 deletions contracts/interfaces/IRevenueDistributionToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ interface IRevenueDistributionToken is IERC20, IERC4626 {
/*** Events ***/
/**************/

/**
* @dev Issuance parameters have been updated after a `_mint` or `_burn`.
* @param freeAssets_ Resulting `freeAssets` (y-intercept) value after accounting update.
* @param issuanceRate_ The new issuance rate of `asset` until `vestingPeriodFinish_`.
*/
event IssuanceParamsUpdated(uint256 freeAssets_, uint256 issuanceRate_);

/**
* @dev `newOwner_` has accepted the transferral of RDT ownership from `previousOwner_`.
* @param previousOwner_ The previous RDT owner.
Expand All @@ -27,12 +34,11 @@ interface IRevenueDistributionToken is IERC20, IERC4626 {
event PendingOwnerSet(address indexed owner_, address indexed pendingOwner_);

/**
* @dev `owner_` has updated the RDT vesting schedule to end at `vestingPeriodFinish_`, with an issuance rate of `issuanceRate_`.
* @dev `owner_` has updated the RDT vesting schedule to end at `vestingPeriodFinish_`.
* @param owner_ The current RDT owner.
* @param vestingPeriodFinish_ When the unvested balance will finish vesting.
* @param issuanceRate_ The new issuance rate of `asset` until `vestingPeriodFinish_`.
*/
event VestingScheduleUpdated(address indexed owner_, uint256 indexed vestingPeriodFinish_, uint256 issuanceRate_);
event VestingScheduleUpdated(address indexed owner_, uint256 vestingPeriodFinish_);

/***********************/
/*** State Variables ***/
Expand Down

0 comments on commit 0fb7a68

Please sign in to comment.