From db95d2aa79690bf6a3448d5c45a932d7e89a7907 Mon Sep 17 00:00:00 2001 From: Jon Ator Date: Mon, 2 Sep 2024 12:08:25 -0400 Subject: [PATCH 1/5] add authorized skip API client --- packages/bridge/src/skip/index.ts | 2 +- packages/bridge/src/skip/transfer-status.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/bridge/src/skip/index.ts b/packages/bridge/src/skip/index.ts index c32974768c..1c6cb24140 100644 --- a/packages/bridge/src/skip/index.ts +++ b/packages/bridge/src/skip/index.ts @@ -42,7 +42,7 @@ import { 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 { diff --git a/packages/bridge/src/skip/transfer-status.ts b/packages/bridge/src/skip/transfer-status.ts index 6670e0be86..b9105d0124 100644 --- a/packages/bridge/src/skip/transfer-status.ts +++ b/packages/bridge/src/skip/transfer-status.ts @@ -10,7 +10,7 @@ import type { TransferStatusReceiver, } from "../interface"; import { SkipBridgeProvider } from "."; -import { SkipApiClient } from "./queries"; +import { SkipApiClient } from "./client"; /** Tracks (polls skip endpoint) and reports status updates on Skip bridge transfers. */ export class SkipTransferStatusProvider implements TransferStatusProvider { From 7310d615e0a379c89ddd2672e62198d3118432d3 Mon Sep 17 00:00:00 2001 From: Jon Ator Date: Mon, 2 Sep 2024 12:17:24 -0400 Subject: [PATCH 2/5] fix build --- .../bridge/src/skip/{queries.ts => client.ts} | 74 ++++++++++++------- packages/bridge/src/skip/transfer-status.ts | 2 +- 2 files changed, 50 insertions(+), 26 deletions(-) rename packages/bridge/src/skip/{queries.ts => client.ts} (56%) diff --git a/packages/bridge/src/skip/queries.ts b/packages/bridge/src/skip/client.ts similarity index 56% rename from packages/bridge/src/skip/queries.ts rename to packages/bridge/src/skip/client.ts index d89f7a31ba..277b8b5b2e 100644 --- a/packages/bridge/src/skip/queries.ts +++ b/packages/bridge/src/skip/client.ts @@ -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; }>(url.toString()); @@ -47,7 +47,7 @@ export class SkipApiClient { url.searchParams.append("only_testnets", "true"); } - const data = await apiClient<{ + const data = await this.authorizedApiClient<{ chains: SkipChain[]; }>(url.toString()); @@ -55,24 +55,30 @@ export class SkipApiClient { } async route(options: SkipRouteRequest) { - return apiClient(`${this.baseUrl}/v2/fungible/route`, { - method: "POST", - body: JSON.stringify({ - ...options, - cumulative_affiliate_fee_bps: - options.cumulative_affiliate_fee_bps ?? "0", - }), - }); + return this.authorizedApiClient( + `${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(`${this.baseUrl}/v2/fungible/msgs`, { - method: "POST", - body: JSON.stringify({ - ...options, - slippage_tolerance_percent: options.slippage_tolerance_percent ?? "0", - }), - }); + return this.authorizedApiClient( + `${this.baseUrl}/v2/fungible/msgs`, + { + method: "POST", + body: JSON.stringify({ + ...options, + slippage_tolerance_percent: options.slippage_tolerance_percent ?? "0", + }), + } + ); } async trackTransaction({ @@ -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({ @@ -103,6 +112,21 @@ export class SkipApiClient { url.searchParams.append("chain_id", chainID); url.searchParams.append("tx_hash", txHash); - return apiClient(url.toString()); + return this.authorizedApiClient(url.toString()); + } + + protected authorizedApiClient( + ...args: Parameters + ) { + const key = process.env.SKIP_API_KEY; + + if (!key) throw new Error("SKIP_API_KEY is not set"); + + return apiClient(args[0], { + ...args[1], + headers: { + Authorization: `${key}`, + }, + }); } } diff --git a/packages/bridge/src/skip/transfer-status.ts b/packages/bridge/src/skip/transfer-status.ts index b9105d0124..d937f56135 100644 --- a/packages/bridge/src/skip/transfer-status.ts +++ b/packages/bridge/src/skip/transfer-status.ts @@ -9,8 +9,8 @@ import type { TransferStatusProvider, TransferStatusReceiver, } from "../interface"; -import { SkipBridgeProvider } from "."; 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 { From 65c0d0c1c674e12f36db823c63bb06a0b520a90c Mon Sep 17 00:00:00 2001 From: Jon Ator Date: Mon, 2 Sep 2024 12:18:11 -0400 Subject: [PATCH 3/5] cleanup --- packages/bridge/src/skip/index.ts | 5 ----- packages/bridge/src/squid/index.ts | 5 ----- 2 files changed, 10 deletions(-) diff --git a/packages/bridge/src/skip/index.ts b/packages/bridge/src/skip/index.ts index 1c6cb24140..4bce785b66 100644 --- a/packages/bridge/src/skip/index.ts +++ b/packages/bridge/src/skip/index.ts @@ -28,7 +28,6 @@ import { BridgeAsset, BridgeChain, BridgeCoin, - BridgeDepositAddress, BridgeExternalUrl, BridgeProvider, BridgeProviderContext, @@ -39,7 +38,6 @@ import { GetBridgeExternalUrlParams, GetBridgeQuoteParams, GetBridgeSupportedAssetsParams, - GetDepositAddressParams, } from "../interface"; import { BridgeAssetMap } from "../utils"; import { SkipApiClient } from "./client"; @@ -55,9 +53,6 @@ export class SkipBridgeProvider implements BridgeProvider { constructor(protected readonly ctx: BridgeProviderContext) { this.skipClient = new SkipApiClient(ctx.env); } - getDepositAddress?: - | ((params: GetDepositAddressParams) => Promise) - | undefined; async getQuote(params: GetBridgeQuoteParams): Promise { const { diff --git a/packages/bridge/src/squid/index.ts b/packages/bridge/src/squid/index.ts index efd3b59f7c..01792b617b 100644 --- a/packages/bridge/src/squid/index.ts +++ b/packages/bridge/src/squid/index.ts @@ -34,7 +34,6 @@ import { BridgeQuoteError } from "../errors"; import { BridgeAsset, BridgeChain, - BridgeDepositAddress, BridgeExternalUrl, BridgeProvider, BridgeProviderContext, @@ -45,7 +44,6 @@ import { GetBridgeExternalUrlParams, GetBridgeQuoteParams, GetBridgeSupportedAssetsParams, - GetDepositAddressParams, } from "../interface"; import { BridgeAssetMap } from "../utils"; import { getSquidErrors } from "./error"; @@ -72,9 +70,6 @@ export class SquidBridgeProvider implements BridgeProvider { ? "https://axelarscan.io" : "https://testnet.axelarscan.io"; } - getDepositAddress?: - | ((params: GetDepositAddressParams) => Promise) - | undefined; async getQuote({ fromAmount, From a0613fe00ed4f80a57fac6047711351b965d2ac4 Mon Sep 17 00:00:00 2001 From: Jon Ator Date: Mon, 2 Sep 2024 12:29:52 -0400 Subject: [PATCH 4/5] nits --- packages/bridge/src/skip/client.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/bridge/src/skip/client.ts b/packages/bridge/src/skip/client.ts index 277b8b5b2e..991f643d97 100644 --- a/packages/bridge/src/skip/client.ts +++ b/packages/bridge/src/skip/client.ts @@ -125,7 +125,8 @@ export class SkipApiClient { return apiClient(args[0], { ...args[1], headers: { - Authorization: `${key}`, + // This is the format confirmed by Skip team + Authorization: key, }, }); } From 940d3d7007af88cd0055bccc399aa4d6211d54ad Mon Sep 17 00:00:00 2001 From: Jon Ator Date: Mon, 2 Sep 2024 12:33:56 -0400 Subject: [PATCH 5/5] avoid auth in tests --- packages/bridge/src/skip/client.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/bridge/src/skip/client.ts b/packages/bridge/src/skip/client.ts index 991f643d97..51507064ff 100644 --- a/packages/bridge/src/skip/client.ts +++ b/packages/bridge/src/skip/client.ts @@ -118,13 +118,17 @@ export class SkipApiClient { protected authorizedApiClient( ...args: Parameters ) { - const key = process.env.SKIP_API_KEY; + if (process.env.NODE_ENV === "test") { + return apiClient(args[0], args[1]); + } + const key = process.env.SKIP_API_KEY; if (!key) throw new Error("SKIP_API_KEY is not set"); return apiClient(args[0], { ...args[1], headers: { + ...args[1]?.headers, // This is the format confirmed by Skip team Authorization: key, },