{"version":3,"sources":["../src/core-tools.ts"],"sourcesContent":["import { formatUnits } from \"viem\";\nimport { z } from \"zod\";\nimport type { Tool, UnwrappedTool } from \"./tool\";\nimport type { WalletClient } from \"./wallets\";\nimport { getChainToken, isEVMWalletClient } from \"./wallets\";\n\nexport const getAddressParametersSchema = z.object({});\n\nexport const getBalanceParametersSchema = z.object({\n    address: z\n        .optional(z.string())\n        .describe(\"The address to get the balance of, defaults to the address of the wallet\"),\n});\n\nexport function getAddress(\n    walletClient: WalletClient,\n    _parameters: z.infer<typeof getAddressParametersSchema>,\n): string {\n    return walletClient.getAddress();\n}\n\nexport async function getBalance(\n    walletClient: WalletClient,\n    parameters: z.infer<typeof getBalanceParametersSchema>,\n): Promise<string> {\n    try {\n        let address: string = parameters.address ?? getAddress(walletClient, {});\n\n        if (isEVMWalletClient(walletClient)) {\n            address = await walletClient.resolveAddress(address);\n        }\n\n        const balance = await walletClient.balanceOf(address.toString());\n\n        return formatUnits(balance.value, balance.decimals);\n    } catch (error) {\n        throw new Error(`Failed to fetch balance: ${error}`);\n    }\n}\n\nexport const unwrappedTools: UnwrappedTool<WalletClient>[] = [\n    {\n        name: \"get_address\",\n        description: \"This {{tool}} returns the address of the wallet.\",\n        parameters: getAddressParametersSchema,\n        method: getAddress,\n    },\n    {\n        name: \"get_balance\",\n        description: \"This {{tool}} returns the {{token}} balance of the wallet.\",\n        parameters: getBalanceParametersSchema,\n        method: getBalance,\n    },\n];\n\nexport function getCoreTools(walletClient: WalletClient): Tool[] {\n    return unwrappedTools.map((tool) => ({\n        ...tool,\n        description: tool.description.replace(\"{{token}}\", getChainToken(walletClient.getChain()).symbol),\n        method: (parameters: z.infer<typeof tool.parameters>) => tool.method(walletClient, parameters),\n    }));\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,mBAAmB;AAC5B,SAAS,SAAS;AAKX,IAAM,6BAA6B,EAAE,OAAO,CAAC,CAAC;AAE9C,IAAM,6BAA6B,EAAE,OAAO;AAAA,EAC/C,SAAS,EACJ,SAAS,EAAE,OAAO,CAAC,EACnB,SAAS,0EAA0E;AAC5F,CAAC;AAEM,SAAS,WACZ,cACA,aACM;AACN,SAAO,aAAa,WAAW;AACnC;AAEA,eAAsB,WAClB,cACA,YACe;AACf,MAAI;AACA,QAAI,UAAkB,WAAW,WAAW,WAAW,cAAc,CAAC,CAAC;AAEvE,QAAI,kBAAkB,YAAY,GAAG;AACjC,gBAAU,MAAM,aAAa,eAAe,OAAO;AAAA,IACvD;AAEA,UAAM,UAAU,MAAM,aAAa,UAAU,QAAQ,SAAS,CAAC;AAE/D,WAAO,YAAY,QAAQ,OAAO,QAAQ,QAAQ;AAAA,EACtD,SAAS,OAAO;AACZ,UAAM,IAAI,MAAM,4BAA4B,KAAK,EAAE;AAAA,EACvD;AACJ;AAEO,IAAM,iBAAgD;AAAA,EACzD;AAAA,IACI,MAAM;AAAA,IACN,aAAa;AAAA,IACb,YAAY;AAAA,IACZ,QAAQ;AAAA,EACZ;AAAA,EACA;AAAA,IACI,MAAM;AAAA,IACN,aAAa;AAAA,IACb,YAAY;AAAA,IACZ,QAAQ;AAAA,EACZ;AACJ;AAEO,SAAS,aAAa,cAAoC;AAC7D,SAAO,eAAe,IAAI,CAAC,UAAU;AAAA,IACjC,GAAG;AAAA,IACH,aAAa,KAAK,YAAY,QAAQ,aAAa,cAAc,aAAa,SAAS,CAAC,EAAE,MAAM;AAAA,IAChG,QAAQ,CAAC,eAAgD,KAAK,OAAO,cAAc,UAAU;AAAA,EACjG,EAAE;AACN;","names":[]}