Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: suggested-fees min amounts #1196

Merged
merged 6 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion api/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -598,11 +598,24 @@ export const getRelayerFeeDetails = async (
relayerAddress?: string,
gasPrice?: sdk.utils.BigNumberish
): Promise<sdk.relayFeeCalculator.RelayerFeeDetails> => {
console.log("function inputs:", {
inputToken,
outputToken,
amount: amount.toString(),
originChainId,
destinationChainId,
recipientAddress,
tokenPrice,
message,
relayerAddress,
gasPrice: gasPrice?.toString(),
});

const relayFeeCalculator = getRelayerFeeCalculator(destinationChainId, {
relayerAddress,
});
try {
return await relayFeeCalculator.relayerFeeDetails(
const results = await relayFeeCalculator.relayerFeeDetails(
{
inputAmount: sdk.utils.toBN(amount),
outputAmount: sdk.utils.toBN(amount),
Expand All @@ -627,6 +640,16 @@ export const getRelayerFeeDetails = async (
tokenPrice
// gasPrice // FIXME
);
console.log("Relayer fee details:", {
amountToRelay: results.amountToRelay.toString(),
relayerFee: results.capitalDiscountPercent.toString(),
totalFee: results.capitalFeePercent.toString(),
capitalFeeTotal: results.capitalFeeTotal.toString(),
feeLimitPct: results.feeLimitPercent.toString(),
minDeposit: results.minDeposit.toString(),
});

return results;
} catch (err: unknown) {
const reason = resolveEthersError(err);
throw new InputError(`Relayer fill simulation failed - ${reason}`);
Expand Down
9 changes: 7 additions & 2 deletions api/suggested-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,9 @@ const handler = async (

const skipAmountLimitEnabled = skipAmountLimit === "true";

if (!skipAmountLimitEnabled && relayerFeeDetails.isAmountTooLow)
if (!skipAmountLimitEnabled && relayerFeeDetails.isAmountTooLow) {
throw new InputError("Sent amount is too low relative to fees");
}

// Across V3's new `deposit` function requires now a total fee that includes the LP fee
const totalRelayFee = BigNumber.from(relayerFeeDetails.relayFeeTotal).add(
Expand All @@ -287,6 +288,10 @@ const handler = async (
amountInUsd
);

const isAmountTooLow =
james-a-morris marked this conversation as resolved.
Show resolved Hide resolved
relayerFeeDetails.isAmountTooLow ||
BigNumber.from(amountInput).lt(limits.minDeposit);

const { exclusiveRelayer, exclusivityPeriod } =
await selectExclusiveRelayer(
computedOriginChainId,
Expand All @@ -312,7 +317,7 @@ const handler = async (
timestamp: isNaN(parsedTimestamp)
? quoteTimestamp.toString()
: parsedTimestamp.toString(),
isAmountTooLow: relayerFeeDetails.isAmountTooLow,
isAmountTooLow,
quoteBlock: quoteBlockNumber.toString(),
exclusiveRelayer,
exclusivityDeadline,
Expand Down
Loading