Skip to content

Commit

Permalink
feat: allowed free deistribution
Browse files Browse the repository at this point in the history
  • Loading branch information
geolffreym committed Aug 19, 2024
1 parent 827aa97 commit d6fc2f8
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 56 deletions.
2 changes: 1 addition & 1 deletion contracts/Distributor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract Distributor is
__ERC165_init();
__Ownable_init(_owner);
__CurrencyManager_init();
__Fees_init(1, address(0));
__Fees_init(0, address(0));

if (bytes(_endpoint).length == 0) revert InvalidEndpoint();
endpoint = _endpoint;
Expand Down
33 changes: 18 additions & 15 deletions contracts/RightsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import "contracts/base/upgradeable/extensions/RightsManagerDelegationUpgradeable
import "contracts/interfaces/IRegistrableVerifiable.sol";
import "contracts/interfaces/IReferendumVerifiable.sol";
import "contracts/interfaces/IRightsManager.sol";
import "contracts/interfaces/IStrategy.sol";
import "contracts/interfaces/ILicense.sol";
import "contracts/interfaces/IDistributor.sol";
import "contracts/interfaces/IRepository.sol";
import "contracts/libraries/TreasuryHelper.sol";
Expand Down Expand Up @@ -86,6 +86,7 @@ contract RightsManager is
error InvalidNotApprovedContent();
error InvalidNotAllowedContent();
error InvalidUnknownContent();
error InvalidAlreadyRegisteredContent();
error NoFundsToWithdraw(address);
error NoDeal(string reason);

Expand Down Expand Up @@ -177,7 +178,7 @@ contract RightsManager is
}

/// @notice Allocates the specified amount across a distribution array and returns the remaining unallocated amount.
/// @dev Distributes the amount based on the provided distribution array.
/// @dev Distributes the amount based on the provided distribution array.
/// Ensures no more than 100 allocations and a minimum of 1% per distributor.
/// @param amount The total amount to be allocated.
/// @param currency The address of the currency being allocated.
Expand Down Expand Up @@ -356,6 +357,11 @@ contract RightsManager is
address to,
uint256 contentId
) external onlyApprovedContent(to, contentId) {
// if(ownerOf(contentId) == to){
// // if the owner is trying to re-mint, nothing happens..
// return;
// }

_mint(to, contentId);
emit RegisteredContent(contentId);
}
Expand Down Expand Up @@ -383,25 +389,25 @@ contract RightsManager is
}

/// @inheritdoc IRightsDelegable
/// @notice Delegates rights for a specific content ID to a grantee.
/// @notice Delegates rights for a specific content ID to a license validator.
/// @param validator The address of strategy license validator contract to delegate rights to.
/// @param contentId The content ID for which rights are being delegated.
function grantRights(
address validator,
uint256 contentId
) external onlyHolder(contentId) onlyStrategyContract(validator) {
) external onlyHolder(contentId) onlyLicenseContract(validator) {
_grantRights(validator, contentId);
emit RightsDelegated(validator, contentId);
}

/// @inheritdoc IRightsDelegable
/// @notice Delegates rights for a specific content ID to a grantee.
/// @notice Delegates rights for a specific content ID to a license validator.
/// @param validator The address of strategy license validator contract to revoke rights to.
/// @param contentId The content ID for which rights are being revoked.
function revokeRights(
address validator,
uint256 contentId
) external onlyHolder(contentId) onlyStrategyContract(validator) {
) external onlyHolder(contentId) onlyLicenseContract(validator) {
_revokeRights(validator, contentId);
emit RightsRevoked(validator, contentId);
}
Expand All @@ -425,16 +431,15 @@ contract RightsManager is
if (!isEligibleForDistribution(contentId))
revert InvalidNotAllowedContent();

// the sender MUST be a IStrategy license advocate/validator
// the sender MUST be a ILicense advocate/validator
address advocate = _msgSender();
IStrategy strategy = IStrategy(advocate);
ILicense license = ILicense(advocate);
IDistributor distributor = IDistributor(getCustodial(contentId));
T.Allocation memory alloc = strategy.allocation(account, contentId);
T.Allocation memory alloc = license.allocation(account, contentId);

// transaction details
uint256 amount = alloc.t9n.amount;
address currency = alloc.t9n.currency;

// The user, owner or delegated validator 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.
Expand All @@ -448,11 +453,9 @@ contract RightsManager is
if (deductions > total) revert NoDeal("The fees are too high.");
uint256 remaining = _allocate(total - deductions, currency, alloc.d10n);

address owner = ownerOf(contentId);
address manager = distributor.getManager();
// register amounts in ledger..
_sumLedgerEntry(owner, remaining, currency);
_sumLedgerEntry(manager, acceptedSplit, currency);
// register split distribution in ledger..
_sumLedgerEntry(ownerOf(contentId), remaining, currency);
_sumLedgerEntry(distributor.getManager(), acceptedSplit, currency);
_grantAccess(account, contentId, advocate);
emit GrantedAccess(account, contentId);
}
Expand Down
10 changes: 4 additions & 6 deletions contracts/base/upgradeable/FeesManagerUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,24 @@ abstract contract FeesManagerUpgradeable is Initializable, IFeesManager {
/// @param token The address of the token to check.
modifier onlySupportedToken(address token) {
FeesStorage storage $ = _getFeesStorage();
// fees == 0 is default for uint256.
// address(0) is equivalent to native token if fees > 0
if (!$._tokenSupported[token]) revert InvalidUnsupportedToken(token);
_;
}

/// @notice Modifier to ensure only valid basis points are used.
/// @param fees The fee amount to check.
modifier onlyBasePointsAllowed(uint256 fees) {
// if fees < 1 = 0.01% || fees basis > 10_000 = 100%
if (fees < 1 || fees > C.BPS_MAX)
// fees basis > 10_000 = 100%
if (fees > C.BPS_MAX)
revert InvalidBasisPointRange();
_;
}

/// @notice Modifier to ensure only valid nominal fees are used.
/// @param fees The fee amount to check.
modifier onlyNominalAllowed(uint256 fees) {
// if fees < 1% || fees > 100%
if (fees < 1 || fees > C.SCALE_FACTOR)
// fees > 100%
if (fees > C.SCALE_FACTOR)
revert InvalidNominalRange();
_;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol";
import "contracts/interfaces/IRightsAccessController.sol";
import "contracts/interfaces/IStrategy.sol";
import "contracts/interfaces/ILicense.sol";
import "contracts/libraries/Types.sol";

/// @title Rights Manager Content Access Upgradeable
/// @notice This abstract contract manages content access control using a license
/// validator contract that must implement the IStrategy interface.
/// validator contract that must implement the ILicense interface.
abstract contract RightsManagerContentAccessUpgradeable is
Initializable,
IRightsAccessController
{
using ERC165Checker for address;

/// @dev The interface ID for IStrategy, used to verify that a validator contract implements the correct interface.
/// @dev The interface ID for ILicense, used to verify that a validator contract implements the correct interface.
bytes4 private constant INTERFACE_STRATEGY_VALIDATOR =
type(IStrategy).interfaceId;
type(ILicense).interfaceId;

/// @custom:storage-location erc7201:rightscontentaccess.upgradeable
/// @dev Storage struct for the access control list (ACL) that maps content IDs and accounts to validator contracts.
Expand All @@ -45,17 +45,17 @@ abstract contract RightsManagerContentAccessUpgradeable is
}
}

/// @dev Error thrown when the validator contract does not implement the IStrategy interface.
/// @dev Error thrown when the validator contract does not implement the ILicense interface.
error InvalidStrategyContract(address strategy);

/**
* @dev Modifier to check that a strategy validator contract implements the IStrategy interface.
* @param strategy The address of the strategy validator contract.
* @dev Modifier to check that a license contract implements the ILicense interface.
* @param license The address of the license validator contract.
* Reverts if the validator does not implement the required interface.
*/
modifier onlyStrategyContract(address strategy) {
if (!strategy.supportsInterface(INTERFACE_STRATEGY_VALIDATOR)) {
revert InvalidStrategyContract(strategy);
modifier onlyLicenseContract(address license) {
if (!license.supportsInterface(INTERFACE_STRATEGY_VALIDATOR)) {
revert InvalidStrategyContract(license);
}
_;
}
Expand All @@ -65,7 +65,7 @@ abstract contract RightsManagerContentAccessUpgradeable is
* @dev The function associates a content ID and account with a validator contract in the ACL storage.
* @param account The address of the account to be granted access.
* @param contentId The ID of the content for which access is being granted.
* @param validator The address of the validator contract that will be used to validate access.
* @param validator The address of the license validator contract that will be used to validate access.
*/
function _grantAccess(
address account,
Expand All @@ -92,7 +92,7 @@ abstract contract RightsManagerContentAccessUpgradeable is
address strategyValidator = $._acl[contentId][account];
// if the access is not registered, return false.
if (strategyValidator == address(0)) return false;
// The approved method is called and executed according to the IStrategy specification.
return IStrategy(strategyValidator).license(account, contentId);
// The approved method is called and executed according to the ILicense specification.
return ILicense(strategyValidator).terms(account, contentId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
pragma solidity ^0.8.24;
import "contracts/libraries/Types.sol";

/// @title IStrategy
/// @notice Interface for managing access to content based on conditions,
/// @title ILicense
/// @notice Interface for managing access to content based on licensing terms,
/// transactions, and distribution of royalties or fees.
interface IStrategy {
/// @notice Verify whether the license for an account and content ID is still valid
/// @param account The address of the account to approve.
/// @param contentId The content ID to approve against.
function license(
interface ILicense {
/// @notice Verify whether the access terms for an account and content ID are satisfied
/// @param account The address of the account to check.
/// @param contentId The content ID to check against.
function terms(
address account,
uint256 contentId
) external view returns (bool);

/// @notice Retrieves the allocation spec to distribute the royalties or fees.
/// @notice Retrieves the allocation specification to distribute the royalties or fees.
/// @param account The address of the account initiating the transaction.
/// @param contentId The content ID related to the transaction.
function allocation(
Expand Down
Loading

0 comments on commit d6fc2f8

Please sign in to comment.