Skip to content

Commit

Permalink
refactor: removed timestamp from events
Browse files Browse the repository at this point in the history
  • Loading branch information
geolffreym committed Jan 9, 2025
1 parent 47636f5 commit b36aadb
Show file tree
Hide file tree
Showing 16 changed files with 414 additions and 187 deletions.
187 changes: 187 additions & 0 deletions broadcast/04_Deploy_Economics_Tollgate.s.sol/80002/run-1736433298.json

Large diffs are not rendered by default.

110 changes: 55 additions & 55 deletions broadcast/04_Deploy_Economics_Tollgate.s.sol/80002/run-latest.json

Large diffs are not rendered by default.

142 changes: 71 additions & 71 deletions broadcast/05_Deploy_Economics_Treasury.s.sol/80002/run-latest.json

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions contracts/assets/AssetOwnership.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ contract AssetOwnership is

/// @dev Emitted when a new asset is registered on the platform.
/// @param owner The address of the creator or owner of the asset being registered.
/// @param timestamp The timestamp indicating when the asset was registered.
/// @param assetId The unique identifier for the registered asset.
event RegisteredAsset(address indexed owner, uint256 indexed timestamp, uint256 assetId);
event RegisteredAsset(address indexed owner, uint256 assetId);

/// @dev Error indicating that an operation attempted to reference content that has not been approved.
/// This error is triggered when the asset being accessed or referenced is not in an approved state.
Expand Down Expand Up @@ -91,7 +90,7 @@ contract AssetOwnership is
/// @param assetId The unique identifier for the asset, which serves as the NFT ID.
function registerAsset(address to, uint256 assetId) external onlyApprovedAsset(to, assetId) {
_mint(to, assetId); // register asset as 721 token
emit RegisteredAsset(to, block.timestamp, assetId);
emit RegisteredAsset(to, assetId);
}

/// @dev Internal function to update the ownership of a token.
Expand Down
20 changes: 8 additions & 12 deletions contracts/assets/AssetReferendum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,19 @@ contract AssetReferendum is
/// @dev Event emitted when a content is submitted for referendum.
/// @param assetId The ID of the asset that has been submitted.
/// @param initiator The address of the initiator who submitted the asset.
/// @param timestamp The timestamp indicating when the asset was submitted.
event Submitted(address indexed initiator, uint256 timestamp, uint256 assetId);
event Submitted(address indexed initiator, uint256 assetId);

/// @dev Event emitted when a content is approved.
/// @param assetId The ID of the asset that has been approved.
/// @param timestamp The timestamp indicating when the asset was approved.
event Approved(uint256 assetId, uint256 timestamp);
event Approved(uint256 assetId);

/// @dev Event emitted when a content is revoked.
/// @param assetId The ID of the asset that has been revoked.
/// @param timestamp The timestamp indicating when the asset was revoked.
event Revoked(uint256 assetId, uint256 timestamp);
event Revoked(uint256 assetId);

/// @dev Event emitted when a content is rejected.
/// @param assetId The ID of the asset that has been rejected.
/// @param timestamp The timestamp indicating when the asset was revoked.
event Rejected(uint256 assetId, uint256 timestamp);
event Rejected(uint256 assetId);

// /// @dev Error thrown when the signature of the asset submission is invalid.
// error InvalidSubmissionSignature();
Expand Down Expand Up @@ -77,7 +73,7 @@ contract AssetReferendum is
function submit(uint256 assetId) external {
_register(assetId); // bundled check-effects-interaction
_submissions[msg.sender].add(assetId);
emit Submitted(msg.sender, block.timestamp, assetId);
emit Submitted(msg.sender, assetId);
}

// /// @notice Submits a content proposition for referendum with a signature.
Expand All @@ -101,21 +97,21 @@ contract AssetReferendum is
/// @param assetId The ID of the asset to be revoked.
function revoke(uint256 assetId) external restricted {
_revoke(assetId); // bundled check-effects-interaction
emit Revoked(assetId, block.timestamp);
emit Revoked(assetId);
}

/// @notice Reject a content proposition.
/// @param assetId The ID of the asset to be rejected.
function reject(uint256 assetId) external restricted {
_block(assetId); // bundled check-effects-interaction
emit Rejected(assetId, block.timestamp);
emit Rejected(assetId);
}

/// @notice Approves a content proposition.
/// @param assetId The ID of the asset to be approved.
function approve(uint256 assetId) external restricted {
_approve(assetId); // bundled check-effects-interaction
emit Approved(assetId, block.timestamp);
emit Approved(assetId);
}

/// @notice Checks if the asset is approved.
Expand Down
9 changes: 9 additions & 0 deletions contracts/core/interfaces/rights/IRightsPolicyManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ pragma solidity 0.8.26;
/// @notice Interface for managing content rights policies.
/// @dev This interface handles retrieving/managing/registering policies.
interface IRightsPolicyManager {
/// @notice Retrieves the list of policies associated with a specific account and content ID.
/// @param account The address of the account for which policies are being retrieved.
function getPolicies(address account) external view returns (address[] memory);

/// @notice Retrieves the address of the Rights Policies Authorizer contract.
/// @return The address of the contract responsible for authorizing rights policies.
function getPolicyAuthorizer() external view returns (address);
Expand All @@ -16,6 +20,11 @@ interface IRightsPolicyManager {
/// @return policyAddress Address of the matching policy or zero if none found.
function getActivePolicy(address account, bytes memory criteria) external view returns (bool, address);

/// @notice Retrieves the list of active policies matching the criteria for an account.
/// @param account Address of the account to evaluate.
/// @param criteria Encoded data containing parameters for access verification. eg: assetId, holder
function getActivePolicies(address account, bytes memory criteria) external view returns (address[] memory);

/// @notice Verifies if a specific policy is active for the provided account and content.
/// @param account The address of the user whose compliance is being evaluated.
/// @param policy The address of the policy contract to check compliance against.
Expand Down
11 changes: 11 additions & 0 deletions contracts/core/libraries/LoopOps.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,15 @@ library LoopOps {
j = i + 1;
}
}

/// @notice Decrements a given integer by 1 without overflow checks.
/// @dev The `unchecked` keyword is used to skip overflow checks, reducing gas costs.
/// This is safe when you know that the variable `i` will not reach the minimum value of `uint256`.
/// @param i The integer to decrement.
/// @return j The decremented integer.
function uncheckedDec(uint256 i) internal pure returns (uint256 j) {
unchecked {
j = i - 1;
}
}
}
5 changes: 2 additions & 3 deletions contracts/rights/RightsAssetCustodian.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ contract RightsAssetCustodian is Initializable, UUPSUpgradeable, AccessControlle
/// @notice Emitted when custodial distribution rights are granted to a distributor.
/// @param newCustody The address of the distributor granted custodial rights.
/// @param rightsHolder The address of the asset's rights holder.
/// @param timestamp The timestamp indicating when the custodial rights were granted.
event CustodialGranted(address indexed newCustody, address indexed rightsHolder, uint256 timestamp);
event CustodialGranted(address indexed newCustody, address indexed rightsHolder);

/// @dev Error that is thrown when a content hash is already registered.
error InvalidInactiveDistributor();
Expand Down Expand Up @@ -78,7 +77,7 @@ contract RightsAssetCustodian is Initializable, UUPSUpgradeable, AccessControlle

_custodiansByHolder[msg.sender].add(distributor);
_holdersUnderCustodian[distributor].add(msg.sender);
emit CustodialGranted(distributor, msg.sender, block.timestamp);
emit CustodialGranted(distributor, msg.sender);
}

/// @notice Checks if the given distributor is a custodian for the specified content holder
Expand Down
10 changes: 4 additions & 6 deletions contracts/rights/RightsPolicyAuthorizer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ contract RightsPolicyAuthorizer is
/// @param policy The policy contract address granted rights.
/// @param holder The address of the asset rights holder.
/// @param data The data used to initialize the policy.
/// @param timestamp The timestamp indicating when the rights were granted.
event RightsGranted(address indexed policy, address indexed holder, uint256 timestamp, bytes data);
event RightsGranted(address indexed policy, address indexed holder, bytes data);

/// @notice Emitted when rights are revoked from a policy for content.
/// @param policy The policy contract address whose rights are being revoked.
/// @param holder The address of the asset rights holder.
/// @param timestamp The timestamp indicating when the rights were revoked.
event RightsRevoked(address indexed policy, address indexed holder, uint256 timestamp);
event RightsRevoked(address indexed policy, address indexed holder);

/// @dev Error thrown when a policy has not been audited or approved for operation.
/// @param policy The address of the unaudited policy.
Expand Down Expand Up @@ -77,14 +75,14 @@ contract RightsPolicyAuthorizer is
(bool success, ) = policy.call(abi.encodeCall(IPolicy.initialize, (msg.sender, data)));
if (!success) revert InvalidPolicyInitialization("Error during policy initialization call");
_authorizedPolicies[msg.sender].add(policy); // register policy as authorized for the authorizer
emit RightsGranted(policy, msg.sender, block.timestamp, data);
emit RightsGranted(policy, msg.sender, data);
}

/// @notice Revokes the delegation of rights to a policy contract.
/// @param policy The address of the policy contract whose rights delegation is being revoked.
function revokePolicy(address policy) external {
_authorizedPolicies[msg.sender].remove(policy);
emit RightsRevoked(policy, msg.sender, block.timestamp);
emit RightsRevoked(policy, msg.sender);
}

/// @dev Verify if the specified policy contract has been delegated the rights by the asset holder.
Expand Down
54 changes: 44 additions & 10 deletions contracts/rights/RightsPolicyManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,55 @@ contract RightsPolicyManager is Initializable, UUPSUpgradeable, AccessControlled
/// @param account Address of the account to evaluate.
/// @param criteria Encoded data containing parameters for access verification. eg: assetId, holder
function getActivePolicy(address account, bytes memory criteria) external view returns (bool, address) {
// https://docs.openzeppelin.com/contracts/5.x/api/utils#EnumerableSet-values-struct-EnumerableSet-AddressSet-
// This operation (.values()) will copy the entire storage to memory, which can be quite expensive.
// This is designed to mostly be used by view accessors that are queried without any gas fees.
// Developers should keep in mind that this function has an unbounded cost,
/// and using it as part of a state-changing function may render the function uncallable
/// if the set grows to a point where copying to memory consumes too much gas to fit in a block.
address[] memory policies = _closures[account].values();
address[] memory policies = getPolicies(account);
uint256 i = policies.length;

// Get the first active policy in LIFO order and return it
while (i > 0) {
address currentPolicy = policies[i - 1];
if (isActivePolicy(account, currentPolicy, criteria)) {
return (true, currentPolicy);
}

// safe unchecked
// limited to i > 0
i = i.uncheckedDec();
}

return (false, address(0));
}

/// @notice Retrieves the list of active policies matching the criteria for an account.
/// @param account Address of the account to evaluate.
/// @param criteria Encoded data containing parameters for access verification. eg: assetId, holder
function getActivePolicies(address account, bytes memory criteria) external view returns (address[] memory) {
address[] memory policies = getPolicies(account);
address[] memory filtered = new address[](policies.length);
uint256 policiesLen = policies.length;
uint256 j = 0; // filtered cursor

for (uint256 i = 0; i < policiesLen; i = i.uncheckedInc()) {
bool comply = isActivePolicy(account, policies[i], criteria);
if (comply) return (true, policies[i]);
if (!isActivePolicy(account, policies[i], criteria)) continue;
filtered[j] = policies[i];

// safe unchecked
// limited to i increment = max policy length
j = j.uncheckedDec();
}

return (false, address(0));
return filtered;
}

/// @notice Retrieves the list of policys associated with a specific account and content ID.
/// @param account The address of the account for which policies are being retrieved.
function getPolicies(address account) public view returns (address[] memory) {
// https://docs.openzeppelin.com/contracts/5.x/api/utils#EnumerableSet-values-struct-EnumerableSet-AddressSet-
// This operation will copy the entire storage to memory, which can be quite expensive.
// This is designed to mostly be used by view accessors that are queried without any gas fees.
// Developers should keep in mind that this function has an unbounded cost,
/// and using it as part of a state-changing function may render the function uncallable
/// if the set grows to a point where copying to memory consumes too much gas to fit in a block.
return _closures[account].values();
}

/// @notice Verifies if a specific policy is active for the provided account and criteria.
Expand Down
5 changes: 2 additions & 3 deletions contracts/syndication/DistributorFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ contract DistributorFactory is UpgradeableBeacon, Pausable, IDistributorFactory
/// @notice Event emitted when a new distributor is created.
/// @param distributorAddress Address of the newly created distributor.
/// @param endpoint Endpoint associated with the new distributor.
/// @param timestamp The timestamp indicating when the distributor was created.
event DistributorCreated(address indexed distributorAddress, string endpoint, uint256 timestamp);
event DistributorCreated(address indexed distributorAddress, string endpoint);

/// @notice Error to be thrown when attempting to register an already registered distributor.
error DistributorAlreadyRegistered();
Expand Down Expand Up @@ -63,7 +62,7 @@ contract DistributorFactory is UpgradeableBeacon, Pausable, IDistributorFactory
// initialize storage layout using Distributor contract impl..
bytes memory data = abi.encodeWithSignature("initialize(string,address)", endpoint, msg.sender);
address newContract = address(new BeaconProxy(address(this), data));
emit DistributorCreated(newContract, endpoint, block.timestamp);
emit DistributorCreated(newContract, endpoint);
return newContract;
}
}
20 changes: 8 additions & 12 deletions contracts/syndication/DistributorReferendum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,24 +45,20 @@ contract DistributorReferendum is

/// @notice Event emitted when a distributor is registered
/// @param distributor The address of the registered distributor
/// @param timestamp The timestamp indicating when the distributor was registered
/// @param paidFees The amount of fees that were paid upon registration
event Registered(address indexed distributor, uint256 timestamp, uint256 paidFees);
event Registered(address indexed distributor, uint256 paidFees);

/// @notice Event emitted when a distributor is approved
/// @param distributor The address of the approved distributor
/// @param timestamp The timestamp indicating when the distributor was approved
event Approved(address indexed distributor, uint256 timestamp);
event Approved(address indexed distributor);

/// @notice Event emitted when a distributor is revoked
/// @param distributor The address of the revoked distributor
/// @param timestamp The timestamp indicating when the distributor was revoked
event Revoked(address indexed distributor, uint256 timestamp);
event Revoked(address indexed distributor);

/// @notice Emitted when a new period is set
/// @param setBy The address that set the new period
/// @param newPeriod The new period that is set, could be in seconds, blocks, or any other unit
event PeriodSet(address indexed setBy, uint256 newPeriod);
event PeriodSet(uint256 newPeriod);

/// @notice Error thrown when a distributor contract is invalid
/// @param invalid The address of the distributor contract that is invalid
Expand Down Expand Up @@ -176,30 +172,30 @@ contract DistributorReferendum is
// set the distributor active enrollment period..
// after this time the distributor is considered inactive and cannot collect his profits...
_enrollmentDeadline[distributor] = block.timestamp + _expirationPeriod;
emit Registered(distributor, block.timestamp, fees);
emit Registered(distributor, fees);
}

/// @notice Approves a distributor's registration.
/// @param distributor The address of the distributor to approve.
function approve(address distributor) external restricted onlyValidDistributor(distributor) {
_enrollmentsCount++;
_approve(uint160(distributor));
emit Approved(distributor, block.timestamp);
emit Approved(distributor);
}

/// @notice Revokes the registration of a distributor.
/// @param distributor The address of the distributor to revoke.
function revoke(address distributor) external restricted onlyValidDistributor(distributor) {
_enrollmentsCount--;
_revoke(uint160(distributor));
emit Revoked(distributor, block.timestamp);
emit Revoked(distributor);
}

/// @notice Sets a new expiration period for an enrollment or registration.
/// @param newPeriod The new expiration period, in seconds.
function setExpirationPeriod(uint256 newPeriod) external restricted {
_expirationPeriod = newPeriod;
emit PeriodSet(msg.sender, newPeriod);
emit PeriodSet(newPeriod);
}

/// @notice Function that should revert when msg.sender is not authorized to upgrade the contract.
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@synaps3/protocol",
"version": "1.8.1",
"version": "1.9.0",
"description": "Core contracts for the Synapse Protocol",
"homepage": "https://github.com/Synaps3Protocol/protocol-core-v1#readme",
"bugs": {
Expand Down
2 changes: 1 addition & 1 deletion packages/types/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@synaps3/types",
"version": "1.8.1",
"version": "1.9.0",
"description": "Essential interfaces and types for Synapse Protocol.",
"homepage": "https://github.com/Synaps3Protocol/protocol-core-v1#readme",
"bugs": {
Expand Down
Loading

0 comments on commit b36aadb

Please sign in to comment.