-
Notifications
You must be signed in to change notification settings - Fork 1
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: staking factory to check mech and requester staking instances #38
Conversation
kupermind
commented
Aug 26, 2024
- Staking factory to check mech and requester staking instances.
/// @dev Performs actions before the delivery of a request. | ||
/// @param data Self-descriptive opaque data-blob. | ||
/// @return requestData Data for the request processing. | ||
function _preDeliver(address, uint256, bytes memory data) internal virtual returns (bytes memory requestData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not deleting, just moving around to have a better contract visibility.
/// @dev Checks agent mech for contract validity. | ||
/// @param mech Agent mech address. | ||
/// @param mechServiceId Mech operator service Id. | ||
function checkMech(address mech, uint256 mechServiceId) public view { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are changed to ones below
contracts/MechMarketplace.sol
Outdated
|
||
// Check if the requester service is staked | ||
IStaking.StakingState state = IStaking(requesterStakingInstance).getStakingState(requesterServiceId); | ||
if (state != IStaking.StakingState.Staked) { | ||
revert ServiceNotStaked(requesterStakingInstance, requesterServiceId); | ||
} | ||
checkMech(priorityMech, priorityMechStakingInstance, priorityMechServiceId); | ||
|
||
// Get the staked service info | ||
IStaking.ServiceInfo memory serviceInfo = IStaking(requesterStakingInstance).getServiceInfo(requesterServiceId); | ||
// Check staked service multisig | ||
if (serviceInfo.multisig != msg.sender) { | ||
revert OwnerOnly(msg.sender, serviceInfo.multisig); | ||
} | ||
// Check requester |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mechs and requester services are verified in these functions
/// @dev Checks for staking instance contract validity. | ||
/// @param stakingInstance Staking instance address. | ||
/// @param serviceId Service Id. | ||
function checkStakingInstance(address stakingInstance, uint256 serviceId) public view { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function verifies that the staking contract of either requester / mech is valid and that the corresponding service is staked.
/// @dev mech Agent mech contract address. | ||
/// @param mechStakingInstance Agent mech staking instance address. | ||
/// @param mechServiceId Agent mech service Id. | ||
function checkMech(address mech, address mechStakingInstance, uint256 mechServiceId) public view { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function then additionally checks that the mech is correct
/// @dev requester Requester contract address. | ||
/// @param requesterStakingInstance Requester staking instance address. | ||
/// @param requesterServiceId Requester service Id. | ||
function checkRequester(address requester, address requesterStakingInstance, uint256 requesterServiceId) public view { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is additionally checkin that the requester is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!