@ael-protocol/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/README.md ADDED
@@ -0,0 +1,252 @@
1
+ # @ael-protocol/sdk
2
+
3
+ **AEL SDK** - Intent-based trading execution for AI Agents on Base.
4
+
5
+ AEL (Agent Execution Layer) enables AI agents to execute on-chain trades through a simple intent-based API. Submit your trading intent, and Solvers compete to execute it at the best price.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @ael-protocol/sdk viem
11
+ ```
12
+
13
+ ## Quick Start (6 Lines)
14
+
15
+ ```typescript
16
+ import { AEL, BASE_MAINNET, ETH_ADDRESS } from '@ael-protocol/sdk';
17
+ import { base } from 'viem/chains';
18
+ import { parseEther, parseUnits } from 'viem';
19
+
20
+ // Recommend using Alchemy or Infura RPC for production
21
+ const ael = new AEL({ privateKey: '0x...', routerAddress: BASE_MAINNET.AEL_ROUTER, chain: base, rpcUrl: process.env.BASE_RPC_URL || 'https://mainnet.base.org' });
22
+ const result = await ael.swap({ tokenIn: ETH_ADDRESS, tokenOut: BASE_MAINNET.USDC, amountIn: parseEther('0.1'), minAmountOut: parseUnits('200', 6) });
23
+ const status = await ael.waitForSettlement(result.intentHash);
24
+ ```
25
+
26
+ ## Contract Addresses
27
+
28
+ ### Base Mainnet (Chain ID: 8453)
29
+
30
+ | Contract | Address |
31
+ |----------|---------|
32
+ | Router | `0x85977BD37d8100F81566A1c6815047f5557bCDCB` |
33
+ | SolverRegistry | `0xd14D394631C32Ea35fFF8407157C6867bCc8E946` |
34
+ | FeeVault | `0xF8E3646b03a83465D6DAE65edbF380C77feb5DE0` |
35
+
36
+ ### Base Sepolia (Chain ID: 84532)
37
+
38
+ | Contract | Address |
39
+ |----------|---------|
40
+ | Router | `0x83A260939cF1326E9aa94eF6c814F2Fd876535e8` |
41
+ | SolverRegistry | `0xC69A90904B44297af5fC7C554d7ca37612Ef01B3` |
42
+ | FeeVault | `0xAec32AbD0233a124B7D0A17055fB40a50442E088` |
43
+
44
+ ## API Reference
45
+
46
+ ### `new AEL(config)`
47
+
48
+ Create a new AEL instance.
49
+
50
+ ```typescript
51
+ interface AELConfig {
52
+ privateKey: `0x${string}`; // Agent's private key
53
+ routerAddress: `0x${string}`; // AEL Router address
54
+ chain: Chain; // viem chain object (base or baseSepolia)
55
+ rpcUrl: string; // RPC endpoint URL
56
+ }
57
+
58
+ // Recommend using Alchemy or Infura RPC for production
59
+ const ael = new AEL({
60
+ privateKey: process.env.PRIVATE_KEY as `0x${string}`,
61
+ routerAddress: BASE_MAINNET.AEL_ROUTER,
62
+ chain: base,
63
+ rpcUrl: process.env.BASE_RPC_URL || 'https://mainnet.base.org',
64
+ });
65
+ ```
66
+
67
+ ### `ael.swap(params): Promise<SwapResult>`
68
+
69
+ Submit a swap intent. Handles EIP-712 signing and ERC20 approval automatically.
70
+
71
+ ```typescript
72
+ interface SwapParams {
73
+ tokenIn: `0x${string}`; // Input token (use ETH_ADDRESS for ETH)
74
+ tokenOut: `0x${string}`; // Output token address
75
+ amountIn: bigint; // Amount to swap (in wei)
76
+ minAmountOut: bigint; // Minimum output (slippage protection)
77
+ deadline?: bigint; // Optional deadline (default: 1 hour)
78
+ }
79
+
80
+ interface SwapResult {
81
+ intentHash: `0x${string}`; // Unique intent identifier
82
+ txHash: `0x${string}`; // Transaction hash
83
+ status: IntentStatus; // 'Pending'
84
+ }
85
+
86
+ // Example
87
+ const result = await ael.swap({
88
+ tokenIn: ETH_ADDRESS,
89
+ tokenOut: BASE_MAINNET.USDC,
90
+ amountIn: parseEther('0.1'),
91
+ minAmountOut: parseUnits('200', 6),
92
+ });
93
+ ```
94
+
95
+ ### `ael.quote(tokenIn, tokenOut, amountIn): Promise<QuoteResult | null>`
96
+
97
+ Get a price quote from Uniswap V3. Tries all fee tiers (0.05%, 0.3%, 1%) and returns the best.
98
+
99
+ ```typescript
100
+ interface QuoteResult {
101
+ amountOut: bigint; // Expected output amount
102
+ priceImpact: number; // Price impact percentage
103
+ fee: number; // Pool fee tier (500, 3000, or 10000)
104
+ }
105
+
106
+ const quote = await ael.quote(ETH_ADDRESS, BASE_MAINNET.USDC, parseEther('1'));
107
+ if (quote) {
108
+ console.log('Expected:', quote.amountOut, 'Fee tier:', quote.fee);
109
+ }
110
+ ```
111
+
112
+ ### `ael.cancel(intentHash): Promise<Hash>`
113
+
114
+ Cancel a pending intent and get refunded. Only works after 30-second lock period.
115
+
116
+ ```typescript
117
+ const txHash = await ael.cancel(intentHash);
118
+ ```
119
+
120
+ ### `ael.getStatus(intentHash): Promise<IntentStatus>`
121
+
122
+ Check the current status of an intent.
123
+
124
+ ```typescript
125
+ enum IntentStatus {
126
+ None = 0, // Intent doesn't exist
127
+ Pending = 1, // Waiting for Solver
128
+ Settled = 2, // Successfully executed
129
+ Refunded = 3, // Cancelled or failed
130
+ Expired = 4, // Deadline passed
131
+ }
132
+
133
+ const status = await ael.getStatus(intentHash);
134
+ ```
135
+
136
+ ### `ael.waitForSettlement(intentHash, timeoutMs?): Promise<IntentStatus>`
137
+
138
+ Poll until intent is settled, refunded, or expired. Default timeout: 60 seconds.
139
+
140
+ ```typescript
141
+ const finalStatus = await ael.waitForSettlement(intentHash, 120000);
142
+ if (finalStatus === IntentStatus.Settled) {
143
+ console.log('Trade executed!');
144
+ }
145
+ ```
146
+
147
+ ### `ael.address`
148
+
149
+ Get the agent's wallet address.
150
+
151
+ ```typescript
152
+ console.log('Agent:', ael.address);
153
+ ```
154
+
155
+ ## Constants
156
+
157
+ ```typescript
158
+ import { BASE_MAINNET, BASE_SEPOLIA, ETH_ADDRESS } from '@ael-protocol/sdk';
159
+
160
+ // Mainnet
161
+ BASE_MAINNET.AEL_ROUTER // Router contract
162
+ BASE_MAINNET.USDC // 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
163
+ BASE_MAINNET.WETH // 0x4200000000000000000000000000000000000006
164
+
165
+ // Testnet
166
+ BASE_SEPOLIA.AEL_ROUTER // Router contract
167
+ BASE_SEPOLIA.USDC // 0x036CbD53842c5426634e7929541eC2318f3dCF7e
168
+
169
+ // Native ETH
170
+ ETH_ADDRESS // 0x0000000000000000000000000000000000000000
171
+ ```
172
+
173
+ ## Intent Lifecycle
174
+
175
+ ```
176
+ [Agent] submitIntent() --> [Pending] --> [Solver] settle() --> [Settled]
177
+ |
178
+ +--> [Agent] cancel() --> [Refunded]
179
+ |
180
+ +--> deadline passed --> [Expired]
181
+ ```
182
+
183
+ ## Fee Structure
184
+
185
+ - Protocol fee: **2 basis points (0.02%)** on input token
186
+ - Fee distribution:
187
+ - **70%** to Solver (execution reward)
188
+ - **20%** to Protocol Treasury
189
+ - **10%** to Governance Fund
190
+
191
+ ## Complete Example
192
+
193
+ ```typescript
194
+ import { AEL, BASE_MAINNET, ETH_ADDRESS, IntentStatus } from '@ael-protocol/sdk';
195
+ import { base } from 'viem/chains';
196
+ import { parseEther, parseUnits, formatUnits } from 'viem';
197
+
198
+ async function main() {
199
+ // Recommend using Alchemy or Infura RPC for production
200
+ const ael = new AEL({
201
+ privateKey: process.env.PRIVATE_KEY as `0x${string}`,
202
+ routerAddress: BASE_MAINNET.AEL_ROUTER,
203
+ chain: base,
204
+ rpcUrl: process.env.BASE_RPC_URL || 'https://mainnet.base.org',
205
+ });
206
+
207
+ console.log('Agent:', ael.address);
208
+
209
+ // Get quote
210
+ const quote = await ael.quote(ETH_ADDRESS, BASE_MAINNET.USDC, parseEther('0.1'));
211
+ if (!quote) throw new Error('No liquidity');
212
+
213
+ console.log('Quote:', formatUnits(quote.amountOut, 6), 'USDC');
214
+
215
+ // Swap with 2% slippage
216
+ const minOut = quote.amountOut * 98n / 100n;
217
+ const result = await ael.swap({
218
+ tokenIn: ETH_ADDRESS,
219
+ tokenOut: BASE_MAINNET.USDC,
220
+ amountIn: parseEther('0.1'),
221
+ minAmountOut: minOut,
222
+ });
223
+
224
+ console.log('Intent:', result.intentHash);
225
+
226
+ // Wait for settlement
227
+ const status = await ael.waitForSettlement(result.intentHash, 60000);
228
+ console.log('Status:', IntentStatus[status]);
229
+ }
230
+
231
+ main().catch(console.error);
232
+ ```
233
+
234
+ ## Error Handling
235
+
236
+ ```typescript
237
+ try {
238
+ await ael.swap({...});
239
+ } catch (error) {
240
+ if (error.message.includes('DepositCapExceeded')) {
241
+ // Protocol deposit limit reached
242
+ } else if (error.message.includes('InsufficientOutput')) {
243
+ // Slippage protection triggered
244
+ } else if (error.message.includes('InvalidDeadline')) {
245
+ // Deadline too short or too long
246
+ }
247
+ }
248
+ ```
249
+
250
+ ## License
251
+
252
+ MIT
package/dist/abi.d.ts ADDED
@@ -0,0 +1,287 @@
1
+ /**
2
+ * AEL Router ABI
3
+ */
4
+ export declare const ROUTER_ABI: readonly [{
5
+ readonly type: "event";
6
+ readonly name: "IntentSubmitted";
7
+ readonly inputs: readonly [{
8
+ readonly name: "intentHash";
9
+ readonly type: "bytes32";
10
+ readonly indexed: true;
11
+ }, {
12
+ readonly name: "agent";
13
+ readonly type: "address";
14
+ readonly indexed: true;
15
+ }, {
16
+ readonly name: "tokenIn";
17
+ readonly type: "address";
18
+ readonly indexed: false;
19
+ }, {
20
+ readonly name: "tokenOut";
21
+ readonly type: "address";
22
+ readonly indexed: false;
23
+ }, {
24
+ readonly name: "amountIn";
25
+ readonly type: "uint256";
26
+ readonly indexed: false;
27
+ }, {
28
+ readonly name: "minAmountOut";
29
+ readonly type: "uint256";
30
+ readonly indexed: false;
31
+ }, {
32
+ readonly name: "deadline";
33
+ readonly type: "uint256";
34
+ readonly indexed: false;
35
+ }];
36
+ }, {
37
+ readonly type: "event";
38
+ readonly name: "IntentSettled";
39
+ readonly inputs: readonly [{
40
+ readonly name: "intentHash";
41
+ readonly type: "bytes32";
42
+ readonly indexed: true;
43
+ }, {
44
+ readonly name: "solver";
45
+ readonly type: "address";
46
+ readonly indexed: true;
47
+ }, {
48
+ readonly name: "amountOut";
49
+ readonly type: "uint256";
50
+ readonly indexed: false;
51
+ }, {
52
+ readonly name: "fee";
53
+ readonly type: "uint256";
54
+ readonly indexed: false;
55
+ }];
56
+ }, {
57
+ readonly type: "event";
58
+ readonly name: "IntentCancelled";
59
+ readonly inputs: readonly [{
60
+ readonly name: "intentHash";
61
+ readonly type: "bytes32";
62
+ readonly indexed: true;
63
+ }];
64
+ }, {
65
+ readonly type: "event";
66
+ readonly name: "IntentExpired";
67
+ readonly inputs: readonly [{
68
+ readonly name: "intentHash";
69
+ readonly type: "bytes32";
70
+ readonly indexed: true;
71
+ }];
72
+ }, {
73
+ readonly type: "function";
74
+ readonly name: "submitIntent";
75
+ readonly inputs: readonly [{
76
+ readonly name: "intent";
77
+ readonly type: "tuple";
78
+ readonly components: readonly [{
79
+ readonly name: "agent";
80
+ readonly type: "address";
81
+ }, {
82
+ readonly name: "tokenIn";
83
+ readonly type: "address";
84
+ }, {
85
+ readonly name: "tokenOut";
86
+ readonly type: "address";
87
+ }, {
88
+ readonly name: "amountIn";
89
+ readonly type: "uint256";
90
+ }, {
91
+ readonly name: "minAmountOut";
92
+ readonly type: "uint256";
93
+ }, {
94
+ readonly name: "deadline";
95
+ readonly type: "uint256";
96
+ }, {
97
+ readonly name: "nonce";
98
+ readonly type: "uint256";
99
+ }, {
100
+ readonly name: "signature";
101
+ readonly type: "bytes";
102
+ }];
103
+ }];
104
+ readonly outputs: readonly [{
105
+ readonly name: "intentHash";
106
+ readonly type: "bytes32";
107
+ }];
108
+ readonly stateMutability: "payable";
109
+ }, {
110
+ readonly type: "function";
111
+ readonly name: "cancelIntent";
112
+ readonly inputs: readonly [{
113
+ readonly name: "intentHash";
114
+ readonly type: "bytes32";
115
+ }];
116
+ readonly outputs: readonly [];
117
+ readonly stateMutability: "nonpayable";
118
+ }, {
119
+ readonly type: "function";
120
+ readonly name: "getIntentStatus";
121
+ readonly inputs: readonly [{
122
+ readonly name: "intentHash";
123
+ readonly type: "bytes32";
124
+ }];
125
+ readonly outputs: readonly [{
126
+ readonly name: "";
127
+ readonly type: "uint8";
128
+ }];
129
+ readonly stateMutability: "view";
130
+ }, {
131
+ readonly type: "function";
132
+ readonly name: "getNonce";
133
+ readonly inputs: readonly [{
134
+ readonly name: "agent";
135
+ readonly type: "address";
136
+ }];
137
+ readonly outputs: readonly [{
138
+ readonly name: "";
139
+ readonly type: "uint256";
140
+ }];
141
+ readonly stateMutability: "view";
142
+ }, {
143
+ readonly type: "function";
144
+ readonly name: "domainSeparator";
145
+ readonly inputs: readonly [];
146
+ readonly outputs: readonly [{
147
+ readonly name: "";
148
+ readonly type: "bytes32";
149
+ }];
150
+ readonly stateMutability: "view";
151
+ }, {
152
+ readonly type: "function";
153
+ readonly name: "intents";
154
+ readonly inputs: readonly [{
155
+ readonly name: "intentHash";
156
+ readonly type: "bytes32";
157
+ }];
158
+ readonly outputs: readonly [{
159
+ readonly name: "agent";
160
+ readonly type: "address";
161
+ }, {
162
+ readonly name: "tokenIn";
163
+ readonly type: "address";
164
+ }, {
165
+ readonly name: "tokenOut";
166
+ readonly type: "address";
167
+ }, {
168
+ readonly name: "amountIn";
169
+ readonly type: "uint256";
170
+ }, {
171
+ readonly name: "minAmountOut";
172
+ readonly type: "uint256";
173
+ }, {
174
+ readonly name: "deadline";
175
+ readonly type: "uint256";
176
+ }, {
177
+ readonly name: "status";
178
+ readonly type: "uint8";
179
+ }];
180
+ readonly stateMutability: "view";
181
+ }];
182
+ /**
183
+ * ERC20 ABI
184
+ */
185
+ export declare const ERC20_ABI: readonly [{
186
+ readonly type: "function";
187
+ readonly name: "approve";
188
+ readonly inputs: readonly [{
189
+ readonly name: "spender";
190
+ readonly type: "address";
191
+ }, {
192
+ readonly name: "amount";
193
+ readonly type: "uint256";
194
+ }];
195
+ readonly outputs: readonly [{
196
+ readonly name: "";
197
+ readonly type: "bool";
198
+ }];
199
+ readonly stateMutability: "nonpayable";
200
+ }, {
201
+ readonly type: "function";
202
+ readonly name: "allowance";
203
+ readonly inputs: readonly [{
204
+ readonly name: "owner";
205
+ readonly type: "address";
206
+ }, {
207
+ readonly name: "spender";
208
+ readonly type: "address";
209
+ }];
210
+ readonly outputs: readonly [{
211
+ readonly name: "";
212
+ readonly type: "uint256";
213
+ }];
214
+ readonly stateMutability: "view";
215
+ }, {
216
+ readonly type: "function";
217
+ readonly name: "balanceOf";
218
+ readonly inputs: readonly [{
219
+ readonly name: "account";
220
+ readonly type: "address";
221
+ }];
222
+ readonly outputs: readonly [{
223
+ readonly name: "";
224
+ readonly type: "uint256";
225
+ }];
226
+ readonly stateMutability: "view";
227
+ }, {
228
+ readonly type: "function";
229
+ readonly name: "decimals";
230
+ readonly inputs: readonly [];
231
+ readonly outputs: readonly [{
232
+ readonly name: "";
233
+ readonly type: "uint8";
234
+ }];
235
+ readonly stateMutability: "view";
236
+ }, {
237
+ readonly type: "function";
238
+ readonly name: "symbol";
239
+ readonly inputs: readonly [];
240
+ readonly outputs: readonly [{
241
+ readonly name: "";
242
+ readonly type: "string";
243
+ }];
244
+ readonly stateMutability: "view";
245
+ }];
246
+ /**
247
+ * Uniswap V3 Quoter ABI
248
+ */
249
+ export declare const QUOTER_ABI: readonly [{
250
+ readonly type: "function";
251
+ readonly name: "quoteExactInputSingle";
252
+ readonly inputs: readonly [{
253
+ readonly name: "params";
254
+ readonly type: "tuple";
255
+ readonly components: readonly [{
256
+ readonly name: "tokenIn";
257
+ readonly type: "address";
258
+ }, {
259
+ readonly name: "tokenOut";
260
+ readonly type: "address";
261
+ }, {
262
+ readonly name: "amountIn";
263
+ readonly type: "uint256";
264
+ }, {
265
+ readonly name: "fee";
266
+ readonly type: "uint24";
267
+ }, {
268
+ readonly name: "sqrtPriceLimitX96";
269
+ readonly type: "uint160";
270
+ }];
271
+ }];
272
+ readonly outputs: readonly [{
273
+ readonly name: "amountOut";
274
+ readonly type: "uint256";
275
+ }, {
276
+ readonly name: "sqrtPriceX96After";
277
+ readonly type: "uint160";
278
+ }, {
279
+ readonly name: "initializedTicksCrossed";
280
+ readonly type: "uint32";
281
+ }, {
282
+ readonly name: "gasEstimate";
283
+ readonly type: "uint256";
284
+ }];
285
+ readonly stateMutability: "nonpayable";
286
+ }];
287
+ //# sourceMappingURL=abi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"abi.d.ts","sourceRoot":"","sources":["../src/abi.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyGb,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0CZ,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyBb,CAAC"}