UNPKG

pharos-agent-kit

Version:
30 lines 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.approveToken = approveToken; const viem_1 = require("viem"); async function approveToken(agent, tokenAddress, spender, amount) { try { // Check current allowance const allowance = await agent.publicClient.readContract({ address: tokenAddress, abi: viem_1.erc20Abi, functionName: "allowance", args: [agent.wallet_address, spender] }); // If allowance is already sufficient, skip approval if (allowance >= amount) { return; } // Prepare approval transaction await agent.walletClient.writeContract({ address: tokenAddress, abi: viem_1.erc20Abi, functionName: "approve", args: [spender, amount] }); // Using 'as any' to bypass type-checking issues } catch (error) { throw new Error(`Failed to approve token: ${error instanceof Error ? error.message : String(error)}`); } } //# sourceMappingURL=approveTokens.js.map