DistributedCollective/Sovryn-smart-contracts

Add events to facilitate FE/BE data processing

Closed this issue · 7 comments

When a user stakes or unstakes, it has to specify the 'until' parameter that defines the staking slot to use, but for some reason the unstaking event is not reporting that parameter, so it makes sense to refactor it, but some contracts cannot be redeployed, Tyrone knows better which ones.

Sovryn-smart-contracts/contracts/governance/Staking/Staking.sol
	function _withdraw(
		uint96 amount,
		uint256 until, <======== until parameter
        ...
        line 341: emit TokensWithdrawn(msg.sender, receiver, amount);

Lending rewards needs a new event:

Finding the event: functions calling _payInterest and associated events:
    function _rollover(bytes32 loanId, bytes memory loanDataBytes) internal {
    function _settleInterest(
    function withdrawAccruedInterest(address loanToken) external {
    function extendLoanDuration(
    function reduceLoanDuration(
    function _initializeInterest(

        function _payInterest(address lender, address interestToken) internal {
            No event!

    	    function _payInterestTransfer(
                No event!

                /// Transfers the interest to the lender, less the interest fee.
                vaultWithdraw(interestToken, lender, interestOwedNow.sub(lendingFee));
                    event VaultWithdraw(address indexed asset, address indexed to, uint256 amount);

The lending reward is the interest and _payInterest is the place to get event information from, but there is no event at that function. A lower level function vaultWithdraw has an event with the information needed, but this function is also used on another occasions such as:

function _liquidate(
function _settleInterestToPrincipal(
function _withdrawAsset(
function _closeWithSwap(
function withdrawCollateral(
function reduceLoanDuration(

Basically this same event is generally used when transferring tokens from lending pools to users (lenders and borrowers). There is no easy way to tell apart which one of these events is really coming from paying interests. So we cannot use it to find out just the lending rewards.

My suggestion is when refactoring to add a new event on contract Sovryn-smart-contracts/contracts/mixins/InterestUser.sol , function _payInterest(address lender, address interestToken) specific for interest payments as a way to meter users lending rewards from now on.

Created new local branch: eventsForBackend

Checkpoints.sol declares the event:

/// @notice An event emitted when tokens get withdrawn.
event TokensWithdrawn(address indexed staker, address receiver, uint256 amount);

Having the same name as another event on VestingLogic contract.

Event name on Checkpoints should be refactored:
1.- Name changed to StakingWithdrawn
2.- Added all missing function parameters: 'until' and 'isGovernance'

/// @notice An event emitted when staked tokens get withdrawn.
event StakingWithdrawn(address indexed staker, uint256 amount, uint256 until, address indexed receiver, bool isGovernance);

Betsy asks to add the "amount" field to the ExtendedStakingDuration event. It's doable and easy to implement.

Changes are summerized into this:
TokensWithdrawn event: name changed (StakingWithdrawn) and added 2 parameters.
PayInterestTransfer new event created.
ExtendedStakingDuration event: added 1 parameter.