From 69e8fb060c1d38af38f08e6cab1cc83e0cb6bc71 Mon Sep 17 00:00:00 2001 From: "zer0cache@protonmail.com" Date: Thu, 29 Feb 2024 13:51:39 -0500 Subject: [PATCH 1/3] Make jupiter swap api an env var --- pkg/jupiter/client.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/pkg/jupiter/client.go b/pkg/jupiter/client.go index a4552e25..205b29e2 100644 --- a/pkg/jupiter/client.go +++ b/pkg/jupiter/client.go @@ -6,6 +6,8 @@ import ( "encoding/json" "fmt" "io" + "os" + "net/http" "strconv" "strings" @@ -17,10 +19,10 @@ 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" @@ -28,6 +30,15 @@ const ( 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 From 61c7b97a3355e1fbdb283c0ce4679847a69b0f5c Mon Sep 17 00:00:00 2001 From: "zer0cache@protonmail.com" Date: Mon, 4 Mar 2024 14:58:02 -0500 Subject: [PATCH 2/3] Update README --- README.md | 8 ++++++++ pkg/jupiter/client.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 403ec57e..a2d07d8b 100644 --- a/README.md +++ b/README.md @@ -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/ +``` \ No newline at end of file diff --git a/pkg/jupiter/client.go b/pkg/jupiter/client.go index 205b29e2..000eaa38 100644 --- a/pkg/jupiter/client.go +++ b/pkg/jupiter/client.go @@ -22,7 +22,7 @@ import ( // Reference: https://station.jup.ag/docs/apis/swap-api + https://www.jupiterapi.com var ( - DefaultApiBaseUrl = getEnv("JUPITER_API_BASE_URL", "https://public.jupiterapi.com/") + DefaultApiBaseUrl = getEnv("JUPITER_API_BASE_URL", "https://quote-api.jup.ag/v6/") quoteEndpointName = "quote" swapInstructionsEndpointName = "swap-instructions" From 26b33815514255b92e207f204901cdf7b29bd87a Mon Sep 17 00:00:00 2001 From: "zer0cache@protonmail.com" Date: Mon, 4 Mar 2024 15:00:07 -0500 Subject: [PATCH 3/3] Update default URL for higher rate limits --- pkg/jupiter/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/jupiter/client.go b/pkg/jupiter/client.go index 000eaa38..205b29e2 100644 --- a/pkg/jupiter/client.go +++ b/pkg/jupiter/client.go @@ -22,7 +22,7 @@ import ( // Reference: https://station.jup.ag/docs/apis/swap-api + https://www.jupiterapi.com var ( - DefaultApiBaseUrl = getEnv("JUPITER_API_BASE_URL", "https://quote-api.jup.ag/v6/") + DefaultApiBaseUrl = getEnv("JUPITER_API_BASE_URL", "https://public.jupiterapi.com/") quoteEndpointName = "quote" swapInstructionsEndpointName = "swap-instructions"