Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Skip API key #3816

Merged
merged 5 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class SkipApiClient {
url.searchParams.append("only_testnets", "true");
}

const data = await apiClient<{
const data = await this.authorizedApiClient<{
chain_to_assets_map: Record<string, { assets: SkipAsset[] }>;
}>(url.toString());

Expand All @@ -47,32 +47,38 @@ export class SkipApiClient {
url.searchParams.append("only_testnets", "true");
}

const data = await apiClient<{
const data = await this.authorizedApiClient<{
chains: SkipChain[];
}>(url.toString());

return data.chains;
}

async route(options: SkipRouteRequest) {
return apiClient<SkipRouteResponse>(`${this.baseUrl}/v2/fungible/route`, {
method: "POST",
body: JSON.stringify({
...options,
cumulative_affiliate_fee_bps:
options.cumulative_affiliate_fee_bps ?? "0",
}),
});
return this.authorizedApiClient<SkipRouteResponse>(
`${this.baseUrl}/v2/fungible/route`,
{
method: "POST",
body: JSON.stringify({
...options,
cumulative_affiliate_fee_bps:
options.cumulative_affiliate_fee_bps ?? "0",
}),
}
);
}

async messages(options: SkipMsgsRequest) {
return apiClient<SkipMsgsResponse>(`${this.baseUrl}/v2/fungible/msgs`, {
method: "POST",
body: JSON.stringify({
...options,
slippage_tolerance_percent: options.slippage_tolerance_percent ?? "0",
}),
});
return this.authorizedApiClient<SkipMsgsResponse>(
`${this.baseUrl}/v2/fungible/msgs`,
{
method: "POST",
body: JSON.stringify({
...options,
slippage_tolerance_percent: options.slippage_tolerance_percent ?? "0",
}),
}
);
}

async trackTransaction({
Expand All @@ -82,13 +88,16 @@ export class SkipApiClient {
chainID: string;
txHash: string;
}) {
return apiClient<{ tx_id: string }>(`${this.baseUrl}/v2/tx/track`, {
method: "POST",
body: JSON.stringify({
chain_id: chainID,
tx_hash: txHash,
}),
});
return this.authorizedApiClient<{ tx_id: string }>(
`${this.baseUrl}/v2/tx/track`,
{
method: "POST",
body: JSON.stringify({
chain_id: chainID,
tx_hash: txHash,
}),
}
);
}

async transactionStatus({
Expand All @@ -103,6 +112,21 @@ export class SkipApiClient {
url.searchParams.append("chain_id", chainID);
url.searchParams.append("tx_hash", txHash);

return apiClient<SkipTxStatusResponse>(url.toString());
return this.authorizedApiClient<SkipTxStatusResponse>(url.toString());
}

protected authorizedApiClient<Response>(
...args: Parameters<typeof apiClient>
) {
const key = process.env.SKIP_API_KEY;

if (!key) throw new Error("SKIP_API_KEY is not set");

return apiClient<Response>(args[0], {
...args[1],
headers: {
Authorization: `${key}`,
jonator marked this conversation as resolved.
Show resolved Hide resolved
},
});
}
}
7 changes: 1 addition & 6 deletions packages/bridge/src/skip/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
BridgeAsset,
BridgeChain,
BridgeCoin,
BridgeDepositAddress,
BridgeExternalUrl,
BridgeProvider,
BridgeProviderContext,
Expand All @@ -39,10 +38,9 @@ import {
GetBridgeExternalUrlParams,
GetBridgeQuoteParams,
GetBridgeSupportedAssetsParams,
GetDepositAddressParams,
} from "../interface";
import { BridgeAssetMap } from "../utils";
import { SkipApiClient } from "./queries";
import { SkipApiClient } from "./client";
import { SkipEvmTx, SkipMsg, SkipMultiChainMsg } from "./types";

export class SkipBridgeProvider implements BridgeProvider {
Expand All @@ -55,9 +53,6 @@ export class SkipBridgeProvider implements BridgeProvider {
constructor(protected readonly ctx: BridgeProviderContext) {
this.skipClient = new SkipApiClient(ctx.env);
}
getDepositAddress?:
| ((params: GetDepositAddressParams) => Promise<BridgeDepositAddress>)
| undefined;

async getQuote(params: GetBridgeQuoteParams): Promise<BridgeQuote> {
const {
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge/src/skip/transfer-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import type {
TransferStatusProvider,
TransferStatusReceiver,
} from "../interface";
import { SkipBridgeProvider } from ".";
import { SkipApiClient } from "./queries";
import { SkipApiClient } from "./client";
import { SkipBridgeProvider } from "./index";

/** Tracks (polls skip endpoint) and reports status updates on Skip bridge transfers. */
export class SkipTransferStatusProvider implements TransferStatusProvider {
Expand Down
5 changes: 0 additions & 5 deletions packages/bridge/src/squid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { BridgeQuoteError } from "../errors";
import {
BridgeAsset,
BridgeChain,
BridgeDepositAddress,
BridgeExternalUrl,
BridgeProvider,
BridgeProviderContext,
Expand All @@ -45,7 +44,6 @@ import {
GetBridgeExternalUrlParams,
GetBridgeQuoteParams,
GetBridgeSupportedAssetsParams,
GetDepositAddressParams,
} from "../interface";
import { BridgeAssetMap } from "../utils";
import { getSquidErrors } from "./error";
Expand All @@ -72,9 +70,6 @@ export class SquidBridgeProvider implements BridgeProvider {
? "https://axelarscan.io"
: "https://testnet.axelarscan.io";
}
getDepositAddress?:
| ((params: GetDepositAddressParams) => Promise<BridgeDepositAddress>)
| undefined;

async getQuote({
fromAmount,
Expand Down
Loading