Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
# skill entry point for the agent.
#
# packages/connector-ui/public/skills/
# Served at https://agentconnect.polygon.technology/skills/ — agents fetch
# skill files at runtime from this URL.
# Served at https://agentconnect.polygon.technology/skills/ — full tree.
#
# packages/connector-ui/public/<sub-skill>/
# Also served at https://agentconnect.polygon.technology/<sub-skill>/SKILL.md
# (e.g. /polygon-discovery/SKILL.md) to match the URLs in the root SKILL.md.
#
# packages/polygon-agent-cli/skills/
# Bundled inside the published npm package so skills are available
Expand Down Expand Up @@ -41,15 +44,23 @@ function copyDir(src, dest) {
// Sync root SKILL.md to connector-ui public root (served at /SKILL.md)
fs.copyFileSync('skills/SKILL.md', 'packages/connector-ui/public/SKILL.md');

// Sync to connector-ui (verbatim)
// Sync to connector-ui (verbatim — full tree under /skills/)
copyDir('skills', 'packages/connector-ui/public/skills');

// Also serve each sub-skill at the root level (e.g. /polygon-discovery/SKILL.md)
// to match the URLs referenced in the root SKILL.md
for (const entry of fs.readdirSync('skills', { withFileTypes: true })) {
if (entry.isDirectory()) {
copyDir(path.join('skills', entry.name), path.join('packages/connector-ui/public', entry.name));
}
}

// Sync to CLI package (rewrite name field in root SKILL.md only)
copyDir('skills', 'packages/polygon-agent-cli/skills');
const cliSkill = path.join('packages/polygon-agent-cli/skills/SKILL.md');
fs.writeFileSync(cliSkill, fs.readFileSync(cliSkill, 'utf8').replace('name: polygon-agent-kit', 'name: polygon-agent-cli'));
"
git add packages/connector-ui/public/SKILL.md packages/connector-ui/public/skills packages/polygon-agent-cli/skills
git add packages/connector-ui/public/SKILL.md packages/connector-ui/public/skills packages/connector-ui/public/polygon-* packages/polygon-agent-cli/skills

pnpm exec lint-staged
pnpm run typecheck
209 changes: 209 additions & 0 deletions packages/connector-ui/public/polygon-defi/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
---
name: polygon-defi
description: DeFi operations on Polygon using the Polygon Agent CLI. Covers same-chain token swaps, cross-chain bridging, and yield deposits into Aave v3 and Morpho vaults via Trails earn pool discovery. All commands dry-run by default — add --broadcast to execute.
---

# Polygon DeFi Skill

## Swap Tokens (Same-Chain)

```bash
# Dry-run — shows route and output amount
polygon-agent swap --from USDC --to USDT --amount 5

# Execute
polygon-agent swap --from USDC --to USDT --amount 5 --broadcast

# Custom slippage (default 0.5%)
polygon-agent swap --from USDC --to USDT --amount 5 --slippage 0.005 --broadcast
```

## Bridge Tokens (Cross-Chain)

```bash
# Bridge USDC from Polygon to Arbitrum
polygon-agent swap --from USDC --to USDC --amount 0.5 --to-chain arbitrum --broadcast

# Bridge to other supported chains
polygon-agent swap --from USDC --to USDC --amount 1 --to-chain optimism --broadcast
polygon-agent swap --from USDC --to USDC --amount 1 --to-chain base --broadcast
polygon-agent swap --from USDC --to USDC --amount 1 --to-chain mainnet --broadcast
```

Valid `--to-chain` values: `polygon`, `amoy`, `mainnet`, `arbitrum`, `optimism`, `base`.

## Query Earn Pools

Use `getEarnPools` to discover live yield opportunities across protocols before deciding where to deposit.

### HTTP

```bash
curl --request POST \
--url https://trails-api.sequence.app/rpc/Trails/GetEarnPools \
--header 'Content-Type: application/json' \
--data '{"chainIds": [137]}'
```

All request fields are optional — omit any you don't need to filter on.

| Field | Type | Description |
|-------|------|-------------|
| `chainIds` | `number[]` | Filter by chain (e.g. `[137]` for Polygon mainnet) |
| `protocols` | `string[]` | Filter by protocol name, e.g. `["Aave"]`, `["Morpho"]` |
| `minTvl` | `number` | Minimum TVL in USD |
| `maxApy` | `number` | Maximum APY (useful to exclude outlier/at-risk pools) |

### Fetch (agent code)

The API key is the project access key already available to the agent (`SEQUENCE_PROJECT_ACCESS_KEY`).

```typescript
const res = await fetch('https://trails-api.sequence.app/rpc/Trails/GetEarnPools', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ chainIds: [137] }),
});
const { pools } = await res.json();
```

### Response Schema

```typescript
interface GetEarnPoolsResponse {
pools: EarnPool[];
timestamp: string; // ISO-8601 fetch time
cached: boolean;
}

interface EarnPool {
id: string; // "{protocol}-{chainId}-{address}"
name: string; // e.g. "USDC Market"
protocol: string; // "Aave" | "Morpho"
chainId: number;
apy: number; // annualised yield as a decimal percent
tvl: number; // USD
token: PoolTokenInfo;
depositAddress: string; // contract to approve/send to
isActive: boolean;
poolUrl?: string;
protocolUrl?: string;
wrappedTokenGatewayAddress?: string; // non-null for Aave native-token markets
}

interface PoolTokenInfo {
symbol: string;
name: string;
address: string;
decimals: number;
logoUrl?: string;
}
```

> **Tip:** `wrappedTokenGatewayAddress` is set on Aave markets that accept a wrapped native token (WPOL, WETH). Pass this address instead of `depositAddress` when depositing POL/ETH directly.

---

## Deposit to Earn Yield

Pool discovery uses `TrailsApi.getEarnPools` — picks the most liquid pool (highest TVL) for the asset on the current chain. No hardcoded addresses — the pool is resolved at runtime.

```bash
# Dry-run — shows pool name, APY, TVL, and deposit address before committing
polygon-agent deposit --asset USDC --amount 0.3

# Execute — deposits into the highest-TVL active pool
polygon-agent deposit --asset USDC --amount 0.3 --broadcast

# Filter by protocol
polygon-agent deposit --asset USDC --amount 0.3 --protocol aave --broadcast
polygon-agent deposit --asset USDC --amount 0.3 --protocol morpho --broadcast
```

### Supported Protocols

| Protocol | Encoding | Description |
|----------|----------|-------------|
| **Aave v3** | `supply(asset, amount, onBehalfOf, referralCode)` | Lending pool deposit |
| **Morpho** | `deposit(assets, receiver)` — ERC-4626 | Vault deposit |

Vault/pool addresses are resolved dynamically from Trails — they are not hardcoded. The dry-run output includes `depositAddress` so you can inspect the exact contract before broadcasting.

### Session Whitelisting

If the deposit is rejected with a session permission error, the pool's contract address needs to be whitelisted when creating the wallet session:

```bash
# 1. Dry-run first to get the depositAddress
polygon-agent deposit --asset USDC --amount 0.3
# → note the depositAddress in output

# 2. Re-create wallet session with that contract whitelisted
polygon-agent wallet create --contract <depositAddress>

# 3. Retry
polygon-agent deposit --asset USDC --amount 0.3 --broadcast
```

When creating a wallet specifically for yield, add `--contract` flags for all intended vaults upfront and omit `--usdc-limit`:

```bash
polygon-agent wallet create \
--contract 0x794a61358d6845594f94dc1db02a252b5b4814ad \
--contract 0x781fb7f6d845e3be129289833b04d43aa8558c42
```

### Yield Vault Contract Whitelist

#### Polygon Mainnet (chainId 137)

| Protocol | Asset | Address |
|----------|-------|---------|
| Aave V3 Pool (all markets) | USDC, USDT, WETH, WMATIC… | `0x794a61358d6845594f94dc1db02a252b5b4814ad` |
| Morpho Compound USDC | USDC | `0x781fb7f6d845e3be129289833b04d43aa8558c42` |
| Morpho Compound WETH | WETH | `0xf5c81d25ee174d83f1fd202ca94ae6070d073ccf` |
| Morpho Compound POL | POL | `0x3f33f9f7e2d7cfbcbdf8ea8b870a6e3d449664c2` |

#### Katana (chainId 747474) — Morpho Vaults

| Vault | Asset | TVL | Address |
|-------|-------|-----|---------|
| Gauntlet USDT | USDT | ~$97M | `0x1ecdc3f2b5e90bfb55ff45a7476ff98a8957388e` |
| Steakhouse Prime USDC | USDC | ~$54M | `0x61d4f9d3797ba4da152238c53a6f93fb665c3c1d` |
| Yearn OG ETH | WETH | ~$16M | `0xfade0c546f44e33c134c4036207b314ac643dc2e` |
| Yearn OG USDC | USDC | ~$16M | `0xce2b8e464fc7b5e58710c24b7e5ebfb6027f29d7` |
| Gauntlet USDC | USDC | ~$8M | `0xe4248e2105508fcbad3fe95691551d1af14015f7` |
| Yearn OG USDT | USDT | ~$8M | `0x8ed68f91afbe5871dce31ae007a936ebe8511d47` |
| Gauntlet WETH | WETH | ~$6M | `0xc5e7ab07030305fc925175b25b93b285d40dcdff` |
| Hyperithm vbUSDC Apex | USDC | ~$3M | `0xef77f8c53af95f3348cee0fb2a02ee02ab9cdca5` |

---

## Full DeFi Flow Example

```bash
# 1. Check balances
polygon-agent balances

# 2. Swap POL → USDC
polygon-agent swap --from POL --to USDC --amount 1 --broadcast

# 3. Deposit USDC into highest-TVL yield pool
polygon-agent deposit --asset USDC --amount 1 --broadcast
# → protocol: morpho (or aave, whichever has highest TVL at the time)
# → poolApy shown in dry-run output

# 4. Bridge remaining USDC to Arbitrum
polygon-agent swap --from USDC --to USDC --amount 0.5 --to-chain arbitrum --broadcast
```

---

## Troubleshooting

| Error | Cause | Fix |
|-------|-------|-----|
| `Deposit session rejected` | Pool contract not whitelisted in session | Re-create wallet with `--contract <depositAddress>` |
| `Protocol X not yet supported` | Trails returned a protocol other than aave/morpho | Use `polygon-agent swap` to obtain the yield-bearing token manually |
| `Fee option errors` | Wallet has insufficient balance | Run `polygon-agent balances` and fund the wallet |
| `swap`: no route found | Insufficient liquidity for the pair | Try a different amount or token pair |
117 changes: 117 additions & 0 deletions packages/connector-ui/public/polygon-discovery/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
name: polygon-discovery
description: x402 Bazaar — pay-per-call API services accessible via the Polygon Agent CLI. No API keys or subscriptions needed. Each call costs a small USDC amount drawn from the agent's smart wallet. Covers web search, news, AI image generation, Twitter/X data, code review, text summarization, sentiment analysis, and article extraction.
---

# x402 Bazaar Services

Pay-per-call APIs accessible via `x402-pay`. No API keys or subscriptions — each call costs a small USDC amount drawn from your wallet. The CLI detects the 402 response, funds the exact amount, and retries automatically.

**Catalog:** `GET https://x402-api.onrender.com/api/catalog?status=online`

---

## Prerequisites — Check Before Any x402 Call

Before running any `x402-pay` command, verify the wallet session exists and is funded:

```bash
# Check if a wallet is configured
polygon-agent wallet list
```

**If no wallet is listed**, the smart session has not been created. Run through the complete setup flow before proceeding:

1. `polygon-agent setup --name "MyAgent"` — creates EOA and Sequence project
2. `polygon-agent wallet create --usdc-limit 100` — opens browser for session approval; enter the 6-digit code when prompted
3. `polygon-agent wallet address` — get address, then fund via https://agentconnect.polygon.technology
4. `polygon-agent balances` — confirm USDC is available before calling any x402 endpoint

**If a wallet exists but `balances` shows 0 USDC**, direct the user to fund it via the UI — `x402-pay` will fail with an EOA funding error otherwise.

Once a funded wallet is confirmed, proceed with the x402 calls below.

---

## Read Twitter/X Profile

$0.005 USDC per call.

> **Note:** The catalog proxy (`/api/call/99063826-...`) returns 401 or HTML for this service.
> Use the direct endpoint below instead.

```bash
# Profile + recent tweets
polygon-agent x402-pay \
--url "https://x402-api.onrender.com/api/twitter?user=<username>" \
--wallet main --method POST

# Specific tweet
polygon-agent x402-pay \
--url "https://x402-api.onrender.com/api/twitter?tweet=https://x.com/user/status/<id>" \
--wallet main --method POST
```

Returns: follower/following counts and tweet metrics.

**Troubleshooting:** If the direct endpoint fails, check the live catalog for the current URL:
```bash
curl -s "https://x402-api.onrender.com/api/catalog?status=online" \
| jq '.[] | select(.name | test("twitter"; "i"))'
```

---

## Generate an AI Image

$0.02 USDC per call. Powered by Google Gemini.

```bash
polygon-agent x402-pay \
--url "https://x402-api.onrender.com/api/call/2998d205-94d9-4f7e-8f8a-201a090a5530?prompt=<description>&size=512" \
--wallet main --method GET
```

`size` options: `256`, `512`, `1024`. Returns JSON with `data_uri` (base64 PNG) for embedding.

---

## Review Code for Bugs & Security

$0.01 USDC per call. Powered by GPT-4o.

```bash
polygon-agent x402-pay \
--url "https://x402-api.onrender.com/api/call/7f21e675-9fdc-4ba3-9a8d-145c6ac703c7" \
--wallet main \
--body '{"code": "<snippet>", "language": "<python|javascript|go|...>"}'
```

Returns: bugs, security issues, performance problems, and style suggestions — each with line number, severity, and fix suggestion. Plus an overall quality score.

---

## Other Services

| Service | Price | Endpoint | Key param |
|---------|-------|----------|-----------|
| Web search (DuckDuckGo) | $0.005 | `9b0f5b5f-8e6c-4b55-a264-008e4e490c26` | `?q=<query>&max=10` |
| Latest news (Google News) | $0.005 | `266d045f-bae2-4c71-9469-3638ec860fc4` | `?topic=<topic>&lang=en` |
| Summarize text (GPT-4o-mini) | $0.01 | `dd9b5098-700d-47a9-a41a-c9eae66ca49d` | `?text=<text>&maxLength=200` |
| Article → Markdown | $0.005 | `87b50238-5b99-4521-b5e1-7515a9c1526d` | `?url=<article-url>` |
| Sentiment analysis (GPT-4o-mini) | $0.005 | `66d68ca6-a8d9-41a3-b024-a3fac2f5c7ba` | `?text=<text>` |

All use GET via `polygon-agent x402-pay --url "https://x402-api.onrender.com/api/call/<id><params>" --wallet main --method GET`.

---

## How x402 Works

1. CLI sends the request to the endpoint
2. Endpoint responds with `HTTP 402 Payment Required` + payment details
3. CLI automatically funds the builder EOA with the exact token amount from the smart wallet
4. EOA signs an EIP-3009 payment authorization
5. CLI retries the original request with the payment header
6. Response is returned — the whole flow is transparent to the agent

Chain and token are auto-detected from the 402 response. No manual configuration needed.
Loading
Loading