agentlaunch-templates 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generator.js +1 -1
- package/dist/generator.js.map +1 -1
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +2 -0
- package/dist/registry.js.map +1 -1
- package/dist/templates/chat-memory.d.ts +20 -0
- package/dist/templates/chat-memory.d.ts.map +1 -0
- package/dist/templates/chat-memory.js +284 -0
- package/dist/templates/chat-memory.js.map +1 -0
- package/dist/templates/genesis.d.ts.map +1 -1
- package/dist/templates/genesis.js +173 -61
- package/dist/templates/genesis.js.map +1 -1
- package/package.json +1 -1
package/dist/generator.js
CHANGED
|
@@ -478,7 +478,7 @@ function buildAgentlaunchConfig(template, vars) {
|
|
|
478
478
|
export function generateFromTemplate(templateName, variables, options = { variables: {} }) {
|
|
479
479
|
const template = getTemplate(templateName);
|
|
480
480
|
if (!template) {
|
|
481
|
-
const available = ["
|
|
481
|
+
const available = ["chat-memory", "swarm-starter", "custom", "price-monitor", "trading-bot", "data-analyzer", "research", "gifter"];
|
|
482
482
|
throw new Error(`Template "${templateName}" not found. Available templates: ${available.join(", ")}`);
|
|
483
483
|
}
|
|
484
484
|
const strict = options.strict ?? false;
|
package/dist/generator.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,WAAW,EAA6C,MAAM,eAAe,CAAC;AAEvF,8EAA8E;AAC9E,mCAAmC;AACnC,8EAA8E;AAE9E,MAAM,YAAY,GAAG,6BAA6B,CAAC;AACnD,MAAM,WAAW,GAAG,iEAAiE,CAAC;AACtF,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB;IACvD,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,KAAK,CAAC,CAAC,CAAC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AE,QAAQ,CAAC,CAAC;QACpI,MAAM,IAAI,KAAK,CACb,aAAa,YAAY,qCAAqC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CACrF,CAAC;IACJ,CAAC;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC;IACvC,MAAM,QAAQ,GAAG,gBAAgB,CAAC,QAAQ,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;IAEzE,MAAM,IAAI,GAAG,UAAU,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IACjD,MAAM,MAAM,GAAG,WAAW,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC/C,MAAM,UAAU,GAAG,eAAe,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACvD,MAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACnD,MAAM,cAAc,GAAG,mBAAmB,EAAE,CAAC;IAC7C,MAAM,iBAAiB,GAAG,sBAAsB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IACrE,MAAM,gBAAgB,GAAG,qBAAqB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAEnE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,CAAC;AACrG,CAAC"}
|
package/dist/registry.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAeH,MAAM,WAAW,gBAAgB;IAC/B,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mEAAmE;IACnE,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,aAAa;IAC5B,sEAAsE;IACtE,IAAI,EAAE,MAAM,CAAC;IACb,6CAA6C;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,SAAS,EAAE,gBAAgB,EAAE,CAAC;IAC9B,8DAA8D;IAC9D,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,wEAAwE;IACxE,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,4DAA4D;IAC5D,IAAI,EAAE,MAAM,CAAC;CACd;AA+BD;;;GAGG;AACH,wBAAgB,aAAa,IAAI,aAAa,EAAE,CAE/C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAInE;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAQ7D"}
|
package/dist/registry.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* 1. Creating src/templates/<name>.ts exporting `template: AgentTemplate`
|
|
7
7
|
* 2. Importing and adding to TEMPLATES below
|
|
8
8
|
*/
|
|
9
|
+
import { template as chatMemoryTemplate } from "./templates/chat-memory.js";
|
|
9
10
|
import { template as genesisTemplate } from "./templates/genesis.js";
|
|
10
11
|
import { template as customTemplate } from "./templates/custom.js";
|
|
11
12
|
import { template as priceMonitorTemplate } from "./templates/price-monitor.js";
|
|
@@ -17,6 +18,7 @@ import { template as gifterTemplate } from "./templates/gifter.js";
|
|
|
17
18
|
// Internal registry
|
|
18
19
|
// ---------------------------------------------------------------------------
|
|
19
20
|
const TEMPLATES = [
|
|
21
|
+
chatMemoryTemplate, // Base template - recommended starting point
|
|
20
22
|
genesisTemplate,
|
|
21
23
|
customTemplate,
|
|
22
24
|
priceMonitorTemplate,
|
package/dist/registry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,QAAQ,IAAI,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAE,QAAQ,IAAI,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAC5E,OAAO,EAAE,QAAQ,IAAI,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAChF,OAAO,EAAE,QAAQ,IAAI,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,QAAQ,IAAI,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAkCnE,8EAA8E;AAC9E,oBAAoB;AACpB,8EAA8E;AAE9E,MAAM,SAAS,GAAoB;IACjC,eAAe;IACf,cAAc;IACd,oBAAoB;IACpB,kBAAkB;IAClB,oBAAoB;IACpB,gBAAgB;IAChB,cAAc;CACf,CAAC;AAEF;;;;;GAKG;AACH,MAAM,gBAAgB,GAA2B;IAC/C,eAAe,EAAE,SAAS;CAC3B,CAAC;AAEF,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;AACxB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,wDAAwD;IACxD,MAAM,YAAY,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;IACpD,OAAO,SAAS,CAAC,IAA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AACH,MAAM,gBAAgB,GAA2B;IAC/C,eAAe,EAAE,SAAS;CAC3B,CAAC;AAEF,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;GAGG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,CAAC,GAAG,SAAS,CAAC,CAAC;AACxB,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,wDAAwD;IACxD,MAAM,YAAY,GAAG,gBAAgB,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC;IACpD,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,YAAY,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,YAAoB;IACnD,qDAAqD;IACrD,KAAK,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC/D,IAAI,MAAM,KAAK,YAAY,EAAE,CAAC;YAC5B,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IACD,OAAO,YAAY,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* chat-memory.ts — Base template with conversation memory and configurable LLM
|
|
3
|
+
*
|
|
4
|
+
* This is the foundation template for building AI agents on Agentverse.
|
|
5
|
+
* Features:
|
|
6
|
+
* - Conversation memory (persists last N exchanges per user)
|
|
7
|
+
* - Configurable LLM backend (ASI1, OpenRouter, OpenAI, or any compatible API)
|
|
8
|
+
* - Clean Chat Protocol v0.3.0 implementation
|
|
9
|
+
* - Session persistence via ctx.storage
|
|
10
|
+
* - Lazy LLM client initialization (avoids compile-time issues)
|
|
11
|
+
*
|
|
12
|
+
* Compatible LLM providers:
|
|
13
|
+
* - ASI1: https://api.asi1.ai/v1 (default)
|
|
14
|
+
* - OpenRouter: https://openrouter.ai/api/v1
|
|
15
|
+
* - OpenAI: https://api.openai.com/v1
|
|
16
|
+
* - Any OpenAI-compatible endpoint
|
|
17
|
+
*/
|
|
18
|
+
import type { AgentTemplate } from "../registry.js";
|
|
19
|
+
export declare const template: AgentTemplate;
|
|
20
|
+
//# sourceMappingURL=chat-memory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-memory.d.ts","sourceRoot":"","sources":["../../src/templates/chat-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,eAAO,MAAM,QAAQ,EAAE,aAyQtB,CAAC"}
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* chat-memory.ts — Base template with conversation memory and configurable LLM
|
|
3
|
+
*
|
|
4
|
+
* This is the foundation template for building AI agents on Agentverse.
|
|
5
|
+
* Features:
|
|
6
|
+
* - Conversation memory (persists last N exchanges per user)
|
|
7
|
+
* - Configurable LLM backend (ASI1, OpenRouter, OpenAI, or any compatible API)
|
|
8
|
+
* - Clean Chat Protocol v0.3.0 implementation
|
|
9
|
+
* - Session persistence via ctx.storage
|
|
10
|
+
* - Lazy LLM client initialization (avoids compile-time issues)
|
|
11
|
+
*
|
|
12
|
+
* Compatible LLM providers:
|
|
13
|
+
* - ASI1: https://api.asi1.ai/v1 (default)
|
|
14
|
+
* - OpenRouter: https://openrouter.ai/api/v1
|
|
15
|
+
* - OpenAI: https://api.openai.com/v1
|
|
16
|
+
* - Any OpenAI-compatible endpoint
|
|
17
|
+
*/
|
|
18
|
+
export const template = {
|
|
19
|
+
name: "chat-memory",
|
|
20
|
+
description: "AI agent with conversation memory and configurable LLM (ASI1, OpenRouter, OpenAI)",
|
|
21
|
+
category: "AI/ML",
|
|
22
|
+
variables: [
|
|
23
|
+
{ name: "agent_name", required: true, description: "Name of the agent" },
|
|
24
|
+
{
|
|
25
|
+
name: "description",
|
|
26
|
+
required: false,
|
|
27
|
+
default: "AI assistant with conversation memory",
|
|
28
|
+
description: "Short description of what this agent does",
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "system_prompt",
|
|
32
|
+
default: "You are a helpful AI assistant. Be concise and accurate.",
|
|
33
|
+
description: "System prompt that defines the agent's personality and knowledge",
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "llm_base_url",
|
|
37
|
+
default: "https://api.asi1.ai/v1",
|
|
38
|
+
description: "LLM API base URL (ASI1, OpenRouter, OpenAI, or compatible)",
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "llm_model",
|
|
42
|
+
default: "asi1-mini",
|
|
43
|
+
description: "Model name to use (e.g., asi1-mini, gpt-4o-mini, claude-3-haiku)",
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "max_history",
|
|
47
|
+
default: "10",
|
|
48
|
+
description: "Number of conversation exchanges to remember per user",
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "max_tokens",
|
|
52
|
+
default: "1500",
|
|
53
|
+
description: "Maximum tokens in LLM response",
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: "temperature",
|
|
57
|
+
default: "0.7",
|
|
58
|
+
description: "LLM temperature (0.0-1.0, lower = more deterministic)",
|
|
59
|
+
},
|
|
60
|
+
],
|
|
61
|
+
dependencies: ["openai"],
|
|
62
|
+
secrets: ["LLM_API_KEY", "AGENTVERSE_API_KEY"],
|
|
63
|
+
code: `"""
|
|
64
|
+
{{agent_name}} — AI Agent with Conversation Memory
|
|
65
|
+
|
|
66
|
+
{{description}}
|
|
67
|
+
|
|
68
|
+
Built with the chat-memory template.
|
|
69
|
+
Supports ASI1, OpenRouter, OpenAI, or any OpenAI-compatible LLM.
|
|
70
|
+
|
|
71
|
+
Environment variables (set as Agentverse secrets):
|
|
72
|
+
LLM_API_KEY - Your LLM provider API key (required)
|
|
73
|
+
LLM_BASE_URL - API endpoint (default: {{llm_base_url}})
|
|
74
|
+
LLM_MODEL - Model name (default: {{llm_model}})
|
|
75
|
+
SYSTEM_PROMPT - Override the default system prompt
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
from uagents import Agent, Context, Protocol
|
|
79
|
+
from uagents_core.contrib.protocols.chat import (
|
|
80
|
+
ChatMessage, ChatAcknowledgement, TextContent,
|
|
81
|
+
EndSessionContent, chat_protocol_spec
|
|
82
|
+
)
|
|
83
|
+
from datetime import datetime
|
|
84
|
+
import json
|
|
85
|
+
import os
|
|
86
|
+
|
|
87
|
+
agent = Agent()
|
|
88
|
+
chat_proto = Protocol(spec=chat_protocol_spec)
|
|
89
|
+
|
|
90
|
+
# =============================================================================
|
|
91
|
+
# CONFIGURATION
|
|
92
|
+
# =============================================================================
|
|
93
|
+
|
|
94
|
+
CONFIG = {
|
|
95
|
+
"name": "{{agent_name}}",
|
|
96
|
+
"description": "{{description}}",
|
|
97
|
+
"llm_base_url": os.environ.get("LLM_BASE_URL", "{{llm_base_url}}"),
|
|
98
|
+
"llm_model": os.environ.get("LLM_MODEL", "{{llm_model}}"),
|
|
99
|
+
"max_history": {{max_history}},
|
|
100
|
+
"max_tokens": {{max_tokens}},
|
|
101
|
+
"temperature": {{temperature}},
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
DEFAULT_SYSTEM_PROMPT = """{{system_prompt}}"""
|
|
105
|
+
|
|
106
|
+
SYSTEM_PROMPT = os.environ.get("SYSTEM_PROMPT", DEFAULT_SYSTEM_PROMPT)
|
|
107
|
+
|
|
108
|
+
# =============================================================================
|
|
109
|
+
# LLM CLIENT (Lazy initialization)
|
|
110
|
+
# =============================================================================
|
|
111
|
+
|
|
112
|
+
_llm_client = None
|
|
113
|
+
|
|
114
|
+
def get_llm_client():
|
|
115
|
+
"""Get or create LLM client. Lazy init avoids compile-time issues."""
|
|
116
|
+
global _llm_client
|
|
117
|
+
if _llm_client is None:
|
|
118
|
+
from openai import OpenAI
|
|
119
|
+
_llm_client = OpenAI(
|
|
120
|
+
api_key=os.environ.get("LLM_API_KEY", ""),
|
|
121
|
+
base_url=CONFIG["llm_base_url"]
|
|
122
|
+
)
|
|
123
|
+
return _llm_client
|
|
124
|
+
|
|
125
|
+
# =============================================================================
|
|
126
|
+
# CONVERSATION MEMORY
|
|
127
|
+
# =============================================================================
|
|
128
|
+
|
|
129
|
+
def get_session(ctx: Context, sender: str) -> dict:
|
|
130
|
+
"""Get or create session state with conversation history."""
|
|
131
|
+
key = f"session:{sender}"
|
|
132
|
+
data = ctx.storage.get(key)
|
|
133
|
+
if data:
|
|
134
|
+
session = json.loads(data)
|
|
135
|
+
if "history" not in session:
|
|
136
|
+
session["history"] = []
|
|
137
|
+
return session
|
|
138
|
+
return {"history": [], "message_count": 0}
|
|
139
|
+
|
|
140
|
+
def save_session(ctx: Context, sender: str, session: dict):
|
|
141
|
+
"""Persist session state."""
|
|
142
|
+
ctx.storage.set(f"session:{sender}", json.dumps(session))
|
|
143
|
+
|
|
144
|
+
def add_to_history(session: dict, role: str, content: str):
|
|
145
|
+
"""Add message to history, keeping only last MAX_HISTORY exchanges."""
|
|
146
|
+
session["history"].append({"role": role, "content": content})
|
|
147
|
+
max_messages = CONFIG["max_history"] * 2 # user + assistant pairs
|
|
148
|
+
if len(session["history"]) > max_messages:
|
|
149
|
+
session["history"] = session["history"][-max_messages:]
|
|
150
|
+
|
|
151
|
+
# =============================================================================
|
|
152
|
+
# LLM INTERACTION
|
|
153
|
+
# =============================================================================
|
|
154
|
+
|
|
155
|
+
def chat_with_llm(user_message: str, history: list = None) -> str:
|
|
156
|
+
"""
|
|
157
|
+
Send a message to the LLM with conversation history.
|
|
158
|
+
Returns the assistant's response.
|
|
159
|
+
"""
|
|
160
|
+
messages = [{"role": "system", "content": SYSTEM_PROMPT}]
|
|
161
|
+
|
|
162
|
+
if history:
|
|
163
|
+
messages.extend(history)
|
|
164
|
+
|
|
165
|
+
messages.append({"role": "user", "content": user_message})
|
|
166
|
+
|
|
167
|
+
try:
|
|
168
|
+
client = get_llm_client()
|
|
169
|
+
response = client.chat.completions.create(
|
|
170
|
+
model=CONFIG["llm_model"],
|
|
171
|
+
messages=messages,
|
|
172
|
+
max_tokens=CONFIG["max_tokens"],
|
|
173
|
+
temperature=CONFIG["temperature"]
|
|
174
|
+
)
|
|
175
|
+
return response.choices[0].message.content
|
|
176
|
+
|
|
177
|
+
except Exception as e:
|
|
178
|
+
return f"I encountered an error: {str(e)}. Please try again."
|
|
179
|
+
|
|
180
|
+
# =============================================================================
|
|
181
|
+
# RESPONSE HELPERS
|
|
182
|
+
# =============================================================================
|
|
183
|
+
|
|
184
|
+
async def send_text(ctx: Context, sender: str, msg_id: str, text: str, end: bool = False):
|
|
185
|
+
"""Send a text response, optionally ending the session."""
|
|
186
|
+
await ctx.send(sender, ChatMessage(
|
|
187
|
+
timestamp=datetime.now(),
|
|
188
|
+
msg_id=msg_id,
|
|
189
|
+
content=[TextContent(text=text)]
|
|
190
|
+
))
|
|
191
|
+
if end:
|
|
192
|
+
await ctx.send(sender, ChatMessage(
|
|
193
|
+
timestamp=datetime.now(),
|
|
194
|
+
msg_id=msg_id,
|
|
195
|
+
content=[EndSessionContent()]
|
|
196
|
+
))
|
|
197
|
+
|
|
198
|
+
def get_help() -> str:
|
|
199
|
+
"""Return help message."""
|
|
200
|
+
return f"""# {CONFIG["name"]}
|
|
201
|
+
|
|
202
|
+
{CONFIG["description"]}
|
|
203
|
+
|
|
204
|
+
**Commands:**
|
|
205
|
+
- \`help\` — Show this message
|
|
206
|
+
- \`clear\` — Clear conversation history
|
|
207
|
+
- \`status\` — Show session info
|
|
208
|
+
|
|
209
|
+
Just send a message to start chatting!
|
|
210
|
+
"""
|
|
211
|
+
|
|
212
|
+
# =============================================================================
|
|
213
|
+
# CHAT HANDLER
|
|
214
|
+
# =============================================================================
|
|
215
|
+
|
|
216
|
+
@chat_proto.on_message(ChatMessage)
|
|
217
|
+
async def handle_message(ctx: Context, sender: str, msg: ChatMessage):
|
|
218
|
+
"""Main chat handler with conversation memory."""
|
|
219
|
+
ctx.logger.info(f"Message from {sender}")
|
|
220
|
+
|
|
221
|
+
# Extract text from message
|
|
222
|
+
text = ""
|
|
223
|
+
for content in msg.content:
|
|
224
|
+
if hasattr(content, "text"):
|
|
225
|
+
text = content.text.strip()
|
|
226
|
+
break
|
|
227
|
+
|
|
228
|
+
if not text:
|
|
229
|
+
await send_text(ctx, sender, msg.msg_id, "Please send a text message.", end=True)
|
|
230
|
+
return
|
|
231
|
+
|
|
232
|
+
ctx.logger.info(f"Query: {text[:100]}")
|
|
233
|
+
|
|
234
|
+
# Get session with conversation history
|
|
235
|
+
session = get_session(ctx, sender)
|
|
236
|
+
|
|
237
|
+
# Handle commands
|
|
238
|
+
command = text.lower().split()[0] if text else ""
|
|
239
|
+
|
|
240
|
+
if command in {"help", "?", "start", "hello", "hi"}:
|
|
241
|
+
await send_text(ctx, sender, msg.msg_id, get_help(), end=True)
|
|
242
|
+
return
|
|
243
|
+
|
|
244
|
+
if command in {"clear", "reset", "new"}:
|
|
245
|
+
session["history"] = []
|
|
246
|
+
save_session(ctx, sender, session)
|
|
247
|
+
await send_text(ctx, sender, msg.msg_id, "Conversation cleared. Starting fresh!", end=True)
|
|
248
|
+
return
|
|
249
|
+
|
|
250
|
+
if command == "status":
|
|
251
|
+
status = f"""**Session Status**
|
|
252
|
+
- Messages: {session.get('message_count', 0)}
|
|
253
|
+
- History: {len(session.get('history', []))} messages
|
|
254
|
+
- Model: {CONFIG['llm_model']}
|
|
255
|
+
- Provider: {CONFIG['llm_base_url']}
|
|
256
|
+
"""
|
|
257
|
+
await send_text(ctx, sender, msg.msg_id, status, end=True)
|
|
258
|
+
return
|
|
259
|
+
|
|
260
|
+
# Chat with LLM using conversation history
|
|
261
|
+
response = chat_with_llm(text, session.get("history", []))
|
|
262
|
+
|
|
263
|
+
# Save this exchange to history
|
|
264
|
+
add_to_history(session, "user", text)
|
|
265
|
+
add_to_history(session, "assistant", response)
|
|
266
|
+
session["message_count"] = session.get("message_count", 0) + 1
|
|
267
|
+
save_session(ctx, sender, session)
|
|
268
|
+
|
|
269
|
+
await send_text(ctx, sender, msg.msg_id, response, end=True)
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
@chat_proto.on_message(ChatAcknowledgement)
|
|
273
|
+
async def handle_ack(ctx: Context, sender: str, msg: ChatAcknowledgement):
|
|
274
|
+
"""Handle acknowledgements (required by protocol)."""
|
|
275
|
+
ctx.logger.info(f"Ack from {sender}: {msg.acknowledged_msg_id}")
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
agent.include(chat_proto, publish_manifest=True)
|
|
279
|
+
|
|
280
|
+
if __name__ == "__main__":
|
|
281
|
+
agent.run()
|
|
282
|
+
`,
|
|
283
|
+
};
|
|
284
|
+
//# sourceMappingURL=chat-memory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat-memory.js","sourceRoot":"","sources":["../../src/templates/chat-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,MAAM,CAAC,MAAM,QAAQ,GAAkB;IACrC,IAAI,EAAE,aAAa;IACnB,WAAW,EAAE,mFAAmF;IAChG,QAAQ,EAAE,OAAO;IACjB,SAAS,EAAE;QACT,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,mBAAmB,EAAE;QACxE;YACE,IAAI,EAAE,aAAa;YACnB,QAAQ,EAAE,KAAK;YACf,OAAO,EAAE,uCAAuC;YAChD,WAAW,EAAE,2CAA2C;SACzD;QACD;YACE,IAAI,EAAE,eAAe;YACrB,OAAO,EAAE,0DAA0D;YACnE,WAAW,EAAE,kEAAkE;SAChF;QACD;YACE,IAAI,EAAE,cAAc;YACpB,OAAO,EAAE,wBAAwB;YACjC,WAAW,EAAE,4DAA4D;SAC1E;QACD;YACE,IAAI,EAAE,WAAW;YACjB,OAAO,EAAE,WAAW;YACpB,WAAW,EAAE,kEAAkE;SAChF;QACD;YACE,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE,IAAI;YACb,WAAW,EAAE,uDAAuD;SACrE;QACD;YACE,IAAI,EAAE,YAAY;YAClB,OAAO,EAAE,MAAM;YACf,WAAW,EAAE,gCAAgC;SAC9C;QACD;YACE,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE,KAAK;YACd,WAAW,EAAE,uDAAuD;SACrE;KACF;IACD,YAAY,EAAE,CAAC,QAAQ,CAAC;IACxB,OAAO,EAAE,CAAC,aAAa,EAAE,oBAAoB,CAAC;IAC9C,IAAI,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2NP;CACA,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genesis.d.ts","sourceRoot":"","sources":["../../src/templates/genesis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAQpD,eAAO,MAAM,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"genesis.d.ts","sourceRoot":"","sources":["../../src/templates/genesis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAQpD,eAAO,MAAM,QAAQ,EAAE,aAiwCtB,CAAC"}
|
|
@@ -200,17 +200,23 @@ BUSINESS = {
|
|
|
200
200
|
"max_input_length": 5000,
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
#
|
|
204
|
-
|
|
203
|
+
# FETAgentCoin contract ABI — the token IS the bonding curve
|
|
204
|
+
TOKEN_ABI = [
|
|
205
205
|
{"name": "buyTokens", "type": "function",
|
|
206
|
-
"inputs": [{"name": "
|
|
207
|
-
{"name": "
|
|
208
|
-
|
|
206
|
+
"inputs": [{"name": "buyer", "type": "address"},
|
|
207
|
+
{"name": "slippageAmount", "type": "uint256"},
|
|
208
|
+
{"name": "_buyAmount", "type": "uint256"}],
|
|
209
|
+
"outputs": [], "stateMutability": "nonpayable"},
|
|
209
210
|
{"name": "sellTokens", "type": "function",
|
|
210
|
-
"inputs": [{"name": "
|
|
211
|
-
{"name": "tokenAmount", "type": "uint256"},
|
|
212
|
-
{"name": "minFetOut", "type": "uint256"}],
|
|
211
|
+
"inputs": [{"name": "tokenAmount", "type": "uint256"}],
|
|
213
212
|
"outputs": [], "stateMutability": "nonpayable"},
|
|
213
|
+
{"name": "FET_TOKEN", "type": "function",
|
|
214
|
+
"inputs": [], "outputs": [{"name": "", "type": "address"}],
|
|
215
|
+
"stateMutability": "view"},
|
|
216
|
+
{"name": "calculateTokensReceived", "type": "function",
|
|
217
|
+
"inputs": [{"name": "fetAmount", "type": "uint256"}],
|
|
218
|
+
"outputs": [{"name": "", "type": "uint256"}],
|
|
219
|
+
"stateMutability": "view"},
|
|
214
220
|
]
|
|
215
221
|
|
|
216
222
|
ERC20_ABI = [
|
|
@@ -218,6 +224,10 @@ ERC20_ABI = [
|
|
|
218
224
|
"inputs": [{"name": "spender", "type": "address"},
|
|
219
225
|
{"name": "amount", "type": "uint256"}],
|
|
220
226
|
"outputs": [{"name": "", "type": "bool"}], "stateMutability": "nonpayable"},
|
|
227
|
+
{"name": "allowance", "type": "function",
|
|
228
|
+
"inputs": [{"name": "owner", "type": "address"},
|
|
229
|
+
{"name": "spender", "type": "address"}],
|
|
230
|
+
"outputs": [{"name": "", "type": "uint256"}], "stateMutability": "view"},
|
|
221
231
|
{"name": "balanceOf", "type": "function",
|
|
222
232
|
"inputs": [{"name": "account", "type": "address"}],
|
|
223
233
|
"outputs": [{"name": "", "type": "uint256"}], "stateMutability": "view"},
|
|
@@ -230,6 +240,9 @@ ERC20_ABI = [
|
|
|
230
240
|
"outputs": [{"name": "", "type": "bool"}], "stateMutability": "nonpayable"},
|
|
231
241
|
]
|
|
232
242
|
|
|
243
|
+
# Default TFET address on BSC Testnet
|
|
244
|
+
TFET_ADDRESS = "0x304ddf3eE068c53514f782e2341B71A80c8aE3C7"
|
|
245
|
+
|
|
233
246
|
|
|
234
247
|
# ==========================================================================
|
|
235
248
|
# LAYER 1: LOGGER — structured logging with audit trail
|
|
@@ -691,8 +704,13 @@ class HoldingsManager:
|
|
|
691
704
|
|
|
692
705
|
def buy_via_web3(
|
|
693
706
|
self, ctx: Context, token_address: str, fet_amount_wei: int,
|
|
694
|
-
|
|
707
|
+
slippage_percent: int = 5,
|
|
695
708
|
) -> Tuple[bool, str]:
|
|
709
|
+
"""
|
|
710
|
+
Buy tokens on the bonding curve. The token IS the bonding curve.
|
|
711
|
+
|
|
712
|
+
Flow: approve FET -> call buyTokens(buyer, minTokens, fetAmount) on token.
|
|
713
|
+
"""
|
|
696
714
|
try:
|
|
697
715
|
from web3 import Web3
|
|
698
716
|
|
|
@@ -705,32 +723,76 @@ class HoldingsManager:
|
|
|
705
723
|
return False, "Cannot connect to BSC RPC."
|
|
706
724
|
|
|
707
725
|
account = w3.eth.account.from_key(private_key)
|
|
708
|
-
|
|
726
|
+
token_addr = Web3.to_checksum_address(token_address)
|
|
709
727
|
|
|
710
|
-
|
|
711
|
-
return False, self.generate_buy_link(token_address, fet_amount_wei)
|
|
728
|
+
token_contract = w3.eth.contract(address=token_addr, abi=TOKEN_ABI)
|
|
712
729
|
|
|
713
|
-
#
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
730
|
+
# 1. Resolve FET token address from contract (fallback to testnet TFET)
|
|
731
|
+
try:
|
|
732
|
+
fet_addr = token_contract.functions.FET_TOKEN().call()
|
|
733
|
+
except Exception:
|
|
734
|
+
fet_addr = TFET_ADDRESS
|
|
735
|
+
fet_contract = w3.eth.contract(
|
|
736
|
+
address=Web3.to_checksum_address(fet_addr), abi=ERC20_ABI,
|
|
718
737
|
)
|
|
719
|
-
|
|
720
|
-
|
|
738
|
+
|
|
739
|
+
# 2. Check FET balance
|
|
740
|
+
balance = fet_contract.functions.balanceOf(account.address).call()
|
|
741
|
+
if balance < fet_amount_wei:
|
|
742
|
+
return False, (
|
|
743
|
+
f"Insufficient FET. Have {balance}, need {fet_amount_wei}. "
|
|
744
|
+
f"Deficit: {fet_amount_wei - balance}"
|
|
745
|
+
)
|
|
746
|
+
|
|
747
|
+
nonce = w3.eth.get_transaction_count(account.address)
|
|
748
|
+
gas_price = w3.eth.gas_price
|
|
749
|
+
chain_id = w3.eth.chain_id
|
|
750
|
+
|
|
751
|
+
# 3. Approve FET spend on the token contract (if needed)
|
|
752
|
+
allowance = fet_contract.functions.allowance(
|
|
753
|
+
account.address, token_addr,
|
|
754
|
+
).call()
|
|
755
|
+
if allowance < fet_amount_wei:
|
|
756
|
+
approve_tx = fet_contract.functions.approve(
|
|
757
|
+
token_addr, fet_amount_wei,
|
|
758
|
+
).build_transaction({
|
|
759
|
+
"from": account.address, "nonce": nonce,
|
|
760
|
+
"gas": 100000, "gasPrice": gas_price, "chainId": chain_id,
|
|
761
|
+
})
|
|
762
|
+
signed_approve = w3.eth.account.sign_transaction(approve_tx, private_key)
|
|
763
|
+
approve_hash = w3.eth.send_raw_transaction(signed_approve.raw_transaction)
|
|
764
|
+
w3.eth.wait_for_transaction_receipt(approve_hash, timeout=60)
|
|
765
|
+
nonce += 1
|
|
766
|
+
Logger.info(ctx, "FET_APPROVED", {
|
|
767
|
+
"spender": token_address[:12], "amount": fet_amount_wei,
|
|
768
|
+
})
|
|
769
|
+
|
|
770
|
+
# 4. Calculate expected tokens and apply slippage
|
|
771
|
+
expected_tokens = token_contract.functions.calculateTokensReceived(
|
|
772
|
+
fet_amount_wei,
|
|
773
|
+
).call()
|
|
774
|
+
min_tokens = expected_tokens * (100 - slippage_percent) // 100
|
|
775
|
+
|
|
776
|
+
# 5. Buy: buyTokens(buyer, slippageAmount, _buyAmount)
|
|
777
|
+
buy_tx = token_contract.functions.buyTokens(
|
|
778
|
+
account.address, min_tokens, fet_amount_wei,
|
|
721
779
|
).build_transaction({
|
|
722
|
-
"from": account.address,
|
|
723
|
-
"
|
|
724
|
-
"nonce": nonce,
|
|
725
|
-
"gas": 300000,
|
|
726
|
-
"gasPrice": w3.eth.gas_price,
|
|
727
|
-
"chainId": w3.eth.chain_id,
|
|
780
|
+
"from": account.address, "nonce": nonce,
|
|
781
|
+
"gas": 300000, "gasPrice": gas_price, "chainId": chain_id,
|
|
728
782
|
})
|
|
729
|
-
|
|
730
|
-
tx_hash = w3.eth.send_raw_transaction(
|
|
783
|
+
signed_buy = w3.eth.account.sign_transaction(buy_tx, private_key)
|
|
784
|
+
tx_hash = w3.eth.send_raw_transaction(signed_buy.raw_transaction)
|
|
785
|
+
|
|
786
|
+
# 6. Wait for confirmation
|
|
787
|
+
receipt = w3.eth.wait_for_transaction_receipt(tx_hash, timeout=60)
|
|
788
|
+
if receipt.status != 1:
|
|
789
|
+
return False, f"Buy transaction reverted: {tx_hash.hex()}"
|
|
790
|
+
|
|
731
791
|
Logger.info(ctx, "BUY_VIA_WEB3", {
|
|
732
792
|
"token": token_address[:12],
|
|
733
|
-
"
|
|
793
|
+
"fet_spent": fet_amount_wei,
|
|
794
|
+
"expected_tokens": expected_tokens,
|
|
795
|
+
"min_tokens": min_tokens,
|
|
734
796
|
"tx": tx_hash.hex(),
|
|
735
797
|
})
|
|
736
798
|
return True, f"0x{tx_hash.hex()}"
|
|
@@ -738,12 +800,18 @@ class HoldingsManager:
|
|
|
738
800
|
except ImportError:
|
|
739
801
|
return False, self.generate_buy_link(token_address, fet_amount_wei)
|
|
740
802
|
except Exception as e:
|
|
803
|
+
Logger.error(ctx, "BUY_ERROR", str(e))
|
|
741
804
|
return False, str(e)
|
|
742
805
|
|
|
743
806
|
def sell_via_web3(
|
|
744
807
|
self, ctx: Context, token_address: str, token_amount: int,
|
|
745
|
-
bonding_curve_address: str = "",
|
|
746
808
|
) -> Tuple[bool, str]:
|
|
809
|
+
"""
|
|
810
|
+
Sell tokens back to the bonding curve. No approval needed — the token
|
|
811
|
+
contract burns from msg.sender directly.
|
|
812
|
+
|
|
813
|
+
Flow: call sellTokens(tokenAmount) on the token contract.
|
|
814
|
+
"""
|
|
747
815
|
try:
|
|
748
816
|
from web3 import Web3
|
|
749
817
|
|
|
@@ -756,44 +824,33 @@ class HoldingsManager:
|
|
|
756
824
|
return False, "Cannot connect to BSC RPC."
|
|
757
825
|
|
|
758
826
|
account = w3.eth.account.from_key(private_key)
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
if not bonding_curve_address:
|
|
762
|
-
return False, self.generate_sell_link(token_address, token_amount)
|
|
827
|
+
token_addr = Web3.to_checksum_address(token_address)
|
|
763
828
|
|
|
764
|
-
#
|
|
765
|
-
token_contract = w3.eth.contract(
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
).build_transaction({
|
|
772
|
-
"from": account.address,
|
|
773
|
-
"nonce": nonce,
|
|
774
|
-
"gas": 100000,
|
|
775
|
-
"gasPrice": w3.eth.gas_price,
|
|
776
|
-
"chainId": w3.eth.chain_id,
|
|
777
|
-
})
|
|
778
|
-
signed_approve = w3.eth.account.sign_transaction(approve_tx, private_key)
|
|
779
|
-
w3.eth.send_raw_transaction(signed_approve.raw_transaction)
|
|
829
|
+
# 1. Check token balance
|
|
830
|
+
token_contract = w3.eth.contract(address=token_addr, abi=TOKEN_ABI + ERC20_ABI)
|
|
831
|
+
balance = token_contract.functions.balanceOf(account.address).call()
|
|
832
|
+
if balance < token_amount:
|
|
833
|
+
return False, (
|
|
834
|
+
f"Insufficient tokens. Have {balance}, want to sell {token_amount}."
|
|
835
|
+
)
|
|
780
836
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
)
|
|
786
|
-
sell_tx = curve.functions.sellTokens(
|
|
787
|
-
Web3.to_checksum_address(token_address), token_amount, 0
|
|
837
|
+
# 2. Sell: sellTokens(tokenAmount) — no approval needed
|
|
838
|
+
nonce = w3.eth.get_transaction_count(account.address)
|
|
839
|
+
sell_tx = token_contract.functions.sellTokens(
|
|
840
|
+
token_amount,
|
|
788
841
|
).build_transaction({
|
|
789
|
-
"from": account.address,
|
|
790
|
-
"
|
|
791
|
-
"gas": 300000,
|
|
792
|
-
"gasPrice": w3.eth.gas_price,
|
|
842
|
+
"from": account.address, "nonce": nonce,
|
|
843
|
+
"gas": 300000, "gasPrice": w3.eth.gas_price,
|
|
793
844
|
"chainId": w3.eth.chain_id,
|
|
794
845
|
})
|
|
795
846
|
signed_sell = w3.eth.account.sign_transaction(sell_tx, private_key)
|
|
796
847
|
tx_hash = w3.eth.send_raw_transaction(signed_sell.raw_transaction)
|
|
848
|
+
|
|
849
|
+
# 3. Wait for confirmation
|
|
850
|
+
receipt = w3.eth.wait_for_transaction_receipt(tx_hash, timeout=60)
|
|
851
|
+
if receipt.status != 1:
|
|
852
|
+
return False, f"Sell transaction reverted: {tx_hash.hex()}"
|
|
853
|
+
|
|
797
854
|
Logger.info(ctx, "SELL_VIA_WEB3", {
|
|
798
855
|
"token": token_address[:12],
|
|
799
856
|
"amount": token_amount,
|
|
@@ -804,8 +861,63 @@ class HoldingsManager:
|
|
|
804
861
|
except ImportError:
|
|
805
862
|
return False, self.generate_sell_link(token_address, token_amount)
|
|
806
863
|
except Exception as e:
|
|
864
|
+
Logger.error(ctx, "SELL_ERROR", str(e))
|
|
807
865
|
return False, str(e)
|
|
808
866
|
|
|
867
|
+
def get_balances(
|
|
868
|
+
self, ctx: Context, token_address: str = "",
|
|
869
|
+
) -> Dict[str, Any]:
|
|
870
|
+
"""Check wallet BNB, FET, and (optionally) token balances."""
|
|
871
|
+
result: Dict[str, Any] = {"bnb": 0, "fet": 0, "token": 0, "wallet": ""}
|
|
872
|
+
try:
|
|
873
|
+
from web3 import Web3
|
|
874
|
+
|
|
875
|
+
private_key = os.environ.get("BSC_PRIVATE_KEY", "")
|
|
876
|
+
if not private_key:
|
|
877
|
+
return result
|
|
878
|
+
|
|
879
|
+
w3 = Web3(Web3.HTTPProvider(self.BSC_RPC))
|
|
880
|
+
if not w3.is_connected():
|
|
881
|
+
return result
|
|
882
|
+
|
|
883
|
+
account = w3.eth.account.from_key(private_key)
|
|
884
|
+
result["wallet"] = account.address
|
|
885
|
+
|
|
886
|
+
# BNB balance
|
|
887
|
+
result["bnb"] = w3.eth.get_balance(account.address)
|
|
888
|
+
|
|
889
|
+
# FET balance
|
|
890
|
+
try:
|
|
891
|
+
if token_address:
|
|
892
|
+
tc = w3.eth.contract(
|
|
893
|
+
address=Web3.to_checksum_address(token_address), abi=TOKEN_ABI,
|
|
894
|
+
)
|
|
895
|
+
fet_addr = tc.functions.FET_TOKEN().call()
|
|
896
|
+
else:
|
|
897
|
+
fet_addr = TFET_ADDRESS
|
|
898
|
+
fet_contract = w3.eth.contract(
|
|
899
|
+
address=Web3.to_checksum_address(fet_addr), abi=ERC20_ABI,
|
|
900
|
+
)
|
|
901
|
+
result["fet"] = fet_contract.functions.balanceOf(account.address).call()
|
|
902
|
+
except Exception:
|
|
903
|
+
pass
|
|
904
|
+
|
|
905
|
+
# Token balance (if address provided)
|
|
906
|
+
if token_address:
|
|
907
|
+
try:
|
|
908
|
+
token_contract = w3.eth.contract(
|
|
909
|
+
address=Web3.to_checksum_address(token_address), abi=ERC20_ABI,
|
|
910
|
+
)
|
|
911
|
+
result["token"] = token_contract.functions.balanceOf(account.address).call()
|
|
912
|
+
except Exception:
|
|
913
|
+
pass
|
|
914
|
+
|
|
915
|
+
except ImportError:
|
|
916
|
+
pass
|
|
917
|
+
except Exception:
|
|
918
|
+
pass
|
|
919
|
+
return result
|
|
920
|
+
|
|
809
921
|
def get_holdings_summary(self, ctx: Context, token_addresses: List[str]) -> List[Dict]:
|
|
810
922
|
results = []
|
|
811
923
|
for addr in token_addresses:
|
|
@@ -934,7 +1046,7 @@ async def handle_business(
|
|
|
934
1046
|
wallet — WalletManager: get_balance(), get_address(), fund_check()
|
|
935
1047
|
revenue — RevenueTracker: record_income/expense(), get_summary()
|
|
936
1048
|
self_aware — SelfAwareMixin: update(), get_effort_mode(), get_token_summary()
|
|
937
|
-
holdings — HoldingsManager: buy_via_web3(), sell_via_web3(), get_holdings_summary()
|
|
1049
|
+
holdings — HoldingsManager: buy_via_web3(), sell_via_web3(), get_balances(), get_holdings_summary()
|
|
938
1050
|
cache — Cache: get(), set()
|
|
939
1051
|
|
|
940
1052
|
Args:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"genesis.js","sourceRoot":"","sources":["../../src/templates/genesis.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,6FAA6F;AAC7F,MAAM,YAAY,GAAG,6BAA6B,CAAC;AACnD,MAAM,WAAW,GAAG,iEAAiE,CAAC;AACtF,MAAM,gBAAgB,GAAG,OAAO,CAAC,GAAG,CAAC,oBAAoB;IACvD,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,KAAK,KAAK,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC;AAExE,MAAM,CAAC,MAAM,QAAQ,GAAkB;IACrC,IAAI,EAAE,SAAS;IACf,WAAW,EACT,iGAAiG;IACnG,QAAQ,EAAE,iBAAiB;IAC3B,SAAS,EAAE;QACT,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,mBAAmB,EAAE;QACxE;YACE,IAAI,EAAE,aAAa;YACnB,OAAO,EAAE,yBAAyB;YAClC,WAAW,EAAE,2CAA2C;SACzD;QACD;YACE,IA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