Skip to content

Commit

Permalink
Chore/merge alchemy changes (#1185)
Browse files Browse the repository at this point in the history
* feat: adds alchemy and changes api key and api usage

* chore: changeset

* chore: fix bsc alchemy symbol

* feat: WIP improve api handling

* feat: WIP improve api handling

* feat: WIP nightly release

* feat: WIP nightly release

* feat: WIP nightly release

* chore: bump version

* chore: bump version

* chore: nightly

* chore: nightly

* wip: nightly

* wip: nightly

* wip: fix up branch

* wip: fix up branch

* chore: changeset

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
towanTG and github-actions[bot] authored Feb 12, 2025
1 parent 522d696 commit 6b9a5d7
Show file tree
Hide file tree
Showing 65 changed files with 2,760 additions and 966 deletions.
27 changes: 27 additions & 0 deletions .changeset/hungry-zoos-rush.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
"@swapkit/wallet-evm-extensions": minor
"@swapkit/wallet-keepkey-bex": minor
"@swapkit/wallet-polkadotjs": minor
"@swapkit/plugin-chainflip": minor
"@swapkit/toolbox-cosmos": minor
"@swapkit/wallet-coinbase": minor
"@swapkit/wallet-keystore": minor
"@swapkit/wallet-talisman": minor
"@swapkit/helpers": minor
"@swapkit/wallet-phantom": minor
"@swapkit/tokens": minor
"@swapkit/wizard": minor
"@swapkit/toolbox-utxo": minor
"@swapkit/wallet-bitget": minor
"@swapkit/wallet-exodus": minor
"@swapkit/wallet-ledger": minor
"@swapkit/wallet-trezor": minor
"@swapkit/toolbox-evm": minor
"@swapkit/wallet-keplr": minor
"@swapkit/wallet-ctrl": minor
"@swapkit/api": minor
"@swapkit/wallet-okx": minor
"@swapkit/wallet-wc": minor
---

Adds alchemy api and refactors wallets api handling internally
Binary file modified bun.lockb
Binary file not shown.
14 changes: 9 additions & 5 deletions packages/plugins/chainflip/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { swapkitApiEndpoints } from "@swapkit/api";
import {
AssetValue,
type ConnectConfig,
type EVMWallets,
ProviderName,
type SolanaWallets,
Expand All @@ -15,11 +16,13 @@ type SupportedChain = keyof (EVMWallets & SubstrateWallets & UTXOWallets & Solan

function plugin({
getWallet,
config: { chainflipBrokerUrl: legacyChainflipBrokerUrl, chainflipBrokerConfig },
}: SwapKitPluginParams<{
chainflipBrokerUrl?: string;
chainflipBrokerConfig?: { chainflipBrokerUrl: string };
}>) {
config: {
chainflipBrokerUrl: legacyChainflipBrokerUrl,
chainflipBrokerConfig,
swapkitConfig,
swapkitApiKey,
},
}: SwapKitPluginParams<ConnectConfig>) {
async function swap(swapParams: RequestSwapDepositAddressParams) {
const { chainflipBrokerUrl } = chainflipBrokerConfig || {};

Expand Down Expand Up @@ -66,6 +69,7 @@ function plugin({
destinationAddress: recipient || chainflip.destinationAddress,
maxBoostFeeBps: maxBoostFeeBps || chainflip.maxBoostFeeBps,
},
apiKey: swapkitApiKey || swapkitConfig?.swapkitApiKey,
});

const tx = await wallet.transfer({
Expand Down
21 changes: 14 additions & 7 deletions packages/swapkit/api/src/swapkitApi/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ function getBaseUrl(isDev?: boolean) {
return isDev ? baseUrlDev : baseUrl;
}

const getAuthHeaders = (hash?: string, apiKey?: string, referer?: string) => ({
const getAuthHeaders = ({
hash,
apiKey,
referer,
}: { hash?: string; apiKey?: string; referer?: string }) => ({
...(apiKey && !hash ? { "x-api-key": apiKey } : {}),
...(hash && referer ? { "x-payload-hash": hash, referer } : {}),
});
Expand Down Expand Up @@ -89,7 +93,7 @@ export function getTrackerDetails(payload: TrackerParams, apiKey?: string, refer
: undefined;
return RequestClient.post<TrackerResponse>(url, {
json: payload,
headers: getAuthHeaders(hash, apiKey, referer),
headers: getAuthHeaders({ hash, apiKey, referer }),
});
}

Expand Down Expand Up @@ -122,7 +126,7 @@ export async function getSwapQuote<T extends boolean>(
: undefined;
const response = await RequestClient.post<QuoteResponse>(url, {
json: searchParams,
headers: getAuthHeaders(hash, apiKey, referer),
headers: getAuthHeaders({ hash, apiKey, referer }),
});

if (response.error) {
Expand Down Expand Up @@ -155,7 +159,7 @@ export function getTokenListProvidersV2(isDev = false, apiKey?: string, referer?
})
: undefined;
return RequestClient.get<TokenListProvidersResponse>(url, {
headers: getAuthHeaders(hash, apiKey, referer),
headers: getAuthHeaders({ hash, apiKey, referer }),
});
}

Expand Down Expand Up @@ -187,7 +191,7 @@ export function getTokenList(
})
: undefined;
return RequestClient.get<TokensResponseV2>(url, {
headers: getAuthHeaders(hash, apiKey, referer),
headers: getAuthHeaders({ hash, apiKey, referer }),
});
}

Expand All @@ -208,7 +212,7 @@ export async function getPrice(
: undefined;
const response = await RequestClient.post<PriceResponse>(url, {
json: body,
headers: getAuthHeaders(hash, apiKey, referer),
headers: getAuthHeaders({ hash, apiKey, referer }),
});

try {
Expand Down Expand Up @@ -236,7 +240,7 @@ export async function getGasRate(isDev = false, apiKey?: string, referer?: strin
: undefined;

const response = await RequestClient.get<GasResponse>(url, {
headers: getAuthHeaders(hash, apiKey, referer),
headers: getAuthHeaders({ hash, apiKey, referer }),
});

try {
Expand Down Expand Up @@ -351,9 +355,11 @@ export async function getChainflipDepositChannel({
isDev = false,
baseUrl,
body,
apiKey,
}: {
isDev?: boolean;
baseUrl?: string;
apiKey?: string;
body: BrokerDepositChannelParams;
}) {
const { destinationAddress } = body;
Expand All @@ -365,6 +371,7 @@ export async function getChainflipDepositChannel({

const response = await RequestClient.post<DepositChannelResponse>(url, {
json: body,
headers: getAuthHeaders({ apiKey }),
});

try {
Expand Down
21 changes: 6 additions & 15 deletions packages/swapkit/helpers/src/helpers/web3wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,14 @@ export const listWeb3EVMWallets = () => {
return wallets;
};

export function ensureEVMApiKeys({
export function pickEvmApiKey({
chain,
covalentApiKey,
ethplorerApiKey,
}: { chain: Chain; covalentApiKey?: string; ethplorerApiKey?: string }) {
const missingKey =
chain !== Chain.Ethereum && !covalentApiKey
? "covalentApiKey"
: ethplorerApiKey
? undefined
: "ethplorerApiKey";

if (missingKey) {
throw new SwapKitError({ errorKey: "wallet_missing_api_key", info: { missingKey } });
}
nonEthApiKey,
ethApiKey,
}: { chain: Chain; nonEthApiKey?: string; ethApiKey?: string }) {
const apiKey = chain === Chain.Ethereum ? ethApiKey : nonEthApiKey;

return { covalentApiKey: covalentApiKey as string, ethplorerApiKey: ethplorerApiKey as string };
return apiKey;
}

export function getEIP6963Wallets() {
Expand Down
4 changes: 2 additions & 2 deletions packages/swapkit/helpers/src/modules/assetValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class AssetValue extends BigIntArithmetics {

warnOnce(
!(asyncTokenLookup || tokenDecimal),
`Couldn't find static decimal for ${unsafeIdentifier} (Using default ${BaseDecimal[chain]} decimal as fallback).
`Couldn't find static decimal for a token on chain (Using default ${BaseDecimal[chain]} decimal as fallback).
This can result in incorrect calculations and mess with amount sent on transactions.
You can load static assets by installing @swapkit/tokens package and calling AssetValue.loadStaticAssets()
or by passing asyncTokenLookup: true to the from() function, which will make it async and return a promise.`,
Expand Down Expand Up @@ -174,7 +174,7 @@ or by passing asyncTokenLookup: true to the from() function, which will make it
for (const tokenList of Object.values(tokenPackage.tokenLists)) {
for (const { identifier, chain, ...rest } of tokenList.tokens) {
staticTokensMap.set(
chain !== "SOL" ? (identifier.toUpperCase() as TokenNames) : identifier,
chain === "SOL" ? identifier : (identifier.toUpperCase() as TokenNames),
{
identifier,
decimal: "decimals" in rest ? rest.decimals : BaseDecimal[chain as Chain],
Expand Down
6 changes: 3 additions & 3 deletions packages/swapkit/helpers/src/types/commonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { ChainWallet, CryptoChain } from "./wallet";
/**
* @optional for swapkit API access
*/
type SwapkitConfig = {
export type SwapkitConfig = {
swapkitConfig?: {
isDev?: boolean;
swapkitApiKey?: string;
Expand All @@ -19,11 +19,11 @@ type SwapkitConfig = {
export type ConnectConfig = SwapkitConfig & {
stagenet?: boolean;
/**
* @required for AVAX & BSC
* @required
*/
thorswapApiKey?: string;
/**
* @required for AVAX & BSC
* @optional for non ETH EVM chains - if not set you must use alchemyApi
*/
covalentApiKey?: string;
/**
Expand Down
12 changes: 9 additions & 3 deletions packages/swapkit/helpers/src/types/sdk.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import type { CovalentApiType, EthplorerApiType } from "@swapkit/toolbox-evm";
import type { BlockchairApiType } from "@swapkit/toolbox-utxo";

import type { AlchemyApiType } from "@swapkit/toolbox-evm/src/api/alchemyApi";
import type { AssetValue } from "../modules/assetValue";
import type { Chain, CosmosChain, UTXOChain } from "./chains";

type CovalentChains =
type NonEthEvmChains =
| Chain.Base
| Chain.BinanceSmartChain
| Chain.Polygon
| Chain.Avalanche
| Chain.Arbitrum
| Chain.Optimism;

export type ChainApis = { [key in CovalentChains]?: CovalentApiType } & {
export type ChainApis = { [key in NonEthEvmChains]?: CovalentApiType | AlchemyApiType } & {
[key in Chain.Ethereum]?: EthplorerApiType;
} & {
[key in UTXOChain]?: BlockchairApiType;
Expand All @@ -22,7 +23,12 @@ export type ChainApis = { [key in CovalentChains]?: CovalentApiType } & {
[key in Chain.Fiat]?: undefined;
};

export type ChainApi = EthplorerApiType | CovalentApiType | BlockchairApiType | string;
export type ChainApi =
| EthplorerApiType
| CovalentApiType
| AlchemyApiType
| BlockchairApiType
| string;

export type GenericSwapParams<T = unknown> = {
buyAsset?: AssetValue;
Expand Down
2 changes: 1 addition & 1 deletion packages/swapkit/helpers/src/types/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export type TokenNames =
| (typeof tokenLists)["CaviarV1List"]["tokens"][number]["identifier"]
| (typeof tokenLists)["ChainflipList"]["tokens"][number]["identifier"]
| (typeof tokenLists)["JupiterList"]["tokens"][number]["identifier"]
// | (typeof tokenLists)["KadoList"]["tokens"][number]["identifier"]
| (typeof tokenLists)["KadoList"]["tokens"][number]["identifier"]
| (typeof tokenLists)["MayaList"]["tokens"][number]["identifier"]
// | (typeof tokenLists)['OciswapV1List']["tokens"][number]["identifier"]
| (typeof tokenLists)["OneInchList"]["tokens"][number]["identifier"]
Expand Down
2 changes: 1 addition & 1 deletion packages/swapkit/tokens/fetchTokenLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function parseIdentifier(identifier: string) {
return identifier;
}

const providers = (await SwapKitApi.getTokenListProvidersV2(true)).filter(
const providers = (await SwapKitApi.getTokenListProvidersV2(false)).filter(
(provider) =>
![
ProviderName.CHAINFLIP_STREAMING,
Expand Down
28 changes: 24 additions & 4 deletions packages/swapkit/tokens/src/tokenLists/camelot_v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export const list = {
provider: "CAMELOT_V3",
chainId: "42161",
name: "Camelot V3",
timestamp: "1737552726554",
count: 1591,
timestamp: "1738954930065",
count: 1593,
tokens: [
{
address: "0xda39A32c9c5Bb2C9E99d4e2a24bc55A418599F90",
Expand Down Expand Up @@ -2075,6 +2075,16 @@ export const list = {
"https://storage.googleapis.com/token-list-swapkit/images/arb.anima-0xccd05a0fcfc1380e9da27862adb2198e58e0d66f.png",
ticker: "ANIMA",
},
{
address: "0x37a645648dF29205C6261289983FB04ECD70b4B3",
chain: "ARB",
chainId: "42161",
decimals: 18,
identifier: "ARB.ANIME-0x37a645648dF29205C6261289983FB04ECD70b4B3",
logoURI:
"https://storage.googleapis.com/token-list-swapkit/images/arb.anime-0x37a645648df29205c6261289983fb04ecd70b4b3.png",
ticker: "ANIME",
},
{
address: "0xBb97CCB699dfC1aF2e05ea68b547505A9D5450C3",
chain: "ARB",
Expand Down Expand Up @@ -11425,6 +11435,16 @@ export const list = {
"https://storage.googleapis.com/token-list-swapkit/images/arb.plsdpx-0xf236ea74b515ef96a9898f5a4ed4aa591f253ce1.png",
ticker: "plsDPX",
},
{
address: "0x9e6B748d25Ed2600Aa0ce7Cbb42267adCF21Fd9B",
chain: "ARB",
chainId: "42161",
decimals: 18,
identifier: "ARB.plsGRAIL-0x9e6B748d25Ed2600Aa0ce7Cbb42267adCF21Fd9B",
logoURI:
"https://storage.googleapis.com/token-list-swapkit/images/arb.plsgrail-0x9e6b748d25ed2600aa0ce7cbb42267adcf21fd9b.png",
ticker: "plsGRAIL",
},
{
address: "0xe7f6C3c1F0018E4C08aCC52965e5cbfF99e34A44",
chain: "ARB",
Expand Down Expand Up @@ -13587,11 +13607,11 @@ export const list = {
ticker: "SUPR",
},
{
address: "0x7788a3538c5fc7f9c7c8a74eac4c898fc8d87d92",
address: "0x7788A3538C5fc7F9c7C8A74EAC4c898fC8d87d92",
chain: "ARB",
chainId: "42161",
decimals: 18,
identifier: "ARB.sUSDX-0x7788a3538c5fc7f9c7c8a74eac4c898fc8d87d92",
identifier: "ARB.sUSDX-0x7788A3538C5fc7F9c7C8A74EAC4c898fC8d87d92",
logoURI:
"https://storage.googleapis.com/token-list-swapkit/images/arb.susdx-0x7788a3538c5fc7f9c7c8a74eac4c898fc8d87d92.png",
ticker: "sUSDX",
Expand Down
2 changes: 1 addition & 1 deletion packages/swapkit/tokens/src/tokenLists/caviar_v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const list = {
provider: "CAVIAR_V1",
chainId: "radix-mainnet",
name: "CAVIAR_V1",
timestamp: "2025-01-22T13:31:45.456Z",
timestamp: "2025-02-07T19:02:44.180Z",
version: {
major: 1,
minor: 0,
Expand Down
2 changes: 1 addition & 1 deletion packages/swapkit/tokens/src/tokenLists/chainflip.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const list = {
provider: "CHAINFLIP",
name: "CHAINFLIP",
timestamp: "2025-01-22T13:30:48.543Z",
timestamp: "2025-02-07T19:01:37.235Z",
version: {
major: 1,
minor: 0,
Expand Down
1 change: 1 addition & 0 deletions packages/swapkit/tokens/src/tokenLists/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { list as CaviarV1List } from "./caviar_v1";
export { list as ChainflipList } from "./chainflip";
export { list as JupiterList } from "./jupiter";
export { list as KadoList } from "./kado";
export { list as MayaList } from "./mayachain";
export { list as OneInchList } from "./oneinch";
export { list as OpenOceanV2List } from "./openocean_v2";
Expand Down
Loading

0 comments on commit 6b9a5d7

Please sign in to comment.