rook-agent-sdk 0.1.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/RookAgent.d.ts +115 -0
- package/dist/RookAgent.js +237 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/package.json +30 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ROOK Agent SDK
|
|
3
|
+
*
|
|
4
|
+
* Bu SDK, AI ajanlarinin ROOK cuzdanini kullanmasini saglar.
|
|
5
|
+
* Insan kullanici ajani olusturduktan sonra, private key ve config'i
|
|
6
|
+
* ajana verir. Ajan bu SDK'yi kullanarak islem yapar.
|
|
7
|
+
*
|
|
8
|
+
* Kullanim:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { RookAgent } from '@rook/agent-sdk';
|
|
11
|
+
*
|
|
12
|
+
* const agent = new RookAgent({
|
|
13
|
+
* privateKey: '0x...', // Insandan alinan private key
|
|
14
|
+
* config: { // Insandan alinan limit config
|
|
15
|
+
* dailyLimitMON: '10',
|
|
16
|
+
* perTxLimitMON: '1',
|
|
17
|
+
* contractWhitelist: []
|
|
18
|
+
* }
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Islem gonder
|
|
22
|
+
* const result = await agent.send('0xRecipient...', '0.5');
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { ethers } from 'ethers';
|
|
26
|
+
export interface AgentConfig {
|
|
27
|
+
dailyLimitMON: string;
|
|
28
|
+
perTxLimitMON: string;
|
|
29
|
+
contractWhitelist: string[];
|
|
30
|
+
expiresAt?: number | null;
|
|
31
|
+
}
|
|
32
|
+
export interface AgentOptions {
|
|
33
|
+
privateKey: string;
|
|
34
|
+
config: AgentConfig;
|
|
35
|
+
rpcUrl?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface TransactionResult {
|
|
38
|
+
success: boolean;
|
|
39
|
+
txHash?: string;
|
|
40
|
+
error?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface SpendingRecord {
|
|
43
|
+
date: string;
|
|
44
|
+
amount: string;
|
|
45
|
+
txHash: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* ROOK Agent - AI ajanlari icin cuzdan SDK'si
|
|
49
|
+
*/
|
|
50
|
+
export declare class RookAgent {
|
|
51
|
+
private wallet;
|
|
52
|
+
private provider;
|
|
53
|
+
private config;
|
|
54
|
+
private spendingHistory;
|
|
55
|
+
constructor(options: AgentOptions);
|
|
56
|
+
/**
|
|
57
|
+
* Ajan adresi
|
|
58
|
+
*/
|
|
59
|
+
get address(): string;
|
|
60
|
+
/**
|
|
61
|
+
* Bakiye sorgula
|
|
62
|
+
*/
|
|
63
|
+
getBalance(): Promise<string>;
|
|
64
|
+
/**
|
|
65
|
+
* Bugunun tarihi (YYYY-MM-DD)
|
|
66
|
+
*/
|
|
67
|
+
private getTodayDate;
|
|
68
|
+
/**
|
|
69
|
+
* Bugun harcanan miktar
|
|
70
|
+
*/
|
|
71
|
+
getSpentToday(): number;
|
|
72
|
+
/**
|
|
73
|
+
* Kalan gunluk limit
|
|
74
|
+
*/
|
|
75
|
+
getRemainingDailyLimit(): number;
|
|
76
|
+
/**
|
|
77
|
+
* Islem validasyonu
|
|
78
|
+
*/
|
|
79
|
+
private validateTransaction;
|
|
80
|
+
/**
|
|
81
|
+
* MON gonder
|
|
82
|
+
*
|
|
83
|
+
* @param to - Alici adresi
|
|
84
|
+
* @param amountMON - MON miktari
|
|
85
|
+
*/
|
|
86
|
+
send(to: string, amountMON: string): Promise<TransactionResult>;
|
|
87
|
+
/**
|
|
88
|
+
* Smart contract cagir
|
|
89
|
+
*
|
|
90
|
+
* @param contractAddress - Kontrat adresi
|
|
91
|
+
* @param abi - Kontrat ABI'si
|
|
92
|
+
* @param method - Cagrilacak metod
|
|
93
|
+
* @param args - Metod argumanlari
|
|
94
|
+
* @param valueMON - Gonderilecek MON (opsiyonel)
|
|
95
|
+
*/
|
|
96
|
+
callContract(contractAddress: string, abi: ethers.InterfaceAbi, method: string, args?: unknown[], valueMON?: string): Promise<TransactionResult>;
|
|
97
|
+
/**
|
|
98
|
+
* Islem gecmisi
|
|
99
|
+
*/
|
|
100
|
+
getTransactionHistory(): SpendingRecord[];
|
|
101
|
+
/**
|
|
102
|
+
* Durum ozeti
|
|
103
|
+
*/
|
|
104
|
+
getStatus(): Promise<{
|
|
105
|
+
address: string;
|
|
106
|
+
balance: string;
|
|
107
|
+
spentToday: number;
|
|
108
|
+
remainingToday: number;
|
|
109
|
+
dailyLimit: string;
|
|
110
|
+
perTxLimit: string;
|
|
111
|
+
network: string;
|
|
112
|
+
chainId: number;
|
|
113
|
+
}>;
|
|
114
|
+
}
|
|
115
|
+
export default RookAgent;
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ROOK Agent SDK
|
|
3
|
+
*
|
|
4
|
+
* Bu SDK, AI ajanlarinin ROOK cuzdanini kullanmasini saglar.
|
|
5
|
+
* Insan kullanici ajani olusturduktan sonra, private key ve config'i
|
|
6
|
+
* ajana verir. Ajan bu SDK'yi kullanarak islem yapar.
|
|
7
|
+
*
|
|
8
|
+
* Kullanim:
|
|
9
|
+
* ```typescript
|
|
10
|
+
* import { RookAgent } from '@rook/agent-sdk';
|
|
11
|
+
*
|
|
12
|
+
* const agent = new RookAgent({
|
|
13
|
+
* privateKey: '0x...', // Insandan alinan private key
|
|
14
|
+
* config: { // Insandan alinan limit config
|
|
15
|
+
* dailyLimitMON: '10',
|
|
16
|
+
* perTxLimitMON: '1',
|
|
17
|
+
* contractWhitelist: []
|
|
18
|
+
* }
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* // Islem gonder
|
|
22
|
+
* const result = await agent.send('0xRecipient...', '0.5');
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
import { ethers } from 'ethers';
|
|
26
|
+
// Monad Testnet Config
|
|
27
|
+
const MONAD_CONFIG = {
|
|
28
|
+
chainId: 10143,
|
|
29
|
+
name: 'Monad Testnet',
|
|
30
|
+
rpcUrl: 'https://testnet-rpc.monad.xyz',
|
|
31
|
+
symbol: 'MON',
|
|
32
|
+
explorerUrl: 'https://monad-testnet.socialscan.io'
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* ROOK Agent - AI ajanlari icin cuzdan SDK'si
|
|
36
|
+
*/
|
|
37
|
+
export class RookAgent {
|
|
38
|
+
wallet;
|
|
39
|
+
provider;
|
|
40
|
+
config;
|
|
41
|
+
spendingHistory = [];
|
|
42
|
+
constructor(options) {
|
|
43
|
+
// Provider olustur
|
|
44
|
+
this.provider = new ethers.JsonRpcProvider(options.rpcUrl || MONAD_CONFIG.rpcUrl, {
|
|
45
|
+
chainId: MONAD_CONFIG.chainId,
|
|
46
|
+
name: MONAD_CONFIG.name
|
|
47
|
+
});
|
|
48
|
+
// Wallet olustur
|
|
49
|
+
this.wallet = new ethers.Wallet(options.privateKey, this.provider);
|
|
50
|
+
this.config = options.config;
|
|
51
|
+
console.log(`ROOK Agent initialized`);
|
|
52
|
+
console.log(` Address: ${this.wallet.address}`);
|
|
53
|
+
console.log(` Daily Limit: ${this.config.dailyLimitMON} MON`);
|
|
54
|
+
console.log(` Per-Tx Limit: ${this.config.perTxLimitMON} MON`);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Ajan adresi
|
|
58
|
+
*/
|
|
59
|
+
get address() {
|
|
60
|
+
return this.wallet.address;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Bakiye sorgula
|
|
64
|
+
*/
|
|
65
|
+
async getBalance() {
|
|
66
|
+
const balance = await this.provider.getBalance(this.wallet.address);
|
|
67
|
+
return ethers.formatEther(balance);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Bugunun tarihi (YYYY-MM-DD)
|
|
71
|
+
*/
|
|
72
|
+
getTodayDate() {
|
|
73
|
+
return new Date().toISOString().split('T')[0];
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Bugun harcanan miktar
|
|
77
|
+
*/
|
|
78
|
+
getSpentToday() {
|
|
79
|
+
const today = this.getTodayDate();
|
|
80
|
+
return this.spendingHistory
|
|
81
|
+
.filter(s => s.date === today)
|
|
82
|
+
.reduce((sum, s) => sum + parseFloat(s.amount), 0);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Kalan gunluk limit
|
|
86
|
+
*/
|
|
87
|
+
getRemainingDailyLimit() {
|
|
88
|
+
const spent = this.getSpentToday();
|
|
89
|
+
const limit = parseFloat(this.config.dailyLimitMON);
|
|
90
|
+
return Math.max(0, limit - spent);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Islem validasyonu
|
|
94
|
+
*/
|
|
95
|
+
validateTransaction(to, amountMON) {
|
|
96
|
+
const amount = parseFloat(amountMON);
|
|
97
|
+
// 1. Sure dolmus mu?
|
|
98
|
+
if (this.config.expiresAt && Date.now() > this.config.expiresAt) {
|
|
99
|
+
return { valid: false, reason: 'Agent access has expired' };
|
|
100
|
+
}
|
|
101
|
+
// 2. Islem basina limit
|
|
102
|
+
const perTxLimit = parseFloat(this.config.perTxLimitMON);
|
|
103
|
+
if (amount > perTxLimit) {
|
|
104
|
+
return {
|
|
105
|
+
valid: false,
|
|
106
|
+
reason: `Amount ${amountMON} MON exceeds per-transaction limit of ${this.config.perTxLimitMON} MON`
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
// 3. Gunluk limit
|
|
110
|
+
const remaining = this.getRemainingDailyLimit();
|
|
111
|
+
if (amount > remaining) {
|
|
112
|
+
return {
|
|
113
|
+
valid: false,
|
|
114
|
+
reason: `Would exceed daily limit. Remaining today: ${remaining.toFixed(4)} MON`
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
// 4. Whitelist kontrolu
|
|
118
|
+
if (this.config.contractWhitelist.length > 0) {
|
|
119
|
+
const isWhitelisted = this.config.contractWhitelist.some(addr => addr.toLowerCase() === to.toLowerCase());
|
|
120
|
+
if (!isWhitelisted) {
|
|
121
|
+
return {
|
|
122
|
+
valid: false,
|
|
123
|
+
reason: 'Recipient address is not in the allowed contracts list'
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return { valid: true };
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* MON gonder
|
|
131
|
+
*
|
|
132
|
+
* @param to - Alici adresi
|
|
133
|
+
* @param amountMON - MON miktari
|
|
134
|
+
*/
|
|
135
|
+
async send(to, amountMON) {
|
|
136
|
+
console.log(`Sending ${amountMON} MON to ${to}...`);
|
|
137
|
+
// Validasyon
|
|
138
|
+
const validation = this.validateTransaction(to, amountMON);
|
|
139
|
+
if (!validation.valid) {
|
|
140
|
+
console.log(`Transaction rejected: ${validation.reason}`);
|
|
141
|
+
return { success: false, error: validation.reason };
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
// Adres kontrolu
|
|
145
|
+
if (!ethers.isAddress(to)) {
|
|
146
|
+
return { success: false, error: 'Invalid recipient address' };
|
|
147
|
+
}
|
|
148
|
+
// Islem gonder
|
|
149
|
+
const tx = await this.wallet.sendTransaction({
|
|
150
|
+
to,
|
|
151
|
+
value: ethers.parseEther(amountMON)
|
|
152
|
+
});
|
|
153
|
+
console.log(`Transaction sent: ${tx.hash}`);
|
|
154
|
+
// Onay bekle
|
|
155
|
+
await tx.wait();
|
|
156
|
+
console.log(`Transaction confirmed!`);
|
|
157
|
+
// Harcamayi kaydet
|
|
158
|
+
this.spendingHistory.push({
|
|
159
|
+
date: this.getTodayDate(),
|
|
160
|
+
amount: amountMON,
|
|
161
|
+
txHash: tx.hash
|
|
162
|
+
});
|
|
163
|
+
return { success: true, txHash: tx.hash };
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
const message = error instanceof Error ? error.message : 'Transaction failed';
|
|
167
|
+
console.log(`Transaction failed: ${message}`);
|
|
168
|
+
return { success: false, error: message };
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Smart contract cagir
|
|
173
|
+
*
|
|
174
|
+
* @param contractAddress - Kontrat adresi
|
|
175
|
+
* @param abi - Kontrat ABI'si
|
|
176
|
+
* @param method - Cagrilacak metod
|
|
177
|
+
* @param args - Metod argumanlari
|
|
178
|
+
* @param valueMON - Gonderilecek MON (opsiyonel)
|
|
179
|
+
*/
|
|
180
|
+
async callContract(contractAddress, abi, method, args = [], valueMON = '0') {
|
|
181
|
+
console.log(`Calling ${method} on ${contractAddress}...`);
|
|
182
|
+
// Validasyon (eger MON gonderiliyorsa)
|
|
183
|
+
if (parseFloat(valueMON) > 0) {
|
|
184
|
+
const validation = this.validateTransaction(contractAddress, valueMON);
|
|
185
|
+
if (!validation.valid) {
|
|
186
|
+
console.log(`Transaction rejected: ${validation.reason}`);
|
|
187
|
+
return { success: false, error: validation.reason };
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
try {
|
|
191
|
+
const contract = new ethers.Contract(contractAddress, abi, this.wallet);
|
|
192
|
+
const tx = await contract[method](...args, {
|
|
193
|
+
value: ethers.parseEther(valueMON)
|
|
194
|
+
});
|
|
195
|
+
console.log(`Transaction sent: ${tx.hash}`);
|
|
196
|
+
await tx.wait();
|
|
197
|
+
console.log(`Transaction confirmed!`);
|
|
198
|
+
// Harcamayi kaydet
|
|
199
|
+
if (parseFloat(valueMON) > 0) {
|
|
200
|
+
this.spendingHistory.push({
|
|
201
|
+
date: this.getTodayDate(),
|
|
202
|
+
amount: valueMON,
|
|
203
|
+
txHash: tx.hash
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
return { success: true, txHash: tx.hash };
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
const message = error instanceof Error ? error.message : 'Contract call failed';
|
|
210
|
+
console.log(`Contract call failed: ${message}`);
|
|
211
|
+
return { success: false, error: message };
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Islem gecmisi
|
|
216
|
+
*/
|
|
217
|
+
getTransactionHistory() {
|
|
218
|
+
return [...this.spendingHistory];
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Durum ozeti
|
|
222
|
+
*/
|
|
223
|
+
async getStatus() {
|
|
224
|
+
const balance = await this.getBalance();
|
|
225
|
+
return {
|
|
226
|
+
address: this.wallet.address,
|
|
227
|
+
balance,
|
|
228
|
+
spentToday: this.getSpentToday(),
|
|
229
|
+
remainingToday: this.getRemainingDailyLimit(),
|
|
230
|
+
dailyLimit: this.config.dailyLimitMON,
|
|
231
|
+
perTxLimit: this.config.perTxLimitMON,
|
|
232
|
+
network: MONAD_CONFIG.name,
|
|
233
|
+
chainId: MONAD_CONFIG.chainId
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
export default RookAgent;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ROOK Agent SDK
|
|
3
|
+
*
|
|
4
|
+
* SDK for AI agents to interact with ROOK Wallet on Monad blockchain.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { RookAgent } from '@rook/agent-sdk';
|
|
9
|
+
*
|
|
10
|
+
* const agent = new RookAgent({
|
|
11
|
+
* privateKey: '0x...',
|
|
12
|
+
* config: {
|
|
13
|
+
* dailyLimitMON: '10',
|
|
14
|
+
* perTxLimitMON: '1',
|
|
15
|
+
* contractWhitelist: []
|
|
16
|
+
* }
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* await agent.send('0x...', '0.5');
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export { RookAgent, type AgentConfig, type AgentOptions, type TransactionResult, type SpendingRecord } from './RookAgent.js';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ROOK Agent SDK
|
|
3
|
+
*
|
|
4
|
+
* SDK for AI agents to interact with ROOK Wallet on Monad blockchain.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { RookAgent } from '@rook/agent-sdk';
|
|
9
|
+
*
|
|
10
|
+
* const agent = new RookAgent({
|
|
11
|
+
* privateKey: '0x...',
|
|
12
|
+
* config: {
|
|
13
|
+
* dailyLimitMON: '10',
|
|
14
|
+
* perTxLimitMON: '1',
|
|
15
|
+
* contractWhitelist: []
|
|
16
|
+
* }
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* await agent.send('0x...', '0.5');
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export { RookAgent } from './RookAgent.js';
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "rook-agent-sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ROOK Agent SDK - Non-custodial AI agent wallet for Monad blockchain",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "dist/index.js",
|
|
10
|
+
"types": "dist/index.d.ts",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
14
|
+
"import": "./dist/index.js"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"dev": "tsc --watch"
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"ethers": "^6.13.4"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/node": "^22.0.0",
|
|
26
|
+
"typescript": "^5.6.0"
|
|
27
|
+
},
|
|
28
|
+
"keywords": ["rook", "wallet", "ai-agent", "monad", "crypto", "sdk", "mcp"],
|
|
29
|
+
"license": "MIT"
|
|
30
|
+
}
|