Add function assertions required for staking rewards fuzzing: withdrawDelegatorRewards, finalizePool, and endEpoch. Also adds payProtocolFee-related assertions to fillOrder
This commit is contained in:
@@ -113,3 +113,31 @@ export function calculateFillResults(
|
||||
protocolFeePaid: safeMul(protocolFeeMultiplier, gasPrice),
|
||||
};
|
||||
}
|
||||
|
||||
export const LibFractions = {
|
||||
add: (n1: BigNumber, d1: BigNumber, n2: BigNumber, d2: BigNumber): [BigNumber, BigNumber] => {
|
||||
if (n1.isZero()) {
|
||||
return [n2, d2];
|
||||
}
|
||||
if (n2.isZero()) {
|
||||
return [n1, d1];
|
||||
}
|
||||
const numerator = safeAdd(safeMul(n1, d2), safeMul(n2, d1));
|
||||
const denominator = safeMul(d1, d2);
|
||||
return [numerator, denominator];
|
||||
},
|
||||
normalize: (
|
||||
numerator: BigNumber,
|
||||
denominator: BigNumber,
|
||||
maxValue: BigNumber = new BigNumber(2 ** 127),
|
||||
): [BigNumber, BigNumber] => {
|
||||
if (numerator.isGreaterThan(maxValue) || denominator.isGreaterThan(maxValue)) {
|
||||
const rescaleBase = numerator.isGreaterThanOrEqualTo(denominator)
|
||||
? safeDiv(numerator, maxValue)
|
||||
: safeDiv(denominator, maxValue);
|
||||
return [safeDiv(numerator, rescaleBase), safeDiv(denominator, rescaleBase)];
|
||||
} else {
|
||||
return [numerator, denominator];
|
||||
}
|
||||
},
|
||||
};
|
||||
|
Reference in New Issue
Block a user