@swapkit/core 1.0.0-rc.122 → 1.0.0-rc.124
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -2
- package/dist/index.js.map +3 -3
- package/package.json +9 -9
- package/src/client.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -117,7 +117,7 @@ function SwapKit({
|
|
|
117
117
|
return getWallet(chain)?.balance || [];
|
|
118
118
|
}
|
|
119
119
|
function validateAddress({ address, chain }) {
|
|
120
|
-
getWallet(chain)?.validateAddress?.(address);
|
|
120
|
+
return getWallet(chain)?.validateAddress?.(address);
|
|
121
121
|
}
|
|
122
122
|
async function getWalletWithBalance(chain, potentialScamFilter = true) {
|
|
123
123
|
const defaultBalance = [AssetValue.fromChainOrSignature(chain)];
|
|
@@ -160,4 +160,4 @@ export {
|
|
|
160
160
|
SwapKit
|
|
161
161
|
};
|
|
162
162
|
|
|
163
|
-
//# debugId=
|
|
163
|
+
//# debugId=481EAEF7C9A043A064756e2164756e21
|
package/dist/index.js.map
CHANGED
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
"sources": ["../src/index.ts", "../src/client.ts", "../src/helpers/explorerUrls.ts", "../src/client.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"export * from \"@swapkit/api\";\nexport * from \"@swapkit/helpers\";\n\nexport { SwapKit } from \"./client.ts\";\nexport * from \"./client.ts\";\nexport * from \"./types.ts\";\n",
|
|
6
|
-
"import {\n ApproveMode,\n type ApproveReturnType,\n AssetValue,\n type AvailableProviders,\n type BaseWallet,\n Chain,\n type ChainWallet,\n type PluginName,\n SwapKitError,\n type SwapKitPlugin,\n type SwapKitPlugins,\n type SwapParams,\n} from \"@swapkit/helpers\";\nimport type { CosmosWallets, ThorchainWallets } from \"@swapkit/toolbox-cosmos\";\nimport type { BaseEVMWallet, EVMWallets } from \"@swapkit/toolbox-evm\";\nimport type { SubstrateWallets } from \"@swapkit/toolbox-substrate\";\nimport type { UTXOWallets } from \"@swapkit/toolbox-utxo\";\nimport {\n getExplorerAddressUrl as getAddressUrl,\n getExplorerTxUrl as getTxUrl,\n} from \"./helpers/explorerUrls.ts\";\nimport type { ConnectWalletParamsLocal as ConnectWalletParams } from \"./types.ts\";\n\nexport type SwapKitReturnType = SwapKitPlugins & {\n getAddress: (chain: Chain) => string;\n getWallet: (chain: Chain) => ChainWallet | undefined;\n getWalletWithBalance: (chain: Chain, potentialScamFilter?: boolean) => Promise<ChainWallet>;\n getBalance: (chain: Chain, refresh?: boolean) => Promise<AssetValue[]>;\n getExplorerTxUrl: typeof getTxUrl;\n getExplorerAddressUrl: typeof getAddressUrl;\n swap: (params: SwapParams) => Promise<string>;\n validateAddress: (params: { address: string; chain: Chain }) =>\n | boolean\n | Promise<boolean>\n | undefined;\n approveAssetValue: (assetValue: AssetValue, contractAddress: string) => boolean | Promise<string>;\n isAssetValueApproved: (\n assetValue: AssetValue,\n contractAddress: string,\n ) => boolean | Promise<boolean>;\n};\n\nexport type Wallet = BaseWallet<\n EVMWallets & CosmosWallets & ThorchainWallets & UTXOWallets & SubstrateWallets\n>;\n\nexport type SwapKitWallet = {\n connectMethodName: string;\n connect: (params: ConnectWalletParams) => (connectParams: Todo) => undefined | string;\n};\n\nexport function SwapKit<\n ExtendedProviders extends {},\n ConnectWalletMethods = Record<string, ReturnType<SwapKitWallet[\"connect\"]>>,\n>({\n stagenet,\n wallets,\n plugins,\n config = {},\n apis = {},\n rpcUrls = {},\n}: {\n plugins: SwapKitPlugin[];\n stagenet: boolean;\n wallets: SwapKitWallet[];\n config?: Record<string, Todo>;\n apis: Record<string, Todo>;\n rpcUrls: Record<string, Todo>;\n}) {\n const connectedWallets = {} as Wallet;\n const availablePlugins: AvailableProviders<ExtendedProviders> = {};\n\n for (const plugin of plugins) {\n const { name, methods } = plugin({ wallets: connectedWallets, stagenet });\n\n availablePlugins[name] = methods;\n }\n\n const connectWalletMethods = wallets.reduce((acc, wallet) => {\n // @ts-expect-error TODO\n acc[wallet.connectMethodName] = wallet.connect({\n // @ts-expect-error TODO\n addChain,\n config,\n apis,\n rpcUrls,\n });\n\n return acc;\n }, {} as ConnectWalletMethods);\n\n /**\n * @Private\n * Internal helpers\n */\n function getSwapKitPlugin(pluginName?: PluginName) {\n const plugin =\n (availablePlugins as SwapKitPlugins)[pluginName as PluginName] ||\n Object.values(availablePlugins)[0];\n\n if (!plugin) {\n throw new SwapKitError(\"core_plugin_not_found\", \"Could not find the requested plugin\");\n }\n\n return plugin;\n }\n\n function addChain(connectWallet: Wallet[Chain]) {\n // @ts-expect-error TODO\n connectedWallets[connectWallet.chain] = connectWallet;\n }\n\n /**\n * @Private\n * Wallet interaction helpers\n */\n function approve<T extends ApproveMode>({\n assetValue,\n type = \"checkOnly\" as T,\n contractAddress: spenderAddress,\n }: {\n type: T;\n assetValue: AssetValue;\n contractAddress: string;\n }): ApproveReturnType<T> {\n const { address, chain, isGasAsset, isSynthetic } = assetValue;\n const isEVMChain = [Chain.Ethereum, Chain.Avalanche, Chain.BinanceSmartChain].includes(chain);\n const isNativeEVM = isEVMChain && isGasAsset;\n\n if (isNativeEVM || !isEVMChain || isSynthetic) {\n return Promise.resolve(type === \"checkOnly\" ? true : \"approved\") as ApproveReturnType<T>;\n }\n\n const walletMethods = connectedWallets[chain] as BaseEVMWallet;\n const walletAction = type === \"checkOnly\" ? walletMethods?.isApproved : walletMethods?.approve;\n if (!walletAction) throw new SwapKitError(\"core_wallet_connection_not_found\");\n\n const from = getAddress(chain);\n if (!(address && from)) {\n throw new SwapKitError(\"core_approve_asset_address_or_from_not_found\");\n }\n\n return walletAction({\n amount: assetValue.getBaseValue(\"bigint\"),\n assetAddress: address,\n from,\n spenderAddress,\n }) as ApproveReturnType<T>;\n }\n\n /**\n * @Public\n * Wallet helpers\n */\n function getWallet(chain:
|
|
6
|
+
"import {\n ApproveMode,\n type ApproveReturnType,\n AssetValue,\n type AvailableProviders,\n type BaseWallet,\n Chain,\n type ChainWallet,\n type PluginName,\n SwapKitError,\n type SwapKitPlugin,\n type SwapKitPlugins,\n type SwapParams,\n} from \"@swapkit/helpers\";\nimport type { CosmosWallets, ThorchainWallets } from \"@swapkit/toolbox-cosmos\";\nimport type { BaseEVMWallet, EVMWallets } from \"@swapkit/toolbox-evm\";\nimport type { SubstrateWallets } from \"@swapkit/toolbox-substrate\";\nimport type { UTXOWallets } from \"@swapkit/toolbox-utxo\";\nimport {\n getExplorerAddressUrl as getAddressUrl,\n getExplorerTxUrl as getTxUrl,\n} from \"./helpers/explorerUrls.ts\";\nimport type { ConnectWalletParamsLocal as ConnectWalletParams } from \"./types.ts\";\n\nexport type SwapKitReturnType = SwapKitPlugins & {\n getAddress: (chain: Chain) => string;\n getWallet: (chain: Chain) => ChainWallet | undefined;\n getWalletWithBalance: (chain: Chain, potentialScamFilter?: boolean) => Promise<ChainWallet>;\n getBalance: (chain: Chain, refresh?: boolean) => Promise<AssetValue[]>;\n getExplorerTxUrl: typeof getTxUrl;\n getExplorerAddressUrl: typeof getAddressUrl;\n swap: (params: SwapParams) => Promise<string>;\n validateAddress: (params: { address: string; chain: Chain }) =>\n | boolean\n | Promise<boolean>\n | undefined;\n approveAssetValue: (assetValue: AssetValue, contractAddress: string) => boolean | Promise<string>;\n isAssetValueApproved: (\n assetValue: AssetValue,\n contractAddress: string,\n ) => boolean | Promise<boolean>;\n};\n\nexport type Wallet = BaseWallet<\n EVMWallets & CosmosWallets & ThorchainWallets & UTXOWallets & SubstrateWallets\n>;\n\nexport type SwapKitWallet = {\n connectMethodName: string;\n connect: (params: ConnectWalletParams) => (connectParams: Todo) => undefined | string;\n};\n\nexport function SwapKit<\n ExtendedProviders extends {},\n ConnectWalletMethods = Record<string, ReturnType<SwapKitWallet[\"connect\"]>>,\n>({\n stagenet,\n wallets,\n plugins,\n config = {},\n apis = {},\n rpcUrls = {},\n}: {\n plugins: SwapKitPlugin[];\n stagenet: boolean;\n wallets: SwapKitWallet[];\n config?: Record<string, Todo>;\n apis: Record<string, Todo>;\n rpcUrls: Record<string, Todo>;\n}) {\n const connectedWallets = {} as Wallet;\n const availablePlugins: AvailableProviders<ExtendedProviders> = {};\n\n for (const plugin of plugins) {\n const { name, methods } = plugin({ wallets: connectedWallets, stagenet });\n\n availablePlugins[name] = methods;\n }\n\n const connectWalletMethods = wallets.reduce((acc, wallet) => {\n // @ts-expect-error TODO\n acc[wallet.connectMethodName] = wallet.connect({\n // @ts-expect-error TODO\n addChain,\n config,\n apis,\n rpcUrls,\n });\n\n return acc;\n }, {} as ConnectWalletMethods);\n\n /**\n * @Private\n * Internal helpers\n */\n function getSwapKitPlugin(pluginName?: PluginName) {\n const plugin =\n (availablePlugins as SwapKitPlugins)[pluginName as PluginName] ||\n Object.values(availablePlugins)[0];\n\n if (!plugin) {\n throw new SwapKitError(\"core_plugin_not_found\", \"Could not find the requested plugin\");\n }\n\n return plugin;\n }\n\n function addChain(connectWallet: Wallet[Chain]) {\n // @ts-expect-error TODO\n connectedWallets[connectWallet.chain] = connectWallet;\n }\n\n /**\n * @Private\n * Wallet interaction helpers\n */\n function approve<T extends ApproveMode>({\n assetValue,\n type = \"checkOnly\" as T,\n contractAddress: spenderAddress,\n }: {\n type: T;\n assetValue: AssetValue;\n contractAddress: string;\n }): ApproveReturnType<T> {\n const { address, chain, isGasAsset, isSynthetic } = assetValue;\n const isEVMChain = [Chain.Ethereum, Chain.Avalanche, Chain.BinanceSmartChain].includes(chain);\n const isNativeEVM = isEVMChain && isGasAsset;\n\n if (isNativeEVM || !isEVMChain || isSynthetic) {\n return Promise.resolve(type === \"checkOnly\" ? true : \"approved\") as ApproveReturnType<T>;\n }\n\n const walletMethods = connectedWallets[chain] as BaseEVMWallet;\n const walletAction = type === \"checkOnly\" ? walletMethods?.isApproved : walletMethods?.approve;\n if (!walletAction) throw new SwapKitError(\"core_wallet_connection_not_found\");\n\n const from = getAddress(chain);\n if (!(address && from)) {\n throw new SwapKitError(\"core_approve_asset_address_or_from_not_found\");\n }\n\n return walletAction({\n amount: assetValue.getBaseValue(\"bigint\"),\n assetAddress: address,\n from,\n spenderAddress,\n }) as ApproveReturnType<T>;\n }\n\n /**\n * @Public\n * Wallet helpers\n */\n function getWallet<T extends Chain>(chain: T) {\n return connectedWallets[chain];\n }\n function getAddress(chain: Chain) {\n return getWallet(chain)?.address || \"\";\n }\n async function getBalance(chain: Chain, refresh?: boolean) {\n if (refresh) {\n const wallet = await getWalletWithBalance(chain, true);\n return wallet.balance || [];\n }\n\n return getWallet(chain)?.balance || [];\n }\n /**\n * TODO: Figure out validation without connecting to wallet\n */\n function validateAddress({ address, chain }: { address: string; chain: Chain }) {\n return getWallet(chain)?.validateAddress?.(address);\n }\n\n async function getWalletWithBalance(chain: Chain, potentialScamFilter = true) {\n const defaultBalance = [AssetValue.fromChainOrSignature(chain)];\n const wallet = getWallet(chain);\n\n if (!wallet) {\n throw new SwapKitError(\"core_wallet_connection_not_found\");\n }\n\n if (\"getBalance\" in wallet) {\n const balance = await wallet.getBalance(wallet.address, potentialScamFilter);\n wallet.balance = balance?.length ? balance : defaultBalance;\n }\n\n return wallet;\n }\n\n /**\n * @Public\n * Wallet interaction methods\n */\n function approveAssetValue(assetValue: AssetValue, contractAddress: string) {\n return approve({ assetValue, contractAddress, type: ApproveMode.Approve });\n }\n\n function isAssetValueApproved(assetValue: AssetValue, contractAddress: string) {\n return approve({ assetValue, contractAddress, type: ApproveMode.CheckOnly });\n }\n\n function swap({ provider, ...rest }: SwapParams) {\n const plugin = getSwapKitPlugin(provider?.name);\n\n return plugin.swap({ provider, ...rest });\n }\n\n return {\n ...availablePlugins,\n ...connectWalletMethods,\n\n getExplorerAddressUrl: getAddressUrl,\n getExplorerTxUrl: getTxUrl,\n\n approveAssetValue,\n getAddress,\n getBalance,\n getWallet,\n getWalletWithBalance,\n isAssetValueApproved,\n swap,\n validateAddress,\n };\n}\n\nexport type SwapKitClient<T extends {}, K> = ReturnType<typeof SwapKit<T, K>>;\n",
|
|
7
7
|
"import { Chain, ChainToExplorerUrl } from \"@swapkit/helpers\";\n\nexport function getExplorerTxUrl({ chain, txHash }: { txHash: string; chain: Chain }) {\n const baseUrl = ChainToExplorerUrl[chain];\n\n switch (chain) {\n case Chain.Binance:\n case Chain.Maya:\n case Chain.Kujira:\n case Chain.Cosmos:\n case Chain.THORChain:\n return `${baseUrl}/tx/${txHash.startsWith(\"0x\") ? txHash.slice(2) : txHash}`;\n\n case Chain.Arbitrum:\n case Chain.Avalanche:\n case Chain.BinanceSmartChain:\n case Chain.Ethereum:\n case Chain.Optimism:\n case Chain.Polkadot:\n case Chain.Polygon:\n return `${baseUrl}/tx/${txHash.startsWith(\"0x\") ? txHash : `0x${txHash}`}`;\n\n case Chain.Litecoin:\n case Chain.Bitcoin:\n case Chain.BitcoinCash:\n case Chain.Dogecoin:\n return `${baseUrl}/transaction/${txHash.toLowerCase()}`;\n\n default:\n throw new Error(`Unsupported chain: ${chain}`);\n }\n}\n\nexport function getExplorerAddressUrl({ chain, address }: { address: string; chain: Chain }) {\n const baseUrl = ChainToExplorerUrl[chain];\n\n return `${baseUrl}/address/${address}`;\n}\n",
|
|
8
|
-
"import {\n ApproveMode,\n type ApproveReturnType,\n AssetValue,\n type AvailableProviders,\n type BaseWallet,\n Chain,\n type ChainWallet,\n type PluginName,\n SwapKitError,\n type SwapKitPlugin,\n type SwapKitPlugins,\n type SwapParams,\n} from \"@swapkit/helpers\";\nimport type { CosmosWallets, ThorchainWallets } from \"@swapkit/toolbox-cosmos\";\nimport type { BaseEVMWallet, EVMWallets } from \"@swapkit/toolbox-evm\";\nimport type { SubstrateWallets } from \"@swapkit/toolbox-substrate\";\nimport type { UTXOWallets } from \"@swapkit/toolbox-utxo\";\nimport {\n getExplorerAddressUrl as getAddressUrl,\n getExplorerTxUrl as getTxUrl,\n} from \"./helpers/explorerUrls.ts\";\nimport type { ConnectWalletParamsLocal as ConnectWalletParams } from \"./types.ts\";\n\nexport type SwapKitReturnType = SwapKitPlugins & {\n getAddress: (chain: Chain) => string;\n getWallet: (chain: Chain) => ChainWallet | undefined;\n getWalletWithBalance: (chain: Chain, potentialScamFilter?: boolean) => Promise<ChainWallet>;\n getBalance: (chain: Chain, refresh?: boolean) => Promise<AssetValue[]>;\n getExplorerTxUrl: typeof getTxUrl;\n getExplorerAddressUrl: typeof getAddressUrl;\n swap: (params: SwapParams) => Promise<string>;\n validateAddress: (params: { address: string; chain: Chain }) =>\n | boolean\n | Promise<boolean>\n | undefined;\n approveAssetValue: (assetValue: AssetValue, contractAddress: string) => boolean | Promise<string>;\n isAssetValueApproved: (\n assetValue: AssetValue,\n contractAddress: string,\n ) => boolean | Promise<boolean>;\n};\n\nexport type Wallet = BaseWallet<\n EVMWallets & CosmosWallets & ThorchainWallets & UTXOWallets & SubstrateWallets\n>;\n\nexport type SwapKitWallet = {\n connectMethodName: string;\n connect: (params: ConnectWalletParams) => (connectParams: Todo) => undefined | string;\n};\n\nexport function SwapKit<\n ExtendedProviders extends {},\n ConnectWalletMethods = Record<string, ReturnType<SwapKitWallet[\"connect\"]>>,\n>({\n stagenet,\n wallets,\n plugins,\n config = {},\n apis = {},\n rpcUrls = {},\n}: {\n plugins: SwapKitPlugin[];\n stagenet: boolean;\n wallets: SwapKitWallet[];\n config?: Record<string, Todo>;\n apis: Record<string, Todo>;\n rpcUrls: Record<string, Todo>;\n}) {\n const connectedWallets = {} as Wallet;\n const availablePlugins: AvailableProviders<ExtendedProviders> = {};\n\n for (const plugin of plugins) {\n const { name, methods } = plugin({ wallets: connectedWallets, stagenet });\n\n availablePlugins[name] = methods;\n }\n\n const connectWalletMethods = wallets.reduce((acc, wallet) => {\n // @ts-expect-error TODO\n acc[wallet.connectMethodName] = wallet.connect({\n // @ts-expect-error TODO\n addChain,\n config,\n apis,\n rpcUrls,\n });\n\n return acc;\n }, {} as ConnectWalletMethods);\n\n /**\n * @Private\n * Internal helpers\n */\n function getSwapKitPlugin(pluginName?: PluginName) {\n const plugin =\n (availablePlugins as SwapKitPlugins)[pluginName as PluginName] ||\n Object.values(availablePlugins)[0];\n\n if (!plugin) {\n throw new SwapKitError(\"core_plugin_not_found\", \"Could not find the requested plugin\");\n }\n\n return plugin;\n }\n\n function addChain(connectWallet: Wallet[Chain]) {\n // @ts-expect-error TODO\n connectedWallets[connectWallet.chain] = connectWallet;\n }\n\n /**\n * @Private\n * Wallet interaction helpers\n */\n function approve<T extends ApproveMode>({\n assetValue,\n type = \"checkOnly\" as T,\n contractAddress: spenderAddress,\n }: {\n type: T;\n assetValue: AssetValue;\n contractAddress: string;\n }): ApproveReturnType<T> {\n const { address, chain, isGasAsset, isSynthetic } = assetValue;\n const isEVMChain = [Chain.Ethereum, Chain.Avalanche, Chain.BinanceSmartChain].includes(chain);\n const isNativeEVM = isEVMChain && isGasAsset;\n\n if (isNativeEVM || !isEVMChain || isSynthetic) {\n return Promise.resolve(type === \"checkOnly\" ? true : \"approved\") as ApproveReturnType<T>;\n }\n\n const walletMethods = connectedWallets[chain] as BaseEVMWallet;\n const walletAction = type === \"checkOnly\" ? walletMethods?.isApproved : walletMethods?.approve;\n if (!walletAction) throw new SwapKitError(\"core_wallet_connection_not_found\");\n\n const from = getAddress(chain);\n if (!(address && from)) {\n throw new SwapKitError(\"core_approve_asset_address_or_from_not_found\");\n }\n\n return walletAction({\n amount: assetValue.getBaseValue(\"bigint\"),\n assetAddress: address,\n from,\n spenderAddress,\n }) as ApproveReturnType<T>;\n }\n\n /**\n * @Public\n * Wallet helpers\n */\n function getWallet(chain:
|
|
8
|
+
"import {\n ApproveMode,\n type ApproveReturnType,\n AssetValue,\n type AvailableProviders,\n type BaseWallet,\n Chain,\n type ChainWallet,\n type PluginName,\n SwapKitError,\n type SwapKitPlugin,\n type SwapKitPlugins,\n type SwapParams,\n} from \"@swapkit/helpers\";\nimport type { CosmosWallets, ThorchainWallets } from \"@swapkit/toolbox-cosmos\";\nimport type { BaseEVMWallet, EVMWallets } from \"@swapkit/toolbox-evm\";\nimport type { SubstrateWallets } from \"@swapkit/toolbox-substrate\";\nimport type { UTXOWallets } from \"@swapkit/toolbox-utxo\";\nimport {\n getExplorerAddressUrl as getAddressUrl,\n getExplorerTxUrl as getTxUrl,\n} from \"./helpers/explorerUrls.ts\";\nimport type { ConnectWalletParamsLocal as ConnectWalletParams } from \"./types.ts\";\n\nexport type SwapKitReturnType = SwapKitPlugins & {\n getAddress: (chain: Chain) => string;\n getWallet: (chain: Chain) => ChainWallet | undefined;\n getWalletWithBalance: (chain: Chain, potentialScamFilter?: boolean) => Promise<ChainWallet>;\n getBalance: (chain: Chain, refresh?: boolean) => Promise<AssetValue[]>;\n getExplorerTxUrl: typeof getTxUrl;\n getExplorerAddressUrl: typeof getAddressUrl;\n swap: (params: SwapParams) => Promise<string>;\n validateAddress: (params: { address: string; chain: Chain }) =>\n | boolean\n | Promise<boolean>\n | undefined;\n approveAssetValue: (assetValue: AssetValue, contractAddress: string) => boolean | Promise<string>;\n isAssetValueApproved: (\n assetValue: AssetValue,\n contractAddress: string,\n ) => boolean | Promise<boolean>;\n};\n\nexport type Wallet = BaseWallet<\n EVMWallets & CosmosWallets & ThorchainWallets & UTXOWallets & SubstrateWallets\n>;\n\nexport type SwapKitWallet = {\n connectMethodName: string;\n connect: (params: ConnectWalletParams) => (connectParams: Todo) => undefined | string;\n};\n\nexport function SwapKit<\n ExtendedProviders extends {},\n ConnectWalletMethods = Record<string, ReturnType<SwapKitWallet[\"connect\"]>>,\n>({\n stagenet,\n wallets,\n plugins,\n config = {},\n apis = {},\n rpcUrls = {},\n}: {\n plugins: SwapKitPlugin[];\n stagenet: boolean;\n wallets: SwapKitWallet[];\n config?: Record<string, Todo>;\n apis: Record<string, Todo>;\n rpcUrls: Record<string, Todo>;\n}) {\n const connectedWallets = {} as Wallet;\n const availablePlugins: AvailableProviders<ExtendedProviders> = {};\n\n for (const plugin of plugins) {\n const { name, methods } = plugin({ wallets: connectedWallets, stagenet });\n\n availablePlugins[name] = methods;\n }\n\n const connectWalletMethods = wallets.reduce((acc, wallet) => {\n // @ts-expect-error TODO\n acc[wallet.connectMethodName] = wallet.connect({\n // @ts-expect-error TODO\n addChain,\n config,\n apis,\n rpcUrls,\n });\n\n return acc;\n }, {} as ConnectWalletMethods);\n\n /**\n * @Private\n * Internal helpers\n */\n function getSwapKitPlugin(pluginName?: PluginName) {\n const plugin =\n (availablePlugins as SwapKitPlugins)[pluginName as PluginName] ||\n Object.values(availablePlugins)[0];\n\n if (!plugin) {\n throw new SwapKitError(\"core_plugin_not_found\", \"Could not find the requested plugin\");\n }\n\n return plugin;\n }\n\n function addChain(connectWallet: Wallet[Chain]) {\n // @ts-expect-error TODO\n connectedWallets[connectWallet.chain] = connectWallet;\n }\n\n /**\n * @Private\n * Wallet interaction helpers\n */\n function approve<T extends ApproveMode>({\n assetValue,\n type = \"checkOnly\" as T,\n contractAddress: spenderAddress,\n }: {\n type: T;\n assetValue: AssetValue;\n contractAddress: string;\n }): ApproveReturnType<T> {\n const { address, chain, isGasAsset, isSynthetic } = assetValue;\n const isEVMChain = [Chain.Ethereum, Chain.Avalanche, Chain.BinanceSmartChain].includes(chain);\n const isNativeEVM = isEVMChain && isGasAsset;\n\n if (isNativeEVM || !isEVMChain || isSynthetic) {\n return Promise.resolve(type === \"checkOnly\" ? true : \"approved\") as ApproveReturnType<T>;\n }\n\n const walletMethods = connectedWallets[chain] as BaseEVMWallet;\n const walletAction = type === \"checkOnly\" ? walletMethods?.isApproved : walletMethods?.approve;\n if (!walletAction) throw new SwapKitError(\"core_wallet_connection_not_found\");\n\n const from = getAddress(chain);\n if (!(address && from)) {\n throw new SwapKitError(\"core_approve_asset_address_or_from_not_found\");\n }\n\n return walletAction({\n amount: assetValue.getBaseValue(\"bigint\"),\n assetAddress: address,\n from,\n spenderAddress,\n }) as ApproveReturnType<T>;\n }\n\n /**\n * @Public\n * Wallet helpers\n */\n function getWallet<T extends Chain>(chain: T) {\n return connectedWallets[chain];\n }\n function getAddress(chain: Chain) {\n return getWallet(chain)?.address || \"\";\n }\n async function getBalance(chain: Chain, refresh?: boolean) {\n if (refresh) {\n const wallet = await getWalletWithBalance(chain, true);\n return wallet.balance || [];\n }\n\n return getWallet(chain)?.balance || [];\n }\n /**\n * TODO: Figure out validation without connecting to wallet\n */\n function validateAddress({ address, chain }: { address: string; chain: Chain }) {\n return getWallet(chain)?.validateAddress?.(address);\n }\n\n async function getWalletWithBalance(chain: Chain, potentialScamFilter = true) {\n const defaultBalance = [AssetValue.fromChainOrSignature(chain)];\n const wallet = getWallet(chain);\n\n if (!wallet) {\n throw new SwapKitError(\"core_wallet_connection_not_found\");\n }\n\n if (\"getBalance\" in wallet) {\n const balance = await wallet.getBalance(wallet.address, potentialScamFilter);\n wallet.balance = balance?.length ? balance : defaultBalance;\n }\n\n return wallet;\n }\n\n /**\n * @Public\n * Wallet interaction methods\n */\n function approveAssetValue(assetValue: AssetValue, contractAddress: string) {\n return approve({ assetValue, contractAddress, type: ApproveMode.Approve });\n }\n\n function isAssetValueApproved(assetValue: AssetValue, contractAddress: string) {\n return approve({ assetValue, contractAddress, type: ApproveMode.CheckOnly });\n }\n\n function swap({ provider, ...rest }: SwapParams) {\n const plugin = getSwapKitPlugin(provider?.name);\n\n return plugin.swap({ provider, ...rest });\n }\n\n return {\n ...availablePlugins,\n ...connectWalletMethods,\n\n getExplorerAddressUrl: getAddressUrl,\n getExplorerTxUrl: getTxUrl,\n\n approveAssetValue,\n getAddress,\n getBalance,\n getWallet,\n getWalletWithBalance,\n isAssetValueApproved,\n swap,\n validateAddress,\n };\n}\n\nexport type SwapKitClient<T extends {}, K> = ReturnType<typeof SwapKit<T, K>>;\n"
|
|
9
9
|
],
|
|
10
10
|
"mappings": ";AAAA;AACA;;;ACDA;AAAA;AAAA;AAAA,SAME;AAAA;AAAA;;;ACNF;AAEO,SAAS,gBAAgB,GAAG,OAAO,UAA4C;AACpF,QAAM,UAAU,mBAAmB;AAEnC,UAAQ;AAAA,SACD,MAAM;AAAA,SACN,MAAM;AAAA,SACN,MAAM;AAAA,SACN,MAAM;AAAA,SACN,MAAM;AACT,aAAO,GAAG,cAAc,OAAO,WAAW,IAAI,IAAI,OAAO,MAAM,CAAC,IAAI;AAAA,SAEjE,MAAM;AAAA,SACN,MAAM;AAAA,SACN,MAAM;AAAA,SACN,MAAM;AAAA,SACN,MAAM;AAAA,SACN,MAAM;AAAA,SACN,MAAM;AACT,aAAO,GAAG,cAAc,OAAO,WAAW,IAAI,IAAI,SAAS,KAAK;AAAA,SAE7D,MAAM;AAAA,SACN,MAAM;AAAA,SACN,MAAM;AAAA,SACN,MAAM;AACT,aAAO,GAAG,uBAAuB,OAAO,YAAY;AAAA;AAGpD,YAAM,IAAI,MAAM,sBAAsB,OAAO;AAAA;AAAA;AAI5C,SAAS,qBAAqB,GAAG,OAAO,WAA8C;AAC3F,QAAM,UAAU,mBAAmB;AAEnC,SAAO,GAAG,mBAAmB;AAAA;",
|
|
11
|
-
"debugId": "
|
|
11
|
+
"debugId": "481EAEF7C9A043A064756e2164756e21",
|
|
12
12
|
"names": []
|
|
13
13
|
}
|
package/package.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@swapkit/api": "1.0.0-rc.
|
|
5
|
-
"@swapkit/helpers": "1.0.0-rc.
|
|
4
|
+
"@swapkit/api": "1.0.0-rc.52",
|
|
5
|
+
"@swapkit/helpers": "1.0.0-rc.87"
|
|
6
6
|
},
|
|
7
7
|
"description": "SwapKit - Core",
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@swapkit/tokens": "1.0.0-rc.47",
|
|
10
|
-
"@swapkit/toolbox-cosmos": "1.0.0-rc.
|
|
11
|
-
"@swapkit/toolbox-evm": "1.0.0-rc.
|
|
12
|
-
"@swapkit/toolbox-substrate": "1.0.0-rc.
|
|
13
|
-
"@swapkit/toolbox-utxo": "1.0.0-rc.
|
|
10
|
+
"@swapkit/toolbox-cosmos": "1.0.0-rc.104",
|
|
11
|
+
"@swapkit/toolbox-evm": "1.0.0-rc.93",
|
|
12
|
+
"@swapkit/toolbox-substrate": "1.0.0-rc.22",
|
|
13
|
+
"@swapkit/toolbox-utxo": "1.0.0-rc.95",
|
|
14
14
|
"bun-types": "1.1.2"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
|
-
"@swapkit/api": "1.0.0-rc.
|
|
18
|
-
"@swapkit/helpers": "1.0.0-rc.
|
|
17
|
+
"@swapkit/api": "1.0.0-rc.52",
|
|
18
|
+
"@swapkit/helpers": "1.0.0-rc.87"
|
|
19
19
|
},
|
|
20
20
|
"files": [
|
|
21
21
|
"src/",
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
},
|
|
41
41
|
"type": "module",
|
|
42
42
|
"types": "./src/index.ts",
|
|
43
|
-
"version": "1.0.0-rc.
|
|
43
|
+
"version": "1.0.0-rc.124"
|
|
44
44
|
}
|
package/src/client.ts
CHANGED
|
@@ -153,7 +153,7 @@ export function SwapKit<
|
|
|
153
153
|
* @Public
|
|
154
154
|
* Wallet helpers
|
|
155
155
|
*/
|
|
156
|
-
function getWallet(chain:
|
|
156
|
+
function getWallet<T extends Chain>(chain: T) {
|
|
157
157
|
return connectedWallets[chain];
|
|
158
158
|
}
|
|
159
159
|
function getAddress(chain: Chain) {
|
|
@@ -171,7 +171,7 @@ export function SwapKit<
|
|
|
171
171
|
* TODO: Figure out validation without connecting to wallet
|
|
172
172
|
*/
|
|
173
173
|
function validateAddress({ address, chain }: { address: string; chain: Chain }) {
|
|
174
|
-
getWallet(chain)?.validateAddress?.(address);
|
|
174
|
+
return getWallet(chain)?.validateAddress?.(address);
|
|
175
175
|
}
|
|
176
176
|
|
|
177
177
|
async function getWalletWithBalance(chain: Chain, potentialScamFilter = true) {
|