-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/mstable/mStable-contracts …
…into emissions-test-staking
- Loading branch information
Showing
19 changed files
with
360 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
pragma solidity 0.8.6; | ||
|
||
import { IERC20, SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import { IDisperse } from "../interfaces/IDisperse.sol"; | ||
import { ImmutableModule } from "../shared/ImmutableModule.sol"; | ||
|
||
/** | ||
* @title DisperseForwarder | ||
* @author mStable | ||
* @notice Transfers reward tokens to a list of off-chain calculated recipients and amounts. | ||
* @dev Disperse contract on Mainnet and Polygon: 0xD152f549545093347A162Dce210e7293f1452150 | ||
* @dev VERSION: 1.0 | ||
* DATE: 2021-11-03 | ||
*/ | ||
contract DisperseForwarder is ImmutableModule { | ||
using SafeERC20 for IERC20; | ||
|
||
/// @notice Rewards token that is to be dispersed. | ||
IERC20 public immutable REWARDS_TOKEN; | ||
/// @notice Token Disperser contract. eg 0xD152f549545093347A162Dce210e7293f1452150 | ||
IDisperse public immutable DISPERSE; | ||
|
||
/** | ||
* @param _rewardsToken Bridged rewards token on the Polygon chain. | ||
* @param _disperse Token disperser contract. | ||
*/ | ||
constructor(address _nexus, address _rewardsToken, address _disperse) | ||
ImmutableModule(_nexus) { | ||
require(_rewardsToken != address(0), "Invalid Rewards token"); | ||
require(_disperse != address(0), "Invalid Disperse contract"); | ||
|
||
REWARDS_TOKEN = IERC20(_rewardsToken); | ||
DISPERSE = IDisperse(_disperse); | ||
|
||
} | ||
|
||
/** | ||
* @notice Transfers reward tokens to a list of recipients with amounts. | ||
* @param recipients Array of address that are to receive token rewards. | ||
* @param values Array of reward token amounts for each recipient including decimal places. | ||
*/ | ||
function disperseToken(address[] memory recipients, uint256[] memory values) external onlyKeeperOrGovernor { | ||
uint256 len = recipients.length; | ||
require(values.length == len, "array mismatch"); | ||
|
||
// Calculate the total amount of rewards that will be dispersed. | ||
uint256 total = 0; | ||
for (uint256 i = 0; i < len; i++) { | ||
total += values[i]; | ||
} | ||
|
||
uint256 rewardBal = REWARDS_TOKEN.balanceOf(address(this)); | ||
require(rewardBal >= total, "Insufficient rewards"); | ||
|
||
// Approve only the amount to be dispersed. Any more and the funds in this contract can be stolen | ||
// using the disperseTokenSimple function on the Disperse contract. | ||
REWARDS_TOKEN.safeApprove(address(DISPERSE), total); | ||
|
||
DISPERSE.disperseTokenSimple(REWARDS_TOKEN, recipients, values); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
pragma solidity 0.8.6; | ||
|
||
import { IERC20, SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
import { IVotiumBribe } from "../interfaces/IVotiumBribe.sol"; | ||
import { ImmutableModule } from "../shared/ImmutableModule.sol"; | ||
|
||
/** | ||
* @title VotiumBribeForwarder | ||
* @author mStable | ||
* @notice Uses reward tokens to bribe vlCVX holders to vote for a Curve gauge using Votium. | ||
* @dev VotiumBribe contract on Mainnet, Polygon, Fantom: 0x19bbc3463dd8d07f55438014b021fb457ebd4595 | ||
* @dev VERSION: 1.0 | ||
* DATE: 2021-11-03 | ||
*/ | ||
contract VotiumBribeForwarder is ImmutableModule { | ||
using SafeERC20 for IERC20; | ||
|
||
/// @notice Rewards token that is to be deposit. | ||
// solhint-disable-next-line var-name-mixedcase | ||
IERC20 public immutable REWARDS_TOKEN; | ||
/// @notice Token VotiumBribe contract. eg 0x19bbc3463dd8d07f55438014b021fb457ebd4595 | ||
// solhint-disable-next-line var-name-mixedcase | ||
IVotiumBribe public immutable VOTIUM_BRIBE; | ||
/// @notice Votium brive deposit choice index. | ||
uint256 public choiceIndex; | ||
|
||
/** | ||
* @param _rewardsToken Bridged rewards token on the Polygon chain. | ||
* @param _votiumBribe Token votium bribe contract. | ||
*/ | ||
constructor(address _nexus, address _rewardsToken, address _votiumBribe) | ||
ImmutableModule(_nexus) { | ||
require(_rewardsToken != address(0), "Invalid Rewards token"); | ||
require(_votiumBribe != address(0), "Invalid VotiumBribe contract"); | ||
REWARDS_TOKEN = IERC20(_rewardsToken); | ||
VOTIUM_BRIBE = IVotiumBribe(_votiumBribe); | ||
} | ||
|
||
|
||
/** | ||
* @notice Deposits a bribe into Votium, choiceIndex must be set previously. | ||
* @param amount amount of reward token to deposit including decimal places. | ||
* @param proposal votium brive proposal | ||
*/ | ||
function depositBribe(uint256 amount, bytes32 proposal) external onlyKeeperOrGovernor { | ||
require(amount != 0, "Invalid amount"); | ||
|
||
uint256 rewardBal = REWARDS_TOKEN.balanceOf(address(this)); | ||
require(rewardBal >= amount, "Insufficient rewards"); | ||
// Approve only the amount to be bribe. Any more and the funds in this contract can be stolen | ||
// using the depositBribe function on the VotiumBribe contract. | ||
REWARDS_TOKEN.safeApprove(address(VOTIUM_BRIBE), amount); | ||
VOTIUM_BRIBE.depositBribe(address(REWARDS_TOKEN), amount, proposal, choiceIndex); | ||
} | ||
|
||
/** | ||
* @notice Updates the choice index used for the bribe. | ||
* @param _choiceIndex the bribe choice index | ||
*/ | ||
function updateChoiceIndex(uint256 _choiceIndex) public onlyKeeperOrGovernor { | ||
choiceIndex = _choiceIndex; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
pragma solidity 0.8.6; | ||
|
||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
interface IDisperse { | ||
function disperseTokenSimple(IERC20 token, address[] memory recipients, uint256[] memory values) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-or-later | ||
pragma solidity 0.8.6; | ||
|
||
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
||
interface IVotiumBribe { | ||
function depositBribe(address _token, uint256 _amount, bytes32 _proposal, uint256 _choiceIndex) external ; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.