forked from cowprotocol/services
-
Notifications
You must be signed in to change notification settings - Fork 0
feat: creating the coingecko mock API; #7
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
Open
lgahdl
wants to merge
3
commits into
luizhatem/cow-539-add-additional-tokens-usdt-gno-and-uniswapv2pairs
Choose a base branch
from
luizhatem/cow-542-implement-coingecko-api-mock-for-offline-price-fetching
base: luizhatem/cow-539-add-additional-tokens-usdt-gno-and-uniswapv2pairs
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Mock Services | ||
|
|
||
| This directory contains mock services used for offline development and testing of the CoW Protocol playground. | ||
|
|
||
| ## Available Mocks | ||
|
|
||
| ### Coingecko (`./coingecko/`) | ||
|
|
||
| Mock implementation of the Coingecko API for price fetching in offline mode. | ||
|
|
||
| - **Technology**: Node.js + TypeScript + Hono API | ||
| - **Endpoint**: `/api/v3/simple/token_price/ethereum` | ||
| - **Purpose**: Provides configurable token prices in ETH denomination without requiring external API access | ||
| - **Configuration**: Token prices can be configured in `./coingecko/src/tokens.config.ts` | ||
|
|
||
| **Supported Tokens** (offline mode): | ||
| - WETH | ||
| - DAI | ||
| - USDC | ||
| - USDT | ||
| - GNO | ||
|
|
||
| See `./coingecko/README.md` for detailed documentation. | ||
|
|
||
| ## Architecture | ||
|
|
||
| Mock services are organized at the playground level to: | ||
| - Maintain clear separation from deployment infrastructure (`offline-mode/`) | ||
| - Improve discoverability of available mocks | ||
| - Enable easy addition of new mock services (e.g., block explorer, subgraph, etc.) | ||
| - Support reusability across different playground configurations | ||
|
|
||
| ## Adding New Mocks | ||
|
|
||
| To add a new mock service: | ||
|
|
||
| 1. Create a new directory: `mocks/<service-name>/` | ||
| 2. Implement the mock service with a Dockerfile | ||
| 3. Add the service to `docker-compose.offline.yml` | ||
| 4. Update this README with documentation | ||
|
|
||
| ## Usage | ||
|
|
||
| Mock services are automatically started when running the offline playground: | ||
|
|
||
| ```bash | ||
| docker-compose -f docker-compose.offline.yml up | ||
| ``` | ||
|
|
||
| Individual mocks can be built and run separately: | ||
|
|
||
| ```bash | ||
| docker-compose -f docker-compose.offline.yml up coingecko-mock | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| node_modules | ||
| dist | ||
| *.log | ||
| .env | ||
| .DS_Store | ||
| README.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| node_modules/ | ||
| dist/ | ||
| *.log | ||
| .env | ||
| .DS_Store |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| FROM node:20-alpine | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| # Copy package files | ||
| COPY package*.json ./ | ||
| COPY tsconfig.json ./ | ||
|
|
||
| # Install dependencies | ||
| RUN npm install | ||
|
|
||
| # Copy source code | ||
| COPY src ./src | ||
|
|
||
| # Build TypeScript | ||
| RUN npm run build | ||
|
|
||
| # Expose port | ||
| EXPOSE 3000 | ||
|
|
||
| # Start the server | ||
| CMD ["npm", "start"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # Coingecko Mock API | ||
|
|
||
| Mock implementation of the Coingecko API for offline development and testing. | ||
|
|
||
| ## Overview | ||
|
|
||
| This service provides a lightweight mock of the Coingecko API, specifically the `/api/v3/simple/token_price` endpoint. It returns configurable prices for the 5 tokens deployed in offline mode. | ||
|
|
||
| ## Supported Tokens | ||
|
|
||
| The following tokens are supported (configured in `src/tokens.config.ts`): | ||
|
|
||
| | Symbol | Address | Price (ETH) | | ||
| |--------|---------|-------------| | ||
| | WETH | `0xb3af08c783c4d9c380893257980b5e26657f2317` | 1.0 | | ||
| | DAI | `0xb12812c0cad46d18b669b31059d485fe90b1a839` | 0.0004 | | ||
| | USDC | `0xb04afbcd351a0a7e4ff658b3772ee5f3f5b6e4ae` | 0.0004 | | ||
| | USDT | `0x171a30524fd943df1a12cbb9da291bf4e34ac84b` | 0.0004 | | ||
| | GNO | `0x51a53858a4a8b81814da35c4604eb9003d56a895` | 0.05 | | ||
|
|
||
| ## API Endpoints | ||
|
|
||
| ### Price Fetching | ||
|
|
||
| ```bash | ||
| GET /api/v3/simple/token_price/ethereum?contract_addresses=<addresses>&vs_currencies=eth&precision=full | ||
| ``` | ||
|
|
||
| **Query Parameters:** | ||
| - `contract_addresses`: Comma-separated list of token contract addresses | ||
| - `vs_currencies`: Currency denomination (only `eth` is supported) | ||
| - `precision`: Precision level (e.g., `full`) | ||
|
|
||
| **Example Request:** | ||
| ```bash | ||
| curl "http://localhost:3000/api/v3/simple/token_price/ethereum?contract_addresses=0xb3af08c783c4d9c380893257980b5e26657f2317,0xb12812c0cad46d18b669b31059d485fe90b1a839&vs_currencies=eth&precision=full" | ||
| ``` | ||
|
|
||
| **Example Response:** | ||
| ```json | ||
| { | ||
| "0xb3af08c783c4d9c380893257980b5e26657f2317": { | ||
| "eth": 1.0 | ||
| }, | ||
| "0xb12812c0cad46d18b669b31059d485fe90b1a839": { | ||
| "eth": 0.0004 | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Health Check | ||
|
|
||
| ```bash | ||
| GET /health | ||
| ``` | ||
|
|
||
| Returns the service status. | ||
|
|
||
| ### List Supported Tokens | ||
|
|
||
| ```bash | ||
| GET /api/v3/tokens | ||
| ``` | ||
|
|
||
| Returns a list of all supported token addresses. | ||
|
|
||
| ## Local Development | ||
|
|
||
| ### Prerequisites | ||
|
|
||
| - Node.js 20+ | ||
| - npm or yarn | ||
|
|
||
| ### Installation | ||
|
|
||
| ```bash | ||
| npm install | ||
| ``` | ||
|
|
||
| ### Running | ||
|
|
||
| ```bash | ||
| # Development mode with hot reload | ||
| npm run dev | ||
|
|
||
| # Production build | ||
| npm run build | ||
| npm start | ||
| ``` | ||
|
|
||
| ### Environment Variables | ||
|
|
||
| - `PORT`: Server port (default: 3000) | ||
|
|
||
| ## Docker | ||
|
|
||
| ### Build | ||
|
|
||
| ```bash | ||
| docker build -t coingecko-mock . | ||
| ``` | ||
|
|
||
| ### Run | ||
|
|
||
| ```bash | ||
| docker run -p 3000:3000 coingecko-mock | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| To add or modify token prices, edit `src/tokens.config.ts` and update the `TOKENS` object. | ||
|
|
||
| ## Limitations | ||
|
|
||
| - Only supports Ethereum platform (`ethereum`) | ||
| - Only supports ETH denomination (`vs_currencies=eth`) | ||
| - Only returns prices for tokens defined in `tokens.config.ts` | ||
| - Does not support historical prices, market caps, or other Coingecko features |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "name": "coingecko-mock", | ||
| "version": "1.0.0", | ||
| "description": "Mock Coingecko API for offline development", | ||
| "main": "dist/index.js", | ||
| "scripts": { | ||
| "dev": "tsx watch src/index.ts", | ||
| "build": "tsc", | ||
| "start": "node dist/index.js" | ||
| }, | ||
| "keywords": ["coingecko", "mock", "api"], | ||
| "author": "", | ||
| "license": "MIT", | ||
| "dependencies": { | ||
| "hono": "^4.0.0", | ||
| "@hono/node-server": "^1.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/node": "^20.0.0", | ||
| "tsx": "^4.0.0", | ||
| "typescript": "^5.0.0" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍