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 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
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
49 changes: 49 additions & 0 deletions cowswap-ai-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# CoWSwap-AI

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

## Description

CoWSwap-AI: Your intelligent companion for real-time fair cryptocurrency trading with MEV-Protection!

Cowswap is a revolutionary decentralized trading platform that stands out by offering a unique, user-centric experience in the DeFi space. It leverages batch auctions to minimize front-running and slippage, ensuring fair and transparent trades for all users. Cowswap’s innovative approach allows traders to benefit from optimal pricing across multiple liquidity sources, making it a highly efficient and cost-effective solution for decentralized trading. With its focus on user protection and seamless trading, Cowswap is an invaluable tool for both beginners and seasoned traders looking to maximize their returns in the DeFi ecosystem.

[![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=cowswap-ai.vercel.app)
[![Demo](https://img.shields.io/badge/Demo-Visit%20Demo-brightgreen)](https://cowswap-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%2Fcowswap-ai-plugin)


**Tooling:**

[![Use Case](https://img.shields.io/badge/Use%20Case-Cryptocurrency%20Quotes,Swaps,MEV%20Protection-blue)](#)
[![Tools](https://img.shields.io/badge/Tools-CoWSwap%20API-blue)](#)
[![Framework](https://img.shields.io/badge/Framework-NextJS%2014-blue)](#)

## Project Walkthrough

CoWSwap-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 cowswap-ai-plugin && git checkout && cd cowswap-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 CoWSwap-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. Click "Deploy" and wait for the build to complete.

Once deployed, you can access your CoWSwap-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.

<img src="https://i.imgur.com/CcWSqba.png" alt="detail_image" width="0"/>

Binary file added cowswap-ai-plugin/app/favicon.ico
Binary file not shown.
6 changes: 6 additions & 0 deletions cowswap-ai-plugin/app/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/quote/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

import { parseQuoteRequest } from "@/utils/tokens";
import { type NextRequest, NextResponse } from "next/server";

const COW_API = "https://api.cow.fi"

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

const response = await fetch(`${COW_API}/${requestBody.network}/api/v1/quote`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(requestBody)
});
if (!response.ok) {
const message = await response.text();
return NextResponse.json({ message }, { status: response.status });
}
const data = await response.json();

return NextResponse.json(data);
} catch (error: unknown) {
return NextResponse.json({ error }, { status: 400 });
}
}
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}`,
}
]
};

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;
45 changes: 45 additions & 0 deletions cowswap-ai-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"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",
"csv-parser": "^3.0.0",
"ethers": "^5",
"fs": "^0.0.1-security",
"near-ca": "^0.5.0",
"next": "^14.2.7",
"react": "^18",
"react-dom": "^18",
"vercel-url": "^0.2.1",
"viem": "^2.21.4"
},
"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