Skip to content
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

New staking - part 1 and 2 - SWIP-19 and 20 combined #252

Merged
merged 39 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
de1413d
reformat code and add some state optimizations
0xCardinalError Apr 10, 2024
955a3da
refactor code to be more concise, refactor test for proper deployment
0xCardinalError Apr 10, 2024
bad3a0e
remove reverts use custom errors
0xCardinalError Apr 10, 2024
170f00e
rewrite tests to match new errors
0xCardinalError Apr 10, 2024
52fb11f
cleanup errors
0xCardinalError Apr 10, 2024
6c5df4a
swap all the overlays keys with address keys and use them
0xCardinalError Apr 16, 2024
c317a3a
change redis contract to use new staking mappings
0xCardinalError Apr 16, 2024
0373ea6
fixing all staking tests
0xCardinalError Apr 16, 2024
6de0e5a
fix redistribution tests, 5 more failing
0xCardinalError Apr 16, 2024
df5b180
fix test errors, add function to check overlay is proper
0xCardinalError Apr 16, 2024
fd0dfd3
fix game stakes
0xCardinalError Apr 18, 2024
b3e1537
add code to change overlays, add tests to test changing of overlays t…
0xCardinalError Apr 18, 2024
a8c47fc
remove owner from staking mapping, adjust tests to work with that and…
0xCardinalError May 6, 2024
dc217e6
remove obsolete var
0xCardinalError May 6, 2024
ad14c60
change event name
0xCardinalError May 17, 2024
6c707f2
remove obsolete parametar
0xCardinalError May 17, 2024
25e7b18
change owner to sender, add crucial revert for hopping not to be hack…
0xCardinalError May 17, 2024
d7541d6
fix tests to work with new contract changes
0xCardinalError May 17, 2024
d88fd0c
change the name
0xCardinalError May 17, 2024
9bb99bc
switch to using overload function for isParticipatingInUpcomingRound
0xCardinalError May 20, 2024
cc9d49c
remove overlay from commit, use lookup for whole struct and reuse it
0xCardinalError May 20, 2024
6121290
change reveal to not use overlay, adjust tests
0xCardinalError May 20, 2024
a847545
add most optimized version of struct reading
0xCardinalError May 22, 2024
1cc528e
cleanup
0xCardinalError May 22, 2024
850bbb3
add direct lookups or better gas util
0xCardinalError May 23, 2024
fc1534b
fix tests to use actuall node address on all places
0xCardinalError May 24, 2024
b40526c
cleanup logs, cleanup tests
0xCardinalError May 24, 2024
551da73
remove old logs from tests
0xCardinalError May 24, 2024
3776f1b
remove console log
0xCardinalError May 24, 2024
5673ba1
remove double staking calls
0xCardinalError May 28, 2024
8e4e93d
fix doc and line break
0xCardinalError May 28, 2024
75072a4
Merge branch 'master' of github.com:ethersphere/storage-incentives in…
0xCardinalError May 29, 2024
e285072
remove oveloading function, no need for it as its not called by contr…
0xCardinalError Jun 10, 2024
420f219
change functionality of depositStake to be one function to do all thi…
0xCardinalError Jun 10, 2024
c558efb
change to manageState
0xCardinalError Jun 10, 2024
4b492c3
adjust tests
0xCardinalError Jun 10, 2024
a276407
add deployments with updated contracts
0xCardinalError Jul 3, 2024
0d6540e
Improved staking (new staking - part 2 - SWIP-20) (#264)
0xCardinalError Aug 26, 2024
87e8c6a
Merge branch 'master' into new_staking
0xCardinalError Aug 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/Redistribution.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ interface IPriceOracle {
}

interface IStakeRegistry {
function freezeDeposit(bytes32 overlay, uint256 time) external;
function freezeDeposit(address _owner, uint256 _time) external;
0xCardinalError marked this conversation as resolved.
Show resolved Hide resolved

function lastUpdatedBlockNumberOfOverlay(bytes32 overlay) external view returns (uint256);
function lastUpdatedBlockNumberOfOverlay(address _owner) external view returns (uint256);

function ownerOfOverlay(bytes32 overlay) external view returns (address);
function overlayOfAddress(address _owner) external view returns (bytes32);

function stakeOfOverlay(bytes32 overlay) external view returns (uint256);
function stakeOfAddress(address _owner) external view returns (uint256);
}

/**
Expand Down Expand Up @@ -279,7 +279,7 @@ contract Redistribution is AccessControl, Pausable {
*/
function commit(bytes32 _obfuscatedHash, bytes32 _overlay, uint64 _roundNumber) external whenNotPaused {
uint64 cr = currentRound();
uint256 nstake = Stakes.stakeOfOverlay(_overlay);
uint256 nstake = Stakes.stakeOfAddress(msg.sender);

if (!currentPhaseCommit()) {
revert NotCommitPhase();
Expand All @@ -300,11 +300,11 @@ contract Redistribution is AccessControl, Pausable {
revert BelowMinimumStake();
}

if (Stakes.ownerOfOverlay(_overlay) != msg.sender) {
if (Stakes.overlayOfAddress(msg.sender) != _overlay) {
0xCardinalError marked this conversation as resolved.
Show resolved Hide resolved
revert NotMatchingOwner();
}

if (Stakes.lastUpdatedBlockNumberOfOverlay(_overlay) >= block.number - 2 * ROUND_LENGTH) {
if (Stakes.lastUpdatedBlockNumberOfOverlay(msg.sender) >= block.number - 2 * ROUND_LENGTH) {
0xCardinalError marked this conversation as resolved.
Show resolved Hide resolved
revert MustStake2Rounds();
}

Expand Down Expand Up @@ -532,7 +532,7 @@ contract Redistribution is AccessControl, Pausable {
(truthRevealedHash != currentReveal.hash || truthRevealedDepth != currentReveal.depth)
) {
Stakes.freezeDeposit(
currentReveal.overlay,
currentReveal.owner,
penaltyMultiplierDisagreement * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)
);
}
Expand All @@ -542,7 +542,7 @@ contract Redistribution is AccessControl, Pausable {
// slash in later phase (ph5)
// Stakes.slashDeposit(currentCommits[i].overlay, currentCommits[i].stake);
Stakes.freezeDeposit(
currentCommit.overlay,
currentCommit.owner,
penaltyMultiplierNonRevealed * ROUND_LENGTH * uint256(2 ** truthRevealedDepth)
);
}
Expand Down Expand Up @@ -793,23 +793,23 @@ contract Redistribution is AccessControl, Pausable {

/**
* @notice Determine if a the owner of a given overlay can participate in the upcoming round.
* @param overlay The overlay address of the applicant.
* @param depth The storage depth the applicant intends to report.
* @param _owner The address of the applicant from.
0xCardinalError marked this conversation as resolved.
Show resolved Hide resolved
* @param _depth The storage depth the applicant intends to report.
*/
function isParticipatingInUpcomingRound(bytes32 overlay, uint8 depth) public view returns (bool) {
function isParticipatingInUpcomingRound(address _owner, uint8 _depth) public view returns (bool) {
if (currentPhaseReveal()) {
revert WrongPhase();
}

if (Stakes.lastUpdatedBlockNumberOfOverlay(overlay) >= block.number - 2 * ROUND_LENGTH) {
if (Stakes.lastUpdatedBlockNumberOfOverlay(_owner) >= block.number - 2 * ROUND_LENGTH) {
revert MustStake2Rounds();
}

if (Stakes.stakeOfOverlay(overlay) < MIN_STAKE) {
if (Stakes.stakeOfAddress(_owner) < MIN_STAKE) {
revert BelowMinimumStake();
}

return inProximity(overlay, currentRoundAnchor(), depth);
return inProximity(Stakes.overlayOfAddress(_owner), currentRoundAnchor(), _depth);
0xCardinalError marked this conversation as resolved.
Show resolved Hide resolved
}

// ----------------------------- Reveal ------------------------------
Expand Down
Loading
Loading