@0x/contracts-staking: Add maximumMakersInPool hyper parameter.
`@0x/contracts-staking`: Add assertions against `maximumMakersInPool` and `rewardDelegatedStakeWeight`. `@0x/contracts-staking`: Rebase against 3.0 (again).
This commit is contained in:
@@ -24,6 +24,7 @@ blockchainTests('Hyper-Parameters', env => {
|
||||
epochDurationInSeconds: Numberish;
|
||||
rewardDelegatedStakeWeight: Numberish;
|
||||
minimumPoolStake: Numberish;
|
||||
maximumMakersInPool: Numberish;
|
||||
cobbDouglasAlphaNumerator: Numberish;
|
||||
cobbDouglasAlphaDenomintor: Numberish;
|
||||
}
|
||||
@@ -34,6 +35,7 @@ blockchainTests('Hyper-Parameters', env => {
|
||||
epochDurationInSeconds: TWO_WEEKS,
|
||||
rewardDelegatedStakeWeight: PPM_90_PERCENT,
|
||||
minimumPoolStake: '100e18',
|
||||
maximumMakersInPool: 10,
|
||||
cobbDouglasAlphaNumerator: 1,
|
||||
cobbDouglasAlphaDenomintor: 2,
|
||||
};
|
||||
@@ -47,6 +49,7 @@ blockchainTests('Hyper-Parameters', env => {
|
||||
new BigNumber(_params.epochDurationInSeconds),
|
||||
new BigNumber(_params.rewardDelegatedStakeWeight),
|
||||
new BigNumber(_params.minimumPoolStake),
|
||||
new BigNumber(_params.maximumMakersInPool),
|
||||
new BigNumber(_params.cobbDouglasAlphaNumerator),
|
||||
new BigNumber(_params.cobbDouglasAlphaDenomintor),
|
||||
{ from },
|
||||
@@ -57,6 +60,7 @@ blockchainTests('Hyper-Parameters', env => {
|
||||
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);
|
||||
// Assert `getHyperParameters()`.
|
||||
@@ -64,8 +68,9 @@ blockchainTests('Hyper-Parameters', env => {
|
||||
expect(actual[0]).to.bignumber.eq(_params.epochDurationInSeconds);
|
||||
expect(actual[1]).to.bignumber.eq(_params.rewardDelegatedStakeWeight);
|
||||
expect(actual[2]).to.bignumber.eq(_params.minimumPoolStake);
|
||||
expect(actual[3]).to.bignumber.eq(_params.cobbDouglasAlphaNumerator);
|
||||
expect(actual[4]).to.bignumber.eq(_params.cobbDouglasAlphaDenomintor);
|
||||
expect(actual[3]).to.bignumber.eq(_params.maximumMakersInPool);
|
||||
expect(actual[4]).to.bignumber.eq(_params.cobbDouglasAlphaNumerator);
|
||||
expect(actual[5]).to.bignumber.eq(_params.cobbDouglasAlphaDenomintor);
|
||||
}
|
||||
|
||||
it('throws if not called by owner', async () => {
|
||||
@@ -78,6 +83,33 @@ blockchainTests('Hyper-Parameters', env => {
|
||||
return tuneAndAssertAsync({});
|
||||
});
|
||||
|
||||
describe('rewardDelegatedStakeWeight', () => {
|
||||
it('throws when > PPM_100_PERCENT', async () => {
|
||||
const params = {
|
||||
// tslint:disable-next-line restrict-plus-operands
|
||||
rewardDelegatedStakeWeight: constants.PPM_100_PERCENT + 1,
|
||||
};
|
||||
const tx = tuneAndAssertAsync(params);
|
||||
const expectedError = new StakingRevertErrors.InvalidTuningValueError(
|
||||
StakingRevertErrors.InvalidTuningValueErrorCode.InvalidRewardDelegatedStakeWeight,
|
||||
);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('maximumMakersInPool', () => {
|
||||
it('throws when == 0', async () => {
|
||||
const params = {
|
||||
maximumMakersInPool: 0,
|
||||
};
|
||||
const tx = tuneAndAssertAsync(params);
|
||||
const expectedError = new StakingRevertErrors.InvalidTuningValueError(
|
||||
StakingRevertErrors.InvalidTuningValueErrorCode.InvalidMaximumMakersInPool,
|
||||
);
|
||||
return expect(tx).to.revertWith(expectedError);
|
||||
});
|
||||
});
|
||||
|
||||
describe('cobb-douglas alpha', () => {
|
||||
const NEGATIVE_ONE = constants.MAX_UINT256.minus(1);
|
||||
|
||||
|
||||
@@ -321,7 +321,11 @@ blockchainTests('Staking Pool Management', env => {
|
||||
const operatorShare = (39 / 100) * PPM_DENOMINATOR;
|
||||
const poolOperator = new PoolOperatorActor(operatorAddress, stakingApiWrapper);
|
||||
|
||||
const makerAddresses = users.slice(1, stakingConstants.MAX_MAKERS_IN_POOL + 2);
|
||||
const makerAddresses = users.slice(
|
||||
1,
|
||||
// tslint:disable-next-line restrict-plus-operands
|
||||
stakingConstants.DEFAULT_HYPER_PARAMETERS.maximumMakersInPool.toNumber() + 2,
|
||||
);
|
||||
const makers = makerAddresses.map(makerAddress => new MakerActor(makerAddress, stakingApiWrapper));
|
||||
|
||||
// create pool
|
||||
@@ -338,7 +342,9 @@ blockchainTests('Staking Pool Management', env => {
|
||||
|
||||
// check the number of makers in the pool
|
||||
const numMakers = await stakingApiWrapper.stakingContract.getNumberOfMakersInStakingPool.callAsync(poolId);
|
||||
expect(numMakers, 'number of makers in pool').to.be.bignumber.equal(stakingConstants.MAX_MAKERS_IN_POOL);
|
||||
expect(numMakers, 'number of makers in pool').to.be.bignumber.equal(
|
||||
stakingConstants.DEFAULT_HYPER_PARAMETERS.maximumMakersInPool,
|
||||
);
|
||||
|
||||
const lastMakerAddress = _.last(makerAddresses) as string;
|
||||
// Try to add last maker to the pool
|
||||
|
||||
@@ -15,7 +15,7 @@ export const constants = {
|
||||
epochDurationInSeconds: new BigNumber(TWO_WEEKS),
|
||||
rewardDelegatedStakeWeight: new BigNumber(0.9 * 1e6), // 90%
|
||||
minimumPoolStake: testConstants.DUMMY_TOKEN_DECIMALS.times(100), // 100 ZRX
|
||||
maxMakersInPool: new BigNumber(10),
|
||||
maximumMakersInPool: new BigNumber(10),
|
||||
cobbDouglasAlphaNumerator: new BigNumber(1),
|
||||
cobbDouglasAlphaDenomintor: new BigNumber(2),
|
||||
},
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
} from '../../src';
|
||||
|
||||
import { constants } from './constants';
|
||||
import { HyperParameters, SignedStakingPoolApproval, StakeBalance } from './types';
|
||||
import { HyperParameters, StakeBalance } from './types';
|
||||
|
||||
export class StakingWrapper {
|
||||
private readonly _web3Wrapper: Web3Wrapper;
|
||||
@@ -200,6 +200,7 @@ export class StakingWrapper {
|
||||
_params.epochDurationInSeconds,
|
||||
_params.rewardDelegatedStakeWeight,
|
||||
_params.minimumPoolStake,
|
||||
_params.maximumMakersInPool,
|
||||
_params.cobbDouglasAlphaNumerator,
|
||||
_params.cobbDouglasAlphaDenomintor,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user