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
40 changes: 40 additions & 0 deletions v2/earn_vault_data/python/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Earn Vault Data - Python Example

This example demonstrates how to get the top vault sorted by 30-day net annualized APY (after fees) using the Compass API Python SDK.

## Prerequisites

- Python 3.9+ installed
- A Compass API key ([Get one here](https://auth-compasslabs-ai.auth.eu-west-2.amazoncognito.com/login?client_id=2l366l2b3dok7k71nbnu8r1u36&redirect_uri=https://api.compasslabs.ai/auth/callback&response_type=code&scope=openid+email+profile))

## Setup

1. Install dependencies:
```bash
pip install compass-api-sdk python-dotenv
```

2. Create a `.env` file with your API key:
```
COMPASS_API_KEY=your_api_key_here
```

## Run

```bash
python main.py
```

## What This Does

This example fetches the top vault sorted by 30-day net annualized APY (after fees) from the `/v2/earn/vaults` endpoint. It displays the vault name and its 30-day annualized return percentage.

The example uses `order_by="one_month_cagr_net"` and `direction="desc"` to get vault with the highest 30-day net annualized return.

## Endpoint Overview

The `/v2/earn/vaults` endpoint provides access to all available Earn vaults with comprehensive metrics. You can:

- **Sort by different metrics**: `lifetime_return`, `one_month_cagr_net`, `three_months_cagr_net`, `three_months_sharpe_net`, `current_nav`
- **Filter by chain**: `ETHEREUM`, `BASE`, `ARBITRUM`
- **Paginate results**: Use `offset` and `limit` to fetch multiple vaults
24 changes: 24 additions & 0 deletions v2/earn_vault_data/python/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# SNIPPET START 1
from compass_api_sdk import CompassAPI, models
import os
from dotenv import load_dotenv

load_dotenv()

COMPASS_API_KEY = os.getenv("COMPASS_API_KEY")

with CompassAPI(api_key_auth=COMPASS_API_KEY) as compass_api:
# SNIPPET END 1

# SNIPPET START 2
# Top vault sorted by 30-day net annualized APY (after fees)
res = compass_api.earn.earn_vaults(
order_by="one_month_cagr_net",
chain=models.V2EarnVaultsChain.ETHEREUM,
direction=models.Direction.DESC,
offset=0,
limit=1,
)
vault = res.vaults[0]
print(f"{vault.name}: {float(vault.one_month_cagr_net) * 100:.2f}% (30 day annualized return)")
# SNIPPET END 2
9 changes: 9 additions & 0 deletions v2/earn_vault_data/python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
name = "earn_vault_ranker_python_example"
version = "1.0.0"
description = "Example: Earn Vault Ranker using Compass API"
dependencies = [
"compass-api-sdk",
"python-dotenv",
]

46 changes: 46 additions & 0 deletions v2/earn_vault_data/typescript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Earn Vault Data - TypeScript Example

This example demonstrates how to get the top vault sorted by 30-day net annualized APY (after fees) using the Compass API TypeScript SDK.

## Prerequisites

- Node.js 18+ installed
- A Compass API key ([Get one here](https://auth-compasslabs-ai.auth.eu-west-2.amazoncognito.com/login?client_id=2l366l2b3dok7k71nbnu8r1u36&redirect_uri=https://api.compasslabs.ai/auth/callback&response_type=code&scope=openid+email+profile))

## Setup

1. Install dependencies:
```bash
npm install
```

2. Create a `.env` file with your API key:
```
COMPASS_API_KEY=your_api_key_here
```

## Run

```bash
npx tsx src/index.ts
```

Or build and run:
```bash
npm run build
npm start
```

## What This Does

This example fetches the top vault sorted by 30-day net annualized APY (after fees) from the `/v2/earn/vaults` endpoint. It displays the vault name and its 30-day annualized return percentage.

The example uses `orderBy="one_month_cagr_net"` and `direction="desc"` to get vault with highest 30-day net annualized return.

## Endpoint Overview

The `/v2/earn/vaults` endpoint provides access to all available Earn vaults with comprehensive metrics. You can:

- **Sort by different metrics**: `lifetime_return`, `one_month_cagr_net`, `three_months_cagr_net`, `three_months_sharpe_net`, `current_nav`
- **Filter by chain**: `ethereum`, `base`, `arbitrum`
- **Paginate results**: Use `offset` and `limit` to fetch multiple vaults
26 changes: 26 additions & 0 deletions v2/earn_vault_data/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "earn_vault_ranker_typescript_example",
"version": "1.0.0",
"type": "module",
"main": "index.js",
"scripts": {
"build": "tsc",
"start": "tsc && node dist/index.js",
"dev": "ts-node --esm src/index.ts"
},
"author": "",
"license": "ISC",
"description": "Example: Earn Vault Ranker using Compass API",
"dependencies": {
"@compass-labs/api-sdk": "^1.3.5",
"dotenv": "^16.5.0",
"viem": "^2.31.0"
},
"devDependencies": {
"@types/node": "^24.0.0",
"prettier": "^3.6.2",
"ts-node": "^10.9.2",
"typescript": "^5.8.3"
}
}

32 changes: 32 additions & 0 deletions v2/earn_vault_data/typescript/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// SNIPPET START 1
import { CompassApiSDK } from "@compass-labs/api-sdk";
import dotenv from "dotenv";

dotenv.config();

const COMPASS_API_KEY = process.env.COMPASS_API_KEY as string;

const compassApiSDK = new CompassApiSDK({
apiKeyAuth: COMPASS_API_KEY,
});
// SNIPPET END 1

// SNIPPET START 2
async function run() {
// Top vault sorted by 30-day net annualized APY (after fees)
const result = await compassApiSDK.earn.earnVaults({
orderBy: "one_month_cagr_net",
direction: "desc",
offset: 0,
limit: 1,
chain: "ethereum",
});
const vault = result.vaults[0];
const apy = vault.oneMonthCagrNet
? (Number(vault.oneMonthCagrNet) * 100).toFixed(2)
: "N/A";
console.log(`${vault.name}: ${apy}% (30 day annualized return)`);
}

run();
// SNIPPET END 2
17 changes: 17 additions & 0 deletions v2/earn_vault_data/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"compilerOptions": {
"target": "es2020",
"module": "ESNext",
"lib": ["ES2020"],
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"strict": true,
"resolveJsonModule": true,
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}

Loading