Fix build
This commit is contained in:
parent
de9527ce2f
commit
6641af2a58
@ -1,4 +1,4 @@
|
||||
import { blockchainTests, constants, expect, filterLogsToArguments, hexRandom } from '@0x/contracts-test-utils';
|
||||
import { blockchainTests, constants, expect, filterLogsToArguments, randomAddress } from '@0x/contracts-test-utils';
|
||||
import { StakingRevertErrors } from '@0x/order-utils';
|
||||
import { BigNumber, OwnableRevertErrors, StringRevertError } from '@0x/utils';
|
||||
|
||||
@ -42,10 +42,6 @@ blockchainTests('Migration tests', env => {
|
||||
);
|
||||
});
|
||||
|
||||
function randomAddress(): string {
|
||||
return hexRandom(constants.ADDRESS_LENGTH);
|
||||
}
|
||||
|
||||
async function enableInitRevertsAsync(): Promise<void> {
|
||||
const revertAddress = await initTargetContract.SHOULD_REVERT_ADDRESS.callAsync();
|
||||
// Deposit some ether into `revertAddress` to signal `initTargetContract`
|
||||
@ -67,7 +63,7 @@ blockchainTests('Migration tests', env => {
|
||||
});
|
||||
expect(senderAddress).to.eq(ownerAddress);
|
||||
expect(thisAddress).to.eq(proxyContract.address);
|
||||
const attachedAddress = await proxyContract.getAttachedContract.callAsync();
|
||||
const attachedAddress = await proxyContract.stakingContract.callAsync();
|
||||
expect(attachedAddress).to.eq(initTargetContract.address);
|
||||
}
|
||||
|
||||
@ -150,14 +146,32 @@ blockchainTests('Migration tests', env => {
|
||||
});
|
||||
|
||||
it('throws if not called by owner', async () => {
|
||||
const tx = stakingContract.init.awaitTransactionSuccessAsync({ from: notOwnerAddress });
|
||||
const tx = stakingContract.init.awaitTransactionSuccessAsync(
|
||||
randomAddress(),
|
||||
randomAddress(),
|
||||
randomAddress(),
|
||||
randomAddress(),
|
||||
{
|
||||
from: notOwnerAddress,
|
||||
},
|
||||
);
|
||||
const expectedError = new OwnableRevertErrors.OnlyOwnerError(notOwnerAddress, ownerAddress);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
||||
it('throws if already intitialized', async () => {
|
||||
await stakingContract.init.awaitTransactionSuccessAsync();
|
||||
const tx = stakingContract.init.awaitTransactionSuccessAsync();
|
||||
await stakingContract.init.awaitTransactionSuccessAsync(
|
||||
randomAddress(),
|
||||
randomAddress(),
|
||||
randomAddress(),
|
||||
randomAddress(),
|
||||
);
|
||||
const tx = stakingContract.init.awaitTransactionSuccessAsync(
|
||||
randomAddress(),
|
||||
randomAddress(),
|
||||
randomAddress(),
|
||||
randomAddress(),
|
||||
);
|
||||
const expectedError = new StakingRevertErrors.InitializationError();
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
|
@ -1,8 +1,11 @@
|
||||
import { blockchainTests, constants, expect, filterLogsToArguments, Numberish } from '@0x/contracts-test-utils';
|
||||
import { blockchainTests, constants, expect, filterLogsToArguments } from '@0x/contracts-test-utils';
|
||||
import { StakingRevertErrors } from '@0x/order-utils';
|
||||
import { BigNumber, OwnableRevertErrors } from '@0x/utils';
|
||||
|
||||
import { artifacts, IStakingEventsParamsChangedEventArgs, MixinParamsContract } from '../src/';
|
||||
import { artifacts, IStakingEventsParamsSetEventArgs, MixinParamsContract } from '../src/';
|
||||
|
||||
import { constants as stakingConstants } from './utils/constants';
|
||||
import { StakingParams } from './utils/types';
|
||||
|
||||
blockchainTests('Configurable Parameters', env => {
|
||||
let testContract: MixinParamsContract;
|
||||
@ -20,29 +23,9 @@ blockchainTests('Configurable Parameters', env => {
|
||||
});
|
||||
|
||||
blockchainTests.resets('setParams()', () => {
|
||||
interface Params {
|
||||
epochDurationInSeconds: Numberish;
|
||||
rewardDelegatedStakeWeight: Numberish;
|
||||
minimumPoolStake: Numberish;
|
||||
maximumMakersInPool: Numberish;
|
||||
cobbDouglasAlphaNumerator: Numberish;
|
||||
cobbDouglasAlphaDenomintor: Numberish;
|
||||
}
|
||||
|
||||
const TWO_WEEKS = 14 * 24 * 60 * 60;
|
||||
const PPM_90_PERCENT = 10 ** 6 * 0.9;
|
||||
const DEFAULT_PARAMS = {
|
||||
epochDurationInSeconds: TWO_WEEKS,
|
||||
rewardDelegatedStakeWeight: PPM_90_PERCENT,
|
||||
minimumPoolStake: constants.DUMMY_TOKEN_DECIMALS.times(100),
|
||||
maximumMakersInPool: 10,
|
||||
cobbDouglasAlphaNumerator: 1,
|
||||
cobbDouglasAlphaDenomintor: 2,
|
||||
};
|
||||
|
||||
async function setParamsAndAssertAsync(params: Partial<Params>, from?: string): Promise<void> {
|
||||
async function setParamsAndAssertAsync(params: Partial<StakingParams>, from?: string): Promise<void> {
|
||||
const _params = {
|
||||
...DEFAULT_PARAMS,
|
||||
...stakingConstants.DEFAULT_PARAMS,
|
||||
...params,
|
||||
};
|
||||
const receipt = await testContract.setParams.awaitTransactionSuccessAsync(
|
||||
@ -52,17 +35,25 @@ blockchainTests('Configurable Parameters', env => {
|
||||
new BigNumber(_params.maximumMakersInPool),
|
||||
new BigNumber(_params.cobbDouglasAlphaNumerator),
|
||||
new BigNumber(_params.cobbDouglasAlphaDenomintor),
|
||||
_params.wethProxyAddress,
|
||||
_params.ethVaultAddress,
|
||||
_params.rewardVaultAddress,
|
||||
_params.zrxVaultAddress,
|
||||
{ from },
|
||||
);
|
||||
// Assert event.
|
||||
expect(receipt.logs.length).to.eq(1);
|
||||
const event = filterLogsToArguments<IStakingEventsParamsChangedEventArgs>(receipt.logs, 'ParamsChanged')[0];
|
||||
const event = filterLogsToArguments<IStakingEventsParamsSetEventArgs>(receipt.logs, 'ParamsChanged')[0];
|
||||
expect(event.epochDurationInSeconds).to.bignumber.eq(_params.epochDurationInSeconds);
|
||||
expect(event.rewardDelegatedStakeWeight).to.bignumber.eq(_params.rewardDelegatedStakeWeight);
|
||||
expect(event.minimumPoolStake).to.bignumber.eq(_params.minimumPoolStake);
|
||||
expect(event.maximumMakersInPool).to.bignumber.eq(_params.maximumMakersInPool);
|
||||
expect(event.cobbDouglasAlphaNumerator).to.bignumber.eq(_params.cobbDouglasAlphaNumerator);
|
||||
expect(event.cobbDouglasAlphaDenomintor).to.bignumber.eq(_params.cobbDouglasAlphaDenomintor);
|
||||
expect(event.wethProxyAddress).to.eq(_params.wethProxyAddress);
|
||||
expect(event.ethVaultAddress).to.eq(_params.ethVaultAddress);
|
||||
expect(event.rewardVaultAddress).to.eq(_params.rewardVaultAddress);
|
||||
expect(event.zrxVaultAddress).to.eq(_params.zrxVaultAddress);
|
||||
// Assert `getParams()`.
|
||||
const actual = await testContract.getParams.callAsync();
|
||||
expect(actual[0]).to.bignumber.eq(_params.epochDurationInSeconds);
|
||||
@ -71,6 +62,10 @@ blockchainTests('Configurable Parameters', env => {
|
||||
expect(actual[3]).to.bignumber.eq(_params.maximumMakersInPool);
|
||||
expect(actual[4]).to.bignumber.eq(_params.cobbDouglasAlphaNumerator);
|
||||
expect(actual[5]).to.bignumber.eq(_params.cobbDouglasAlphaDenomintor);
|
||||
expect(actual[6]).to.eq(_params.wethProxyAddress);
|
||||
expect(actual[7]).to.eq(_params.ethVaultAddress);
|
||||
expect(actual[8]).to.eq(_params.rewardVaultAddress);
|
||||
expect(actual[9]).to.eq(_params.zrxVaultAddress);
|
||||
}
|
||||
|
||||
it('throws if not called by owner', async () => {
|
||||
@ -99,7 +94,7 @@ blockchainTests('Configurable Parameters', env => {
|
||||
describe('maximumMakersInPool', () => {
|
||||
it('throws when == 0', async () => {
|
||||
const params = {
|
||||
maximumMakersInPool: 0,
|
||||
maximumMakersInPool: constants.ZERO_AMOUNT,
|
||||
};
|
||||
const tx = setParamsAndAssertAsync(params);
|
||||
const expectedError = new StakingRevertErrors.InvalidParamValueError(
|
||||
|
@ -1,4 +1,11 @@
|
||||
import { blockchainTests, constants, expect, filterLogsToArguments, hexRandom } from '@0x/contracts-test-utils';
|
||||
import {
|
||||
blockchainTests,
|
||||
constants,
|
||||
expect,
|
||||
filterLogsToArguments,
|
||||
hexRandom,
|
||||
randomAddress,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { StakingRevertErrors } from '@0x/order-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { LogEntry } from 'ethereum-types';
|
||||
@ -54,7 +61,6 @@ blockchainTests('Protocol Fee Unit Tests', env => {
|
||||
}
|
||||
|
||||
blockchainTests.resets('payProtocolFee()', () => {
|
||||
const randomAddress = () => hexRandom(constants.ADDRESS_LENGTH);
|
||||
const DEFAULT_PROTOCOL_FEE_PAID = new BigNumber(150e3).times(1e9);
|
||||
const { ZERO_AMOUNT } = constants;
|
||||
const makerAddress = randomAddress();
|
||||
|
@ -79,6 +79,10 @@ export class StakingApiWrapper {
|
||||
_params.maximumMakersInPool,
|
||||
_params.cobbDouglasAlphaNumerator,
|
||||
_params.cobbDouglasAlphaDenomintor,
|
||||
_params.wethProxyAddress,
|
||||
_params.ethVaultAddress,
|
||||
_params.rewardVaultAddress,
|
||||
_params.zrxVaultAddress,
|
||||
);
|
||||
},
|
||||
|
||||
@ -164,38 +168,6 @@ export async function deployAndConfigureContractsAsync(
|
||||
txDefaults,
|
||||
artifacts,
|
||||
);
|
||||
// deploy staking proxy
|
||||
const stakingProxyContract = await StakingProxyContract.deployFrom0xArtifactAsync(
|
||||
artifacts.StakingProxy,
|
||||
env.provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
stakingContract.address,
|
||||
readOnlyProxyContract.address,
|
||||
erc20ProxyContract.address,
|
||||
);
|
||||
|
||||
// deploy zrx vault
|
||||
const zrxVaultContract = await ZrxVaultContract.deployFrom0xArtifactAsync(
|
||||
artifacts.ZrxVault,
|
||||
env.provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
erc20ProxyContract.address,
|
||||
zrxTokenContract.address,
|
||||
);
|
||||
// configure erc20 proxy to accept calls from zrx vault
|
||||
await erc20ProxyContract.addAuthorizedAddress.awaitTransactionSuccessAsync(zrxVaultContract.address);
|
||||
// set staking proxy contract in zrx vault
|
||||
await zrxVaultContract.setStakingContract.awaitTransactionSuccessAsync(stakingProxyContract.address);
|
||||
// set zrx vault in staking contract
|
||||
const setZrxVaultCalldata = stakingContract.setZrxVault.getABIEncodedTransactionData(zrxVaultContract.address);
|
||||
const setZrxVaultTxData = {
|
||||
from: ownerAddress,
|
||||
to: stakingProxyContract.address,
|
||||
data: setZrxVaultCalldata,
|
||||
};
|
||||
await env.web3Wrapper.awaitTransactionSuccessAsync(await env.web3Wrapper.sendTransactionAsync(setZrxVaultTxData));
|
||||
// deploy eth vault
|
||||
const ethVaultContract = await EthVaultContract.deployFrom0xArtifactAsync(
|
||||
artifacts.EthVault,
|
||||
@ -210,22 +182,35 @@ export async function deployAndConfigureContractsAsync(
|
||||
txDefaults,
|
||||
artifacts,
|
||||
);
|
||||
// set eth vault in reward vault
|
||||
await rewardVaultContract.setEthVault.sendTransactionAsync(ethVaultContract.address);
|
||||
// set staking proxy contract in reward vault
|
||||
await rewardVaultContract.setStakingContract.awaitTransactionSuccessAsync(stakingProxyContract.address);
|
||||
// set reward vault in staking contract
|
||||
const setStakingPoolRewardVaultCalldata = stakingContract.setStakingPoolRewardVault.getABIEncodedTransactionData(
|
||||
// deploy zrx vault
|
||||
const zrxVaultContract = await ZrxVaultContract.deployFrom0xArtifactAsync(
|
||||
artifacts.ZrxVault,
|
||||
env.provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
erc20ProxyContract.address,
|
||||
zrxTokenContract.address,
|
||||
);
|
||||
// deploy staking proxy
|
||||
const stakingProxyContract = await StakingProxyContract.deployFrom0xArtifactAsync(
|
||||
artifacts.StakingProxy,
|
||||
env.provider,
|
||||
txDefaults,
|
||||
artifacts,
|
||||
stakingContract.address,
|
||||
readOnlyProxyContract.address,
|
||||
erc20ProxyContract.address,
|
||||
ethVaultContract.address,
|
||||
rewardVaultContract.address,
|
||||
zrxVaultContract.address,
|
||||
);
|
||||
const setStakingPoolRewardVaultTxData = {
|
||||
from: ownerAddress,
|
||||
to: stakingProxyContract.address,
|
||||
data: setStakingPoolRewardVaultCalldata,
|
||||
};
|
||||
await env.web3Wrapper.awaitTransactionSuccessAsync(
|
||||
await env.web3Wrapper.sendTransactionAsync(setStakingPoolRewardVaultTxData),
|
||||
);
|
||||
|
||||
// configure erc20 proxy to accept calls from zrx vault
|
||||
await erc20ProxyContract.addAuthorizedAddress.awaitTransactionSuccessAsync(zrxVaultContract.address);
|
||||
// set staking proxy contract in zrx vault
|
||||
await zrxVaultContract.setStakingProxy.awaitTransactionSuccessAsync(stakingProxyContract.address);
|
||||
// set staking proxy contract in reward vault
|
||||
await rewardVaultContract.setStakingProxy.awaitTransactionSuccessAsync(stakingProxyContract.address);
|
||||
|
||||
return new StakingApiWrapper(
|
||||
env,
|
||||
|
@ -1,7 +1,8 @@
|
||||
import { constants as testConstants } from '@0x/contracts-test-utils';
|
||||
import { constants as testConstants, randomAddress } from '@0x/contracts-test-utils';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
|
||||
const TWO_WEEKS = 14 * 24 * 60 * 60;
|
||||
const PPM_90_PERCENT = 10 ** 6 * 0.9;
|
||||
export const constants = {
|
||||
TOKEN_MULTIPLIER: testConstants.DUMMY_TOKEN_DECIMALS,
|
||||
INITIAL_POOL_ID: '0x0000000000000000000000000000000100000000000000000000000000000000',
|
||||
@ -11,10 +12,14 @@ export const constants = {
|
||||
INITIAL_EPOCH: new BigNumber(0),
|
||||
DEFAULT_PARAMS: {
|
||||
epochDurationInSeconds: new BigNumber(TWO_WEEKS),
|
||||
rewardDelegatedStakeWeight: new BigNumber(0.9 * 1e6), // 90%
|
||||
minimumPoolStake: testConstants.DUMMY_TOKEN_DECIMALS.times(100), // 100 ZRX
|
||||
rewardDelegatedStakeWeight: new BigNumber(PPM_90_PERCENT),
|
||||
minimumPoolStake: testConstants.DUMMY_TOKEN_DECIMALS.times(100),
|
||||
maximumMakersInPool: new BigNumber(10),
|
||||
cobbDouglasAlphaNumerator: new BigNumber(1),
|
||||
cobbDouglasAlphaDenomintor: new BigNumber(2),
|
||||
wethProxyAddress: randomAddress(),
|
||||
ethVaultAddress: randomAddress(),
|
||||
rewardVaultAddress: randomAddress(),
|
||||
zrxVaultAddress: randomAddress(),
|
||||
},
|
||||
};
|
||||
|
@ -4,11 +4,15 @@ import { constants } from './constants';
|
||||
|
||||
export interface StakingParams {
|
||||
epochDurationInSeconds: BigNumber;
|
||||
rewardDelegatedStakeWeight: BigNumber;
|
||||
rewardDelegatedStakeWeight: number | BigNumber;
|
||||
minimumPoolStake: BigNumber;
|
||||
maxMakersInPool: BigNumber;
|
||||
cobbDouglasAlphaNumerator: BigNumber;
|
||||
cobbDouglasAlphaDenomintor: BigNumber;
|
||||
maximumMakersInPool: BigNumber;
|
||||
cobbDouglasAlphaNumerator: number | BigNumber;
|
||||
cobbDouglasAlphaDenomintor: number | BigNumber;
|
||||
wethProxyAddress: string;
|
||||
ethVaultAddress: string;
|
||||
rewardVaultAddress: string;
|
||||
zrxVaultAddress: string;
|
||||
}
|
||||
|
||||
export interface StakerBalances {
|
||||
|
@ -1,11 +1,6 @@
|
||||
import { generatePseudoRandomSalt } from '@0x/order-utils';
|
||||
import { crypto } from '@0x/order-utils/lib/src/crypto';
|
||||
import { constants } from './constants';
|
||||
import { hexRandom } from './hex_utils';
|
||||
|
||||
export const addressUtils = {
|
||||
generatePseudoRandomAddress(): string {
|
||||
const randomBigNum = generatePseudoRandomSalt();
|
||||
const randomBuff = crypto.solSHA3([randomBigNum]);
|
||||
const randomAddress = `0x${randomBuff.slice(0, 20).toString('hex')}`;
|
||||
return randomAddress;
|
||||
},
|
||||
};
|
||||
export function randomAddress(): string {
|
||||
return hexRandom(constants.ADDRESS_LENGTH);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ export { typeEncodingUtils } from './type_encoding_utils';
|
||||
export { profiler } from './profiler';
|
||||
export { coverage } from './coverage';
|
||||
export { Web3ProviderEngine } from '@0x/subproviders';
|
||||
export { addressUtils } from './address_utils';
|
||||
export { randomAddress } from './address_utils';
|
||||
export { OrderFactory } from './order_factory';
|
||||
export { bytes32Values, testCombinatoriallyWithReferenceFunc, uint256Values } from './combinatorial_utils';
|
||||
export { TransactionFactory } from './transaction_factory';
|
||||
|
Loading…
x
Reference in New Issue
Block a user