Skip to content

Commit

Permalink
fix calculateBatcherFee
Browse files Browse the repository at this point in the history
  • Loading branch information
m1n999999 committed Sep 18, 2024
1 parent ccfa184 commit ff87c55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/batcher-fee-reduction/calculate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Assets, UTxO } from "lucid-cardano";

import { NetworkEnvironment } from "../types/network";
import {
FIXED_BATCHER_FEE,
BATCHER_FEE_CONFIG,
getActiveBatcherFee,
getReducedBatcherFee,
} from "./configs.internal";
Expand All @@ -23,10 +23,11 @@ export function calculateBatcherFee({
reductionAssets: Assets;
} {
const reductionAssets: Assets = {};
const standardFee = BATCHER_FEE_CONFIG[networkEnv][dexVersion].standardFee;
const activeBatcherFeeConfig = getActiveBatcherFee(networkEnv, dexVersion);
if (!activeBatcherFeeConfig) {
return {
batcherFee: FIXED_BATCHER_FEE,
batcherFee: standardFee,
reductionAssets,
};
}
Expand All @@ -51,6 +52,7 @@ export function calculateBatcherFee({
}
return {
batcherFee: getReducedBatcherFee(
standardFee,
activeBatcherFeeConfig,
eligibleReductionAssets
),
Expand Down
9 changes: 5 additions & 4 deletions src/batcher-fee-reduction/configs.internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export function getActiveBatcherFee(
}

export function getReducedBatcherFee(
standardFee: bigint,
activeReductionConfig: BatcherFeeReductionConfig,
reductionAssets: Assets
): bigint {
Expand All @@ -54,20 +55,20 @@ export function getReducedBatcherFee(
? new BigNumber(1)
: totalReductionAmountRatio;

const maximumReduction = new BigNumber(FIXED_BATCHER_FEE.toString())
const maximumReduction = new BigNumber(standardFee.toString())
.minus(minFee.toString())
.div(FIXED_BATCHER_FEE.toString())
.div(standardFee.toString())
.multipliedBy(100);

// Apply the ratio to calculate batcher fee reduction
const totalReduction = new BigNumber(maximumReduction)
.multipliedBy(maximumReductionAmountRatio)
.div(100);

// New batcher fee = (1 - reduction) * DEFAULT BATCHER FEE
// New batcher fee = (1 - reduction) * standardFee
const finalFee = new BigNumber(1)
.minus(totalReduction)
.multipliedBy(new BigNumber(FIXED_BATCHER_FEE.toString()))
.multipliedBy(new BigNumber(standardFee.toString()))
.toFixed(0);
return BigInt(finalFee);
}
Expand Down

0 comments on commit ff87c55

Please sign in to comment.