From 5f5856813264647eca157c66550f08a29ce556e1 Mon Sep 17 00:00:00 2001 From: Piet Duijnstee Date: Wed, 26 Nov 2025 15:14:47 +0100 Subject: [PATCH 1/5] Add earn vault ranker example - top 3 vaults by 30d Net APY --- v2/earn_vault_ranker/python/README.md | 47 ++++++++++++++ v2/earn_vault_ranker/python/main.py | 63 ++++++++++++++++++ v2/earn_vault_ranker/python/pyproject.toml | 9 +++ v2/earn_vault_ranker/typescript/README.md | 48 ++++++++++++++ v2/earn_vault_ranker/typescript/package.json | 26 ++++++++ v2/earn_vault_ranker/typescript/src/index.ts | 64 +++++++++++++++++++ v2/earn_vault_ranker/typescript/tsconfig.json | 17 +++++ 7 files changed, 274 insertions(+) create mode 100644 v2/earn_vault_ranker/python/README.md create mode 100644 v2/earn_vault_ranker/python/main.py create mode 100644 v2/earn_vault_ranker/python/pyproject.toml create mode 100644 v2/earn_vault_ranker/typescript/README.md create mode 100644 v2/earn_vault_ranker/typescript/package.json create mode 100644 v2/earn_vault_ranker/typescript/src/index.ts create mode 100644 v2/earn_vault_ranker/typescript/tsconfig.json diff --git a/v2/earn_vault_ranker/python/README.md b/v2/earn_vault_ranker/python/README.md new file mode 100644 index 00000000..366ee166 --- /dev/null +++ b/v2/earn_vault_ranker/python/README.md @@ -0,0 +1,47 @@ +# Earn Vault Ranker - Python Example + +This example demonstrates how to get the top 3 vaults sorted by 30d Net 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 (make sure you have the latest version): +```bash +pip install --upgrade compass-api-sdk python-dotenv +``` + +Or if using `uv`: +```bash +uv pip install compass-api-sdk python-dotenv +``` + +2. Copy the example environment file: +```bash +cp .env.example .env +``` + +3. Fill in your `.env` file with your actual values: + - `COMPASS_API_KEY`: Your Compass API key + +## Run + +```bash +python main.py +``` + +## What This Does + +This example fetches the top 3 vaults sorted by 30d Net APY (after fees) from highest to lowest. For each vault, it displays: + +- **Protocol name** & **Vault address** +- **30d Net APY (after fees)** - `one_month_cagr_net` +- **3m Net APY (after fees)** - `three_months_cagr_net` +- **3m Sharpe Ratio** - `three_months_sharpe_net` +- **Denomination** - The underlying token (e.g., USDC, ETH) +- **TVL** - Total Value Locked (if available) - `current_nav` + +The example uses the `/v2/earn/vaults` endpoint with `order_by="one_month_cagr_net"` and `direction="desc"` to get the highest performing vaults by 30-day net APY. diff --git a/v2/earn_vault_ranker/python/main.py b/v2/earn_vault_ranker/python/main.py new file mode 100644 index 00000000..914e4bd1 --- /dev/null +++ b/v2/earn_vault_ranker/python/main.py @@ -0,0 +1,63 @@ +# SNIPPET START 1 +# Import Libraries & Environment Variables +from compass_api_sdk import CompassAPI, models +import os +from dotenv import load_dotenv + +load_dotenv() + +COMPASS_API_KEY = os.getenv("COMPASS_API_KEY") +# SNIPPET END 1 + +# SNIPPET START 2 +# Initialize Compass SDK +compass = CompassAPI(api_key_auth=COMPASS_API_KEY) +# SNIPPET END 2 + +# SNIPPET START 3 +# Get top 3 vaults sorted by 30d Net APY (after fees) high to low +with CompassAPI(api_key_auth=COMPASS_API_KEY) as compass_api: + # Fetch vaults ordered by 30d Net APY (one_month_cagr_net) descending + vaults_response = compass_api.earn.earn_vaults( + chain=models.Chain.BASE, + order_by="one_month_cagr_net", + direction=models.Direction.DESC, + offset=0, + limit=3, + ) + + print("Top 3 Vaults by 30d Net APY (after fees):\n") + + for i, vault in enumerate(vaults_response.vaults, 1): + # Format APY values as percentages + one_month_apy = ( + f"{float(vault.one_month_cagr_net) * 100:.2f}%" + if vault.one_month_cagr_net + else "N/A" + ) + three_month_apy = ( + f"{float(vault.three_months_cagr_net) * 100:.2f}%" + if vault.three_months_cagr_net + else "N/A" + ) + sharpe_ratio = ( + f"{float(vault.three_months_sharpe_net):.2f}" + if vault.three_months_sharpe_net + else "N/A" + ) + tvl = ( + f"{float(vault.current_nav):,.2f} {vault.denomination}" + if vault.current_nav + else "N/A" + ) + + print(f"{i}. {vault.name}") + print(f" Protocol: {vault.protocol}") + print(f" Vault Address: {vault.address}") + print(f" 30d Net APY (after fees): {one_month_apy}") + print(f" 3m Net APY (after fees): {three_month_apy}") + print(f" 3m Sharpe Ratio: {sharpe_ratio}") + print(f" Denomination: {vault.denomination}") + print(f" TVL: {tvl}") + print() +# SNIPPET END 3 diff --git a/v2/earn_vault_ranker/python/pyproject.toml b/v2/earn_vault_ranker/python/pyproject.toml new file mode 100644 index 00000000..3f1fb062 --- /dev/null +++ b/v2/earn_vault_ranker/python/pyproject.toml @@ -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", +] + diff --git a/v2/earn_vault_ranker/typescript/README.md b/v2/earn_vault_ranker/typescript/README.md new file mode 100644 index 00000000..5bd8f314 --- /dev/null +++ b/v2/earn_vault_ranker/typescript/README.md @@ -0,0 +1,48 @@ +# Earn Vault Ranker - TypeScript Example + +This example demonstrates how to get the top 3 vaults sorted by 30d Net 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. Copy the example environment file: +```bash +cp .env.example .env +``` + +3. Fill in your `.env` file with your actual values: + - `COMPASS_API_KEY`: Your Compass API key + +## Run + +```bash +npm run dev +``` + +Or build and run: +```bash +npm run build +npm start +``` + +## What This Does + +This example fetches the top 3 vaults sorted by 30d Net APY (after fees) from highest to lowest. For each vault, it displays: + +- **Protocol name** & **Vault address** +- **30d Net APY (after fees)** - `one_month_cagr_net` +- **3m Net APY (after fees)** - `three_months_cagr_net` +- **3m Sharpe Ratio** - `three_months_sharpe_net` +- **Denomination** - The underlying token (e.g., USDC, ETH) +- **TVL** - Total Value Locked (if available) - `current_nav` + +The example uses the `/v2/earn/vaults` endpoint with `orderBy="one_month_cagr_net"` and `direction="desc"` to get the highest performing vaults by 30-day net APY. diff --git a/v2/earn_vault_ranker/typescript/package.json b/v2/earn_vault_ranker/typescript/package.json new file mode 100644 index 00000000..b94a602f --- /dev/null +++ b/v2/earn_vault_ranker/typescript/package.json @@ -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" + } +} + diff --git a/v2/earn_vault_ranker/typescript/src/index.ts b/v2/earn_vault_ranker/typescript/src/index.ts new file mode 100644 index 00000000..476f786f --- /dev/null +++ b/v2/earn_vault_ranker/typescript/src/index.ts @@ -0,0 +1,64 @@ +// SNIPPET START 1 +// Import Libraries & Environment Variables +import { CompassApiSDK } from "@compass-labs/api-sdk"; +import dotenv from "dotenv"; + +dotenv.config(); + +const COMPASS_API_KEY = process.env.COMPASS_API_KEY as string; +// SNIPPET END 1 + +// SNIPPET START 2 +// Initialize Compass SDK +const compass = new CompassApiSDK({ + apiKeyAuth: COMPASS_API_KEY, +}); +// SNIPPET END 2 + +// SNIPPET START 3 +// Get top 3 vaults sorted by 30d Net APY (after fees) high to low +async function run() { + // Fetch vaults ordered by 30d Net APY (one_month_cagr_net) descending + const vaultsResponse = await compass.earn.earnVaults({ + chain: "base", + orderBy: "one_month_cagr_net", + direction: "desc", + offset: 0, + limit: 3, + }); + + console.log("Top 3 Vaults by 30d Net APY (after fees):\n"); + + vaultsResponse.vaults.forEach((vault, index) => { + // Format APY values as percentages + // Note: SDK converts snake_case API fields to camelCase + const oneMonthAPY = (vault as any).oneMonthCagrNet + ? `${(parseFloat((vault as any).oneMonthCagrNet) * 100).toFixed(2)}%` + : "N/A"; + const threeMonthAPY = (vault as any).threeMonthsCagrNet + ? `${(parseFloat((vault as any).threeMonthsCagrNet) * 100).toFixed(2)}%` + : "N/A"; + const sharpeRatio = (vault as any).threeMonthsSharpeNet + ? parseFloat((vault as any).threeMonthsSharpeNet).toFixed(2) + : "N/A"; + const tvl = (vault as any).currentNav + ? `${parseFloat((vault as any).currentNav).toLocaleString(undefined, { + minimumFractionDigits: 2, + maximumFractionDigits: 2, + })} ${vault.denomination}` + : "N/A"; + + console.log(`${index + 1}. ${vault.name}`); + console.log(` Protocol: ${vault.protocol}`); + console.log(` Vault Address: ${vault.address}`); + console.log(` 30d Net APY (after fees): ${oneMonthAPY}`); + console.log(` 3m Net APY (after fees): ${threeMonthAPY}`); + console.log(` 3m Sharpe Ratio: ${sharpeRatio}`); + console.log(` Denomination: ${vault.denomination}`); + console.log(` TVL: ${tvl}`); + console.log(); + }); +} + +run(); +// SNIPPET END 3 diff --git a/v2/earn_vault_ranker/typescript/tsconfig.json b/v2/earn_vault_ranker/typescript/tsconfig.json new file mode 100644 index 00000000..d127c035 --- /dev/null +++ b/v2/earn_vault_ranker/typescript/tsconfig.json @@ -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"] +} + From edc99458ab4ef43a7835f55acf443b824510d045 Mon Sep 17 00:00:00 2001 From: Piet Duijnstee Date: Thu, 27 Nov 2025 12:53:15 +0100 Subject: [PATCH 2/5] Add earn_vault_data example (renamed from earn_vault_ranker) --- v2/earn_vault_data/python/README.md | 47 ++++++++++++++++++ v2/earn_vault_data/python/main.py | 28 +++++++++++ v2/earn_vault_data/python/pyproject.toml | 9 ++++ v2/earn_vault_data/typescript/README.md | 48 +++++++++++++++++++ v2/earn_vault_data/typescript/check_params.ts | 26 ++++++++++ v2/earn_vault_data/typescript/debug_order.ts | 31 ++++++++++++ .../typescript/debug_orderby.ts | 42 ++++++++++++++++ v2/earn_vault_data/typescript/package.json | 26 ++++++++++ v2/earn_vault_data/typescript/src/index.ts | 31 ++++++++++++ v2/earn_vault_data/typescript/test_compare.ts | 24 ++++++++++ .../typescript/test_no_order.ts | 28 +++++++++++ v2/earn_vault_data/typescript/test_raw.ts | 27 +++++++++++ v2/earn_vault_data/typescript/test_request.ts | 36 ++++++++++++++ v2/earn_vault_data/typescript/test_sort.ts | 29 +++++++++++ v2/earn_vault_data/typescript/tsconfig.json | 17 +++++++ 15 files changed, 449 insertions(+) create mode 100644 v2/earn_vault_data/python/README.md create mode 100644 v2/earn_vault_data/python/main.py create mode 100644 v2/earn_vault_data/python/pyproject.toml create mode 100644 v2/earn_vault_data/typescript/README.md create mode 100644 v2/earn_vault_data/typescript/check_params.ts create mode 100644 v2/earn_vault_data/typescript/debug_order.ts create mode 100644 v2/earn_vault_data/typescript/debug_orderby.ts create mode 100644 v2/earn_vault_data/typescript/package.json create mode 100644 v2/earn_vault_data/typescript/src/index.ts create mode 100644 v2/earn_vault_data/typescript/test_compare.ts create mode 100644 v2/earn_vault_data/typescript/test_no_order.ts create mode 100644 v2/earn_vault_data/typescript/test_raw.ts create mode 100644 v2/earn_vault_data/typescript/test_request.ts create mode 100644 v2/earn_vault_data/typescript/test_sort.ts create mode 100644 v2/earn_vault_data/typescript/tsconfig.json diff --git a/v2/earn_vault_data/python/README.md b/v2/earn_vault_data/python/README.md new file mode 100644 index 00000000..366ee166 --- /dev/null +++ b/v2/earn_vault_data/python/README.md @@ -0,0 +1,47 @@ +# Earn Vault Ranker - Python Example + +This example demonstrates how to get the top 3 vaults sorted by 30d Net 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 (make sure you have the latest version): +```bash +pip install --upgrade compass-api-sdk python-dotenv +``` + +Or if using `uv`: +```bash +uv pip install compass-api-sdk python-dotenv +``` + +2. Copy the example environment file: +```bash +cp .env.example .env +``` + +3. Fill in your `.env` file with your actual values: + - `COMPASS_API_KEY`: Your Compass API key + +## Run + +```bash +python main.py +``` + +## What This Does + +This example fetches the top 3 vaults sorted by 30d Net APY (after fees) from highest to lowest. For each vault, it displays: + +- **Protocol name** & **Vault address** +- **30d Net APY (after fees)** - `one_month_cagr_net` +- **3m Net APY (after fees)** - `three_months_cagr_net` +- **3m Sharpe Ratio** - `three_months_sharpe_net` +- **Denomination** - The underlying token (e.g., USDC, ETH) +- **TVL** - Total Value Locked (if available) - `current_nav` + +The example uses the `/v2/earn/vaults` endpoint with `order_by="one_month_cagr_net"` and `direction="desc"` to get the highest performing vaults by 30-day net APY. diff --git a/v2/earn_vault_data/python/main.py b/v2/earn_vault_data/python/main.py new file mode 100644 index 00000000..ff22891b --- /dev/null +++ b/v2/earn_vault_data/python/main.py @@ -0,0 +1,28 @@ +# 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") +# SNIPPET END 1 + +# SNIPPET START 2 +with CompassAPI(api_key_auth=COMPASS_API_KEY) as compass_api: +# SNIPPET END 2 + +# SNIPPET START 3 + # Get top vault sorted by 30-day annualized net return (after fees), high to low + vaults_response = compass_api.earn.earn_vaults( + chain=models.V2EarnVaultsChain.BASE, + order_by="one_month_cagr_net", + direction=models.Direction.DESC, + limit=1, + ) + + for i, vault in enumerate(vaults_response.vaults, 1): + print(f"{i}. {vault.name}: {float(vault.one_month_cagr_net) * 100:.2f}%") + + + \ No newline at end of file diff --git a/v2/earn_vault_data/python/pyproject.toml b/v2/earn_vault_data/python/pyproject.toml new file mode 100644 index 00000000..3f1fb062 --- /dev/null +++ b/v2/earn_vault_data/python/pyproject.toml @@ -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", +] + diff --git a/v2/earn_vault_data/typescript/README.md b/v2/earn_vault_data/typescript/README.md new file mode 100644 index 00000000..5bd8f314 --- /dev/null +++ b/v2/earn_vault_data/typescript/README.md @@ -0,0 +1,48 @@ +# Earn Vault Ranker - TypeScript Example + +This example demonstrates how to get the top 3 vaults sorted by 30d Net 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. Copy the example environment file: +```bash +cp .env.example .env +``` + +3. Fill in your `.env` file with your actual values: + - `COMPASS_API_KEY`: Your Compass API key + +## Run + +```bash +npm run dev +``` + +Or build and run: +```bash +npm run build +npm start +``` + +## What This Does + +This example fetches the top 3 vaults sorted by 30d Net APY (after fees) from highest to lowest. For each vault, it displays: + +- **Protocol name** & **Vault address** +- **30d Net APY (after fees)** - `one_month_cagr_net` +- **3m Net APY (after fees)** - `three_months_cagr_net` +- **3m Sharpe Ratio** - `three_months_sharpe_net` +- **Denomination** - The underlying token (e.g., USDC, ETH) +- **TVL** - Total Value Locked (if available) - `current_nav` + +The example uses the `/v2/earn/vaults` endpoint with `orderBy="one_month_cagr_net"` and `direction="desc"` to get the highest performing vaults by 30-day net APY. diff --git a/v2/earn_vault_data/typescript/check_params.ts b/v2/earn_vault_data/typescript/check_params.ts new file mode 100644 index 00000000..25ed7366 --- /dev/null +++ b/v2/earn_vault_data/typescript/check_params.ts @@ -0,0 +1,26 @@ +import { CompassApiSDK } from "@compass-labs/api-sdk"; +import dotenv from "dotenv"; + +dotenv.config(); + +const compass = new CompassApiSDK({ + apiKeyAuth: process.env.COMPASS_API_KEY as string, +}); + +async function check() { + const resp = await compass.earn.earnVaults({ + chain: "base", + orderBy: "one_month_cagr_net", + direction: "desc", + limit: 1, + }); + + console.log("TypeScript parameters:"); + console.log(" chain: base"); + console.log(" orderBy: one_month_cagr_net"); + console.log(" direction: desc"); + console.log(" limit: 1"); + console.log(`Result: ${resp.vaults[0].name} - ${(Number(resp.vaults[0].oneMonthCagrNet) * 100).toFixed(2)}%`); +} + +check(); diff --git a/v2/earn_vault_data/typescript/debug_order.ts b/v2/earn_vault_data/typescript/debug_order.ts new file mode 100644 index 00000000..e66fa5ff --- /dev/null +++ b/v2/earn_vault_data/typescript/debug_order.ts @@ -0,0 +1,31 @@ +import { CompassApiSDK } from "@compass-labs/api-sdk"; +import dotenv from "dotenv"; + +dotenv.config(); + +const compass = new CompassApiSDK({ + apiKeyAuth: process.env.COMPASS_API_KEY as string, +}); + +async function test() { + const resp = await compass.earn.earnVaults({ + chain: "base", + orderBy: "one_month_cagr_net", + direction: "desc", + limit: 3, + }); + + console.log("TypeScript - Checking if orderBy is working:"); + console.log(`Total vaults returned: ${resp.vaults.length}`); + console.log("Vaults in order:"); + resp.vaults.forEach((v, i) => { + console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); + }); + // Check if they're actually sorted + const values = resp.vaults.map(v => Number(v.oneMonthCagrNet)); + console.log(`APY values: ${values}`); + const isDescending = JSON.stringify(values) === JSON.stringify([...values].sort((a, b) => b - a)); + console.log(`Is descending? ${isDescending}`); +} + +test(); diff --git a/v2/earn_vault_data/typescript/debug_orderby.ts b/v2/earn_vault_data/typescript/debug_orderby.ts new file mode 100644 index 00000000..f3986cbb --- /dev/null +++ b/v2/earn_vault_data/typescript/debug_orderby.ts @@ -0,0 +1,42 @@ +import { CompassApiSDK } from "@compass-labs/api-sdk"; +import dotenv from "dotenv"; + +dotenv.config(); + +const compass = new CompassApiSDK({ + apiKeyAuth: process.env.COMPASS_API_KEY as string, +}); + +async function test() { + // Test with snake_case (what we're using) + console.log("=== Testing with orderBy: 'one_month_cagr_net' ==="); + const resp1 = await compass.earn.earnVaults({ + chain: "base", + orderBy: "one_month_cagr_net", + direction: "desc", + limit: 3, + }); + console.log("Results:"); + resp1.vaults.forEach((v, i) => { + console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); + }); + + // Test with camelCase (what TypeScript might expect) + console.log("\n=== Testing with orderBy: 'oneMonthCagrNet' ==="); + try { + const resp2 = await compass.earn.earnVaults({ + chain: "base", + orderBy: "oneMonthCagrNet", + direction: "desc", + limit: 3, + }); + console.log("Results:"); + resp2.vaults.forEach((v, i) => { + console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); + }); + } catch (e) { + console.log("Error:", e.message); + } +} + +test(); diff --git a/v2/earn_vault_data/typescript/package.json b/v2/earn_vault_data/typescript/package.json new file mode 100644 index 00000000..b94a602f --- /dev/null +++ b/v2/earn_vault_data/typescript/package.json @@ -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" + } +} + diff --git a/v2/earn_vault_data/typescript/src/index.ts b/v2/earn_vault_data/typescript/src/index.ts new file mode 100644 index 00000000..4b681f6e --- /dev/null +++ b/v2/earn_vault_data/typescript/src/index.ts @@ -0,0 +1,31 @@ +// 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; +// SNIPPET END 1 + +// SNIPPET START 2 +const compass = new CompassApiSDK({ + apiKeyAuth: COMPASS_API_KEY, +}); +// SNIPPET END 2 + +// SNIPPET START 3 +// Get top vault sorted by 30-day annualized net return (after fees), high to low +const vaultsResponse = await compass.earn.earnVaults({ + chain: "base", + orderBy: "one_month_cagr_net", + direction: "desc", + limit: 1, +}); + +vaultsResponse.vaults.forEach((vault, index) => { + const apy = vault.oneMonthCagrNet + ? `${(Number(vault.oneMonthCagrNet) * 100).toFixed(2)}%` + : "N/A"; + console.log(`${index + 1}. ${vault.name}: ${apy}`); +}); +// SNIPPET END 3 diff --git a/v2/earn_vault_data/typescript/test_compare.ts b/v2/earn_vault_data/typescript/test_compare.ts new file mode 100644 index 00000000..8a6f13fa --- /dev/null +++ b/v2/earn_vault_data/typescript/test_compare.ts @@ -0,0 +1,24 @@ +import { CompassApiSDK } from "@compass-labs/api-sdk"; +import dotenv from "dotenv"; + +dotenv.config(); + +const compass = new CompassApiSDK({ + apiKeyAuth: process.env.COMPASS_API_KEY as string, +}); + +async function test() { + const resp = await compass.earn.earnVaults({ + chain: "base", + orderBy: "one_month_cagr_net", + direction: "desc", + limit: 3, + }); + + console.log("TypeScript - First 3 vaults:"); + resp.vaults.forEach((v, i) => { + console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}% (raw: ${v.oneMonthCagrNet})`); + }); +} + +test(); diff --git a/v2/earn_vault_data/typescript/test_no_order.ts b/v2/earn_vault_data/typescript/test_no_order.ts new file mode 100644 index 00000000..cf016873 --- /dev/null +++ b/v2/earn_vault_data/typescript/test_no_order.ts @@ -0,0 +1,28 @@ +import { CompassApiSDK } from "@compass-labs/api-sdk"; +import dotenv from "dotenv"; + +dotenv.config(); + +const compass = new CompassApiSDK({ + apiKeyAuth: process.env.COMPASS_API_KEY as string, +}); + +async function test() { + // Test without orderBy + const resp1 = await compass.earn.earnVaults({ + chain: "base", + limit: 1, + }); + console.log("Without orderBy:", resp1.vaults[0].name, (Number(resp1.vaults[0].oneMonthCagrNet) * 100).toFixed(2) + "%"); + + // Test with orderBy + const resp2 = await compass.earn.earnVaults({ + chain: "base", + orderBy: "one_month_cagr_net", + direction: "desc", + limit: 1, + }); + console.log("With orderBy:", resp2.vaults[0].name, (Number(resp2.vaults[0].oneMonthCagrNet) * 100).toFixed(2) + "%"); +} + +test(); diff --git a/v2/earn_vault_data/typescript/test_raw.ts b/v2/earn_vault_data/typescript/test_raw.ts new file mode 100644 index 00000000..5eb7f8b6 --- /dev/null +++ b/v2/earn_vault_data/typescript/test_raw.ts @@ -0,0 +1,27 @@ +import { CompassApiSDK } from "@compass-labs/api-sdk"; +import dotenv from "dotenv"; + +dotenv.config(); + +const compass = new CompassApiSDK({ + apiKeyAuth: process.env.COMPASS_API_KEY as string, +}); + +async function test() { + const resp = await compass.earn.earnVaults({ + chain: "base", + orderBy: "one_month_cagr_net", + direction: "desc", + limit: 3, + }); + + console.log("=== TYPESCRIPT RAW OUTPUT ==="); + resp.vaults.forEach((v, i) => { + console.log(`${i + 1}. Name: ${v.name}`); + console.log(` oneMonthCagrNet: ${v.oneMonthCagrNet} (type: ${typeof v.oneMonthCagrNet})`); + console.log(` Calculated: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); + console.log(); + }); +} + +test(); diff --git a/v2/earn_vault_data/typescript/test_request.ts b/v2/earn_vault_data/typescript/test_request.ts new file mode 100644 index 00000000..15db5588 --- /dev/null +++ b/v2/earn_vault_data/typescript/test_request.ts @@ -0,0 +1,36 @@ +import { CompassApiSDK } from "@compass-labs/api-sdk"; +import dotenv from "dotenv"; + +dotenv.config(); + +const compass = new CompassApiSDK({ + apiKeyAuth: process.env.COMPASS_API_KEY as string, +}); + +async function test() { + // Try with snake_case (what API expects) + console.log("=== Testing with orderBy: 'one_month_cagr_net' ==="); + const resp1 = await compass.earn.earnVaults({ + chain: "base", + orderBy: "one_month_cagr_net", + direction: "desc", + limit: 3, + }); + resp1.vaults.forEach((v, i) => { + console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); + }); + + // Try with camelCase (what TypeScript SDK might expect) + console.log("\n=== Testing with orderBy: 'oneMonthCagrNet' ==="); + const resp2 = await compass.earn.earnVaults({ + chain: "base", + orderBy: "oneMonthCagrNet", + direction: "desc", + limit: 3, + }); + resp2.vaults.forEach((v, i) => { + console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); + }); +} + +test(); diff --git a/v2/earn_vault_data/typescript/test_sort.ts b/v2/earn_vault_data/typescript/test_sort.ts new file mode 100644 index 00000000..b4dd070d --- /dev/null +++ b/v2/earn_vault_data/typescript/test_sort.ts @@ -0,0 +1,29 @@ +import { CompassApiSDK } from "@compass-labs/api-sdk"; +import dotenv from "dotenv"; + +dotenv.config(); + +const compass = new CompassApiSDK({ + apiKeyAuth: process.env.COMPASS_API_KEY as string, +}); + +async function test() { + const resp = await compass.earn.earnVaults({ + chain: "base", + orderBy: "one_month_cagr_net", + direction: "desc", + limit: 5, + }); + + console.log("TypeScript - Top 5 by oneMonthCagrNet:"); + resp.vaults.forEach((v, i) => { + console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); + }); + + const values = resp.vaults.map(v => Number(v.oneMonthCagrNet)); + console.log(`Values: [${values.join(", ")}]`); + const isDesc = JSON.stringify(values) === JSON.stringify([...values].sort((a, b) => b - a)); + console.log(`Is descending? ${isDesc}`); +} + +test(); diff --git a/v2/earn_vault_data/typescript/tsconfig.json b/v2/earn_vault_data/typescript/tsconfig.json new file mode 100644 index 00000000..d127c035 --- /dev/null +++ b/v2/earn_vault_data/typescript/tsconfig.json @@ -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"] +} + From d6d175bc0a2f350692b1b15f93b54ade9a8e6ee7 Mon Sep 17 00:00:00 2001 From: Piet Duijnstee Date: Thu, 27 Nov 2025 17:08:41 +0100 Subject: [PATCH 3/5] Update earn_vault_data example: simplify to top vault by 30-day APY, remove test files, update READMEs --- v2/earn_vault_data/python/README.md | 37 +++++------ v2/earn_vault_data/python/main.py | 22 +++---- v2/earn_vault_data/typescript/README.md | 32 +++++----- v2/earn_vault_data/typescript/check_params.ts | 26 -------- v2/earn_vault_data/typescript/debug_order.ts | 31 --------- .../typescript/debug_orderby.ts | 42 ------------ v2/earn_vault_data/typescript/src/index.ts | 37 +++++------ v2/earn_vault_data/typescript/test_compare.ts | 24 ------- .../typescript/test_no_order.ts | 28 -------- v2/earn_vault_data/typescript/test_raw.ts | 27 -------- v2/earn_vault_data/typescript/test_request.ts | 36 ----------- v2/earn_vault_data/typescript/test_sort.ts | 29 --------- v2/earn_vault_ranker/python/README.md | 47 -------------- v2/earn_vault_ranker/python/main.py | 63 ------------------ v2/earn_vault_ranker/python/pyproject.toml | 9 --- v2/earn_vault_ranker/typescript/README.md | 48 -------------- v2/earn_vault_ranker/typescript/package.json | 26 -------- v2/earn_vault_ranker/typescript/src/index.ts | 64 ------------------- v2/earn_vault_ranker/typescript/tsconfig.json | 17 ----- 19 files changed, 58 insertions(+), 587 deletions(-) delete mode 100644 v2/earn_vault_data/typescript/check_params.ts delete mode 100644 v2/earn_vault_data/typescript/debug_order.ts delete mode 100644 v2/earn_vault_data/typescript/debug_orderby.ts delete mode 100644 v2/earn_vault_data/typescript/test_compare.ts delete mode 100644 v2/earn_vault_data/typescript/test_no_order.ts delete mode 100644 v2/earn_vault_data/typescript/test_raw.ts delete mode 100644 v2/earn_vault_data/typescript/test_request.ts delete mode 100644 v2/earn_vault_data/typescript/test_sort.ts delete mode 100644 v2/earn_vault_ranker/python/README.md delete mode 100644 v2/earn_vault_ranker/python/main.py delete mode 100644 v2/earn_vault_ranker/python/pyproject.toml delete mode 100644 v2/earn_vault_ranker/typescript/README.md delete mode 100644 v2/earn_vault_ranker/typescript/package.json delete mode 100644 v2/earn_vault_ranker/typescript/src/index.ts delete mode 100644 v2/earn_vault_ranker/typescript/tsconfig.json diff --git a/v2/earn_vault_data/python/README.md b/v2/earn_vault_data/python/README.md index 366ee166..762c0cf3 100644 --- a/v2/earn_vault_data/python/README.md +++ b/v2/earn_vault_data/python/README.md @@ -1,6 +1,6 @@ -# Earn Vault Ranker - Python Example +# Earn Vault Data - Python Example -This example demonstrates how to get the top 3 vaults sorted by 30d Net APY (after fees) using the Compass API Python SDK. +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 @@ -9,24 +9,16 @@ This example demonstrates how to get the top 3 vaults sorted by 30d Net APY (aft ## Setup -1. Install dependencies (make sure you have the latest version): +1. Install dependencies: ```bash -pip install --upgrade compass-api-sdk python-dotenv +pip install compass-api-sdk python-dotenv ``` -Or if using `uv`: -```bash -uv pip install compass-api-sdk python-dotenv +2. Create a `.env` file with your API key: ``` - -2. Copy the example environment file: -```bash -cp .env.example .env +COMPASS_API_KEY=your_api_key_here ``` -3. Fill in your `.env` file with your actual values: - - `COMPASS_API_KEY`: Your Compass API key - ## Run ```bash @@ -35,13 +27,14 @@ python main.py ## What This Does -This example fetches the top 3 vaults sorted by 30d Net APY (after fees) from highest to lowest. For each vault, it displays: +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 the highest performing vault by 30-day net annualized return. + +## Endpoint Overview -- **Protocol name** & **Vault address** -- **30d Net APY (after fees)** - `one_month_cagr_net` -- **3m Net APY (after fees)** - `three_months_cagr_net` -- **3m Sharpe Ratio** - `three_months_sharpe_net` -- **Denomination** - The underlying token (e.g., USDC, ETH) -- **TVL** - Total Value Locked (if available) - `current_nav` +The `/v2/earn/vaults` endpoint provides access to all available Earn vaults with comprehensive metrics. You can: -The example uses the `/v2/earn/vaults` endpoint with `order_by="one_month_cagr_net"` and `direction="desc"` to get the highest performing vaults by 30-day net APY. +- **Sort by different metrics**: `lifetime_return`, `one_month_cagr_net`, `three_months_cagr_net`, `three_months_sharpe_net`, `current_nav` (TVL) +- **Filter by chain**: `ETHEREUM`, `BASE`, `ARBITRUM` +- **Paginate results**: Use `offset` and `limit` to fetch multiple vaults diff --git a/v2/earn_vault_data/python/main.py b/v2/earn_vault_data/python/main.py index ff22891b..7b863dde 100644 --- a/v2/earn_vault_data/python/main.py +++ b/v2/earn_vault_data/python/main.py @@ -6,23 +6,19 @@ load_dotenv() COMPASS_API_KEY = os.getenv("COMPASS_API_KEY") -# SNIPPET END 1 -# SNIPPET START 2 with CompassAPI(api_key_auth=COMPASS_API_KEY) as compass_api: -# SNIPPET END 2 +# SNIPPET END 1 -# SNIPPET START 3 - # Get top vault sorted by 30-day annualized net return (after fees), high to low - vaults_response = compass_api.earn.earn_vaults( - chain=models.V2EarnVaultsChain.BASE, +# 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, ) - - for i, vault in enumerate(vaults_response.vaults, 1): - print(f"{i}. {vault.name}: {float(vault.one_month_cagr_net) * 100:.2f}%") - - - \ No newline at end of file + vault = res.vaults[0] + print(f"{vault.name}: {float(vault.one_month_cagr_net) * 100:.2f}% (30 day annualized return)") +# SNIPPET END 2 \ No newline at end of file diff --git a/v2/earn_vault_data/typescript/README.md b/v2/earn_vault_data/typescript/README.md index 5bd8f314..1b41c09d 100644 --- a/v2/earn_vault_data/typescript/README.md +++ b/v2/earn_vault_data/typescript/README.md @@ -1,6 +1,6 @@ -# Earn Vault Ranker - TypeScript Example +# Earn Vault Data - TypeScript Example -This example demonstrates how to get the top 3 vaults sorted by 30d Net APY (after fees) using the Compass API TypeScript SDK. +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 @@ -14,18 +14,15 @@ This example demonstrates how to get the top 3 vaults sorted by 30d Net APY (aft npm install ``` -2. Copy the example environment file: -```bash -cp .env.example .env +2. Create a `.env` file with your API key: +``` +COMPASS_API_KEY=your_api_key_here ``` - -3. Fill in your `.env` file with your actual values: - - `COMPASS_API_KEY`: Your Compass API key ## Run ```bash -npm run dev +npx tsx src/index.ts ``` Or build and run: @@ -36,13 +33,14 @@ npm start ## What This Does -This example fetches the top 3 vaults sorted by 30d Net APY (after fees) from highest to lowest. For each vault, it displays: +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 the highest performing vault by 30-day net annualized return. + +## Endpoint Overview -- **Protocol name** & **Vault address** -- **30d Net APY (after fees)** - `one_month_cagr_net` -- **3m Net APY (after fees)** - `three_months_cagr_net` -- **3m Sharpe Ratio** - `three_months_sharpe_net` -- **Denomination** - The underlying token (e.g., USDC, ETH) -- **TVL** - Total Value Locked (if available) - `current_nav` +The `/v2/earn/vaults` endpoint provides access to all available Earn vaults with comprehensive metrics. You can: -The example uses the `/v2/earn/vaults` endpoint with `orderBy="one_month_cagr_net"` and `direction="desc"` to get the highest performing vaults by 30-day net APY. +- **Sort by different metrics**: `lifetime_return`, `one_month_cagr_net`, `three_months_cagr_net`, `three_months_sharpe_net`, `current_nav` (TVL) +- **Filter by chain**: `ethereum`, `base`, `arbitrum` +- **Paginate results**: Use `offset` and `limit` to fetch multiple vaults diff --git a/v2/earn_vault_data/typescript/check_params.ts b/v2/earn_vault_data/typescript/check_params.ts deleted file mode 100644 index 25ed7366..00000000 --- a/v2/earn_vault_data/typescript/check_params.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { CompassApiSDK } from "@compass-labs/api-sdk"; -import dotenv from "dotenv"; - -dotenv.config(); - -const compass = new CompassApiSDK({ - apiKeyAuth: process.env.COMPASS_API_KEY as string, -}); - -async function check() { - const resp = await compass.earn.earnVaults({ - chain: "base", - orderBy: "one_month_cagr_net", - direction: "desc", - limit: 1, - }); - - console.log("TypeScript parameters:"); - console.log(" chain: base"); - console.log(" orderBy: one_month_cagr_net"); - console.log(" direction: desc"); - console.log(" limit: 1"); - console.log(`Result: ${resp.vaults[0].name} - ${(Number(resp.vaults[0].oneMonthCagrNet) * 100).toFixed(2)}%`); -} - -check(); diff --git a/v2/earn_vault_data/typescript/debug_order.ts b/v2/earn_vault_data/typescript/debug_order.ts deleted file mode 100644 index e66fa5ff..00000000 --- a/v2/earn_vault_data/typescript/debug_order.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { CompassApiSDK } from "@compass-labs/api-sdk"; -import dotenv from "dotenv"; - -dotenv.config(); - -const compass = new CompassApiSDK({ - apiKeyAuth: process.env.COMPASS_API_KEY as string, -}); - -async function test() { - const resp = await compass.earn.earnVaults({ - chain: "base", - orderBy: "one_month_cagr_net", - direction: "desc", - limit: 3, - }); - - console.log("TypeScript - Checking if orderBy is working:"); - console.log(`Total vaults returned: ${resp.vaults.length}`); - console.log("Vaults in order:"); - resp.vaults.forEach((v, i) => { - console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); - }); - // Check if they're actually sorted - const values = resp.vaults.map(v => Number(v.oneMonthCagrNet)); - console.log(`APY values: ${values}`); - const isDescending = JSON.stringify(values) === JSON.stringify([...values].sort((a, b) => b - a)); - console.log(`Is descending? ${isDescending}`); -} - -test(); diff --git a/v2/earn_vault_data/typescript/debug_orderby.ts b/v2/earn_vault_data/typescript/debug_orderby.ts deleted file mode 100644 index f3986cbb..00000000 --- a/v2/earn_vault_data/typescript/debug_orderby.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { CompassApiSDK } from "@compass-labs/api-sdk"; -import dotenv from "dotenv"; - -dotenv.config(); - -const compass = new CompassApiSDK({ - apiKeyAuth: process.env.COMPASS_API_KEY as string, -}); - -async function test() { - // Test with snake_case (what we're using) - console.log("=== Testing with orderBy: 'one_month_cagr_net' ==="); - const resp1 = await compass.earn.earnVaults({ - chain: "base", - orderBy: "one_month_cagr_net", - direction: "desc", - limit: 3, - }); - console.log("Results:"); - resp1.vaults.forEach((v, i) => { - console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); - }); - - // Test with camelCase (what TypeScript might expect) - console.log("\n=== Testing with orderBy: 'oneMonthCagrNet' ==="); - try { - const resp2 = await compass.earn.earnVaults({ - chain: "base", - orderBy: "oneMonthCagrNet", - direction: "desc", - limit: 3, - }); - console.log("Results:"); - resp2.vaults.forEach((v, i) => { - console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); - }); - } catch (e) { - console.log("Error:", e.message); - } -} - -test(); diff --git a/v2/earn_vault_data/typescript/src/index.ts b/v2/earn_vault_data/typescript/src/index.ts index 4b681f6e..6df417c7 100644 --- a/v2/earn_vault_data/typescript/src/index.ts +++ b/v2/earn_vault_data/typescript/src/index.ts @@ -5,27 +5,28 @@ import dotenv from "dotenv"; dotenv.config(); const COMPASS_API_KEY = process.env.COMPASS_API_KEY as string; -// SNIPPET END 1 -// SNIPPET START 2 -const compass = new CompassApiSDK({ +const compassApiSDK = new CompassApiSDK({ apiKeyAuth: COMPASS_API_KEY, }); -// SNIPPET END 2 - -// SNIPPET START 3 -// Get top vault sorted by 30-day annualized net return (after fees), high to low -const vaultsResponse = await compass.earn.earnVaults({ - chain: "base", - orderBy: "one_month_cagr_net", - direction: "desc", - limit: 1, -}); +// SNIPPET END 1 -vaultsResponse.vaults.forEach((vault, index) => { +// 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)}%` + ? (Number(vault.oneMonthCagrNet) * 100).toFixed(2) : "N/A"; - console.log(`${index + 1}. ${vault.name}: ${apy}`); -}); -// SNIPPET END 3 + console.log(`${vault.name}: ${apy}% (30 day annualized return)`); +} + +run(); +// SNIPPET END 2 diff --git a/v2/earn_vault_data/typescript/test_compare.ts b/v2/earn_vault_data/typescript/test_compare.ts deleted file mode 100644 index 8a6f13fa..00000000 --- a/v2/earn_vault_data/typescript/test_compare.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { CompassApiSDK } from "@compass-labs/api-sdk"; -import dotenv from "dotenv"; - -dotenv.config(); - -const compass = new CompassApiSDK({ - apiKeyAuth: process.env.COMPASS_API_KEY as string, -}); - -async function test() { - const resp = await compass.earn.earnVaults({ - chain: "base", - orderBy: "one_month_cagr_net", - direction: "desc", - limit: 3, - }); - - console.log("TypeScript - First 3 vaults:"); - resp.vaults.forEach((v, i) => { - console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}% (raw: ${v.oneMonthCagrNet})`); - }); -} - -test(); diff --git a/v2/earn_vault_data/typescript/test_no_order.ts b/v2/earn_vault_data/typescript/test_no_order.ts deleted file mode 100644 index cf016873..00000000 --- a/v2/earn_vault_data/typescript/test_no_order.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { CompassApiSDK } from "@compass-labs/api-sdk"; -import dotenv from "dotenv"; - -dotenv.config(); - -const compass = new CompassApiSDK({ - apiKeyAuth: process.env.COMPASS_API_KEY as string, -}); - -async function test() { - // Test without orderBy - const resp1 = await compass.earn.earnVaults({ - chain: "base", - limit: 1, - }); - console.log("Without orderBy:", resp1.vaults[0].name, (Number(resp1.vaults[0].oneMonthCagrNet) * 100).toFixed(2) + "%"); - - // Test with orderBy - const resp2 = await compass.earn.earnVaults({ - chain: "base", - orderBy: "one_month_cagr_net", - direction: "desc", - limit: 1, - }); - console.log("With orderBy:", resp2.vaults[0].name, (Number(resp2.vaults[0].oneMonthCagrNet) * 100).toFixed(2) + "%"); -} - -test(); diff --git a/v2/earn_vault_data/typescript/test_raw.ts b/v2/earn_vault_data/typescript/test_raw.ts deleted file mode 100644 index 5eb7f8b6..00000000 --- a/v2/earn_vault_data/typescript/test_raw.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { CompassApiSDK } from "@compass-labs/api-sdk"; -import dotenv from "dotenv"; - -dotenv.config(); - -const compass = new CompassApiSDK({ - apiKeyAuth: process.env.COMPASS_API_KEY as string, -}); - -async function test() { - const resp = await compass.earn.earnVaults({ - chain: "base", - orderBy: "one_month_cagr_net", - direction: "desc", - limit: 3, - }); - - console.log("=== TYPESCRIPT RAW OUTPUT ==="); - resp.vaults.forEach((v, i) => { - console.log(`${i + 1}. Name: ${v.name}`); - console.log(` oneMonthCagrNet: ${v.oneMonthCagrNet} (type: ${typeof v.oneMonthCagrNet})`); - console.log(` Calculated: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); - console.log(); - }); -} - -test(); diff --git a/v2/earn_vault_data/typescript/test_request.ts b/v2/earn_vault_data/typescript/test_request.ts deleted file mode 100644 index 15db5588..00000000 --- a/v2/earn_vault_data/typescript/test_request.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { CompassApiSDK } from "@compass-labs/api-sdk"; -import dotenv from "dotenv"; - -dotenv.config(); - -const compass = new CompassApiSDK({ - apiKeyAuth: process.env.COMPASS_API_KEY as string, -}); - -async function test() { - // Try with snake_case (what API expects) - console.log("=== Testing with orderBy: 'one_month_cagr_net' ==="); - const resp1 = await compass.earn.earnVaults({ - chain: "base", - orderBy: "one_month_cagr_net", - direction: "desc", - limit: 3, - }); - resp1.vaults.forEach((v, i) => { - console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); - }); - - // Try with camelCase (what TypeScript SDK might expect) - console.log("\n=== Testing with orderBy: 'oneMonthCagrNet' ==="); - const resp2 = await compass.earn.earnVaults({ - chain: "base", - orderBy: "oneMonthCagrNet", - direction: "desc", - limit: 3, - }); - resp2.vaults.forEach((v, i) => { - console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); - }); -} - -test(); diff --git a/v2/earn_vault_data/typescript/test_sort.ts b/v2/earn_vault_data/typescript/test_sort.ts deleted file mode 100644 index b4dd070d..00000000 --- a/v2/earn_vault_data/typescript/test_sort.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { CompassApiSDK } from "@compass-labs/api-sdk"; -import dotenv from "dotenv"; - -dotenv.config(); - -const compass = new CompassApiSDK({ - apiKeyAuth: process.env.COMPASS_API_KEY as string, -}); - -async function test() { - const resp = await compass.earn.earnVaults({ - chain: "base", - orderBy: "one_month_cagr_net", - direction: "desc", - limit: 5, - }); - - console.log("TypeScript - Top 5 by oneMonthCagrNet:"); - resp.vaults.forEach((v, i) => { - console.log(` ${i + 1}. ${v.name}: ${(Number(v.oneMonthCagrNet) * 100).toFixed(2)}%`); - }); - - const values = resp.vaults.map(v => Number(v.oneMonthCagrNet)); - console.log(`Values: [${values.join(", ")}]`); - const isDesc = JSON.stringify(values) === JSON.stringify([...values].sort((a, b) => b - a)); - console.log(`Is descending? ${isDesc}`); -} - -test(); diff --git a/v2/earn_vault_ranker/python/README.md b/v2/earn_vault_ranker/python/README.md deleted file mode 100644 index 366ee166..00000000 --- a/v2/earn_vault_ranker/python/README.md +++ /dev/null @@ -1,47 +0,0 @@ -# Earn Vault Ranker - Python Example - -This example demonstrates how to get the top 3 vaults sorted by 30d Net 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 (make sure you have the latest version): -```bash -pip install --upgrade compass-api-sdk python-dotenv -``` - -Or if using `uv`: -```bash -uv pip install compass-api-sdk python-dotenv -``` - -2. Copy the example environment file: -```bash -cp .env.example .env -``` - -3. Fill in your `.env` file with your actual values: - - `COMPASS_API_KEY`: Your Compass API key - -## Run - -```bash -python main.py -``` - -## What This Does - -This example fetches the top 3 vaults sorted by 30d Net APY (after fees) from highest to lowest. For each vault, it displays: - -- **Protocol name** & **Vault address** -- **30d Net APY (after fees)** - `one_month_cagr_net` -- **3m Net APY (after fees)** - `three_months_cagr_net` -- **3m Sharpe Ratio** - `three_months_sharpe_net` -- **Denomination** - The underlying token (e.g., USDC, ETH) -- **TVL** - Total Value Locked (if available) - `current_nav` - -The example uses the `/v2/earn/vaults` endpoint with `order_by="one_month_cagr_net"` and `direction="desc"` to get the highest performing vaults by 30-day net APY. diff --git a/v2/earn_vault_ranker/python/main.py b/v2/earn_vault_ranker/python/main.py deleted file mode 100644 index 914e4bd1..00000000 --- a/v2/earn_vault_ranker/python/main.py +++ /dev/null @@ -1,63 +0,0 @@ -# SNIPPET START 1 -# Import Libraries & Environment Variables -from compass_api_sdk import CompassAPI, models -import os -from dotenv import load_dotenv - -load_dotenv() - -COMPASS_API_KEY = os.getenv("COMPASS_API_KEY") -# SNIPPET END 1 - -# SNIPPET START 2 -# Initialize Compass SDK -compass = CompassAPI(api_key_auth=COMPASS_API_KEY) -# SNIPPET END 2 - -# SNIPPET START 3 -# Get top 3 vaults sorted by 30d Net APY (after fees) high to low -with CompassAPI(api_key_auth=COMPASS_API_KEY) as compass_api: - # Fetch vaults ordered by 30d Net APY (one_month_cagr_net) descending - vaults_response = compass_api.earn.earn_vaults( - chain=models.Chain.BASE, - order_by="one_month_cagr_net", - direction=models.Direction.DESC, - offset=0, - limit=3, - ) - - print("Top 3 Vaults by 30d Net APY (after fees):\n") - - for i, vault in enumerate(vaults_response.vaults, 1): - # Format APY values as percentages - one_month_apy = ( - f"{float(vault.one_month_cagr_net) * 100:.2f}%" - if vault.one_month_cagr_net - else "N/A" - ) - three_month_apy = ( - f"{float(vault.three_months_cagr_net) * 100:.2f}%" - if vault.three_months_cagr_net - else "N/A" - ) - sharpe_ratio = ( - f"{float(vault.three_months_sharpe_net):.2f}" - if vault.three_months_sharpe_net - else "N/A" - ) - tvl = ( - f"{float(vault.current_nav):,.2f} {vault.denomination}" - if vault.current_nav - else "N/A" - ) - - print(f"{i}. {vault.name}") - print(f" Protocol: {vault.protocol}") - print(f" Vault Address: {vault.address}") - print(f" 30d Net APY (after fees): {one_month_apy}") - print(f" 3m Net APY (after fees): {three_month_apy}") - print(f" 3m Sharpe Ratio: {sharpe_ratio}") - print(f" Denomination: {vault.denomination}") - print(f" TVL: {tvl}") - print() -# SNIPPET END 3 diff --git a/v2/earn_vault_ranker/python/pyproject.toml b/v2/earn_vault_ranker/python/pyproject.toml deleted file mode 100644 index 3f1fb062..00000000 --- a/v2/earn_vault_ranker/python/pyproject.toml +++ /dev/null @@ -1,9 +0,0 @@ -[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", -] - diff --git a/v2/earn_vault_ranker/typescript/README.md b/v2/earn_vault_ranker/typescript/README.md deleted file mode 100644 index 5bd8f314..00000000 --- a/v2/earn_vault_ranker/typescript/README.md +++ /dev/null @@ -1,48 +0,0 @@ -# Earn Vault Ranker - TypeScript Example - -This example demonstrates how to get the top 3 vaults sorted by 30d Net 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. Copy the example environment file: -```bash -cp .env.example .env -``` - -3. Fill in your `.env` file with your actual values: - - `COMPASS_API_KEY`: Your Compass API key - -## Run - -```bash -npm run dev -``` - -Or build and run: -```bash -npm run build -npm start -``` - -## What This Does - -This example fetches the top 3 vaults sorted by 30d Net APY (after fees) from highest to lowest. For each vault, it displays: - -- **Protocol name** & **Vault address** -- **30d Net APY (after fees)** - `one_month_cagr_net` -- **3m Net APY (after fees)** - `three_months_cagr_net` -- **3m Sharpe Ratio** - `three_months_sharpe_net` -- **Denomination** - The underlying token (e.g., USDC, ETH) -- **TVL** - Total Value Locked (if available) - `current_nav` - -The example uses the `/v2/earn/vaults` endpoint with `orderBy="one_month_cagr_net"` and `direction="desc"` to get the highest performing vaults by 30-day net APY. diff --git a/v2/earn_vault_ranker/typescript/package.json b/v2/earn_vault_ranker/typescript/package.json deleted file mode 100644 index b94a602f..00000000 --- a/v2/earn_vault_ranker/typescript/package.json +++ /dev/null @@ -1,26 +0,0 @@ -{ - "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" - } -} - diff --git a/v2/earn_vault_ranker/typescript/src/index.ts b/v2/earn_vault_ranker/typescript/src/index.ts deleted file mode 100644 index 476f786f..00000000 --- a/v2/earn_vault_ranker/typescript/src/index.ts +++ /dev/null @@ -1,64 +0,0 @@ -// SNIPPET START 1 -// Import Libraries & Environment Variables -import { CompassApiSDK } from "@compass-labs/api-sdk"; -import dotenv from "dotenv"; - -dotenv.config(); - -const COMPASS_API_KEY = process.env.COMPASS_API_KEY as string; -// SNIPPET END 1 - -// SNIPPET START 2 -// Initialize Compass SDK -const compass = new CompassApiSDK({ - apiKeyAuth: COMPASS_API_KEY, -}); -// SNIPPET END 2 - -// SNIPPET START 3 -// Get top 3 vaults sorted by 30d Net APY (after fees) high to low -async function run() { - // Fetch vaults ordered by 30d Net APY (one_month_cagr_net) descending - const vaultsResponse = await compass.earn.earnVaults({ - chain: "base", - orderBy: "one_month_cagr_net", - direction: "desc", - offset: 0, - limit: 3, - }); - - console.log("Top 3 Vaults by 30d Net APY (after fees):\n"); - - vaultsResponse.vaults.forEach((vault, index) => { - // Format APY values as percentages - // Note: SDK converts snake_case API fields to camelCase - const oneMonthAPY = (vault as any).oneMonthCagrNet - ? `${(parseFloat((vault as any).oneMonthCagrNet) * 100).toFixed(2)}%` - : "N/A"; - const threeMonthAPY = (vault as any).threeMonthsCagrNet - ? `${(parseFloat((vault as any).threeMonthsCagrNet) * 100).toFixed(2)}%` - : "N/A"; - const sharpeRatio = (vault as any).threeMonthsSharpeNet - ? parseFloat((vault as any).threeMonthsSharpeNet).toFixed(2) - : "N/A"; - const tvl = (vault as any).currentNav - ? `${parseFloat((vault as any).currentNav).toLocaleString(undefined, { - minimumFractionDigits: 2, - maximumFractionDigits: 2, - })} ${vault.denomination}` - : "N/A"; - - console.log(`${index + 1}. ${vault.name}`); - console.log(` Protocol: ${vault.protocol}`); - console.log(` Vault Address: ${vault.address}`); - console.log(` 30d Net APY (after fees): ${oneMonthAPY}`); - console.log(` 3m Net APY (after fees): ${threeMonthAPY}`); - console.log(` 3m Sharpe Ratio: ${sharpeRatio}`); - console.log(` Denomination: ${vault.denomination}`); - console.log(` TVL: ${tvl}`); - console.log(); - }); -} - -run(); -// SNIPPET END 3 diff --git a/v2/earn_vault_ranker/typescript/tsconfig.json b/v2/earn_vault_ranker/typescript/tsconfig.json deleted file mode 100644 index d127c035..00000000 --- a/v2/earn_vault_ranker/typescript/tsconfig.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "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"] -} - From 40d242b7061c11291c561415664b4104d785e7fc Mon Sep 17 00:00:00 2001 From: elisabethd <77678812+ElisabethDuijnstee@users.noreply.github.com> Date: Thu, 27 Nov 2025 16:16:04 +0000 Subject: [PATCH 4/5] Update README.md --- v2/earn_vault_data/python/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/v2/earn_vault_data/python/README.md b/v2/earn_vault_data/python/README.md index 762c0cf3..d3e4a249 100644 --- a/v2/earn_vault_data/python/README.md +++ b/v2/earn_vault_data/python/README.md @@ -29,12 +29,12 @@ python main.py 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 the highest performing vault by 30-day net annualized return. +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` (TVL) +- **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 From 0a025ba2f0ff49cacc31dc871a489ea0b48801da Mon Sep 17 00:00:00 2001 From: elisabethd <77678812+ElisabethDuijnstee@users.noreply.github.com> Date: Thu, 27 Nov 2025 16:16:48 +0000 Subject: [PATCH 5/5] Update README.md --- v2/earn_vault_data/typescript/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/v2/earn_vault_data/typescript/README.md b/v2/earn_vault_data/typescript/README.md index 1b41c09d..52b007a8 100644 --- a/v2/earn_vault_data/typescript/README.md +++ b/v2/earn_vault_data/typescript/README.md @@ -35,12 +35,12 @@ npm start 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 the highest performing vault by 30-day net annualized return. +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` (TVL) +- **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