-
Notifications
You must be signed in to change notification settings - Fork 23
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
Smart contracts: Registry + Challenger #22
Merged
Merged
Changes from 8 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
e2e4526
chore: contracts dir
merklefruit eeb1fb7
forge install: openzeppelin-contracts
merklefruit 42344d5
forge install: relic-sdk
merklefruit 32bd4ec
chore: init basic registry
merklefruit 839a7fd
feat: basic registry
merklefruit 1cc992f
Merge branch 'feat/bolt-frontend-gt' of github.com:chainbound/bolt-v0…
merklefruit 4ca139f
chore: rm forge-std files from git
merklefruit f62d61a
forge install: forge-std
merklefruit 88095eb
feat: bolt challenger stub
merklefruit 8b2a799
feat: challenger progress and refactor
merklefruit b007b1a
feat: ssz libraries
merklefruit f9aafca
feat: challenger resolution progress
merklefruit 838085e
chore: fmt + comments
merklefruit 71f10e8
feat: challenger update: account data proof
merklefruit 485c8d0
fix: some compile errors, formatting. wip
thedevbirb 11f4c0d
feat: solve challenge in case of invalid protocol rules
merklefruit 4269cce
chore: fmt
merklefruit a6dba78
chore: small nit
merklefruit 63af8e8
feat: updated registry to confirm opt out methods
merklefruit 71fdaac
chore: fmt
merklefruit 7c942c3
feat: refactored libraries, cleaned challenger contract
merklefruit 0528dd7
chore: moved scripts to their own dir for cleaner repo organization
merklefruit 4559704
chore: fix compile errors
merklefruit 1b6693a
feat(challenger): added challenge opening tests
merklefruit 3934b77
feat: added more registry tests
merklefruit abd9726
chore: fmt
merklefruit aba2381
chore: adapted justfile to scripts dir
merklefruit 9cc5217
chore: address challenger review
merklefruit File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[submodule "bolt-contracts/lib/forge-std"] | ||
path = bolt-contracts/lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "bolt-contracts/lib/openzeppelin-contracts"] | ||
path = bolt-contracts/lib/openzeppelin-contracts | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts | ||
[submodule "bolt-contracts/lib/relic-sdk"] | ||
path = bolt-contracts/lib/relic-sdk | ||
url = https://github.com/Relic-Protocol/relic-sdk |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cache/ | ||
out/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[profile.default] | ||
src = "src" | ||
out = "out" | ||
libs = ["lib"] | ||
|
||
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options |
Submodule openzeppelin-contracts
added at
dbb610
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Script, console} from "forge-std/Script.sol"; | ||
|
||
contract CounterScript is Script { | ||
function setUp() public {} | ||
|
||
function run() public { | ||
vm.broadcast(); | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.13; | ||
|
||
contract BoltRegistry { | ||
uint256 public constant OPT_OUT_COOLDOWN = 1 days; | ||
|
||
// Struct to hold opted-in proposers | ||
struct BasedProposer { | ||
// The address of the proposer opted in | ||
address addr; | ||
// The status of the proposer in the protocol | ||
BoltStatus status; | ||
// The timestamp of the last time the proposer opted in. | ||
// This is used to enforce the opt-out cooldown period | ||
uint256 lastOptedInTimestamp; | ||
} | ||
|
||
// Enum to hold the status of the based proposers | ||
enum BoltStatus { | ||
Active, | ||
Inactive | ||
} | ||
|
||
// Mapping to hold the based proposers | ||
mapping(address => BasedProposer) public basedProposers; | ||
|
||
// Error messages | ||
error BasedProposerAlreadyExists(); | ||
error BasedProposerDoesNotExist(); | ||
error InvalidStatusChange(); | ||
error CooldownNotElapsed(); | ||
error Unauthorized(); | ||
error NotFound(); | ||
|
||
// Event to log the status change of a based proposer | ||
event BasedProposerStatusChanged(address indexed basedProposer, BoltStatus status); | ||
|
||
/// @notice Constructor | ||
constructor() {} | ||
|
||
/// @notice Allows a based proposer to opt-in to the protocol | ||
function optIn() external { | ||
if (basedProposers[msg.sender].addr != address(0)) { | ||
revert BasedProposerAlreadyExists(); | ||
} | ||
|
||
basedProposers[msg.sender] = BasedProposer(msg.sender, BoltStatus.Active, block.timestamp); | ||
emit BasedProposerStatusChanged(msg.sender, BoltStatus.Active); | ||
} | ||
|
||
/// @notice Allows a based proposer to opt-out of the protocol | ||
function optOut() external { | ||
BasedProposer memory basedProposer = basedProposers[msg.sender]; | ||
|
||
if (basedProposer.addr != msg.sender) { | ||
revert BasedProposerDoesNotExist(); | ||
} | ||
if (basedProposer.status == BoltStatus.Inactive) { | ||
revert InvalidStatusChange(); | ||
} | ||
if (block.timestamp - basedProposer.lastOptedInTimestamp < OPT_OUT_COOLDOWN) { | ||
revert CooldownNotElapsed(); | ||
} | ||
merklefruit marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
basedProposer.status = BoltStatus.Inactive; | ||
emit BasedProposerStatusChanged(msg.sender, BoltStatus.Inactive); | ||
} | ||
|
||
/// @notice Check if an address is a based proposer | ||
/// @param _basedProposer The address to check | ||
/// @return True if the address is a based proposer, false otherwise | ||
function isBasedProposer(address _basedProposer) external view returns (bool) { | ||
return basedProposers[_basedProposer].addr != address(0); | ||
} | ||
|
||
/// @notice Get the status of a based proposer | ||
/// @param _basedProposers The address of the based proposer | ||
/// @return The status of the based proposer | ||
function getBasedProposerStatus(address _basedProposers) external view returns (BoltStatus) { | ||
if (basedProposers[_basedProposers].addr == address(0)) { | ||
revert BasedProposerDoesNotExist(); | ||
} | ||
|
||
return basedProposers[_basedProposers].status; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.13; | ||
|
||
import {Test, console} from "forge-std/Test.sol"; | ||
import {BoltRegistry} from "../src/BoltRegistry.sol"; | ||
|
||
contract BoltRegistryTest is Test { | ||
BoltRegistry public registry; | ||
|
||
address alice = address(0x1); | ||
address bob = address(0x2); | ||
|
||
function setUp() public { | ||
registry = new BoltRegistry(); | ||
} | ||
|
||
function testAddBasedProposerToRegistry() public { | ||
vm.prank(alice); | ||
registry.optIn(); | ||
|
||
assertEq(uint8(registry.getBasedProposerStatus(alice)), uint8(BoltRegistry.BoltStatus.Active)); | ||
} | ||
} |
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.
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.
We can remove this file
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.
I did it in the upstream PR #35
Will leave it here for now