Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: mech manager to control marketplaces and factories #51

Merged
merged 9 commits into from
Dec 16, 2024

Conversation

kupermind
Copy link
Collaborator

@kupermind kupermind commented Dec 13, 2024

  • Mech manager to control marketplaces and factories;
  • Payment handling for request deliveries;
  • Everything is able to be processed by mech marketplaces only.

Base automatically changed from service3 to service2 December 13, 2024 23:17
An error occurred while trying to automatically change base from service2 to service December 13, 2024 23:19
An error occurred while trying to automatically change base from service2 to service December 13, 2024 23:19
@DavidMinarsch DavidMinarsch changed the base branch from service2 to unchained_mm December 13, 2024 23:19
/// @dev Sets mech marketplace statues.
/// @param mechMarketplaces Mech marketplace contract addresses.
/// @param statuses Corresponding whitelisting statues.
function setMechMarketplaceStatuses(address[] memory mechMarketplaces, bool[] memory statuses) external {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have multiple marketplaces? That's really not needed and just adding confusion for a user of the system

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactoring...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented

@@ -58,19 +57,25 @@ contract MechMarketplace is IErrorsMarketplace {
// Maximum response time
uint256 public immutable maxResponseTimeout;
// Mech karma contract address
address public immutable karmaProxy;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why changed the name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaner - nobody cares in the contract if it's proxy or not, the setup matters

// Number of undelivered requests
uint256 public numUndeliveredRequests;
// Number of total requests
uint256 public numTotalRequests;
// Reentrancy lock
uint256 internal _locked = 1;

// Map of request payments
mapping(uint256 => uint256) public mapRequestIdPayments;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this? Can we not get away with a fee counter per mech?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what is meant by that. Funds don't go to mechs before requests are delivered, but payment is taken during the request. What is your suggestion?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the mech specifies its price and fee, why is it a mech that decides which fee goes to the marketplace?


// Process payment
if (payment > 0) {
uint256 fee = IMechManager(mechManager).fee();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to have multiple marketplaces. Don't like the complexity this introduces. imo it's much simpler to scope fees logic to mechs. Then marketplace interface stays the same and simply the factory supports new types of mechs. A mech specifies its fee model that gets retrieved here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactoring... but fee needs further clarification

Comment on lines 171 to 172
// Transfer payment
(bool success, ) = deliveryMech.call{value: msg.value}("");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary gas overhead no? why not make it pull rather than push. I.e. just have a mapping that's mech specific that contains their accrued fees.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented

Comment on lines 205 to 232
function increaseRequestsCounts(address requester) external {
// Check for marketplace access
if (!mapMechMarketplaces[msg.sender]) {
revert UnauthorizedAccount(msg.sender);
}

// Record the request count
mapRequestCounts[requester]++;
// Increase the number of undelivered requests
numUndeliveredRequests++;
// Increase the total number of requests
numTotalRequests++;
}

function increaseDeliveryCounts(address requester, address agentMech, address mechServiceMultisig) external {
// Check for marketplace access
if (!mapMechMarketplaces[msg.sender]) {
revert UnauthorizedAccount(msg.sender);
}

// Decrease the number of undelivered requests
numUndeliveredRequests--;
// Increase the amount of requester delivered requests
mapDeliveryCounts[requester]++;
// Increase the amount of agent mech delivery counts
mapAgentMechDeliveryCounts[agentMech]++;
// Increase the amount of mech service multisig delivered requests
mapMechServiceDeliveryCounts[mechServiceMultisig]++;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better on marketplace. just confusing having this manager

Comment on lines 238 to 242
function checkMechValidity(address agentMech) external view returns (bool status) {
// TODO: shall we also check the status of the factory?
// TODO: if yes, what if the factory was de-whitelisted? all the mechs then become invalid
status = mapAgentMechFactories[agentMech] != address(0);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do the same as in stkaing, once created its valid. Only check at creation time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then anybody is able to create a factory with its mech and then deliver the request, so at least we ned to check created mechs.

Comment on lines 149 to 150
// Record factory that created agent mech
mapAgentMechFactories[mech] = mechFactory;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed imo.

But where are we recording the mechs that the marketplace has registered on it?

Currently there's no on-chain mapping. That makes discovery very hard.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's push each mech into the set

@@ -37,6 +37,7 @@ contract Karma {
// Contract owner
address public owner;

// TODO This must be fetched from mech manager and be removed / inaccessible from here
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Irrelevant now, stays as is

/// @param requestId Request id.
/// @param data Self-descriptive opaque data-blob.
/// @param mechStakingInstance Mech staking instance address (optional).
/// @param mechServiceId Mech operator service Id.
function deliverToMarketplace(
address mechMarketplace,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple marketplaces is not helpful

@DavidMinarsch DavidMinarsch merged commit 089eb23 into unchained_mm Dec 16, 2024
1 of 2 checks passed
@DavidMinarsch DavidMinarsch deleted the mech_manager branch December 16, 2024 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants