Skip to content

Commit 9218fcc

Browse files
committed
test: fixed tests and added council logics
1 parent ef60667 commit 9218fcc

22 files changed

Lines changed: 203 additions & 384 deletions

contracts/access/AccessManager.sol

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ contract AccessManager is Initializable, UUPSUpgradeable, AccessManagerUpgradeab
4242
// Handles protocol upgrades, pause mechanisms, and operational role assignments.
4343
// - MOD_ROLE: Managed by a smart account or council.
4444
// Approves policy submissions and moderates hook operations.
45-
// - VAL_ROLE: Managed by a smart account or council.
46-
// Participates in governance referenda for content curation/validation.
47-
// - NOD_ROLE: Managed by a smart account or council.
45+
// - CONTENT_COUNCIL_ROLE: Managed by a smart account or council.
46+
// Participates in governance referenda for content curation.
47+
// - NODE_VALIDATOR_ROLE: Managed by a smart account or council.
4848
// Participates in governance referenda for nodes validation.
4949
//
5050
// Individual/Contract Based Roles:
@@ -62,18 +62,19 @@ contract AccessManager is Initializable, UUPSUpgradeable, AccessManagerUpgradeab
6262
│ │
6363
│ └── OPS_ROLE (Internal Contract Role)
6464
65-
├── VAL_ROLE (Smart Account / Council)
65+
├── CONTENT_COUNCIL_ROLE (Smart Account / Council)
6666
67-
├── NOD_ROLE (Smart Account / Council)
67+
├── NODE_VALIDATOR_ROLE (Smart Account / Council)
6868
6969
├── VER_ROLE (Individual Trusted Creator)
7070
*/
7171

72-
_setRoleAdmin(C.VER_ROLE, C.GOV_ROLE);
73-
_setRoleAdmin(C.VAL_ROLE, C.GOV_ROLE);
74-
_setRoleAdmin(C.NOD_ROLE, C.GOV_ROLE);
7572
_setRoleAdmin(C.MOD_ROLE, C.ADMIN_ROLE);
7673
_setRoleAdmin(C.OPS_ROLE, C.ADMIN_ROLE);
74+
75+
_setRoleAdmin(C.VER_ROLE, C.GOV_ROLE);
76+
_setRoleAdmin(C.NODE_VALIDATOR_ROLE, C.GOV_ROLE);
77+
_setRoleAdmin(C.CONTENT_COUNCIL_ROLE, C.GOV_ROLE);
7778
}
7879

7980
// TODO pause protocol based on permission and roles

contracts/assets/AssetOwnership.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ contract AssetOwnership is
143143
/// @notice Transfers an asset to a new owner.
144144
/// @param to The address of the new owner.
145145
/// @param assetId The unique identifier of the asset being transferred.
146-
function transfer(address to, uint256 assetId) external {
146+
function transfer(address to, uint256 assetId) external onlyOwner(assetId) {
147147
_transfer(msg.sender, to, assetId);
148148
emit TransferredAsset(msg.sender, to, assetId);
149149
}

contracts/core/interfaces/custody/ICustodianExpirable.sol

Lines changed: 0 additions & 15 deletions
This file was deleted.

contracts/core/interfaces/custody/ICustodianInspectable.sol

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ pragma solidity 0.8.26;
44
/// @title ICustodianInspectable
55
/// @dev Interface for retrieving custodian enrollment data.
66
interface ICustodianInspectable {
7-
/// @notice Retrieves the enrollment deadline for a custodian.
8-
/// @param custodian The address of the custodian.
9-
/// @return The enrollment deadline timestamp.
10-
function getEnrollmentDeadline(address custodian) external view returns (uint256);
11-
127
/// @notice Retrieves the total number of enrollments.
138
/// @return The number of enrollments.
149
function getEnrollmentCount() external view returns (uint256);

contracts/core/interfaces/custody/ICustodianReferendum.sol

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// NatSpec format convention - https://docs.soliditylang.org/en/v0.5.10/natspec-format.html
33
pragma solidity 0.8.26;
44

5-
import { ICustodianExpirable } from "@synaps3/core/interfaces/custody/ICustodianExpirable.sol";
65
import { ICustodianRegistrable } from "@synaps3/core/interfaces/custody/ICustodianRegistrable.sol";
76
import { ICustodianInspectable } from "@synaps3/core/interfaces/custody/ICustodianInspectable.sol";
87
import { ICustodianVerifiable } from "@synaps3/core/interfaces/custody/ICustodianVerifiable.sol";
@@ -13,7 +12,6 @@ import { ICustodianRevokable } from "@synaps3/core/interfaces/custody/ICustodian
1312
interface ICustodianReferendum is
1413
ICustodianRegistrable,
1514
ICustodianVerifiable,
16-
ICustodianExpirable,
1715
ICustodianInspectable,
1816
ICustodianRevokable
1917
{}

contracts/core/interfaces/custody/ICustodianRegistrable.sol

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@ pragma solidity 0.8.26;
77
/// @dev This interface indirectly implements the FSM defined in `IQuorum` using `QuorumUpgradeable`.
88
/// Functions here are semantically equivalent to the FSM transitions: register → approve.
99
interface ICustodianRegistrable {
10-
/// @notice Registers data with a given identifier.
11-
/// @param proof The unique identifier of the agreement to be enforced.
12-
/// @param currency The currency used to pay enrollment.
13-
function register(uint256 proof, address currency) external;
10+
/// @notice Registers a custodian to be approved by council.
11+
/// @param custodian The address of the custodian to register.
12+
function register(address custodian) external;
1413

15-
/// @notice Approves the data associated with the given identifier.
14+
/// @notice Approves the data custodian with the given address.
1615
/// @param custodian The address of the custodian to approve.
1716
function approve(address custodian) external;
1817
}

contracts/core/interfaces/policies/IPolicy.sol

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ import { T } from "@synaps3/core/primitives/Types.sol";
88
/// @notice Interface for managing access to content based on licensing terms.
99
/// @dev This interface defines the basic information about the policy, such as its name and description.
1010
interface IPolicy {
11-
/// @notice Returns the string identifier associated with the policy.
12-
/// @dev This function provides a way to identify the specific policy being used.
13-
function name() external pure returns (string memory);
14-
15-
/// @notice Returns the business/strategy model implemented by the policy.
16-
/// @dev A description of the business model as bytes, allowing more complex representations (such as encoded data).
17-
function description() external pure returns (string memory);
18-
1911
/// @notice Initializes the policy with specific data for a given holder.
2012
/// @dev Only the Rights Policies Authorizer contract has permission to call this function.
2113
/// @param holder The address of the holder for whom the policy is being initialized.
@@ -46,4 +38,12 @@ interface IPolicy {
4638
/// @notice Retrieves the address of the attestation provider.
4739
/// @return The address of the provider associated with the policy.
4840
function getAttestationProvider() external view returns (address);
41+
42+
/// @notice Returns the string identifier associated with the policy.
43+
/// @dev This function provides a way to identify the specific policy being used.
44+
function name() external pure returns (string memory);
45+
46+
/// @notice Returns the business/strategy model implemented by the policy.
47+
/// @dev A description of the business model as bytes, allowing more complex representations (such as encoded data).
48+
function description() external pure returns (string memory);
4949
}

contracts/core/primitives/Constants.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ library C {
1616
uint64 internal constant MOD_ROLE = 2; // moderator role
1717
uint64 internal constant VER_ROLE = 3; // account verified role
1818
uint64 internal constant OPS_ROLE = 4; // operations roles
19-
uint64 internal constant VAL_ROLE = 5; // content validation/curation roles
20-
uint64 internal constant NOD_ROLE = 6; // nodes validations roles
19+
20+
uint64 internal constant CONTENT_COUNCIL_ROLE = 5; // content validation/curation roles
21+
uint64 internal constant NODE_VALIDATOR_ROLE = 6; // nodes validations roles
2122

2223
bytes32 internal constant REFERENDUM_SUBMIT_TYPEHASH =
2324
keccak256("Submission(uint256 assetId, address initiator, uint256 nonce)");

contracts/custody/CustodianImpl.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ contract CustodianImpl is
4848
/// @dev Ensures that the provided endpoint is valid and initializes ERC165 and Ownable contracts.
4949
function initialize(string calldata endpoint, address owner) external initializer {
5050
if (bytes(endpoint).length == 0) revert InvalidEndpoint();
51+
5152
__ERC165_init();
5253
__Ownable_init(owner);
5354
_endpoint = endpoint;

contracts/custody/CustodianReferendum.sol

Lines changed: 13 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,8 @@ import { Initializable } from "@openzeppelin/contracts-upgradeable/proxy/utils/I
77
// solhint-disable-next-line max-line-length
88
import { AccessControlledUpgradeable } from "@synaps3/core/primitives/upgradeable/AccessControlledUpgradeable.sol";
99
import { QuorumUpgradeable } from "@synaps3/core/primitives/upgradeable/QuorumUpgradeable.sol";
10-
import { IAgreementSettler } from "@synaps3/core/interfaces/financial/IAgreementSettler.sol";
11-
import { IFeeSchemeValidator } from "@synaps3/core/interfaces/economics/IFeeSchemeValidator.sol";
1210
import { ICustodianReferendum } from "@synaps3/core/interfaces/custody/ICustodianReferendum.sol";
1311
import { ICustodianFactory } from "@synaps3/core/interfaces/custody/ICustodianFactory.sol";
14-
import { FinancialOps } from "@synaps3/core/libraries/FinancialOps.sol";
1512
import { T } from "@synaps3/core/primitives/Types.sol";
1613

1714
/// @title CustodianReferendum
@@ -24,27 +21,17 @@ contract CustodianReferendum is
2421
UUPSUpgradeable,
2522
QuorumUpgradeable,
2623
AccessControlledUpgradeable,
27-
ICustodianReferendum,
28-
IFeeSchemeValidator
24+
ICustodianReferendum
2925
{
30-
using FinancialOps for address;
31-
3226
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
33-
IAgreementSettler public immutable AGREEMENT_SETTLER;
3427
ICustodianFactory public immutable CUSTODIAN_FACTORY;
3528
//slither-disable-end naming-convention
3629

37-
/// @dev Defines the expiration period for enrollment, determining how long a custodian remains active.
38-
uint256 private _expirationPeriod;
3930
/// @dev Tracks the number of active enrollments within the system.
4031
uint256 private _enrollmentsCount;
41-
/// @dev Maps a custodian's address to their respective enrollment deadline timestamp.
42-
mapping(address => uint256) private _enrollmentDeadline;
43-
4432
/// @notice Event emitted when a custodian is registered
4533
/// @param custodian The address of the registered custodian
46-
/// @param paidFees The amount of fees that were paid upon registration
47-
event Registered(address indexed custodian, uint256 paidFees);
34+
event Registered(address indexed custodian);
4835

4936
/// @notice Event emitted when a custodian is approved
5037
/// @param custodian The address of the approved custodian
@@ -54,34 +41,25 @@ contract CustodianReferendum is
5441
/// @param custodian The address of the revoked custodian
5542
event Revoked(address indexed custodian);
5643

57-
/// @notice Emitted when a new period is set
58-
/// @param newPeriod The new period that is set, could be in seconds, blocks, or any other unit
59-
event PeriodSet(uint256 newPeriod);
60-
6144
/// @notice Error thrown when the custodian is not recognized by the factory.
6245
/// @param custodian The address of the unregistered custodian contract.
6346
error UnregisteredCustodian(address custodian);
6447

65-
/// @notice Error thrown when the custodian does not match the agreement's registered party.
66-
/// @param custodian The custodian provided for the operation.s
67-
error CustodianAgreementMismatch(address custodian);
68-
6948
/// @notice Modifier to ensure the custodian was deployed through the trusted factory.
7049
/// @param custodian The address of the custodian contract to verify.
7150
modifier onlyValidCustodian(address custodian) {
7251
// ensure the custodian was deployed through the trusted factory and is known to the protocol
7352
if (!CUSTODIAN_FACTORY.isRegistered(custodian)) {
74-
revert UnregisteredCustodian(msg.sender);
53+
revert UnregisteredCustodian(custodian);
7554
}
7655
_;
7756
}
7857

7958
/// @custom:oz-upgrades-unsafe-allow constructor
80-
constructor(address agreementSettler, address custodianFactory) {
59+
constructor(address custodianFactory) {
8160
/// https://forum.openzeppelin.com/t/what-does-disableinitializers-function-mean/28730/5
8261
/// https://forum.openzeppelin.com/t/uupsupgradeable-vulnerability-post-mortem/15680
8362
_disableInitializers();
84-
AGREEMENT_SETTLER = IAgreementSettler(agreementSettler);
8563
CUSTODIAN_FACTORY = ICustodianFactory(custodianFactory);
8664
}
8765

@@ -90,54 +68,19 @@ contract CustodianReferendum is
9068
__Quorum_init();
9169
__UUPSUpgradeable_init();
9270
__AccessControlled_init(accessManager);
93-
// 6 months initially..
94-
_expirationPeriod = 180 days;
95-
}
96-
97-
/// @notice Checks if the given fee scheme is supported in this context.
98-
/// @param scheme The fee scheme to validate.
99-
/// @return True if the scheme is supported.
100-
function isFeeSchemeSupported(T.Scheme scheme) external pure returns (bool) {
101-
// support only FLAT scheme
102-
return scheme == T.Scheme.FLAT;
103-
}
104-
105-
/// @notice Retrieves the current expiration period for enrollments or registrations.
106-
function getExpirationPeriod() external view returns (uint256) {
107-
return _expirationPeriod;
108-
}
109-
110-
/// @notice Retrieves the enrollment deadline for a custodian.
111-
/// @param custodian The address of the custodian.
112-
function getEnrollmentDeadline(address custodian) external view returns (uint256) {
113-
return _enrollmentDeadline[custodian];
114-
}
115-
116-
/// @notice Retrieves the total number of enrollments.
117-
function getEnrollmentCount() external view returns (uint256) {
118-
return _enrollmentsCount;
11971
}
12072

12173
/// @notice Checks if the entity is active.
12274
/// @dev This function verifies the active status of the custodian.
12375
/// @param custodian The custodian's address to check.
12476
function isActive(address custodian) external view returns (bool) {
125-
// TODO a renovation mechanism is needed to update the enrollment time
126-
/// It ensures that custodians remain engaged and do not become inactive for extended periods.
127-
/// The enrollment deadline enforces a time-based mechanism where custodians must renew
128-
/// their registration to maintain their active status. This prevents dormant custodians
129-
/// from continuing to benefit from the protocol without contributing.
130-
13177
// TODO add stateful management to custodians contract, the custodian can
13278
// change his state to "maintenance mode" or "inactive" if its facing issues
13379
// in that way the custodian is omitted during load balancing.
13480
// in this line we can check if the custodian contract is active custodian.isActive()
13581
// this is important feature if the custodians want to avoid harm reputation
13682

137-
// This mechanism helps to verify the availability of the custodian,
138-
// forcing recurrent registrations and ensuring ongoing participation.
139-
bool notExpiredDeadline = _enrollmentDeadline[custodian] > block.timestamp;
140-
return _status(uint160(custodian)) == T.Status.Active && notExpiredDeadline;
83+
return _status(uint160(custodian)) == T.Status.Active;
14184
}
14285

14386
/// @notice Checks if the entity is waiting.
@@ -154,61 +97,34 @@ contract CustodianReferendum is
15497
return _status(uint160(custodian)) == T.Status.Blocked;
15598
}
15699

157-
/// @notice Registers a custodian by sending a payment to the contract.
158-
/// @param proof The unique identifier of the agreement to be enforced.
100+
/// @notice Registers a custodian to be approved by council.
159101
/// @param custodian The address of the custodian to register.
160-
function register(uint256 proof, address custodian) external onlyValidCustodian(custodian) {
161-
/// TODO penalize invalid endpoints, and revoked during referendum
162-
// !IMPORTANT:
163-
// Fees act as a mechanism to prevent abuse or spam by users
164-
// when submitting custodians for approval. This discourages users from
165-
// making frivolous or excessive registrations without genuine intent.
166-
//
167-
// Additionally, the fees establish a foundation of real interest and commitment
168-
// from the custodian. This ensures that only those who see value in the protocol
169-
// and are willing to contribute to its ecosystem will participate.
170-
//
171-
// The collected fees are used to support the protocol's operations, aligning
172-
// individual actions with the broader sustainability of the network.
173-
174-
// IMPORTANT:
175-
// The expected fees are locked in the agreement, based on the custodians fees defined by the tollgate.
176-
// If the fee amount is insufficient, the transaction will revert during agreement creation.
177-
// Only valid agreements can be settled; the validity is guaranteed by the proof.
178-
T.Agreement memory agreement = AGREEMENT_SETTLER.settleAgreement(proof, msg.sender);
179-
if (agreement.parties[0] != custodian) {
180-
revert CustodianAgreementMismatch(custodian);
181-
}
182-
102+
function register(address custodian) external onlyValidCustodian(custodian) {
183103
// register custodian as pending approval
184104
_register(uint160(custodian));
185105
// set the custodian active enrollment period..
186-
// after this time the custodian is considered inactive and cannot collect his profits...
187-
_enrollmentDeadline[custodian] = block.timestamp + _expirationPeriod;
188-
emit Registered(custodian, agreement.fees);
106+
emit Registered(custodian);
189107
}
190108

191109
/// @notice Approves a custodian's registration.
192110
/// @param custodian The address of the custodian to approve.
193111
function approve(address custodian) external restricted {
194-
_enrollmentsCount++;
195112
_approve(uint160(custodian));
113+
_enrollmentsCount++;
196114
emit Approved(custodian);
197115
}
198116

199117
/// @notice Revokes the registration of a custodian.
200118
/// @param custodian The address of the custodian to revoke.
201119
function revoke(address custodian) external restricted {
202-
_enrollmentsCount--;
203120
_revoke(uint160(custodian));
121+
_enrollmentsCount--;
204122
emit Revoked(custodian);
205123
}
206124

207-
/// @notice Sets a new expiration period for an enrollment or registration.
208-
/// @param newPeriod The new expiration period, in seconds.
209-
function setExpirationPeriod(uint256 newPeriod) external restricted {
210-
_expirationPeriod = newPeriod;
211-
emit PeriodSet(newPeriod);
125+
/// @notice Retrieves the total number of enrollments.
126+
function getEnrollmentCount() external view returns (uint256) {
127+
return _enrollmentsCount;
212128
}
213129

214130
/// @notice Function that should revert when msg.sender is not authorized to upgrade the contract.

0 commit comments

Comments
 (0)