Changed nextPoolId
to lastPoolId
This commit is contained in:
@@ -68,8 +68,8 @@ contract MixinStorage is
|
||||
// mapping from Owner to Amount of Withdrawable Stake
|
||||
mapping (address => uint256) internal _withdrawableStakeByOwner;
|
||||
|
||||
// tracking Pool Id
|
||||
bytes32 public nextPoolId = bytes32(uint256(1));
|
||||
// tracking Pool Id, a unique identifier for each staking pool.
|
||||
bytes32 public lastPoolId;
|
||||
|
||||
// mapping from Maker Address to Pool Id of maker
|
||||
mapping (address => bytes32) public poolIdByMaker;
|
||||
|
@@ -40,7 +40,7 @@ interface IStorage {
|
||||
view
|
||||
returns (address);
|
||||
|
||||
function nextPoolId()
|
||||
function lastPoolId()
|
||||
external
|
||||
view
|
||||
returns (bytes32);
|
||||
|
@@ -53,9 +53,8 @@ contract MixinStakingPool is
|
||||
// note that an operator must be payable
|
||||
address payable operator = msg.sender;
|
||||
|
||||
// assign pool id and generate next id
|
||||
poolId = nextPoolId;
|
||||
nextPoolId = _computeNextStakingPoolId(poolId);
|
||||
// compute unique id for this pool
|
||||
poolId = lastPoolId = bytes32(uint256(lastPoolId).safeAdd(1));
|
||||
|
||||
// sanity check on operator share
|
||||
_assertNewOperatorShare(
|
||||
@@ -80,7 +79,7 @@ contract MixinStakingPool is
|
||||
emit StakingPoolCreated(poolId, operator, operatorShare);
|
||||
|
||||
if (addOperatorAsMaker) {
|
||||
setMakerStakingPool(poolId);
|
||||
joinStakingPoolAsMaker(poolId);
|
||||
}
|
||||
|
||||
return poolId;
|
||||
@@ -112,7 +111,7 @@ contract MixinStakingPool is
|
||||
|
||||
/// @dev Allows caller to join a staking pool as a maker.
|
||||
/// @param poolId Unique id of pool.
|
||||
function setMakerStakingPool(bytes32 poolId)
|
||||
function joinStakingPoolAsMaker(bytes32 poolId)
|
||||
public
|
||||
{
|
||||
address maker = msg.sender;
|
||||
@@ -133,17 +132,6 @@ contract MixinStakingPool is
|
||||
return _poolById[poolId];
|
||||
}
|
||||
|
||||
/// @dev Computes the unique id that comes after the input pool id.
|
||||
/// @param poolId Unique id of pool.
|
||||
/// @return Next pool id after input pool.
|
||||
function _computeNextStakingPoolId(bytes32 poolId)
|
||||
internal
|
||||
pure
|
||||
returns (bytes32)
|
||||
{
|
||||
return bytes32(uint256(poolId).safeAdd(1));
|
||||
}
|
||||
|
||||
/// @dev Reverts iff a staking pool does not exist.
|
||||
/// @param poolId Unique id of pool.
|
||||
function _assertStakingPoolExists(bytes32 poolId)
|
||||
|
@@ -175,8 +175,8 @@ contract TestStorageLayoutAndConstants is
|
||||
slot := add(slot, 0x1)
|
||||
|
||||
assertSlotAndOffset(
|
||||
nextPoolId_slot,
|
||||
nextPoolId_offset,
|
||||
lastPoolId_slot,
|
||||
lastPoolId_offset,
|
||||
slot,
|
||||
offset
|
||||
)
|
||||
|
@@ -5,9 +5,9 @@ import * as _ from 'lodash';
|
||||
import { PoolOperatorActor } from './pool_operator_actor';
|
||||
|
||||
export class MakerActor extends PoolOperatorActor {
|
||||
public async setMakerStakingPoolAsync(poolId: string, revertError?: RevertError): Promise<void> {
|
||||
public async joinStakingPoolAsMakerAsync(poolId: string, revertError?: RevertError): Promise<void> {
|
||||
// add maker
|
||||
const txReceiptPromise = this._stakingApiWrapper.stakingContract.setMakerStakingPool.awaitTransactionSuccessAsync(
|
||||
const txReceiptPromise = this._stakingApiWrapper.stakingContract.joinStakingPoolAsMaker.awaitTransactionSuccessAsync(
|
||||
poolId,
|
||||
{ from: this.getOwner() },
|
||||
);
|
||||
|
@@ -10,8 +10,6 @@ export class PoolOperatorActor extends BaseActor {
|
||||
addOperatorAsMaker: boolean,
|
||||
revertError?: RevertError,
|
||||
): Promise<string> {
|
||||
// query next pool id
|
||||
const nextPoolId = await this._stakingApiWrapper.stakingContract.nextPoolId.callAsync();
|
||||
// create pool
|
||||
const poolIdPromise = this._stakingApiWrapper.utils.createStakingPoolAsync(
|
||||
this._owner,
|
||||
@@ -24,7 +22,8 @@ export class PoolOperatorActor extends BaseActor {
|
||||
}
|
||||
const poolId = await poolIdPromise;
|
||||
// validate pool id
|
||||
expect(poolId, 'pool id').to.be.bignumber.equal(nextPoolId);
|
||||
const lastPoolId = await this._stakingApiWrapper.stakingContract.lastPoolId.callAsync();
|
||||
expect(poolId, 'pool id').to.be.bignumber.equal(lastPoolId);
|
||||
|
||||
if (addOperatorAsMaker) {
|
||||
// check the pool id of the operator
|
||||
|
@@ -40,8 +40,8 @@ blockchainTests('Staking Pool Management', env => {
|
||||
const poolId = await poolOperator.createStakingPoolAsync(operatorShare, false);
|
||||
expect(poolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
|
||||
// check that the next pool id was incremented
|
||||
const nextPoolId = await stakingApiWrapper.stakingContract.nextPoolId.callAsync();
|
||||
expect(nextPoolId).to.be.equal(stakingConstants.SECOND_POOL_ID);
|
||||
const lastPoolId = await stakingApiWrapper.stakingContract.lastPoolId.callAsync();
|
||||
expect(lastPoolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
|
||||
});
|
||||
it('Should successfully create several staking pools, as long as the operator is only a maker in one', async () => {
|
||||
// test parameters
|
||||
@@ -77,8 +77,8 @@ blockchainTests('Staking Pool Management', env => {
|
||||
const poolId = await poolOperator.createStakingPoolAsync(operatorShare, true);
|
||||
expect(poolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
|
||||
// check that the next pool id was incremented
|
||||
const nextPoolId = await stakingApiWrapper.stakingContract.nextPoolId.callAsync();
|
||||
expect(nextPoolId).to.be.equal(stakingConstants.SECOND_POOL_ID);
|
||||
const lastPoolId = await stakingApiWrapper.stakingContract.lastPoolId.callAsync();
|
||||
expect(lastPoolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
|
||||
});
|
||||
it('Should throw if operatorShare is > PPM_DENOMINATOR', async () => {
|
||||
// test parameters
|
||||
@@ -107,7 +107,7 @@ blockchainTests('Staking Pool Management', env => {
|
||||
const poolId = await poolOperator.createStakingPoolAsync(operatorShare, true);
|
||||
expect(poolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
|
||||
// maker joins pool
|
||||
await maker.setMakerStakingPoolAsync(poolId);
|
||||
await maker.joinStakingPoolAsMakerAsync(poolId);
|
||||
});
|
||||
it('Maker should successfully remove themselves from a pool', async () => {
|
||||
// test parameters
|
||||
@@ -120,9 +120,9 @@ blockchainTests('Staking Pool Management', env => {
|
||||
const poolId = await poolOperator.createStakingPoolAsync(operatorShare, true);
|
||||
expect(poolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
|
||||
// maker joins pool
|
||||
await maker.setMakerStakingPoolAsync(poolId);
|
||||
await maker.joinStakingPoolAsMakerAsync(poolId);
|
||||
// maker removes themselves from pool
|
||||
await maker.setMakerStakingPoolAsync(stakingConstants.NIL_POOL_ID);
|
||||
await maker.joinStakingPoolAsMakerAsync(stakingConstants.NIL_POOL_ID);
|
||||
});
|
||||
it('Should successfully add/remove multiple makers to the same pool', async () => {
|
||||
// test parameters
|
||||
@@ -135,9 +135,11 @@ blockchainTests('Staking Pool Management', env => {
|
||||
const poolId = await poolOperator.createStakingPoolAsync(operatorShare, false);
|
||||
expect(poolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
|
||||
// add makers to pool
|
||||
await Promise.all(makers.map(async maker => maker.setMakerStakingPoolAsync(poolId)));
|
||||
await Promise.all(makers.map(async maker => maker.joinStakingPoolAsMakerAsync(poolId)));
|
||||
// remove makers to pool
|
||||
await Promise.all(makers.map(async maker => maker.setMakerStakingPoolAsync(stakingConstants.NIL_POOL_ID)));
|
||||
await Promise.all(
|
||||
makers.map(async maker => maker.joinStakingPoolAsMakerAsync(stakingConstants.NIL_POOL_ID)),
|
||||
);
|
||||
});
|
||||
it('Operator should successfully decrease their share of rewards', async () => {
|
||||
// test parameters
|
||||
|
@@ -44,7 +44,11 @@ blockchainTests.resets('Stake Statuses', env => {
|
||||
await stakingApiWrapper.utils.createStakingPoolAsync(poolOperator, 4, false),
|
||||
await stakingApiWrapper.utils.createStakingPoolAsync(poolOperator, 5, false),
|
||||
]);
|
||||
unusedPoolId = await stakingApiWrapper.stakingContract.nextPoolId.callAsync();
|
||||
const lastPoolId = await stakingApiWrapper.stakingContract.lastPoolId.callAsync();
|
||||
unusedPoolId = `0x${new BigNumber(lastPoolId)
|
||||
.plus(1)
|
||||
.toString(16)
|
||||
.padStart(64, '0')}`;
|
||||
});
|
||||
describe('Stake', () => {
|
||||
it('should successfully stake zero ZRX', async () => {
|
||||
|
Reference in New Issue
Block a user