Basic payouts to delegators when the pool is empty and they receive 100% of the reward.

This commit is contained in:
Greg Hysen
2019-06-11 16:56:12 -07:00
parent 362a8c8fc5
commit 7d85e61cc5
5 changed files with 80 additions and 12 deletions

View File

@@ -1090,7 +1090,42 @@ describe('Staking Core', () => {
///// 8 CHECK PROFITS VIA STAKING CONTRACT /////
///// 9 WITHDRAW PROFITS VIA STAKING CONTRACT /////
/////
///// 10 CHECK DELEGATOR BY UNDELEGATING /////
const ethBalancesByDelegatorInit = await Promise.all([
stakingWrapper.getEthBalanceAsync(delegators[0]),
stakingWrapper.getEthBalanceAsync(delegators[1]),
stakingWrapper.getEthBalanceAsync(delegators[2]),
]);
await Promise.all([
stakingWrapper.deactivateAndTimelockDelegatedStakeAsync(delegators[0], poolIds[2], stakeByDelegator[0]),
stakingWrapper.deactivateAndTimelockDelegatedStakeAsync(delegators[1], poolIds[2], stakeByDelegator[1]),
stakingWrapper.deactivateAndTimelockDelegatedStakeAsync(delegators[2], poolIds[2], stakeByDelegator[2]),
]);
const ethBalancesByDelegatorFinal = await Promise.all([
stakingWrapper.getEthBalanceAsync(delegators[0]),
stakingWrapper.getEthBalanceAsync(delegators[1]),
stakingWrapper.getEthBalanceAsync(delegators[2]),
]);
const rewardByDelegator = [
ethBalancesByDelegatorFinal[0].minus(ethBalancesByDelegatorInit[0]),
ethBalancesByDelegatorFinal[1].minus(ethBalancesByDelegatorInit[1]),
ethBalancesByDelegatorFinal[2].minus(ethBalancesByDelegatorInit[2]),
];
// note that these may be slightly off due to rounding down on each entry
// there is a carry over between calls, which we account for here.
// if the last person to leave rounded down, then there is some trace amount left in the pool.
// carry-over here is 00000000000000000002
const expectedRewardByDelegator = [
payoutByPoolOperator[2].times(stakeByDelegator[0]).dividedToIntegerBy(totalStakeByDelegators),
payoutByPoolOperator[2].times(stakeByDelegator[1]).dividedToIntegerBy(totalStakeByDelegators),
new BigNumber('13927564703644768540'), // computed by hand to account for carry-over
];
expect(rewardByDelegator[0]).to.be.bignumber.equal(expectedRewardByDelegator[0]);
expect(rewardByDelegator[1]).to.be.bignumber.equal(expectedRewardByDelegator[1]);
expect(rewardByDelegator[2]).to.be.bignumber.equal(expectedRewardByDelegator[2]);
///// 10 CHECK DELEGATOR BUY-IN ON A SUBSEQUENT EPOCH, WHEN AMOUNT IS NON-ZERO /////
});
});
});

View File

@@ -122,12 +122,10 @@ export class StakingWrapper {
to: this.getStakingProxyContract().address,
data: calldata,
gas: 3000000,
gasPrice: 0,
value
}
const txHash = await this._web3Wrapper.sendTransactionAsync(txData);
if (includeLogs) {
}
const txReceipt = await (includeLogs ? this._logDecoder.getTxWithDecodedLogsAsync(txHash) : this._web3Wrapper.awaitTransactionSuccessAsync(txHash));
return txReceipt;
}
@@ -141,6 +139,10 @@ export class StakingWrapper {
const returnValue = await this._web3Wrapper.callAsync(txData);
return returnValue;
}
public async getEthBalanceAsync(owner: string): Promise<BigNumber> {
const balance = this._web3Wrapper.getBalanceInWeiAsync(owner);
return balance;
}
///// STAKE /////
public async depositAsync(owner: string, amount: BigNumber): Promise<TransactionReceiptWithDecodedLogs> {
const calldata = this.getStakingContract().deposit.getABIEncodedTransactionData(amount);
@@ -154,7 +156,8 @@ export class StakingWrapper {
}
public async depositAndDelegateAsync(owner: string, poolId: string, amount: BigNumber): Promise<TransactionReceiptWithDecodedLogs> {
const calldata = this.getStakingContract().depositAndDelegate.getABIEncodedTransactionData(poolId, amount);
const txReceipt = await this._executeTransactionAsync(calldata, owner);
const txReceipt = await this._executeTransactionAsync(calldata, owner);//, new BigNumber(0), true);
//console.log(JSON.stringify(txReceipt, null, 4));
return txReceipt;
}
public async activateStakeAsync(owner: string, amount: BigNumber): Promise<TransactionReceiptWithDecodedLogs> {
@@ -174,7 +177,8 @@ export class StakingWrapper {
}
public async deactivateAndTimelockDelegatedStakeAsync(owner: string, poolId: string, amount: BigNumber): Promise<TransactionReceiptWithDecodedLogs> {
const calldata = this.getStakingContract().deactivateAndTimelockDelegatedStake.getABIEncodedTransactionData(poolId, amount);
const txReceipt = await this._executeTransactionAsync(calldata, owner);
const txReceipt = await this._executeTransactionAsync(calldata, owner, new BigNumber(0), true);
console.log(JSON.stringify(txReceipt, null, 4));
return txReceipt;
}
public async withdrawAsync(owner: string, amount: BigNumber): Promise<TransactionReceiptWithDecodedLogs> {