Skip to content

Commit cac03b7

Browse files
committed
test: right asset custodian
1 parent c9ac330 commit cac03b7

File tree

14 files changed

+1227
-982
lines changed

14 files changed

+1227
-982
lines changed

.github/workflows/cov-badge.svg

Lines changed: 1 addition & 1 deletion
Loading

contracts/core/interfaces/economics/IFeesCollector.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pragma solidity 0.8.26;
77
/// @dev This interface defines the mechanism for transferring collected fees to the treasury.
88
interface IFeesCollector {
99
/// @notice Disburses funds from the contract to the treasury.
10-
/// @param currency The address of the ERC20 token to disburse tokens.
11-
function disburse(address currency) external returns (uint256);
10+
/// @param amount The amount of tokens to disburse.
11+
/// @param currency The address of the token to disburse tokens.
12+
function disburse(uint256 amount, address currency) external returns (uint256);
1213
}
Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,47 @@
11
// SPDX-License-Identifier: BUSL-1.1
22
pragma solidity 0.8.26;
33

4-
/// @title IRightsRedundancyManager
5-
/// @notice Interface for managing redundancy limits for custodians.
4+
/// @title IRightsAssetCustodianManager
5+
/// @notice Interface for managing custodian assignment priorities, redundancy limits, and weight calculations.
66
interface IRightsAssetCustodianManager {
77
/// @notice Sets a custom priority value for a specific custodian assigned to the caller.
88
/// @dev Influences the weighting in the balancing algorithm used to select custodians.
99
/// @param custodian The custodian whose priority is being set.
1010
/// @param priority The priority value to assign. Must be >= 1.
1111
function setPriority(address custodian, uint256 priority) external;
1212

13+
/// @notice Sets the maximum allowed number of custodians per holder.
14+
/// @param value The new maximum redundancy value.
15+
function setMaxAllowedRedundancy(uint256 value) external;
16+
1317
/// @notice Returns the maximum allowed number of custodians per holder.
1418
/// @return The maximum redundancy value.
1519
function getMaxAllowedRedundancy() external view returns (uint256);
1620

17-
/// @notice Sets the maximum allowed number of custodians per holder.
18-
/// @param value The new maximum redundancy value.
19-
function setMaxAllowedRedundancy(uint256 value) external;
21+
/// @notice Retrieves the priority level associated with a specific custodian and holder.
22+
/// @param custodian The address of the custodian whose priority is being queried.
23+
/// @param holder The address of the holder associated with the custodian.
24+
/// @return The priority level as a uint256 value.
25+
function getPriority(address custodian, address holder) external view returns (uint256);
26+
27+
/// @notice Returns a custodian selected by a probabilistic balancing algorithm.
28+
/// @dev The selection is based on priority, demand and economic weight (balance).
29+
/// @param holder The address of the asset holder requesting a custodian.
30+
/// @param currency The currency used to evaluate the custodian's balance.
31+
/// @return The selected custodian address.
32+
function getCustodian(address holder, address currency) external view returns (address);
33+
34+
/// @notice Calculates the weighted score of a custodian for a specific holder and currency.
35+
/// @dev Used to externally query the score that influences custodian selection.
36+
/// @param custodian The address of the custodian.
37+
/// @param holder The address of the rights holder.
38+
/// @param currency The token used to evaluate economic backing.
39+
/// @return The computed weight used in the balancing algorithm.
40+
function getWeight(address custodian, address holder, address currency) external view returns (uint256);
41+
42+
/// @notice Retrieves the total number of holders assigned to a custodian.
43+
/// @dev Represents the current load (demand) of a custodian in terms of assignments.
44+
/// @param custodian The custodian address to query.
45+
/// @return The number of holders currently assigned to the custodian.
46+
function getDemand(address custodian) external view returns (uint256);
2047
}

contracts/core/interfaces/rights/IRightsAssetCustodianVerifiable.sol

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pragma solidity 0.8.26;
44

55
/// @title IRightsAssetCustodianVerifiable
66
/// @notice Interface for verifying custodian assignments and querying custody-related data.
7-
/// @dev Includes read-access functions used in balancing and audit operations.
87
interface IRightsAssetCustodianVerifiable {
98
/// @notice Checks whether a custodian is currently assigned to a holder.
109
/// @dev Returns true only if the custodian is active and listed for the specified holder.
@@ -13,24 +12,5 @@ interface IRightsAssetCustodianVerifiable {
1312
/// @return True if `custodian` is valid and assigned to `holder`, false otherwise.
1413
function isCustodian(address custodian, address holder) external view returns (bool);
1514

16-
/// @notice Returns a custodian selected by a probabilistic balancing algorithm.
17-
/// @dev The selection is based on priority, demand and economic weight (balance).
18-
/// @param holder The address of the asset holder requesting a custodian.
19-
/// @param currency The currency used to evaluate the custodian's balance.
20-
/// @return The selected custodian address.
21-
function getBalancedCustodian(address holder, address currency) external view returns (address);
2215

23-
/// @notice Retrieves the total number of holders assigned to a custodian.
24-
/// @dev Represents the current load (demand) of a custodian in terms of assignments.
25-
/// @param custodian The custodian address to query.
26-
/// @return The number of holders currently assigned to the custodian.
27-
function getCustodyCount(address custodian) external view returns (uint256);
28-
29-
/// @notice Calculates the weighted score of a custodian for a specific holder and currency.
30-
/// @dev Used to externally query the score that influences custodian selection.
31-
/// @param custodian The address of the custodian.
32-
/// @param holder The address of the rights holder.
33-
/// @param currency The token used to evaluate economic backing.
34-
/// @return The computed weight used in the balancing algorithm.
35-
function calcWeight(address custodian, address holder, address currency) external view returns (uint256);
3616
}

contracts/core/primitives/Types.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ library T {
4545
address initiator; // the initiator of the transaction
4646
uint256 total; // the transaction total amount
4747
uint256 fees; // the agreement protocol fees
48-
address[] parties; // the accounts related to agreement
48+
address[] parties; // the accounts or beneficiaries bounded to the agreement
4949
bytes payload; // any additional data needed during agreement execution
5050
}
5151

contracts/core/primitives/upgradeable/FeesCollectorUpgradeable.sol

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,6 @@ abstract contract FeesCollectorUpgradeable is Initializable, IFeesCollector {
4444
_;
4545
}
4646

47-
/// @notice Disburses all collected funds of a specified currency from the contract to the treasury. (visitor)
48-
/// @dev This function can only be called by the treasury. It transfers the full balance of the specified currency.
49-
/// @param currency The address of the ERC20 token to disburse.
50-
function disburse(address currency) external virtual onlyTreasury returns (uint256) {
51-
// Transfer all funds of the specified currency to the treasury.
52-
address treasuryAddress = getTreasuryAddress();
53-
uint256 amount = address(this).balanceOf(currency);
54-
if (amount == 0) return 0; // error trying transfer zero amount..
55-
// safe direct transfer to treasury address..
56-
treasuryAddress.transfer(amount, currency);
57-
emit FeesDisbursed(treasuryAddress, amount, currency);
58-
return amount;
59-
}
60-
6147
/// @notice Returns the current address of the treasury.
6248
/// @return The address of the treasury.
6349
function getTreasuryAddress() public view returns (address) {

contracts/custody/CustodianFactory.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ contract CustodianFactory is UpgradeableBeacon, ICustodianFactory {
5959
return _manager[custodian] != address(0);
6060
}
6161

62+
// TODO endpoint expected as multi-address
63+
// potential validation needed here
64+
6265
/// @notice Function to create a new custodian contract.
6366
/// @dev Ensures that the same endpoint is not registered twice.
6467
/// @param endpoint The endpoint associated with the new custodian.

contracts/custody/CustodianImpl.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ contract CustodianImpl is
6464
return owner();
6565
}
6666

67+
68+
/// TODO add method to return encoded multi-address. getAddress()
6769
/// @notice Returns the current distribution endpoint URL.
6870
function getEndpoint() external view returns (string memory) {
6971
return _endpoint;
@@ -75,7 +77,7 @@ contract CustodianImpl is
7577
function setEndpoint(string calldata endpoint_) external onlyOwner {
7678
if (bytes(endpoint_).length == 0) revert InvalidEndpoint();
7779
string memory oldEndpoint = _endpoint;
78-
_endpoint = endpoint_;
80+
_endpoint = endpoint_; // update the endpoint!
7981
emit EndpointUpdated(oldEndpoint, endpoint_);
8082
}
8183

@@ -97,7 +99,7 @@ contract CustodianImpl is
9799
/// @notice Retrieves the contract's balance for a given currency.
98100
/// @param currency The token address to check the balance of (use `address(0)` for native currency).
99101
/// @dev This function is restricted to the contract owner.
100-
function getBalance(address currency) public view onlyOwner returns (uint256) {
102+
function getBalance(address currency) public view returns (uint256) {
101103
return address(this).balanceOf(currency);
102104
}
103105
}

contracts/custody/CustodianReferendum.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ contract CustodianReferendum is
170170
//
171171
// The collected fees are used to support the protocol's operations, aligning
172172
// individual actions with the broader sustainability of the network.
173-
// !IMPORTANT If tollgate does not support the currency, will revert..
174173
T.Agreement memory agreement = AGREEMENT_SETTLER.settleAgreement(proof, msg.sender);
175174
if (agreement.parties[0] != custodian) {
176175
revert CustodianAgreementMismatch(custodian);

contracts/economics/Treasury.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ contract Treasury is
7373
/// @param collector The address of an authorized fee collector.
7474
/// @param currency The address of the ERC20 token for which fees are being collected.
7575
function collectFees(address collector, address currency) external restricted nonReentrant {
76-
IFeesCollector feesCollector = IFeesCollector(collector);
77-
uint256 collected = feesCollector.disburse(currency);
78-
_sumLedgerEntry(address(this), collected, currency);
79-
emit FeesCollected(collector, collected, currency);
76+
// IFeesCollector feesCollector = IFeesCollector(collector);
77+
// uint256 collected = feesCollector.disburse(currency);
78+
// _sumLedgerEntry(address(this), collected, currency);
79+
// emit FeesCollected(collector, collected, currency);
8080
}
8181

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

0 commit comments

Comments
 (0)