@iqai/mcp-fraxlend
Version:
Mcp server for Fraxlend access
42 lines • 1.65 kB
JavaScript
import { FRAXLEND_ABI } from "../lib/fraxlend.abi.js";
export class RemoveCollateralService {
walletService;
constructor(walletService) {
this.walletService = walletService;
}
async execute({ pairAddress, amount, }) {
const publicClient = this.walletService.getPublicClient();
const walletClient = this.walletService.getWalletClient();
if (!walletClient) {
throw new Error("Wallet client not initialized");
}
if (!walletClient.account) {
throw new Error("Wallet account not initialized");
}
const userAddress = walletClient.account.address;
const collateralBalance = await publicClient.readContract({
address: pairAddress,
abi: FRAXLEND_ABI,
functionName: "userCollateralBalance",
args: [userAddress],
account: walletClient.account,
});
if (collateralBalance < amount) {
throw new Error(`Insufficient collateral balance. Available: ${collateralBalance}, Requested: ${amount}`);
}
const { request } = await publicClient.simulateContract({
address: pairAddress,
abi: FRAXLEND_ABI,
functionName: "removeCollateral",
args: [amount, userAddress],
account: walletClient.account,
});
const hash = await walletClient.writeContract(request);
const receipt = await publicClient.waitForTransactionReceipt({ hash });
return {
txHash: receipt.transactionHash,
amount,
};
}
}
//# sourceMappingURL=remove-collateral.js.map