Replaced any contract-style libraries with real libraries.

This commit is contained in:
Greg Hysen
2019-06-25 15:00:34 -07:00
parent 56184c6f4f
commit 4d2ba9f1e6
10 changed files with 221 additions and 135 deletions

View File

@@ -18,7 +18,8 @@
pragma solidity ^0.5.5;
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
import "../libs/LibSafeMath64Bit.sol";
import "../immutable/MixinConstants.sol";
import "../immutable/MixinStorage.sol";
import "../interfaces/IStructs.sol";
@@ -27,10 +28,12 @@ contract MixinEpoch is
MixinStorage
{
using LibSafeMath64Bit for uint64;
/// @dev returns the current epoch in seconds
function getEpochPeriodInSeconds()
public
view
pure
returns (uint64)
{
return EPOCH_PERIOD_IN_SECONDS;
@@ -38,7 +41,7 @@ contract MixinEpoch is
function getTimelockPeriodInEpochs()
public
view
pure
returns (uint64)
{
return TIMELOCK_PERIOD_IN_EPOCHS;
@@ -65,7 +68,7 @@ contract MixinEpoch is
view
returns (uint64)
{
return getCurrentEpochStartTimeInSeconds() + getEpochPeriodInSeconds();
return getCurrentEpochStartTimeInSeconds()._add(getEpochPeriodInSeconds());
}
function getCurrentTimelockPeriodEndEpoch()
@@ -73,7 +76,7 @@ contract MixinEpoch is
view
returns (uint64)
{
return getCurrentTimelockPeriodStartEpoch() + getTimelockPeriodInEpochs();
return getCurrentTimelockPeriodStartEpoch()._add(getTimelockPeriodInEpochs());
}
function getCurrentEpoch()

View File

@@ -18,8 +18,6 @@
pragma solidity ^0.5.5;
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
import "../interfaces/IStakingEvents.sol";
import "../immutable/MixinConstants.sol";
@@ -27,8 +25,6 @@ import "../immutable/MixinStorage.sol";
contract MixinExchange is
// libraries
SafeMath,
// interfaces
IStakingEvents,
// immutables

View File

@@ -18,7 +18,7 @@
pragma solidity ^0.5.5;
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
import "../libs/LibSafeMath.sol";
import "../interfaces/IVault.sol";
import "../immutable/MixinStorage.sol";
import "../immutable/MixinConstants.sol";
@@ -33,8 +33,6 @@ import "../libs/LibMath.sol";
contract MixinFees is
// libraries
SafeMath,
// interfaces
IStakingEvents,
IStructs,
@@ -50,6 +48,8 @@ contract MixinFees is
MixinPools
{
using LibSafeMath for uint256;
function payProtocolFee(address makerAddress)
external
payable
@@ -58,7 +58,7 @@ contract MixinFees is
uint256 amount = msg.value;
bytes32 poolId = getMakerPoolId(makerAddress);
uint256 _feesCollectedThisEpoch = protocolFeesThisEpochByPool[poolId];
protocolFeesThisEpochByPool[poolId] = _safeAdd(_feesCollectedThisEpoch, amount);
protocolFeesThisEpochByPool[poolId] = _feesCollectedThisEpoch._add(amount);
if (_feesCollectedThisEpoch == 0) {
activePoolIdsThisEpoch.push(poolId);
}
@@ -87,13 +87,6 @@ contract MixinFees is
return address(this).balance;
}
event E(
uint256 totalRewards,
uint256 ownerFees,
uint256 totalFees,
uint256 ownerStake,
uint256 totalStake
);
function _payRebates()
internal
{
@@ -104,7 +97,7 @@ contract MixinFees is
for (uint i = 0; i != numberOfActivePoolIds; i++) {
activePoolIds[i].poolId = activePoolIdsThisEpoch[i];
activePoolIds[i].feesCollected = protocolFeesThisEpochByPool[activePoolIds[i].poolId];
totalFees = _safeAdd(totalFees, activePoolIds[i].feesCollected);
totalFees = totalFees._add(activePoolIds[i].feesCollected);
}
uint256 totalRewards = address(this).balance;
uint256 totalStake = getActivatedStakeAcrossAllOwners();
@@ -128,23 +121,12 @@ contract MixinFees is
for (uint i = 0; i != numberOfActivePoolIds; i++) {
uint256 stakeDelegatedToPool = getStakeDelegatedToPool(activePoolIds[i].poolId);
uint256 stakeHeldByPoolOperator = getActivatedAndUndelegatedStake(getPoolOperator(activePoolIds[i].poolId));
uint256 scaledStake = _safeAdd(
stakeHeldByPoolOperator,
_safeDiv(
_safeMul(
stakeDelegatedToPool,
REWARD_PAYOUT_DELEGATED_STAKE_PERCENT_VALUE
),
100
)
);
emit E(
totalRewards,
activePoolIds[i].feesCollected,
totalFees,
scaledStake,
totalStake
uint256 scaledStake = stakeHeldByPoolOperator._add(
stakeDelegatedToPool
._mul(REWARD_PAYOUT_DELEGATED_STAKE_PERCENT_VALUE)
._div(100)
);
uint256 reward = LibMath._cobbDouglasSuperSimplified(
totalRewards,
activePoolIds[i].feesCollected,
@@ -155,7 +137,7 @@ contract MixinFees is
// record reward in vault
_recordDepositInRewardVault(activePoolIds[i].poolId, reward);
totalRewardsRecordedInVault = _safeAdd(totalRewardsRecordedInVault, reward);
totalRewardsRecordedInVault = totalRewardsRecordedInVault._add(reward);
// clear state for refunds
protocolFeesThisEpochByPool[activePoolIds[i].poolId] = 0;

View File

@@ -19,7 +19,7 @@
pragma solidity ^0.5.5;
pragma experimental ABIEncoderV2;
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
import "../libs/LibSafeMath.sol";
import "../libs/LibSignatureValidator.sol";
import "../libs/LibEIP712Hash.sol";
@@ -33,8 +33,6 @@ import "./MixinRewardVault.sol";
contract MixinPools is
// libraries
SafeMath,
// interfaces
IStakingEvents,
// immutables
@@ -44,6 +42,8 @@ contract MixinPools is
MixinRewardVault
{
using LibSafeMath for uint256;
modifier onlyPoolOperator(bytes32 poolId) {
require(
msg.sender == getPoolOperator(poolId),
@@ -58,9 +58,9 @@ contract MixinPools is
returns (bytes32 poolId)
{
address payable operatorAddress = msg.sender;
//
poolId = nextPoolId;
nextPoolId = bytes32(_safeAdd(uint256(nextPoolId >> 128), 1) << 128);
nextPoolId = _computeNextPoolId(poolId);
//
Pool memory pool = Pool({
@@ -188,6 +188,16 @@ contract MixinPools is
return pool;
}
function _computeNextPoolId(bytes32 poolId)
internal
pure
returns (bytes32)
{
uint256 poolIdRightAligned = uint256(poolId >> 128);
uint256 poolIdRightAlignedAndIncremented = poolIdRightAligned._add(1);
return bytes32(poolIdRightAlignedAndIncremented) << 128;
}
function _recordMaker(
bytes32 poolId,
address makerAddress

View File

@@ -18,9 +18,9 @@
pragma solidity ^0.5.5;
import "../libs/LibSafeMath.sol";
import "../libs/LibRewardMath.sol";
import "../immutable/MixinStorage.sol";
import "../libs/LibRewards.sol";
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
import "../immutable/MixinConstants.sol";
import "../interfaces/IStakingEvents.sol";
import "./MixinStakeBalances.sol";
@@ -28,9 +28,6 @@ import "./MixinRewardVault.sol";
import "./MixinPools.sol";
contract MixinRewards is
// libraries
SafeMath,
LibRewards,
// immutables
MixinConstants,
MixinStorage,
@@ -41,6 +38,8 @@ contract MixinRewards is
MixinPools
{
using LibSafeMath for uint256;
function withdrawOperatorReward(bytes32 poolId, uint256 amount)
external
onlyPoolOperator(poolId)
@@ -59,8 +58,8 @@ contract MixinRewards is
"INVALID_AMOUNT"
);
shadowRewardsInPoolByOwner[owner][poolId] = _safeAdd(shadowRewardsInPoolByOwner[owner][poolId], amount);
shadowRewardsByPoolId[poolId] = _safeAdd(shadowRewardsByPoolId[poolId], amount);
shadowRewardsInPoolByOwner[owner][poolId] = shadowRewardsInPoolByOwner[owner][poolId]._add(amount);
shadowRewardsByPoolId[poolId] = shadowRewardsByPoolId[poolId]._add(amount);
_withdrawFromPoolInRewardVault(poolId, amount);
owner.transfer(amount);
@@ -85,8 +84,8 @@ contract MixinRewards is
address payable owner = msg.sender;
uint256 amount = computeRewardBalance(poolId, owner);
shadowRewardsInPoolByOwner[owner][poolId] = _safeAdd(shadowRewardsInPoolByOwner[owner][poolId], amount);
shadowRewardsByPoolId[poolId] = _safeAdd(shadowRewardsByPoolId[poolId], amount);
shadowRewardsInPoolByOwner[owner][poolId] = shadowRewardsInPoolByOwner[owner][poolId]._add(amount);
shadowRewardsByPoolId[poolId] = shadowRewardsByPoolId[poolId]._add(amount);
_withdrawFromPoolInRewardVault(poolId, amount);
owner.transfer(amount);
@@ -100,7 +99,7 @@ contract MixinRewards is
returns (uint256)
{
uint256 poolBalance = getBalanceOfPoolInRewardVault(poolId);
return _computePayoutDenominatedInRealAsset(
return LibRewardMath._computePayoutDenominatedInRealAsset(
delegatedStakeToPoolByOwner[owner][poolId],
delegatedStakeByPoolId[poolId],
shadowRewardsInPoolByOwner[owner][poolId],

View File

@@ -18,25 +18,18 @@
pragma solidity ^0.5.5;
import "../libs/LibRewards.sol";
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
import "../libs/LibSafeMath.sol";
import "../libs/LibRewardMath.sol";
import "../immutable/MixinConstants.sol";
import "../immutable/MixinStorage.sol";
import "../interfaces/IStakingEvents.sol";
import "./MixinZrxVault.sol";
import "./MixinRewardVault.sol";
import "./MixinEpoch.sol";
import "./MixinStakeBalances.sol";
contract MixinStake is
// libraries
SafeMath,
LibRewards,
// interfaces
IStakingEvents,
// immutables
@@ -50,6 +43,8 @@ contract MixinStake is
MixinStakeBalances
{
using LibSafeMath for uint256;
function deposit(uint256 amount)
external
{
@@ -93,8 +88,8 @@ contract MixinStake is
getDeactivatedStake(owner) >= amount,
"INSUFFICIENT_BALANCE"
);
activeStakeByOwner[owner] = _safeAdd(activeStakeByOwner[owner], amount);
totalActivatedStake = _safeAdd(totalActivatedStake, amount);
activeStakeByOwner[owner] = activeStakeByOwner[owner]._add(amount);
totalActivatedStake = totalActivatedStake._add(amount);
}
function activateAndDelegateStake(
@@ -117,8 +112,8 @@ contract MixinStake is
getActivatedStake(owner) >= amount,
"INSUFFICIENT_BALANCE"
);
activeStakeByOwner[owner] = _safeSub(activeStakeByOwner[owner], amount);
totalActivatedStake = _safeSub(totalActivatedStake, amount);
activeStakeByOwner[owner] = activeStakeByOwner[owner]._sub(amount);
totalActivatedStake = totalActivatedStake._sub(amount);
_timelockStake(owner, amount);
}
@@ -145,7 +140,7 @@ contract MixinStake is
_depositFromOwnerIntoZrxVault(owner, amount);
// mint stake
stakeByOwner[owner] = _safeAdd(stakeByOwner[owner], amount);
stakeByOwner[owner] = stakeByOwner[owner]._add(amount);
// emit stake event
emit StakeMinted(
@@ -158,7 +153,7 @@ contract MixinStake is
private
{
// burn stake
stakeByOwner[owner] = _safeSub(stakeByOwner[owner], amount);
stakeByOwner[owner] = stakeByOwner[owner]._sub(amount);
// withdraw equivalent amount of ZRX from vault
_withdrawToOwnerFromZrxVault(owner, amount);
@@ -179,38 +174,29 @@ contract MixinStake is
uint256 _delegatedStakeByPoolId = delegatedStakeByPoolId[poolId];
// increment how much stake the owner has delegated
delegatedStakeByOwner[owner] = _safeAdd(_delegatedStakeByOwner, amount);
delegatedStakeByOwner[owner] = _delegatedStakeByOwner._add(amount);
// increment how much stake the owner has delegated to the input pool
delegatedStakeToPoolByOwner[owner][poolId] = _safeAdd(_delegatedStakeToPoolByOwner, amount);
delegatedStakeToPoolByOwner[owner][poolId] = _delegatedStakeToPoolByOwner._add(amount);
// increment how much stake has been delegated to pool
delegatedStakeByPoolId[poolId] = _safeAdd(_delegatedStakeByPoolId, amount);
delegatedStakeByPoolId[poolId] = _delegatedStakeByPoolId._add(amount);
// update delegator's share of reward pool
// note that this uses the snapshot parameters
uint256 poolBalance = getBalanceOfPoolInRewardVault(poolId);
uint256 buyIn = _computeBuyInDenominatedInShadowAsset(
uint256 buyIn = LibRewardMath._computeBuyInDenominatedInShadowAsset(
amount,
_delegatedStakeByPoolId,
shadowRewardsByPoolId[poolId],
poolBalance
);
if (buyIn > 0) {
shadowRewardsInPoolByOwner[owner][poolId] = _safeAdd(shadowRewardsInPoolByOwner[owner][poolId], buyIn);
shadowRewardsByPoolId[poolId] = _safeAdd(shadowRewardsByPoolId[poolId], buyIn);
shadowRewardsInPoolByOwner[owner][poolId] = shadowRewardsInPoolByOwner[owner][poolId]._add(buyIn);
shadowRewardsByPoolId[poolId] = shadowRewardsByPoolId[poolId]._add(buyIn);
}
}
event K(
uint256 amountDelegatedByOwner,
uint256 totalAmountDelegated,
uint256 amountOfShadowAssetHeldByOwner,
uint256 totalAmountOfShadowAsset,
uint256 totalAmountOfRealAsset,
uint256 payoutInRealAsset
);
// question - should we then return the amount withdrawn?
function _undelegateStake(address payable owner, bytes32 poolId, uint256 amount)
private
@@ -221,13 +207,13 @@ contract MixinStake is
uint256 _delegatedStakeByPoolId = delegatedStakeByPoolId[poolId];
// decrement how much stake the owner has delegated
delegatedStakeByOwner[owner] = _safeSub(_delegatedStakeByOwner, amount);
delegatedStakeByOwner[owner] = _delegatedStakeByOwner._sub(amount);
// decrement how much stake the owner has delegated to the input pool
delegatedStakeToPoolByOwner[owner][poolId] = _safeSub(_delegatedStakeToPoolByOwner, amount);
delegatedStakeToPoolByOwner[owner][poolId] = _delegatedStakeToPoolByOwner._sub(amount);
// decrement how much stake has been delegated to pool
delegatedStakeByPoolId[poolId] = _safeSub(_delegatedStakeByPoolId, amount);
delegatedStakeByPoolId[poolId] = _delegatedStakeByPoolId._sub(amount);
// get payout
// TODO -- not full balance, just balance that belongs to delegators.
@@ -237,7 +223,7 @@ contract MixinStake is
if (_delegatedStakeToPoolByOwner == amount) {
// full payout
payoutInShadowAsset = shadowRewardsInPoolByOwner[owner][poolId];
payoutInRealAsset = _computePayoutDenominatedInRealAsset(
payoutInRealAsset = LibRewardMath._computePayoutDenominatedInRealAsset(
amount,
_delegatedStakeByPoolId,
payoutInShadowAsset,
@@ -246,7 +232,7 @@ contract MixinStake is
);
} else {
// partial payout
(payoutInRealAsset, payoutInShadowAsset) = _computePartialPayout(
(payoutInRealAsset, payoutInShadowAsset) = LibRewardMath._computePartialPayout(
amount,
_delegatedStakeToPoolByOwner,
_delegatedStakeByPoolId,
@@ -255,8 +241,8 @@ contract MixinStake is
poolBalance
);
}
shadowRewardsInPoolByOwner[owner][poolId] = _safeSub(shadowRewardsInPoolByOwner[owner][poolId], payoutInShadowAsset);
shadowRewardsByPoolId[poolId] = _safeSub(shadowRewardsByPoolId[poolId], payoutInShadowAsset);
shadowRewardsInPoolByOwner[owner][poolId] = shadowRewardsInPoolByOwner[owner][poolId]._sub(payoutInShadowAsset);
shadowRewardsByPoolId[poolId] = shadowRewardsByPoolId[poolId]._sub(payoutInShadowAsset);
// withdraw payout for delegator
if (payoutInRealAsset > 0) {
@@ -283,11 +269,7 @@ contract MixinStake is
private
{
(Timelock memory ownerTimelock,) = _getSynchronizedTimelock(owner);
require(
amount <= 2**96 - 1,
"AMOUNT_TOO_LARGE"
);
uint96 downcastAmount = uint96(amount);
uint96 downcastAmount = amount._downcastToUint96();
ownerTimelock.total += downcastAmount;
timelockedStakeByOwner[owner] = ownerTimelock;
}

View File

@@ -19,20 +19,21 @@
pragma solidity ^0.5.5;
pragma experimental ABIEncoderV2;
import "../libs/LibSafeMath.sol";
import "../interfaces/IStructs.sol";
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
import "../immutable/MixinConstants.sol";
import "../immutable/MixinStorage.sol";
import "./MixinEpoch.sol";
contract MixinStakeBalances is
SafeMath,
MixinConstants,
MixinStorage,
MixinEpoch
{
using LibSafeMath for uint256;
function getActivatedStakeAcrossAllOwners()
public
view
@@ -62,16 +63,15 @@ contract MixinStakeBalances is
view
returns (uint256)
{
return _safeSub(getTotalStake(owner), getActivatedStake(owner));
return getTotalStake(owner)._sub(getActivatedStake(owner));
}
function getActivatedAndUndelegatedStake(address owner)
public
view
returns (uint256)
{
return _safeSub(activeStakeByOwner[owner], getStakeDelegatedByOwner(owner));
return activeStakeByOwner[owner]._sub(getStakeDelegatedByOwner(owner));
}
function getActivatableStake(address owner)
@@ -79,7 +79,7 @@ contract MixinStakeBalances is
view
returns (uint256)
{
return _safeSub(getDeactivatedStake(owner), getTimelockedStake(owner));
return getDeactivatedStake(owner)._sub(getTimelockedStake(owner));
}
function getWithdrawableStake(address owner)
@@ -134,7 +134,7 @@ contract MixinStakeBalances is
uint64 currentTimelockPeriod = getCurrentTimelockPeriod();
ownerTimelock = timelockedStakeByOwner[owner];
isOutOfSync = false;
if (currentTimelockPeriod == _safeAdd(ownerTimelock.lockedAt, 1)) {
if (currentTimelockPeriod == ownerTimelock.lockedAt._add(1)) {
// shift n periods
ownerTimelock.pending = ownerTimelock.total;
isOutOfSync = true;

View File

@@ -18,18 +18,12 @@
pragma solidity ^0.5.5;
import "@0x/contracts-utils/contracts/src/SafeMath.sol";
import "./LibSafeMath.sol";
contract LibRewards is SafeMath {
library LibRewardMath {
event J (
uint256 amountDelegatedByOwner,
uint256 totalAmountDelegated,
uint256 amountOfShadowAssetHeldByOwner,
uint256 totalAmountOfShadowAsset,
uint256 totalAmountOfRealAsset
);
using LibSafeMath for uint256;
function _computePayoutDenominatedInRealAsset(
uint256 amountDelegatedByOwner,
@@ -42,13 +36,9 @@ uint256 amountDelegatedByOwner,
pure
returns (uint256)
{
uint256 combinedPayout = _safeDiv(
_safeMul(
amountDelegatedByOwner,
_safeAdd(totalAmountOfShadowAsset, totalAmountOfRealAsset)
),
totalAmountDelegated
);
uint256 combinedPayout = amountDelegatedByOwner
._mul(totalAmountOfShadowAsset._add(totalAmountOfRealAsset))
._div(totalAmountDelegated);
// we round up the amount of shadow assets when computing buy-ins.
// the result is that sometimes the amount of actual assets in the pool
@@ -75,7 +65,10 @@ uint256 amountDelegatedByOwner,
uint256 payoutInShadowAsset
)
{
payoutInShadowAsset = _safeDiv(_safeMul(amountOfShadowAssetHeldByOwner, partialAmountDelegatedByOwner), amountDelegatedByOwner);
payoutInShadowAsset = amountOfShadowAssetHeldByOwner
._mul(partialAmountDelegatedByOwner)
._div(amountDelegatedByOwner);
payoutInRealAsset = _computePayoutDenominatedInRealAsset(
partialAmountDelegatedByOwner,
totalAmountDelegated,
@@ -99,20 +92,9 @@ uint256 amountDelegatedByOwner,
if (totalAmountDelegated == 0) {
return 0;
}
return _safeDiv(
_safeAdd( // we round up when computing shadow asset
_safeMul(
amountToDelegateByOwner,
_safeAdd(
totalAmountOfShadowAsset,
totalAmountOfRealAsset
)
),
_safeSub(totalAmountDelegated, 1)
),
totalAmountDelegated
);
return amountToDelegateByOwner
._mul(totalAmountOfShadowAsset._add(totalAmountOfRealAsset))
._add(totalAmountDelegated._sub(1)) // we round up when computing shadow asset
._div(totalAmountDelegated);
}
}

View File

@@ -0,0 +1,132 @@
/*
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;
library LibSafeMath64Bit {
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
* - Addition cannot overflow.
*/
function _add(uint64 a, uint64 b) internal pure returns (uint64) {
uint64 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*/
function _sub(uint64 a, uint64 b) internal pure returns (uint64) {
require(b <= a, "SafeMath: subtraction overflow");
uint64 c = a - b;
return c;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
* - Multiplication cannot overflow.
*/
function _mul(uint64 a, uint64 b) internal pure returns (uint64) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint64 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
/**
* @dev Returns the integer division of two unsigned integers. Reverts on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function _div(uint64 a, uint64 b) internal pure returns (uint64) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, "SafeMath: division by zero");
uint64 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* Reverts when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*/
function _mod(uint64 a, uint64 b)
internal
pure
returns (uint64)
{
require(b != 0, "SafeMath: modulo by zero");
return a % b;
}
function _computePercentageCeil(uint64 value, uint8 numerator)
internal
pure
returns (uint64)
{
uint64 scaledNumerator = _mul(value, numerator);
uint64 ceilScalar = uint64(99);
uint64 denominator = uint64(100);
return _div(
_add(scaledNumerator, ceilScalar),
denominator
);
}
}

View File

@@ -9,7 +9,7 @@ import { artifacts as erc20Artifacts, DummyERC20TokenContract } from '@0x/contra
import { ERC20ProxyContract } from '@0x/contracts-asset-proxy';
import * as _ from 'lodash';
import { artifacts, StakingEEventArgs, StakingContract, StakingProxyContract, ZrxVaultContract, RewardVaultContract, LibMathTestContract } from '../../src';
import { artifacts, StakingContract, StakingProxyContract, ZrxVaultContract, RewardVaultContract, LibMathTestContract } from '../../src';
import { ApprovalFactory } from './ApprovalFactory';
import { SignedStakingPoolApproval } from './types';
import { constants } from './constants';