Skip to content

Commit

Permalink
Fix rebase issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kyledewy committed Apr 13, 2023
1 parent bd67cdf commit 21f4ff3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
15 changes: 7 additions & 8 deletions contracts/modules/staking/StakingPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -836,11 +836,11 @@ contract StakingPool is IStakingPool, Multicall {
) {

trancheCapacities = getTrancheCapacities(
productId,
block.timestamp / TRANCHE_DURATION, // first active tranche id
MAX_ACTIVE_TRANCHES,
globalCapacityRatio,
capacityReductionRatio,
stakingProducts.getProductTargetWeight(poolId, productId)
capacityReductionRatio
);

totalCapacity = Math.sum(trancheCapacities);
Expand All @@ -849,11 +849,11 @@ contract StakingPool is IStakingPool, Multicall {
}

function getTrancheCapacities(
uint productId,
uint firstTrancheId,
uint trancheCount,
uint capacityRatio,
uint reductionRatio,
uint productTargetWeight
uint reductionRatio
) public view returns (uint[] memory trancheCapacities) {

// will revert if with unprocessed expirations
Expand All @@ -873,7 +873,7 @@ contract StakingPool is IStakingPool, Multicall {
uint multiplier =
capacityRatio
* (CAPACITY_REDUCTION_DENOMINATOR - reductionRatio)
* productTargetWeight;
* stakingProducts.getProductTargetWeight(poolId, productId);

uint denominator =
GLOBAL_CAPACITY_DENOMINATOR
Expand Down Expand Up @@ -914,13 +914,12 @@ contract StakingPool is IStakingPool, Multicall {
uint firstTrancheIdToUse = (block.timestamp + request.period + request.gracePeriod) / TRANCHE_DURATION;
uint startIndex = firstTrancheIdToUse - _firstActiveTrancheId;

uint productTargetWeight = stakingProducts.getProductTargetWeight(poolId, request.productId);
uint[] memory trancheCapacities = getTrancheCapacities(
request.productId,
firstTrancheIdToUse,
MAX_ACTIVE_TRANCHES - startIndex, // count
request.globalCapacityRatio,
request.capacityReductionRatio,
productTargetWeight
request.capacityReductionRatio
);

uint remainingAmount = coverAllocationAmount;
Expand Down
30 changes: 12 additions & 18 deletions test/integration/StakingProducts/recalculateEffectiveWeights.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
const { accounts, ethers } = require("hardhat");
const { ethers } = require('hardhat');
const { expect } = require('chai');
const { calculateFirstTrancheId } = require("../utils/staking");
const { calculateFirstTrancheId } = require('../utils/staking');
const { MaxUint256 } = ethers.constants;
const { parseEther } = ethers.utils;
const { daysToSeconds } = require('../../../lib/helpers');

const [
,
/* owner */ member1,
member2,
member3,
coverHolder,
] = accounts;

const stakedProductParamTemplate = {
productId: 1,
recalculateEffectiveWeight: true,
Expand All @@ -22,15 +14,13 @@ const stakedProductParamTemplate = {
targetPrice: 100,
};


describe.only('recalculateEffectiveWeights', function () {
describe('recalculateEffectiveWeights', function () {
beforeEach(async function () {
const { tk: nxm, tc: tokenController } = this.contracts;
await nxm.approve(tokenController.address, MaxUint256);
});

it('recalculates effective weights', async function () {

const { stakingProducts, stakingPool1 } = this.contracts;
const staker = this.accounts.defaultSender;
const [manager1] = this.accounts.stakingPoolManagers;
Expand All @@ -42,16 +32,20 @@ describe.only('recalculateEffectiveWeights', function () {

const targetWeight = 5;

await stakingProducts.connect(manager1).setProducts(productId, [{
...stakedProductParamTemplate, targetWeight
}]);
await stakingProducts.connect(manager1).setProducts(productId, [
{
...stakedProductParamTemplate,
targetWeight,
},
]);

// stake
const firstActiveTrancheId = await calculateFirstTrancheId(
const firstActiveTrancheId = calculateFirstTrancheId(
await ethers.provider.getBlock('latest'),
daysToSeconds(30),
0,
);

await stakingPool1.connect(staker).depositTo(stakeAmount, firstActiveTrancheId + 5, 0, staker.address);

await stakingProducts.recalculateEffectiveWeightsForAllProducts(poolId);
Expand All @@ -60,4 +54,4 @@ describe.only('recalculateEffectiveWeights', function () {

expect(product.lastEffectiveWeight).to.be.equal(targetWeight);
});
});
});

0 comments on commit 21f4ff3

Please sign in to comment.