From f40c3aa739a7aaa4f9514642eb74238f5c51ec20 Mon Sep 17 00:00:00 2001
From: james-a-morris <jaamorris@cs.stonybrook.edu>
Date: Fri, 6 Sep 2024 14:30:04 -0400
Subject: [PATCH 1/6] chore: test with logs

Signed-off-by: james-a-morris <jaamorris@cs.stonybrook.edu>
---
 api/_utils.ts         | 13 +++++++++++++
 api/suggested-fees.ts |  3 ++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/api/_utils.ts b/api/_utils.ts
index 2ed3eb3d8..70979e3d3 100644
--- a/api/_utils.ts
+++ b/api/_utils.ts
@@ -598,6 +598,19 @@ export const getRelayerFeeDetails = async (
   relayerAddress?: string,
   gasPrice?: sdk.utils.BigNumberish
 ): Promise<sdk.relayFeeCalculator.RelayerFeeDetails> => {
+  console.log("inputs:", {
+    inputToken,
+    outputToken,
+    amount,
+    originChainId,
+    destinationChainId,
+    recipientAddress,
+    tokenPrice,
+    message,
+    relayerAddress,
+    gasPrice,
+  });
+
   const relayFeeCalculator = getRelayerFeeCalculator(destinationChainId, {
     relayerAddress,
   });
diff --git a/api/suggested-fees.ts b/api/suggested-fees.ts
index 834e98ecf..2aed35882 100644
--- a/api/suggested-fees.ts
+++ b/api/suggested-fees.ts
@@ -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(

From 276e8b4238adc3670843b480b12c41c337a6d537 Mon Sep 17 00:00:00 2001
From: james-a-morris <jaamorris@cs.stonybrook.edu>
Date: Fri, 6 Sep 2024 14:38:09 -0400
Subject: [PATCH 2/6] fix: make isAmountTooLow context aware of limits

Signed-off-by: james-a-morris <jaamorris@cs.stonybrook.edu>
---
 api/_utils.ts         | 18 ++++++++++++++----
 api/suggested-fees.ts |  6 +++++-
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/api/_utils.ts b/api/_utils.ts
index 70979e3d3..8c040c5d3 100644
--- a/api/_utils.ts
+++ b/api/_utils.ts
@@ -598,24 +598,24 @@ export const getRelayerFeeDetails = async (
   relayerAddress?: string,
   gasPrice?: sdk.utils.BigNumberish
 ): Promise<sdk.relayFeeCalculator.RelayerFeeDetails> => {
-  console.log("inputs:", {
+  console.log("function inputs:", {
     inputToken,
     outputToken,
-    amount,
+    amount: amount.toString(),
     originChainId,
     destinationChainId,
     recipientAddress,
     tokenPrice,
     message,
     relayerAddress,
-    gasPrice,
+    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),
@@ -640,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}`);
diff --git a/api/suggested-fees.ts b/api/suggested-fees.ts
index 2aed35882..30e3ee314 100644
--- a/api/suggested-fees.ts
+++ b/api/suggested-fees.ts
@@ -288,6 +288,10 @@ const handler = async (
           amountInUsd
         );
 
+    const isAmountTooLow =
+      relayerFeeDetails.isAmountTooLow ||
+      BigNumber.from(amountInput).lt(limits.minDeposit);
+
     const { exclusiveRelayer, exclusivityPeriod } =
       await selectExclusiveRelayer(
         computedOriginChainId,
@@ -313,7 +317,7 @@ const handler = async (
       timestamp: isNaN(parsedTimestamp)
         ? quoteTimestamp.toString()
         : parsedTimestamp.toString(),
-      isAmountTooLow: relayerFeeDetails.isAmountTooLow,
+      isAmountTooLow,
       quoteBlock: quoteBlockNumber.toString(),
       exclusiveRelayer,
       exclusivityDeadline,

From eba53ca87163522741b99f9a065b7593af983c93 Mon Sep 17 00:00:00 2001
From: james-a-morris <jaamorris@cs.stonybrook.edu>
Date: Fri, 6 Sep 2024 14:43:08 -0400
Subject: [PATCH 3/6] improve: rearrange amount too low

Signed-off-by: james-a-morris <jaamorris@cs.stonybrook.edu>
---
 api/suggested-fees.ts | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/api/suggested-fees.ts b/api/suggested-fees.ts
index 30e3ee314..ef704f0d5 100644
--- a/api/suggested-fees.ts
+++ b/api/suggested-fees.ts
@@ -265,9 +265,12 @@ const handler = async (
       gasPrice
     );
 
-    const skipAmountLimitEnabled = skipAmountLimit === "true";
+    const isAmountTooLow =
+      relayerFeeDetails.isAmountTooLow ||
+      BigNumber.from(amountInput).lt(limits.minDeposit);
 
-    if (!skipAmountLimitEnabled && relayerFeeDetails.isAmountTooLow) {
+    const skipAmountLimitEnabled = skipAmountLimit === "true";
+    if (!skipAmountLimitEnabled && isAmountTooLow) {
       throw new InputError("Sent amount is too low relative to fees");
     }
 
@@ -288,10 +291,6 @@ const handler = async (
           amountInUsd
         );
 
-    const isAmountTooLow =
-      relayerFeeDetails.isAmountTooLow ||
-      BigNumber.from(amountInput).lt(limits.minDeposit);
-
     const { exclusiveRelayer, exclusivityPeriod } =
       await selectExclusiveRelayer(
         computedOriginChainId,

From 25939924464dce221b9a7cc1c4b2c59307347dd4 Mon Sep 17 00:00:00 2001
From: james-a-morris <jaamorris@cs.stonybrook.edu>
Date: Fri, 6 Sep 2024 14:44:19 -0400
Subject: [PATCH 4/6] nit: test

Signed-off-by: james-a-morris <jaamorris@cs.stonybrook.edu>
---
 api/suggested-fees.ts | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/api/suggested-fees.ts b/api/suggested-fees.ts
index ef704f0d5..8f3f24a08 100644
--- a/api/suggested-fees.ts
+++ b/api/suggested-fees.ts
@@ -317,6 +317,9 @@ const handler = async (
         ? quoteTimestamp.toString()
         : parsedTimestamp.toString(),
       isAmountTooLow,
+
+      minDepositForRelayer: relayerFeeDetails.minDeposit,
+
       quoteBlock: quoteBlockNumber.toString(),
       exclusiveRelayer,
       exclusivityDeadline,

From 6d1a23ca5e5d92d9fdd76c7082429ca1b9f166ee Mon Sep 17 00:00:00 2001
From: james-a-morris <jaamorris@cs.stonybrook.edu>
Date: Fri, 6 Sep 2024 15:36:11 -0400
Subject: [PATCH 5/6] chore: remove logs

Signed-off-by: james-a-morris <jaamorris@cs.stonybrook.edu>
---
 api/_utils.ts | 25 +------------------------
 1 file changed, 1 insertion(+), 24 deletions(-)

diff --git a/api/_utils.ts b/api/_utils.ts
index 8c040c5d3..2ed3eb3d8 100644
--- a/api/_utils.ts
+++ b/api/_utils.ts
@@ -598,24 +598,11 @@ 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 {
-    const results = await relayFeeCalculator.relayerFeeDetails(
+    return await relayFeeCalculator.relayerFeeDetails(
       {
         inputAmount: sdk.utils.toBN(amount),
         outputAmount: sdk.utils.toBN(amount),
@@ -640,16 +627,6 @@ 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}`);

From 2168559731ac5c5276a833afdca7aa45535c3596 Mon Sep 17 00:00:00 2001
From: james-a-morris <jaamorris@cs.stonybrook.edu>
Date: Fri, 6 Sep 2024 15:37:06 -0400
Subject: [PATCH 6/6] chore: remove logs

Signed-off-by: james-a-morris <jaamorris@cs.stonybrook.edu>
---
 api/suggested-fees.ts | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/api/suggested-fees.ts b/api/suggested-fees.ts
index 8f3f24a08..ef704f0d5 100644
--- a/api/suggested-fees.ts
+++ b/api/suggested-fees.ts
@@ -317,9 +317,6 @@ const handler = async (
         ? quoteTimestamp.toString()
         : parsedTimestamp.toString(),
       isAmountTooLow,
-
-      minDepositForRelayer: relayerFeeDetails.minDeposit,
-
       quoteBlock: quoteBlockNumber.toString(),
       exclusiveRelayer,
       exclusivityDeadline,