UNPKG

sei-agent-kit

Version:

A package for building AI agents on the SEI blockchain

63 lines 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.stakeSei = stakeSei; const stargate_1 = require("@cosmjs/stargate"); const chain_1 = require("../../utils/chain"); const useSeiBridge_1 = require("../../utils/useSeiBridge"); /** * Stakes SEI tokens on the network * @param agent SeiAgentKit instance * @param amount Amount of SEI to stake as a string (e.g., "1.5" for 1.5 SEI) * @returns Transaction hash or error message */ async function stakeSei(agent, amount) { console.log(`Staking ${amount} SEI...`); const amountNum = Number(amount); if (Number(await agent.getERC20Balance()) < amountNum) { console.log(`Insufficient balance of sei`); throw new Error("Insufficient balance"); } if (isNaN(amountNum) || amountNum <= 0) { const errorMsg = `Invalid staking amount: ${amount}. Amount must be a positive number.`; throw new Error(errorMsg); } try { // Get the chain config for the desired network const chainConfig = (0, chain_1.getChainConfig)('mainnet'); if (!chainConfig) { throw new Error("Failed to get chain configuration for mainnet"); } // Prepare the staking parameters const executeMsg = { bond: {} }; // Convert to micro SEI (1 SEI = 10^6 usei) const microAmount = amountNum * 10 ** 6; if (!Number.isFinite(microAmount)) { throw new Error(`Amount conversion to micro SEI resulted in invalid value: ${microAmount}`); } const fundsMsg = (0, stargate_1.coins)(microAmount, 'usei'); if (!fundsMsg) { throw new Error("Failed to create coins message"); } // Execute the transaction using the agent's private key if (!useSeiBridge_1.seiBridge) { throw new Error("SEI bridge utility is not available"); } const tx_hash = await (0, useSeiBridge_1.seiBridge)({ agent, executeMsg, fundsMsg, chainConfig, amount, }); if (!tx_hash) { throw new Error("Transaction was executed but no hash was returned"); } return tx_hash; } catch (error) { const errorMsg = error instanceof Error ? error?.message : String(error); console.error(errorMsg); throw error; } } //# sourceMappingURL=stakeBond.js.map