Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate $BB in YieldDistributor #94

Merged
merged 12 commits into from
Sep 22, 2024
2 changes: 2 additions & 0 deletions script/deploy/DeployYieldDistributor.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ contract DeployYieldDistributor is Script {
string public deployConfigPath = string(bytes("./script/deploy/config/deployYD.json"));
string config_data = vm.readFile(deployConfigPath);
address _bread = stdJson.readAddress(config_data, "._bread");
address _butteredBread = stdJson.readAddress(config_data, "._butteredBread");
uint256 _minRequiredVotingPower = stdJson.readUint(config_data, "._minRequiredVotingPower");
uint256 _cycleLength = stdJson.readUint(config_data, "._cycleLength");
uint256 _maxPoints = stdJson.readUint(config_data, "._maxPoints");
Expand All @@ -24,6 +25,7 @@ contract DeployYieldDistributor is Script {
bytes initData = abi.encodeWithSelector(
YieldDistributor.initialize.selector,
_bread,
_butteredBread,
_precision,
_minRequiredVotingPower,
_maxPoints,
Expand Down
8 changes: 6 additions & 2 deletions script/deploy/config/deployBB.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"_owner": "0x918dEf5d593F46735f74F9E2B280Fe51AF3A99ad",
"_liquidityPools": ["0xa555d5344f6FB6c65da19e403Cb4c1eC4a1a5Ee3"],
"_scalingFactors": ["100"],
"_liquidityPools": [
"0xf3d8f3de71657d342db60dd714c8a2ae37eac6b4"
],
"_scalingFactors": [
"100"
],
"_name": "ButteredBread",
"_symbol": "BB"
}
1 change: 1 addition & 0 deletions script/deploy/config/deployYD.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"_bread": "0xa555d5344f6FB6c65da19e403Cb4c1eC4a1a5Ee3",
"_butteredbread": "0x123456789abcdef123456789abcdef123456789a",
"_owner": "0x918dEf5d593F46735f74F9E2B280Fe51AF3A99ad",
"_projectNames": [
"laborDao",
Expand Down
20 changes: 18 additions & 2 deletions src/YieldDistributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {IYieldDistributor} from "src/interfaces/IYieldDistributor.sol";
contract YieldDistributor is IYieldDistributor, OwnableUpgradeable {
/// @notice The address of the $BREAD token contract
Bread public BREAD;
/// @notice The address of the $BUTTEREDBREAD token contract
ERC20VotesUpgradeable public BUTTEREDBREAD;
RonTuretzky marked this conversation as resolved.
Show resolved Hide resolved
/// @notice The precision to use for calculations
uint256 public PRECISION;
/// @notice The minimum number of blocks between yield distributions
Expand Down Expand Up @@ -57,6 +59,7 @@ contract YieldDistributor is IYieldDistributor, OwnableUpgradeable {

function initialize(
address _bread,
address _butteredBread,
uint256 _precision,
uint256 _minRequiredVotingPower,
uint256 _maxPoints,
Expand All @@ -68,6 +71,7 @@ contract YieldDistributor is IYieldDistributor, OwnableUpgradeable {
__Ownable_init(msg.sender);

BREAD = Bread(_bread);
BUTTEREDBREAD = ERC20VotesUpgradeable(_butteredBread);
RonTuretzky marked this conversation as resolved.
Show resolved Hide resolved
PRECISION = _precision;
minRequiredVotingPower = _minRequiredVotingPower;
maxPoints = _maxPoints;
Expand Down Expand Up @@ -97,8 +101,12 @@ contract YieldDistributor is IYieldDistributor, OwnableUpgradeable {
* @return uint256 The voting power of the user
*/
function getCurrentVotingPower(address _account) public view returns (uint256) {
return
this.getVotingPowerForPeriod(BREAD, lastClaimedBlockNumber - cycleLength, lastClaimedBlockNumber, _account);
return this.getVotingPowerForPeriod(
RonTuretzky marked this conversation as resolved.
Show resolved Hide resolved
BREAD, lastClaimedBlockNumber - cycleLength, lastClaimedBlockNumber, _account
)
+ this.getVotingPowerForPeriod(
RonTuretzky marked this conversation as resolved.
Show resolved Hide resolved
BUTTEREDBREAD, lastClaimedBlockNumber - cycleLength, lastClaimedBlockNumber, _account
);
}

/**
Expand Down Expand Up @@ -373,4 +381,12 @@ contract YieldDistributor is IYieldDistributor, OwnableUpgradeable {

yieldFixedSplitDivisor = _yieldFixedSplitDivisor;
}

/**
* @notice Set the ButteredBread token contract
* @param _butteredBread Address of the ButteredBread token contract
*/
function setButteredBread(address _butteredBread) public onlyOwner {
BUTTEREDBREAD = ERC20VotesUpgradeable(_butteredBread);
}
}
5 changes: 5 additions & 0 deletions test/YieldDistributor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {TransparentUpgradeableProxy} from
import {YieldDistributor, IYieldDistributor} from "src/YieldDistributor.sol";
import {YieldDistributorTestWrapper} from "src/test/YieldDistributorTestWrapper.sol";

import {ButteredBread} from "src/ButteredBread.sol";

abstract contract Bread is ERC20VotesUpgradeable, OwnableUpgradeable {
function claimYield(uint256 amount, address receiver) public virtual;
function yieldAccrued() external view virtual returns (uint256);
Expand Down Expand Up @@ -43,6 +45,7 @@ contract YieldDistributorTest is Test {
uint256 _lastClaimedBlockNumber = stdJson.readUint(config_data, "._lastClaimedBlockNumber");
uint256 _yieldFixedSplitDivisor = stdJson.readUint(config_data, "._yieldFixedSplitDivisor");
Bread public bread = Bread(address(_bread));
ButteredBread public butteredBread = ButteredBread(address(_bread));
uint256 minHoldingDurationInBlocks = _minHoldingDuration / _blocktime;

// For testing purposes, these values were used in the following way to configure _minRequiredVotingPower
Expand All @@ -61,6 +64,7 @@ contract YieldDistributorTest is Test {
bytes memory initData = abi.encodeWithSelector(
YieldDistributor.initialize.selector,
address(bread),
address(butteredBread),
_precision,
_minRequiredVotingPower,
_maxPoints,
Expand All @@ -79,6 +83,7 @@ contract YieldDistributorTest is Test {
initData = abi.encodeWithSelector(
YieldDistributor.initialize.selector,
address(bread),
address(butteredBread),
_precision,
_minRequiredVotingPower,
_maxPoints,
Expand Down
1 change: 1 addition & 0 deletions test/test_deploy.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"_bread": "0xa555d5344f6FB6c65da19e403Cb4c1eC4a1a5Ee3",
"_butteredbread": "0x123456789abcdef123456789abcdef123456789a",
"_projectNames": [
"laborDao",
"Dandelion",
Expand Down