New logic for makers joining pools
This commit is contained in:
@@ -1,41 +1,47 @@
|
||||
import { SignatureType } from '@0x/types';
|
||||
import { expect } from '@0x/contracts-test-utils';
|
||||
import { RevertError } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { StakingWrapper } from '../utils/staking_wrapper';
|
||||
import { SignedStakingPoolApproval } from '../utils/types';
|
||||
import { constants as stakingConstants } from '../utils/constants';
|
||||
|
||||
import { BaseActor } from './base_actor';
|
||||
|
||||
export class MakerActor extends BaseActor {
|
||||
private readonly _ownerPrivateKeyIfExists?: Buffer;
|
||||
private readonly _signatureVerifierIfExists?: string;
|
||||
private readonly _chainIdIfExists?: number;
|
||||
public async joinStakingPoolAsMakerAsync(poolId: string, revertError?: RevertError): Promise<void> {
|
||||
// Join pool
|
||||
const txReceiptPromise = this._stakingWrapper.joinStakingPoolAsMakerAsync(poolId, this._owner);
|
||||
|
||||
constructor(
|
||||
owner: string,
|
||||
stakingWrapper: StakingWrapper,
|
||||
ownerPrivateKey?: Buffer,
|
||||
signatureVerifier?: string,
|
||||
chainId?: number,
|
||||
) {
|
||||
super(owner, stakingWrapper);
|
||||
this._ownerPrivateKeyIfExists = ownerPrivateKey;
|
||||
this._signatureVerifierIfExists = signatureVerifier;
|
||||
this._chainIdIfExists = chainId;
|
||||
if (revertError !== undefined) {
|
||||
await expect(txReceiptPromise).to.revertWith(revertError);
|
||||
return;
|
||||
}
|
||||
await txReceiptPromise;
|
||||
|
||||
// Pool id of the maker should be nil (join would've thrown otherwise)
|
||||
const poolIdOfMaker = await this._stakingWrapper.getStakingPoolIdOfMakerAsync(this._owner);
|
||||
expect(poolIdOfMaker, 'pool id of maker').to.be.equal(stakingConstants.NIL_POOL_ID);
|
||||
}
|
||||
|
||||
public signApprovalForStakingPool(
|
||||
public async removeMakerFromStakingPoolAsync(
|
||||
poolId: string,
|
||||
signatureType: SignatureType = SignatureType.EthSign,
|
||||
): SignedStakingPoolApproval {
|
||||
const approval = this._stakingWrapper.signApprovalForStakingPool(
|
||||
makerAddress: string,
|
||||
revertError?: RevertError,
|
||||
): Promise<void> {
|
||||
// remove maker (should fail if makerAddress !== this._owner)
|
||||
const txReceiptPromise = this._stakingWrapper.removeMakerFromStakingPoolAsync(
|
||||
poolId,
|
||||
makerAddress,
|
||||
this._owner,
|
||||
this._ownerPrivateKeyIfExists,
|
||||
this._signatureVerifierIfExists,
|
||||
this._chainIdIfExists,
|
||||
signatureType,
|
||||
);
|
||||
return approval;
|
||||
|
||||
if (revertError !== undefined) {
|
||||
await expect(txReceiptPromise).to.revertWith(revertError);
|
||||
return;
|
||||
}
|
||||
await txReceiptPromise;
|
||||
|
||||
// check the pool id of the maker
|
||||
const poolIdOfMakerAfterRemoving = await this._stakingWrapper.getStakingPoolIdOfMakerAsync(this._owner);
|
||||
expect(poolIdOfMakerAfterRemoving, 'pool id of maker').to.be.equal(stakingConstants.NIL_POOL_ID);
|
||||
}
|
||||
}
|
||||
|
@@ -3,20 +3,23 @@ import { RevertError } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { constants as stakingConstants } from '../utils/constants';
|
||||
import { StakingWrapper } from '../utils/staking_wrapper';
|
||||
|
||||
import { BaseActor } from './base_actor';
|
||||
|
||||
export class PoolOperatorActor extends BaseActor {
|
||||
constructor(owner: string, stakingWrapper: StakingWrapper) {
|
||||
super(owner, stakingWrapper);
|
||||
}
|
||||
|
||||
public async createStakingPoolAsync(operatorShare: number, revertError?: RevertError): Promise<string> {
|
||||
public async createStakingPoolAsync(
|
||||
operatorShare: number,
|
||||
addOperatorAsMaker: boolean,
|
||||
revertError?: RevertError,
|
||||
): Promise<string> {
|
||||
// query next pool id
|
||||
const nextPoolId = await this._stakingWrapper.getNextStakingPoolIdAsync();
|
||||
// create pool
|
||||
const poolIdPromise = this._stakingWrapper.createStakingPoolAsync(this._owner, operatorShare);
|
||||
const poolIdPromise = this._stakingWrapper.createStakingPoolAsync(
|
||||
this._owner,
|
||||
operatorShare,
|
||||
addOperatorAsMaker,
|
||||
);
|
||||
if (revertError !== undefined) {
|
||||
await expect(poolIdPromise).to.revertWith(revertError);
|
||||
return '';
|
||||
@@ -24,21 +27,24 @@ export class PoolOperatorActor extends BaseActor {
|
||||
const poolId = await poolIdPromise;
|
||||
// validate pool id
|
||||
expect(poolId, 'pool id').to.be.bignumber.equal(nextPoolId);
|
||||
|
||||
if (addOperatorAsMaker) {
|
||||
// check the pool id of the operator
|
||||
const poolIdOfMaker = await this._stakingWrapper.getStakingPoolIdOfMakerAsync(this._owner);
|
||||
expect(poolIdOfMaker, 'pool id of maker').to.be.equal(poolId);
|
||||
// check the number of makers in the pool
|
||||
const numMakersAfterRemoving = await this._stakingWrapper.getNumberOfMakersInStakingPoolAsync(poolId);
|
||||
expect(numMakersAfterRemoving, 'number of makers in pool').to.be.bignumber.equal(1);
|
||||
}
|
||||
return poolId;
|
||||
}
|
||||
public async addMakerToStakingPoolAsync(
|
||||
poolId: string,
|
||||
makerAddress: string,
|
||||
makerSignature: string,
|
||||
revertError?: RevertError,
|
||||
): Promise<void> {
|
||||
// add maker
|
||||
const txReceiptPromise = this._stakingWrapper.addMakerToStakingPoolAsync(
|
||||
poolId,
|
||||
makerAddress,
|
||||
makerSignature,
|
||||
this._owner,
|
||||
);
|
||||
const txReceiptPromise = this._stakingWrapper.addMakerToStakingPoolAsync(poolId, makerAddress, this._owner);
|
||||
if (revertError !== undefined) {
|
||||
await expect(txReceiptPromise).to.revertWith(revertError);
|
||||
return;
|
||||
@@ -47,9 +53,6 @@ export class PoolOperatorActor extends BaseActor {
|
||||
// check the pool id of the maker
|
||||
const poolIdOfMaker = await this._stakingWrapper.getStakingPoolIdOfMakerAsync(makerAddress);
|
||||
expect(poolIdOfMaker, 'pool id of maker').to.be.equal(poolId);
|
||||
// check the list of makers for the pool
|
||||
const makerAddressesForPool = await this._stakingWrapper.getMakersForStakingPoolAsync(poolId);
|
||||
expect(makerAddressesForPool, 'maker addresses for pool').to.include(makerAddress);
|
||||
}
|
||||
public async removeMakerFromStakingPoolAsync(
|
||||
poolId: string,
|
||||
@@ -70,8 +73,5 @@ export class PoolOperatorActor extends BaseActor {
|
||||
// check the pool id of the maker
|
||||
const poolIdOfMakerAfterRemoving = await this._stakingWrapper.getStakingPoolIdOfMakerAsync(makerAddress);
|
||||
expect(poolIdOfMakerAfterRemoving, 'pool id of maker').to.be.equal(stakingConstants.NIL_POOL_ID);
|
||||
// check the list of makers for the pool
|
||||
const makerAddressesForPoolAfterRemoving = await this._stakingWrapper.getMakersForStakingPoolAsync(poolId);
|
||||
expect(makerAddressesForPoolAfterRemoving, 'maker addresses for pool').to.not.include(makerAddress);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user