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

chore: async imports #1199

Merged
merged 3 commits into from
Feb 19, 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
192 changes: 175 additions & 17 deletions bun.lock

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion packages/core/src/helpers/walletAddressValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ export async function getAddressValidator() {
const { evmValidateAddress } = await import("@swapkit/toolboxes/evm");
const { substrateValidateAddress } = await import("@swapkit/toolboxes/substrate");
const { utxoValidateAddress } = await import("@swapkit/toolboxes/utxo");
const { validateAddress: solanaValidateAddress } = await import("@swapkit/toolboxes/solana");
const { getAddressValidator: getSolValidator } = await import("@swapkit/toolboxes/solana");
const { validateAddress: validateRadixAddress } = await import("@swapkit/toolboxes/radix");

const solanaValidateAddress = await getSolValidator();

return function validateAddress({ address, chain }: { address: string; chain: Chain }) {
switch (chain) {
case Chain.Arbitrum:
Expand Down
56 changes: 19 additions & 37 deletions packages/helpers/src/modules/assetValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,44 +167,26 @@ or by passing asyncTokenLookup: true to the from() function, which will make it
return assetValue as ConditionalAssetValueReturn<T>;
}

static loadStaticAssets() {
return new Promise<{ ok: true } | { ok: false; message: string; error: any }>(
(resolve, reject) => {
try {
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: refactor
import("@swapkit/helpers/tokens").then((tokenPackage) => {
if (!tokenPackage.tokenLists) {
console.warn(
"No token lists found in @swapkit/tokens package. Ensure you have installed it correctly.",
);
return;
}

for (const tokenList of Object.values(tokenPackage.tokenLists)) {
for (const { identifier, chain, ...rest } of tokenList.tokens) {
staticTokensMap.set(
chain === "SOL" ? identifier : (identifier.toUpperCase() as TokenNames),
{
identifier,
decimal: "decimals" in rest ? rest.decimals : BaseDecimal[chain as Chain],
},
);
}
}

resolve({ ok: true });
});
} catch (error) {
console.error(error);
reject({
ok: false,
error,
message:
"Couldn't load static assets. Ensure you have installed @swapkit/tokens package",
});
static async loadStaticAssets() {
try {
await import("@swapkit/helpers/tokens").then(({ tokenLists }) => {
for (const { tokens } of Object.values(tokenLists)) {
for (const { identifier, chain, ...rest } of tokens) {
staticTokensMap.set(
chain === "SOL" ? identifier : (identifier.toUpperCase() as TokenNames),
{
identifier,
decimal: "decimals" in rest ? rest.decimals : BaseDecimal[chain as Chain],
},
);
}
}
},
);
});
return true;
} catch (error) {
console.error(error);
return false;
}
}
}

Expand Down
13 changes: 0 additions & 13 deletions packages/helpers/src/tokens/helpers.ts

This file was deleted.

17 changes: 15 additions & 2 deletions packages/helpers/src/tokens/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
export * as tokenLists from "./lists";
export * from "./helpers";
import * as tokenLists from "./lists";

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((token) => token.identifier === identifier);
if (token?.logoURI) {
return token.logoURI;
}
}

return undefined;
}

export { tokenLists };
20 changes: 0 additions & 20 deletions packages/plugins/src/chainflip/broker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Assets, Chains } from "@chainflip/sdk/swap";
import { decodeAddress } from "@polkadot/keyring";
import { isHex, u8aToHex } from "@polkadot/util";
import { AssetValue, Chain, SwapKitError, wrapWithThrow } from "@swapkit/helpers";
Expand All @@ -8,25 +7,6 @@ import type { ChainflipToolbox } from "@swapkit/toolboxes/substrate";

import type { WithdrawFeeResponse } from "./types";

export const chainToChainflipChain = new Map<Chain, keyof typeof Chains>([
[Chain.Arbitrum, Chains.Arbitrum],
[Chain.Bitcoin, Chains.Bitcoin],
[Chain.Ethereum, Chains.Ethereum],
[Chain.Polkadot, Chains.Polkadot],
[Chain.Solana, Chains.Solana],
[Chain.Polkadot, Chains.Polkadot],
]);

export const assetTickerToChainflipAsset = new Map<string, keyof typeof Assets>([
["FLIP", Assets.FLIP],
["BTC", Assets.BTC],
["ETH", Assets.ETH],
["USDC", Assets.USDC],
["USDT", Assets.USDT],
["DOT", Assets.DOT],
["SOL", Assets.SOL],
]);

export const assetIdentifierToChainflipTicker = new Map<string, string>([
["ARB.ETH", "ArbEth"],
["ARB.USDC-0XAF88D065E77C8CC2239327C5EDB3A432268E5831", "ArbUsdc"],
Expand Down
1 change: 0 additions & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"author": "swapkit-oss",
"dependencies": {
"@swapkit/core": "workspace:*",
"@swapkit/helpers": "workspace:*",
"@swapkit/plugins": "workspace:*",
"@swapkit/wallets": "workspace:*"
},
Expand Down
203 changes: 100 additions & 103 deletions packages/toolboxes/package.json
Original file line number Diff line number Diff line change
@@ -1,105 +1,102 @@
{
"description": "SwapKit - Toolboxes",
"files": [
"src/",
"dist/"
],
"dependencies": {
"@bitcoinerlab/secp256k1": "1.2.0",
"@cosmjs/amino": "0.33.0",
"@cosmjs/crypto": "0.33.0",
"@cosmjs/encoding": "0.33.0",
"@cosmjs/proto-signing": "0.33.0",
"@cosmjs/stargate": "0.33.0",
"@polkadot/api": "15.6.1",
"@polkadot/api-base": "15.6.1",
"@polkadot/keyring": "13.4.3",
"@polkadot/util": "13.4.3",
"@polkadot/util-crypto": "13.4.3",
"@psf/bitcoincashjs-lib": "4.0.3",
"@radixdlt/babylon-gateway-api-sdk": "1.9.2",
"@radixdlt/radix-dapp-toolkit": "2.2.1",
"@radixdlt/wallet-sdk": "1.0.1",
"@scure/base": "1.2.4",
"@scure/bip32": "1.6.2",
"@scure/bip39": "1.5.4",
"@solana/spl-memo": "0.2.5",
"@solana/spl-token": "0.4.12",
"@solana/spl-token-registry": "0.2.4574",
"@solana/web3.js": "1.98.0",
"@swapkit/helpers": "workspace:*",
"base64-js": "1.5.1",
"bitcoinjs-lib": "6.1.7",
"bs58check": "4.0.0",
"cashaddrjs": "0.4.4",
"coininfo": "5.2.1",
"cosmjs-types": "0.9.0",
"ecpair": "2.1.0",
"ethers": "6.13.5",
"micro-key-producer": "0.7.5",
"protobufjs": "7.4.0"
},
"devDependencies": {
"@nomicfoundation/hardhat-ethers": "3.0.8",
"@nomicfoundation/hardhat-toolbox": "5.0.0",
"@polkadot/types": "15.6.1",
"@types/bn.js": "5.1.6",
"@types/crypto-js": "4.2.2",
"@types/elliptic": "6.4.18",
"hardhat": "2.22.18"
},
"exports": {
".": {
"default": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./src/index.ts"
},
"./cosmos": {
"default": "./dist/cosmos/index.js",
"require": "./dist/cosmos/index.cjs",
"types": "./src/cosmos/index.ts"
},
"./evm": {
"default": "./dist/evm/index.js",
"require": "./dist/evm/index.cjs",
"types": "./src/evm/index.ts"
},
"./radix": {
"default": "./dist/radix/index.js",
"require": "./dist/radix/index.cjs",
"types": "./src/radix/index.ts"
},
"./solana": {
"default": "./dist/solana/index.js",
"require": "./dist/solana/index.cjs",
"types": "./src/solana/index.ts"
},
"./substrate": {
"default": "./dist/substrate/index.js",
"require": "./dist/substrate/index.cjs",
"types": "./src/substrate/index.ts"
},
"./utxo": {
"default": "./dist/utxo/index.js",
"require": "./dist/utxo/index.cjs",
"types": "./src/utxo/index.ts"
}
},
"homepage": "https://github.com/thorswap/SwapKit",
"license": "Apache-2.0",
"name": "@swapkit/toolboxes",
"repository": {
"type": "git",
"url": "git+https://github.com/thorswap/SwapKit.git"
},
"scripts": {
"build": "bun run ./build.ts",
"clean": "rm -rf dist node_modules *.tsbuildinfo",
"lint": "biome check --write ./src",
"test": "echo 'bun test'",
"test:coverage": "bun test --coverage",
"type-check": "tsc --noEmit"
},
"type": "module",
"version": "0.1.0"
"description": "SwapKit - Toolboxes",
"files": ["src/", "dist/"],
"dependencies": {
"@bitcoinerlab/secp256k1": "1.2.0",
"@cosmjs/amino": "0.33.0",
"@cosmjs/crypto": "0.33.0",
"@cosmjs/encoding": "0.33.0",
"@cosmjs/proto-signing": "0.33.0",
"@cosmjs/stargate": "0.33.0",
"@polkadot/api": "15.6.1",
"@polkadot/api-base": "15.6.1",
"@polkadot/keyring": "13.4.3",
"@polkadot/util": "13.4.3",
"@polkadot/util-crypto": "13.4.3",
"@psf/bitcoincashjs-lib": "4.0.3",
"@radixdlt/babylon-gateway-api-sdk": "1.9.2",
"@radixdlt/radix-dapp-toolkit": "2.2.1",
"@radixdlt/wallet-sdk": "1.0.1",
"@scure/base": "1.2.4",
"@scure/bip32": "1.6.2",
"@scure/bip39": "1.5.4",
"@solana/spl-memo": "0.2.5",
"@solana/spl-token": "0.4.12",
"@solana/spl-token-registry": "0.2.4574",
"@solana/web3.js": "1.98.0",
"@swapkit/helpers": "workspace:*",
"base64-js": "1.5.1",
"bitcoinjs-lib": "6.1.7",
"bs58check": "4.0.0",
"cashaddrjs": "0.4.4",
"coininfo": "5.2.1",
"cosmjs-types": "0.9.0",
"ecpair": "2.1.0",
"ethers": "6.13.5",
"micro-key-producer": "0.7.5",
"protobufjs": "7.4.0"
},
"devDependencies": {
"@nomicfoundation/hardhat-ethers": "3.0.8",
"@nomicfoundation/hardhat-toolbox": "5.0.0",
"@polkadot/types": "15.6.1",
"@types/bn.js": "5.1.6",
"@types/crypto-js": "4.2.2",
"@types/elliptic": "6.4.18",
"hardhat": "2.22.18"
},
"exports": {
".": {
"default": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./src/index.ts"
},
"./cosmos": {
"default": "./dist/cosmos/index.js",
"require": "./dist/cosmos/index.cjs",
"types": "./src/cosmos/index.ts"
},
"./evm": {
"default": "./dist/evm/index.js",
"require": "./dist/evm/index.cjs",
"types": "./src/evm/index.ts"
},
"./radix": {
"default": "./dist/radix/index.js",
"require": "./dist/radix/index.cjs",
"types": "./src/radix/index.ts"
},
"./solana": {
"default": "./dist/solana/index.js",
"require": "./dist/solana/index.cjs",
"types": "./src/solana/index.ts"
},
"./substrate": {
"default": "./dist/substrate/index.js",
"require": "./dist/substrate/index.cjs",
"types": "./src/substrate/index.ts"
},
"./utxo": {
"default": "./dist/utxo/index.js",
"require": "./dist/utxo/index.cjs",
"types": "./src/utxo/index.ts"
}
},
"homepage": "https://github.com/thorswap/SwapKit",
"license": "Apache-2.0",
"name": "@swapkit/toolboxes",
"repository": {
"type": "git",
"url": "git+https://github.com/thorswap/SwapKit.git"
},
"scripts": {
"build": "bun run ./build.ts",
"clean": "rm -rf dist node_modules *.tsbuildinfo",
"lint": "biome check --write ./src",
"test": "echo 'bun test'",
"test:coverage": "bun test --coverage",
"type-check": "tsc --noEmit"
},
"type": "module",
"version": "0.1.0"
}
Loading