-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
36 lines (28 loc) · 1.04 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import "dotenv/config";
import express, { Request, Response } from "express";
import { swapToken } from "./controllers/walletController";
const app = express();
const PORT = process.env.PORT || 5000;
app.use(express.json());
/**
* @route POST /swapToken
* @desc Swap tokens using the `swapToken` function
* @access Public
*/
app.post("/swapToken", async (req: Request, res: Response): Promise<void> => {
const { inputMint, outputMint, amount, slippageBps } = req.body;
if (!inputMint || !outputMint || !amount || !slippageBps) {
res.status(400).json({ error: "Missing required fields." });
return;
}
try {
await swapToken(inputMint, outputMint, parseFloat(amount), parseFloat(slippageBps));
res.status(200).json({ message: "Swap executed successfully." });
} catch (err) {
console.error("Error during token swap:", err);
res.status(500).json({ error: "Failed to execute swap.", details: err || "Unknown error" });
}
});
app.listen(PORT, () => {
console.log(`Server is running on http://localhost:${PORT}`);
});