Change Insufficient Allowance message to High network fee

This commit is contained in:
2025-10-17 14:45:21 +07:00
parent 3f1b5f09e0
commit acea43ec71
3 changed files with 48 additions and 5 deletions

View File

@@ -770,6 +770,34 @@ export const openGmxPositionImpl = async (
direction: direction
});
// Check and handle token allowance for GMX contracts
console.log('🔐 Checking token allowances for position opening...');
await approveTokenForContract(
sdk,
"USDC", // Using USDC as collateral
collateralToken,
collateralAmount,
"OrderVault"
);
await approveTokenForContract(
sdk,
"USDC", // Using USDC as collateral
collateralToken,
collateralAmount,
"ExchangeRouter"
);
await approveTokenForContract(
sdk,
"USDC", // Using USDC as collateral
collateralToken,
collateralAmount,
"SyntheticsRouter"
);
console.log('✅ Token allowances verified, proceeding with position opening...');
// Check gas fees before opening position
console.log('⛽ Checking gas fees before opening position...');
const estimatedGasFee = await estimatePositionGasFee(sdk);
@@ -881,6 +909,17 @@ export async function openGmxPosition(
};
}
// Handle approval-specific errors with better messaging
if (error instanceof Error && error.message.includes('Failed to handle token allowance')) {
reply.status(400);
return {
success: false,
error: error.message,
errorType: 'APPROVAL_FAILED',
suggestion: 'Token approval failed. Please ensure you have sufficient funds and try again, or manually approve the GMX contracts to spend your USDC tokens.'
};
}
return handleError(this, reply, error, 'gmx/open-position');
}
}