Ran yarn fix

This commit is contained in:
Greg Hysen
2019-06-26 14:15:01 -07:00
parent a02f96c913
commit 9294bf40a7
17 changed files with 114 additions and 204 deletions

View File

@@ -1,5 +0,0 @@
import { StakingWrapper } from '../utils/staking_wrapper';
import { DelegatorActor } from './delegator_actor';
import { MakerActor } from './maker_actor';
import { PoolOperatorActor } from './pool_operator_actor';

View File

@@ -1,10 +1,5 @@
import { import {
chaiSetup,
constants,
expectTransactionFailedAsync, expectTransactionFailedAsync,
provider,
txDefaults,
web3Wrapper,
} from '@0x/contracts-test-utils'; } from '@0x/contracts-test-utils';
import { RevertReason } from '@0x/types'; import { RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
@@ -39,7 +34,7 @@ export class DelegatorActor extends StakerActor {
const txReceipt = await txReceiptPromise; const txReceipt = await txReceiptPromise;
// @TODO check receipt logs and return value via eth_call // @TODO check receipt logs and return value via eth_call
// check balances // check balances
let expectedDelegatorBalances = initDelegatorBalances; const expectedDelegatorBalances = initDelegatorBalances;
expectedDelegatorBalances.zrxBalance = initDelegatorBalances.zrxBalance.minus(amount); expectedDelegatorBalances.zrxBalance = initDelegatorBalances.zrxBalance.minus(amount);
expectedDelegatorBalances.stakeBalance = initDelegatorBalances.stakeBalance.plus(amount); expectedDelegatorBalances.stakeBalance = initDelegatorBalances.stakeBalance.plus(amount);
expectedDelegatorBalances.stakeBalanceInVault = initDelegatorBalances.stakeBalanceInVault.plus(amount); expectedDelegatorBalances.stakeBalanceInVault = initDelegatorBalances.stakeBalanceInVault.plus(amount);
@@ -71,7 +66,7 @@ export class DelegatorActor extends StakerActor {
// @TODO check receipt logs and return value via eth_call // @TODO check receipt logs and return value via eth_call
// check balances // check balances
// check balances // check balances
let expectedDelegatorBalances = initDelegatorBalances; const expectedDelegatorBalances = initDelegatorBalances;
expectedDelegatorBalances.activatedStakeBalance = initDelegatorBalances.activatedStakeBalance.plus(amount); expectedDelegatorBalances.activatedStakeBalance = initDelegatorBalances.activatedStakeBalance.plus(amount);
expectedDelegatorBalances.withdrawableStakeBalance = expectedDelegatorBalances.withdrawableStakeBalance.minus( expectedDelegatorBalances.withdrawableStakeBalance = expectedDelegatorBalances.withdrawableStakeBalance.minus(
amount, amount,
@@ -109,7 +104,7 @@ export class DelegatorActor extends StakerActor {
const txReceipt = await txReceiptPromise; const txReceipt = await txReceiptPromise;
// @TODO check receipt logs and return value via eth_call // @TODO check receipt logs and return value via eth_call
// check balances // check balances
let expectedDelegatorBalances = initDelegatorBalances; const expectedDelegatorBalances = initDelegatorBalances;
expectedDelegatorBalances.activatedStakeBalance = initDelegatorBalances.activatedStakeBalance.minus(amount); expectedDelegatorBalances.activatedStakeBalance = initDelegatorBalances.activatedStakeBalance.minus(amount);
expectedDelegatorBalances.timelockedStakeBalance = expectedDelegatorBalances.timelockedStakeBalance.plus( expectedDelegatorBalances.timelockedStakeBalance = expectedDelegatorBalances.timelockedStakeBalance.plus(
amount, amount,
@@ -126,7 +121,7 @@ export class DelegatorActor extends StakerActor {
} }
public async getBalancesAsync(maybePoolIds?: string[]): Promise<DelegatorBalances> { public async getBalancesAsync(maybePoolIds?: string[]): Promise<DelegatorBalances> {
const stakerBalances = await super.getBalancesAsync(); const stakerBalances = await super.getBalancesAsync();
let delegatorBalances = { const delegatorBalances = {
...stakerBalances, ...stakerBalances,
delegatedStakeBalance: await this._stakingWrapper.getStakeDelegatedByOwnerAsync(this._owner), delegatedStakeBalance: await this._stakingWrapper.getStakeDelegatedByOwnerAsync(this._owner),
stakeDelegatedToPoolByOwner: Array(), stakeDelegatedToPoolByOwner: Array(),

View File

@@ -1,22 +1,11 @@
import { import { SignatureType } from '@0x/types';
chaiSetup,
constants,
expectTransactionFailedAsync,
provider,
txDefaults,
web3Wrapper,
} from '@0x/contracts-test-utils';
import { RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { SignatureType } from '@0x/types';
import { StakingWrapper } from '../utils/staking_wrapper'; import { StakingWrapper } from '../utils/staking_wrapper';
import { DelegatorBalances, StakerBalances } from '../utils/types'; import { SignedStakingPoolApproval } from '../utils/types';
import { BaseActor } from './base_actor'; import { BaseActor } from './base_actor';
import { SignedStakingPoolApproval } from '../utils/types';
const expect = chai.expect; const expect = chai.expect;

View File

@@ -1,21 +1,14 @@
import { import {
chaiSetup,
constants,
expectTransactionFailedAsync, expectTransactionFailedAsync,
provider,
txDefaults,
web3Wrapper,
} from '@0x/contracts-test-utils'; } from '@0x/contracts-test-utils';
import { RevertReason } from '@0x/types'; import { RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { constants as stakingConstants } from '../utils/constants';
import { StakingWrapper } from '../utils/staking_wrapper'; import { StakingWrapper } from '../utils/staking_wrapper';
import { DelegatorBalances, StakerBalances } from '../utils/types';
import { BaseActor } from './base_actor'; import { BaseActor } from './base_actor';
import { constants as stakingConstants } from '../utils/constants';
const expect = chai.expect; const expect = chai.expect;

View File

@@ -1,10 +1,5 @@
import { import {
chaiSetup,
constants,
expectTransactionFailedAsync, expectTransactionFailedAsync,
provider,
txDefaults,
web3Wrapper,
} from '@0x/contracts-test-utils'; } from '@0x/contracts-test-utils';
import { RevertReason } from '@0x/types'; import { RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
@@ -13,6 +8,7 @@ import * as _ from 'lodash';
import { StakingWrapper } from '../utils/staking_wrapper'; import { StakingWrapper } from '../utils/staking_wrapper';
import { StakerBalances } from '../utils/types'; import { StakerBalances } from '../utils/types';
import { BaseActor } from './base_actor'; import { BaseActor } from './base_actor';
const expect = chai.expect; const expect = chai.expect;
@@ -38,7 +34,7 @@ export class StakerActor extends BaseActor {
const txReceipt = await txReceiptPromise; const txReceipt = await txReceiptPromise;
// @TODO check receipt logs and return value via eth_call // @TODO check receipt logs and return value via eth_call
// check balances // check balances
let expectedStakerBalances = initStakerBalances; const expectedStakerBalances = initStakerBalances;
expectedStakerBalances.zrxBalance = initStakerBalances.zrxBalance.minus(amount); expectedStakerBalances.zrxBalance = initStakerBalances.zrxBalance.minus(amount);
expectedStakerBalances.stakeBalance = initStakerBalances.stakeBalance.plus(amount); expectedStakerBalances.stakeBalance = initStakerBalances.stakeBalance.plus(amount);
expectedStakerBalances.stakeBalanceInVault = initStakerBalances.stakeBalanceInVault.plus(amount); expectedStakerBalances.stakeBalanceInVault = initStakerBalances.stakeBalanceInVault.plus(amount);
@@ -60,7 +56,7 @@ export class StakerActor extends BaseActor {
const txReceipt = await txReceiptPromise; const txReceipt = await txReceiptPromise;
// @TODO check receipt logs and return value via eth_call // @TODO check receipt logs and return value via eth_call
// check balances // check balances
let expectedStakerBalances = initStakerBalances; const expectedStakerBalances = initStakerBalances;
expectedStakerBalances.withdrawableStakeBalance = initStakerBalances.withdrawableStakeBalance.minus(amount); expectedStakerBalances.withdrawableStakeBalance = initStakerBalances.withdrawableStakeBalance.minus(amount);
expectedStakerBalances.activatableStakeBalance = initStakerBalances.activatableStakeBalance.minus(amount); expectedStakerBalances.activatableStakeBalance = initStakerBalances.activatableStakeBalance.minus(amount);
expectedStakerBalances.activatedStakeBalance = initStakerBalances.activatedStakeBalance.plus(amount); expectedStakerBalances.activatedStakeBalance = initStakerBalances.activatedStakeBalance.plus(amount);
@@ -79,7 +75,7 @@ export class StakerActor extends BaseActor {
const txReceipt = await txReceiptPromise; const txReceipt = await txReceiptPromise;
// @TODO check receipt logs and return value via eth_call // @TODO check receipt logs and return value via eth_call
// check balances // check balances
let expectedStakerBalances = initStakerBalances; const expectedStakerBalances = initStakerBalances;
expectedStakerBalances.activatedStakeBalance = initStakerBalances.activatedStakeBalance.minus(amount); expectedStakerBalances.activatedStakeBalance = initStakerBalances.activatedStakeBalance.minus(amount);
expectedStakerBalances.timelockedStakeBalance = initStakerBalances.timelockedStakeBalance.plus(amount); expectedStakerBalances.timelockedStakeBalance = initStakerBalances.timelockedStakeBalance.plus(amount);
expectedStakerBalances.deactivatedStakeBalance = initStakerBalances.deactivatedStakeBalance.plus(amount); expectedStakerBalances.deactivatedStakeBalance = initStakerBalances.deactivatedStakeBalance.plus(amount);
@@ -98,7 +94,7 @@ export class StakerActor extends BaseActor {
const txReceipt = await txReceiptPromise; const txReceipt = await txReceiptPromise;
// @TODO check receipt logs and return value via eth_call // @TODO check receipt logs and return value via eth_call
// check balances // check balances
let expectedStakerBalances = initStakerBalances; const expectedStakerBalances = initStakerBalances;
expectedStakerBalances.zrxBalance = initStakerBalances.zrxBalance.plus(amount); expectedStakerBalances.zrxBalance = initStakerBalances.zrxBalance.plus(amount);
expectedStakerBalances.stakeBalance = initStakerBalances.stakeBalance.minus(amount); expectedStakerBalances.stakeBalance = initStakerBalances.stakeBalance.minus(amount);
expectedStakerBalances.stakeBalanceInVault = initStakerBalances.stakeBalanceInVault.minus(amount); expectedStakerBalances.stakeBalanceInVault = initStakerBalances.stakeBalanceInVault.minus(amount);
@@ -158,7 +154,7 @@ export class StakerActor extends BaseActor {
// skip to next period // skip to next period
await this._stakingWrapper.skipToNextTimelockPeriodAsync(); await this._stakingWrapper.skipToNextTimelockPeriodAsync();
// validate new balances // validate new balances
let expectedBalances = initBalances; const expectedBalances = initBalances;
const currentTimelockPeriod = await this._stakingWrapper.getCurrentTimelockPeriodAsync(); const currentTimelockPeriod = await this._stakingWrapper.getCurrentTimelockPeriodAsync();
if (currentTimelockPeriod.minus(timelockStart).isGreaterThan(1)) { if (currentTimelockPeriod.minus(timelockStart).isGreaterThan(1)) {
expectedBalances.activatableStakeBalance = initBalances.activatableStakeBalance.plus( expectedBalances.activatableStakeBalance = initBalances.activatableStakeBalance.plus(

View File

@@ -1,25 +1,18 @@
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { import {
chaiSetup, chaiSetup,
constants,
expectTransactionFailedAsync,
provider, provider,
txDefaults,
web3Wrapper, web3Wrapper,
} from '@0x/contracts-test-utils'; } from '@0x/contracts-test-utils';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { BlockchainLifecycle } from '@0x/dev-utils'; import { BlockchainLifecycle } from '@0x/dev-utils';
import { RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { constants as stakingConstants } from './utils/constants'; import { constants as stakingConstants } from './utils/constants';
import { StakingWrapper } from './utils/staking_wrapper'; import { StakingWrapper } from './utils/staking_wrapper';
import { ERC20Wrapper, ERC20ProxyContract } from '@0x/contracts-asset-proxy';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);

View File

@@ -1,29 +1,20 @@
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { import {
chaiSetup, chaiSetup,
constants,
expectTransactionFailedAsync, expectTransactionFailedAsync,
provider, provider,
txDefaults,
web3Wrapper, web3Wrapper,
} from '@0x/contracts-test-utils'; } from '@0x/contracts-test-utils';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { BlockchainLifecycle } from '@0x/dev-utils'; import { BlockchainLifecycle } from '@0x/dev-utils';
import { RevertReason } from '@0x/types'; import { RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { constants as stakingConstants } from './utils/constants';
import { StakingWrapper } from './utils/staking_wrapper'; import { StakingWrapper } from './utils/staking_wrapper';
import { ERC20Wrapper, ERC20ProxyContract } from '@0x/contracts-asset-proxy';
import { StakingContract } from '../src';
import { StakerActor } from './actors/staker_actor';
import { DelegatorActor } from './actors/delegator_actor';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);

View File

@@ -1,12 +1,10 @@
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { import {
chaiSetup, chaiSetup,
constants,
expectTransactionFailedAsync,
provider, provider,
txDefaults,
web3Wrapper, web3Wrapper,
} from '@0x/contracts-test-utils'; } from '@0x/contracts-test-utils';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { BlockchainLifecycle } from '@0x/dev-utils'; import { BlockchainLifecycle } from '@0x/dev-utils';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import * as chai from 'chai'; import * as chai from 'chai';
@@ -14,8 +12,6 @@ import * as _ from 'lodash';
import { StakingWrapper } from './utils/staking_wrapper'; import { StakingWrapper } from './utils/staking_wrapper';
import { ERC20Wrapper, ERC20ProxyContract } from '@0x/contracts-asset-proxy';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);

View File

@@ -1,31 +1,23 @@
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { import {
chaiSetup, chaiSetup,
constants,
expectTransactionFailedAsync, expectTransactionFailedAsync,
provider, provider,
txDefaults,
web3Wrapper, web3Wrapper,
} from '@0x/contracts-test-utils'; } from '@0x/contracts-test-utils';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { BlockchainLifecycle } from '@0x/dev-utils'; import { BlockchainLifecycle } from '@0x/dev-utils';
import { RevertReason } from '@0x/types'; import { RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types';
import * as ethUtil from 'ethereumjs-util'; import * as ethUtil from 'ethereumjs-util';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { constants as stakingConstants } from './utils/constants';
import { StakingWrapper } from './utils/staking_wrapper';
import { ERC20Wrapper, ERC20ProxyContract } from '@0x/contracts-asset-proxy';
import { StakingContract } from '../src';
import { StakerActor } from './actors/staker_actor';
import { DelegatorActor } from './actors/delegator_actor';
import { PoolOperatorActor } from './actors/pool_operator_actor';
import { MakerActor } from './actors/maker_actor'; import { MakerActor } from './actors/maker_actor';
import { PoolOperatorActor } from './actors/pool_operator_actor';
import { constants as stakingConstants } from './utils/constants';
import { StakingWrapper } from './utils/staking_wrapper';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;

View File

@@ -1,3 +1,17 @@
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 { import {
chaiSetup, chaiSetup,
constants, constants,
@@ -6,41 +20,13 @@ import {
txDefaults, txDefaults,
web3Wrapper, web3Wrapper,
} from '@0x/contracts-test-utils'; } from '@0x/contracts-test-utils';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { BlockchainLifecycle } from '@0x/dev-utils'; import { BlockchainLifecycle } from '@0x/dev-utils';
import { RevertReason } from '@0x/types'; import { RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types'; import { LogWithDecodedArgs } from 'ethereum-types';
import * as _ from 'lodash'; import * as _ from 'lodash';
rc20ProxyContract: ERC20ProxyContract;
import { constants as stakingConstants } from './utils/constants';
import { StakingWrapper } from './utils/staking_wrapper';
import { ERC20Wrapper, ERC20ProxyContract } from '@0x/contracts-asset-proxy';
import { StakingContract } from '../src';
import { StakerActor } from './actors/staker_actor';
import { DelegatorActor } from './actors/delegator_actor';
import { SimulationParams } from './utils/types';
import { Simulation } from './utils/Simulation';
chaiSetup.configure();
const expect = chai.expect;
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;
let stakers: string[]; let stakers: string[];
let makers: string[]; let makers: string[];
@@ -141,7 +127,7 @@ describe('End-To-End Simulations', () => {
/* /*
\ // the expected payouts were computed by hand \ // the expected payouts were computed by hand
// @TODO - get computations more accurate // @TODO - get computations more accurate
Pool | Total Fees | Total Stake | Total Delegated Stake | Total Stake (Scaled) Pool | Total Fees | Total Stake | Total Delegated Stake | Total Stake (Scaled)
0 | 0.304958 | 42 | 0 | 42 0 | 0.304958 | 42 | 0 | 42
1 | 15.323258 | 84 | 0 | 84 1 | 15.323258 | 84 | 0 | 84
3 | 28.12222236 | 97 | 182 | 260.8 3 | 28.12222236 | 97 | 182 | 260.8
@@ -218,7 +204,7 @@ describe('End-To-End Simulations', () => {
it('Should successfully simulate (delegators withdraw by undelegating / includes shadow balances / delegators enter after reward payouts)', async () => { it('Should successfully simulate (delegators withdraw by undelegating / includes shadow balances / delegators enter after reward payouts)', async () => {
// @TODO - get computations more accurate // @TODO - get computations more accurate
/* /*
Pool | Total Fees | Total Stake | Total Delegated Stake | Total Stake (Scaled) Pool | Total Fees | Total Stake | Total Delegated Stake | Total Stake (Scaled)
0 | 0.304958 | 42 | 0 | 42 0 | 0.304958 | 42 | 0 | 42
1 | 15.323258 | 84 | 0 | 84 1 | 15.323258 | 84 | 0 | 84
3 | 28.12222236 | 97 | 182 | 260.8 3 | 28.12222236 | 97 | 182 | 260.8
@@ -297,7 +283,7 @@ describe('End-To-End Simulations', () => {
it('Should successfully simulate (delegators withdraw without undelegating / includes shadow balances / delegators enter after reward payouts)', async () => { it('Should successfully simulate (delegators withdraw without undelegating / includes shadow balances / delegators enter after reward payouts)', async () => {
// @TODO - get computations more accurate // @TODO - get computations more accurate
/* /*
Pool | Total Fees | Total Stake | Total Delegated Stake | Total Stake (Scaled) Pool | Total Fees | Total Stake | Total Delegated Stake | Total Stake (Scaled)
0 | 0.304958 | 42 | 0 | 42 0 | 0.304958 | 42 | 0 | 42
1 | 15.323258 | 84 | 0 | 84 1 | 15.323258 | 84 | 0 | 84
3 | 28.12222236 | 97 | 182 | 260.8 3 | 28.12222236 | 97 | 182 | 260.8

View File

@@ -1,28 +1,20 @@
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { import {
chaiSetup, chaiSetup,
constants,
expectTransactionFailedAsync,
provider, provider,
txDefaults,
web3Wrapper, web3Wrapper,
} from '@0x/contracts-test-utils'; } from '@0x/contracts-test-utils';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { BlockchainLifecycle } from '@0x/dev-utils'; import { BlockchainLifecycle } from '@0x/dev-utils';
import { RevertReason } from '@0x/types'; import { RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { constants as stakingConstants } from './utils/constants';
import { StakingWrapper } from './utils/staking_wrapper';
import { ERC20Wrapper, ERC20ProxyContract } from '@0x/contracts-asset-proxy';
import { StakingContract } from '../src';
import { StakerActor } from './actors/staker_actor';
import { DelegatorActor } from './actors/delegator_actor'; import { DelegatorActor } from './actors/delegator_actor';
import { StakerActor } from './actors/staker_actor';
import { StakingWrapper } from './utils/staking_wrapper';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;

View File

@@ -1,6 +1,5 @@
import { signingUtils } from '@0x/contracts-test-utils'; import { signingUtils } from '@0x/contracts-test-utils';
import { SignatureType } from '@0x/types'; import { SignatureType } from '@0x/types';
import { BigNumber } from '@0x/utils';
import * as ethUtil from 'ethereumjs-util'; import * as ethUtil from 'ethereumjs-util';
import { hashUtils } from './hash_utils'; import { hashUtils } from './hash_utils';

View File

@@ -1,14 +1,15 @@
import { chaiSetup } from '@0x/contracts-test-utils'; import { chaiSetup } from '@0x/contracts-test-utils';
import * as _ from 'lodash';
import * as chai from 'chai';
import { PoolOperatorActor } from '../actors/pool_operator_actor';
import { MakerActor } from '../actors/maker_actor';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import { SimulationParams } from './types'; import * as chai from 'chai';
import { StakingWrapper } from './staking_wrapper'; import * as _ from 'lodash';
import { Queue } from './queue';
import { DelegatorActor } from '../actors/delegator_actor'; import { DelegatorActor } from '../actors/delegator_actor';
import { MakerActor } from '../actors/maker_actor';
import { PoolOperatorActor } from '../actors/pool_operator_actor';
import { Queue } from './queue';
import { StakingWrapper } from './staking_wrapper';
import { SimulationParams } from './types';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
@@ -17,11 +18,11 @@ export class Simulation {
private readonly _stakingWrapper: StakingWrapper; private readonly _stakingWrapper: StakingWrapper;
private readonly _p: SimulationParams; private readonly _p: SimulationParams;
private _userQueue: Queue<string>; private _userQueue: Queue<string>;
private _poolOperators: PoolOperatorActor[]; private readonly _poolOperators: PoolOperatorActor[];
private _poolOperatorsAsDelegators: DelegatorActor[]; private readonly _poolOperatorsAsDelegators: DelegatorActor[];
private _poolIds: string[]; private readonly _poolIds: string[];
private _makers: MakerActor[]; private readonly _makers: MakerActor[];
private _delegators: DelegatorActor[]; private readonly _delegators: DelegatorActor[];
constructor(stakingWrapper: StakingWrapper, simulationParams: SimulationParams) { constructor(stakingWrapper: StakingWrapper, simulationParams: SimulationParams) {
this._stakingWrapper = stakingWrapper; this._stakingWrapper = stakingWrapper;

View File

@@ -1,25 +1,26 @@
import { ERC20ProxyContract } from '@0x/contracts-asset-proxy';
import { artifacts as erc20Artifacts, DummyERC20TokenContract } from '@0x/contracts-erc20';
import { constants as testUtilsConstants, LogDecoder, txDefaults } from '@0x/contracts-test-utils'; 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 } from '@0x/utils';
import { Web3Wrapper } from '@0x/web3-wrapper'; import { Web3Wrapper } from '@0x/web3-wrapper';
import * as chai from 'chai'; import * as chai from 'chai';
import { assetDataUtils } from '@0x/order-utils'; import { Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import { SignatureType } from '@0x/types';
import { LogWithDecodedArgs, Provider, TransactionReceiptWithDecodedLogs } from 'ethereum-types';
import { artifacts as erc20Artifacts, DummyERC20TokenContract } from '@0x/contracts-erc20';
import { ERC20ProxyContract } from '@0x/contracts-asset-proxy';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { import {
artifacts, artifacts,
LibFeeMathTestContract,
RewardVaultContract,
StakingContract, StakingContract,
StakingProxyContract, StakingProxyContract,
ZrxVaultContract, ZrxVaultContract,
RewardVaultContract,
LibFeeMathTestContract,
} from '../../src'; } from '../../src';
import { ApprovalFactory } from './ApprovalFactory'; import { ApprovalFactory } from './ApprovalFactory';
import { SignedStakingPoolApproval } from './types';
import { constants } from './constants'; import { constants } from './constants';
import { SignedStakingPoolApproval } from './types';
const expect = chai.expect; const expect = chai.expect;
@@ -92,7 +93,7 @@ export class StakingWrapper {
); );
// configure erc20 proxy to accept calls from zrx vault // configure erc20 proxy to accept calls from zrx vault
await this._erc20ProxyContract.addAuthorizedAddress.awaitTransactionSuccessAsync( await this._erc20ProxyContract.addAuthorizedAddress.awaitTransactionSuccessAsync(
(this._zrxVaultContractIfExists as ZrxVaultContract).address, (this._zrxVaultContractIfExists).address,
); );
// deploy staking contract // deploy staking contract
this._stakingContractIfExists = await StakingContract.deployFrom0xArtifactAsync( this._stakingContractIfExists = await StakingContract.deployFrom0xArtifactAsync(
@@ -105,21 +106,21 @@ export class StakingWrapper {
artifacts.StakingProxy, artifacts.StakingProxy,
this._provider, this._provider,
txDefaults, txDefaults,
(this._stakingContractIfExists as StakingContract).address, (this._stakingContractIfExists).address,
); );
// set staking proxy contract in zrx vault // set staking proxy contract in zrx vault
await (this await (this
._zrxVaultContractIfExists as ZrxVaultContract).setStakingContractAddrsess.awaitTransactionSuccessAsync( ._zrxVaultContractIfExists).setStakingContractAddrsess.awaitTransactionSuccessAsync(
(this._stakingProxyContractIfExists as StakingProxyContract).address, (this._stakingProxyContractIfExists).address,
); );
// set zrx vault in staking contract // set zrx vault in staking contract
const setZrxVaultCalldata = await (this const setZrxVaultCalldata = await (this
._stakingContractIfExists as StakingContract).setZrxVault.getABIEncodedTransactionData( ._stakingContractIfExists).setZrxVault.getABIEncodedTransactionData(
(this._zrxVaultContractIfExists as ZrxVaultContract).address, (this._zrxVaultContractIfExists).address,
); );
const setZrxVaultTxData = { const setZrxVaultTxData = {
from: this._ownerAddres, from: this._ownerAddres,
to: (this._stakingProxyContractIfExists as StakingProxyContract).address, to: (this._stakingProxyContractIfExists).address,
data: setZrxVaultCalldata, data: setZrxVaultCalldata,
}; };
await this._web3Wrapper.awaitTransactionSuccessAsync( await this._web3Wrapper.awaitTransactionSuccessAsync(
@@ -127,17 +128,17 @@ export class StakingWrapper {
); );
// set staking proxy contract in reward vault // set staking proxy contract in reward vault
await (this await (this
._rewardVaultContractIfExists as RewardVaultContract).setStakingContractAddrsess.awaitTransactionSuccessAsync( ._rewardVaultContractIfExists).setStakingContractAddrsess.awaitTransactionSuccessAsync(
(this._stakingProxyContractIfExists as StakingProxyContract).address, (this._stakingProxyContractIfExists).address,
); );
// set reward vault in staking contract // set reward vault in staking contract
const setRewardVaultCalldata = await (this const setRewardVaultCalldata = await (this
._stakingContractIfExists as StakingContract).setRewardVault.getABIEncodedTransactionData( ._stakingContractIfExists).setRewardVault.getABIEncodedTransactionData(
(this._rewardVaultContractIfExists as RewardVaultContract).address, (this._rewardVaultContractIfExists).address,
); );
const setRewardVaultTxData = { const setRewardVaultTxData = {
from: this._ownerAddres, from: this._ownerAddres,
to: (this._stakingProxyContractIfExists as StakingProxyContract).address, to: (this._stakingProxyContractIfExists).address,
data: setRewardVaultCalldata, data: setRewardVaultCalldata,
}; };
await this._web3Wrapper.awaitTransactionSuccessAsync( await this._web3Wrapper.awaitTransactionSuccessAsync(
@@ -150,36 +151,6 @@ export class StakingWrapper {
txDefaults, txDefaults,
); );
} }
private async _executeTransactionAsync(
calldata: string,
from?: string,
value?: BigNumber,
includeLogs?: boolean,
): Promise<TransactionReceiptWithDecodedLogs> {
const txData = {
from: from ? from : this._ownerAddres,
to: this.getStakingProxyContract().address,
data: calldata,
gas: 3000000,
gasPrice: 0,
value,
};
const txHash = await this._web3Wrapper.sendTransactionAsync(txData);
const txReceipt = await (includeLogs
? this._logDecoder.getTxWithDecodedLogsAsync(txHash)
: this._web3Wrapper.awaitTransactionSuccessAsync(txHash));
return txReceipt;
}
private async _callAsync(calldata: string, from?: string): Promise<any> {
const txData = {
from: from ? from : this._ownerAddres,
to: this.getStakingProxyContract().address,
data: calldata,
gas: 3000000,
};
const returnValue = await this._web3Wrapper.callAsync(txData);
return returnValue;
}
public async getEthBalanceAsync(owner: string): Promise<BigNumber> { public async getEthBalanceAsync(owner: string): Promise<BigNumber> {
const balance = this._web3Wrapper.getBalanceInWeiAsync(owner); const balance = this._web3Wrapper.getBalanceInWeiAsync(owner);
return balance; return balance;
@@ -653,7 +624,7 @@ export class StakingWrapper {
} }
///// MATH ///// ///// MATH /////
public async nthRoot(value: BigNumber, n: BigNumber): Promise<BigNumber> { public async nthRoot(value: BigNumber, n: BigNumber): Promise<BigNumber> {
//const txReceipt = await this.getLibFeeMathTestContract().nthRoot.await(value, n); // const txReceipt = await this.getLibFeeMathTestContract().nthRoot.await(value, n);
const output = await this.getLibFeeMathTestContract().nthRoot.callAsync(value, n); const output = await this.getLibFeeMathTestContract().nthRoot.callAsync(value, n);
return output; return output;
} }
@@ -761,6 +732,36 @@ export class StakingWrapper {
.dividedBy(scalar); .dividedBy(scalar);
return amountAsFloatingPoint; return amountAsFloatingPoint;
} }
private async _executeTransactionAsync(
calldata: string,
from?: string,
value?: BigNumber,
includeLogs?: boolean,
): Promise<TransactionReceiptWithDecodedLogs> {
const txData = {
from: from ? from : this._ownerAddres,
to: this.getStakingProxyContract().address,
data: calldata,
gas: 3000000,
gasPrice: 0,
value,
};
const txHash = await this._web3Wrapper.sendTransactionAsync(txData);
const txReceipt = await (includeLogs
? this._logDecoder.getTxWithDecodedLogsAsync(txHash)
: this._web3Wrapper.awaitTransactionSuccessAsync(txHash));
return txReceipt;
}
private async _callAsync(calldata: string, from?: string): Promise<any> {
const txData = {
from: from ? from : this._ownerAddres,
to: this.getStakingProxyContract().address,
data: calldata,
gas: 3000000,
};
const returnValue = await this._web3Wrapper.callAsync(txData);
return returnValue;
}
private _validateDeployedOrThrow() { private _validateDeployedOrThrow() {
if (this._stakingContractIfExists === undefined) { if (this._stakingContractIfExists === undefined) {
throw new Error('Staking contracts are not deployed. Call `deployStakingContracts`'); throw new Error('Staking contracts are not deployed. Call `deployStakingContracts`');

View File

@@ -1,29 +1,20 @@
import { ERC20ProxyContract, ERC20Wrapper } from '@0x/contracts-asset-proxy';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { import {
chaiSetup, chaiSetup,
constants,
expectTransactionFailedAsync, expectTransactionFailedAsync,
provider, provider,
txDefaults,
web3Wrapper, web3Wrapper,
} from '@0x/contracts-test-utils'; } from '@0x/contracts-test-utils';
import { DummyERC20TokenContract } from '@0x/contracts-erc20';
import { BlockchainLifecycle } from '@0x/dev-utils'; import { BlockchainLifecycle } from '@0x/dev-utils';
import { RevertReason } from '@0x/types'; import { RevertReason } from '@0x/types';
import { BigNumber } from '@0x/utils'; import { BigNumber } from '@0x/utils';
import * as chai from 'chai'; import * as chai from 'chai';
import { LogWithDecodedArgs } from 'ethereum-types';
import * as _ from 'lodash'; import * as _ from 'lodash';
import { constants as stakingConstants } from './utils/constants';
import { StakingWrapper } from './utils/staking_wrapper'; import { StakingWrapper } from './utils/staking_wrapper';
import { ERC20Wrapper, ERC20ProxyContract } from '@0x/contracts-asset-proxy';
import { StakingContract } from '../src';
import { StakerActor } from './actors/staker_actor';
import { DelegatorActor } from './actors/delegator_actor';
chaiSetup.configure(); chaiSetup.configure();
const expect = chai.expect; const expect = chai.expect;
const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper);