Skip to content

Commit

Permalink
GaugeController: Add Events & Natspec (#276)
Browse files Browse the repository at this point in the history
* update(GaugeController.sol): add new events to contract

* update(GaugeController.sol): add natspec to events

* Update contracts/GaugeController.sol

Co-authored-by: Pierrick Turelier <pierrick@turelier.com>

* Update contracts/GaugeController.sol

Co-authored-by: Pierrick Turelier <pierrick@turelier.com>

* Update contracts/GaugeController.sol

Co-authored-by: Pierrick Turelier <pierrick@turelier.com>

* Update contracts/GaugeController.sol

Co-authored-by: Pierrick Turelier <pierrick@turelier.com>

* Update contracts/GaugeController.sol

Co-authored-by: Pierrick Turelier <pierrick@turelier.com>

* Update contracts/GaugeController.sol

Co-authored-by: Pierrick Turelier <pierrick@turelier.com>

* Update contracts/GaugeController.sol

Co-authored-by: Pierrick Turelier <pierrick@turelier.com>

* Update contracts/GaugeController.sol

Co-authored-by: Pierrick Turelier <pierrick@turelier.com>

* Update contracts/GaugeController.sol

Co-authored-by: Pierrick Turelier <pierrick@turelier.com>

* update(GaugeController.sol): add event emitters to functions

* update(GaugeController.sol): minor fix

* fix

* update(GaugeController.sol): finalize current interface natspec

Co-authored-by: Pierrick Turelier <pierrick@turelier.com>
  • Loading branch information
kamescg and PierrickGT committed Jun 1, 2022
1 parent 5f82459 commit e259f46
Showing 1 changed file with 65 additions and 5 deletions.
70 changes: 65 additions & 5 deletions contracts/GaugeController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,70 @@ contract GaugeController is IGaugeController, Ownable {
/// @notice Governance scale set for existing Gauge.
mapping(address => TwabLib.Account) internal gaugeScaleTwabs;

/**
* @notice Event emitted when the contract is deployed
* @param token Address of the token being staked in the gauge
*/
event Deployed(IERC20 token, IGaugeReward gaugeReward, address owner);

/**
* @notice Emitted when GaugeReward address is set/updated
* @param gaugeReward Address of the newly set GaugeReward contract
*/
*/
event GaugeRewardSet(IGaugeReward gaugeReward);

/**
* @notice Event emitted when the contract is deployed
* @param token Address of the token being staked in the gauge
* @notice Emitted when User deposits 'token' into the gauge.
* @param user Address of the user who deposited 'token' into the GaugeController
* @param amount Amount of 'token' deposited into the GaugeController
*/
event Deployed(IERC20 token, IGaugeReward gaugeReward, address owner);
event TokenDeposited(address indexed user, uint256 amount);

/**
* @notice Emitted when User withdraws 'token' from the gauge.
* @param user Address of the user who withdrew 'token' from the GaugeController
* @param amount Amount of 'token' withdrawn from the GaugeController
*/
event TokenWithdrawn(address indexed user, uint256 amount);

/**
* @notice Emitted when User increases a Gauge weight.
* @param user User address
* @param gauge Existing Gauge address
* @param amount Amount of 'balance' debited from the User and credited to the Gauge
*/
event GaugeIncreased(address indexed user, address indexed gauge, uint256 amount);

/**
* @notice Emitted when User decrease a Gauge weight.
* @param user User address
* @param gauge Existing Gauge address
* @param amount Amount of 'balance' debited from the Gauge and credited to the User
*/
event GaugeDecreased(address indexed user, address indexed gauge, uint256 amount);

/**
* @notice Emitted when an Authorized User adds a new Gauge to the GaugeController
* @param user Authorized address
* @param gauge New Gauge address
*/
event GaugeAdded(address indexed user, address gauge);

/**
* @notice Emitted when an Authorized User removes an existing Gauge from the GaugeController
* @param user Authorized address
* @param gauge Gauge address
*/
event GaugeRemoved(address indexed user, address indexed gauge);

/**
* @notice Emitted when an Authorized User sets an existing Gauge 'scale' weight.
* @param user Authorized address
* @param gauge Gauge address
* @param scale New Gauge scale
* @param oldScale Old Gauge scale
*/
event GaugeScaleSet(address indexed user, address indexed gauge, uint256 scale, uint256 oldScale);

/* ================================================================================ */
/* Constructor & Modifiers */
Expand All @@ -85,6 +138,7 @@ contract GaugeController is IGaugeController, Ownable {
* @notice GaugeController Construction
* @param _token ERC20 contract address (used to weight gauges)
* @param _gaugeReward GaugeReward to store ERC20 balances for stakers
* @param _owner Address of authorized owner
*/
constructor (
IERC20 _token,
Expand Down Expand Up @@ -132,6 +186,7 @@ contract GaugeController is IGaugeController, Ownable {
function deposit(address _to, uint256 _amount) public {
balances[_to] += _amount;
token.transferFrom(msg.sender, address(this), _amount);
emit TokenDeposited(msg.sender, _amount);
}

/**
Expand All @@ -141,6 +196,7 @@ contract GaugeController is IGaugeController, Ownable {
function withdraw(uint256 _amount) public {
balances[msg.sender] -= _amount;
token.transfer(msg.sender, _amount);
emit TokenWithdrawn(msg.sender, _amount);
}

/**
Expand All @@ -157,6 +213,7 @@ contract GaugeController is IGaugeController, Ownable {
) = TwabLib.increaseBalance(gaugeTwab, _amount.toUint208(), uint32(block.timestamp));
gaugeTwab.details = twabDetails;
gaugeReward.afterIncreaseGauge(_gauge, msg.sender, uint256(twabDetails.balance) - _amount);
emit GaugeIncreased(msg.sender, _gauge, _amount);
}

/**
Expand All @@ -173,6 +230,7 @@ contract GaugeController is IGaugeController, Ownable {
) = TwabLib.decreaseBalance(gaugeTwab, _amount.toUint208(), "insuff", uint32(block.timestamp));
gaugeTwab.details = twabDetails;
gaugeReward.afterDecreaseGauge(_gauge, msg.sender, uint256(twabDetails.balance) + _amount);
emit GaugeDecreased(msg.sender, _gauge, _amount);
}

/// @TODO: Add Governance/Executive authorization modifier/function.
Expand Down Expand Up @@ -206,6 +264,7 @@ contract GaugeController is IGaugeController, Ownable {
twabDetails,,
) = TwabLib.decreaseBalance(gaugeScaleTwab, twabDetails.balance, "insuff", uint32(block.timestamp));
gaugeScaleTwab.details = twabDetails;
emit GaugeRemoved(msg.sender, _gauge);
}

/**
Expand All @@ -215,7 +274,6 @@ contract GaugeController is IGaugeController, Ownable {
function setGaugeReward(IGaugeReward _gaugeReward) external onlyOwner {
require(address(_gaugeReward) != address(0), "GC/GaugeReward-not-zero-address");
gaugeReward = _gaugeReward;

emit GaugeRewardSet(_gaugeReward);
}

Expand All @@ -238,6 +296,7 @@ contract GaugeController is IGaugeController, Ownable {
) = TwabLib.increaseBalance(gaugeScaleTwab, _scale.toUint208() - twabDetails.balance, uint32(block.timestamp));
}
gaugeScaleTwab.details = twabDetails;
emit GaugeScaleSet(msg.sender, _gauge, _scale, twabDetails.balance);
}

/// @inheritdoc IGaugeController
Expand Down Expand Up @@ -306,6 +365,7 @@ contract GaugeController is IGaugeController, Ownable {
uint32(block.timestamp)
);
gaugeScaleTwab.details = twabDetails;
emit GaugeAdded(msg.sender, _gauge);
}

function _getAverageGaugeBalanceBetween(address _gauge, uint256 _startTime, uint256 _endTime) internal view returns (uint256) {
Expand Down

0 comments on commit e259f46

Please sign in to comment.