Skip to content

Commit

Permalink
Add OpenOcean proxy API (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doctor-Cyclone authored Feb 20, 2024
2 parents c135699 + 7f1c590 commit 55bff9c
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 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.1.0",
"version": "5.1.1",
"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,5 +1,5 @@
export const openOceanApiUrl = {
tokenList: (chain: string) => `https://open-api.openocean.finance/v3/${chain}/tokenList`,
quote: (chain: string) => `https://open-api.openocean.finance/v3/${chain}/quote`,
swapQuote: (chain: string) => `https://open-api.openocean.finance/v3/${chain}/swap_quote`
tokenList: (chain: string) => `https://x-api.rubic.exchange/oo/api/token_list/${chain}`,
quote: (chain: string) => `https://x-api.rubic.exchange/oo/api/v3/${chain}/quote`,
swapQuote: (chain: string) => `https://x-api.rubic.exchange/oo/api/v3/${chain}/swap_quote`
};
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export class OpenOceanProvider extends AggregatorOnChainProvider {
const apiUrl = openOceanApiUrl.quote(openOceanBlockchainName[blockchain]);
const quoteResponse = await pTimeout(
Injector.httpClient.get<OpenOceanQuoteResponse>(apiUrl, {
headers: { apikey: 'sndfje3u4b3fnNSDNFUSDNVSunw345842hrnfd3b4nt4' },
params: {
chain: openOceanBlockchainName[blockchain],
inTokenAddress: this.getTokenAddress(fromWithoutFee),
Expand Down Expand Up @@ -151,7 +152,10 @@ export class OpenOceanProvider extends AggregatorOnChainProvider {
const apiUrl = openOceanApiUrl.tokenList(
openOceanBlockchainName[from.blockchain as OpenoceanOnChainSupportedBlockchain]
);
const tokenListResponse = await Injector.httpClient.get<OpenOceanTokenListResponse>(apiUrl);
const tokenListResponse = await Injector.httpClient.get<OpenOceanTokenListResponse>(
apiUrl,
{ headers: { apikey: 'sndfje3u4b3fnNSDNFUSDNVSunw345842hrnfd3b4nt4' } }
);
const tokens = tokenListResponse?.data?.map(token => token.address.toLocaleLowerCase());
const isSupportedTokens =
Boolean(tokens.length) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export class OpenOceanTrade extends AggregatorEvmOnChainTrade {
const swapQuoteResponse = await Injector.httpClient.get<OpenoceanSwapQuoteResponse>(
apiUrl,
{
headers: { apikey: 'sndfje3u4b3fnNSDNFUSDNVSunw345842hrnfd3b4nt4' },
params: {
chain: openOceanBlockchainName[
this.from.blockchain as OpenoceanOnChainSupportedBlockchain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export abstract class OneinchAbstractProvider extends EvmOnChainProvider {
path: Token[];
data: string | null;
}> {
const fakeAddress = '0xe388Ed184958062a2ea29B7fD049ca21244AE02e';
const isDefaultWrappedAddress = options.wrappedAddress === oneinchApiParams.nativeAddress;
const isNative = from.isNative || from.address === oneinchApiParams.nativeAddress;
const fromTokenAddress =
Expand Down Expand Up @@ -182,7 +183,7 @@ export abstract class OneinchAbstractProvider extends EvmOnChainProvider {
params: {
...quoteTradeParams.params,
slippage: (options.slippageTolerance * 100).toString(),
from: this.walletAddress,
from: this.walletAddress || fakeAddress,
disableEstimate: options.gasCalculation === 'disabled'
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export function oneInchHttpGetRequest<T>(
return Injector.httpClient.get(
`https://x-api.rubic.exchange/api/swap/v5.2/${blockchainId[blockchain]}/${path}`,
{
...options
...options,
headers: { apikey: 'sndfje3u4b3fnNSDNFUSDNVSunw345842hrnfd3b4nt4' }
}
);
}
Expand All @@ -23,7 +24,8 @@ export function oneInchHttpGetApproveRequest<T>(
return Injector.httpClient.get(
`https://x-api.rubic.exchange/api/${path}/${blockchainId[blockchain]}`,
{
...options
...options,
headers: { apikey: 'sndfje3u4b3fnNSDNFUSDNVSunw345842hrnfd3b4nt4' }
}
);
}

0 comments on commit 55bff9c

Please sign in to comment.