Skip to content

Commit

Permalink
feat: Master Blueprint Service Manager Draft (#22)
Browse files Browse the repository at this point in the history
* feat: add openzeppelin contracts

* feat: Master Blueprint Service Manager Draft

* fix: add MBSM revision to the Blueprint

* feat: make BSM callable by MBSM

* chore: address PR comments
  • Loading branch information
shekohex authored Nov 26, 2024
1 parent 07f3925 commit d8af40a
Show file tree
Hide file tree
Showing 8 changed files with 642 additions and 170 deletions.
3 changes: 2 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ libs = ["dependencies"]
# optimizer = true (default)
optimizer_runs = 200
fs_permissions = [{ access = "read-write", path = "./" }]
solc = "0.8.19"
solc = "0.8.20"

[profile.ci]
verbosity = 4
Expand Down Expand Up @@ -37,3 +37,4 @@ mainnet = "${MAINNET_RPC}"

[dependencies]
forge-std = "1.9.4"
"@openzeppelin-contracts" = "5.1.0"
1 change: 1 addition & 0 deletions remappings.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
@openzeppelin/contracts/=dependencies/@openzeppelin-contracts-5.1.0/
forge-std/=dependencies/forge-std-1.9.4/src/
7 changes: 7 additions & 0 deletions soldeer.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
[[dependencies]]
name = "@openzeppelin-contracts"
version = "5.1.0"
url = "https://soldeer-revisions.s3.amazonaws.com/@openzeppelin-contracts/5_1_0_19-10-2024_10:28:52_contracts.zip"
checksum = "fd3d1ea561cb27897008aee18ada6e85f248eb161c86e4435272fc2b5777574f"
integrity = "cb6cf6e878f2943b2291d5636a9d72ac51d43d8135896ceb6cf88d36c386f212"

[[dependencies]]
name = "forge-std"
version = "1.9.4"
Expand Down
86 changes: 49 additions & 37 deletions src/BlueprintServiceManagerBase.sol
Original file line number Diff line number Diff line change
@@ -1,66 +1,78 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.19;
pragma solidity ^0.8.20;

import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import "src/Permissions.sol";
import "src/IBlueprintServiceManager.sol";

/**
* @title BlueprintServiceManagerBase
* @author Tangle Network Team
* @dev This contract acts as a manager for the lifecycle of a Blueprint Instance,
* facilitating various stages such as registration, service requests, job execution,
* and job result handling. It is designed to be used by the service blueprint designer
* (gadget developer) and integrates with the RootChain for permissioned operations.
* Each function serves as a hook for different lifecycle events, and reverting any
* of these functions interrupts the process flow.
*/
/// @title BlueprintServiceManagerBase
/// @author Tangle Network Team
/// @dev This contract acts as a manager for the lifecycle of a Blueprint Instance,
/// facilitating various stages such as registration, service requests, job execution,
/// and job result handling. It is designed to be used by the service blueprint designer
/// (gadget developer) and integrates with the RootChain for permissioned operations.
/// Each function serves as a hook for different lifecycle events, and reverting any
/// of these functions interrupts the process flow.
contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabled {
/// @dev The Current Blueprint Id
uint256 public currentBlueprintId;

/// @dev The address of the owner of the blueprint
address public blueprintOwner;

/// @inheritdoc IBlueprintServiceManager
function onBlueprintCreated(uint64 blueprintId, address owner, address mbsm) external virtual onlyFromRootChain {
currentBlueprintId = blueprintId;
blueprintOwner = owner;
masterBlueprintServiceManager = mbsm;
}

/// @inheritdoc IBlueprintServiceManager
function onRegister(
OperatorPreferences calldata operator,
ServiceOperators.OperatorPreferences calldata operator,
bytes calldata registrationInputs
)
external
payable
override
onlyFromRootChain
virtual
onlyFromMaster
{ }

/// @inheritdoc IBlueprintServiceManager
function onUnregister(OperatorPreferences calldata operator) external override onlyFromRootChain { }
function onUnregister(ServiceOperators.OperatorPreferences calldata operator) external virtual onlyFromMaster { }

/// @inheritdoc IBlueprintServiceManager
function onUpdatePriceTargets(OperatorPreferences calldata operator) external payable override onlyFromRootChain { }
function onUpdatePriceTargets(ServiceOperators.OperatorPreferences calldata operator) external payable virtual onlyFromMaster { }

/// @inheritdoc IBlueprintServiceManager
function onRequest(
uint64 requestId,
address requester,
OperatorPreferences[] calldata operators,
ServiceOperators.OperatorPreferences[] calldata operators,
bytes calldata requestInputs,
address[] calldata permittedCallers,
uint64 ttl
)
external
payable
override
onlyFromRootChain
virtual
onlyFromMaster
{ }

/// @inheritdoc IBlueprintServiceManager
function onApprove(
OperatorPreferences calldata operator,
ServiceOperators.OperatorPreferences calldata operator,
uint64 requestId,
uint8 restakingPercent
)
external
payable
override
onlyFromRootChain
virtual
onlyFromMaster
{ }

/// @inheritdoc IBlueprintServiceManager
function onReject(OperatorPreferences calldata operator, uint64 requestId) external override onlyFromRootChain { }
function onReject(ServiceOperators.OperatorPreferences calldata operator, uint64 requestId) external virtual onlyFromMaster { }

/// @inheritdoc IBlueprintServiceManager
function onServiceInitialized(
Expand All @@ -71,8 +83,8 @@ contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabl
uint64 ttl
)
external
override
onlyFromRootChain
virtual
onlyFromMaster
{ }

/// @inheritdoc IBlueprintServiceManager
Expand All @@ -84,27 +96,27 @@ contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabl
)
external
payable
override
onlyFromRootChain
virtual
onlyFromMaster
{ }

/// @inheritdoc IBlueprintServiceManager
function onJobResult(
uint64 serviceId,
uint8 job,
uint64 jobCallId,
OperatorPreferences calldata operator,
ServiceOperators.OperatorPreferences calldata operator,
bytes calldata inputs,
bytes calldata outputs
)
external
payable
override
onlyFromRootChain
virtual
onlyFromMaster
{ }

/// @inheritdoc IBlueprintServiceManager
function onServiceTermination(uint64 serviceId, address owner) external override onlyFromRootChain { }
function onServiceTermination(uint64 serviceId, address owner) external virtual onlyFromMaster { }

/// @inheritdoc IBlueprintServiceManager
function onUnappliedSlash(
Expand All @@ -114,8 +126,8 @@ contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabl
uint256 totalPayout
)
external
override
onlyFromRootChain
virtual
onlyFromMaster
{ }

/// @inheritdoc IBlueprintServiceManager
Expand All @@ -126,17 +138,17 @@ contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabl
uint256 totalPayout
)
external
override
onlyFromRootChain
virtual
onlyFromMaster
{ }

/// @inheritdoc IBlueprintServiceManager
function querySlashingOrigin(uint64) external view override returns (address slashingOrigin) {
function querySlashingOrigin(uint64) external view virtual returns (address slashingOrigin) {
return address(this);
}

/// @inheritdoc IBlueprintServiceManager
function queryDisputeOrigin(uint64) external view override returns (address disputeOrigin) {
function queryDisputeOrigin(uint64) external view virtual returns (address disputeOrigin) {
return address(this);
}
}
Loading

0 comments on commit d8af40a

Please sign in to comment.