Skip to content

Commit

Permalink
minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pxrl committed Jan 16, 2024
1 parent 106c706 commit 276fc86
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
19 changes: 11 additions & 8 deletions src/relayFeeCalculator/relayFeeCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import assert from "assert";
import { BigNumber } from "ethers";
import {
BigNumberish,
bnZero,
fixedPointAdjustment,
toBNWei,
nativeToToken,
Expand Down Expand Up @@ -232,13 +233,15 @@ export class RelayFeeCalculator {
throw new Error(`Could not find token information for ${inputToken}`);
}

const outputAmount = getDepositOutputAmount(deposit);
const bn100 = toBN(100);
const getGasCosts = this.queries
.getGasCosts(
{
...deposit,
amount: simulateZeroFill && isV2Deposit(deposit) ? toBN(100) : outputAmount,
amount: simulateZeroFill && isV2Deposit(deposit) ? bn100 : outputAmount,
},
simulateZeroFill ? toBN(100) : amountToRelay,
simulateZeroFill ? bn100 : amountToRelay,
relayerAddress
)
.catch((error) => {
Expand Down Expand Up @@ -278,7 +281,7 @@ export class RelayFeeCalculator {
_destinationRoute?: ChainIdAsString
): BigNumber {
// If amount is 0, then the capital fee % should be the max 100%
if (toBN(_amountToRelay).eq(toBN(0))) return MAX_BIG_INT;
if (toBN(_amountToRelay).eq(bnZero)) return MAX_BIG_INT;

// V0: Ensure that there is a capital fee available for the token.
// If not, then we should throw an error because this is indicative
Expand Down Expand Up @@ -312,15 +315,15 @@ export class RelayFeeCalculator {

// triangleSlope is slope of fee curve from lower bound to upper bound. If cutoff is 0, slope is 0.
// triangleCharge is interval of curve from 0 to y for curve = triangleSlope * y
const triangleSlope = toBN(config.cutoff).eq(toBN(0))
? toBN(0)
const triangleSlope = toBN(config.cutoff).eq(bnZero)
? bnZero
: toBN(config.upperBound).sub(config.lowerBound).mul(fixedPointAdjustment).div(config.cutoff);
const triangleHeight = triangleSlope.mul(yTriangle).div(fixedPointAdjustment);
const triangleCharge = triangleHeight.mul(yTriangle).div(toBNWei(2));

// For any amounts above the cutoff, the marginal fee % will not increase but will be fixed at the upper bound
// value.
const yRemainder = max(toBN(0), y.sub(config.cutoff));
const yRemainder = max(bnZero, y.sub(config.cutoff));
const remainderCharge = yRemainder.mul(toBN(config.upperBound).sub(config.lowerBound)).div(fixedPointAdjustment);

return minCharge.add(triangleCharge).add(remainderCharge).mul(fixedPointAdjustment).div(y);
Expand Down Expand Up @@ -380,11 +383,11 @@ export class RelayFeeCalculator {
// gas fee %: maxGasFeePercent = gasFeeTotal / minDeposit. Refactor this to figure out the minDeposit:
// minDeposit = gasFeeTotal / maxGasFeePercent, and subsequently determine
// isAmountTooLow = amountToRelay < minDeposit.
const maxGasFeePercent = max(toBNWei(this.feeLimitPercent / 100).sub(capitalFeePercent), toBN(0));
const maxGasFeePercent = max(toBNWei(this.feeLimitPercent / 100).sub(capitalFeePercent), bnZero);
// If maxGasFee % is 0, then the min deposit should be infinite because there is no deposit amount that would
// incur a non zero gas fee % charge. In this case, isAmountTooLow should always be true.
let minDeposit: BigNumber, isAmountTooLow: boolean;
if (maxGasFeePercent.eq(toBN(0))) {
if (maxGasFeePercent.eq(bnZero)) {
minDeposit = MAX_BIG_INT;
isAmountTooLow = true;
} else {
Expand Down
4 changes: 2 additions & 2 deletions test/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,9 +248,9 @@ export async function simpleDeposit(
}
return {
...depositObject,
realizedLpFeePct: toBNWei("0"),
realizedLpFeePct: bnZero,
destinationToken: zeroAddress,
message: "0x",
message: EMPTY_MESSAGE,
};
}

Expand Down

0 comments on commit 276fc86

Please sign in to comment.