Skip to content
Merged
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
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ VITE_JITO_BLOCK_ENGINE_URL=https://mainnet.block-engine.jito.wtf

# relay
VITE_RELAY_API_URL=https://api.relay.link
VITE_RELAY_API_KEY=d62274fb-1edd-481a-b952-632896ebf830
Comment thread
coderabbitai[bot] marked this conversation as resolved.

# affiliate revenue
VITE_AFFILIATE_REVENUE_URL=https://api.revenue.shapeshift.com
Expand Down
1 change: 1 addition & 0 deletions packages/public-api/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ ACROSS_API_KEY=
BEBOP_API_KEY=
CHAINFLIP_API_KEY=
NEAR_INTENTS_API_KEY=
RELAY_API_KEY=

# Affiliate
DEFAULT_AFFILIATE_BPS=60
Expand Down
1 change: 1 addition & 0 deletions packages/public-api/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const getServerConfig = (): SwapperConfig => ({
VITE_CHAINFLIP_API_URL: env.CHAINFLIP_API_URL,
VITE_FEATURE_CHAINFLIP_SWAP_DCA: env.FEATURE_CHAINFLIP_SWAP_DCA,
VITE_RELAY_API_URL: env.RELAY_API_URL,
VITE_RELAY_API_KEY: env.RELAY_API_KEY,
VITE_BEBOP_API_KEY: env.BEBOP_API_KEY,
VITE_NEAR_INTENTS_API_KEY: env.NEAR_INTENTS_API_KEY,
VITE_TRON_GRID_API_KEY: env.TRON_GRID_API_KEY,
Expand Down
1 change: 1 addition & 0 deletions packages/public-api/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ const envSchema = z.object({
BOB_GATEWAY_API_KEY: z.string().default(''),
CHAINFLIP_API_KEY: z.string().min(1),
NEAR_INTENTS_API_KEY: z.string().min(1),
RELAY_API_KEY: z.string().default(''),
TRON_GRID_API_KEY: z.string().default(''),

// Feature flags
Expand Down
11 changes: 8 additions & 3 deletions packages/swapper/src/swappers/RelaySwapper/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getTradeQuote } from './getTradeQuote/getTradeQuote'
import { getTradeRate } from './getTradeRate/getTradeRate'
import { getLatestRelayStatusMessage } from './utils/getLatestRelayStatusMessage'
import { notifyTransactionIndexing } from './utils/notifyTransactionIndexing'
import { relayService } from './utils/relayService'
import { getRelayRequestConfig, relayService } from './utils/relayService'
import type { RelayStatus, RelayTradeQuoteInput, RelayTradeRateInput } from './utils/types'

// Keep track of the trades we already notified the relay indexer about
Expand Down Expand Up @@ -86,7 +86,8 @@ export const relayApi: SwapperApi = {
const swapperTxLink = `https://relay.link/transaction/${txHash}`

const maybeStatusResponse = await relayService.get<RelayStatus>(
`${config.VITE_RELAY_API_URL}/intents/status/v2?requestId=${relayMetadata.relayId}`,
`${config.VITE_RELAY_API_URL}/intents/status/v3?requestId=${relayMetadata.relayId}`,
getRelayRequestConfig(config),
)

if (maybeStatusResponse.isErr()) {
Expand All @@ -105,9 +106,13 @@ export const relayApi: SwapperApi = {
switch (statusResponse.status) {
case 'success':
return TxStatus.Confirmed
case 'waiting':
case 'delayed':
case 'pending':
case 'depositing':
case 'submitted':
return TxStatus.Pending
case 'failed':
case 'failure':
case 'refund':
return TxStatus.Failed
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import type { Result } from '@sniptt/monads'
import type { AxiosResponse } from 'axios'

import type { SwapErrorRight, SwapperConfig } from '../../../types'
import { relayService } from './relayService'
import { getRelayRequestConfig, relayService } from './relayService'
import type { RelayFetchQuoteParams, RelayQuote } from './types'

export const fetchRelayTrade = async <T extends 'quote' | 'rate'>(
params: RelayFetchQuoteParams<T>,
config: SwapperConfig,
): Promise<Result<AxiosResponse<RelayQuote, any>, SwapErrorRight>> => {
return await relayService.post<RelayQuote>(`${config.VITE_RELAY_API_URL}/quote/v2`, params)
return await relayService.post<RelayQuote>(
`${config.VITE_RELAY_API_URL}/quote/v2`,
params,
getRelayRequestConfig(config),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ export const getLatestRelayStatusMessage = (status: RelayStatus): string => {
case statusValue === 'delayed':
return RelayStatusMessage.Retrying
case statusValue === 'pending':
case statusValue === 'depositing':
case statusValue === 'submitted':
return RelayStatusMessage.DepositDetected
case statusValue === 'success':
return RelayStatusMessage.SwapComplete
case statusValue === 'failed':
case statusValue === 'failure':
Comment thread
coderabbitai[bot] marked this conversation as resolved.
return RelayStatusMessage.SwapFailed
default:
return 'Unknown status'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Result } from '@sniptt/monads'
import type { AxiosResponse } from 'axios'

import type { SwapErrorRight, SwapperConfig } from '../../../types'
import { relayService } from './relayService'
import { getRelayRequestConfig, relayService } from './relayService'
import type { RelayQuote } from './types'

type NotifyTransactionIndexingParams = {
Expand All @@ -18,5 +18,6 @@ export const notifyTransactionIndexing = async (
return await relayService.post<RelayQuote>(
`${config.VITE_RELAY_API_URL}/transactions/single`,
params,
getRelayRequestConfig(config),
)
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import type { AxiosRequestConfig } from 'axios'

import type { SwapperConfig } from '../../../types'
import { createCache, makeSwapperAxiosServiceMonadic } from '../../../utils'

const maxAgeMillis = 15 * 1000
Expand All @@ -14,3 +17,6 @@ const axiosConfig = {
const relayServiceBase = createCache(maxAgeMillis, cachedUrls, axiosConfig)

export const relayService = makeSwapperAxiosServiceMonadic(relayServiceBase)

export const getRelayRequestConfig = (config: SwapperConfig): AxiosRequestConfig | undefined =>
config.VITE_RELAY_API_KEY ? { headers: { 'x-api-key': config.VITE_RELAY_API_KEY } } : undefined
12 changes: 10 additions & 2 deletions packages/swapper/src/swappers/RelaySwapper/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,19 @@ export type RelayMetadata = {
}

export type RelayStatus = {
status: 'success' | 'failed' | 'pending' | 'refund' | 'delayed' | 'waiting'
status:
| 'success'
| 'failure'
| 'pending'
| 'submitted'
| 'depositing'
| 'refund'
| 'delayed'
| 'waiting'
details?: string
inTxHashes: string[]
txHashes: string[]
time: number
updatedAt: number
originChainId: number
destinationChainId: number
}
Expand Down
1 change: 1 addition & 0 deletions packages/swapper/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export type SwapperConfig = {
VITE_CHAINFLIP_API_URL: string
VITE_FEATURE_CHAINFLIP_SWAP_DCA: boolean
VITE_RELAY_API_URL: string
VITE_RELAY_API_KEY: string
VITE_BEBOP_API_KEY: string
VITE_NEAR_INTENTS_API_KEY: string
VITE_SUI_NODE_URL: string
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ const validators = {
VITE_FEATURE_THORCHAIN_TCY_WIDGET: bool({ default: false }),
VITE_FEATURE_THORCHAIN_TCY_ACTIVITY: bool({ default: false }),
VITE_RELAY_API_URL: url(),
VITE_RELAY_API_KEY: str({ default: '' }),
VITE_COINCAP_API_KEY: str(),
VITE_FEATURE_MAYA_SWAP: bool({ default: false }),
VITE_FEATURE_BUTTERSWAP: bool({ default: false }),
Expand Down
1 change: 1 addition & 0 deletions src/vite-env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ interface ImportMetaEnv {
readonly VITE_BERACHAIN_NODE_URL: string
readonly VITE_FEATURE_BERACHAIN: string
readonly VITE_RELAY_API_URL: string
readonly VITE_RELAY_API_KEY: string
Comment thread
coderabbitai[bot] marked this conversation as resolved.
readonly VITE_TENDERLY_ACCOUNT_SLUG: string
readonly VITE_TENDERLY_PROJECT_SLUG: string
readonly VITE_TENDERLY_API_KEY: string
Expand Down
Loading