Skip to content

feat: add getBalance and getAccountInfo tools#71

Merged
daiwikmh merged 1 commit into
Stellar-Tools:mainfrom
monafrau24-wq:feat/account-tools
Apr 30, 2026
Merged

feat: add getBalance and getAccountInfo tools#71
daiwikmh merged 1 commit into
Stellar-Tools:mainfrom
monafrau24-wq:feat/account-tools

Conversation

@monafrau24-wq

@monafrau24-wq monafrau24-wq commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

Summary by cubic

Add Stellar account tools to fetch balances and account details, plus AgentClient methods to access them easily. Exposes both tools in stellarTools for use across the app.

  • New Features
    • Added stellar_get_balance and stellar_get_account_info tools. Balance returns XLM and asset balances; account info includes sequence, signers, thresholds (excluding _links and balances).
    • Added AgentClient.getBalance(publicKey?) and AgentClient.getAccountInfo(publicKey?), defaulting to the client’s publicKey. Results return JSON when possible, otherwise a readable error message.
    • Tools validate public keys and support testnet and mainnet. Exported via stellarTools in index.ts.

Written for commit 40bf265. Summary will update on new commits. Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 3 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="tools/stellar.ts">

<violation number="1" location="tools/stellar.ts:97">
P2: Non-native balance formatting assumes `asset_code`/`asset_issuer` always exist, misreporting `liquidity_pool_shares` balances as `undefined:undefined`.</violation>
</file>

<file name="agent.ts">

<violation number="1" location="agent.ts:166">
P2: Using `publicKey || this.publicKey` silently falls back on empty-string input, which can query the wrong account instead of rejecting invalid caller input.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread tools/stellar.ts
};
} else {
return {
asset: `${balance.asset_code}:${balance.asset_issuer}`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Non-native balance formatting assumes asset_code/asset_issuer always exist, misreporting liquidity_pool_shares balances as undefined:undefined.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tools/stellar.ts, line 97:

<comment>Non-native balance formatting assumes `asset_code`/`asset_issuer` always exist, misreporting `liquidity_pool_shares` balances as `undefined:undefined`.</comment>

<file context>
@@ -64,4 +64,82 @@ export const stellarSendPaymentTool = new DynamicStructuredTool({
+          };
+        } else {
+          return {
+            asset: `${balance.asset_code}:${balance.asset_issuer}`,
+            balance: balance.balance,
+          };
</file context>
Suggested change
asset: `${balance.asset_code}:${balance.asset_issuer}`,
asset:
balance.asset_type === "liquidity_pool_shares"
? `LP:${balance.liquidity_pool_id}`
: `${balance.asset_code}:${balance.asset_issuer}`,

Comment thread agent.ts
* @param publicKey Optional Stellar public key (defaults to client's publicKey)
*/
async getBalance(publicKey?: string) {
const targetPublicKey = publicKey || this.publicKey;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Using publicKey || this.publicKey silently falls back on empty-string input, which can query the wrong account instead of rejecting invalid caller input.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At agent.ts, line 166:

<comment>Using `publicKey || this.publicKey` silently falls back on empty-string input, which can query the wrong account instead of rejecting invalid caller input.</comment>

<file context>
@@ -157,6 +158,51 @@ export class AgentClient {
+   * @param publicKey Optional Stellar public key (defaults to client's publicKey)
+   */
+  async getBalance(publicKey?: string) {
+    const targetPublicKey = publicKey || this.publicKey;
+    if (!targetPublicKey) {
+      throw new Error("Public key is required to fetch balance.");
</file context>

@daiwikmh daiwikmh merged commit 67db6ad into Stellar-Tools:main Apr 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants