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

feat(PRT): Add Prt and PrtFeeSplitExtension #176

Merged
merged 19 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion contracts/adapters/FeeSplitExtension.sol
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ contract FeeSplitExtension is BaseExtension, TimeLockUpgrade, MutualUpgrade {
* will automatically be sent to this address so reading the balance of the SetToken in the contract after accrual is
* sufficient for accounting for all collected fees.
*/
function accrueFeesAndDistribute() public {
function accrueFeesAndDistribute() public virtual {
// Emits a FeeActualized event
streamingFeeModule.accrueFee(setToken);

Expand Down Expand Up @@ -260,6 +260,7 @@ contract FeeSplitExtension is BaseExtension, TimeLockUpgrade, MutualUpgrade {
*/
function updateFeeSplit(uint256 _newFeeSplit)
external
virtual
mutualUpgrade(manager.operator(), manager.methodologist())
{
require(_newFeeSplit <= PreciseUnitMath.preciseUnit(), "Fee must be less than 100%");
Expand Down
137 changes: 137 additions & 0 deletions contracts/adapters/PrtFeeSplitExtension.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
/*
Copyright 2024 Index Cooperative

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

SPDX-License-Identifier: Apache License, Version 2.0
*/

pragma solidity 0.6.10;
pragma experimental ABIEncoderV2;

import { Address } from "@openzeppelin/contracts/utils/Address.sol";
import { SafeMath } from "@openzeppelin/contracts/math/SafeMath.sol";

import { FeeSplitExtension } from "./FeeSplitExtension.sol";
import { IBaseManager } from "../interfaces/IBaseManager.sol";
import { IIssuanceModule } from "../interfaces/IIssuanceModule.sol";
import { IPrt } from "../interfaces/IPrt.sol";
import { IPrtStakingPool } from "../interfaces/IPrtStakingPool.sol";
import { IStreamingFeeModule } from "../interfaces/IStreamingFeeModule.sol";
import { PreciseUnitMath } from "../lib/PreciseUnitMath.sol";

/**
* @title PrtFeeSplitExtension
* @dev Extension that allows for splitting and setting streaming and mint/redeem fees with a
* PRT Staking Pool. The operator can accrue fees from the streaming fee module and distribute
* them to the operator and the PRT Staking Pool, snapshotting the PRT Staking Pool. The operator
* can update the PRT staking pool address and the fee split between the operator and the
* PRT staking pool.
*/
contract PrtFeeSplitExtension is FeeSplitExtension {
using Address for address;
using PreciseUnitMath for uint256;
using SafeMath for uint256;

/* ============ Events ============ */

event PrtFeesDistributed(
address indexed operatorFeeRecipient,
address indexed prtStakingPool,
uint256 operatorTake,
uint256 prtTake
);

/* ============ State Variables ============ */

IPrt public prt;
ckoopmann marked this conversation as resolved.
Show resolved Hide resolved
IPrtStakingPool public prtStakingPool;

/* ============ Constructor ============ */

constructor(
IBaseManager _manager,
IStreamingFeeModule _streamingFeeModule,
IIssuanceModule _issuanceModule,
uint256 _operatorFeeSplit,
address _operatorFeeRecipient,
IPrt _prt
)
public
FeeSplitExtension(
_manager,
_streamingFeeModule,
_issuanceModule,
_operatorFeeSplit,
_operatorFeeRecipient
)
{
require(_prt.setToken() == address(manager.setToken()), "SetToken mismatch with Prt");
prt = _prt;
}

/* ============ External Functions ============ */

/**
* @notice ONLY OPERATOR: Updates PRT staking pool. PRT staking pool must have this extension set as the feeSplitExtension.
* @param _prtStakingPool Address of the new PRT staking pool
*/
function updatePrtStakingPool(IPrtStakingPool _prtStakingPool) external onlyOperator {
ckoopmann marked this conversation as resolved.
Show resolved Hide resolved
require(address(_prtStakingPool) != address(0), "Zero address not valid");
require(_prtStakingPool.feeSplitExtension() == address(this), "PrtFeeSplitExtension must be set");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that in the newer version of SnapshotStakingPool.sol the public variable is called distributor and not feeSplitExtension

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also check to make sure the Staking Pool's stakeToken matches the address stored in prt?

In the constructor we check if prt.setToken() is correct, but I don't think that's effective unless we also check that the StakingPool uses that same prt.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added additional checks to match the SnapshotStakingPool here 515e783

prtStakingPool = _prtStakingPool;
ckoopmann marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* @notice ONLY OPERATOR: Accrues fees from streaming fee module. Gets resulting balance after fee accrual, calculates fees for
* operator and PRT staking pool, and sends to operator fee recipient and PRT Staking Pool respectively. NOTE: mint/redeem fees
* will automatically be sent to this address so reading the balance of the SetToken in the contract after accrual is
* sufficient for accounting for all collected fees. If the PRT take is greater than 0, the PRT Staking Pool will accrue the fees
* and update the snapshot.
*/
function accrueFeesAndDistribute() public override onlyOperator {
// Emits a FeeActualized event
streamingFeeModule.accrueFee(setToken);

uint256 totalFees = setToken.balanceOf(address(this));

uint256 operatorTake = totalFees.preciseMul(operatorFeeSplit);
uint256 prtTake = totalFees.sub(operatorTake);

if (operatorTake > 0) {
setToken.transfer(operatorFeeRecipient, operatorTake);
}

// Accrue PRT Staking Pool rewards and update snapshot
if (prtTake > 0) {
setToken.approve(address(prtStakingPool), prtTake);
prtStakingPool.accrue(prtTake);
ckoopmann marked this conversation as resolved.
Show resolved Hide resolved
}

emit PrtFeesDistributed(operatorFeeRecipient, address(prtStakingPool), operatorTake, prtTake);
}

/**
* @notice Updates fee split between operator and PRT Staking Pool. Split defined in precise units (1% = 10^16).
* Does not accrue fees and snapshot PRT Staking Pool.
* @param _newFeeSplit Percent of fees in precise units (10^16 = 1%) sent to operator, (rest go to the PRT Staking Pool).
*/
function updateFeeSplit(uint256 _newFeeSplit)
external
override
onlyOperator
{
require(_newFeeSplit <= PreciseUnitMath.preciseUnit(), "Fee must be less than 100%");
operatorFeeSplit = _newFeeSplit;
ckoopmann marked this conversation as resolved.
Show resolved Hide resolved
}
}
8 changes: 8 additions & 0 deletions contracts/interfaces/IPrt.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: Apache License, Version 2.0
pragma solidity 0.6.10;

import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";

interface IPrt is IERC20 {
function setToken() external view returns (address);
}
15 changes: 15 additions & 0 deletions contracts/interfaces/IPrtStakingPool.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: Apache License, Version 2.0
pragma solidity ^0.6.10;

interface IPrtStakingPool {
function stake(uint256 _amount) external;
function unstake(uint256 _amount) external;
function accrue(uint256 _amount) external;
function claim() external;
function setFeeSplitExtension(address _feeSplitExtension) external;
function getCurrentId() external view returns (uint256);
function getPendingRewards(address _account) external view returns (uint256);
function getSnapshotRewards(uint256 _snapshotId, address _account) external view returns (uint256);
function feeSplitExtension() external view returns (address);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting the newer version of SnapshotStakingPool uses the variable name distributor instead of feeSplitExtension

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed here 515e783

function prt() external view returns (address);
}
Loading
Loading