AI Agent for On‑Chain Finance: multi‑chain token swaps, lending / borrowing (Echelon ecosystem), DeFi data insights, and cross‑chain atomic swap flows between Aptos and Ethereum.
nexAI is an AI‑driven autonomous assistant that:
- Executes or prepares token swaps on supported DEX / router backends.
- Interacts with lending & borrowing protocols (Echelon — deposits, positions data, markets info).
- Retrieves structured on‑chain & DeFi analytics (prices, TVL, protocol stats, coin metadata).
- Orchestrates cross‑chain atomic swap intent flows between Aptos and Ethereum (in progress: finalization logic / relayer layer).
- Explains actions before broadcasting transactions for transparency.

| Domain | Capability |
|---|---|
| Swaps | Discover + construct token swap transactions. |
| Lending / Borrowing | Query markets, health, balances (Echelon), prepare deposit/withdraw actions. |
| DeFi Data | Fetch token info, prices, protocol TVL, formatting utilities. |
| Cross‑Chain Atomic Swap | Initiate Aptos ↔ Ethereum atomic swap flow (hash‑time / intent model WIP). |
| AI Reasoning | LangChain + OpenAI planning with tool invocation and streamed responses. |
- User prompts the AI (chat interface).
- Model plans which on‑chain tools to invoke (price, market, balances, etc.).
- Tools return structured JSON; AI synthesizes human‑readable explanation + proposed transaction steps.
- For swaps / lending the agent can output prepared transaction payloads (Aptos Move or EVM calldata) pending user signing.
- For cross‑chain atomic swaps it initiates a two‑leg flow (lock / commit on origin, claim / finalize on destination) — relayer / proof infra under active development.
- Runtime: Next.js (frontend) + API route for streaming AI responses.
- AI: LangChain, OpenAI Chat (streaming / tool calls).
- Chains: Aptos (
@aptos-labs/ts-sdk) & Ethereum testnet (Sepolia) (EVM integration layer & ABIs to be finalized). - Internal SDK:
@nexai/echelon-sdkfor Echelon protocol primitives. - Monorepo: Yarn 4 workspaces + Turborepo.
MULTISWAPPER CONTRACT https://explorer.aptoslabs.com/txn/0x74a454eb3a42e48decdf3826762e452b4c1cf3628eb2af8c4eadcdd0fc3a46ab?network=testnet
{
"Result": {
"transaction_hash": "0x74a454eb3a42e48decdf3826762e452b4c1cf3628eb2af8c4eadcdd0fc3a46ab",
"gas_used": 8125,
"gas_unit_price": 100,
"sender": "76b738dfadf6bb561b53de17deee8b49e1250601ac5d4085870453b96991913c",
"sequence_number": 0,
"replay_protector": {
"SequenceNumber": 0
},
"success": true,
"timestamp_us": 1755966374158298,
"version": 6845491953,
"vm_status": "Executed successfully"
}
}
```
## 🔑 Environment
Create `packages/frontend/.env.local`:
OPENAI_API_KEY=sk-...
Add any RPC keys (Infura / custom) as you extend Ethereum interactions.
## ▶️ Quick Start
```bash
# Install
yarn install
# Dev (frontend + builds dependencies automatically)
yarn workspace @nexai/frontend dev
# Build production
yarn workspace @nexai/frontend build
# Run production
yarn workspace @nexai/frontend start
Add a new tool:
- Create a file under
packages/frontend/src/tools/exporting a LangChainDynamicTool. - Import and append it to the tools list in
pages/api/chat.ts. - Reference it naturally in a prompt; the model can now select it.
Current scope:
- Address registry & contract addresses defined (
contract.ts). - Atomic swap conceptual flow (hash‑time / conditional release) under implementation.
- UI simply reflects direction & amount (execution layer intentionally minimal until final relayer spec is merged).
Planned next steps:
- Minimal ABIs (EVM) & Move entry function catalog.
- HTLC / intent commit on origin chain.
- Event listener + relayer service -> destination finalize call.
- Safety checks (expiry, refund path) surfaced in AI explanations.
- EVM calldata builder for swaps & atomic swap leg.
- Echelon advanced lending actions (liquidation risk analysis, leverage suggestions — advisory only).
- Transaction simulation + risk scoring.
- Persistent conversation + action audit trail.
- Relayer / oracle for atomic swap finalization.
- Test suite (unit + integration) with mock chain state.