Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
@0x/contracts-staking: It compiles!
Browse files Browse the repository at this point in the history
  • Loading branch information
merklejerk committed Sep 18, 2019
1 parent f577293 commit eb9b9b3
Show file tree
Hide file tree
Showing 35 changed files with 894 additions and 648 deletions.
18 changes: 16 additions & 2 deletions contracts/staking/contracts/src/Staking.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,24 @@ import "./fees/MixinExchangeFees.sol";

contract Staking is
IStaking,
IStakingEvents,
MixinAbstract,
MixinConstants,
MixinDeploymentConstants,
Ownable,
MixinStorage,
MixinStakingPoolModifiers,
MixinExchangeManager,
MixinParams,
MixinScheduler,
MixinStakeStorage,
MixinStakingPoolMakers,
MixinStakeBalances,
MixinCumulativeRewards,
MixinStakingPoolRewards,
MixinStakingPool,
MixinStake,
MixinExchangeFees,
MixinExchangeFees
{
// this contract can receive ETH
// solhint-disable no-empty-blocks
Expand All @@ -54,7 +68,7 @@ contract Staking is
address payable _rewardVaultAddress,
address _zrxVaultAddress
)
external
public
onlyOwner
{
// DANGER! When performing upgrades, take care to modify this logic
Expand Down
2 changes: 2 additions & 0 deletions contracts/staking/contracts/src/StakingProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import "./interfaces/IStakingProxy.sol";

contract StakingProxy is
IStakingProxy,
MixinConstants,
Ownable,
MixinStorage
{
using LibProxy for address;
Expand Down
17 changes: 13 additions & 4 deletions contracts/staking/contracts/src/fees/MixinExchangeFees.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,19 @@ import "./MixinExchangeManager.sol";
/// disincentive for market makers to monopolize a single pool that they
/// all delegate to.
contract MixinExchangeFees is
IStakingEvents,
MixinAbstract,
MixinConstants,
MixinDeploymentConstants,
Ownable,
MixinStorage,
MixinStakingPoolModifiers,
MixinExchangeManager,
MixinAbstract,
MixinScheduler,
MixinStakeStorage,
MixinStakingPoolMakers,
MixinStakeBalances,
MixinCumulativeRewards,
MixinStakingPoolRewards,
MixinStakingPool
{
Expand Down Expand Up @@ -99,7 +108,7 @@ contract MixinExchangeFees is
}

// Look up the pool for this epoch.
uint256 currentEpoch = getCurrentEpoch();
uint256 currentEpoch = currentEpoch;
mapping (bytes32 => IStructs.ActivePool) storage activePoolsThisEpoch =
_getActivePoolsFromEpoch(currentEpoch);
IStructs.ActivePool memory pool = activePoolsThisEpoch[poolId];
Expand Down Expand Up @@ -169,7 +178,7 @@ contract MixinExchangeFees is
// because we only need to remember state in the current epoch and the
// epoch prior.
IStructs.ActivePool memory pool =
_getActivePoolFromEpoch(getCurrentEpoch(), poolId);
_getActivePoolFromEpoch(currentEpoch, poolId);
feesCollected = pool.feesCollected;
}

Expand All @@ -188,7 +197,7 @@ contract MixinExchangeFees is
returns (uint256 membersStake, uint256 weightedStake)
{
uint256 operatorStake = getStakeDelegatedToPoolByOwner(
getPoolOperator(poolId),
poolById[poolId].operator,
poolId
).currentEpochBalance;
membersStake = totalStake.safeSub(operatorStake);
Expand Down
2 changes: 2 additions & 0 deletions contracts/staking/contracts/src/fees/MixinExchangeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import "../immutable/MixinStorage.sol";
/// then it should be removed.
contract MixinExchangeManager is
IStakingEvents,
MixinConstants,
Ownable,
MixinStorage
{
/// @dev Asserts that the call is coming from a valid exchange.
Expand Down
24 changes: 9 additions & 15 deletions contracts/staking/contracts/src/immutable/MixinStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ contract MixinStorage is
// mapping from Owner to Amount of Withdrawable Stake
mapping (address => uint256) internal _withdrawableStakeByOwner;

// Mapping from Owner to Pool Id to epoch of the last rewards collected.
// This is the last reward epoch for a pool that a delegator collected
// rewards from. This is different from the epoch when the rewards were
// collected This will always be `<= currentEpoch`.
mapping (address => mapping (bytes32 => uint256)) internal lastCollectedRewardsEpochToPoolByOwner;

// tracking Pool Id
bytes32 public nextPoolId = INITIAL_POOL_ID;

Expand Down Expand Up @@ -137,36 +131,36 @@ contract MixinStorage is

/// @dev The total fees collected in the current epoch, built up iteratively
/// in `payProtocolFee()`.
uint256 internal totalFeesCollectedThisEpoch;
uint256 public totalFeesCollectedThisEpoch;

/// @dev The total weighted stake in the current epoch, built up iteratively
/// in `payProtocolFee()`.
uint256 internal totalWeightedStakeThisEpoch;
uint256 public totalWeightedStakeThisEpoch;

/// @dev State information for each active pool in an epoch.
/// In practice, we only store state for `currentEpoch % 2`.
mapping(uint256 => mapping(bytes32 => IStructs.ActivePool))
internal
activePoolsByEpoch;
_activePoolsByEpoch;

/// @dev Number of pools activated in the current epoch.
uint256 internal numActivePoolsThisEpoch;
uint256 public numActivePoolsThisEpoch;

/// @dev Rewards (ETH) available to the epoch being finalized (the previous
/// epoch). This is simply the balance of the contract at the end of
/// the epoch.
uint256 internal unfinalizedRewardsAvailable;
uint256 public unfinalizedRewardsAvailable;

/// @dev The number of active pools in the last epoch that have yet to be
/// finalized through `finalizePools()`.
uint256 internal unfinalizedPoolsRemaining;
uint256 public unfinalizedPoolsRemaining;

/// @dev The total fees collected for the epoch being finalized.
uint256 internal unfinalizedTotalFeesCollected;
uint256 public unfinalizedTotalFeesCollected;

/// @dev The total fees collected for the epoch being finalized.
uint256 internal unfinalizedTotalWeightedStake;
uint256 public unfinalizedTotalWeightedStake;

/// @dev How many rewards were paid at the end of finalization.
uint256 internal totalRewardsPaidLastEpoch;
uint256 public totalRewardsPaidLastEpoch;
}
15 changes: 8 additions & 7 deletions contracts/staking/contracts/src/interfaces/IEthVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ interface IEthVault {
uint256 amount
);

/// @dev Deposit an `amount` of ETH from `owner` into the vault.
/// Note that only the Staking contract can call this.
/// Note that this can only be called when *not* in Catostrophic Failure mode.
/// @param owner of ETH Tokens.
function depositFor(address owner)
external
payable;
/// @dev Record a deposit of an amount of ETH for `owner` into the vault.
/// The staking contract should pay this contract the ETH owed in the
/// same transaction.
/// Note that this is only callable by the staking contract.
/// @param owner Owner of the ETH.
/// @param amount Amount of deposit.
function recordDepositFor(address owner, uint256 amount)
external;

/// @dev Withdraw an `amount` of ETH to `msg.sender` from the vault.
/// Note that only the Staking contract can call this.
Expand Down
12 changes: 6 additions & 6 deletions contracts/staking/contracts/src/interfaces/IStakingEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ interface IStakingEvents {
/// @param epoch The epoch in which the pool was activated.
/// @param poolId The ID of the pool.
event StakingPoolActivated(
uint256 epoch,
bytes32 poolId
uint256 indexed epoch,
bytes32 indexed poolId
);

/// @dev Emitted by MixinFinalizer when an epoch has ended.
Expand All @@ -59,7 +59,7 @@ interface IStakingEvents {
/// @param totalWeightedStake Total weighted stake across all active pools.
/// @param totalFeesCollected Total fees collected across all active pools.
event EpochEnded(
uint256 epoch,
uint256 indexed epoch,
uint256 numActivePools,
uint256 rewardsAvailable,
uint256 totalFeesCollected,
Expand All @@ -71,7 +71,7 @@ interface IStakingEvents {
/// @param rewardsPaid Total amount of rewards paid out.
/// @param rewardsRemaining Rewards left over.
event EpochFinalized(
uint256 epoch,
uint256 indexed epoch,
uint256 rewardsPaid,
uint256 rewardsRemaining
);
Expand All @@ -82,8 +82,8 @@ interface IStakingEvents {
/// @param operatorReward Amount of reward paid to pool operator.
/// @param membersReward Amount of reward paid to pool members.
event RewardsPaid(
uint256 epoch,
bytes32 poolId,
uint256 indexed epoch,
bytes32 indexed poolId,
uint256 operatorReward,
uint256 membersReward
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,34 +33,35 @@ interface IStakingPoolRewardVault {
uint256 amount
);

/// @dev Emitted when a reward is transferred to the ETH vault.
/// @param amount The amount in ETH withdrawn.
/// @param member of the pool.
/// @param poolId The pool the reward was deposited for.
event PoolRewardTransferredToEthVault(
/// @dev Emitted when rewards are transferred out fo the vault.
/// @param poolId Unique Id of pool.
/// @param to Address to send funds to.
/// @param amount Amount of ETH to transfer.
event PoolRewardTransferred(
bytes32 indexed poolId,
address indexed member,
address to,
uint256 amount
);

/// @dev Deposit an amount of ETH (`msg.value`) for `poolId` into the vault.
/// Note that this is only callable by the staking contract.
/// @param poolId that owns the ETH.
function depositFor(bytes32 poolId)
external
payable;

/// @dev Withdraw some amount in ETH of a pool member.
/// Note that this is only callable by the staking contract.
/// @dev Record a deposit of an amount of ETH for `poolId` into the vault.
/// The staking contract should pay this contract the ETH owed in the
/// same transaction.
/// Note that this is only callable by the staking contract.
/// @param poolId Pool that holds the ETH.
/// @param amount Amount of deposit.
function recordDepositFor(bytes32 poolId, uint256 amount)
external;

/// @dev Withdraw some amount in ETH from a pool.
/// Note that this is only callable by the staking contract.
/// @param poolId Unique Id of pool.
/// @param member of pool to transfer funds to.
/// @param amount Amount in ETH to transfer.
/// @param ethVaultAddress address of Eth Vault to send rewards to.
function transferToEthVault(
/// @param to Address to send funds to.
/// @param amount Amount of ETH to transfer.
function transfer(
bytes32 poolId,
address member,
uint256 amount,
address ethVaultAddress
address payable to,
uint256 amount
)
external;

Expand Down
10 changes: 0 additions & 10 deletions contracts/staking/contracts/src/interfaces/IStructs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ interface IStructs {
uint256 membersStake;
}

/// @dev Rewards credited to a pool during finalization.
/// @param operatorReward The amount of reward credited to the pool operator.
/// @param membersReward The amount of reward credited to the pool members.
/// @param membersStake The amount of members/delegated stake in the pool.
struct PoolRewards {
uint256 operatorReward;
uint256 membersReward;
uint256 membersStake;
}

/// @dev Encapsulates a balance for the current and next epochs.
/// Note that these balances may be stale if the current epoch
/// is greater than `currentEpoch`.
Expand Down
Loading

0 comments on commit eb9b9b3

Please sign in to comment.