fixing linter errors
This commit is contained in:
parent
9294bf40a7
commit
5147b6e699
@ -75,6 +75,8 @@
|
||||
"@0x/base-contract": "^5.1.0",
|
||||
"@0x/contracts-test-utils": "^3.1.6",
|
||||
"@0x/contracts-utils": "3.1.1",
|
||||
"@0x/contracts-asset-proxy": "^2.1.1",
|
||||
"@0x/contracts-erc20": "^2.2.0",
|
||||
"@0x/order-utils": "^7.2.0",
|
||||
"@0x/types": "^2.2.2",
|
||||
"@0x/typescript-typings": "^4.2.2",
|
||||
|
@ -23,7 +23,7 @@ export class DelegatorActor extends StakerActor {
|
||||
revertReason?: RevertReason,
|
||||
): Promise<void> {
|
||||
// query init balances
|
||||
const initZrxBalanceOfVault = await this._stakingWrapper.getZrxTokenBalanceOfZrxVault();
|
||||
const initZrxBalanceOfVault = await this._stakingWrapper.getZrxTokenBalanceOfZrxVaultAsync();
|
||||
const initDelegatorBalances = await this.getBalancesAsync([poolId]);
|
||||
// deposit stake
|
||||
const txReceiptPromise = this._stakingWrapper.depositAndDelegateAsync(this._owner, poolId, amount);
|
||||
@ -31,7 +31,7 @@ export class DelegatorActor extends StakerActor {
|
||||
await expectTransactionFailedAsync(txReceiptPromise, revertReason);
|
||||
return;
|
||||
}
|
||||
const txReceipt = await txReceiptPromise;
|
||||
await txReceiptPromise;
|
||||
// @TODO check receipt logs and return value via eth_call
|
||||
// check balances
|
||||
const expectedDelegatorBalances = initDelegatorBalances;
|
||||
@ -46,7 +46,7 @@ export class DelegatorActor extends StakerActor {
|
||||
expectedDelegatorBalances.stakeDelegatedToPool[0] = initDelegatorBalances.stakeDelegatedToPool[0].plus(amount);
|
||||
await this.assertBalancesAsync(expectedDelegatorBalances, [poolId]);
|
||||
// check zrx balance of vault
|
||||
const finalZrxBalanceOfVault = await this._stakingWrapper.getZrxTokenBalanceOfZrxVault();
|
||||
const finalZrxBalanceOfVault = await this._stakingWrapper.getZrxTokenBalanceOfZrxVaultAsync();
|
||||
expect(finalZrxBalanceOfVault).to.be.bignumber.equal(initZrxBalanceOfVault.plus(amount));
|
||||
}
|
||||
public async activateAndDelegateStakeAsync(
|
||||
@ -62,7 +62,7 @@ export class DelegatorActor extends StakerActor {
|
||||
await expectTransactionFailedAsync(txReceiptPromise, revertReason);
|
||||
return;
|
||||
}
|
||||
const txReceipt = await txReceiptPromise;
|
||||
await txReceiptPromise;
|
||||
// @TODO check receipt logs and return value via eth_call
|
||||
// check balances
|
||||
// check balances
|
||||
@ -101,7 +101,7 @@ export class DelegatorActor extends StakerActor {
|
||||
await expectTransactionFailedAsync(txReceiptPromise, revertReason);
|
||||
return;
|
||||
}
|
||||
const txReceipt = await txReceiptPromise;
|
||||
await txReceiptPromise;
|
||||
// @TODO check receipt logs and return value via eth_call
|
||||
// check balances
|
||||
const expectedDelegatorBalances = initDelegatorBalances;
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { SignatureType } from '@0x/types';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
import { StakingWrapper } from '../utils/staking_wrapper';
|
||||
@ -7,8 +6,6 @@ import { SignedStakingPoolApproval } from '../utils/types';
|
||||
|
||||
import { BaseActor } from './base_actor';
|
||||
|
||||
const expect = chai.expect;
|
||||
|
||||
export class MakerActor extends BaseActor {
|
||||
private readonly _ownerPrivateKeyIfExists?: Buffer;
|
||||
private readonly _signatureVerifierIfExists?: string;
|
||||
|
@ -48,12 +48,12 @@ export class PoolOperatorActor extends BaseActor {
|
||||
await expectTransactionFailedAsync(txReceiptPromise, revertReason);
|
||||
return;
|
||||
}
|
||||
const txReceipt = await txReceiptPromise;
|
||||
await txReceiptPromise;
|
||||
// check the pool id of the maker
|
||||
const poolIdOfMaker = await this._stakingWrapper.getMakerPoolId(makerAddress);
|
||||
const poolIdOfMaker = await this._stakingWrapper.getMakerPoolIdAsync(makerAddress);
|
||||
expect(poolIdOfMaker, 'pool id of maker').to.be.equal(poolId);
|
||||
// check the list of makers for the pool
|
||||
const makerAddressesForPool = await this._stakingWrapper.getMakerAddressesForPool(poolId);
|
||||
const makerAddressesForPool = await this._stakingWrapper.getMakerAddressesForPoolAsync(poolId);
|
||||
expect(makerAddressesForPool, 'maker addresses for pool').to.include(makerAddress);
|
||||
}
|
||||
public async removeMakerFromPoolAsync(
|
||||
@ -67,12 +67,12 @@ export class PoolOperatorActor extends BaseActor {
|
||||
await expectTransactionFailedAsync(txReceiptPromise, revertReason);
|
||||
return;
|
||||
}
|
||||
const txReceipt = await txReceiptPromise;
|
||||
await txReceiptPromise;
|
||||
// check the pool id of the maker
|
||||
const poolIdOfMakerAfterRemoving = await this._stakingWrapper.getMakerPoolId(makerAddress);
|
||||
const poolIdOfMakerAfterRemoving = await this._stakingWrapper.getMakerPoolIdAsync(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.getMakerAddressesForPool(poolId);
|
||||
const makerAddressesForPoolAfterRemoving = await this._stakingWrapper.getMakerAddressesForPoolAsync(poolId);
|
||||
expect(makerAddressesForPoolAfterRemoving, 'maker addresses for pool').to.not.include(makerAddress);
|
||||
}
|
||||
}
|
||||
|
@ -18,12 +18,12 @@ export class StakerActor extends BaseActor {
|
||||
super(owner, stakingWrapper);
|
||||
}
|
||||
public async depositAsync(amount: BigNumber, revertReason?: RevertReason): Promise<void> {
|
||||
throw new Error('Unimplemented');
|
||||
// @TODO - Implement by calling this._stakingWrapper.depositAsync(this._owner, amount);
|
||||
await this._stakingWrapper.depositAsync(this._owner, amount);
|
||||
throw new Error('Checks Unimplemented');
|
||||
}
|
||||
public async depositAndStakeAsync(amount: BigNumber, revertReason?: RevertReason): Promise<void> {
|
||||
// query init balances
|
||||
const initZrxBalanceOfVault = await this._stakingWrapper.getZrxTokenBalanceOfZrxVault();
|
||||
const initZrxBalanceOfVault = await this._stakingWrapper.getZrxTokenBalanceOfZrxVaultAsync();
|
||||
const initStakerBalances = await this.getBalancesAsync();
|
||||
// deposit stake
|
||||
const txReceiptPromise = this._stakingWrapper.depositAndStakeAsync(this._owner, amount);
|
||||
@ -31,7 +31,7 @@ export class StakerActor extends BaseActor {
|
||||
await expectTransactionFailedAsync(txReceiptPromise, revertReason);
|
||||
return;
|
||||
}
|
||||
const txReceipt = await txReceiptPromise;
|
||||
await txReceiptPromise;
|
||||
// @TODO check receipt logs and return value via eth_call
|
||||
// check balances
|
||||
const expectedStakerBalances = initStakerBalances;
|
||||
@ -41,7 +41,7 @@ export class StakerActor extends BaseActor {
|
||||
expectedStakerBalances.activatedStakeBalance = initStakerBalances.activatedStakeBalance.plus(amount);
|
||||
await this.assertBalancesAsync(expectedStakerBalances);
|
||||
// check zrx balance of vault
|
||||
const finalZrxBalanceOfVault = await this._stakingWrapper.getZrxTokenBalanceOfZrxVault();
|
||||
const finalZrxBalanceOfVault = await this._stakingWrapper.getZrxTokenBalanceOfZrxVaultAsync();
|
||||
expect(finalZrxBalanceOfVault).to.be.bignumber.equal(initZrxBalanceOfVault.plus(amount));
|
||||
}
|
||||
public async activateStakeAsync(amount: BigNumber, revertReason?: RevertReason): Promise<void> {
|
||||
@ -53,7 +53,7 @@ export class StakerActor extends BaseActor {
|
||||
await expectTransactionFailedAsync(txReceiptPromise, revertReason);
|
||||
return;
|
||||
}
|
||||
const txReceipt = await txReceiptPromise;
|
||||
await txReceiptPromise;
|
||||
// @TODO check receipt logs and return value via eth_call
|
||||
// check balances
|
||||
const expectedStakerBalances = initStakerBalances;
|
||||
@ -72,7 +72,7 @@ export class StakerActor extends BaseActor {
|
||||
await expectTransactionFailedAsync(txReceiptPromise, revertReason);
|
||||
return;
|
||||
}
|
||||
const txReceipt = await txReceiptPromise;
|
||||
await txReceiptPromise;
|
||||
// @TODO check receipt logs and return value via eth_call
|
||||
// check balances
|
||||
const expectedStakerBalances = initStakerBalances;
|
||||
@ -83,7 +83,7 @@ export class StakerActor extends BaseActor {
|
||||
}
|
||||
public async withdrawAsync(amount: BigNumber, revertReason?: RevertReason): Promise<void> {
|
||||
// query init balances
|
||||
const initZrxBalanceOfVault = await this._stakingWrapper.getZrxTokenBalanceOfZrxVault();
|
||||
const initZrxBalanceOfVault = await this._stakingWrapper.getZrxTokenBalanceOfZrxVaultAsync();
|
||||
const initStakerBalances = await this.getBalancesAsync();
|
||||
// withdraw stake
|
||||
const txReceiptPromise = this._stakingWrapper.withdrawAsync(this._owner, amount);
|
||||
@ -91,7 +91,7 @@ export class StakerActor extends BaseActor {
|
||||
await expectTransactionFailedAsync(txReceiptPromise, revertReason);
|
||||
return;
|
||||
}
|
||||
const txReceipt = await txReceiptPromise;
|
||||
await txReceiptPromise;
|
||||
// @TODO check receipt logs and return value via eth_call
|
||||
// check balances
|
||||
const expectedStakerBalances = initStakerBalances;
|
||||
@ -103,14 +103,14 @@ export class StakerActor extends BaseActor {
|
||||
expectedStakerBalances.deactivatedStakeBalance = initStakerBalances.deactivatedStakeBalance.minus(amount);
|
||||
await this.assertBalancesAsync(expectedStakerBalances);
|
||||
// check zrx balance of vault
|
||||
const finalZrxBalanceOfVault = await this._stakingWrapper.getZrxTokenBalanceOfZrxVault();
|
||||
const finalZrxBalanceOfVault = await this._stakingWrapper.getZrxTokenBalanceOfZrxVaultAsync();
|
||||
expect(finalZrxBalanceOfVault).to.be.bignumber.equal(initZrxBalanceOfVault.minus(amount));
|
||||
}
|
||||
public async getBalancesAsync(): Promise<StakerBalances> {
|
||||
const stakerBalances = {
|
||||
zrxBalance: await this._stakingWrapper.getZrxTokenBalance(this._owner),
|
||||
zrxBalance: await this._stakingWrapper.getZrxTokenBalanceAsync(this._owner),
|
||||
stakeBalance: await this._stakingWrapper.getTotalStakeAsync(this._owner),
|
||||
stakeBalanceInVault: await this._stakingWrapper.getZrxVaultBalance(this._owner),
|
||||
stakeBalanceInVault: await this._stakingWrapper.getZrxVaultBalanceAsync(this._owner),
|
||||
withdrawableStakeBalance: await this._stakingWrapper.getWithdrawableStakeAsync(this._owner),
|
||||
activatableStakeBalance: await this._stakingWrapper.getActivatableStakeAsync(this._owner),
|
||||
activatedStakeBalance: await this._stakingWrapper.getActivatedStakeAsync(this._owner),
|
||||
|
@ -23,10 +23,6 @@ describe('Epochs', () => {
|
||||
// tokens & addresses
|
||||
let accounts: string[];
|
||||
let owner: string;
|
||||
let exchange: string;
|
||||
let stakers: string[];
|
||||
let makers: string[];
|
||||
let delegators: string[];
|
||||
let zrxTokenContract: DummyERC20TokenContract;
|
||||
let erc20ProxyContract: ERC20ProxyContract;
|
||||
// wrappers
|
||||
@ -43,9 +39,6 @@ describe('Epochs', () => {
|
||||
// create accounts
|
||||
accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
owner = accounts[0];
|
||||
exchange = accounts[1];
|
||||
stakers = accounts.slice(2, 5);
|
||||
makers = accounts.slice(4, 10);
|
||||
// deploy erc20 proxy
|
||||
erc20Wrapper = new ERC20Wrapper(provider, accounts, owner);
|
||||
erc20ProxyContract = await erc20Wrapper.deployProxyAsync();
|
||||
@ -54,7 +47,7 @@ describe('Epochs', () => {
|
||||
await erc20Wrapper.setBalancesAndAllowancesAsync();
|
||||
// deploy staking contracts
|
||||
stakingWrapper = new StakingWrapper(provider, owner, erc20ProxyContract, zrxTokenContract, accounts);
|
||||
await stakingWrapper.deployAndConfigureContracts();
|
||||
await stakingWrapper.deployAndConfigureContractsAsync();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
|
@ -12,7 +12,6 @@ import { BigNumber } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
|
||||
import { StakingWrapper } from './utils/staking_wrapper';
|
||||
|
||||
chaiSetup.configure();
|
||||
@ -26,9 +25,6 @@ describe('Exchange Integrations', () => {
|
||||
let accounts: string[];
|
||||
let owner: string;
|
||||
let exchange: string;
|
||||
let stakers: string[];
|
||||
let makers: string[];
|
||||
let delegators: string[];
|
||||
let zrxTokenContract: DummyERC20TokenContract;
|
||||
let erc20ProxyContract: ERC20ProxyContract;
|
||||
// wrappers
|
||||
@ -46,8 +42,6 @@ describe('Exchange Integrations', () => {
|
||||
accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
owner = accounts[0];
|
||||
exchange = accounts[1];
|
||||
stakers = accounts.slice(2, 5);
|
||||
makers = accounts.slice(4, 10);
|
||||
// deploy erc20 proxy
|
||||
erc20Wrapper = new ERC20Wrapper(provider, accounts, owner);
|
||||
erc20ProxyContract = await erc20Wrapper.deployProxyAsync();
|
||||
@ -56,7 +50,7 @@ describe('Exchange Integrations', () => {
|
||||
await erc20Wrapper.setBalancesAndAllowancesAsync();
|
||||
// deploy staking contracts
|
||||
stakingWrapper = new StakingWrapper(provider, owner, erc20ProxyContract, zrxTokenContract, accounts);
|
||||
await stakingWrapper.deployAndConfigureContracts();
|
||||
await stakingWrapper.deployAndConfigureContractsAsync();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
|
@ -46,7 +46,7 @@ describe('Math Libraries', () => {
|
||||
await erc20Wrapper.setBalancesAndAllowancesAsync();
|
||||
// deploy staking contracts
|
||||
stakingWrapper = new StakingWrapper(provider, owner, erc20ProxyContract, zrxTokenContract, accounts);
|
||||
await stakingWrapper.deployAndConfigureContracts();
|
||||
await stakingWrapper.deployAndConfigureContractsAsync();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
@ -58,14 +58,14 @@ describe('Math Libraries', () => {
|
||||
it('nth root', async () => {
|
||||
const base = new BigNumber(1419857);
|
||||
const n = new BigNumber(5);
|
||||
const root = await stakingWrapper.nthRoot(base, n);
|
||||
const root = await stakingWrapper.nthRootAsync(base, n);
|
||||
expect(root).to.be.bignumber.equal(17);
|
||||
});
|
||||
|
||||
it('nth root #2', async () => {
|
||||
const base = new BigNumber(3375);
|
||||
const n = new BigNumber(3);
|
||||
const root = await stakingWrapper.nthRoot(base, n);
|
||||
const root = await stakingWrapper.nthRootAsync(base, n);
|
||||
expect(root).to.be.bignumber.equal(15);
|
||||
});
|
||||
|
||||
@ -73,7 +73,7 @@ describe('Math Libraries', () => {
|
||||
const decimals = 18;
|
||||
const base = stakingWrapper.toFixedPoint(4.234, decimals);
|
||||
const n = new BigNumber(2);
|
||||
const root = await stakingWrapper.nthRootFixedPoint(base, n);
|
||||
const root = await stakingWrapper.nthRootFixedPointAsync(base, n);
|
||||
const rootAsFloatingPoint = stakingWrapper.toFloatingPoint(root, decimals);
|
||||
const expectedResult = new BigNumber(2.057668584);
|
||||
expect(rootAsFloatingPoint).to.be.bignumber.equal(expectedResult);
|
||||
@ -82,21 +82,19 @@ describe('Math Libraries', () => {
|
||||
it('nth root #3 with fixed point (integer nth root would fail here)', async () => {
|
||||
const decimals = 18;
|
||||
const base = stakingWrapper.toFixedPoint(5429503678976, decimals);
|
||||
console.log(base);
|
||||
const n = new BigNumber(9);
|
||||
const root = await stakingWrapper.nthRootFixedPoint(base, n);
|
||||
const root = await stakingWrapper.nthRootFixedPointAsync(base, n);
|
||||
const rootAsFloatingPoint = stakingWrapper.toFloatingPoint(root, decimals);
|
||||
const expectedResult = new BigNumber(26);
|
||||
expect(rootAsFloatingPoint).to.be.bignumber.equal(expectedResult);
|
||||
});
|
||||
|
||||
it.skip('nth root #4 with fixed point (integer nth root would fail here) (max number of decimals - currently does not retain)', async () => {
|
||||
// @TODO This is the gold standard for nth root. Retain all these decimals :)
|
||||
const decimals = 18;
|
||||
const base = stakingWrapper.toFixedPoint(new BigNumber('5429503678976.295036789761543678', 10), decimals);
|
||||
console.log(base);
|
||||
const n = new BigNumber(9);
|
||||
const root = await stakingWrapper.nthRootFixedPoint(base, n);
|
||||
console.log(`root - ${root}`);
|
||||
const root = await stakingWrapper.nthRootFixedPointAsync(base, n);
|
||||
const rootAsFloatingPoint = stakingWrapper.toFloatingPoint(root, decimals);
|
||||
const expectedResult = new BigNumber(26);
|
||||
expect(rootAsFloatingPoint).to.be.bignumber.equal(expectedResult);
|
||||
|
@ -13,7 +13,6 @@ import * as chai from 'chai';
|
||||
import * as ethUtil from 'ethereumjs-util';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
|
||||
import { MakerActor } from './actors/maker_actor';
|
||||
import { PoolOperatorActor } from './actors/pool_operator_actor';
|
||||
import { constants as stakingConstants } from './utils/constants';
|
||||
@ -29,7 +28,6 @@ describe('Staking Pool Management', () => {
|
||||
// tokens & addresses
|
||||
let accounts: string[];
|
||||
let owner: string;
|
||||
let exchange: string;
|
||||
let users: string[];
|
||||
let zrxTokenContract: DummyERC20TokenContract;
|
||||
let erc20ProxyContract: ERC20ProxyContract;
|
||||
@ -47,8 +45,7 @@ describe('Staking Pool Management', () => {
|
||||
// create accounts
|
||||
accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
owner = accounts[0];
|
||||
exchange = accounts[1];
|
||||
users = accounts.slice(2);
|
||||
users = accounts.slice(1);
|
||||
// deploy erc20 proxy
|
||||
erc20Wrapper = new ERC20Wrapper(provider, accounts, owner);
|
||||
erc20ProxyContract = await erc20Wrapper.deployProxyAsync();
|
||||
@ -57,7 +54,7 @@ describe('Staking Pool Management', () => {
|
||||
await erc20Wrapper.setBalancesAndAllowancesAsync();
|
||||
// deploy staking contracts
|
||||
stakingWrapper = new StakingWrapper(provider, owner, erc20ProxyContract, zrxTokenContract, accounts);
|
||||
await stakingWrapper.deployAndConfigureContracts();
|
||||
await stakingWrapper.deployAndConfigureContractsAsync();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
@ -151,7 +148,6 @@ describe('Staking Pool Management', () => {
|
||||
const operatorShare = 39;
|
||||
const poolOperator = new PoolOperatorActor(operatorAddress, stakingWrapper);
|
||||
const makerAddress = users[1];
|
||||
const maker = new MakerActor(makerAddress, stakingWrapper);
|
||||
// create pool
|
||||
const poolId = await poolOperator.createPoolAsync(operatorShare);
|
||||
expect(poolId).to.be.equal(stakingConstants.INITIAL_POOL_ID);
|
||||
|
@ -1,37 +1,31 @@
|
||||
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
|
||||
import {
|
||||
expectTransactionFailedAsync,
|
||||
provider,
|
||||
web3Wrapper,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { RevertReason } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
|
||||
import { Simulation } from './utils/Simulation';
|
||||
import { StakingWrapper } from './utils/staking_wrapper';
|
||||
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
|
||||
import {
|
||||
chaiSetup,
|
||||
constants,
|
||||
expectTransactionFailedAsync,
|
||||
provider,
|
||||
txDefaults,
|
||||
web3Wrapper,
|
||||
} from '@0x/contracts-test-utils';
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { RevertReason } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import { LogWithDecodedArgs } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
rc20ProxyContract: ERC20ProxyContract;
|
||||
|
||||
let stakers: string[];
|
||||
let makers: string[];
|
||||
let delegators: string[];
|
||||
|
||||
import { Simulation } from './utils/Simulation';
|
||||
import { StakingWrapper } from './utils/staking_wrapper';
|
||||
chaiSetup.configure();
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
// tslint:disable:no-unnecessary-type-assertion
|
||||
describe('End-To-End Simulations', () => {
|
||||
// constants
|
||||
const ZRX_TOKEN_DECIMALS = new BigNumber(18);
|
||||
// tokens & addresses
|
||||
let accounts: string[];
|
||||
let owner: string;
|
||||
let exchange: string;
|
||||
let users: string[];
|
||||
let zrxTokenContract: DummyERC20TokenContract;
|
||||
let erc20ProxyContract: ERC20ProxyContract;
|
||||
// wrappers
|
||||
let stakingWrapper: StakingWrapper;
|
||||
let erc20Wrapper: ERC20Wrapper;
|
||||
@ -48,10 +42,7 @@ rc20ProxyContract: ERC20ProxyContract;
|
||||
owner = accounts[0];
|
||||
exchange = accounts[1];
|
||||
users = accounts.slice(2);
|
||||
|
||||
stakers = accounts.slice(2, 5);
|
||||
makers = accounts.slice(4, 10);
|
||||
users = [...users, ...users]; // maybe this'll work? Not sure lol.
|
||||
users = [...users, ...users]; // @TODO figure out how to get more addresses from `web3Wrapper`
|
||||
|
||||
// deploy erc20 proxy
|
||||
erc20Wrapper = new ERC20Wrapper(provider, accounts, owner);
|
||||
@ -61,7 +52,7 @@ rc20ProxyContract: ERC20ProxyContract;
|
||||
await erc20Wrapper.setBalancesAndAllowancesAsync();
|
||||
// deploy staking contracts
|
||||
stakingWrapper = new StakingWrapper(provider, owner, erc20ProxyContract, zrxTokenContract, accounts);
|
||||
await stakingWrapper.deployAndConfigureContracts();
|
||||
await stakingWrapper.deployAndConfigureContractsAsync();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
|
@ -8,16 +8,13 @@ import {
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { RevertReason } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
|
||||
import { DelegatorActor } from './actors/delegator_actor';
|
||||
import { StakerActor } from './actors/staker_actor';
|
||||
import { StakingWrapper } from './utils/staking_wrapper';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
// tslint:disable:no-unnecessary-type-assertion
|
||||
describe('Staking & Delegating', () => {
|
||||
@ -26,10 +23,7 @@ describe('Staking & Delegating', () => {
|
||||
// tokens & addresses
|
||||
let accounts: string[];
|
||||
let owner: string;
|
||||
let exchange: string;
|
||||
let stakers: string[];
|
||||
let makers: string[];
|
||||
let delegators: string[];
|
||||
let zrxTokenContract: DummyERC20TokenContract;
|
||||
let erc20ProxyContract: ERC20ProxyContract;
|
||||
// wrappers
|
||||
@ -46,9 +40,7 @@ describe('Staking & Delegating', () => {
|
||||
// create accounts
|
||||
accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
owner = accounts[0];
|
||||
exchange = accounts[1];
|
||||
stakers = accounts.slice(2, 5);
|
||||
makers = accounts.slice(4, 10);
|
||||
// deploy erc20 proxy
|
||||
erc20Wrapper = new ERC20Wrapper(provider, accounts, owner);
|
||||
erc20ProxyContract = await erc20Wrapper.deployProxyAsync();
|
||||
@ -57,7 +49,7 @@ describe('Staking & Delegating', () => {
|
||||
await erc20Wrapper.setBalancesAndAllowancesAsync();
|
||||
// deploy staking contracts
|
||||
stakingWrapper = new StakingWrapper(provider, owner, erc20ProxyContract, zrxTokenContract, accounts);
|
||||
await stakingWrapper.deployAndConfigureContracts();
|
||||
await stakingWrapper.deployAndConfigureContractsAsync();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
|
@ -49,22 +49,23 @@ export class Simulation {
|
||||
await this._stakingWrapper.skipToNextEpochAsync();
|
||||
// everyone has been paid out into the vault. check balances.
|
||||
await this._assertVaultBalancesAsync(this._p);
|
||||
await this._withdrawRewardForOperators(this._p);
|
||||
await this._withdrawRewardForOperatorsAsync(this._p);
|
||||
if (this._p.withdrawByUndelegating) {
|
||||
await this._withdrawRewardForDelegators(this._p);
|
||||
await this._withdrawRewardForDelegatorsAsync(this._p);
|
||||
} else {
|
||||
await this._withdrawRewardForDelegatorsByUndelegating(this._p);
|
||||
await this._withdrawRewardForDelegatorsByUndelegatingAsync(this._p);
|
||||
}
|
||||
|
||||
// @TODO cleanup state and verify the staking contract is empty
|
||||
}
|
||||
|
||||
private async _withdrawRewardForDelegatorsByUndelegating(p: SimulationParams): Promise<void> {
|
||||
private async _withdrawRewardForDelegatorsByUndelegatingAsync(p: SimulationParams): Promise<void> {
|
||||
let delegatorIdx = 0;
|
||||
let poolIdx = 0;
|
||||
for (const numberOfDelegatorsInPool of p.numberOfDelegatorsPerPool) {
|
||||
const poolId = this._poolIds[poolIdx];
|
||||
for (const j in _.range(numberOfDelegatorsInPool)) {
|
||||
// tslint:disable-next-line no-unused-variable
|
||||
for (const j of _.range(numberOfDelegatorsInPool)) {
|
||||
const delegator = this._delegators[delegatorIdx];
|
||||
const delegatorAddress = delegator.getOwner();
|
||||
const amountOfStakeDelegated = p.stakeByDelegator[delegatorIdx];
|
||||
@ -87,12 +88,13 @@ export class Simulation {
|
||||
}
|
||||
}
|
||||
|
||||
private async _withdrawRewardForDelegators(p: SimulationParams): Promise<void> {
|
||||
private async _withdrawRewardForDelegatorsAsync(p: SimulationParams): Promise<void> {
|
||||
let delegatorIdx = 0;
|
||||
let poolIdx = 0;
|
||||
for (const numberOfDelegatorsInPool of p.numberOfDelegatorsPerPool) {
|
||||
const poolId = this._poolIds[poolIdx];
|
||||
for (const j in _.range(numberOfDelegatorsInPool)) {
|
||||
// tslint:disable-next-line no-unused-variable
|
||||
for (const j of _.range(numberOfDelegatorsInPool)) {
|
||||
const delegator = this._delegators[delegatorIdx];
|
||||
const delegatorAddress = delegator.getOwner();
|
||||
const initEthBalance = await this._stakingWrapper.getEthBalanceAsync(delegatorAddress);
|
||||
@ -115,7 +117,8 @@ export class Simulation {
|
||||
}
|
||||
|
||||
private async _setupPoolsAsync(p: SimulationParams): Promise<void> {
|
||||
for (const i in _.range(p.numberOfPools)) {
|
||||
// tslint:disable-next-line no-unused-variable
|
||||
for (const i of _.range(p.numberOfPools)) {
|
||||
// create operator
|
||||
const poolOperatorAddress = this._userQueue.popFront();
|
||||
const poolOperator = new PoolOperatorActor(poolOperatorAddress, this._stakingWrapper);
|
||||
@ -134,7 +137,8 @@ export class Simulation {
|
||||
|
||||
private async _setupMakersAsync(p: SimulationParams): Promise<void> {
|
||||
// create makers
|
||||
for (const i in _.range(p.numberOfMakers)) {
|
||||
// tslint:disable-next-line no-unused-variable
|
||||
for (const i of _.range(p.numberOfMakers)) {
|
||||
const makerAddress = this._userQueue.popFront();
|
||||
const maker = new MakerActor(makerAddress, this._stakingWrapper);
|
||||
this._makers.push(maker);
|
||||
@ -145,7 +149,8 @@ export class Simulation {
|
||||
for (const numberOfMakersInPool of p.numberOfMakersPerPool) {
|
||||
const poolId = this._poolIds[poolIdx];
|
||||
const poolOperator = this._poolOperators[poolIdx];
|
||||
for (const j in _.range(numberOfMakersInPool)) {
|
||||
// tslint:disable-next-line no-unused-variable
|
||||
for (const j of _.range(numberOfMakersInPool)) {
|
||||
const maker = this._makers[makerIdx];
|
||||
const makerApproval = maker.signApprovalForStakingPool(poolId);
|
||||
const makerAddress = maker.getOwner();
|
||||
@ -158,7 +163,8 @@ export class Simulation {
|
||||
|
||||
private async _setupDelegatorsAsync(p: SimulationParams): Promise<void> {
|
||||
// create delegators
|
||||
for (const i in _.range(p.numberOfDelegators)) {
|
||||
// tslint:disable-next-line no-unused-variable
|
||||
for (const i of _.range(p.numberOfDelegators)) {
|
||||
const delegatorAddress = this._userQueue.popFront();
|
||||
const delegator = new DelegatorActor(delegatorAddress, this._stakingWrapper);
|
||||
this._delegators.push(delegator);
|
||||
@ -169,7 +175,8 @@ export class Simulation {
|
||||
let poolIdx = 0;
|
||||
for (const numberOfDelegatorsInPool of p.numberOfDelegatorsPerPool) {
|
||||
const poolId = this._poolIds[poolIdx];
|
||||
for (const j in _.range(numberOfDelegatorsInPool)) {
|
||||
// tslint:disable-next-line no-unused-variable
|
||||
for (const j of _.range(numberOfDelegatorsInPool)) {
|
||||
const delegator = this._delegators[delegatorIdx];
|
||||
const amount = p.stakeByDelegator[delegatorIdx];
|
||||
await delegator.depositAndDelegateAsync(poolId, amount);
|
||||
@ -181,7 +188,8 @@ export class Simulation {
|
||||
|
||||
private async _payProtocolFeesAsync(p: SimulationParams): Promise<void> {
|
||||
// pay fees
|
||||
for (const i in _.range(this._makers.length)) {
|
||||
// tslint:disable-next-line no-unused-variable
|
||||
for (const i of _.range(this._makers.length)) {
|
||||
const maker = this._makers[i];
|
||||
const makerAddress = maker.getOwner();
|
||||
const feeAmount = p.protocolFeesByMaker[i];
|
||||
@ -189,7 +197,8 @@ export class Simulation {
|
||||
}
|
||||
// validate fees per pool
|
||||
let expectedTotalFeesThisEpoch = new BigNumber(0);
|
||||
for (const i in _.range(this._poolIds.length)) {
|
||||
// tslint:disable-next-line no-unused-variable
|
||||
for (const i of _.range(this._poolIds.length)) {
|
||||
const poolId = this._poolIds[i];
|
||||
const expectedFees = p.expectedFeesByPool[i];
|
||||
const fees = await this._stakingWrapper.getProtocolFeesThisEpochByPoolAsync(poolId);
|
||||
@ -202,7 +211,8 @@ export class Simulation {
|
||||
}
|
||||
|
||||
private async _assertVaultBalancesAsync(p: SimulationParams): Promise<void> {
|
||||
for (const i in _.range(p.numberOfPools)) {
|
||||
// tslint:disable-next-line no-unused-variable
|
||||
for (const i of _.range(p.numberOfPools)) {
|
||||
// @TODO - we trim balances in here because payouts are accurate only to 5 decimal places.
|
||||
// update once more accurate.
|
||||
// check pool balance in vault
|
||||
@ -243,8 +253,9 @@ export class Simulation {
|
||||
}
|
||||
}
|
||||
|
||||
private async _withdrawRewardForOperators(p: SimulationParams): Promise<void> {
|
||||
for (const i in _.range(p.numberOfPools)) {
|
||||
private async _withdrawRewardForOperatorsAsync(p: SimulationParams): Promise<void> {
|
||||
// tslint:disable-next-line no-unused-variable
|
||||
for (const i of _.range(p.numberOfPools)) {
|
||||
// @TODO - we trim balances in here because payouts are accurate only to 5 decimal places.
|
||||
// update once more accurate.
|
||||
// check pool balance in vault
|
||||
|
@ -3,9 +3,8 @@ import { artifacts as erc20Artifacts, DummyERC20TokenContract } from '@0x/contra
|
||||
import { constants as testUtilsConstants, LogDecoder, txDefaults } from '@0x/contracts-test-utils';
|
||||
import { assetDataUtils } from '@0x/order-utils';
|
||||
import { SignatureType } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import { BigNumber, logUtils } from '@0x/utils';
|
||||
import { Web3Wrapper } from '@0x/web3-wrapper';
|
||||
import * as chai from 'chai';
|
||||
import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
@ -22,8 +21,6 @@ import { ApprovalFactory } from './ApprovalFactory';
|
||||
import { constants } from './constants';
|
||||
import { SignedStakingPoolApproval } from './types';
|
||||
|
||||
const expect = chai.expect;
|
||||
|
||||
export class StakingWrapper {
|
||||
private readonly _web3Wrapper: Web3Wrapper;
|
||||
private readonly _provider: Provider;
|
||||
@ -37,6 +34,33 @@ export class StakingWrapper {
|
||||
private _zrxVaultContractIfExists?: ZrxVaultContract;
|
||||
private _rewardVaultContractIfExists?: RewardVaultContract;
|
||||
private _LibFeeMathTestContractIfExists?: LibFeeMathTestContract;
|
||||
public static toBaseUnitAmount(amount: BigNumber | number): BigNumber {
|
||||
const decimals = 18;
|
||||
const amountAsBigNumber = typeof amount === 'number' ? new BigNumber(amount) : amount;
|
||||
const baseUnitAmount = Web3Wrapper.toBaseUnitAmount(amountAsBigNumber, decimals);
|
||||
return baseUnitAmount;
|
||||
}
|
||||
public static toFixedPoint(amount: BigNumber | number, decimals: number): BigNumber {
|
||||
const amountAsBigNumber = typeof amount === 'number' ? new BigNumber(amount) : amount;
|
||||
const scalar = Math.pow(10, decimals);
|
||||
const amountAsFixedPoint = amountAsBigNumber.times(scalar);
|
||||
return amountAsFixedPoint;
|
||||
}
|
||||
public static toFloatingPoint(amount: BigNumber | number, decimals: number): BigNumber {
|
||||
const amountAsBigNumber = typeof amount === 'number' ? new BigNumber(amount) : amount;
|
||||
const scalar = Math.pow(10, decimals);
|
||||
const amountAsFloatingPoint = amountAsBigNumber.dividedBy(scalar);
|
||||
return amountAsFloatingPoint;
|
||||
}
|
||||
public static trimFloat(amount: BigNumber | number, decimals: number): BigNumber {
|
||||
const amountAsBigNumber = typeof amount === 'number' ? new BigNumber(amount) : amount;
|
||||
const scalar = Math.pow(10, decimals);
|
||||
const amountAsFloatingPoint = amountAsBigNumber
|
||||
.multipliedBy(scalar)
|
||||
.dividedToIntegerBy(1)
|
||||
.dividedBy(scalar);
|
||||
return amountAsFloatingPoint;
|
||||
}
|
||||
|
||||
constructor(
|
||||
provider: Provider,
|
||||
@ -74,7 +98,7 @@ export class StakingWrapper {
|
||||
this._validateDeployedOrThrow();
|
||||
return this._LibFeeMathTestContractIfExists as LibFeeMathTestContract;
|
||||
}
|
||||
public async deployAndConfigureContracts(): Promise<void> {
|
||||
public async deployAndConfigureContractsAsync(): Promise<void> {
|
||||
// deploy zrx vault
|
||||
const zrxAssetData = assetDataUtils.encodeERC20AssetData(this._zrxTokenContract.address);
|
||||
this._zrxVaultContractIfExists = await ZrxVaultContract.deployFrom0xArtifactAsync(
|
||||
@ -114,7 +138,7 @@ export class StakingWrapper {
|
||||
(this._stakingProxyContractIfExists).address,
|
||||
);
|
||||
// set zrx vault in staking contract
|
||||
const setZrxVaultCalldata = await (this
|
||||
const setZrxVaultCalldata = (this
|
||||
._stakingContractIfExists).setZrxVault.getABIEncodedTransactionData(
|
||||
(this._zrxVaultContractIfExists).address,
|
||||
);
|
||||
@ -132,7 +156,7 @@ export class StakingWrapper {
|
||||
(this._stakingProxyContractIfExists).address,
|
||||
);
|
||||
// set reward vault in staking contract
|
||||
const setRewardVaultCalldata = await (this
|
||||
const setRewardVaultCalldata = (this
|
||||
._stakingContractIfExists).setRewardVault.getABIEncodedTransactionData(
|
||||
(this._rewardVaultContractIfExists).address,
|
||||
);
|
||||
@ -325,12 +349,12 @@ export class StakingWrapper {
|
||||
const txReceipt = await this._executeTransactionAsync(calldata, operatorAddress);
|
||||
return txReceipt;
|
||||
}
|
||||
public async getMakerPoolId(makerAddress: string): Promise<string> {
|
||||
public async getMakerPoolIdAsync(makerAddress: string): Promise<string> {
|
||||
const calldata = this.getStakingContract().getMakerPoolId.getABIEncodedTransactionData(makerAddress);
|
||||
const poolId = await this._callAsync(calldata);
|
||||
return poolId;
|
||||
}
|
||||
public async getMakerAddressesForPool(poolId: string): Promise<string[]> {
|
||||
public async getMakerAddressesForPoolAsync(poolId: string): Promise<string[]> {
|
||||
const calldata = this.getStakingContract().getMakerAddressesForPool.getABIEncodedTransactionData(poolId);
|
||||
const returndata = await this._callAsync(calldata);
|
||||
const makerAddresses = this.getStakingContract().getMakerAddressesForPool.getABIDecodedReturnData(returndata);
|
||||
@ -340,7 +364,7 @@ export class StakingWrapper {
|
||||
poolId: string,
|
||||
makerAddress: string,
|
||||
makerSignature: string,
|
||||
): Promise<Boolean> {
|
||||
): Promise<boolean> {
|
||||
const calldata = this.getStakingContract().isValidMakerSignature.getABIEncodedTransactionData(
|
||||
poolId,
|
||||
makerAddress,
|
||||
@ -384,8 +408,8 @@ export class StakingWrapper {
|
||||
public async goToNextEpochAsync(): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const calldata = this.getStakingContract().finalizeFees.getABIEncodedTransactionData();
|
||||
const txReceipt = await this._executeTransactionAsync(calldata, undefined, new BigNumber(0), true);
|
||||
console.log(
|
||||
`finalization: gasUsed = ${txReceipt.gasUsed} / cumulativeGasUsed = ${txReceipt.cumulativeGasUsed}`,
|
||||
logUtils.log(
|
||||
`Finalization costed ${txReceipt.gasUsed} gas`,
|
||||
);
|
||||
return txReceipt;
|
||||
}
|
||||
@ -481,11 +505,11 @@ export class StakingWrapper {
|
||||
return value;
|
||||
}
|
||||
///// EXCHANGES /////
|
||||
public async isValidExchangeAddressAsync(exchangeAddress: string): Promise<Boolean> {
|
||||
public async isValidExchangeAddressAsync(exchangeAddress: string): Promise<boolean> {
|
||||
const calldata = this.getStakingContract().isValidExchangeAddress.getABIEncodedTransactionData(exchangeAddress);
|
||||
const returnData = await this._callAsync(calldata);
|
||||
const value = this.getStakingContract().isValidExchangeAddress.getABIDecodedReturnData(returnData);
|
||||
return value;
|
||||
const isValid = this.getStakingContract().isValidExchangeAddress.getABIDecodedReturnData(returnData);
|
||||
return isValid;
|
||||
}
|
||||
public async addExchangeAddressAsync(exchangeAddress: string): Promise<TransactionReceiptWithDecodedLogs> {
|
||||
const calldata = this.getStakingContract().addExchangeAddress.getABIEncodedTransactionData(exchangeAddress);
|
||||
@ -610,25 +634,25 @@ export class StakingWrapper {
|
||||
return txReceipt;
|
||||
}
|
||||
///// ZRX VAULT /////
|
||||
public async getZrxVaultBalance(holder: string): Promise<BigNumber> {
|
||||
public async getZrxVaultBalanceAsync(holder: string): Promise<BigNumber> {
|
||||
const balance = await this.getZrxVaultContract().balanceOf.callAsync(holder);
|
||||
return balance;
|
||||
}
|
||||
public async getZrxTokenBalance(holder: string): Promise<BigNumber> {
|
||||
public async getZrxTokenBalanceAsync(holder: string): Promise<BigNumber> {
|
||||
const balance = await this._zrxTokenContract.balanceOf.callAsync(holder);
|
||||
return balance;
|
||||
}
|
||||
public async getZrxTokenBalanceOfZrxVault(): Promise<BigNumber> {
|
||||
public async getZrxTokenBalanceOfZrxVaultAsync(): Promise<BigNumber> {
|
||||
const balance = await this._zrxTokenContract.balanceOf.callAsync(this.getZrxVaultContract().address);
|
||||
return balance;
|
||||
}
|
||||
///// MATH /////
|
||||
public async nthRoot(value: BigNumber, n: BigNumber): Promise<BigNumber> {
|
||||
public async nthRootAsync(value: BigNumber, n: BigNumber): Promise<BigNumber> {
|
||||
// const txReceipt = await this.getLibFeeMathTestContract().nthRoot.await(value, n);
|
||||
const output = await this.getLibFeeMathTestContract().nthRoot.callAsync(value, n);
|
||||
return output;
|
||||
}
|
||||
public async nthRootFixedPoint(value: BigNumber, n: BigNumber): Promise<BigNumber> {
|
||||
public async nthRootFixedPointAsync(value: BigNumber, n: BigNumber): Promise<BigNumber> {
|
||||
const output = await this.getLibFeeMathTestContract().nthRootFixedPoint.callAsync(value, n);
|
||||
return output;
|
||||
}
|
||||
@ -640,7 +664,7 @@ export class StakingWrapper {
|
||||
totalStake: BigNumber,
|
||||
alphaNumerator: BigNumber,
|
||||
alphaDenominator: BigNumber,
|
||||
) {
|
||||
): Promise<BigNumber> {
|
||||
const output = await this.getLibFeeMathTestContract().cobbDouglas.callAsync(
|
||||
totalRewards,
|
||||
ownerFees,
|
||||
@ -659,8 +683,8 @@ export class StakingWrapper {
|
||||
ownerStake: BigNumber,
|
||||
totalStake: BigNumber,
|
||||
alphaDenominator: BigNumber,
|
||||
) {
|
||||
const txReceipt = await this.getLibFeeMathTestContract().cobbDouglasSimplifiedInverse.awaitTransactionSuccessAsync(
|
||||
): Promise<BigNumber> {
|
||||
await this.getLibFeeMathTestContract().cobbDouglasSimplifiedInverse.awaitTransactionSuccessAsync(
|
||||
totalRewards,
|
||||
ownerFees,
|
||||
totalFees,
|
||||
@ -685,8 +709,8 @@ export class StakingWrapper {
|
||||
ownerStake: BigNumber,
|
||||
totalStake: BigNumber,
|
||||
alphaDenominator: BigNumber,
|
||||
) {
|
||||
const txReceipt = await this.getLibFeeMathTestContract().cobbDouglasSimplifiedInverse.awaitTransactionSuccessAsync(
|
||||
): Promise<BigNumber> {
|
||||
await this.getLibFeeMathTestContract().cobbDouglasSimplifiedInverse.awaitTransactionSuccessAsync(
|
||||
totalRewards,
|
||||
ownerFees,
|
||||
totalFees,
|
||||
@ -694,7 +718,6 @@ export class StakingWrapper {
|
||||
totalStake,
|
||||
alphaDenominator,
|
||||
);
|
||||
|
||||
const output = await this.getLibFeeMathTestContract().cobbDouglasSimplifiedInverse.callAsync(
|
||||
totalRewards,
|
||||
ownerFees,
|
||||
@ -705,33 +728,6 @@ export class StakingWrapper {
|
||||
);
|
||||
return output;
|
||||
}
|
||||
public toBaseUnitAmount(amount: BigNumber | number): BigNumber {
|
||||
const decimals = 18;
|
||||
const amountAsBigNumber = typeof amount === 'number' ? new BigNumber(amount) : amount;
|
||||
const baseUnitAmount = Web3Wrapper.toBaseUnitAmount(amountAsBigNumber, decimals);
|
||||
return baseUnitAmount;
|
||||
}
|
||||
public toFixedPoint(amount: BigNumber | number, decimals: number): BigNumber {
|
||||
const amountAsBigNumber = typeof amount === 'number' ? new BigNumber(amount) : amount;
|
||||
const scalar = Math.pow(10, decimals);
|
||||
const amountAsFixedPoint = amountAsBigNumber.times(scalar);
|
||||
return amountAsFixedPoint;
|
||||
}
|
||||
public toFloatingPoint(amount: BigNumber | number, decimals: number): BigNumber {
|
||||
const amountAsBigNumber = typeof amount === 'number' ? new BigNumber(amount) : amount;
|
||||
const scalar = Math.pow(10, decimals);
|
||||
const amountAsFloatingPoint = amountAsBigNumber.dividedBy(scalar);
|
||||
return amountAsFloatingPoint;
|
||||
}
|
||||
public trimFloat(amount: BigNumber | number, decimals: number): BigNumber {
|
||||
const amountAsBigNumber = typeof amount === 'number' ? new BigNumber(amount) : amount;
|
||||
const scalar = Math.pow(10, decimals);
|
||||
const amountAsFloatingPoint = amountAsBigNumber
|
||||
.multipliedBy(scalar)
|
||||
.dividedToIntegerBy(1)
|
||||
.dividedBy(scalar);
|
||||
return amountAsFloatingPoint;
|
||||
}
|
||||
private async _executeTransactionAsync(
|
||||
calldata: string,
|
||||
from?: string,
|
||||
@ -762,9 +758,10 @@ export class StakingWrapper {
|
||||
const returnValue = await this._web3Wrapper.callAsync(txData);
|
||||
return returnValue;
|
||||
}
|
||||
private _validateDeployedOrThrow() {
|
||||
private _validateDeployedOrThrow(): void {
|
||||
if (this._stakingContractIfExists === undefined) {
|
||||
throw new Error('Staking contracts are not deployed. Call `deployStakingContracts`');
|
||||
}
|
||||
}
|
||||
}
|
||||
// tslint:disable-line:max-file-line-count
|
||||
|
@ -45,6 +45,6 @@ export interface SimulationParams {
|
||||
expectedMembersPayoutByPool: BigNumber[];
|
||||
expectedPayoutByDelegator: BigNumber[];
|
||||
exchangeAddress: string;
|
||||
delegateInNextEpoch: Boolean;
|
||||
withdrawByUndelegating: Boolean;
|
||||
delegateInNextEpoch: boolean;
|
||||
withdrawByUndelegating: boolean;
|
||||
}
|
||||
|
@ -9,14 +9,11 @@ import {
|
||||
import { BlockchainLifecycle } from '@0x/dev-utils';
|
||||
import { RevertReason } from '@0x/types';
|
||||
import { BigNumber } from '@0x/utils';
|
||||
import * as chai from 'chai';
|
||||
import * as _ from 'lodash';
|
||||
|
||||
|
||||
import { StakingWrapper } from './utils/staking_wrapper';
|
||||
|
||||
chaiSetup.configure();
|
||||
const expect = chai.expect;
|
||||
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);
|
||||
// tslint:disable:no-unnecessary-type-assertion
|
||||
describe('Staking Vaults', () => {
|
||||
@ -25,10 +22,7 @@ describe('Staking Vaults', () => {
|
||||
// tokens & addresses
|
||||
let accounts: string[];
|
||||
let owner: string;
|
||||
let exchange: string;
|
||||
let stakers: string[];
|
||||
let makers: string[];
|
||||
let delegators: string[];
|
||||
let users: string[];
|
||||
let zrxTokenContract: DummyERC20TokenContract;
|
||||
let erc20ProxyContract: ERC20ProxyContract;
|
||||
// wrappers
|
||||
@ -45,9 +39,7 @@ describe('Staking Vaults', () => {
|
||||
// create accounts
|
||||
accounts = await web3Wrapper.getAvailableAddressesAsync();
|
||||
owner = accounts[0];
|
||||
exchange = accounts[1];
|
||||
stakers = accounts.slice(2, 5);
|
||||
makers = accounts.slice(4, 10);
|
||||
users = accounts.slice(1);
|
||||
// deploy erc20 proxy
|
||||
erc20Wrapper = new ERC20Wrapper(provider, accounts, owner);
|
||||
erc20ProxyContract = await erc20Wrapper.deployProxyAsync();
|
||||
@ -56,7 +48,7 @@ describe('Staking Vaults', () => {
|
||||
await erc20Wrapper.setBalancesAndAllowancesAsync();
|
||||
// deploy staking contracts
|
||||
stakingWrapper = new StakingWrapper(provider, owner, erc20ProxyContract, zrxTokenContract, accounts);
|
||||
await stakingWrapper.deployAndConfigureContracts();
|
||||
await stakingWrapper.deployAndConfigureContractsAsync();
|
||||
});
|
||||
beforeEach(async () => {
|
||||
await blockchainLifecycle.startAsync();
|
||||
@ -67,7 +59,7 @@ describe('Staking Vaults', () => {
|
||||
describe('Reward Vault', () => {
|
||||
it.skip('basic management', async () => {
|
||||
// 1 setup test parameters
|
||||
const poolOperator = stakers[1];
|
||||
const poolOperator = users[0];
|
||||
const operatorShare = 39;
|
||||
const poolId = await stakingWrapper.createPoolAsync(poolOperator, operatorShare);
|
||||
const stakingContractAddress = stakingWrapper.getStakingContract().address;
|
||||
|
Loading…
x
Reference in New Issue
Block a user