sei-agent-kit
Version:
A package for building AI agents on the SEI blockchain
376 lines • 14.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SeiAgentKit = void 0;
const viem_1 = require("viem");
const chains_1 = require("viem/chains");
const accounts_1 = require("viem/accounts");
const tools_1 = require("../tools");
const takara_1 = require("../tools/takara");
const swap_1 = require("../tools/symphony/swap");
const modelProvider_1 = require("./modelProvider");
class SeiAgentKit {
/**
* Creates a new SeiAgentKit instance
* @param private_key The private key for the wallet
* @param provider The model provider to use
*/
constructor(private_key, provider) {
const account = (0, accounts_1.privateKeyToAccount)(private_key);
this.publicClient = (0, viem_1.createPublicClient)({
chain: chains_1.sei,
transport: (0, viem_1.http)()
});
this.wallet_address = account.address;
this.walletClient = (0, viem_1.createWalletClient)({
account,
chain: chains_1.sei,
transport: (0, viem_1.http)()
});
this.token = (0, modelProvider_1.getTokenForProvider)(provider);
}
/**
* Gets the ERC20 token balance
* @param contract_address Optional ERC-20 token contract address. If not provided, gets native SEI balance
* @returns Promise with formatted balance as string
*/
async getERC20Balance(contract_address) {
return (0, tools_1.get_erc20_balance)(this, contract_address);
}
/**
* Transfers SEI tokens or ERC-20 tokens
* @param amount Amount to transfer as a string (e.g., "1.5" for 1.5 tokens)
* @param recipient Recipient address
* @param ticker Optional token ticker (if not provided, transfers native SEI)
* @returns Promise with transaction result
*/
async ERC20Transfer(amount, recipient, ticker) {
return (0, tools_1.erc20_transfer)(this, amount, recipient, ticker);
}
/**
* Gets the ERC721 token balance
* @param tokenAddress The ERC-721 token contract address
* @returns Promise with balance as string
*/
async getERC721Balance(tokenAddress) {
return (0, tools_1.get_erc721_balance)(this, tokenAddress);
}
/**
* Transfers an ERC721 token
* @param amount Deprecated parameter (kept for compatibility)
* @param recipient The recipient address
* @param tokenAddress The ERC-721 token contract address
* @param tokenId The token ID to transfer
* @returns Promise with transaction details or error message
*/
async ERC721Transfer(amount, recipient, tokenAddress, tokenId) {
return (0, tools_1.erc721Transfer)(this, BigInt(amount), recipient, tokenAddress, BigInt(tokenId));
}
/**
* Mints an ERC721 token
* @param recipient The recipient address that will receive the minted token
* @param tokenAddress The ERC-721 token contract address
* @param tokenId The token ID to mint
* @returns Promise with transaction details or error message
*/
async ERC721Mint(recipient, tokenAddress, tokenId) {
return (0, tools_1.erc721Mint)(this, recipient, tokenAddress, tokenId);
}
/**
* Gets a token address from its ticker symbol
* @param ticker The token ticker symbol (e.g., "SEI", "USDC")
* @returns Promise with token address or null if not found
*/
async getTokenAddressFromTicker(ticker) {
return (0, tools_1.getTokenAddressFromTicker)(ticker);
}
/**
* Stakes SEI tokens on the network
* @param amount Amount of SEI to stake as a string (e.g., "1.5" for 1.5 SEI)
* @returns Promise with transaction hash or error message
*/
async stake(amount) {
return (0, tools_1.stakeSei)(this, amount);
}
/**
* Unstakes SEI tokens from the network
* @param amount Amount of SEI to unstake as a string (e.g., "1.5" for 1.5 SEI)
* @returns Promise with transaction hash or error message
*/
async unstake(amount) {
return (0, tools_1.unstakeSei)(this, amount);
}
/**
* Swaps tokens using the Symphony aggregator
* @param amount The amount of tokens to swap as a string (e.g., "1.5")
* @param tokenIn The address of the token to swap from
* @param tokenOut The address of the token to swap to
* @returns Transaction details as a string
*/
async swap(amount, tokenIn, tokenOut) {
return (0, swap_1.swap)(this, amount, tokenIn, tokenOut);
}
// Takara Protocol methods
/**
* Mints tTokens by depositing underlying tokens into the Takara Protocol
* @param ticker The token ticker (e.g., "USDC")
* @param mintAmount The amount to mint in human-readable format
* @returns Transaction hash and expected tToken amount
*/
async mintTakara(ticker, mintAmount) {
return (0, takara_1.mintTakara)(this, { ticker, mintAmount });
}
/**
* Borrows underlying tokens from the Takara Protocol using tTokens as collateral
* @param ticker The token ticker (e.g., "USDC")
* @param borrowAmount The amount to borrow in human-readable format
* @returns Transaction hash and borrowed amount
*/
async borrowTakara(ticker, borrowAmount) {
return (0, takara_1.borrowTakara)(this, { ticker, borrowAmount });
}
/**
* Repays borrowed tokens to the Takara Protocol
* @param ticker The token ticker (e.g., "USDC")
* @param repayAmount The amount to repay in human-readable format, or "MAX" to repay full balance
* @returns Transaction hash and amount repaid
*/
async repayTakara(ticker, repayAmount) {
return (0, takara_1.repayTakara)(this, { ticker, repayAmount });
}
/**
* Redeems tTokens from the Takara Protocol to get underlying tokens back
* @param ticker The token ticker (e.g., "USDC")
* @param redeemAmount The amount to redeem in human-readable format, or "MAX" to redeem all
* @param redeemType Whether to redeem underlying tokens or tTokens
* @returns Transaction details and redemption status
*/
async redeemTakara(ticker, redeemAmount, redeemType = 'underlying') {
return (0, takara_1.redeemTakara)(this, { ticker, redeemAmount, redeemType });
}
/**
* Calculates the amount of underlying tokens that can be redeemed by a user
* @param ticker The token ticker (e.g., "USDC")
* @param userAddress Optional address of the user to check
* @returns Information about redeemable amounts
*/
async getRedeemableAmount(ticker, userAddress) {
const tTokenAddress = (0, takara_1.getTakaraTTokenAddress)(ticker);
if (!tTokenAddress) {
throw new Error(`No Takara tToken found for ticker: ${ticker}`);
}
return (0, takara_1.getRedeemableAmount)(this, tTokenAddress, userAddress);
}
/**
* Retrieves the current borrow balance for a user
* @param ticker The token ticker (e.g., "USDC")
* @param userAddress Optional address of the user to check
* @returns Information about the borrow balance
*/
async getBorrowBalance(ticker, userAddress) {
const tTokenAddress = (0, takara_1.getTakaraTTokenAddress)(ticker);
if (!tTokenAddress) {
throw new Error(`No Takara tToken found for ticker: ${ticker}`);
}
return (0, takara_1.getBorrowBalance)(this, tTokenAddress, userAddress);
}
/**
* Posts a tweet to Twitter
* @param tweet The tweet to post
* @returns Transaction hash and tweet details
*/
async postTweet(tweet) {
return (0, tools_1.postTweet)(tweet);
}
/**
* Retrieves details about the authenticated user's Twitter account
* @returns Account details as a string
*/
async getAccountDetails() {
return (0, tools_1.getAccountDetails)();
}
/**
* Retrieves mentions for the authenticated user's Twitter account
* @returns Mentions as a string
*/
async getAccountMentions(args) {
return (0, tools_1.getAccountMentions)(args);
}
/**
* Posts a reply to a tweet on Twitter
* @param args The arguments for posting a reply
* @returns Transaction hash and reply details
*/
async postTweetReply(args) {
return (0, tools_1.postTweetReply)(args);
}
// Citrex Protocol methods
/**
* Deposits USDC tokens into the Citrex Protocol
* @param amount The amount of USDC to deposit as a string (e.g., "1.5" for 1.5 USDC)
* @returns Promise with transaction hash or error message
*/
async citrexDeposit(amount) {
return (0, tools_1.citrexDeposit)(amount);
}
/**
* Withdraws USDC tokens from the Citrex Protocol
* @param amount The amount of USDC to withdraw as a string (e.g., "1.5" for 1.5 USDC)
* @returns Promise with transaction hash or error message
*/
async citrexWithdraw(amount) {
return (0, tools_1.citrexWithdraw)(amount);
}
/**
* Retrieves all products from the Citrex Protocol
* @returns Promise with products or error message
*/
async citrexGetProducts() {
return (0, tools_1.citrexGetProducts)();
}
/**
* Retrieves the order book for a product from the Citrex Protocol
* @param symbol The symbol of the product (e.g., "ethperp")
* @returns Promise with order book or error message
*/
async citrexGetOrderBook(symbol) {
return (0, tools_1.citrexGetOrderBook)(symbol);
}
/**
* Retrieves the account health for the Citrex Protocol
* @returns Promise with account health or error message
*/
async citrexGetAccountHealth() {
return (0, tools_1.citrexGetAccountHealth)();
}
/**
* Retrieves the tickers for the Citrex Protocol
* @returns Promise with tickers or error message
*/
async citrexGetTickers(symbol) {
if (symbol) {
return (0, tools_1.citrexGetTickers)(symbol);
}
else {
return (0, tools_1.citrexGetTickers)();
}
}
/**
* Calculates the required margin for a new order on Citrex Protocol
* @param isBuy Whether to buy (true) or sell (false)
* @param price The price of the asset for the order
* @param productId The product ID of the asset
* @param quantity The quantity of the asset to order
* @returns Promise with the required margin calculation result
*/
async citrexCalculateMarginRequirement(isBuy, price, productId, quantity) {
return (0, tools_1.citrexCalculateMarginRequirement)(isBuy, price, productId, quantity);
}
/**
* Retrieves K-line (candlestick) chart data for a product on Citrex Protocol
* @param productSymbol The product symbol (e.g., 'btcperp', 'ethperp')
* @param optionalArgs Optional arguments for the query
* @returns Promise with K-line data
*/
async citrexGetKlines(productSymbol, optionalArgs) {
return (0, tools_1.citrexGetKlines)(productSymbol, optionalArgs);
}
/**
* Retrieves information about a specific product on Citrex Protocol
* @param identifier The product ID or symbol
* @returns Promise with product information
*/
async citrexGetProduct(identifier) {
return (0, tools_1.citrexGetProduct)(identifier);
}
/**
* Retrieves the current server time from Citrex Protocol
* @returns Promise with server time information
*/
async citrexGetServerTime() {
return (0, tools_1.citrexGetServerTime)();
}
/**
* Retrieves trade history for a product on Citrex Protocol
* @param productSymbol The product symbol (e.g., 'btcperp', 'ethperp')
* @param quantity Optional number of trades to fetch
* @returns Promise with trade history data
*/
async citrexGetTradeHistory(productSymbol, quantity) {
return (0, tools_1.citrexGetTradeHistory)(productSymbol, quantity);
}
/**
* Cancels and replaces an order on Citrex Protocol
* @param orderId The unique ID of the order to replace
* @param orderArgs The new order arguments
* @returns Promise with the new order information
*/
async citrexCancelAndReplaceOrder(orderId, orderArgs) {
return (0, tools_1.citrexCancelAndReplaceOrder)(orderId, orderArgs);
}
/**
* Cancels all open orders for a specific product on Citrex Protocol
* @param productId The product ID to cancel orders for
* @returns Promise with cancellation status
*/
async citrexCancelOpenOrdersForProduct(productId) {
return (0, tools_1.citrexCancelOpenOrdersForProduct)(productId);
}
/**
* Cancels a specific order on Citrex Protocol
* @param orderId The unique ID of the order to cancel
* @param productId The product ID of the order
* @returns Promise with cancellation status
*/
async citrexCancelOrder(orderId, productId) {
return (0, tools_1.citrexCancelOrder)(orderId, productId);
}
/**
* Cancels multiple orders on Citrex Protocol
* @param ordersArgs Array of [orderId, productId] pairs to cancel
* @returns Promise with array of cancellation statuses
*/
async citrexCancelOrders(ordersArgs) {
return (0, tools_1.citrexCancelOrders)(ordersArgs);
}
/**
* Lists all margin balances for the account on Citrex Protocol
* @returns Promise with balance information
*/
async citrexListBalances() {
return (0, tools_1.citrexListBalances)();
}
/**
* Lists all open orders for the account on Citrex Protocol
* @param productSymbol Optional product symbol to filter by
* @returns Promise with open orders information
*/
async citrexListOpenOrders(productSymbol) {
return (0, tools_1.citrexListOpenOrders)(productSymbol);
}
/**
* Lists all positions for the account on Citrex Protocol
* @param productSymbol Optional product symbol to filter by
* @returns Promise with positions information
*/
async citrexListPositions(productSymbol) {
return (0, tools_1.citrexListPositions)(productSymbol);
}
/**
* Places an order on Citrex Protocol
* @param orderArgs The order arguments
* @returns Promise with order information
*/
async citrexPlaceOrder(orderArgs) {
return (0, tools_1.citrexPlaceOrder)(orderArgs);
}
/**
* Places multiple orders on Citrex Protocol
* @param ordersArgs Array of order arguments
* @returns Promise with array of order information
*/
async citrexPlaceOrders(ordersArgs) {
return (0, tools_1.citrexPlaceOrders)(ordersArgs);
}
}
exports.SeiAgentKit = SeiAgentKit;
//# sourceMappingURL=index.js.map