Add ETH and USDC balance check before start/restart bot and autoswap
This commit is contained in:
@@ -75,4 +75,79 @@ public class ServiceUnavailableException : Exception
|
||||
public ServiceUnavailableException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exception thrown when there are insufficient funds or allowance for a transaction
|
||||
/// This typically indicates the user needs to add more ETH for gas or approve token spending
|
||||
/// </summary>
|
||||
public class InsufficientFundsException : Exception
|
||||
{
|
||||
/// <summary>
|
||||
/// The type of insufficient funds error
|
||||
/// </summary>
|
||||
public InsufficientFundsType ErrorType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// User-friendly message explaining what needs to be done
|
||||
/// </summary>
|
||||
public string UserMessage { get; }
|
||||
|
||||
public InsufficientFundsException(string errorMessage, InsufficientFundsType errorType)
|
||||
: base(errorMessage)
|
||||
{
|
||||
ErrorType = errorType;
|
||||
UserMessage = GetUserFriendlyMessage(errorType);
|
||||
}
|
||||
|
||||
private static string GetUserFriendlyMessage(InsufficientFundsType errorType)
|
||||
{
|
||||
return errorType switch
|
||||
{
|
||||
InsufficientFundsType.InsufficientEth =>
|
||||
"❌ **Insufficient ETH for Gas Fees**\n" +
|
||||
"Your wallet doesn't have enough ETH to pay for transaction gas fees.\n" +
|
||||
"Please add ETH to your wallet and try again.",
|
||||
|
||||
InsufficientFundsType.InsufficientAllowance =>
|
||||
"❌ **Insufficient Token Allowance**\n" +
|
||||
"The trading contract doesn't have permission to spend your tokens.\n" +
|
||||
"Please approve token spending in your wallet and try again.",
|
||||
|
||||
InsufficientFundsType.InsufficientBalance =>
|
||||
"❌ **Insufficient Token Balance**\n" +
|
||||
"Your wallet doesn't have enough tokens for this trade.\n" +
|
||||
"Please add more tokens to your wallet and try again.",
|
||||
|
||||
_ => "❌ **Transaction Failed**\n" +
|
||||
"The transaction failed due to insufficient funds.\n" +
|
||||
"Please check your wallet balance and try again."
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Types of insufficient funds errors
|
||||
/// </summary>
|
||||
public enum InsufficientFundsType
|
||||
{
|
||||
/// <summary>
|
||||
/// Not enough ETH for gas fees
|
||||
/// </summary>
|
||||
InsufficientEth,
|
||||
|
||||
/// <summary>
|
||||
/// Token allowance is insufficient (ERC20: transfer amount exceeds allowance)
|
||||
/// </summary>
|
||||
InsufficientAllowance,
|
||||
|
||||
/// <summary>
|
||||
/// Token balance is insufficient
|
||||
/// </summary>
|
||||
InsufficientBalance,
|
||||
|
||||
/// <summary>
|
||||
/// General insufficient funds error
|
||||
/// </summary>
|
||||
General
|
||||
}
|
||||
Reference in New Issue
Block a user