unwrap_wedu
Convert Wrapped EDU (WEDU) back to EDU on the EDUCHAIN network using your wallet's private key and the specified amount of WEDU.
Instructions
Unwrap WEDU (Wrapped EDU) to EDU
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | Amount of WEDU to unwrap | |
| privateKey | Yes | Private key of the wallet |
Input Schema (JSON Schema)
{
"properties": {
"amount": {
"description": "Amount of WEDU to unwrap",
"type": "string"
},
"privateKey": {
"description": "Private key of the wallet",
"type": "string"
}
},
"required": [
"privateKey",
"amount"
],
"type": "object"
}
Implementation Reference
- src/swap.ts:1088-1139 (handler)Core handler function that executes the unwrap logic: checks WEDU balance, calls withdraw on WETH9 contract, returns transaction details.export async function unwrapWEDU( privateKey: string, amount: string ): Promise<{ hash: string; from: string; amount: string; success: boolean; }> { try { const provider = blockchain.getProvider(); const wallet = new ethers.Wallet(privateKey, provider); const fromAddress = wallet.address; // Convert WEDU amount to wei const amountInWei = ethers.parseEther(amount); // Create WETH9 contract instance const wethAbi = [ 'function deposit() external payable', 'function withdraw(uint256 amount) external', 'function balanceOf(address owner) view returns (uint256)', 'function approve(address spender, uint256 amount) external returns (bool)' ]; const wethContract = new ethers.Contract(CONTRACTS.WETH9, wethAbi, wallet); // Check balance const balance = await wethContract.balanceOf(fromAddress); if (balance < amountInWei) { throw new Error(`Insufficient WEDU balance. You have ${ethers.formatEther(balance)} WEDU, but tried to unwrap ${amount} WEDU.`); } // Withdraw WEDU to get EDU const tx = await wethContract.withdraw(amountInWei); const receipt = await tx.wait(); if (!receipt) { throw new Error('Transaction failed'); } return { hash: tx.hash, from: fromAddress, amount, success: true }; } catch (error) { console.error('Error unwrapping WEDU to EDU:', error); throw error; } }
- src/index.ts:694-710 (schema)Input schema definition for the unwrap_wedu tool, specifying parameters privateKey and amount.name: 'unwrap_wedu', description: 'Unwrap WEDU (Wrapped EDU) to EDU', inputSchema: { type: 'object', properties: { privateKey: { type: 'string', description: 'Private key of the wallet', }, amount: { type: 'string', description: 'Amount of WEDU to unwrap', }, }, required: ['privateKey', 'amount'], }, },
- src/index.ts:1442-1479 (registration)MCP tool registration and dispatch handler: validates inputs, calls swap.unwrapWEDU, formats response with success/error handling.case 'unwrap_wedu': { if (!args.privateKey || typeof args.privateKey !== 'string') { throw new McpError(ErrorCode.InvalidParams, 'Private key is required'); } if (!args.amount || typeof args.amount !== 'string') { throw new McpError(ErrorCode.InvalidParams, 'Amount is required'); } try { const result = await swap.unwrapWEDU(args.privateKey, args.amount); return { content: [ { type: 'text', text: JSON.stringify({ ...result, message: `Successfully unwrapped ${args.amount} WEDU to EDU`, }, null, 2), }, ], }; } catch (error) { console.error('Error unwrapping WEDU to EDU:', error); return { content: [ { type: 'text', text: JSON.stringify({ error: 'Failed to unwrap WEDU to EDU', message: (error as Error).message }, null, 2), }, ], isError: true, }; }