Skip to content
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ This will evolve as we continue to build out the platform and open up more ways
## Getting Help

If you have any additional questions or need help integrating Code into your website or application, please reach out to us on [Discord](https://discord.gg/T8Tpj8DBFp) or [Twitter](https://twitter.com/getcode).

### Using custom Swap API endpoints

You can set custom URLs via the configuration for any self-hosted Jupiter APIs, like the [V6 Swap API](https://station.jup.ag/docs/apis/self-hosted) or [Paid Hosted APIs](https://station.jup.ag/docs/apis/self-hosted#paid-hosted-apis) Here is an example:

```
JUPITER_API_BASE_URL=https://quote-api.jup.ag/v6/
```
17 changes: 14 additions & 3 deletions pkg/jupiter/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"encoding/json"
"fmt"
"io"
"os"

"net/http"
"strconv"
"strings"
Expand All @@ -17,17 +19,26 @@ import (
"github.com/code-payments/code-server/pkg/solana"
)

// Reference: https://station.jup.ag/docs/apis/swap-api
// Reference: https://station.jup.ag/docs/apis/swap-api + https://www.jupiterapi.com

const (
DefaultApiBaseUrl = "https://quote-api.jup.ag/v6/"
var (
DefaultApiBaseUrl = getEnv("JUPITER_API_BASE_URL", "https://public.jupiterapi.com/")

quoteEndpointName = "quote"
swapInstructionsEndpointName = "swap-instructions"

metricsStructName = "jupiter.client"
)

// getEnv tries to get the value of an environment variable named key
// and returns the value if found, or fallback value if not found.
func getEnv(key, fallback string) string {
if value, exists := os.LookupEnv(key); exists {
return value
}
return fallback
}

type Client struct {
baseUrl string
httpClient *http.Client
Expand Down