@swapper-finance/sdk
Version:
JavaScript SDK form Swapper
32 lines (26 loc) • 850 B
text/typescript
import { weiToHumanReadable } from "./numbers";
export const calculateFees = ({ route, cashToken, shift4Fees }) => {
const platformFee = Number(
weiToHumanReadable({
amount: route?.platformFeeInUSDC || "0",
decimals: cashToken?.decimals || 6,
precisionFractionalPlaces: 2,
}),
);
const networkFee =
Number(
weiToHumanReadable({
amount: route?.gasCostInUSDC || "0",
decimals: cashToken?.decimals || 6,
precisionFractionalPlaces: 2,
}),
) + Number(shift4Fees?.networkFeeFiatAmount || "0");
const onrampFee = Number(shift4Fees?.processingFeeFiatAmount || "0");
const totalFees = platformFee + networkFee + onrampFee;
return {
totalFees,
platformFee: platformFee.toFixed(2),
networkFee: networkFee.toFixed(2),
onrampFee: onrampFee.toFixed(2),
};
};