@0x:contracts-staking
Addressed some review comments
This commit is contained in:
@@ -33,13 +33,16 @@ contract StakingProxy is
|
||||
|
||||
/// @dev Constructor.
|
||||
/// @param _stakingContract Staking contract to delegate calls to.
|
||||
constructor(address _stakingContract, address _readOnlyProxy)
|
||||
/// @param _readOnlyProxy The address of the read only proxy.
|
||||
/// @param _wethProxyAddress The address that can transfer WETH for fees.
|
||||
constructor(address _stakingContract, address _readOnlyProxy, address _wethProxyAddress)
|
||||
public
|
||||
MixinStorage()
|
||||
{
|
||||
stakingContract = _stakingContract;
|
||||
readOnlyProxyCallee = _stakingContract;
|
||||
readOnlyProxy = _readOnlyProxy;
|
||||
wethAssetProxy = IAssetProxy(_wethProxyAddress);
|
||||
}
|
||||
|
||||
/// @dev Delegates calls to the staking contract, if it is set.
|
||||
|
@@ -19,8 +19,6 @@
|
||||
pragma solidity ^0.5.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IAssetData.sol";
|
||||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IAssetProxy.sol";
|
||||
import "@0x/contracts-erc20/contracts/src/interfaces/IEtherToken.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
|
||||
@@ -105,6 +103,9 @@ contract MixinExchangeFees is
|
||||
(msg.value != protocolFeePaid && msg.value != 0)
|
||||
) {
|
||||
LibRichErrors.rrevert(LibStakingRichErrors.InvalidProtocolFeePaymentError(
|
||||
protocolFeePaid == 0 ?
|
||||
LibStakingRichErrors.ProtocolFeePaymentErrorCodes.ZeroProtocolFeePaid :
|
||||
LibStakingRichErrors.ProtocolFeePaymentErrorCodes.MismatchedFeeAndPayment,
|
||||
protocolFeePaid,
|
||||
msg.value
|
||||
));
|
||||
@@ -112,7 +113,7 @@ contract MixinExchangeFees is
|
||||
|
||||
// Transfer the protocol fee to this address if it should be paid in WETH.
|
||||
if (msg.value == 0) {
|
||||
erc20Proxy.transferFrom(
|
||||
wethAssetProxy.transferFrom(
|
||||
WETH_ASSET_DATA,
|
||||
payerAddress,
|
||||
address(this),
|
||||
|
@@ -45,17 +45,6 @@ contract MixinExchangeManager is
|
||||
_;
|
||||
}
|
||||
|
||||
/// @dev Adds a new erc20 proxy.
|
||||
/// @param erc20AssetProxy The asset proxy that will transfer erc20 tokens.
|
||||
function addERC20AssetProxy(address erc20AssetProxy)
|
||||
external
|
||||
onlyOwner
|
||||
{
|
||||
// Update the erc20 asset proxy.
|
||||
erc20Proxy = IAssetProxy(erc20AssetProxy);
|
||||
emit ERC20AssetProxy(erc20AssetProxy);
|
||||
}
|
||||
|
||||
/// @dev Adds a new exchange address
|
||||
/// @param addr Address of exchange contract to add
|
||||
function addExchangeAddress(address addr)
|
||||
|
@@ -34,8 +34,6 @@ contract MixinConstants is
|
||||
|
||||
bytes32 constant internal NIL_POOL_ID = 0x0000000000000000000000000000000000000000000000000000000000000000;
|
||||
|
||||
bytes32 constant internal NIL_POOL_ID = 0x0000000000000000000000000000000000000000000000000000000000000000;
|
||||
|
||||
address constant internal NIL_ADDRESS = 0x0000000000000000000000000000000000000000;
|
||||
|
||||
bytes32 constant internal UNKNOWN_STAKING_POOL_ID = 0x0000000000000000000000000000000000000000000000000000000000000000;
|
||||
@@ -45,10 +43,4 @@ contract MixinConstants is
|
||||
uint64 constant internal INITIAL_TIMELOCK_PERIOD = INITIAL_EPOCH;
|
||||
|
||||
uint256 constant internal MIN_TOKEN_VALUE = 10**18;
|
||||
|
||||
// The address of the canonical WETH contract -- this will be used as an alternative to ether for paying protocol fees.
|
||||
address constant internal WETH_ADDRESS = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
|
||||
|
||||
// abi.encodeWithSelector(IAssetData(address(0)).ERC20Token.selector, WETH_ADDRESS)
|
||||
bytes constant internal WETH_ASSET_DATA = hex"f47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
|
||||
}
|
||||
|
@@ -33,4 +33,22 @@ contract MixinDeploymentConstants {
|
||||
uint256 constant internal CHAIN_ID = 1;
|
||||
|
||||
uint256 constant internal MAX_MAKERS_IN_POOL = 10;
|
||||
|
||||
// Mainnet WETH9 Address
|
||||
address constant internal WETH_ADDRESS = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
|
||||
|
||||
// Kovan WETH9 Address
|
||||
// address constant internal WETH_ADDRESS = address(0xd0a1e359811322d97991e03f863a0c30c2cf029c);
|
||||
|
||||
// Ropsten & Rinkeby WETH9 Address
|
||||
// address constant internal WETH_ADDRESS = address(0xc778417e063141139fce010982780140aa0cd5ab);
|
||||
|
||||
// Mainnet Weth Asset Data
|
||||
bytes constant internal WETH_ASSET_DATA = hex"f47261b0000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2";
|
||||
|
||||
// Kovan Weth Asset Data
|
||||
// bytes constant internal WETH_ASSET_DATA = hex"f47261b0000000000000000000000000d0a1e359811322d97991e03f863a0c30c2cf029c";
|
||||
|
||||
// Ropsten & Rinkeby Weth Asset Data
|
||||
// bytes constant internal WETH_ASSET_DATA = hex"f47261b0000000000000000000000000c778417e063141139fce010982780140aa0cd5ab";
|
||||
}
|
||||
|
@@ -20,12 +20,15 @@ pragma solidity ^0.5.9;
|
||||
|
||||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IAssetData.sol";
|
||||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IAssetProxy.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibBytes.sol";
|
||||
import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
|
||||
import "@0x/contracts-utils/contracts/src/Ownable.sol";
|
||||
import "./MixinConstants.sol";
|
||||
import "../interfaces/IZrxVault.sol";
|
||||
import "../interfaces/IEthVault.sol";
|
||||
import "../interfaces/IStakingPoolRewardVault.sol";
|
||||
import "../interfaces/IStructs.sol";
|
||||
import "../libs/LibStakingRichErrors.sol";
|
||||
|
||||
|
||||
// solhint-disable max-states-count, no-empty-blocks
|
||||
@@ -34,13 +37,23 @@ contract MixinStorage is
|
||||
Ownable,
|
||||
MixinConstants
|
||||
{
|
||||
using LibBytes for bytes;
|
||||
|
||||
/// @dev Ensures that the WETH_ASSET_DATA is correct.
|
||||
constructor()
|
||||
public
|
||||
Ownable()
|
||||
{} // solhint-disable-line no-empty-blocks
|
||||
{
|
||||
// Ensure that the WETH_ASSET_DATA from MixinDeploymentConstants is correct.
|
||||
if (!WETH_ASSET_DATA.equals(
|
||||
abi.encodeWithSelector(IAssetData(address(0)).ERC20Token.selector, WETH_ADDRESS)
|
||||
)) {
|
||||
LibRichErrors.rrevert(LibStakingRichErrors.InvalidWethAssetDataError());
|
||||
}
|
||||
}
|
||||
|
||||
// 0x ERC20 Proxy
|
||||
IAssetProxy internal erc20Proxy;
|
||||
// WETH Asset Proxy
|
||||
IAssetProxy internal wethAssetProxy;
|
||||
|
||||
// address of staking contract
|
||||
address internal stakingContract;
|
||||
|
@@ -126,10 +126,4 @@ interface IStakingEvents {
|
||||
event StakingPoolRewardVaultChanged(
|
||||
address rewardVaultAddress
|
||||
);
|
||||
|
||||
/// @dev Emitted by MixinExchangeManager when the erc20AssetProxy address changes.
|
||||
/// @param erc20AddressProxy The new erc20 asset proxy address.
|
||||
event ERC20AssetProxy(
|
||||
address erc20AddressProxy
|
||||
);
|
||||
}
|
||||
|
@@ -48,17 +48,17 @@ interface IZrxVault {
|
||||
uint256 amount
|
||||
);
|
||||
|
||||
/// @dev Emitted when the ERC20 Proxy is changed.
|
||||
/// @param erc20ProxyAddress Address of the new ERC20 proxy.
|
||||
event Erc20ProxyChanged(
|
||||
address erc20ProxyAddress
|
||||
/// @dev Emitted when the Zrx Proxy is changed.
|
||||
/// @param zrxProxyAddress Address of the new ERC20 proxy.
|
||||
event ZrxProxyChanged(
|
||||
address zrxProxyAddress
|
||||
);
|
||||
|
||||
/// @dev Sets the ERC20 proxy.
|
||||
/// @dev Sets the Zrx proxy.
|
||||
/// Note that only the contract owner can call this.
|
||||
/// Note that this can only be called when *not* in Catastrophic Failure mode.
|
||||
/// @param erc20ProxyAddress Address of the 0x ERC20 Proxy.
|
||||
function setErc20Proxy(address erc20ProxyAddress)
|
||||
/// @param zrxProxyAddress Address of the 0x Zrx Asset Proxy.
|
||||
function setZrxProxy(address zrxProxyAddress)
|
||||
external;
|
||||
|
||||
/// @dev Deposit an `amount` of Zrx Tokens from `owner` into the vault.
|
||||
|
@@ -22,6 +22,12 @@ import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
|
||||
|
||||
|
||||
library LibStakingRichErrors {
|
||||
|
||||
enum ProtocolFeePaymentErrorCodes {
|
||||
ZeroProtocolFeePaid,
|
||||
MismatchedFeeAndPayment
|
||||
}
|
||||
|
||||
// bytes4(keccak256("MiscalculatedRewardsError(uint256,uint256)"))
|
||||
bytes4 internal constant MISCALCULATED_REWARDS_ERROR_SELECTOR =
|
||||
0xf7806c4e;
|
||||
@@ -113,9 +119,13 @@ library LibStakingRichErrors {
|
||||
POOL_IS_FULL
|
||||
}
|
||||
|
||||
// bytes4(keccak256("InvalidProtocolFeePaymentError(uint256,uint256)"))
|
||||
// bytes4(keccak256("InvalidProtocolFeePaymentError(uint8,uint256,uint256)"))
|
||||
bytes4 internal constant INVALID_PROTOCOL_FEE_PAYMENT_ERROR_SELECTOR =
|
||||
0x31d7a505;
|
||||
0xefd6cb33;
|
||||
|
||||
// bytes4(keccak256("InvalidWethAssetDataError()"))
|
||||
bytes internal constant INVALID_WETH_ASSET_DATA_ERROR =
|
||||
hex"24bf322c";
|
||||
|
||||
// solhint-disable func-name-mixedcase
|
||||
function MiscalculatedRewardsError(
|
||||
@@ -364,6 +374,7 @@ library LibStakingRichErrors {
|
||||
}
|
||||
|
||||
function InvalidProtocolFeePaymentError(
|
||||
ProtocolFeePaymentErrorCodes errorCode,
|
||||
uint256 expectedProtocolFeePaid,
|
||||
uint256 actualProtocolFeePaid
|
||||
)
|
||||
@@ -373,6 +384,7 @@ library LibStakingRichErrors {
|
||||
{
|
||||
return abi.encodeWithSelector(
|
||||
INVALID_PROTOCOL_FEE_PAYMENT_ERROR_SELECTOR,
|
||||
errorCode,
|
||||
expectedProtocolFeePaid,
|
||||
actualProtocolFeePaid
|
||||
);
|
||||
@@ -407,4 +419,11 @@ library LibStakingRichErrors {
|
||||
return PROXY_DESTINATION_CANNOT_BE_NIL;
|
||||
}
|
||||
|
||||
function InvalidWethAssetDataError()
|
||||
internal
|
||||
pure
|
||||
returns (bytes memory)
|
||||
{
|
||||
return INVALID_WETH_ASSET_DATA_ERROR;
|
||||
}
|
||||
}
|
||||
|
@@ -42,8 +42,8 @@ contract ZrxVault is
|
||||
// mapping from Owner to ZRX balance
|
||||
mapping (address => uint256) internal balances;
|
||||
|
||||
// 0x ERC20 Proxy
|
||||
IAssetProxy internal erc20Proxy;
|
||||
// Zrx Asset Proxy
|
||||
IAssetProxy internal zrxAssetProxy;
|
||||
|
||||
// Zrx Token
|
||||
IERC20Token internal zrxToken;
|
||||
@@ -52,15 +52,15 @@ contract ZrxVault is
|
||||
bytes internal zrxAssetData;
|
||||
|
||||
/// @dev Constructor.
|
||||
/// @param erc20ProxyAddress Address of the 0x ERC20 Proxy.
|
||||
/// @param zrxProxyAddress Address of the 0x Zrx Proxy.
|
||||
/// @param zrxTokenAddress Address of the Zrx Token.
|
||||
constructor(
|
||||
address erc20ProxyAddress,
|
||||
address zrxProxyAddress,
|
||||
address zrxTokenAddress
|
||||
)
|
||||
public
|
||||
{
|
||||
erc20Proxy = IAssetProxy(erc20ProxyAddress);
|
||||
zrxAssetProxy = IAssetProxy(zrxProxyAddress);
|
||||
zrxToken = IERC20Token(zrxTokenAddress);
|
||||
zrxAssetData = abi.encodeWithSelector(
|
||||
IAssetData(address(0)).ERC20Token.selector,
|
||||
@@ -68,17 +68,17 @@ contract ZrxVault is
|
||||
);
|
||||
}
|
||||
|
||||
/// @dev Sets the ERC20 proxy.
|
||||
/// @dev Sets the Zrx proxy.
|
||||
/// Note that only the contract owner can call this.
|
||||
/// Note that this can only be called when *not* in Catastrophic Failure mode.
|
||||
/// @param erc20ProxyAddress Address of the 0x ERC20 Proxy.
|
||||
function setErc20Proxy(address erc20ProxyAddress)
|
||||
/// @param zrxProxyAddress Address of the 0x Zrx Proxy.
|
||||
function setZrxProxy(address zrxProxyAddress)
|
||||
external
|
||||
onlyOwner
|
||||
onlyNotInCatastrophicFailure
|
||||
{
|
||||
erc20Proxy = IAssetProxy(erc20ProxyAddress);
|
||||
emit Erc20ProxyChanged(erc20ProxyAddress);
|
||||
zrxAssetProxy = IAssetProxy(zrxProxyAddress);
|
||||
emit ZrxProxyChanged(zrxProxyAddress);
|
||||
}
|
||||
|
||||
/// @dev Deposit an `amount` of Zrx Tokens from `owner` into the vault.
|
||||
@@ -98,7 +98,7 @@ contract ZrxVault is
|
||||
emit ZrxDepositedIntoVault(msg.sender, owner, amount);
|
||||
|
||||
// deposit ZRX from owner
|
||||
erc20Proxy.transferFrom(
|
||||
zrxAssetProxy.transferFrom(
|
||||
zrxAssetData,
|
||||
owner,
|
||||
address(this),
|
||||
|
@@ -19,16 +19,24 @@
|
||||
pragma solidity ^0.5.9;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IAssetProxy.sol";
|
||||
import "../src/Staking.sol";
|
||||
|
||||
|
||||
contract TestProtocolFees is
|
||||
Staking
|
||||
{
|
||||
function setPoolIdOfMaker(bytes32 poolId, address makerAddress)
|
||||
function setWethProxy(address wethProxyAddress)
|
||||
external
|
||||
{
|
||||
poolIdByMakerAddress[makerAddress] = poolId;
|
||||
wethAssetProxy = IAssetProxy(wethProxyAddress);
|
||||
}
|
||||
|
||||
function addMakerToPool(bytes32 poolId, address makerAddress)
|
||||
external
|
||||
{
|
||||
poolJoinedByMakerAddress[makerAddress].poolId = poolId;
|
||||
poolJoinedByMakerAddress[makerAddress].confirmed = true;
|
||||
}
|
||||
|
||||
function getActivePoolsByEpoch()
|
||||
|
@@ -25,8 +25,10 @@ import "../src/Staking.sol";
|
||||
contract TestStaking is
|
||||
Staking
|
||||
{
|
||||
/*
|
||||
// Stub out `payProtocolFee` to be the naive payProtocolFee function so that tests will
|
||||
// not fail for WETH protocol fees.
|
||||
// not fail for WETH protocol fees. These tests will fail otherwise because many of them
|
||||
// will transfer
|
||||
function payProtocolFee(
|
||||
address makerAddress,
|
||||
address,
|
||||
@@ -44,6 +46,7 @@ contract TestStaking is
|
||||
activePoolsThisEpoch.push(poolId);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// Stub out `_unwrapWETH` to prevent the calls to `finalizeFees` from failing in tests
|
||||
// that do not relate to protocol fee payments in WETH.
|
||||
|
Reference in New Issue
Block a user