UNPKG

sei-agent-kit

Version:

A package for building AI agents on the SEI blockchain

59 lines 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.unstakeSei = unstakeSei; const stargate_1 = require("@cosmjs/stargate"); const chain_1 = require("../../utils/chain"); const useSeiBridge_1 = require("../../utils/useSeiBridge"); /** * Unstakes SEI tokens from the network * @param agent SeiAgentKit instance * @param amount Amount of SEI to unstake as a string (e.g., "1.5" for 1.5 SEI) * @returns Transaction hash or error message */ async function unstakeSei(agent, amount) { console.log(`Unstaking ${amount} SEI...`); const amountNum = Number(amount); if (Number(await agent.getERC20Balance('0x5cf6826140c1c56ff49c808a1a75407cd1df9423')) < amountNum) { console.log(`Insufficient balance of isei`); throw new Error("Insufficient balance"); } if (isNaN(amountNum) || amountNum <= 0) { const errorMsg = `Invalid unstaking 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"); } if (!chainConfig.contractAddress) { throw new Error("Contract address is missing in chain configuration"); } // Prepare the unstaking parameters const executeMsg = { queue_unbond: {} }; // Convert to micro SEI using BigInt for safety with large numbers const microAmount = BigInt(Math.floor(amountNum * 10 ** 6)); const fundsMsg = (0, stargate_1.coins)(microAmount.toString(), `factory/${chainConfig.contractAddress}/isei`); // 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, }); 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=unstakeBond.js.map