Skip to content

Commit 4e4f832

Browse files
authored
feat: update agents functions (#20)
1 parent 4d214b5 commit 4e4f832

File tree

9 files changed

+37
-12
lines changed

9 files changed

+37
-12
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ npm-debug.log*
1919
yarn-debug.log*
2020
yarn-error.log*
2121
pnpm-debug.log*
22+
packages/sui-agent/src/examples/
2223

2324
# local env files
2425
.env

apps/web/.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ PORT=2512
33

44
# Atoma SDK Configuration
55
# Get your bearer token from https://atoma.network
6-
ATOMASDK_BEARER_AUTH=your_bearer_token_here
6+
ATOMASDK_BEARER_AUTH=
77
# Specify the Atoma chat model to use
88
ATOMA_CHAT_COMPLETIONS_MODEL=meta-llama/Llama-3.3-70B-Instruct

packages/sui-agent/src/@types/interface.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ export const COIN_SYNONYMS: Record<string, string> = {
119119
// AI and variants
120120
AI: 'AI',
121121
AICOIN: 'AI',
122+
// WSB and variants
123+
WSB: 'WSB',
124+
WSBCOIN: 'WSB',
122125
} as const;
123126

124127
// Mapping of coin symbols to their respective addresses on the Sui network
@@ -158,6 +161,7 @@ export const COIN_ADDRESSES = {
158161
SUIAI:
159162
'0x8f6808fcea9d5143e6d1577822fd49e783cb5ad2be042f4295e7fe2d5cb10b31::suiai::SUIAI',
160163
AI: '0x089de9a53ffd1f9252cf97e32e11b9a242f813e34227362b674b963468ec6620::ai::AI',
164+
WSB: '0x4db126eac4fa99207e98db61d968477021fdeae153de3b244bcfbdc468ef0722::wsb::WSB',
161165
} as const;
162166

163167
// Information about a liquidity pool

packages/sui-agent/src/agents/SuiAgent.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IntentAgentResponse } from '../@types/interface';
2-
import Tools from '../tools/aftermath';
2+
import Tools from '../utils/tools';
33
import { registerAllTools } from './ToolRegistry';
44
import Utils from '../utils';
55
import intent_agent_prompt from '../prompts/intent_agent_prompt';

packages/sui-agent/src/agents/ToolRegistry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Tools from '../tools/aftermath';
1+
import Tools from '../utils/tools';
22
import { getCoinPrice, coinsToPrice } from '../tools/aftermath/PriceTool';
33
import { getTokenAPR } from '../tools/aftermath/apr';
44
import {

packages/sui-agent/src/tools/aftermath/TradeTool.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,38 @@ async function findTokensInPool(
2222
console.log('Available tokens:', availableTokens);
2323
console.log('Looking for tokens:', { coinInType, coinOutType });
2424

25-
// Find matching tokens (case-insensitive and partial match)
25+
// Find matching tokens (case-insensitive and handle both full addresses and short names)
2626
const findToken = (searchToken: string) => {
27-
return availableTokens.find((token) =>
28-
token.toLowerCase().includes(searchToken.toLowerCase()),
27+
// If it's a full address, try exact match first
28+
const exactMatch = availableTokens.find(
29+
(token) => token.toLowerCase() === searchToken.toLowerCase(),
2930
);
31+
if (exactMatch) return exactMatch;
32+
33+
// For short names like 'SUI' or 'WSB', look for them in the token addresses
34+
return availableTokens.find((token) => {
35+
// Normalize the token string to handle malformed addresses
36+
const normalizedToken = token.replace(/:{2,}/g, '::').toLowerCase();
37+
const parts = normalizedToken.split('::');
38+
39+
// Get the token name (last part) and clean it
40+
const tokenName = parts[parts.length - 1];
41+
const searchName = searchToken.toLowerCase();
42+
43+
return (
44+
tokenName === searchName ||
45+
tokenName.includes(searchName) ||
46+
searchName.includes(tokenName)
47+
);
48+
});
3049
};
3150

3251
const matchedCoinIn = findToken(coinInType);
3352
const matchedCoinOut = findToken(coinOutType);
3453

3554
if (!matchedCoinIn || !matchedCoinOut) {
3655
throw new Error(
37-
`Tokens not found in pool. Available tokens: ${availableTokens.join(
38-
', ',
39-
)}`,
56+
`Tokens not found in pool. Available tokens: ${availableTokens.join(', ')}`,
4057
);
4158
}
4259

packages/sui-agent/src/transactions/TransactionTool.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ export async function buildTransferTx(
6161
): Promise<TransactionBlock> {
6262
const tx = new TransactionBlock();
6363

64+
// Set gas budget
65+
tx.setGasBudget(2000000);
66+
6467
// Get coins owned by sender
6568
const coins = await client.getCoins({
6669
owner: fromAddress,

packages/sui-agent/src/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { randomUUID } from 'crypto';
22
import { AtomaSDK } from 'atoma-sdk';
33
import { atomaChat } from '../config/atoma';
4-
import Tools from '../tools/aftermath';
4+
import Tools from './tools';
55
import { ToolArgument } from '../@types/interface';
66

77
/**

packages/sui-agent/src/tools/aftermath/index.ts renamed to packages/sui-agent/src/utils/tools.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Tool, toolResponse } from '../../@types/interface';
2-
import { atomaChat } from '../../config/atoma';
1+
import { Tool, toolResponse } from '../@types/interface';
2+
import { atomaChat } from '../config/atoma';
33
import { AtomaSDK } from 'atoma-sdk';
44

55
/**

0 commit comments

Comments
 (0)