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

Feat/playground improvements #1145

Merged
merged 8 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
44 changes: 44 additions & 0 deletions .changeset/gold-cherries-hide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
"@swapkit/tokens": major
"@swapkit/wallet-evm-extensions": minor
"@swapkit/wallet-keepkey-bex": minor
"@swapkit/wallet-polkadotjs": minor
"@swapkit/toolbox-cosmos": minor
"@swapkit/toolbox-solana": minor
"@swapkit/wallet-coinbase": minor
"@swapkit/wallet-keystore": minor
"@swapkit/wallet-talisman": minor
"@swapkit/helpers": minor
"@swapkit/wallet-keepkey": minor
"@swapkit/wallet-phantom": minor
"@swapkit/wizard": 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-radix": minor
"@swapkit/wallet-ctrl": minor
"@swapkit/api": minor
"@swapkit/wallet-okx": minor
"@swapkit/wallet-wc": minor
---

Breaking Change in @swapkit/tokens:

**What:**

- Moved the tokenlists exports from into a new subobject `tokenLists` within the same module
- added getTokenIcon that returns the Icon url for a given identifier

**How to adept code:**
Use new way of importing the lists

```

import {tokenLists, getTokenIcon} from '@swapkit/tokens'

```

Other packages just got some typing updates - no code changes needed
12 changes: 12 additions & 0 deletions .changeset/good-crabs-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
"@swapkit/wallet-evm-extensions": minor
"@swapkit/wallet-keepkey-bex": minor
"@swapkit/wallet-talisman": minor
"@swapkit/helpers": minor
"@swapkit/wallet-bitget": minor
"@swapkit/wallet-exodus": minor
"@swapkit/wallet-ctrl": minor
"@swapkit/wallet-okx": minor
---

Uses addEVMNetwork only as fallback if the network is not yet known to the wallet
5 changes: 5 additions & 0 deletions .changeset/pink-penguins-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@swapkit/helpers": patch
---

Fixes base rpc url
Binary file modified bun.lockb
Binary file not shown.
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
"devDependencies": {
"@biomejs/biome": "1.8.3",
"@changesets/changelog-github": "0.5.0",
"@changesets/cli": "2.27.7",
"@types/node": "20.14.10",
"@types/react": "18.3.3",
"@types/react-dom": "18.3.0",
"bun-types": "1.1.18",
"lefthook": "1.7.2",
"npm-check-updates": "16.14.20",
"react": "18.2.0",
"typescript": "5.5.4"
"@changesets/cli": "2.27.11",
"@types/node": "22.10.5",
"@types/react": "19.0.3",
"@types/react-dom": "19.0.2",
"bun-types": "1.1.42",
"lefthook": "1.10.1",
"npm-check-updates": "17.1.13",
"react": "19.0.0",
"typescript": "5.7.2"
},
"name": "swapkit-monorepo",
"packageManager": "bun@^1.1.26",
"packageManager": "bun@^1.1.42",
"private": true,
"scripts": {
"bootstrap": "bun clean; bun install --force; bun run build",
Expand Down
2 changes: 1 addition & 1 deletion packages/swapkit/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "swapkit-oss",
"dependencies": {
"@swapkit/helpers": "workspace:*",
"zod": "3.23.8"
"zod": "3.24.1"
},
"description": "SwapKit - API",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion packages/swapkit/helpers/src/helpers/asset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ export async function findAssetBy(
) {
const tokenPackages = await import("@swapkit/tokens");

for (const tokenList of Object.values(tokenPackages)) {
for (const tokenList of Object.values(tokenPackages.tokenLists)) {
for (const { identifier, chain: tokenChain, ...rest } of tokenList.tokens) {
if ("identifier" in params && identifier === params.identifier) {
return identifier as TokenNames;
Expand Down
18 changes: 15 additions & 3 deletions packages/swapkit/helpers/src/helpers/web3wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ declare const window: {
coinbaseWalletExtension: EthereumWindowProvider;
braveSolana: any;
bitkeep?: { ethereum: EthereumWindowProvider };
xfi?: { ethereum: EthereumWindowProvider };
} & Window;

type NetworkParams = {
Expand Down Expand Up @@ -125,12 +126,23 @@ export const prepareNetworkSwitch = <T extends { [key: string]: (...args: any[])
export const addEVMWalletNetwork = (provider: BrowserProvider, networkParams: NetworkParams) =>
providerRequest({ provider, method: "wallet_addEthereumChain", params: [networkParams] });

export const switchEVMWalletNetwork = (provider: BrowserProvider, chainId = ChainId.EthereumHex) =>
providerRequest({ provider, method: "wallet_switchEthereumChain", params: [{ chainId }] });
export const switchEVMWalletNetwork = (
provider: BrowserProvider,
chainId = ChainId.EthereumHex,
networkParams?: NetworkParams,
) => {
try {
providerRequest({ provider, method: "wallet_switchEthereumChain", params: [{ chainId }] });
} catch (_error) {
if (!networkParams) {
throw new Error("Failed to switch network, networkParams not provided");
}
addEVMWalletNetwork(provider, networkParams);
}
};

export const addAccountsChangedCallback = (callback: () => void) => {
window.ethereum?.on("accountsChanged", () => callback());
// @ts-expect-error that should be implemented in ctrl and hooked up via swapkit core
window.xfi?.ethereum.on("accountsChanged", () => callback());
};

Expand Down
1 change: 1 addition & 0 deletions packages/swapkit/helpers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ export * from "./modules/bigIntArithmetics";
export * from "./modules/requestClient";
export * from "./modules/swapKitError";
export * from "./modules/swapKitNumber";
export * from "./modules/walletUtils";
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 @@ -170,8 +170,8 @@ or by passing asyncTokenLookup: true to the from() function, which will make it
return new Promise<{ ok: true } | { ok: false; message: string; error: any }>(
(resolve, reject) => {
try {
import("@swapkit/tokens").then((tokenPackages) => {
for (const tokenList of Object.values(tokenPackages)) {
import("@swapkit/tokens").then((tokenPackage) => {
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,
Expand Down
30 changes: 30 additions & 0 deletions packages/swapkit/helpers/src/modules/walletUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { Chain } from "../types/chains";
import type { WalletOption } from "../types/wallet";
import { SwapKitError } from "./swapKitError";

export function filterSupportedChains<T extends Chain>(
chains: Chain[],
supportedChains: readonly T[],
walletOption: WalletOption,
) {
const supported = chains.filter((chain): chain is T => supportedChains.includes(chain as T));

if (supported.length === 0) {
throw new SwapKitError("wallet_chain_not_supported", {
wallet: walletOption,
chain: chains.join(", "),
});
}

const unsupported = chains.filter((chain) => !supportedChains.includes(chain as T));

if (unsupported.length > 0) {
console.warn(
`${walletOption} wallet does not support the following chains: ${unsupported.join(
", ",
)}. These chains will be ignored.`,
);
}

return supported;
}
2 changes: 1 addition & 1 deletion packages/swapkit/helpers/src/types/chains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export const MAYASupportedChains = [
export const RPC_URLS: Record<Chain | StagenetChain, string> = {
[Chain.Arbitrum]: "https://arb1.arbitrum.io/rpc",
[Chain.Avalanche]: "https://avalanche-c-chain-rpc.publicnode.com",
[Chain.Base]: "https://base.llamarpc.com",
[Chain.Base]: "https://base-rpc.publicnode.com",
[Chain.BinanceSmartChain]: "https://bsc-dataseed.binance.org",
[Chain.Bitcoin]: "https://bitcoin-rpc.publicnode.com",
[Chain.BitcoinCash]: "https://node-router.thorswap.net/bitcoin-cash",
Expand Down
46 changes: 16 additions & 30 deletions packages/swapkit/helpers/src/types/tokens.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
import type {
CaviarV1List,
ChainflipList,
JupiterList,
MayaList,
// OciswapV1List,
OneInchList,
OpenOceanV2List,
PancakeswapList,
PangolinList,
SushiswapList,
ThorchainList,
TraderjoeV2List,
UniswapV2List,
UniswapV3List,
} from "@swapkit/tokens";
import type { tokenLists } from "@swapkit/tokens";

export type TokenTax = { buy: number; sell: number };

export type TokenNames =
| (typeof CaviarV1List)["tokens"][number]["identifier"]
| (typeof ChainflipList)["tokens"][number]["identifier"]
| (typeof JupiterList)["tokens"][number]["identifier"]
| (typeof MayaList)["tokens"][number]["identifier"]
// | (typeof OciswapV1List)["tokens"][number]["identifier"]
| (typeof OneInchList)["tokens"][number]["identifier"]
| (typeof OpenOceanV2List)["tokens"][number]["identifier"]
| (typeof PancakeswapList)["tokens"][number]["identifier"]
| (typeof PangolinList)["tokens"][number]["identifier"]
| (typeof SushiswapList)["tokens"][number]["identifier"]
| (typeof ThorchainList)["tokens"][number]["identifier"]
| (typeof TraderjoeV2List)["tokens"][number]["identifier"]
| (typeof UniswapV2List)["tokens"][number]["identifier"]
| (typeof UniswapV3List)["tokens"][number]["identifier"];
| (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)["MayaList"]["tokens"][number]["identifier"]
// | (typeof tokenLists)['OciswapV1List']["tokens"][number]["identifier"]
| (typeof tokenLists)["OneInchList"]["tokens"][number]["identifier"]
| (typeof tokenLists)["OpenOceanV2List"]["tokens"][number]["identifier"]
| (typeof tokenLists)["PancakeswapList"]["tokens"][number]["identifier"]
| (typeof tokenLists)["PangolinList"]["tokens"][number]["identifier"]
| (typeof tokenLists)["SushiswapList"]["tokens"][number]["identifier"]
| (typeof tokenLists)["ThorchainList"]["tokens"][number]["identifier"]
| (typeof tokenLists)["TraderjoeV2List"]["tokens"][number]["identifier"]
| (typeof tokenLists)["UniswapV2List"]["tokens"][number]["identifier"]
| (typeof tokenLists)["UniswapV3List"]["tokens"][number]["identifier"];
13 changes: 13 additions & 0 deletions packages/swapkit/tokens/src/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { tokenLists } from "./index";

export function getTokenIcon(identifier: string): string | undefined {
// Search through all lists for a matching token
for (const list of Object.values(tokenLists)) {
const token = list.tokens.find((t) => t.identifier === identifier);
if (token?.logoURI) {
return token.logoURI;
}
}

return undefined;
}
64 changes: 50 additions & 14 deletions packages/swapkit/tokens/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,51 @@
export { list as CaviarV1List } from "./tokenLists/caviar_v1";
export { list as ChainflipList } from "./tokenLists/chainflip";
export { list as JupiterList } from "./tokenLists/jupiter";
export { list as KadoList } from "./tokenLists/kado";
export { list as MayaList } from "./tokenLists/mayachain";
import { list as CaviarV1List } from "./tokenLists/caviar_v1";
import { list as ChainflipList } from "./tokenLists/chainflip";
import { list as JupiterList } from "./tokenLists/jupiter";
import { list as KadoList } from "./tokenLists/kado";
import { list as MayaList } from "./tokenLists/mayachain";
// export { list as OciswapV1List } from "./tokenLists/ociswap_v1";
export { list as OneInchList } from "./tokenLists/oneinch";
export { list as OpenOceanV2List } from "./tokenLists/openocean_v2";
export { list as PancakeswapList } from "./tokenLists/pancakeswap";
export { list as PangolinList } from "./tokenLists/pangolin_v1";
export { list as SushiswapList } from "./tokenLists/sushiswap_v2";
export { list as ThorchainList } from "./tokenLists/thorchain";
export { list as TraderjoeV2List } from "./tokenLists/traderjoe_v2";
export { list as UniswapV2List } from "./tokenLists/uniswap_v2";
export { list as UniswapV3List } from "./tokenLists/uniswap_v3";
import { list as OneInchList } from "./tokenLists/oneinch";
import { list as OpenOceanV2List } from "./tokenLists/openocean_v2";
import { list as PancakeswapList } from "./tokenLists/pancakeswap";
import { list as PangolinList } from "./tokenLists/pangolin_v1";
import { list as SushiswapList } from "./tokenLists/sushiswap_v2";
import { list as ThorchainList } from "./tokenLists/thorchain";
import { list as TraderjoeV2List } from "./tokenLists/traderjoe_v2";
import { list as UniswapV2List } from "./tokenLists/uniswap_v2";
import { list as UniswapV3List } from "./tokenLists/uniswap_v3";

export const tokenLists: {
CaviarV1List: typeof CaviarV1List;
ChainflipList: typeof ChainflipList;
JupiterList: typeof JupiterList;
KadoList: typeof KadoList;
MayaList: typeof MayaList;
// OciswapV1List: typeof OciswapV1List
OneInchList: typeof OneInchList;
OpenOceanV2List: typeof OpenOceanV2List;
PancakeswapList: typeof PancakeswapList;
PangolinList: typeof PangolinList;
SushiswapList: typeof SushiswapList;
ThorchainList: typeof ThorchainList;
TraderjoeV2List: typeof TraderjoeV2List;
UniswapV2List: typeof UniswapV2List;
UniswapV3List: typeof UniswapV3List;
} = {
CaviarV1List,
ChainflipList,
JupiterList,
KadoList,
MayaList,
// OciswapV1List,
OneInchList,
OpenOceanV2List,
PancakeswapList,
PangolinList,
SushiswapList,
ThorchainList,
TraderjoeV2List,
UniswapV2List,
UniswapV3List,
};

export * from "./helpers";
2 changes: 1 addition & 1 deletion packages/swapkit/wizard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"@clack/prompts": "0.7.0",
"ejs": "3.1.10",
"picocolors": "1.0.1",
"zod": "3.23.8"
"zod": "3.24.1"
},
"devDependencies": {
"@types/ejs": "3.1.5"
Expand Down
2 changes: 2 additions & 0 deletions packages/toolboxes/cosmos/src/toolbox/thorchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ export const BaseThorchainToolbox = ({
if (!signer) throw new Error("Signer not defined");

const registry = createDefaultRegistry();
const aminoTypes = createDefaultAminoTypes(chain);
const signingClient = await createSigningStargateClient(rpcUrl, signer, {
registry,
aminoTypes,
});

const msgSign = convertToSignable(
Expand Down
2 changes: 1 addition & 1 deletion packages/toolboxes/evm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"author": "swapkit-oss",
"dependencies": {
"@swapkit/helpers": "workspace:*",
"ethers": "6.11.1"
"ethers": "6.13.5"
},
"description": "SwapKit - Toolbox evm",
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions packages/toolboxes/evm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// TODO remove with next major
export {
AbstractSigner,
BrowserProvider,
Expand Down
Loading
Loading