diff --git a/v2/earn_vault_data/python/README.md b/v2/earn_vault_data/python/README.md new file mode 100644 index 00000000..d3e4a249 --- /dev/null +++ b/v2/earn_vault_data/python/README.md @@ -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 diff --git a/v2/earn_vault_data/python/main.py b/v2/earn_vault_data/python/main.py new file mode 100644 index 00000000..7b863dde --- /dev/null +++ b/v2/earn_vault_data/python/main.py @@ -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 \ 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..52b007a8 --- /dev/null +++ b/v2/earn_vault_data/typescript/README.md @@ -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 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..6df417c7 --- /dev/null +++ b/v2/earn_vault_data/typescript/src/index.ts @@ -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 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"] +} +