Skip to content

astriaorg/swap-routing-api

Repository files navigation

Swap Router API

A Google Cloud Function that provides quote functionality for token swaps.

Overview

This service exposes an HTTP endpoint that allows users to get the best route for swapping tokens on a decentralized exchange.

Getting Started

Prerequisites

  • Node.js 22
  • Google Cloud SDK
  • TypeScript

Installation

  1. Clone the repository
  2. Install dependencies:
npm install

Environment Variables

  • LOG_LEVEL: Controls the logging verbosity (default: "debug")

API Reference

Get Quote Route

Calculate the optimal route for swapping between two tokens.

GET /getQuote

Request Parameters

Parameter Type Description
tokenIn string Source token address
tokenOut string Destination token address
amount string Amount of tokenIn to swap

Response

{
  route: string[];          // Array of token addresses in the swap route
  estimatedOutput: string;  // Estimated output amount
  price: string;           // Price impact of the swap
}

Error Responses

  • 400 Bad Request: Missing required parameters
  • 405 Method Not Allowed: Invalid HTTP method
  • 500 Internal Server Error: Server-side error

Logging

The service uses Winston for structured logging with JSON format. All logs include timestamps and are output to the console.

Development

Project Structure

├── index.ts          # Main function handler
└── utils
    └── logger.ts     # Logging configuration

Building

npm run dev

Testing, Linting, Formatting

just test
# lints ts, md files
just lint
# formats ts, md files
npm run format

About

A cloud function that provides quotes for token swaps.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published