pharos-agent-kit
Version:
Connect AI Agents to Pharos protocols
130 lines • 5.41 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.PharosAgentKit = void 0;
const viem_1 = require("viem");
const accounts_1 = require("viem/accounts");
const network_1 = require("../network/network");
const tools_1 = require("../tools");
const constants_1 = require("../tools/defillama/constants");
const wallet_providers_1 = require("../wallet-providers");
/**
* Main class for interacting with Pharos blockchain
* Provides a unified interface for token operations, NFT management, trading and more
*
* @class PharosAgentKit
* @property {PublicClient} connection - Pharos RPC connection
* @property {PharosWalletProvider} wallet - Wallet provider for signing transactions
* @property {Address} wallet_address - Address of the wallet
* @property {Config} config - Configuration object
*/
class PharosAgentKit {
constructor(private_key, rpc_url, config) {
this.rpcUrl = rpc_url;
this.connection = (0, viem_1.createPublicClient)({
chain: network_1.pharosDevnet,
transport: (0, viem_1.http)(rpc_url),
});
this.publicClient = this.connection;
this.wallet_address = (0, accounts_1.privateKeyToAccount)(private_key).address;
this.privateKey = private_key;
const account = (0, accounts_1.privateKeyToAccount)(process.env.PHAROS_PRIVATE_KEY);
const client = (0, viem_1.createWalletClient)({
account,
chain: network_1.pharosDevnet,
transport: (0, viem_1.http)()
});
this.walletClient = client;
this.wallet = new wallet_providers_1.ViemWalletProvider(client);
this.config = config;
}
async getBalance(token_address) {
const balance = await (0, tools_1.get_erc20_balance)(this, token_address);
return Number(balance);
}
async transfer(to, amount, mint) {
return (0, tools_1.transfer)(this, amount.toString(), to, mint);
}
async fetchTokenPriceByChainId(tokenAddr, chainId) {
const chainSlug = constants_1.DEFILLAMA_NETWORK_MAPPING[chainId];
const chainTokenIdentifier = `${chainSlug}:${tokenAddr}`;
return (0, tools_1.fetchPrices)({
chainTokenAddrStrings: [chainTokenIdentifier],
});
}
async fetchTokenPriceByChainSlug(tokenAddr, chainSlug) {
const chainTokenIdentifier = `${chainSlug}:${tokenAddr}`;
return (0, tools_1.fetchPrices)({
chainTokenAddrStrings: [chainTokenIdentifier],
});
}
async fetchTokenPrices(chainTokenIdentifiers) {
return (0, tools_1.fetchPrices)({
chainTokenAddrStrings: chainTokenIdentifiers,
});
}
async fetchProtocolTvl(slug) {
return (0, tools_1.getProtocolTvl)(slug);
}
async getCoingeckoLatestPools() {
return await (0, tools_1.getLatestPools)(this);
}
async getTokenPriceDataUsingCoingecko(...tokenAddresses) {
return await (0, tools_1.getTokenPriceData)(this, tokenAddresses);
}
async getTopGainersOnCoingecko(duration, noOfCoins) {
return await (0, tools_1.getTopGainers)(this, duration, noOfCoins);
}
async getCoingeckoTrendingPools(duration) {
return await (0, tools_1.getTrendingPools)(this, duration);
}
async getTrendingTokensOnCoingecko() {
return await (0, tools_1.getTrendingTokens)(this);
}
async getTrendingTokens() {
const response = await (0, tools_1.getTrendingTokens)(this);
return response;
}
async getTrendingTokensUsingElfaAi() {
const response = await (0, tools_1.getTrendingTokensUsingElfaAi)(this);
return response;
}
async pingElfaAiApi() {
const response = await (0, tools_1.pingElfaAiApi)(this);
return response;
}
async getElfaAiApiKeyStatus() {
const response = await (0, tools_1.getElfaAiApiKeyStatus)(this);
return response;
}
async getSmartMentions(limit = 100, offset = 0) {
const response = await (0, tools_1.getSmartMentions)(this, limit, offset);
return response;
}
async getSmartTwitterAccountStats(username) {
const response = await (0, tools_1.getSmartTwitterAccountStats)(this, username);
return response;
}
async getTopMentionsByTicker(ticker, timeWindow = "1h", page = 1, pageSize = 10, includeAccountDetails = false) {
const response = await (0, tools_1.getTopMentionsByTicker)(this, ticker, timeWindow, page, pageSize, includeAccountDetails);
return response;
}
async searchMentionsByKeywords(keywords, from, to, limit = 20) {
const response = await (0, tools_1.searchMentionsByKeywords)(this, keywords, from, to, limit);
return response;
}
async getERC721Balance(token_address) {
const balance = await (0, tools_1.get_erc721_balance)(this, token_address);
return balance;
}
async transferERC721(to, amount, tokenAddress, tokenId) {
return (0, tools_1.erc721Transfer)(this, BigInt(amount), to, tokenAddress, BigInt(tokenId));
}
async mintERC721(to, tokenAddress, tokenId) {
return (0, tools_1.erc721Mint)(this, to, tokenAddress, tokenId);
}
async getTokenDataByTicker(ticker) {
return (0, tools_1.getTokenDataByTicker)(ticker);
}
}
exports.PharosAgentKit = PharosAgentKit;
//# sourceMappingURL=index.js.map