feat(contracts): inspector bond + slashing-module integration#1029
Merged
Conversation
Adds the per-inspector bond flow specified in Shelterflex#925 alongside the existing collateralised-bond and evidence-slashing models, keeping the existing APIs untouched so nothing else in the workspace breaks. bond_collateral: - set_slashing_module(admin, slashing_module) + set_operator(admin, operator) - deposit_bond(inspector, amount) / withdraw_bond(inspector, amount) / get_bond(inspector) / get_locks(inspector) - lock_bond(operator, inspector, inspection_id) — operator-gated; blocks withdraw_bond while any lock is active - unlock_bond(operator, inspector, inspection_id) - execute_slash(admin, inspector, slash_amount, inspection_id, reason) — admin-gated; cross-contract call to slashing_module.slash; reduces the inspector's bond by exactly slash_amount; fails with InsufficientBond if slash_amount > bond. - New error variants: BondLocked, InsufficientBond, LockAlreadyExists, LockNotFound, SlashingModuleNotSet. slashing_module: - set_bond_contract(admin, bond_contract) / bond_contract() — registers the one bond contract authorised to call slash. - slash(caller, inspector, amount, inspection_id, reason) — appends an InspectorSlashRecord to the inspector's history; rejects callers that are not the registered bond contract; rejects amount <= 0. - get_slash_history(inspector) — read. Both crates now expose rlib so tests can cross-import the generated clients. Tests: bond_collateral adds 12 new tests covering the full lifecycle (deposit, lock-blocks-withdraw, unlock, cross-contract slash reduces bond and records history, slash > bond fails, slash requires admin, slashing module rejects unregistered callers, multi-slash accumulation). slashing module adds 4 tests for the new surface. cargo test --workspace stays green. Closes Shelterflex#925
|
@joannamach250-collab is attempting to deploy a commit to the pope-h's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@joannamach250-collab Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements the per-inspector bond + cross-contract slashing flow from #925 alongside the existing collateralised-bond and validator-evidence-slashing models. The existing public methods are not touched — the new functionality is purely additive — so nothing else in the workspace breaks.
contracts/bond_collateralset_slashing_module(admin, slashing_module)andset_operator(admin, operator)for one-time wiring.deposit_bond(inspector, amount)/withdraw_bond(inspector, amount)/get_bond(inspector)/get_locks(inspector).lock_bond(operator, inspector, inspection_id)— operator-gated; any active lock blockswithdraw_bondwithBondLocked.unlock_bond(operator, inspector, inspection_id).execute_slash(admin, inspector, slash_amount, inspection_id, reason)— admin-gated; cross-contract call toslashing_module.slashto record the slash, then reduces the inspector's bond by exactlyslash_amount. Fails fast withInsufficientBondwhenslash_amount > bond.BondLocked,InsufficientBond,LockAlreadyExists,LockNotFound,SlashingModuleNotSet.contracts/slashing_moduleset_bond_contract(admin, bond_contract)/bond_contract()— registers the single bond contract authorised to callslash.slash(caller, inspector, amount, inspection_id, reason) -> i128— appends anInspectorSlashRecord { inspection_id, amount, reason, slashed_at }to the inspector's history. Rejects callers that aren't the registered bond contract withNotAuthorized; rejectsamount <= 0withArithmeticError.get_slash_history(inspector) -> Vec<InspectorSlashRecord>.Both crates now expose
rlibin addition tocdylibso tests can cross-import the generated*Clienttypes.Acceptance criteria
withdraw_bondis blocked when the bond is locked for a pending inspection dispute (BondLocked).execute_slashreduces the inspector's bond by exactlyslash_amount.InsufficientBond; bond untouched.slashing_module.slashis only callable by the registeredbond_collateralcontract address.cargo test -p bond_collateralandcargo test -p slashing_modulepass.Test plan
cargo test -p bond_collateral— 14 tests pass (2 existing + 12 new inspector-bond tests covering full lifecycle, lock/unlock, cross-contract slash, multi-slash accumulation, every auth error variant).cargo test -p slashing_module— 12 tests pass (8 existing + 4 new forset_bond_contract, unregistered-caller rejection, non-positive-amount rejection, slash history recording).cargo test --workspace— no regressions in any other contract.cargo fmt --all -- --checkclean.cargo clippy --workspace --all-targets --all-featuresclean (matches CI flags).Closes #925