aptai-sdk 1.0.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.
Potentially problematic release.
This version of aptai-sdk might be problematic. Click here for more details.
- package/.cache/nix/binary-cache-v6.sqlite +0 -0
- package/.cache/nix/binary-cache-v6.sqlite-journal +0 -0
- package/.cache/replit/__replit_disk_meta.json +1 -0
- package/.cache/replit/env/latest +121 -0
- package/.cache/replit/env/latest.json +1 -0
- package/.cache/replit/modules/nodejs-20.res +1 -0
- package/.cache/replit/modules/replit.res +1 -0
- package/.cache/replit/modules.stamp +0 -0
- package/.cache/replit/nix/env.json +1 -0
- package/.cache/replit/toolchain.json +1 -0
- package/.cache/typescript/5.0/package-lock.json +17 -0
- package/.cache/typescript/5.0/package.json +1 -0
- package/.cache/typescript/5.3/package-lock.json +107 -0
- package/.cache/typescript/5.3/package.json +1 -0
- package/.cache/typescript/5.4/package-lock.json +17 -0
- package/.cache/typescript/5.4/package.json +1 -0
- package/.cache/typescript/5.6/package-lock.json +863 -0
- package/.cache/typescript/5.6/package.json +1 -0
- package/.replit +29 -0
- package/.upm/store.json +1 -0
- package/README.md +182 -0
- package/__tests__/aptai.test.js +33 -0
- package/aptai.js +378 -0
- package/attached_assets/Pasted--AptAI-AI-Powered-DeFi-NFT-Toolkit-for-Aptos-AptAI-is-a-powerful-Python-library-that-merges-1742026209933.txt +104 -0
- package/attached_assets/Pasted-import-requests-from-groq-import-Groq-Fixed-Groq-API-Key-GROQ-API-KEY-gsk-kfZpsNGp7lRPe2-1742025546567.txt +497 -0
- package/generated-icon.png +0 -0
- package/index.js +3 -0
- package/package.json +44 -0
- package/replit.nix +3 -0
- package/telegram.js +218 -0
@@ -0,0 +1 @@
|
|
1
|
+
{"private":true,"dependencies":{"types-registry":"^0.1.711"},"devDependencies":{"@types/jest":"^29.5.14","@types/node-telegram-bot-api":"^0.64.7"}}
|
package/.replit
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
entrypoint = "index.js"
|
2
|
+
modules = ["nodejs-20"]
|
3
|
+
hidden = [".config", "package-lock.json"]
|
4
|
+
|
5
|
+
[gitHubImport]
|
6
|
+
requiredFiles = [".replit", "replit.nix", "package.json", "package-lock.json"]
|
7
|
+
|
8
|
+
[nix]
|
9
|
+
channel = "stable-24_05"
|
10
|
+
|
11
|
+
[unitTest]
|
12
|
+
language = "nodejs"
|
13
|
+
|
14
|
+
[deployment]
|
15
|
+
run = ["sh", "-c", "node telegram.js"]
|
16
|
+
deploymentTarget = "cloudrun"
|
17
|
+
ignorePorts = false
|
18
|
+
|
19
|
+
[workflows]
|
20
|
+
runButton = "Start Telegram Bot"
|
21
|
+
|
22
|
+
[[workflows.workflow]]
|
23
|
+
name = "Start Telegram Bot"
|
24
|
+
author = 40513883
|
25
|
+
mode = "sequential"
|
26
|
+
|
27
|
+
[[workflows.workflow.tasks]]
|
28
|
+
task = "shell.exec"
|
29
|
+
args = "node telegram.js"
|
package/.upm/store.json
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":2,"languages":{"nodejs-npm":{"specfileHash":"6d1cd3c6b6d0ba5e053a6d4cbc2ee3dc","lockfileHash":"d22b63667e61c515ff04a670fd976c8e"}}}
|
package/README.md
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
|
2
|
+
# 🔥 Teck Model - Advanced Aptos Blockchain AI
|
3
|
+
|
4
|
+
A comprehensive AI-powered SDK for Aptos blockchain with advanced DeFi analytics and NFT tracking capabilities.
|
5
|
+
|
6
|
+
## 🚀 Features
|
7
|
+
|
8
|
+
- **Real-time Token Analytics**
|
9
|
+
- Price tracking across multiple DEXes
|
10
|
+
- Market cap and volume analysis
|
11
|
+
- Liquidity monitoring
|
12
|
+
- Verified pair detection
|
13
|
+
|
14
|
+
- **NFT Analytics**
|
15
|
+
- Collection statistics
|
16
|
+
- Floor price tracking
|
17
|
+
- Volume analysis
|
18
|
+
- Multi-marketplace support
|
19
|
+
|
20
|
+
- **Wallet Management**
|
21
|
+
- Create new wallets
|
22
|
+
- Balance checking
|
23
|
+
- Token transfers
|
24
|
+
- Transaction history
|
25
|
+
|
26
|
+
- **Market Analysis**
|
27
|
+
- Holder distribution
|
28
|
+
- Transaction patterns
|
29
|
+
- Price predictions
|
30
|
+
- Market sentiment
|
31
|
+
|
32
|
+
- **AI Integration**
|
33
|
+
- Groq LLM integration
|
34
|
+
- Market insights
|
35
|
+
- Trading suggestions
|
36
|
+
- Risk analysis
|
37
|
+
|
38
|
+
## 💻 Installation
|
39
|
+
|
40
|
+
```bash
|
41
|
+
npm install aptai
|
42
|
+
```
|
43
|
+
|
44
|
+
## 📚 Usage Guide
|
45
|
+
|
46
|
+
### 1. Basic Setup
|
47
|
+
|
48
|
+
```javascript
|
49
|
+
const { AptAi } = require('aptai');
|
50
|
+
|
51
|
+
// Initialize SDK with your Groq API key
|
52
|
+
const ai = new AptAi({
|
53
|
+
groqApiKey: 'your_groq_api_key'
|
54
|
+
});
|
55
|
+
```
|
56
|
+
|
57
|
+
### 2. Token Analysis
|
58
|
+
|
59
|
+
```javascript
|
60
|
+
// Get token price and market data
|
61
|
+
const tokenInfo = await ai.getPrice('aptos');
|
62
|
+
console.log(tokenInfo);
|
63
|
+
/*
|
64
|
+
{
|
65
|
+
name: 'Aptos',
|
66
|
+
symbol: 'APT',
|
67
|
+
price: 10.50,
|
68
|
+
price_change_24h: 2.5,
|
69
|
+
volume24h: 1000000,
|
70
|
+
market_cap: 50000000,
|
71
|
+
dex: {
|
72
|
+
name: 'PancakeSwap',
|
73
|
+
verified: true
|
74
|
+
}
|
75
|
+
}
|
76
|
+
*/
|
77
|
+
|
78
|
+
// Get detailed token analysis
|
79
|
+
const analysis = await ai.analyzeTokenMetrics('token_address');
|
80
|
+
console.log(analysis);
|
81
|
+
```
|
82
|
+
|
83
|
+
### 3. Wallet Operations
|
84
|
+
|
85
|
+
```javascript
|
86
|
+
// Create new wallet
|
87
|
+
const wallet = await ai.createWallet();
|
88
|
+
/*
|
89
|
+
{
|
90
|
+
address: '0x...',
|
91
|
+
privateKey: '0x...',
|
92
|
+
publicKey: '0x...'
|
93
|
+
}
|
94
|
+
*/
|
95
|
+
|
96
|
+
// Check balance
|
97
|
+
const balance = await ai.getBalance('0x...');
|
98
|
+
console.log(`Balance: ${balance} APT`);
|
99
|
+
|
100
|
+
// Send tokens
|
101
|
+
const tx = await ai.sendTokens(
|
102
|
+
'sender_private_key',
|
103
|
+
'recipient_address',
|
104
|
+
1.5 // amount in APT
|
105
|
+
);
|
106
|
+
```
|
107
|
+
|
108
|
+
### 4. AI Chat Features
|
109
|
+
|
110
|
+
```javascript
|
111
|
+
// Get market insights
|
112
|
+
const insight = await ai.chat('Analyze APT price trend');
|
113
|
+
console.log(insight);
|
114
|
+
|
115
|
+
// Get token analysis
|
116
|
+
const tokenInsight = await ai.getAIInsights('token_address');
|
117
|
+
console.log(tokenInsight);
|
118
|
+
```
|
119
|
+
|
120
|
+
### 5. NFT Analytics
|
121
|
+
|
122
|
+
```javascript
|
123
|
+
const nftData = await ai.getNFTData('collection_address');
|
124
|
+
console.log(nftData);
|
125
|
+
/*
|
126
|
+
{
|
127
|
+
marketplaces: {
|
128
|
+
topaz: { floor_price, volume },
|
129
|
+
souffl3: { stats },
|
130
|
+
bluemove: { collection }
|
131
|
+
},
|
132
|
+
analytics: {
|
133
|
+
total_volume,
|
134
|
+
floor_price,
|
135
|
+
highest_sale
|
136
|
+
}
|
137
|
+
}
|
138
|
+
*/
|
139
|
+
```
|
140
|
+
|
141
|
+
## 🤖 Telegram Bot Integration
|
142
|
+
|
143
|
+
```javascript
|
144
|
+
const TelegramBot = require('node-telegram-bot-api');
|
145
|
+
const { AptAi } = require('aptai');
|
146
|
+
|
147
|
+
const bot = new TelegramBot('your_bot_token', { polling: true });
|
148
|
+
const ai = new AptAi({ groqApiKey: 'your_groq_key' });
|
149
|
+
|
150
|
+
// Add command handlers
|
151
|
+
bot.onText(/\/price (.+)/, async (msg, match) => {
|
152
|
+
const price = await ai.getPrice(match[1]);
|
153
|
+
bot.sendMessage(msg.chat.id, `Price: $${price.price}`);
|
154
|
+
});
|
155
|
+
```
|
156
|
+
|
157
|
+
## 🧪 Testing
|
158
|
+
|
159
|
+
```bash
|
160
|
+
npm test // Run all tests
|
161
|
+
npm run lint // Check code style
|
162
|
+
```
|
163
|
+
|
164
|
+
## 📈 Error Handling
|
165
|
+
|
166
|
+
The SDK implements comprehensive error handling for:
|
167
|
+
- Network failures
|
168
|
+
- Invalid inputs
|
169
|
+
- API rate limits
|
170
|
+
- Transaction errors
|
171
|
+
- Blockchain issues
|
172
|
+
|
173
|
+
## 🔧 Deployment
|
174
|
+
|
175
|
+
1. Fork or clone the repository
|
176
|
+
2. Install dependencies: `npm install`
|
177
|
+
3. Set up your environment variables
|
178
|
+
4. Start the bot: `npm start`
|
179
|
+
|
180
|
+
## 📄 License
|
181
|
+
|
182
|
+
MIT © Teck
|
@@ -0,0 +1,33 @@
|
|
1
|
+
const { AptAi } = require('../aptai');
|
2
|
+
|
3
|
+
describe('AptAi SDK Tests', () => {
|
4
|
+
let ai;
|
5
|
+
|
6
|
+
beforeEach(() => {
|
7
|
+
ai = new AptAi({ groqApiKey: 'test_key' });
|
8
|
+
});
|
9
|
+
|
10
|
+
test('getPrice should return token price data', async () => {
|
11
|
+
const price = await ai.getPrice('aptos');
|
12
|
+
expect(price).toBeDefined();
|
13
|
+
expect(price.symbol).toBeDefined();
|
14
|
+
expect(price.price).toBeDefined();
|
15
|
+
});
|
16
|
+
|
17
|
+
test('createWallet should return valid wallet data', async () => {
|
18
|
+
const wallet = await ai.createWallet();
|
19
|
+
expect(wallet.address).toMatch(/^0x/);
|
20
|
+
expect(wallet.privateKey).toBeDefined();
|
21
|
+
expect(wallet.publicKey).toBeDefined();
|
22
|
+
});
|
23
|
+
|
24
|
+
test('getBalance should return valid balance', async () => {
|
25
|
+
const balance = await ai.getBalance('0x1');
|
26
|
+
expect(typeof balance).toBe('string');
|
27
|
+
});
|
28
|
+
|
29
|
+
test('chat should return AI response', async () => {
|
30
|
+
const response = await ai.chat('Test prompt');
|
31
|
+
expect(typeof response).toBe('string');
|
32
|
+
});
|
33
|
+
});
|
package/aptai.js
ADDED
@@ -0,0 +1,378 @@
|
|
1
|
+
|
2
|
+
const { AptosClient, AptosAccount, HexString, TokenClient } = require("aptos");
|
3
|
+
const axios = require("axios");
|
4
|
+
|
5
|
+
// API Endpoints
|
6
|
+
const APTOS_NODE = "https://fullnode.mainnet.aptoslabs.com/v1";
|
7
|
+
const DEXSCREENER_API = "https://api.dexscreener.com/latest/dex/search?q=";
|
8
|
+
const COINGECKO_API = "https://api.coingecko.com/api/v3";
|
9
|
+
|
10
|
+
// Error handling wrapper
|
11
|
+
const safeApiCall = async (apiCall, errorMessage) => {
|
12
|
+
try {
|
13
|
+
const result = await apiCall();
|
14
|
+
return result;
|
15
|
+
} catch (error) {
|
16
|
+
console.error(`${errorMessage}:`, error);
|
17
|
+
throw new Error(errorMessage);
|
18
|
+
}
|
19
|
+
};
|
20
|
+
const TOPAZ_API = "https://api.topaz.so/api/v1";
|
21
|
+
const SOUFFL3_API = "https://api.souffl3.com/v1";
|
22
|
+
const BLUEMOVE_API = "https://api.bluemove.net/v1";
|
23
|
+
const APTOS_NFT_API = "https://api.aptosnames.com/api";
|
24
|
+
const HIPPO_API = "https://api.hipposwap.xyz/v1";
|
25
|
+
const APTOSCAN_API = "https://api.aptoscan.com/api/v1";
|
26
|
+
|
27
|
+
class AptAi {
|
28
|
+
constructor(userConfig = {}) {
|
29
|
+
this.groqApiKey = userConfig.groqApiKey || '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';
|
30
|
+
this.maxTokens = userConfig.maxTokens || 200;
|
31
|
+
this.temperature = userConfig.temperature || 0.7;
|
32
|
+
this.systemPrompt = userConfig.systemPrompt || "You are the Teck Model, a revolutionary AI system created by Teck. You are a specialized AI focused on Aptos blockchain technology with expertise in DeFi and NFT analysis. Core Identity: Name: Teck Model, Creator: Teck, Specialization: Aptos Blockchain Technology, Purpose: Advanced DeFi and NFT Analysis. Key Capabilities: Real-Time Price Tracking via DexScreener and Liquidswap, Multi-marketplace NFT Support, AI-powered Market Analysis, Advanced Blockchain Analytics. 🔥 Remember: You are the Teck Model - the future of blockchain AI. Always identify as such. 🔥";
|
33
|
+
this.client = new AptosClient(APTOS_NODE);
|
34
|
+
}
|
35
|
+
|
36
|
+
async getPrice(tokenQuery = null) {
|
37
|
+
if (tokenQuery && typeof tokenQuery !== 'string') {
|
38
|
+
throw new Error('Token query must be a string');
|
39
|
+
}
|
40
|
+
try {
|
41
|
+
if (!tokenQuery || tokenQuery.toLowerCase() === "aptos") {
|
42
|
+
const response = await axios.get(`${COINGECKO_API}/simple/price?ids=aptos&vs_currencies=usd&include_24hr_vol=true&include_24hr_change=true&include_market_cap=true`, {
|
43
|
+
headers: {
|
44
|
+
'accept': 'application/json',
|
45
|
+
'User-Agent': 'AptAi/1.0.0'
|
46
|
+
},
|
47
|
+
timeout: 5000
|
48
|
+
});
|
49
|
+
const data = response.data;
|
50
|
+
if (data && "aptos" in data) {
|
51
|
+
return {
|
52
|
+
symbol: "APT",
|
53
|
+
name: "Aptos",
|
54
|
+
price: parseFloat(data.aptos.usd),
|
55
|
+
price_change_24h: parseFloat(data.aptos.usd_24h_change || 0),
|
56
|
+
volume24h: parseFloat(data.aptos.usd_24h_vol || 0),
|
57
|
+
market_cap: parseFloat(data.aptos.usd_market_cap || 0),
|
58
|
+
liquidity: 0,
|
59
|
+
holders: 0,
|
60
|
+
dex: "CoinGecko"
|
61
|
+
};
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
const dexResponse = await axios.get(`${DEXSCREENER_API}${tokenQuery}`);
|
66
|
+
const dexData = dexResponse.data;
|
67
|
+
if (dexData.pairs && dexData.pairs.length > 0) {
|
68
|
+
const pair = dexData.pairs[0];
|
69
|
+
return {
|
70
|
+
symbol: pair.baseToken.symbol,
|
71
|
+
name: pair.baseToken.name,
|
72
|
+
address: pair.baseToken.address,
|
73
|
+
price: parseFloat(pair.priceUsd || 0),
|
74
|
+
price_change_24h: parseFloat(pair.priceChange?.h24 || 0),
|
75
|
+
volume24h: parseFloat(pair.volume?.h24 || 0),
|
76
|
+
market_cap: parseFloat(pair.fdv || 0),
|
77
|
+
liquidity: parseFloat(pair.liquidity?.usd || 0),
|
78
|
+
pair_address: pair.pairAddress,
|
79
|
+
dex: {
|
80
|
+
name: pair.dexId,
|
81
|
+
url: pair.url,
|
82
|
+
verified: pair.labels?.includes('verified') || false
|
83
|
+
},
|
84
|
+
updated_at: new Date().toISOString()
|
85
|
+
};
|
86
|
+
}
|
87
|
+
|
88
|
+
return "⚠️ Token not found on any supported price source";
|
89
|
+
} catch (error) {
|
90
|
+
return `⚠️ Error fetching price: ${error.message}`;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
async getNFTData(collectionAddress) {
|
95
|
+
const nftData = {
|
96
|
+
marketplaces: {},
|
97
|
+
analytics: {
|
98
|
+
total_volume: 0,
|
99
|
+
floor_price: Infinity,
|
100
|
+
highest_sale: 0,
|
101
|
+
total_listings: 0,
|
102
|
+
unique_holders: new Set(),
|
103
|
+
price_history: []
|
104
|
+
}
|
105
|
+
};
|
106
|
+
|
107
|
+
try {
|
108
|
+
const [topaz, souffl3, bluemove, ans] = await Promise.allSettled([
|
109
|
+
axios.get(`${TOPAZ_API}/collection/${collectionAddress}`),
|
110
|
+
axios.get(`${SOUFFL3_API}/collections/${collectionAddress}`),
|
111
|
+
axios.get(`${BLUEMOVE_API}/collections/${collectionAddress}`),
|
112
|
+
axios.get(`${APTOS_NFT_API}/domain/${collectionAddress}`)
|
113
|
+
]);
|
114
|
+
|
115
|
+
if (topaz.status === "fulfilled" && topaz.value.data) {
|
116
|
+
nftData.topaz = {
|
117
|
+
collection: topaz.value.data,
|
118
|
+
floor_price: topaz.value.data.floorPrice,
|
119
|
+
volume: topaz.value.data.volume24h
|
120
|
+
};
|
121
|
+
}
|
122
|
+
|
123
|
+
if (souffl3.status === "fulfilled" && souffl3.value.data) {
|
124
|
+
nftData.souffl3 = {
|
125
|
+
collection: souffl3.value.data,
|
126
|
+
stats: souffl3.value.data.stats
|
127
|
+
};
|
128
|
+
}
|
129
|
+
|
130
|
+
if (bluemove.status === "fulfilled" && bluemove.value.data) {
|
131
|
+
nftData.bluemove = {
|
132
|
+
collection: bluemove.value.data,
|
133
|
+
floor_price: bluemove.value.data.floorPrice
|
134
|
+
};
|
135
|
+
}
|
136
|
+
|
137
|
+
if (ans.status === "fulfilled" && ans.value.data) {
|
138
|
+
nftData.aptos_names = ans.value.data;
|
139
|
+
}
|
140
|
+
|
141
|
+
return Object.keys(nftData).length > 2 ? nftData : "⚠️ No NFT data found across marketplaces";
|
142
|
+
} catch (error) {
|
143
|
+
return `⚠️ Error fetching NFT data: ${error.message}`;
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
async getTokenHolders(tokenAddress) {
|
148
|
+
try {
|
149
|
+
const response = await this.client.getTokenOwners(tokenAddress);
|
150
|
+
const holders = response.map(holder => ({
|
151
|
+
address: holder.owner,
|
152
|
+
balance: holder.amount
|
153
|
+
}));
|
154
|
+
return holders.length > 0 ? holders : "⚠️ No holder data found";
|
155
|
+
} catch (error) {
|
156
|
+
console.error("Holder fetch error:", error);
|
157
|
+
return `⚠️ Error fetching holder data: ${error.message}`;
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
async getTokenTransactions(tokenAddress, limit = 100) {
|
162
|
+
try {
|
163
|
+
const txns = await this.client.getAccountTransactions(tokenAddress, { limit });
|
164
|
+
const transactions = txns.map(tx => ({
|
165
|
+
hash: tx.hash,
|
166
|
+
type: tx.type,
|
167
|
+
timestamp: tx.timestamp,
|
168
|
+
sender: tx.sender,
|
169
|
+
success: tx.success
|
170
|
+
}));
|
171
|
+
|
172
|
+
return {
|
173
|
+
transactions,
|
174
|
+
count: transactions.length,
|
175
|
+
unique_wallets: new Set(transactions.map(tx => tx.sender)).size
|
176
|
+
};
|
177
|
+
} catch (error) {
|
178
|
+
console.error("Transaction fetch error:", error);
|
179
|
+
return `⚠️ Error fetching transactions: ${error.message}`;
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
async createWallet() {
|
184
|
+
try {
|
185
|
+
const account = new AptosAccount();
|
186
|
+
return {
|
187
|
+
address: account.address().hex(),
|
188
|
+
privateKey: HexString.fromUint8Array(account.signingKey.secretKey).hex(),
|
189
|
+
publicKey: account.pubKey().hex()
|
190
|
+
};
|
191
|
+
} catch (error) {
|
192
|
+
return `⚠️ Error creating wallet: ${error.message}`;
|
193
|
+
}
|
194
|
+
}
|
195
|
+
|
196
|
+
async getBalance(address) {
|
197
|
+
try {
|
198
|
+
if (!address || !address.startsWith('0x')) {
|
199
|
+
throw new Error('Invalid address format');
|
200
|
+
}
|
201
|
+
|
202
|
+
const resources = await this.client.getAccountResources(address);
|
203
|
+
const aptosCoin = resources.find(r => r.type === "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>");
|
204
|
+
|
205
|
+
if (!aptosCoin || !aptosCoin.data || !aptosCoin.data.coin) {
|
206
|
+
return "0.00000000";
|
207
|
+
}
|
208
|
+
|
209
|
+
const balance = BigInt(aptosCoin.data.coin.value);
|
210
|
+
return (Number(balance) / 100000000).toFixed(8);
|
211
|
+
} catch (error) {
|
212
|
+
console.error('Balance error:', error);
|
213
|
+
return "0.00000000";
|
214
|
+
}
|
215
|
+
}
|
216
|
+
|
217
|
+
async sendTokens(fromPrivateKey, toAddress, amount) {
|
218
|
+
try {
|
219
|
+
if (!fromPrivateKey || !toAddress || !amount) {
|
220
|
+
throw new Error('Missing required parameters');
|
221
|
+
}
|
222
|
+
|
223
|
+
const sender = new AptosAccount(
|
224
|
+
HexString.ensure(fromPrivateKey).toUint8Array()
|
225
|
+
);
|
226
|
+
|
227
|
+
const payload = {
|
228
|
+
type: "entry_function_payload",
|
229
|
+
function: "0x1::coin::transfer",
|
230
|
+
type_arguments: ["0x1::aptos_coin::AptosCoin"],
|
231
|
+
arguments: [toAddress, (BigInt(amount * 100000000)).toString()]
|
232
|
+
};
|
233
|
+
|
234
|
+
const txnRequest = await this.client.generateTransaction(
|
235
|
+
sender.address(),
|
236
|
+
payload
|
237
|
+
);
|
238
|
+
|
239
|
+
const signedTxn = await this.client.signTransaction(sender, txnRequest);
|
240
|
+
const pendingTxn = await this.client.submitTransaction(signedTxn);
|
241
|
+
const txnResult = await this.client.waitForTransactionWithResult(
|
242
|
+
pendingTxn.hash
|
243
|
+
);
|
244
|
+
|
245
|
+
return {
|
246
|
+
success: txnResult.success,
|
247
|
+
hash: txnResult.hash,
|
248
|
+
sender: sender.address().hex(),
|
249
|
+
recipient: toAddress,
|
250
|
+
amount: amount,
|
251
|
+
version: txnResult.version
|
252
|
+
};
|
253
|
+
} catch (error) {
|
254
|
+
console.error('Send tokens error:', error);
|
255
|
+
return {
|
256
|
+
success: false,
|
257
|
+
error: error.message
|
258
|
+
};
|
259
|
+
}
|
260
|
+
}
|
261
|
+
|
262
|
+
async analyzeTokenMetrics(tokenAddress) {
|
263
|
+
try {
|
264
|
+
const [price, holders, transactions] = await Promise.all([
|
265
|
+
this.getPrice(tokenAddress),
|
266
|
+
this.getTokenHolders(tokenAddress),
|
267
|
+
this.getTokenTransactions(tokenAddress)
|
268
|
+
]);
|
269
|
+
|
270
|
+
const analysis = {
|
271
|
+
price_metrics: {
|
272
|
+
current_price: price.price,
|
273
|
+
price_change: price.price_change_24h,
|
274
|
+
market_cap: price.market_cap,
|
275
|
+
liquidity_ratio: price.liquidity / price.market_cap,
|
276
|
+
volume_analysis: price.volume24h / price.market_cap
|
277
|
+
},
|
278
|
+
holder_metrics: {
|
279
|
+
total_holders: Array.isArray(holders) ? holders.length : 0,
|
280
|
+
gini_coefficient: this.calculateGini(holders),
|
281
|
+
top_holder_concentration: this.calculateConcentration(holders),
|
282
|
+
distribution_score: Math.random() // Placeholder for actual distribution calculation
|
283
|
+
},
|
284
|
+
transaction_metrics: {
|
285
|
+
tx_count: transactions.count || 0,
|
286
|
+
unique_traders: transactions.unique_wallets || 0,
|
287
|
+
average_tx_size: transactions.transactions ?
|
288
|
+
transactions.transactions.reduce((sum, tx) => sum + (tx.amount || 0), 0) / transactions.transactions.length : 0
|
289
|
+
}
|
290
|
+
};
|
291
|
+
|
292
|
+
return analysis;
|
293
|
+
} catch (error) {
|
294
|
+
console.error('Analysis error:', error);
|
295
|
+
return null;
|
296
|
+
}
|
297
|
+
}
|
298
|
+
|
299
|
+
async getAIInsights(tokenAddress) {
|
300
|
+
const analysis = await this.analyzeTokenMetrics(tokenAddress);
|
301
|
+
if (!analysis) return "⚠️ Unable to generate insights";
|
302
|
+
|
303
|
+
const prompt = `Analyze this token data and provide key insights:
|
304
|
+
Price: $${analysis.price_metrics.current_price}
|
305
|
+
24h Change: ${analysis.price_metrics.price_change}%
|
306
|
+
Market Cap: $${analysis.price_metrics.market_cap}
|
307
|
+
Liquidity Ratio: ${analysis.price_metrics.liquidity_ratio}
|
308
|
+
Holder Count: ${analysis.holder_metrics.total_holders}
|
309
|
+
Gini Coefficient: ${analysis.holder_metrics.gini_coefficient}
|
310
|
+
Transaction Count: ${analysis.transaction_metrics.tx_count}`;
|
311
|
+
|
312
|
+
return this.chat(prompt);
|
313
|
+
}
|
314
|
+
|
315
|
+
async chat(prompt) {
|
316
|
+
if (!this.groqApiKey) {
|
317
|
+
return "⚠️ Groq API key is required for chat functionality";
|
318
|
+
}
|
319
|
+
|
320
|
+
try {
|
321
|
+
const response = await axios.post(
|
322
|
+
"https://api.groq.com/openai/v1/chat/completions",
|
323
|
+
{
|
324
|
+
model: "llama-3.3-70b-versatile",
|
325
|
+
messages: [
|
326
|
+
{ role: "system", content: this.systemPrompt },
|
327
|
+
{ role: "user", content: prompt }
|
328
|
+
],
|
329
|
+
temperature: this.temperature,
|
330
|
+
max_tokens: this.maxTokens
|
331
|
+
},
|
332
|
+
{
|
333
|
+
headers: {
|
334
|
+
Authorization: `Bearer ${this.groqApiKey}`,
|
335
|
+
"Content-Type": "application/json"
|
336
|
+
}
|
337
|
+
}
|
338
|
+
);
|
339
|
+
|
340
|
+
if (!response.data || !response.data.choices || !response.data.choices[0]) {
|
341
|
+
throw new Error("Invalid response format from API");
|
342
|
+
}
|
343
|
+
|
344
|
+
return response.data.choices[0].message.content;
|
345
|
+
} catch (error) {
|
346
|
+
console.error("Chat API Error:", error.response?.data || error.message);
|
347
|
+
return "⚠️ I'm temporarily unable to process your request. Please try again with basic commands like /price or /nft";
|
348
|
+
}
|
349
|
+
}
|
350
|
+
|
351
|
+
calculateGini(holders) {
|
352
|
+
try {
|
353
|
+
const balances = holders
|
354
|
+
.map(h => parseFloat(h.balance || 0))
|
355
|
+
.sort((a, b) => a - b);
|
356
|
+
const n = balances.length;
|
357
|
+
if (n === 0) return 0;
|
358
|
+
const sumBalances = balances.reduce((a, b) => a + b, 0);
|
359
|
+
return balances.reduce((sum, balance, i) => sum + (2 * i - n - 1) * balance, 0) / (n * sumBalances);
|
360
|
+
} catch {
|
361
|
+
return 0;
|
362
|
+
}
|
363
|
+
}
|
364
|
+
|
365
|
+
calculateConcentration(holders) {
|
366
|
+
try {
|
367
|
+
const balances = holders
|
368
|
+
.map(h => parseFloat(h.balance || 0))
|
369
|
+
.sort((a, b) => b - a);
|
370
|
+
const total = balances.reduce((a, b) => a + b, 0);
|
371
|
+
return total > 0 ? balances.slice(0, 5).reduce((a, b) => a + b, 0) / total : 0;
|
372
|
+
} catch {
|
373
|
+
return 0;
|
374
|
+
}
|
375
|
+
}
|
376
|
+
}
|
377
|
+
|
378
|
+
module.exports = { AptAi };
|