@0x/contracts-staking: Rebase against 3.0

This commit is contained in:
Lawrence Forman
2019-09-22 13:11:42 -04:00
parent e4126189df
commit eac4520406
15 changed files with 54 additions and 39 deletions

View File

@@ -69,7 +69,7 @@ contract Staking is
address payable _rewardVaultAddress,
address _zrxVaultAddress
)
external
public
onlyAuthorized
{
// DANGER! When performing upgrades, take care to modify this logic

View File

@@ -210,7 +210,7 @@ contract StakingProxy is
}
// Minimum stake must be > 1
if (minimumStake < 2) {
if (minimumPoolStake < 2) {
LibRichErrors.rrevert(
LibStakingRichErrors.InvalidParamValueError(
LibStakingRichErrors.InvalidParamValueErrorCode.InvalidMinimumPoolStake

View File

@@ -246,24 +246,4 @@ contract MixinParams is
_zrxVaultAddress
);
}
/// @dev Rescind the WETH allowance for `oldSpenders` and grant `newSpenders`
/// an unlimited allowance.
/// @param oldSpenders Addresses to remove allowance from.
/// @param newSpenders Addresses to grant allowance to.
function _transferWETHAllownces(
address[2] memory oldSpenders,
address[2] memory newSpenders
)
internal
{
IEtherToken weth = IEtherToken(_getWETHAddress());
// Grant new allowances.
for (uint256 i = 0; i < oldSpenders.length; i++) {
// Rescind old allowance.
weth.approve(oldSpenders[i], 0);
// Grant new allowance.
weth.approve(newSpenders[i], uint256(-1));
}
}
}

View File

@@ -28,7 +28,6 @@ import "./MixinVaultCore.sol";
contract EthVault is
IEthVault,
IVaultCore,
Ownable,
MixinVaultCore
{
using LibSafeMath for uint256;

View File

@@ -24,15 +24,14 @@ import "@0x/contracts-utils/contracts/src/LibRichErrors.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "../libs/LibStakingRichErrors.sol";
import "../libs/LibSafeDowncast.sol";
import "./MixinVaultCore.sol";
import "../interfaces/IStakingPoolRewardVault.sol";
import "./MixinVaultCore.sol";
/// @dev This vault manages staking pool rewards.
contract StakingPoolRewardVault is
IStakingPoolRewardVault,
IVaultCore,
Ownable,
MixinVaultCore
{
using LibSafeMath for uint256;

View File

@@ -18,11 +18,11 @@
pragma solidity ^0.5.9;
import "../interfaces/IZrxVault.sol";
import "@0x/contracts-utils/contracts/src/LibSafeMath.sol";
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IAssetProxy.sol";
import "@0x/contracts-asset-proxy/contracts/src/interfaces/IAssetData.sol";
import "@0x/contracts-erc20/contracts/src/interfaces/IERC20Token.sol";
import "../interfaces/IZrxVault.sol";
import "./MixinVaultCore.sol";
@@ -36,7 +36,6 @@ import "./MixinVaultCore.sol";
contract ZrxVault is
IVaultCore,
IZrxVault,
Ownable,
MixinVaultCore
{
using LibSafeMath for uint256;

View File

@@ -21,6 +21,7 @@ pragma experimental ABIEncoderV2;
import "../src/StakingProxy.sol";
// solhint-disable no-empty-blocks
contract TestAssertStorageParams is
StakingProxy
{

View File

@@ -25,7 +25,6 @@ import "../src/interfaces/IStructs.sol";
contract TestStorageLayout is
MixinConstants,
Ownable,
MixinStorage
{

View File

@@ -37,7 +37,7 @@
},
"config": {
"abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually.",
"abis": "./generated-artifacts/@(EthVault|IEthVault|IStaking|IStakingEvents|IStakingPoolRewardVault|IStakingProxy|IStorage|IStorageInit|IStructs|IVaultCore|IZrxVault|LibCobbDouglas|LibFixedMath|LibFixedMathRichErrors|LibProxy|LibSafeDowncast|LibStakingRichErrors|MixinConstants|MixinCumulativeRewards|MixinDeploymentConstants|MixinExchangeFees|MixinExchangeManager|MixinParams|MixinScheduler|MixinStake|MixinStakeBalances|MixinStakeStorage|MixinStakingPool|MixinStakingPoolMakers|MixinStakingPoolModifiers|MixinStakingPoolRewards|MixinStorage|MixinVaultCore|ReadOnlyProxy|Staking|StakingPoolRewardVault|StakingProxy|TestAssertStorageParams|TestCobbDouglas|TestCumulativeRewardTracking|TestInitTarget|TestLibFixedMath|TestLibProxy|TestLibProxyReceiver|TestLibSafeDowncast|TestMixinVaultCore|TestProtocolFees|TestProtocolFeesERC20Proxy|TestStaking|TestStakingProxy|TestStorageLayout|ZrxVault).json"
"abis": "./generated-artifacts/@(EthVault|IEthVault|IStaking|IStakingEvents|IStakingPoolRewardVault|IStakingProxy|IStorage|IStorageInit|IStructs|IVaultCore|IZrxVault|LibCobbDouglas|LibFixedMath|LibFixedMathRichErrors|LibProxy|LibSafeDowncast|LibStakingRichErrors|MixinAbstract|MixinConstants|MixinCumulativeRewards|MixinDeploymentConstants|MixinExchangeFees|MixinExchangeManager|MixinFinalizer|MixinParams|MixinScheduler|MixinStake|MixinStakeBalances|MixinStakeStorage|MixinStakingPool|MixinStakingPoolMakers|MixinStakingPoolModifiers|MixinStakingPoolRewards|MixinStorage|MixinVaultCore|ReadOnlyProxy|Staking|StakingPoolRewardVault|StakingProxy|TestAssertStorageParams|TestCobbDouglas|TestCumulativeRewardTracking|TestDelegatorRewards|TestFinalizer|TestInitTarget|TestLibFixedMath|TestLibProxy|TestLibProxyReceiver|TestLibSafeDowncast|TestMixinParams|TestMixinVaultCore|TestProtocolFees|TestStaking|TestStakingNoWETH|TestStakingProxy|TestStorageLayout|ZrxVault).json"
},
"repository": {
"type": "git",

View File

@@ -54,10 +54,11 @@ import * as TestLibFixedMath from '../generated-artifacts/TestLibFixedMath.json'
import * as TestLibProxy from '../generated-artifacts/TestLibProxy.json';
import * as TestLibProxyReceiver from '../generated-artifacts/TestLibProxyReceiver.json';
import * as TestLibSafeDowncast from '../generated-artifacts/TestLibSafeDowncast.json';
import * as TestMixinParams from '../generated-artifacts/TestMixinParams.json';
import * as TestMixinVaultCore from '../generated-artifacts/TestMixinVaultCore.json';
import * as TestProtocolFees from '../generated-artifacts/TestProtocolFees.json';
import * as TestProtocolFeesERC20Proxy from '../generated-artifacts/TestProtocolFeesERC20Proxy.json';
import * as TestStaking from '../generated-artifacts/TestStaking.json';
import * as TestStakingNoWETH from '../generated-artifacts/TestStakingNoWETH.json';
import * as TestStakingProxy from '../generated-artifacts/TestStakingProxy.json';
import * as TestStorageLayout from '../generated-artifacts/TestStorageLayout.json';
import * as ZrxVault from '../generated-artifacts/ZrxVault.json';
@@ -112,10 +113,11 @@ export const artifacts = {
TestLibProxy: TestLibProxy as ContractArtifact,
TestLibProxyReceiver: TestLibProxyReceiver as ContractArtifact,
TestLibSafeDowncast: TestLibSafeDowncast as ContractArtifact,
TestMixinParams: TestMixinParams as ContractArtifact,
TestMixinVaultCore: TestMixinVaultCore as ContractArtifact,
TestProtocolFees: TestProtocolFees as ContractArtifact,
TestProtocolFeesERC20Proxy: TestProtocolFeesERC20Proxy as ContractArtifact,
TestStaking: TestStaking as ContractArtifact,
TestStakingNoWETH: TestStakingNoWETH as ContractArtifact,
TestStakingProxy: TestStakingProxy as ContractArtifact,
TestStorageLayout: TestStorageLayout as ContractArtifact,
};

View File

@@ -52,10 +52,11 @@ export * from '../generated-wrappers/test_lib_fixed_math';
export * from '../generated-wrappers/test_lib_proxy';
export * from '../generated-wrappers/test_lib_proxy_receiver';
export * from '../generated-wrappers/test_lib_safe_downcast';
export * from '../generated-wrappers/test_mixin_params';
export * from '../generated-wrappers/test_mixin_vault_core';
export * from '../generated-wrappers/test_protocol_fees';
export * from '../generated-wrappers/test_protocol_fees_erc20_proxy';
export * from '../generated-wrappers/test_staking';
export * from '../generated-wrappers/test_staking_no_w_e_t_h';
export * from '../generated-wrappers/test_staking_proxy';
export * from '../generated-wrappers/test_storage_layout';
export * from '../generated-wrappers/zrx_vault';

View File

@@ -24,7 +24,7 @@ blockchainTests('Migration tests', env => {
before(async () => {
[authorizedAddress, notAuthorizedAddress] = await env.getAccountAddressesAsync();
stakingContract = await StakingContract.deployFrom0xArtifactAsync(
artifacts.Staking,
artifacts.TestStakingNoWETH,
env.provider,
env.txDefaults,
artifacts,

View File

@@ -1,4 +1,4 @@
import { blockchainTests, expect, filterLogsToArguments } from '@0x/contracts-test-utils';
import { blockchainTests, constants, expect, filterLogsToArguments, randomAddress } from '@0x/contracts-test-utils';
import { AuthorizableRevertErrors, BigNumber } from '@0x/utils';
import { TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import * as _ from 'lodash';
@@ -89,6 +89,43 @@ blockchainTests('Configurable Parameters unit tests', env => {
it('works if called by owner', async () => {
return setParamsAndAssertAsync({});
});
describe('WETH allowance', () => {
it('rescinds allowance for old vaults and grants unlimited allowance to new ones', async () => {
const [oldEthVaultAddress, oldRewardVaultAddress, newEthVaultAddress, newRewardVaultAddress] = _.times(
4,
() => randomAddress(),
);
await testContract.setVaultAddresses.awaitTransactionSuccessAsync(
oldEthVaultAddress,
oldRewardVaultAddress,
);
const { logs } = await setParamsAndAssertAsync({
ethVaultAddress: newEthVaultAddress,
rewardVaultAddress: newRewardVaultAddress,
});
const approveEvents = filterLogsToArguments<TestMixinParamsWETHApproveEventArgs>(
logs,
TestMixinParamsEvents.WETHApprove,
);
expect(approveEvents[0]).to.deep.eq({
spender: oldEthVaultAddress,
amount: constants.ZERO_AMOUNT,
});
expect(approveEvents[1]).to.deep.eq({
spender: newEthVaultAddress,
amount: constants.MAX_UINT256,
});
expect(approveEvents[2]).to.deep.eq({
spender: oldRewardVaultAddress,
amount: constants.ZERO_AMOUNT,
});
expect(approveEvents[3]).to.deep.eq({
spender: newRewardVaultAddress,
amount: constants.MAX_UINT256,
});
});
});
});
});
// tslint:enable:no-unnecessary-type-assertion

View File

@@ -1,7 +1,7 @@
import { ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { artifacts as erc20Artifacts, DummyERC20TokenContract, WETH9Contract } from '@0x/contracts-erc20';
import { BlockchainTestsEnvironment, constants, filterLogsToArguments, txDefaults } from '@0x/contracts-test-utils';
import { BigNumber, logUtils } from '@0x/utils';
import { BigNumber } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper';
import { BlockParamLiteral, ContractArtifact, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import * as _ from 'lodash';
@@ -52,14 +52,11 @@ export class StakingApiWrapper {
skipToNextEpochAndFinalizeAsync: async (): Promise<DecodedLogs> => {
await this.utils.fastForwardToNextEpochAsync();
const endOfEpochInfo = await this.utils.endEpochAsync();
let totalGasUsed = 0;
const allLogs = [] as DecodedLogs;
for (const poolId of endOfEpochInfo.activePoolIds) {
const receipt = await this.stakingContract.finalizePool.awaitTransactionSuccessAsync(poolId);
totalGasUsed += receipt.gasUsed;
allLogs.splice(allLogs.length, 0, ...(receipt.logs as DecodedLogs));
}
logUtils.log(`Finalization cost ${totalGasUsed} gas`);
return allLogs;
},

View File

@@ -52,10 +52,11 @@
"generated-artifacts/TestLibProxy.json",
"generated-artifacts/TestLibProxyReceiver.json",
"generated-artifacts/TestLibSafeDowncast.json",
"generated-artifacts/TestMixinParams.json",
"generated-artifacts/TestMixinVaultCore.json",
"generated-artifacts/TestProtocolFees.json",
"generated-artifacts/TestProtocolFeesERC20Proxy.json",
"generated-artifacts/TestStaking.json",
"generated-artifacts/TestStakingNoWETH.json",
"generated-artifacts/TestStakingProxy.json",
"generated-artifacts/TestStorageLayout.json",
"generated-artifacts/ZrxVault.json"