working on it

This commit is contained in:
Greg Hysen
2019-05-23 15:37:04 -07:00
parent 19f6a8dcfe
commit e2a76c621b
2 changed files with 63 additions and 5 deletions

View File

@@ -82,7 +82,7 @@ library LibMath {
// 5. Run Newton's nth Root Algorithm
let delta := 1 // run at least once
for {let i := 0}
or(lt(i, 10), gt(delta, 0))
and(lt(i, 20), gt(delta, 0))
{i := add(i,1)}
{
let lhsDenominator :=
@@ -158,11 +158,11 @@ library LibMath {
"numerator of (1 - alpha) is out of range"
);
uint256 feeRatio = _exp((totalRewards * ownerFees), alphaNumerator) / totalFees;
uint256 feeRatio = _exp((totalRewards * ownerFees) / totalFees, alphaNumerator);
uint256 rootedFeeRatio = _nthRootFixedPoint(feeRatio, alphaDenominator, fixedPointDecimals);
uint256 inverseAlphaNumerator = alphaDenominator - alphaNumerator;
uint256 stakeRatio = _exp((totalRewards * ownerStake), inverseAlphaNumerator) / totalStake;
uint256 stakeRatio = _exp((totalRewards * ownerStake) / totalStake, inverseAlphaNumerator);
uint256 rootedStakeRatio = _nthRootFixedPoint(stakeRatio, alphaDenominator, fixedPointDecimals);
return (rootedFeeRatio * rootedStakeRatio) / scalar;

View File

@@ -145,7 +145,7 @@ describe('Staking Core', () => {
expect(rootAsFloatingPoint).to.be.bignumber.equal(expectedResult);
});
it('cobb douglas - basic computation', async() => {
it.skip('cobb douglas - basic computation', async() => {
const totalRewards = new BigNumber(50);
const ownerFees = new BigNumber(5);
const totalFees = new BigNumber(10);
@@ -173,7 +173,7 @@ describe('Staking Core', () => {
expect(ownerReward).to.be.bignumber.equal(expectedOwnerReward);
});
it('cobb douglas - token computation', async() => {
it.only('cobb douglas - token computation', async() => {
const totalRewards = stakingWrapper.toBaseUnitAmount(50);
const ownerFees = stakingWrapper.toBaseUnitAmount(5);
const totalFees = stakingWrapper.toBaseUnitAmount(10);
@@ -200,6 +200,64 @@ describe('Staking Core', () => {
);
expect(ownerReward).to.be.bignumber.equal(expectedOwnerReward);
});
it.only('cobb douglas - complex token computation', async() => {
const totalRewards = stakingWrapper.toBaseUnitAmount(57.154398);
const ownerFees = stakingWrapper.toBaseUnitAmount(5.64375);
const totalFees = stakingWrapper.toBaseUnitAmount(29.00679);
const ownerStake = stakingWrapper.toBaseUnitAmount(56);
const totalStake = stakingWrapper.toBaseUnitAmount(10906);
const alphaNumerator = new BigNumber(1);
const alphaDenominator = new BigNumber(2);
/*const expectedOwnerReward = totalRewards
.times(
(ownerFees.div(totalFees)).squareRoot()
).times(
(ownerStake.div(totalStake)).squareRoot()
).dividedToIntegerBy(1); // 25000000000000000000*/
const ownerReward = await stakingWrapper.cobbDouglas(
totalRewards,
ownerFees,
totalFees,
ownerStake,
totalStake,
alphaNumerator,
alphaDenominator
);
console.log(ownerReward);
//expect(ownerReward).to.be.bignumber.equal(expectedOwnerReward);
});
it.only('cobb douglas - complex token computation #2', async() => {
const totalRewards = stakingWrapper.toBaseUnitAmount(57.154398);
const ownerFees = stakingWrapper.toBaseUnitAmount(5.64375);
const totalFees = stakingWrapper.toBaseUnitAmount(29.00679);
const ownerStake = stakingWrapper.toBaseUnitAmount(56);
const totalStake = stakingWrapper.toBaseUnitAmount(10906);
const alphaNumerator = new BigNumber(1);
const alphaDenominator = new BigNumber(3);
/*const expectedOwnerReward = totalRewards
.times(
(ownerFees.div(totalFees)).squareRoot()
).times(
(ownerStake.div(totalStake)).squareRoot()
).dividedToIntegerBy(1); // 25000000000000000000*/
const ownerReward = await stakingWrapper.cobbDouglas(
totalRewards,
ownerFees,
totalFees,
ownerStake,
totalStake,
alphaNumerator,
alphaDenominator
);
console.log(ownerReward);
//expect(ownerReward).to.be.bignumber.equal(expectedOwnerReward);
});
});
});
// tslint:enable:no-unnecessary-type-assertion