Skip to content

Commit 8f4975b

Browse files
drewstoneshekohex
andauthored
Update MSBM w/ new features in Tangle (same branch name) (#50)
* chore: Update MSBM w/ new features against drew/slashing-updates in * chore: Add stub impl to contract * chore: fmt * feat: add tests of join/leave functionality * feat: add HooksTests contract * fix: services pallet address * chore: remove artifact from slashing interface * chore: add slash alert * chore: udpate bytecode * chore: update MBSM bytecode --------- Co-authored-by: Shady Khalifa <[email protected]>
1 parent 7647933 commit 8f4975b

11 files changed

+684
-60
lines changed

bytecode/Cargo.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bytecode/src/lib.rs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

src/BlueprintServiceManagerBase.sol

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,7 @@ contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabl
133133
function onUnappliedSlash(
134134
uint64 serviceId,
135135
bytes calldata offender,
136-
uint8 slashPercent,
137-
uint256 totalPayout
136+
uint8 slashPercent
138137
)
139138
external
140139
virtual
@@ -145,8 +144,55 @@ contract BlueprintServiceManagerBase is IBlueprintServiceManager, RootChainEnabl
145144
function onSlash(
146145
uint64 serviceId,
147146
bytes calldata offender,
148-
uint8 slashPercent,
149-
uint256 totalPayout
147+
uint8 slashPercent
148+
)
149+
external
150+
virtual
151+
onlyFromMaster
152+
{ }
153+
154+
/// @inheritdoc IBlueprintServiceManager
155+
function canJoin(
156+
uint64 serviceId,
157+
ServiceOperators.OperatorPreferences calldata operator
158+
)
159+
external
160+
view
161+
virtual
162+
onlyFromMaster
163+
returns (bool allowed)
164+
{
165+
return false;
166+
}
167+
168+
/// @inheritdoc IBlueprintServiceManager
169+
function onOperatorJoined(
170+
uint64 serviceId,
171+
ServiceOperators.OperatorPreferences calldata operator
172+
)
173+
external
174+
virtual
175+
onlyFromMaster
176+
{ }
177+
178+
/// @inheritdoc IBlueprintServiceManager
179+
function canLeave(
180+
uint64 serviceId,
181+
ServiceOperators.OperatorPreferences calldata operator
182+
)
183+
external
184+
view
185+
virtual
186+
onlyFromMaster
187+
returns (bool allowed)
188+
{
189+
return false;
190+
}
191+
192+
/// @inheritdoc IBlueprintServiceManager
193+
function onOperatorLeft(
194+
uint64 serviceId,
195+
ServiceOperators.OperatorPreferences calldata operator
150196
)
151197
external
152198
virtual

src/IBlueprintServiceManager.sol

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,52 @@ interface IBlueprintServiceManager {
115115
/// @param serviceId The ID of the service related to the slash.
116116
/// @param offender The offender's details in bytes format.
117117
/// @param slashPercent The percentage of the slash.
118-
/// @param totalPayout The total payout amount in wei.
119118
function onUnappliedSlash(
120119
uint64 serviceId,
121120
bytes calldata offender,
122-
uint8 slashPercent,
123-
uint256 totalPayout
121+
uint8 slashPercent
124122
)
125123
external;
126124

127125
/// @dev Hook for handling applied slashes. Called when a slash is applied to an offender.
128126
/// @param serviceId The ID of the service related to the slash.
129127
/// @param offender The offender's details in bytes format.
130128
/// @param slashPercent The percentage of the slash.
131-
/// @param totalPayout The total payout amount in wei.
132-
function onSlash(uint64 serviceId, bytes calldata offender, uint8 slashPercent, uint256 totalPayout) external;
129+
function onSlash(uint64 serviceId, bytes calldata offender, uint8 slashPercent) external;
130+
131+
/// @dev Hook to check if an operator can join a service instance
132+
/// @param serviceId The ID of the service instance
133+
/// @param operator The operator's preferences and details
134+
/// @return allowed Returns true if the operator is allowed to join
135+
function canJoin(
136+
uint64 serviceId,
137+
ServiceOperators.OperatorPreferences calldata operator
138+
)
139+
external
140+
view
141+
returns (bool allowed);
142+
143+
/// @dev Hook called after an operator has joined a service instance
144+
/// @param serviceId The ID of the service instance
145+
/// @param operator The operator's preferences and details
146+
function onOperatorJoined(uint64 serviceId, ServiceOperators.OperatorPreferences calldata operator) external;
147+
148+
/// @dev Hook to check if an operator can leave a service instance
149+
/// @param serviceId The ID of the service instance
150+
/// @param operator The operator's preferences and details
151+
/// @return allowed Returns true if the operator is allowed to leave
152+
function canLeave(
153+
uint64 serviceId,
154+
ServiceOperators.OperatorPreferences calldata operator
155+
)
156+
external
157+
view
158+
returns (bool allowed);
159+
160+
/// @dev Hook called after an operator has left a service instance
161+
/// @param serviceId The ID of the service instance
162+
/// @param operator The operator's preferences and details
163+
function onOperatorLeft(uint64 serviceId, ServiceOperators.OperatorPreferences calldata operator) external;
133164

134165
/// @dev Query the slashing origin for a service. This mainly used by the runtime to determine the allowed account
135166
/// that can slash a service. by default, the service manager is the only account that can slash a service. override

src/MasterBlueprintServiceManager.sol

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -185,19 +185,17 @@ contract MasterBlueprintServiceManager is RootChainEnabled, AccessControl, Pausa
185185
/// @param serviceId The ID of the service.
186186
/// @param offender The offender's details.
187187
/// @param slashPercent The percentage of the slash.
188-
/// @param totalPayout The total payout amount.
189188
event UnappliedSlash(
190-
uint64 indexed blueprintId, uint64 indexed serviceId, bytes offender, uint8 slashPercent, uint256 totalPayout
189+
uint64 indexed blueprintId, uint64 indexed serviceId, bytes offender, uint8 slashPercent
191190
);
192191

193192
/// @dev Emitted when a slash is applied to an offender.
194193
/// @param blueprintId The unique identifier of the blueprint.
195194
/// @param serviceId The ID of the service.
196195
/// @param offender The offender's details.
197196
/// @param slashPercent The percentage of the slash.
198-
/// @param totalPayout The total payout amount.
199197
event Slashed(
200-
uint64 indexed blueprintId, uint64 indexed serviceId, bytes offender, uint8 slashPercent, uint256 totalPayout
198+
uint64 indexed blueprintId, uint64 indexed serviceId, bytes offender, uint8 slashPercent
201199
);
202200

203201
// =========== Errors ============
@@ -480,43 +478,39 @@ contract MasterBlueprintServiceManager is RootChainEnabled, AccessControl, Pausa
480478
/// @param serviceId The ID of the service.
481479
/// @param offender The offender's details.
482480
/// @param slashPercent The percentage of the slash.
483-
/// @param totalPayout The total payout amount.
484481
function onUnappliedSlash(
485482
uint64 blueprintId,
486483
uint64 serviceId,
487484
bytes calldata offender,
488-
uint8 slashPercent,
489-
uint256 totalPayout
485+
uint8 slashPercent
490486
)
491487
public
492488
onlyFromRootChain
493489
whenNotPaused
494490
{
495491
address manager = blueprints.get(blueprintId);
496-
IBlueprintServiceManager(manager).onUnappliedSlash(serviceId, offender, slashPercent, totalPayout);
497-
emit UnappliedSlash(blueprintId, serviceId, offender, slashPercent, totalPayout);
492+
IBlueprintServiceManager(manager).onUnappliedSlash(serviceId, offender, slashPercent);
493+
emit UnappliedSlash(blueprintId, serviceId, offender, slashPercent);
498494
}
499495

500496
/// @dev Called when a slash is applied to an offender.
501497
/// @param blueprintId The blueprint unique identifier.
502498
/// @param serviceId The ID of the service.
503499
/// @param offender The offender's details.
504500
/// @param slashPercent The percentage of the slash.
505-
/// @param totalPayout The total payout amount.
506501
function onSlash(
507502
uint64 blueprintId,
508503
uint64 serviceId,
509504
bytes calldata offender,
510-
uint8 slashPercent,
511-
uint256 totalPayout
505+
uint8 slashPercent
512506
)
513507
public
514508
onlyFromRootChain
515509
whenNotPaused
516510
{
517511
address manager = blueprints.get(blueprintId);
518-
IBlueprintServiceManager(manager).onSlash(serviceId, offender, slashPercent, totalPayout);
519-
emit Slashed(blueprintId, serviceId, offender, slashPercent, totalPayout);
512+
IBlueprintServiceManager(manager).onSlash(serviceId, offender, slashPercent);
513+
emit Slashed(blueprintId, serviceId, offender, slashPercent);
520514
}
521515

522516
/// @dev Query the slashing origin for a service.
@@ -537,6 +531,72 @@ contract MasterBlueprintServiceManager is RootChainEnabled, AccessControl, Pausa
537531
return IBlueprintServiceManager(manager).queryDisputeOrigin(serviceId);
538532
}
539533

534+
/// @dev Hook to check if an operator can join a service instance
535+
/// @param blueprintId The blueprint unique identifier
536+
/// @param serviceId The ID of the service instance
537+
/// @param operator The operator's preferences and details
538+
/// @return allowed Returns true if the operator is allowed to join
539+
function canJoin(
540+
uint64 blueprintId,
541+
uint64 serviceId,
542+
ServiceOperators.OperatorPreferences calldata operator
543+
)
544+
public
545+
view
546+
returns (bool allowed)
547+
{
548+
address manager = blueprints.get(blueprintId);
549+
return IBlueprintServiceManager(manager).canJoin(serviceId, operator);
550+
}
551+
552+
/// @dev Hook called after an operator has joined a service instance
553+
/// @param blueprintId The blueprint unique identifier
554+
/// @param serviceId The ID of the service instance
555+
/// @param operator The operator's preferences and details
556+
function onOperatorJoined(
557+
uint64 blueprintId,
558+
uint64 serviceId,
559+
ServiceOperators.OperatorPreferences calldata operator
560+
)
561+
public
562+
{
563+
address manager = blueprints.get(blueprintId);
564+
IBlueprintServiceManager(manager).onOperatorJoined(serviceId, operator);
565+
}
566+
567+
/// @dev Hook to check if an operator can leave a service instance
568+
/// @param blueprintId The blueprint unique identifier
569+
/// @param serviceId The ID of the service instance
570+
/// @param operator The operator's preferences and details
571+
/// @return allowed Returns true if the operator is allowed to leave
572+
function canLeave(
573+
uint64 blueprintId,
574+
uint64 serviceId,
575+
ServiceOperators.OperatorPreferences calldata operator
576+
)
577+
public
578+
view
579+
returns (bool allowed)
580+
{
581+
address manager = blueprints.get(blueprintId);
582+
return IBlueprintServiceManager(manager).canLeave(serviceId, operator);
583+
}
584+
585+
/// @dev Hook called after an operator has left a service instance
586+
/// @param blueprintId The blueprint unique identifier
587+
/// @param serviceId The ID of the service instance
588+
/// @param operator The operator's preferences and details
589+
function onOperatorLeft(
590+
uint64 blueprintId,
591+
uint64 serviceId,
592+
ServiceOperators.OperatorPreferences calldata operator
593+
)
594+
public
595+
{
596+
address manager = blueprints.get(blueprintId);
597+
IBlueprintServiceManager(manager).onOperatorLeft(serviceId, operator);
598+
}
599+
540600
/// @dev Pause the contract.
541601
/// @notice Only the pauser can pause the contract.
542602
function pause() public onlyRole(PAUSER_ROLE) whenNotPaused {

src/Permissions.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pragma solidity ^0.8.20;
66
/// @notice This contract is used to restrict access of certain functions to the root chain only.
77
contract RootChainEnabled {
88
/// @notice The address of the root chain
9-
address public constant ROOT_CHAIN = 0x1111111111111111111111111111111111111111;
9+
address public constant ROOT_CHAIN = 0x09dF6A941ee03B1e632904E382e10862fA9cc0e3;
1010
/// @notice The address of the rewards pallet
1111
address public constant REWARDS_PALLET = address(0x7e87d5);
1212

src/SlashAlert.sol

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity ^0.8.20;
3+
4+
/// @title Slash Alert Interface
5+
/// @notice Interface for handling slashing events in the re-staking protocol
6+
/// @dev Implement this interface to handle slashing events for remote tokens
7+
interface ISlashAlert {
8+
/// @notice Called when a slashing event occurs
9+
/// @param blueprintId The ID of the blueprint
10+
/// @param serviceId The ID of the service
11+
/// @param operator The address/account of the operator being slashed (32 bytes)
12+
/// @param slashAmount The amount to slash in wei
13+
function onSlash(
14+
uint64 blueprintId,
15+
uint64 serviceId,
16+
bytes32 operator,
17+
uint256 slashAmount
18+
) external;
19+
}

0 commit comments

Comments
 (0)