Updates from staking PR review

This commit is contained in:
Greg Hysen 2019-08-20 15:43:09 -07:00
parent 5826825d11
commit 41b372ffe6
15 changed files with 23 additions and 114 deletions

View File

@ -18,8 +18,6 @@
pragma solidity ^0.5.9; pragma solidity ^0.5.9;
import "./IAuthorizable.sol";
contract IAssetProxy { contract IAssetProxy {

View File

@ -166,8 +166,8 @@ contract MixinExchangeFees is
} }
// step 1/3 - compute stats for active maker pools // step 1/3 - compute stats for active maker pools
IStructs.ActivePool[] memory activePools = new IStructs.ActivePool[](activePoolsThisEpoch.length); IStructs.ActivePool[] memory activePools = new IStructs.ActivePool[](totalActivePools);
for (uint i = 0; i != totalActivePools; i++) { for (uint256 i = 0; i != totalActivePools; i++) {
bytes32 poolId = activePoolsThisEpoch[i]; bytes32 poolId = activePoolsThisEpoch[i];
// compute weighted stake // compute weighted stake
@ -203,7 +203,7 @@ contract MixinExchangeFees is
} }
// step 2/3 - record reward for each pool // step 2/3 - record reward for each pool
for (uint i = 0; i != totalActivePools; i++) { for (uint256 i = 0; i != totalActivePools; i++) {
// compute reward using cobb-douglas formula // compute reward using cobb-douglas formula
uint256 reward = LibFeeMath._cobbDouglasSuperSimplified( uint256 reward = LibFeeMath._cobbDouglasSuperSimplified(
initialContractBalance, initialContractBalance,

View File

@ -25,12 +25,14 @@ contract MixinConstants is
MixinDeploymentConstants MixinDeploymentConstants
{ {
uint64 constant internal MAX_UINT_64 = 2**64 - 1; uint64 constant internal MAX_UINT_64 = 0xFFFFFFFFFFFFFFFF;
uint256 constant internal TOKEN_MULTIPLIER = 1000000000000000000; // 10**18 uint256 constant internal TOKEN_MULTIPLIER = 1000000000000000000; // 10**18
// The upper 16 bytes represent the pool id, so this would be pool id 1. See MixinStakinPool for more information.
bytes32 constant internal INITIAL_POOL_ID = 0x0000000000000000000000000000000100000000000000000000000000000000; bytes32 constant internal INITIAL_POOL_ID = 0x0000000000000000000000000000000100000000000000000000000000000000;
// The upper 16 bytes represent the pool id, so this would be an increment of 1. See MixinStakinPool for more information.
uint256 constant internal POOL_ID_INCREMENT_AMOUNT = 0x0000000000000000000000000000000100000000000000000000000000000000; uint256 constant internal POOL_ID_INCREMENT_AMOUNT = 0x0000000000000000000000000000000100000000000000000000000000000000;
bytes32 constant internal NIL_MAKER_ID = 0x0000000000000000000000000000000000000000000000000000000000000000; bytes32 constant internal NIL_MAKER_ID = 0x0000000000000000000000000000000000000000000000000000000000000000;

View File

@ -1,42 +0,0 @@
/*
Copyright 2018 ZeroEx Intl.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
pragma solidity ^0.5.5;
contract IAssetProxy {
/// @dev Transfers assets. Either succeeds or throws.
/// @param assetData Byte array encoded for the respective asset proxy.
/// @param from Address to transfer asset from.
/// @param to Address to transfer asset to.
/// @param amount Amount of asset to transfer.
function transferFrom(
bytes calldata assetData,
address from,
address to,
uint256 amount
)
external;
/// @dev Gets the proxy id associated with the proxy address.
/// @return Proxy id.
function getProxyId()
external
pure
returns (bytes4);
}

View File

@ -76,15 +76,10 @@ interface IStakingPoolRewardVault {
uint8 operatorShare uint8 operatorShare
); );
/// @dev Default constructor. This contract is payable, but only by the staking contract. /// @dev Default constructor.
function ()
external
payable;
/// @dev Deposit a reward in ETH.
/// Note that this is only callable by the staking contract, and when /// Note that this is only callable by the staking contract, and when
/// not in catastrophic failure mode. /// not in catastrophic failure mode.
function deposit() function ()
external external
payable; payable;

View File

@ -23,8 +23,8 @@ import "@0x/contracts-utils/contracts/src/LibEIP712.sol";
import "../interfaces/IStructs.sol"; import "../interfaces/IStructs.sol";
library LibEIP712Hash library LibEIP712Hash {
{
// EIP712 Domain Name value for the Staking contract // EIP712 Domain Name value for the Staking contract
string constant internal EIP712_STAKING_DOMAIN_NAME = "0x Protocol Staking"; string constant internal EIP712_STAKING_DOMAIN_NAME = "0x Protocol Staking";

View File

@ -101,6 +101,7 @@ library LibRewardMath {
/// @dev Computes how much shadow asset to mint a member who wants to /// @dev Computes how much shadow asset to mint a member who wants to
/// join (or delegate more stake to) a staking pool. /// join (or delegate more stake to) a staking pool.
/// See MixinStakingPoolRewards for more information on shadow assets.
/// @param amountToDelegateByOwner Amount of Stake the new member would delegate. /// @param amountToDelegateByOwner Amount of Stake the new member would delegate.
/// @param totalAmountDelegated Total amount currently delegated to the pool. /// @param totalAmountDelegated Total amount currently delegated to the pool.
/// This does *not* include `amountToDelegateByOwner`. /// This does *not* include `amountToDelegateByOwner`.

View File

@ -263,17 +263,7 @@ contract MixinStakingPool is
view view
returns (address[] memory _makerAddressesByPoolId) returns (address[] memory _makerAddressesByPoolId)
{ {
// Load pointer to addresses of makers return makerAddressesByPoolId[poolId];
address[] storage makerAddressesByPoolIdPtr = makerAddressesByPoolId[poolId];
uint256 makerAddressesByPoolIdLength = makerAddressesByPoolIdPtr.length;
// Construct list of makers
_makerAddressesByPoolId = new address[](makerAddressesByPoolIdLength);
for (uint i = 0; i < makerAddressesByPoolIdLength; ++i) {
_makerAddressesByPoolId[i] = makerAddressesByPoolIdPtr[i];
}
return _makerAddressesByPoolId;
} }
/// @dev Returns the unique id that will be assigned to the next pool that is created. /// @dev Returns the unique id that will be assigned to the next pool that is created.
@ -295,6 +285,7 @@ contract MixinStakingPool is
returns (address operatorAddress) returns (address operatorAddress)
{ {
operatorAddress = poolById[poolId].operatorAddress; operatorAddress = poolById[poolId].operatorAddress;
return operatorAddress;
} }
/// @dev Convenience function for loading information on a pool. /// @dev Convenience function for loading information on a pool.

View File

@ -1,42 +1,22 @@
pragma solidity ^0.5.9; pragma solidity ^0.5.9;
import "@0x/contracts-utils/contracts/src/Ownable.sol";
import "../interfaces/IStakingEvents.sol"; import "../interfaces/IStakingEvents.sol";
import "../immutable/MixinStorage.sol"; import "../immutable/MixinStorage.sol";
contract MixinOwnable is contract MixinOwnable is
Ownable,
IStakingEvents, IStakingEvents,
MixinDeploymentConstants, MixinDeploymentConstants,
MixinConstants, MixinConstants,
MixinStorage MixinStorage
{ {
/// @dev This mixin contains logic for ownable contracts. /// @dev This mixin contains logic for ownable contracts.
/// Note that unlike the standardized `ownable` contract, /// Note that unlike the standardized `ownable` contract,
/// there is no state declared here. It is instead located /// there is no state declared here. It is instead located
/// in `immutable/MixinStorage.sol` and its value is set /// in `immutable/MixinStorage.sol` and its value is set
/// by the delegating proxy (StakingProxy.sol) /// by the delegating proxy (StakingProxy.sol)
constructor() public {}
/// @dev reverts if called by a sender other than the owner.
modifier onlyOwner() {
require(
msg.sender == owner,
"NOT_OWNER"
);
_;
}
/// @dev Transfers the ownership of this contract
/// @param newOwner New owner of contract
function transferOwnership(address newOwner)
external
onlyOwner
{
require(
newOwner != address(0),
"CANNOT_SET_OWNEROT_ADDRESS_ZERO"
);
owner = newOwner;
emit OwnershipTransferred(newOwner);
}
} }

View File

@ -49,7 +49,7 @@ contract StakingPoolRewardVault is
// mapping from Pool to Reward Balance in ETH // mapping from Pool to Reward Balance in ETH
mapping (bytes32 => Balance) internal balanceByPoolId; mapping (bytes32 => Balance) internal balanceByPoolId;
/// @dev Default constructor. This contract is payable, but only by the staking contract. /// @dev Fallback function. This contract is payable, but only by the staking contract.
function () function ()
external external
payable payable
@ -59,18 +59,6 @@ contract StakingPoolRewardVault is
emit RewardDeposited(UNKNOWN_STAKING_POOL_ID, msg.value); emit RewardDeposited(UNKNOWN_STAKING_POOL_ID, msg.value);
} }
/// @dev Deposit a reward in ETH.
/// Note that this is only callable by the staking contract, and when
/// not in catastrophic failure mode.
function deposit()
external
payable
onlyStakingContract
onlyNotInCatostrophicFailure
{
emit RewardDeposited(UNKNOWN_STAKING_POOL_ID, msg.value);
}
/// @dev Deposit a reward in ETH for a specific pool. /// @dev Deposit a reward in ETH for a specific pool.
/// Note that this is only callable by the staking contract, and when /// Note that this is only callable by the staking contract, and when
/// not in catastrophic failure mode. /// not in catastrophic failure mode.
@ -124,7 +112,7 @@ contract StakingPoolRewardVault is
); );
// update balance and transfer `amount` in ETH to staking contract // update balance and transfer `amount` in ETH to staking contract
balanceByPoolId[poolId].operatorBalance -= uint96(amount); balanceByPoolId[poolId].operatorBalance -= amount._downcastToUint96();
stakingContractAddress.transfer(amount); stakingContractAddress.transfer(amount);
// notify // notify
@ -147,7 +135,7 @@ contract StakingPoolRewardVault is
); );
// update balance and transfer `amount` in ETH to staking contract // update balance and transfer `amount` in ETH to staking contract
balanceByPoolId[poolId].membersBalance -= uint96(amount); balanceByPoolId[poolId].membersBalance -= amount._downcastToUint96();
stakingContractAddress.transfer(amount); stakingContractAddress.transfer(amount);
// notify // notify

View File

@ -20,7 +20,7 @@ pragma solidity ^0.5.5;
import "../libs/LibSafeMath.sol"; import "../libs/LibSafeMath.sol";
import "../interfaces/IZrxVault.sol"; import "../interfaces/IZrxVault.sol";
import "../interfaces/IAssetProxy.sol"; import "@0x/contracts-asset-proxy/contracts/src/interfaces/IAssetProxy.sol";
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol"; import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
import "./MixinVaultCore.sol"; import "./MixinVaultCore.sol";

View File

@ -36,7 +36,7 @@
"compile:truffle": "truffle compile" "compile:truffle": "truffle compile"
}, },
"config": { "config": {
"abis": "./generated-artifacts/@(IAssetProxy|IStaking|IStakingEvents|IStakingPoolRewardVault|IStakingProxy|IStructs|IVaultCore|IWallet|IZrxVault|LibEIP712Hash|LibFeeMath|LibFeeMathTest|LibRewardMath|LibSafeMath|LibSafeMath64|LibSafeMath96|LibSignatureValidator|MixinConstants|MixinDelegatedStake|MixinDeploymentConstants|MixinExchangeFees|MixinExchangeManager|MixinOwnable|MixinScheduler|MixinStake|MixinStakeBalances|MixinStakingPool|MixinStakingPoolRewardVault|MixinStakingPoolRewards|MixinStorage|MixinTimelockedStake|MixinVaultCore|MixinZrxVault|Staking|StakingPoolRewardVault|StakingProxy|ZrxVault).json", "abis": "./generated-artifacts/@(IStaking|IStakingEvents|IStakingPoolRewardVault|IStakingProxy|IStructs|IVaultCore|IWallet|IZrxVault|LibEIP712Hash|LibFeeMath|LibFeeMathTest|LibRewardMath|LibSafeMath|LibSafeMath64|LibSafeMath96|LibSignatureValidator|MixinConstants|MixinDelegatedStake|MixinDeploymentConstants|MixinExchangeFees|MixinExchangeManager|MixinOwnable|MixinScheduler|MixinStake|MixinStakeBalances|MixinStakingPool|MixinStakingPoolRewardVault|MixinStakingPoolRewards|MixinStorage|MixinTimelockedStake|MixinVaultCore|MixinZrxVault|Staking|StakingPoolRewardVault|StakingProxy|ZrxVault).json",
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually."
}, },
"repository": { "repository": {

View File

@ -5,7 +5,6 @@
*/ */
import { ContractArtifact } from 'ethereum-types'; import { ContractArtifact } from 'ethereum-types';
import * as IAssetProxy from '../generated-artifacts/IAssetProxy.json';
import * as IStaking from '../generated-artifacts/IStaking.json'; import * as IStaking from '../generated-artifacts/IStaking.json';
import * as IStakingEvents from '../generated-artifacts/IStakingEvents.json'; import * as IStakingEvents from '../generated-artifacts/IStakingEvents.json';
import * as IStakingPoolRewardVault from '../generated-artifacts/IStakingPoolRewardVault.json'; import * as IStakingPoolRewardVault from '../generated-artifacts/IStakingPoolRewardVault.json';
@ -32,8 +31,8 @@ import * as MixinScheduler from '../generated-artifacts/MixinScheduler.json';
import * as MixinStake from '../generated-artifacts/MixinStake.json'; import * as MixinStake from '../generated-artifacts/MixinStake.json';
import * as MixinStakeBalances from '../generated-artifacts/MixinStakeBalances.json'; import * as MixinStakeBalances from '../generated-artifacts/MixinStakeBalances.json';
import * as MixinStakingPool from '../generated-artifacts/MixinStakingPool.json'; import * as MixinStakingPool from '../generated-artifacts/MixinStakingPool.json';
import * as MixinStakingPoolRewards from '../generated-artifacts/MixinStakingPoolRewards.json';
import * as MixinStakingPoolRewardVault from '../generated-artifacts/MixinStakingPoolRewardVault.json'; import * as MixinStakingPoolRewardVault from '../generated-artifacts/MixinStakingPoolRewardVault.json';
import * as MixinStakingPoolRewards from '../generated-artifacts/MixinStakingPoolRewards.json';
import * as MixinStorage from '../generated-artifacts/MixinStorage.json'; import * as MixinStorage from '../generated-artifacts/MixinStorage.json';
import * as MixinTimelockedStake from '../generated-artifacts/MixinTimelockedStake.json'; import * as MixinTimelockedStake from '../generated-artifacts/MixinTimelockedStake.json';
import * as MixinVaultCore from '../generated-artifacts/MixinVaultCore.json'; import * as MixinVaultCore from '../generated-artifacts/MixinVaultCore.json';
@ -50,7 +49,6 @@ export const artifacts = {
MixinConstants: MixinConstants as ContractArtifact, MixinConstants: MixinConstants as ContractArtifact,
MixinDeploymentConstants: MixinDeploymentConstants as ContractArtifact, MixinDeploymentConstants: MixinDeploymentConstants as ContractArtifact,
MixinStorage: MixinStorage as ContractArtifact, MixinStorage: MixinStorage as ContractArtifact,
IAssetProxy: IAssetProxy as ContractArtifact,
IStaking: IStaking as ContractArtifact, IStaking: IStaking as ContractArtifact,
IStakingEvents: IStakingEvents as ContractArtifact, IStakingEvents: IStakingEvents as ContractArtifact,
IStakingPoolRewardVault: IStakingPoolRewardVault as ContractArtifact, IStakingPoolRewardVault: IStakingPoolRewardVault as ContractArtifact,

View File

@ -3,7 +3,6 @@
* Warning: This file is auto-generated by contracts-gen. Don't edit manually. * Warning: This file is auto-generated by contracts-gen. Don't edit manually.
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
*/ */
export * from '../generated-wrappers/i_asset_proxy';
export * from '../generated-wrappers/i_staking'; export * from '../generated-wrappers/i_staking';
export * from '../generated-wrappers/i_staking_events'; export * from '../generated-wrappers/i_staking_events';
export * from '../generated-wrappers/i_staking_pool_reward_vault'; export * from '../generated-wrappers/i_staking_pool_reward_vault';

View File

@ -3,7 +3,6 @@
"compilerOptions": { "outDir": "lib", "rootDir": ".", "resolveJsonModule": true }, "compilerOptions": { "outDir": "lib", "rootDir": ".", "resolveJsonModule": true },
"include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"],
"files": [ "files": [
"generated-artifacts/IAssetProxy.json",
"generated-artifacts/IStaking.json", "generated-artifacts/IStaking.json",
"generated-artifacts/IStakingEvents.json", "generated-artifacts/IStakingEvents.json",
"generated-artifacts/IStakingPoolRewardVault.json", "generated-artifacts/IStakingPoolRewardVault.json",