Skip to content

Commit

Permalink
rango x-api (#800)
Browse files Browse the repository at this point in the history
  • Loading branch information
IDIDOS authored Jan 17, 2025
2 parents dfdd069 + 059dc6d commit e38f3c5
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 37 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rubic-sdk",
"version": "5.50.3",
"version": "5.50.4",
"description": "Simplify dApp creation",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const RANGO_API_KEY = 'a24ca428-a18e-4e84-b57f-edb3e2a5bf13';
export const RANGO_X_API_KEY = 'sndfje3u4b3fnNSDNFUSDNVSunw345842hrnfd3b4nt4';

export const RANGO_API_ENDPOINT = 'https://api.rango.exchange/basic';
export const RANGO_X_API_ENDPOINT = 'https://x-api.rubic.exchange/rango/basic';
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export interface RangoSwapQueryParams {
apiKey: string;
from: string;
to: string;
amount: string;
Expand All @@ -19,7 +18,6 @@ export interface RangoSwapQueryParams {
}

export interface RangoBestRouteQueryParams {
apiKey: string;
from: string;
to: string;
amount: string;
Expand All @@ -31,12 +29,10 @@ export interface RangoBestRouteQueryParams {
}

/**
* @property {string} apiKey
* @property {string} requestId Random UUID returned in swap/quote methodes in response
* @property {string} srcTxHash In Rango-api used as `txId` queryParam in getTxStatus request
*/
export interface RangoTxStatusQueryParams {
apiKey: string;
requestId: string;
txId: string;
}
9 changes: 1 addition & 8 deletions src/features/common/providers/rango/services/rango-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Injector } from 'src/core/injector/injector';
import { FAKE_WALLET_ADDRESS } from 'src/features/common/constants/fake-wallet-address';
import { BRIDGE_TYPE } from 'src/features/cross-chain/calculation-manager/providers/common/models/bridge-type';

import { RANGO_API_KEY } from '../constants/rango-api-common';
import { RangoBestRouteRequestOptions } from '../models/rango-api-best-route-types';
import { RangoSwapRequestOptions } from '../models/rango-api-swap-types';
import { RangoTradeType, RUBIC_TO_RANGO_PROVIDERS } from '../models/rango-api-trade-types';
Expand All @@ -31,12 +30,10 @@ export class RangoCommonParser {
const toParam = await RangoUtils.getFromToQueryParam(toToken);
const disabledProviders = this.getRangoDisabledProviders(from, options.swapperGroups || []);
const amountParam = Web3Pure.toWei(from.tokenAmount, from.decimals);
const apiKey = RANGO_API_KEY;
const swapperGroups = disabledProviders?.join(',');
const fromBlockchainType = BlockchainsInfo.getChainType(from.blockchain);

return {
apiKey,
from: fromParam,
to: toParam,
amount: amountParam,
Expand Down Expand Up @@ -67,12 +64,10 @@ export class RangoCommonParser {
const fromAddress = options.fromAddress || walletAddress;
const toAddress = options?.receiverAddress || walletAddress || FAKE_WALLET_ADDRESS;
const slippage = options.slippageTolerance * 100;
const apiKey = RANGO_API_KEY;
const swapperGroups = disabledProviders?.join(',');
const fromBlockchainType = BlockchainsInfo.getChainType(fromToken.blockchain);

return {
apiKey,
amount,
from,
to,
Expand All @@ -89,9 +84,7 @@ export class RangoCommonParser {
srcTxHash: string,
requestId: string
): RangoTxStatusQueryParams {
const apiKey = RANGO_API_KEY;

return { apiKey, requestId, txId: srcTxHash };
return { requestId, txId: srcTxHash };
}

private static getRangoDisabledProviders(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import {
FAKE_BITCOIN_ADDRESS,
FAKE_WALLET_ADDRESS
} from 'src/features/common/constants/fake-wallet-address';
import {
RANGO_API_ENDPOINT,
RANGO_API_KEY
} from 'src/features/common/providers/rango/constants/rango-api-common';
import {
RangoBestRouteSimulationResult,
RangoQuotePath,
Expand Down Expand Up @@ -42,10 +38,6 @@ import { RangoCrossChainApiService } from './services/rango-cross-chain-api-serv
export class RangoCrossChainProvider extends CrossChainProvider {
public type: CrossChainTradeType = CROSS_CHAIN_TRADE_TYPE.RANGO;

public static readonly apiKey = RANGO_API_KEY;

public static readonly apiEndpoint = RANGO_API_ENDPOINT;

private rangoSupportedBlockchains = rangoSupportedBlockchains;

public isSupportedBlockchain(blockchain: EvmBlockchainName): boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { RubicSdkError } from 'src/common/errors';
import { Cache } from 'src/common/utils/decorators';
import { Injector } from 'src/core/injector/injector';
import { RANGO_API_ENDPOINT } from 'src/features/common/providers/rango/constants/rango-api-common';
import {
RANGO_X_API_ENDPOINT,
RANGO_X_API_KEY
} from 'src/features/common/providers/rango/constants/rango-api-common';
import { RangoBestRouteResponse } from 'src/features/common/providers/rango/models/rango-api-best-route-types';
import { HttpClientParams } from 'src/features/common/providers/rango/models/rango-api-common-types';
import { RangoTxStatusResponse } from 'src/features/common/providers/rango/models/rango-api-status-types';
Expand All @@ -17,9 +20,10 @@ export class RangoCrossChainApiService {
params: RangoBestRouteQueryParams
): Promise<RangoBestRouteResponse> {
const res = await Injector.httpClient.get<RangoBestRouteResponse>(
`${RANGO_API_ENDPOINT}/quote`,
`${RANGO_X_API_ENDPOINT}/quote`,
{
params: params as unknown as HttpClientParams
params: params as unknown as HttpClientParams,
headers: { apiKey: RANGO_X_API_KEY }
}
);

Expand All @@ -37,8 +41,8 @@ export class RangoCrossChainApiService {
params: RangoSwapQueryParams
): Promise<RangoSwapTransactionResponse> {
const res = await Injector.httpClient.get<RangoSwapTransactionResponse>(
`${RANGO_API_ENDPOINT}/swap`,
{ params: params as unknown as HttpClientParams }
`${RANGO_X_API_ENDPOINT}/swap`,
{ params: params as unknown as HttpClientParams, headers: { apiKey: RANGO_X_API_KEY } }
);

if (!res.route || res.error) {
Expand All @@ -55,8 +59,8 @@ export class RangoCrossChainApiService {
params: RangoTxStatusQueryParams
): Promise<RangoTxStatusResponse> {
const res = await Injector.httpClient.get<RangoTxStatusResponse>(
`${RANGO_API_ENDPOINT}/status`,
{ params: params as unknown as HttpClientParams }
`${RANGO_X_API_ENDPOINT}/status`,
{ params: params as unknown as HttpClientParams, headers: { apiKey: RANGO_X_API_KEY } }
);

if (res.error || !res.bridgeData || !res.status) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { RubicSdkError } from 'src/common/errors';
import { Cache } from 'src/common/utils/decorators';
import { Injector } from 'src/core/injector/injector';
import { RANGO_API_ENDPOINT } from 'src/features/common/providers/rango/constants/rango-api-common';
import {
RANGO_X_API_ENDPOINT,
RANGO_X_API_KEY
} from 'src/features/common/providers/rango/constants/rango-api-common';
import { RangoBestRouteResponse } from 'src/features/common/providers/rango/models/rango-api-best-route-types';
import { HttpClientParams } from 'src/features/common/providers/rango/models/rango-api-common-types';
import { RangoTxStatusResponse } from 'src/features/common/providers/rango/models/rango-api-status-types';
Expand All @@ -17,9 +20,10 @@ export class RangoOnChainApiService {
params: RangoBestRouteQueryParams
): Promise<RangoBestRouteResponse> {
const res = await Injector.httpClient.get<RangoBestRouteResponse>(
`${RANGO_API_ENDPOINT}/quote`,
`${RANGO_X_API_ENDPOINT}/quote`,
{
params: params as unknown as HttpClientParams
params: params as unknown as HttpClientParams,
headers: { apiKey: RANGO_X_API_KEY }
}
);

Expand All @@ -38,8 +42,8 @@ export class RangoOnChainApiService {
isSwap: boolean
): Promise<RangoSwapTransactionResponse> {
const res = await Injector.httpClient.get<RangoSwapTransactionResponse>(
`${RANGO_API_ENDPOINT}/swap`,
{ params: params as unknown as HttpClientParams }
`${RANGO_X_API_ENDPOINT}/swap`,
{ params: params as unknown as HttpClientParams, headers: { apiKey: RANGO_X_API_KEY } }
);

if (!res.route || (isSwap && (res.error || !res.tx))) {
Expand All @@ -56,8 +60,8 @@ export class RangoOnChainApiService {
params: RangoTxStatusQueryParams
): Promise<RangoTxStatusResponse> {
const res = await Injector.httpClient.get<RangoTxStatusResponse>(
`${RANGO_API_ENDPOINT}/status`,
{ params: params as unknown as HttpClientParams }
`${RANGO_X_API_ENDPOINT}/status`,
{ params: params as unknown as HttpClientParams, headers: { apiKey: RANGO_X_API_KEY } }
);

if (res.error || !res.bridgeData || !res.status) {
Expand Down

0 comments on commit e38f3c5

Please sign in to comment.