Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 14 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ require (
github.com/mitchellh/mapstructure v1.5.0
github.com/multiformats/go-multiaddr v0.14.0
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
github.com/spf13/cobra v1.5.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.12.0
github.com/spf13/viper v1.18.2
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.32.0
golang.org/x/exp v0.0.0-20250106191152-7588d65b2ba8
Expand All @@ -60,7 +60,7 @@ require (
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/pion/datachannel v1.5.10 // indirect
Expand All @@ -80,7 +80,10 @@ require (
github.com/pion/transport/v3 v3.0.7 // indirect
github.com/pion/turn/v2 v2.1.6 // indirect
github.com/pion/webrtc/v3 v3.3.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/stretchr/testify v1.11.1 // indirect
github.com/wlynxg/anet v0.0.5 // indirect
)
Expand Down Expand Up @@ -111,7 +114,7 @@ require (
github.com/ethereum/c-kzg-4844 v0.4.0 // indirect
github.com/flynn/noise v1.1.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
Expand All @@ -127,7 +130,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/uint256 v1.2.4 // indirect
github.com/huin/goupnp v1.3.0 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
github.com/ipfs/boxo v0.27.2 // indirect
github.com/ipfs/go-cid v0.5.0 // indirect
Expand All @@ -153,7 +156,7 @@ require (
github.com/libp2p/go-netroute v0.2.2 // indirect
github.com/libp2p/go-reuseport v0.4.0 // indirect
github.com/libp2p/go-yamux/v4 v4.0.1 // indirect
github.com/magiconair/properties v1.8.6 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
Expand All @@ -178,8 +181,7 @@ require (
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/otiai10/primes v0.0.0-20180210170552-f6d2a1ba97c4 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.9 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
Expand All @@ -195,10 +197,9 @@ require (
github.com/spacemonkeygo/openssl v0.0.0-20181017203307-c2dcc5cca94a // indirect
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/afero v1.8.2 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/subosito/gotenv v1.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/tklauser/go-sysconf v0.3.12 // indirect
github.com/tklauser/numcpus v0.6.1 // indirect
Expand Down
348 changes: 30 additions & 318 deletions go.sum

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions solidity-v1/contracts/AdaptiveStakingPolicy.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
pragma solidity 0.5.17;
pragma solidity ^0.8.0;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "./libraries/grant/UnlockingSchedule.sol";
import "./GrantStakingPolicy.sol";
import "./TokenStaking.sol";
Expand All @@ -16,7 +15,6 @@ import "./TokenStaking.sol";
/// and whether the cliff is considered in the stakeahead
/// can also be chosen.
contract AdaptiveStakingPolicy is GrantStakingPolicy {
using SafeMath for uint256;
using UnlockingSchedule for uint256;
uint256 minimumStake;
uint256 stakeaheadTime;
Expand Down Expand Up @@ -69,16 +67,16 @@ contract AdaptiveStakingPolicy is GrantStakingPolicy {
uint256 start,
uint256 cliff,
uint256 withdrawn
) public view returns (uint256) {
) public view override returns (uint256) {
uint256 unlocked =
_now.add(stakeaheadTime).getUnlockedAmount(
_now + stakeaheadTime.getUnlockedAmount(
grantedAmount,
duration,
start,
(useCliff ? cliff : 0)
);
uint256 remainingInGrant = grantedAmount.sub(withdrawn);
uint256 unlockedInGrant = unlocked.sub(withdrawn);
uint256 remainingInGrant = grantedAmount - withdrawn;
uint256 unlockedInGrant = unlocked - withdrawn;

// Less than minimum stake remaining
// -> may stake what is remaining in grant
Expand Down
8 changes: 4 additions & 4 deletions solidity-v1/contracts/Authorizations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Trust math, not hardware.
*/

pragma solidity 0.5.17;
pragma solidity ^0.8.0;

import "./KeepRegistry.sol";

Expand Down Expand Up @@ -52,7 +52,7 @@ interface AuthorityVerifier {
returns (bool);
}

contract Authorizations is AuthorityVerifier {
abstract contract Authorizations is AuthorityVerifier {
// Authorized operator contracts.
mapping(address => mapping(address => bool)) internal authorizations;

Expand All @@ -72,13 +72,13 @@ contract Authorizations is AuthorityVerifier {
_;
}

constructor(KeepRegistry _registry) public {
constructor(KeepRegistry _registry) {
registry = _registry;
}

/// @notice Gets the authorizer for the specified operator address.
/// @return Authorizer address.
function authorizerOf(address _operator) public view returns (address);
function authorizerOf(address _operator) public view virtual returns (address);

/// @notice Authorizes operator contract to access staked token balance of
/// the provided operator. Can only be executed by stake operator authorizer.
Expand Down
17 changes: 10 additions & 7 deletions solidity-v1/contracts/BeaconBackportRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Trust math, not hardware.
*/

pragma solidity ^0.5.17;
pragma solidity ^0.8.0;

import "./Rewards.sol";
import "./KeepRandomBeaconOperator.sol";
Expand Down Expand Up @@ -82,27 +82,28 @@ contract BeaconBackportRewards is Rewards {
receiveReward(bytes32(groupIndex));
}

function _getKeepCount() internal view returns (uint256) {
function _getKeepCount() internal view override returns (uint256) {
return numberOfCreatedGroups;
}

function _getKeepAtIndex(uint256 i) internal view returns (bytes32) {
function _getKeepAtIndex(uint256 i) internal view override returns (bytes32) {
return bytes32(i);
}

function _getCreationTime(bytes32) internal view returns (uint256) {
function _getCreationTime(bytes32) internal view override returns (uint256) {
// Assign each group to the starting timestamp of its interval
return startOf(0);
}

function _isClosed(bytes32) internal view returns (bool) {
function _isClosed(bytes32) internal view override returns (bool) {
// All groups within the eligible range are considered happily closed.
return true;
}

function _isTerminated(bytes32 groupIndexBytes)
internal
view
override
returns (bool)
{
return false;
Expand All @@ -111,21 +112,23 @@ contract BeaconBackportRewards is Rewards {
function _recognizedByFactory(bytes32 groupIndexBytes)
internal
view
override
returns (bool)
{
return numberOfCreatedGroups > uint256(groupIndexBytes);
}

function _distributeReward(bytes32 groupIndexBytes, uint256 _value)
internal
override
{
bytes memory groupPubkey =
operatorContract.getGroupPublicKey(uint256(groupIndexBytes));
address[] memory members =
operatorContract.getGroupMembers(groupPubkey);

uint256 memberCount = members.length;
uint256 dividend = _value.div(memberCount);
uint256 dividend = _value / memberCount;

// Only pay other members if dividend is nonzero.
if (dividend > 0) {
Expand All @@ -142,7 +145,7 @@ contract BeaconBackportRewards is Rewards {
uint256 remainder = _value.mod(memberCount);
token.safeTransfer(
tokenStaking.beneficiaryOf(members[memberCount - 1]),
dividend.add(remainder)
dividend + remainder
);
}
}
16 changes: 10 additions & 6 deletions solidity-v1/contracts/BeaconRewards.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
Trust math, not hardware.
*/

pragma solidity ^0.5.17;
pragma solidity ^0.8.0;

import "./Rewards.sol";
import "./KeepRandomBeaconOperator.sol";
Expand Down Expand Up @@ -165,24 +165,25 @@ contract BeaconRewards is Rewards {
return eligibleButTerminated(bytes32(groupIndex));
}

function _getKeepCount() internal view returns (uint256) {
function _getKeepCount() internal view override returns (uint256) {
return operatorContract.getNumberOfCreatedGroups();
}

function _getKeepAtIndex(uint256 i) internal view returns (bytes32) {
function _getKeepAtIndex(uint256 i) internal view override returns (bytes32) {
return bytes32(i);
}

function _getCreationTime(bytes32 groupIndexBytes)
internal
view
override
returns (uint256)
{
return
operatorContract.getGroupRegistrationTime(uint256(groupIndexBytes));
}

function _isClosed(bytes32 groupIndexBytes) internal view returns (bool) {
function _isClosed(bytes32 groupIndexBytes) internal view override returns (bool) {
if (_isTerminated(groupIndexBytes)) {
return false;
}
Expand All @@ -194,6 +195,7 @@ contract BeaconRewards is Rewards {
function _isTerminated(bytes32 groupIndexBytes)
internal
view
override
returns (bool)
{
return operatorContract.isGroupTerminated(uint256(groupIndexBytes));
Expand All @@ -202,21 +204,23 @@ contract BeaconRewards is Rewards {
function _recognizedByFactory(bytes32 groupIndexBytes)
internal
view
override
returns (bool)
{
return _getKeepCount() > uint256(groupIndexBytes);
}

function _distributeReward(bytes32 groupIndexBytes, uint256 _value)
internal
override
{
bytes memory groupPubkey =
operatorContract.getGroupPublicKey(uint256(groupIndexBytes));
address[] memory members =
operatorContract.getGroupMembers(groupPubkey);

uint256 memberCount = members.length;
uint256 dividend = _value.div(memberCount);
uint256 dividend = _value / memberCount;

// Only pay other members if dividend is nonzero.
if (dividend > 0) {
Expand All @@ -233,7 +237,7 @@ contract BeaconRewards is Rewards {
uint256 remainder = _value.mod(memberCount);
token.safeTransfer(
tokenStaking.beneficiaryOf(members[memberCount - 1]),
dividend.add(remainder)
dividend + remainder
);
}
}
10 changes: 5 additions & 5 deletions solidity-v1/contracts/Escrow.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pragma solidity 0.5.17;
pragma solidity ^0.8.0;

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "openzeppelin-solidity/contracts/token/ERC20/IERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/SafeERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

// @title Escrow
// @notice A token holder contract allowing contract owner to set beneficiary of
Expand All @@ -17,7 +17,7 @@ contract Escrow is Ownable {
IERC20 public token;
address public beneficiary;

constructor(IERC20 _token) public {
constructor(IERC20 _token) {
token = _token;
}

Expand Down
8 changes: 3 additions & 5 deletions solidity-v1/contracts/GasPriceOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@
Trust math, not hardware.
*/

pragma solidity 0.5.17;
pragma solidity ^0.8.0;

import "openzeppelin-solidity/contracts/math/SafeMath.sol";

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";

/// @dev Interface expected to be implemented by contracts added as a gas price
/// oracle consumers. Consumers are notified by GasPriceOracle every time gas
Expand All @@ -32,7 +31,6 @@ interface GasPriceOracleConsumer {
/// @notice Oracle presenting the current gas price. The oracle is manually
/// updated by its owner.
contract GasPriceOracle is Ownable {
using SafeMath for uint256;

event GasPriceUpdated(uint256 newValue);

Expand All @@ -48,7 +46,7 @@ contract GasPriceOracle is Ownable {
modifier onlyAfterGovernanceDelay {
require(gasPriceChangeInitiated > 0, "Change not initiated");
require(
block.timestamp.sub(gasPriceChangeInitiated) >= governanceDelay,
block.timestamp - gasPriceChangeInitiated >= governanceDelay,
"Governance delay has not elapsed"
);
_;
Expand Down
6 changes: 3 additions & 3 deletions solidity-v1/contracts/GrantStakingPolicy.sol
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
pragma solidity 0.5.17;
pragma solidity ^0.8.0;

/// @title GrantStakingPolicy
/// @notice A staking policy defines the function `getStakeableAmount`
/// which calculates how many tokens may be staked from a token grant.
contract GrantStakingPolicy {
abstract contract GrantStakingPolicy {
function getStakeableAmount(
uint256 _now,
uint256 grantedAmount,
uint256 duration,
uint256 start,
uint256 cliff,
uint256 withdrawn
) public view returns (uint256);
) public view virtual returns (uint256);
}
Loading
Loading