Skip to content

Commit

Permalink
chore: remove compilations
Browse files Browse the repository at this point in the history
  • Loading branch information
geolffreym committed Aug 12, 2024
1 parent 8151652 commit 1a23b3f
Show file tree
Hide file tree
Showing 188 changed files with 325 additions and 341 deletions.
1 change: 0 additions & 1 deletion cache_forge/solidity-files-cache.json

This file was deleted.

16 changes: 0 additions & 16 deletions contracts/Distributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,6 @@ contract Distributor is
_addCurrency(address(0));
}

/// @inheritdoc IDisburser
/// @notice Withdraws the specified amount of native tokens from the contract.
/// @param amount The amount of native tokens to withdraw.
function withdraw(uint256 amount) public override onlyOwner {
// withdraw native token if supported
owner().disburst(amount);
}

/// @inheritdoc IDisburser
/// @notice Withdraws the specified amount of ERC20 tokens from the contract.
/// @param amount The amount of ERC20 tokens to withdraw.
/// @param token The address of the ERC20 token to withdraw.
function withdraw(uint256 amount, address token) public onlyOwner {
owner().disburst(amount, token);
}

/// @inheritdoc IERC165
/// @notice Checks if the contract supports a specific interface.
/// @param interfaceId The interface identifier to check.
Expand Down
89 changes: 60 additions & 29 deletions contracts/RightsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.24;

import "@openzeppelin/contracts/utils/types/Time.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
Expand All @@ -20,6 +21,7 @@ import "contracts/base/upgradeable/extensions/RightsManagerDistributionUpgradeab
import "contracts/interfaces/IRegistrableVerifiable.sol";
import "contracts/interfaces/IReferendumVerifiable.sol";
import "contracts/interfaces/IRightsManager.sol";
import "contracts/interfaces/IDistributor.sol";
import "contracts/interfaces/IRepository.sol";
import "contracts/libraries/TreasuryHelper.sol";
import "contracts/libraries/MathHelper.sol";
Expand Down Expand Up @@ -49,6 +51,11 @@ contract RightsManager is
event GrantedAccess(address account, uint256 contentId);
event RegisteredContent(uint256 contentId);
event RevokedContent(uint256 contentId);
event FeesDisbursed(
address indexed treasury,
uint256 amount,
address token
);

address private syndication;
address private referendum;
Expand Down Expand Up @@ -208,24 +215,26 @@ contract RightsManager is
}

/// @inheritdoc IDisburser
/// @notice Withdraw funds of a specific token from the contract and sends them to the treasury.
/// @param token The address of the token.
/// @param amount The amount of tokens to withdraw.
/// @dev Only callable by governance.
function withdraw(uint256 amount, address token) public onlyGov {
// collect native token and send it to treasury
/// @notice Disburses tokens from the contract to a specified address.
/// @param amount The amount of tokens to disburse.
/// @param token The address of the ERC20 token to disburse tokens.
/// @dev This function can only be called by governance or an authorized entity.
function disburse(uint256 amount, address token) public onlyGov {
// collect tokens/coin token and send it to treasury
address treasury = getTreasuryAddress();
treasury.disburst(amount, token);
treasury.disburse(amount, token);
emit FeesDisbursed(treasury, balance, token);
}

/// @inheritdoc IDisburser
/// @notice Withdraw funds from the contract and sends them to the treasury.
/// @param amount The amount of coins to withdraw.
/// @dev Only callable by governance.
function withdraw(uint256 amount) public onlyGov {
/// @notice Disburses tokens from the contract to a specified address.
/// @param amount The amount of tokens to disburse.
/// @dev This function can only be called by governance or an authorized entity.
function disburse(uint256 amount) public onlyGov {
// collect native token and send it to treasury
address treasure = getTreasuryAddress();
treasure.disburst(amount);
treasure.disburse(amount);
emit FeesDisbursed(treasury, amount, address(0));
}

/// @inheritdoc IRightsManager
Expand Down Expand Up @@ -276,39 +285,61 @@ contract RightsManager is
emit GrantedCustodial(distributor, contentId);
}

function _checkFeesCompletion(
address currency,
uint256 expectedFees,
address payee
) internal pure returns (uint256) {
if (expectedFees == 0) revert;
// if currency is native coin then
if (currency == address(0)) {
if (msg.value < expectedFees) {
revert;
}
} else {
// expect the right amount allowed
if (payee.allowance(token) < expectedFees) revert;
payee.deposit(address(this), expectedFees, currency);
}

return fees;
}

/// @inheritdoc IRightsAccessController
/// @notice Grants access to a specific account for a certain content ID for a given timeframe.
/// @notice Grants access to a specific account for a certain content ID for a given condition.
/// @param account The address of the account.
/// @param contentId The content ID to grant access to.
/// @param condition The proof to validate access.
/// @param condition The proof or conditions that validate access, including any required fees.
function grantAccess(
address account,
uint256 contentId,
T.AccessCondition calldata condition
) public onlyRegisteredContent(contentId) onlyHolder(contentId) {
) public payable onlyRegisteredContent(contentId) onlyHolder(contentId) {
// in some cases the content or distributor could be revoked..
if (!isEligibleForDistribution(contentId))
revert InvalidNotAllowedContent();

address owner = ownerOf(contentId);
address custodial = getCustodial(contentId);
//!IMPORTANT if distributor or trasury does not support the currency, will revert..
uint256 treasurySplit = getFees(condition.txCurrency); // bps
uint256 distSplit = IFeesManager(custodial).getFees(condition.txCurrency); // bps

// get treasure fees and subtract from transaction amount
uint256 treasuryFees = condition.txAmount.perOf(treasurySplit);
uint256 total = condition.txAmount - treasuryFees;
address currency = condition.fee.currency;
uint256 fees = condition.fee.amount;

// init the distributor current content custodial..
IDistributor distributor = IDistributor(custodial);
//!IMPORTANT if distributor or trasury does not support the currency, will revert..
uint256 distSplit = distributor.getFees(currency); // bps
uint256 treasurySplit = getFees(currency); // bps
// The owner or delegated module must ensure that the necessary steps
// are taken to handle the transaction value or set the appropriate
// approve/allowance for the DRM (Digital Rights Management) contract.
_checkFeesCompletion(currency, fees, account);
// the max bps integrity is warrantied by treasure fees only bps modifier
uint256 distributorFees = total.perOf(distSplit);
uint256 depositToOwner = total - distributorFees;

// Deposit the calculated amounts to the respective addresses
account.safeDeposit(owner, depositToOwner, condition.txCurrency);
account.safeDeposit(custodial, distributorFees, condition.txCurrency);
account.safeDeposit(address(this), treasuryFees, condition.txCurrency);

uint256 ownerFees = total - distributorFees;
// a new value is added to ledger to
// TODO withdraw
_sumLedgerEntry(owner, ownerFees, currency);
_sumLedgerEntry(distributor.getManager(), distributorFees, currency);
_grantAccess(account, contentId, condition);
emit GrantedAccess(account, contentId);
}
Expand Down
57 changes: 27 additions & 30 deletions contracts/Syndication.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ contract Syndication is
// 10% initial quitting penalization rate
uint256 public penaltyRate;
uint256 public enrollmentsCount;

/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
mapping(address => uint256) public enrollmentFees;
bytes4 private constant INTERFACE_ID_IDISTRIBUTOR =
type(IDistributor).interfaceId;

Expand All @@ -63,7 +60,11 @@ contract Syndication is
/// @notice Event emitted when an entity is revoked.
/// @param distributor The address of the revoked entity.
event Revoked(address indexed distributor);
event FeesDisbursed(address indexed treasury, uint256 amount);
event FeesDisbursed(
address indexed treasury,
uint256 amount,
address token
);

/// @dev Constructor that disables initializers to prevent the implementation contract from being initialized.
/// @notice This constructor prevents the implementation contract from being initialized.
Expand Down Expand Up @@ -117,14 +118,6 @@ contract Syndication is
address newImplementation
) internal override onlyAdmin {}

/// @notice Private function to store the enrollment fees for distributors.
/// @param manager The address of the contract manager (distributor).
/// @param amount The amount of Wei enrolled by the distributor.
/// @dev This function is used to store the enrollment fees for distributors.
function _setEnrollment(address manager, uint256 amount) private {
enrollmentFees[manager] = amount;
}

/// @inheritdoc ISyndicatable
/// @notice Function to set the penalty rate for quitting enrollment.
/// @param newPenaltyRate The new penalty rate to be set. It should be a value representin base points (bps).
Expand Down Expand Up @@ -153,13 +146,14 @@ contract Syndication is
}

/// @inheritdoc IDisburser
/// @notice Withdraw funds from the contract and sends them to the treasury.
/// @param amount The amount of coins to withdraw.
/// @dev Only callable by governance.
function withdraw(uint256 amount) public onlyGov {
/// @notice Disburses tokens from the contract to a specified address.
/// @param amount The amount of tokens to disburse.
/// @dev This function can only be called by governance or an authorized entity.
function disburse(uint256 amount) public onlyGov {
// collect tokens/coin token and send it to treasury
// collect native token and send it to treasury
address treasury = getTreasuryAddress();
treasury.disburst(amount); // sent..
treasury.disburse(amount); // sent..
emit FeesDisbursed(treasury, amount);
}

Expand Down Expand Up @@ -208,7 +202,7 @@ contract Syndication is
// the contract manager;
address manager = IDistributor(distributor).getManager();
// Persist the enrollment payment in case the distributor quits before approval
_setEnrollment(manager, msg.value);
_setLedgerEntry(manager, msg.value, address(0));
// Set the distributor as pending approval
_register(uint160(distributor));
emit Registered(distributor);
Expand All @@ -221,19 +215,20 @@ contract Syndication is
function quit(
address distributor
) public nonReentrant validContractOnly(distributor) {
address manager = IDistributor(distributor).getManager(); // the contract manager
uint256 registeredAmount = enrollmentFees[manager]; // Wei
address manager = _msgSender(); // the sender is expected to be the manager..
uint256 registeredAmount = getLedgerEntry(manager); // Wei, etc..
if (registeredAmount == 0)
revert FailDuringQuit("Invalid distributor enrollment.");
revert FailDuringQuit("Invalid distributor/manager enrollment.");

// eg: (100 * bps) / BPS_MAX
uint256 penal = registeredAmount.perOf(penaltyRate);
uint256 res = registeredAmount - penal;

_setEnrollment(manager, 0);

// reset ledger..
_setLedgerEntry(manager, 0, address(0));
_quit(uint160(distributor));
// rollback partial payment..
manager.disburst(res);
manager.disburse(res);
emit Resigned(distributor);
}

Expand All @@ -253,7 +248,9 @@ contract Syndication is
function approve(
address distributor
) public onlyGov validContractOnly(distributor) {
_setEnrollment(IDistributor(distributor).getManager(), 0);
address manager = IDistributor(distributor).getManager();
// reset ledger..
_setLedgerEntry(manager, 0, address(0));
_approve(uint160(distributor));
enrollmentsCount++;
emit Approved(distributor);
Expand All @@ -269,9 +266,9 @@ contract Syndication is
) public override onlyGov {}

/// @inheritdoc IDisburser
/// @notice Withdraw funds of a specific token from the contract and sends them to the treasury.
/// @param token The address of the token.
/// @param amount The amount of tokens to withdraw.
/// @dev Only callable by an admin.
function withdraw(uint256 amount, address token) public onlyAdmin {}
/// @notice Disburses tokens from the contract to a specified address.
/// @param amount The amount of tokens to disburse.
/// @param token The address of the ERC20 token to disburse tokens.
/// @dev This function can only be called by governance or an authorized entity.
function disburse(uint256 amount, address token) public onlyGov {}
}
23 changes: 13 additions & 10 deletions contracts/Treasury.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "contracts/base/upgradeable/GovernableUpgradeable.sol";
import "contracts/interfaces/IFeesManager.sol";
import "contracts/interfaces/IDisburser.sol";
import "contracts/interfaces/IFundsManager.sol";

/// @title Treasury Contract
/// @dev This contract is designed to manage funds and token transfers,
Expand All @@ -15,7 +15,7 @@ contract Treasury is
Initializable,
UUPSUpgradeable,
GovernableUpgradeable,
IDisburser
IFundsManager
{
/// @dev Constructor that disables initializers to prevent the implementation contract from being initialized.
/// @notice This constructor prevents the implementation contract from being initialized.
Expand Down Expand Up @@ -45,13 +45,16 @@ contract Treasury is
__Governable_init();
}


/// @notice Withdraws the specified amount of Ether from the contract.
/// @param amount The amount of Ether to withdraw.
function withdraw(uint256 amount) public override onlyGov {}

/// @notice Withdraws the specified amount of the specified token from the contract.
/// @notice Withdraws tokens from the contract to a specified recipient's address.
/// @param recipient The address that will receive the withdrawn tokens.
/// @param amount The amount of tokens to withdraw.
/// @param token The address of the token to withdraw.
function withdraw(uint256 amount, address token) public onlyGov {}
/// @param token The address of the ERC20 token to withdraw, or address(0) to withdraw native tokens.
/// @dev This function can only be called by the owner of the contract or an authorized entity.
function withdraw(
address recipient,
uint256 amount,
address token
) public override onlyGov {}

// TODO multisignature withdraw
}
16 changes: 6 additions & 10 deletions contracts/base/upgradeable/FeesManagerUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ abstract contract FeesManagerUpgradeable is Initializable, IFeesManager {
* @notice Internal function to get the fees storage.
* @return $ The fees storage.
*/
function _getFeesStorage()
private
pure
returns (FeesStorage storage $)
{
function _getFeesStorage() private pure returns (FeesStorage storage $) {
assembly {
$.slot := FEES_SLOT
}
Expand Down Expand Up @@ -82,7 +78,7 @@ abstract contract FeesManagerUpgradeable is Initializable, IFeesManager {
revert InvalidBasisPointRange();
_;
}

/// @notice Modifier to ensure only valid nominal fees are used.
/// @param fees The fee amount to check.
modifier onlyNominalAllowed(uint256 fees) {
Expand All @@ -92,6 +88,9 @@ abstract contract FeesManagerUpgradeable is Initializable, IFeesManager {
_;
}

/// @notice Function to receive native coin.
receive() external payable {}

/// @inheritdoc IFeesManager
/// @notice Gets the fees fee for the specified token.
/// @dev This method could return a basis points (bps) fee or a flat fee depending on the context of use.
Expand All @@ -110,10 +109,7 @@ abstract contract FeesManagerUpgradeable is Initializable, IFeesManager {
/// @param newFeesFee The new fees fee to set.
/// @param token The token to associate fees with. Use address(0) for the native token.
/// @notice Only the owner can call this function.
function _setFees(
uint256 newFeesFee,
address token
) internal virtual {
function _setFees(uint256 newFeesFee, address token) internal virtual {
FeesStorage storage $ = _getFeesStorage();
$._tokenFees[token] = newFeesFee;
$._tokenSupported[token] = true;
Expand Down
Loading

0 comments on commit 1a23b3f

Please sign in to comment.