Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CoW Swap Plugin #179

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Empty file.
3 changes: 3 additions & 0 deletions cowswap-ai-plugin/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
36 changes: 36 additions & 0 deletions cowswap-ai-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js
.yarn/install-state.gz

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env*.local

# vercel
.vercel

# typescript
*.tsbuildinfo
next-env.d.ts
50 changes: 50 additions & 0 deletions cowswap-ai-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# CoinGecko-AI
bh2smith marked this conversation as resolved.
Show resolved Hide resolved

<img src="https://i.imgur.com/s9HSENw.jpg" alt="cover_image" width="0" />

## Description

CoinGecko-AI: Your intelligent companion for real-time cryptocurrency insights and price tracking provided Coingecko API's.

CoinGecko-AI is a cutting-edge project that combines the power of artificial intelligence with real-time cryptocurrency data from CoinGecko. This innovative tool provides users with intelligent insights on crypto market data. CoinGecko-AI offers a unique and intuitive way to navigate the complex world of digital assets, making it an invaluable resource for both novice and experienced crypto enthusiasts.

[![Agent Demo](https://img.shields.io/badge/Demo-Visit%20Demo-orange)](https://wallet.bitte.ai/smart-actions/prompt/what%20can%20you%20help%20me%20with?mode=debug&agentId=coingecko-ai.vercel.app)
[![Demo](https://img.shields.io/badge/Demo-Visit%20Demo-brightgreen)](https://coingecko-ai.vercel.app/)
[![Deploy](https://img.shields.io/badge/Deploy-Deploy%20Now-blue)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2FMintbase%2Ftemplates%2Ftree%2Fmain%2Fcoingecko-ai-plugin)


**Tooling:**

[![Use Case](https://img.shields.io/badge/Use%20Case-Cryptocurrency%20Analysis,Price%20Prediction-blue)](#)
[![Tools](https://img.shields.io/badge/Tools-CoinGecko%20API,TensorFlow-blue)](#)
[![Framework](https://img.shields.io/badge/Framework-NextJS%2014-blue)](#)

## Project Walkthrough

<img src="https://github.com/user-attachments/assets/c59dcf62-fdfe-40d6-a128-073c16a9479f" alt="detail_image" width="500"/>

CoinGecko-AI is built using Next.js 14 and exposes an API Reference using [Scalar](https://scalar.com/).

To run the project locally:

1. Clone this template from the repository tree: `git clone git clone --no-checkout https://github.com/Mintbase/templates.git && cd templates && git sparse-checkout set coingecko-ai-plugin && git checkout && cd coingecko-ai-plugin`
2. Install dependencies: `pnpm install`
3. Set up environment variables: Copy `.env.example` to `.env.local` and fill in your CoinGecko API key.
4. Run the development server: `pnpm run dev`
5. Open `http://localhost:3000` in your browser to view the application.

## Deployment

To deploy CoinGecko-AI on Vercel:

1. Fork the repository to your GitHub account.
2. Sign up for a Vercel account if you haven't already.
3. Click the "Deploy" button above or go to https://vercel.com/new.
4. Select your forked repository.
5. Configure the following environment variables:
- `COINGECKO_API_KEY`: Your CoinGecko API key
6. Click "Deploy" and wait for the build to complete.

Once deployed, you can access your CoinGecko-AI instance at the provided Vercel URL. You can customize the application by modifying the source code and pushing changes to your repository. Vercel will automatically redeploy your application with the latest changes.

For any issues or questions regarding deployment, please refer to the Vercel documentation or open an issue in the project repository.
6 changes: 6 additions & 0 deletions cowswap-ai-plugin/app/api/health/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { NextResponse } from "next/server";

// This is a proxy route that forwards requests to the CoinGecko API
export async function GET(): Promise<NextResponse> {
return NextResponse.json({ok: true, message: "Ok lets go!"});
}
27 changes: 27 additions & 0 deletions cowswap-ai-plugin/app/api/quote/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { type NextRequest, NextResponse } from "next/server";

const COW_API = "https://api.cow.fi"
type Network = "mainnet" | "xdai" | "arbitrum_one";

export async function POST(req: NextRequest): Promise<NextResponse> {
const requestBody = await req.json();
console.log("POST Request for quote:", requestBody)

const network: Network = requestBody.network;

if (!["mainnet", "xdai", "arbitrum_one"].includes(network)) {
return NextResponse.json({ error: `Invalid network '${network}'. Must be one of 'mainnet', 'xdai' OR 'arbitrum_one'` }, { status: 400 });
}

const response = await fetch(`${COW_API}/${network}/api/v1/quote`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
});

const data = await response.json();

return NextResponse.json(data);
}
Binary file added cowswap-ai-plugin/app/favicon.ico
Binary file not shown.
27 changes: 27 additions & 0 deletions cowswap-ai-plugin/app/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import type { ReferenceConfiguration } from "@scalar/api-reference";
import { ApiReference } from "@scalar/nextjs-api-reference";
import { DEPLOYMENT_URL } from "vercel-url";

const config: ReferenceConfiguration = {
spec: {
url: "/.well-known/ai-plugin.json",
},
theme: "moon",
metaData: {
title: "CowSwap AI Plugin",
description: "Bitte.ai Plugin for CowSwap API's",
ogDescription: "AI Compatible API endpoints for RFQ (quotes) and order placement",
ogTitle: "CoW AI",
ogImage: "https://raw.githubusercontent.com/cowprotocol/token-lists/main/src/public/images/1/0xdef1ca1fb7fbcdc777520aa7f396b4e015f497ab/logo.png",
twitterCard: "summary_large_image",
},
servers: [
{
// Override server URLs using Vercel system env variables
// Defaults to http://localhost:3000 on local development
url: `${DEPLOYMENT_URL}/api/v3`,
}
]
};

export const GET = ApiReference(config);
25 changes: 25 additions & 0 deletions cowswap-ai-plugin/next.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
async headers() {
return [
{
source: "/api/:path*",
headers: [
{ key: "Access-Control-Allow-Credentials", value: "true" },
{ key: "Access-Control-Allow-Origin", value: "*" },
{
key: "Access-Control-Allow-Methods",
value: "GET,OPTIONS,POST",
},
{
key: "Access-Control-Allow-Headers",
value:
"X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version",
},
],
},
];
},
};

export default nextConfig;
41 changes: 41 additions & 0 deletions cowswap-ai-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "cowswap-ai-mintbase-template",
"keywords": [
"bitte",
"templates",
"ai",
"agents",
"openapi",
"web3"
],
"repository": "https://github.com/mintbase/templates.git",
"homepage": "https;//templates.mintbase.xyz/coingecko-ai-plugin",
"author": "Mintbase Team <[email protected]>",
"private": true,
"scripts": {
"dev": "next dev --turbo",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@cowprotocol/cow-sdk": "^5.4.1",
"@scalar/api-reference": "^1.24.75",
"@scalar/nextjs-api-reference": "^0.4.73",
"ethers": "^5",
"next": "^14.2.7",
"react": "^18",
"react-dom": "^18",
"vercel-url": "^0.2.1"
},
"devDependencies": {
"@types/node": "^22",
"@types/react": "^18",
"@types/react-dom": "^18",
"eslint": "^8",
"eslint-config-next": "14.2.7",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"typescript": "^5"
}
}
8 changes: 8 additions & 0 deletions cowswap-ai-plugin/postcss.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/** @type {import('postcss-load-config').Config} */
const config = {
plugins: {
tailwindcss: {},
},
};

export default config;
Loading