UNPKG

@coinbase/agentkit

Version:

Coinbase AgentKit core primitives

76 lines (75 loc) 4.05 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.cdpApiActionProvider = exports.CdpApiActionProvider = void 0; const zod_1 = require("zod"); const wallet_providers_1 = require("../../wallet-providers"); const actionDecorator_1 = require("../actionDecorator"); const actionProvider_1 = require("../actionProvider"); const schemas_1 = require("./schemas"); const faucetUtils_1 = require("./faucetUtils"); /** * CdpApiActionProvider is an action provider for CDP API. * * This provider is used for any action that uses the CDP API, but does not require a CDP Wallet. */ class CdpApiActionProvider extends actionProvider_1.ActionProvider { /** * Constructor for the CdpApiActionProvider class. */ constructor() { super("cdp_api", []); /** * Checks if the CDP action provider supports the given network. * * NOTE: Network scoping is done at the action implementation level * * @param _ - The network to check. * @returns True if the CDP action provider supports the network, false otherwise. */ this.supportsNetwork = (_) => true; } /** * Requests test tokens from the faucet for the default address in the wallet. * * @param walletProvider - The wallet provider to request funds from. * @param args - The input arguments for the action. * @returns A confirmation message with transaction details. */ async faucet(walletProvider, args) { const network = walletProvider.getNetwork(); const networkId = network.networkId; const address = walletProvider.getAddress(); const cdpClient = (0, faucetUtils_1.getCdpClient)(walletProvider); (0, faucetUtils_1.validateNetworkSupport)(network, networkId); return network.protocolFamily === "evm" ? (0, faucetUtils_1.handleEvmFaucet)(cdpClient, address, networkId, args) : (0, faucetUtils_1.handleSvmFaucet)(cdpClient, address, args); } } exports.CdpApiActionProvider = CdpApiActionProvider; __decorate([ (0, actionDecorator_1.CreateAction)({ name: "request_faucet_funds", description: `This tool will request test tokens from the faucet for the default address in the wallet. It takes the wallet and asset ID as input. Faucet is only allowed on 'base-sepolia' or 'solana-devnet'. If fauceting on 'base-sepolia', user can only provide asset ID 'eth', 'usdc', 'eurc' or 'cbbtc', if no asset ID is provided, the faucet will default to 'eth'. If fauceting on 'solana-devnet', user can only provide asset ID 'sol' or 'usdc', if no asset ID is provided, the faucet will default to 'sol'. You are not allowed to faucet with any other network or asset ID. If you are on another network, suggest that the user sends you some ETH from another wallet and provide the user with your wallet details.`, schema: schemas_1.RequestFaucetFundsV2Schema, }), __metadata("design:type", Function), __metadata("design:paramtypes", [wallet_providers_1.WalletProvider, void 0]), __metadata("design:returntype", Promise) ], CdpApiActionProvider.prototype, "faucet", null); const cdpApiActionProvider = () => new CdpApiActionProvider(); exports.cdpApiActionProvider = cdpApiActionProvider;