@swapkit/core 1.0.0-rc.172 → 1.0.0-rc.174
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 +4 -4
- package/package.json +10 -13
- package/src/client.ts +108 -150
- package/src/helpers/explorerUrls.ts +0 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export*from"@swapkit/api";export*from"@swapkit/helpers";import{stripToCashAddress as
|
|
1
|
+
export*from"@swapkit/api";export*from"@swapkit/helpers";import{stripToCashAddress as zo} from"@swapkit/toolbox-utxo";import{lowercasedContractAbiMapping as H} from"@swapkit/contracts";import{ApproveMode as Y,AssetValue as Z,Chain as $,EVMChains as d,ProviderName as i,SwapKitError as P,isGasAsset as t} from"@swapkit/helpers";import{estimateTransactionFee as n,cosmosValidateAddress as s} from"@swapkit/toolbox-cosmos";import{evmValidateAddress as l} from"@swapkit/toolbox-evm";import{substrateValidateAddress as e} from"@swapkit/toolbox-substrate";import{utxoValidateAddress as a} from"@swapkit/toolbox-utxo";import{Chain as U,ChainToExplorerUrl as b,SwapKitError as c} from"@swapkit/helpers";function m({chain:q,txHash:_}){const y=b[q];switch(q){case U.Maya:case U.Kujira:case U.Cosmos:case U.THORChain:case U.Solana:return`${y}/tx/${_.startsWith("0x")?_.slice(2):_}`;case U.Arbitrum:case U.Avalanche:case U.BinanceSmartChain:case U.Ethereum:case U.Optimism:case U.Polkadot:case U.Polygon:return`${y}/tx/${_.startsWith("0x")?_:`0x${_}`}`;case U.Litecoin:case U.Bitcoin:case U.BitcoinCash:case U.Dogecoin:return`${y}/transaction/${_.toLowerCase()}`;default:throw new c({errorKey:"core_explorer_unsupported_chain",info:{chain:q}})}}function E({chain:q,address:_}){const y=b[q];switch(q){case U.Solana:return`${y}/account/${_}`;default:return`${y}/address/${_}`}}function Lo({apis:q={},config:_={},plugins:y,rpcUrls:C={},stagenet:D=!1,wallets:F}){const J={},Q=Object.entries(y).reduce((o,[x,{plugin:k,config:T}])=>{const B=k({wallets:J,stagenet:D,config:T??_});return o[x]=B,o},{}),M=Object.entries(F).reduce((o,[x,k])=>{const T=k({addChain:W,config:_,apis:q,rpcUrls:C});return o[x]=T,o},{});function S(o){const x=Q[o]||Object.values(Q)[0];if(!x)throw new P("core_plugin_not_found");return x}function O(o){const x=Object.values(Q).find((k)=>k.supportedSwapkitProviders?.includes(o));if(!x)throw new P("core_plugin_not_found");return x}function W(o){J[o.chain]=o}function j({assetValue:o,type:x="checkOnly",contractAddress:k}){const T=Q[k];if(T){if(x===Y.CheckOnly&&"isAssetValueApproved"in T)return T.isAssetValueApproved({assetValue:o});if(x===Y.Approve&&"approveAssetValue"in T)return T.approveAssetValue({assetValue:o});throw new P({errorKey:"core_approve_asset_target_invalid",info:{message:`Target ${String(k)} cannot be used for approve operation`}})}const B=o.chain,z=d.includes(B);if(z&&o.isGasAsset||!z||o.isSynthetic)return Promise.resolve(x==="checkOnly"?!0:"approved");const L=I(B),R=x==="checkOnly"?L.isApproved:L.approve;if(!R)throw new P("core_wallet_connection_not_found");if(!(o.address&&L.address&&typeof k==="string"))throw new P("core_approve_asset_address_or_from_not_found");return R({amount:o.getBaseValue("bigint"),assetAddress:o.address,from:L.address,spenderAddress:k})}function I(o){return J[o]}function v(){return{...J}}function N(o){return I(o)?.address||""}function K(o,x){return j({assetValue:o,contractAddress:x,type:Y.Approve})}function A(o,x){return j({assetValue:o,contractAddress:x,type:Y.CheckOnly})}function G(o){I(o)?.disconnect?.(),delete J[o]}function w(){for(let o of Object.keys(J))G(o)}function V(o,x){return x?f(o).then((k)=>k.balance):I(o)?.balance||[]}function r({address:o,chain:x}){switch(x){case $.Arbitrum:case $.Avalanche:case $.Optimism:case $.BinanceSmartChain:case $.Polygon:case $.Ethereum:return l({address:o});case $.Litecoin:case $.Dash:case $.Dogecoin:case $.BitcoinCash:case $.Bitcoin:return a({address:o,chain:x});case $.Cosmos:case $.Kujira:case $.Maya:case $.THORChain:return s({address:o,chain:x});case $.Polkadot:return e({address:o,chain:x});default:return!1}}async function f(o,x=!0){const k=[Z.from({chain:o})],T=I(o);if(!T)throw new P("core_wallet_connection_not_found");if("getBalance"in T){const B=await T.getBalance(T.address,x);T.balance=B?.length?B:k}return T}function h({route:o,pluginName:x,...k}){const T=x&&S(x)||O(o.providers[0]);if(!T)throw new P("core_swap_route_not_complete");if("swap"in T)return T.swap({...k,route:o});throw new P("core_plugin_swap_not_found")}function g({from:o,recipient:x,assetValue:k,feeOptionKey:T}){const B=k.chain,z=I(B);if(!z)throw new P("core_wallet_connection_not_found");return z.transfer({from:o,recipient:x,assetValue:k,feeOptionKey:T})}async function p({type:o,feeOptionKey:x,params:k}){const{assetValue:T}=k,{chain:B}=T;if(!I(B))throw new P("core_wallet_connection_not_found");const z=Z.from({chain:B});switch(B){case $.Arbitrum:case $.Avalanche:case $.Ethereum:case $.BinanceSmartChain:case $.Polygon:{const X=I(B);if(o==="transfer"){const L=await X.createTransferTx(k);return X.estimateTransactionFee(L,x)}if(o==="approve"&&!t(T))return X.estimateTransactionFee(await X.createApprovalTx({assetAddress:T.address,spenderAddress:k.contractAddress,amount:T.getBaseValue("bigint"),from:X.address}),x);if(o==="swap"){if(k.route.providers[0]===i.CHAINFLIP){const u=await X.createTransferTx({from:X.address,recipient:X.address,assetValue:T});return X.estimateTransactionFee(u,x)}const{evmTransactionDetails:R}=k.route;if(!(R&&H[R.contractAddress]))return;return X.estimateTransactionFee(await X.createContractTxObject({contractAddress:R.contractAddress,abi:H[R.contractAddress],funcName:R.contractMethod,funcParams:R.contractParams}),x)}return Z.from({chain:B})}case $.Bitcoin:case $.BitcoinCash:case $.Dogecoin:case $.Dash:case $.Litecoin:{const{estimateMaxSendableAmount:X,address:L}=I(B);return X({...k,feeOptionKey:x,from:L,recipient:L})}case $.THORChain:case $.Maya:case $.Kujira:case $.Cosmos:return n(k);case $.Polkadot:{const{address:X,estimateTransactionFee:L}=I(B);return L({...k,recipient:X})}default:return z}}return{...Q,...M,approveAssetValue:K,getAddress:N,getBalance:V,getExplorerAddressUrl:E,getExplorerTxUrl:m,getWallet:I,getAllWallets:v,getWalletWithBalance:f,isAssetValueApproved:A,estimateTransactionFee:p,swap:h,transfer:g,validateAddress:r,disconnectAll:w,disconnectChain:G}}export{zo as stripToCashAddress,Lo as SwapKit};
|
|
2
2
|
|
|
3
|
-
//# debugId=
|
|
3
|
+
//# debugId=C19E100412E60E5664756E2164756E21
|
package/dist/index.js.map
CHANGED
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
"sources": ["../src/index.ts", "../src/client.ts", "../src/helpers/explorerUrls.ts"],
|
|
4
4
|
"sourcesContent": [
|
|
5
5
|
"export * from \"@swapkit/api\";\nexport * from \"@swapkit/helpers\";\nexport { stripToCashAddress } from \"@swapkit/toolbox-utxo\";\n\nexport * from \"./client.ts\";\nexport * from \"./types.ts\";\n",
|
|
6
|
-
"import { lowercasedContractAbiMapping } from \"@swapkit/contracts\";\nimport {\n type AddChainWalletParams,\n ApproveMode,\n type ApproveReturnType,\n AssetValue,\n Chain,\n type ConnectConfig,\n type EVMChain,\n EVMChains,\n type FeeOption,\n ProviderName as PluginNameEnum,\n SwapKitError,\n type SwapParams,\n type UTXOChain,\n type WalletChain,\n isGasAsset,\n} from \"@swapkit/helpers\";\nimport {\n type TransferParams as CosmosTransferParams,\n estimateTransactionFee as cosmosTransactionFee,\n cosmosValidateAddress,\n} from \"@swapkit/toolbox-cosmos\";\nimport {\n type BaseEVMWallet,\n type TransferParams as EVMTransferParams,\n evmValidateAddress,\n} from \"@swapkit/toolbox-evm\";\nimport { substrateValidateAddress } from \"@swapkit/toolbox-substrate\";\nimport { type UTXOTransferParams, utxoValidateAddress } from \"@swapkit/toolbox-utxo\";\n\nimport {\n getExplorerAddressUrl as getAddressUrl,\n getExplorerTxUrl as getTxUrl,\n} from \"./helpers/explorerUrls.ts\";\nimport type { Apis, SwapKitPluginInterface, SwapKitWallet, Wallet } from \"./types.ts\";\n\nexport function SwapKit<\n Plugins extends { [key in string]: SwapKitPluginInterface<{ [key in string]: Todo }> },\n Wallets extends { [key in string]: SwapKitWallet<NotWorth[]> },\n>({\n apis = {},\n config = {},\n plugins,\n rpcUrls = {},\n stagenet = false,\n wallets,\n}: {\n apis?: Apis;\n config?: ConnectConfig;\n plugins: Plugins;\n rpcUrls?: { [key in Chain]?: string };\n stagenet?: boolean;\n wallets: Wallets;\n}) {\n type PluginName = keyof Plugins;\n\n /**\n * @REMOVE (V1)\n * Compatibility layer for plugins and wallets for easier migration and backwards compatibility\n */\n const compatPlugins: Plugins = Array.isArray(plugins)\n ? plugins.reduce((acc, pluginInterface) => {\n // @ts-ignore Ignore until we remove the compatibility layer\n const { name, plugin } = Object.values(pluginInterface)?.[0] || {};\n acc[name] = plugin;\n return acc;\n }, {})\n : plugins;\n const compatWallets: Wallets = Array.isArray(wallets)\n ? wallets.reduce((acc, wallet) => {\n // @ts-ignore Ignore until we remove the compatibility layer\n const [walletName, connectWallet] = Object.entries(wallet)?.[0] || {};\n acc[walletName] = connectWallet;\n return acc;\n }, {})\n : wallets;\n\n const connectedWallets = {} as Wallet;\n const availablePlugins = Object.entries(compatPlugins).reduce(\n (acc, [pluginName, { plugin, config: pluginConfig }]) => {\n const methods = plugin({\n wallets: connectedWallets,\n stagenet,\n config: pluginConfig ?? config,\n });\n\n // @ts-expect-error\n acc[pluginName] = methods;\n return acc;\n },\n {} as { [key in PluginName]: ReturnType<Plugins[key][\"plugin\"]> },\n );\n\n const connectWalletMethods = Object.entries(compatWallets).reduce(\n (acc, [walletName, wallet]) => {\n const connectWallet = wallet({ addChain, config, apis, rpcUrls });\n\n // @ts-expect-error\n acc[walletName] = connectWallet;\n return acc;\n },\n {} as { [key in keyof Wallets]: ReturnType<Wallets[key]> },\n );\n\n /**\n * @Private\n */\n function getSwapKitPlugin<T extends PluginName>(pluginName: T) {\n const plugin = availablePlugins[pluginName] || 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 /**\n * @Private\n */\n function getSwapKitPluginForSKProvider(pluginName: PluginNameEnum): Plugins[keyof Plugins] {\n const plugin = Object.values(availablePlugins).find((plugin) =>\n plugin.supportedSwapkitProviders?.includes(pluginName),\n );\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<T extends Chain>(connectWallet: AddChainWalletParams<T>) {\n // @ts-expect-error: TODO\n connectedWallets[connectWallet.chain] = connectWallet;\n }\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>\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 | PluginName;\n }) {\n const plugin = availablePlugins[spenderAddress];\n\n if (plugin) {\n if (type === ApproveMode.CheckOnly && \"isAssetValueApproved\" in plugin) {\n return plugin.isAssetValueApproved({ assetValue }) as ApproveReturnType<T>;\n }\n if (type === ApproveMode.Approve && \"approveAssetValue\" in plugin) {\n return plugin.approveAssetValue({ assetValue }) as ApproveReturnType<T>;\n }\n\n throw new SwapKitError(\n \"core_approve_asset_target_invalid\",\n `Target ${String(spenderAddress)} cannot be used for approve operation`,\n );\n }\n\n const { address, chain, isGasAsset, isSynthetic } = assetValue;\n const isEVMChain = EVMChains.includes(chain as EVMChain);\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 && typeof spenderAddress === \"string\")) {\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 */\n function getWallet<T extends Chain>(chain: T) {\n return connectedWallets[chain];\n }\n function getAllWallets() {\n return { ...connectedWallets };\n }\n function getAddress<T extends Chain>(chain: T) {\n return getWallet(chain)?.address || \"\";\n }\n\n function validateAddress({ address, chain }: { address: string; chain: Chain }) {\n switch (chain) {\n case Chain.Arbitrum:\n case Chain.Avalanche:\n case Chain.Optimism:\n case Chain.BinanceSmartChain:\n case Chain.Polygon:\n case Chain.Ethereum: {\n return evmValidateAddress({ address });\n }\n case Chain.Polkadot: {\n return substrateValidateAddress({ address, chain });\n }\n case Chain.Litecoin:\n case Chain.Dash:\n case Chain.Dogecoin:\n case Chain.BitcoinCash:\n case Chain.Bitcoin: {\n return utxoValidateAddress({ address, chain });\n }\n case Chain.Cosmos:\n case Chain.Kujira:\n case Chain.Maya:\n case Chain.THORChain: {\n return cosmosValidateAddress({ address, chain });\n }\n }\n return false;\n }\n\n function getBalance<T extends Chain>(chain: T, refresh?: boolean) {\n if (refresh) {\n return getWalletWithBalance(chain).then((wallet) => wallet.balance);\n }\n\n return getWallet(chain)?.balance || [];\n }\n\n async function getWalletWithBalance<T extends Chain>(chain: T, 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 // @ts-expect-error TODO add getBalance to radix\n const balance = await wallet.getBalance(wallet.address, potentialScamFilter);\n wallet.balance = balance?.length ? balance : defaultBalance;\n }\n\n return wallet;\n }\n\n function approveAssetValue(assetValue: AssetValue, contractAddress: string | PluginName) {\n return approve({ assetValue, contractAddress, type: ApproveMode.Approve });\n }\n\n function isAssetValueApproved(assetValue: AssetValue, contractAddress: string | PluginName) {\n return approve({ assetValue, contractAddress, type: ApproveMode.CheckOnly });\n }\n\n function swap<T extends PluginName>({ route, pluginName, ...rest }: SwapParams<T>) {\n const plugin =\n (pluginName && getSwapKitPlugin(pluginName)) ||\n getSwapKitPluginForSKProvider(route.providers[0] as PluginNameEnum);\n if (!plugin) throw new SwapKitError(\"core_swap_route_not_complete\");\n\n if (\"swap\" in plugin) {\n return plugin.swap({ ...rest, route });\n }\n\n throw new SwapKitError(\"core_plugin_swap_not_found\");\n }\n\n function transfer({\n from,\n recipient,\n assetValue,\n feeOptionKey,\n }: UTXOTransferParams | EVMTransferParams | CosmosTransferParams) {\n const chain = assetValue.chain as WalletChain;\n const wallet = connectedWallets[chain];\n if (!wallet) throw new SwapKitError(\"core_wallet_connection_not_found\");\n\n return wallet.transfer({ from, recipient, assetValue, feeOptionKey });\n }\n\n function disconnectAll() {\n for (const chain of Object.keys(connectedWallets)) {\n // @ts-expect-error: TODO\n const wallet = connectedWallets[chain];\n if (\"disconnect\" in wallet) {\n wallet.disconnect();\n }\n // @ts-expect-error: TODO\n delete connectedWallets[chain];\n }\n }\n\n function disconnectChain(chain: Chain) {\n const wallet = connectedWallets[chain];\n const disconnect = wallet?.disconnect;\n if (disconnect) {\n disconnect();\n }\n delete connectedWallets[chain];\n }\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO clean this up\n async function estimateTransactionFee<T extends PluginName>({\n type,\n feeOptionKey,\n params,\n }: (\n | { type: \"swap\"; params: SwapParams<T> & { assetValue: AssetValue } }\n | {\n type: \"transfer\";\n params: UTXOTransferParams | EVMTransferParams | CosmosTransferParams;\n }\n | {\n type: \"approve\";\n params: {\n assetValue: AssetValue;\n contractAddress: string | PluginName;\n feeOptionKey?: FeeOption;\n };\n }\n ) & {\n feeOptionKey: FeeOption;\n }): Promise<AssetValue | undefined> {\n const { assetValue } = params;\n const chain = params.assetValue.chain as WalletChain;\n if (!connectedWallets[chain]) throw new SwapKitError(\"core_wallet_connection_not_found\");\n\n const baseValue = AssetValue.fromChainOrSignature(chain, 0);\n\n switch (chain) {\n case Chain.Arbitrum:\n case Chain.Avalanche:\n case Chain.Ethereum:\n case Chain.BinanceSmartChain:\n case Chain.Polygon: {\n const wallet = connectedWallets[chain as Exclude<EVMChain, Chain.Optimism>];\n switch (type) {\n case \"transfer\": {\n const txObject = await wallet.createTransferTx(params);\n return wallet.estimateTransactionFee(txObject, feeOptionKey);\n }\n\n case \"approve\": {\n if (isGasAsset(assetValue)) return baseValue;\n\n return wallet.estimateTransactionFee(\n await wallet.createApprovalTx({\n assetAddress: assetValue.address as string,\n spenderAddress: params.contractAddress as string,\n amount: assetValue.getBaseValue(\"bigint\"),\n from: wallet.address,\n }),\n feeOptionKey,\n );\n }\n\n case \"swap\": {\n const plugin = params.route.providers[0] as PluginNameEnum;\n if (plugin === PluginNameEnum.CHAINFLIP) {\n const txObject = await wallet.createTransferTx({\n from: wallet.address,\n recipient: wallet.address,\n assetValue,\n });\n return wallet.estimateTransactionFee(txObject, feeOptionKey);\n }\n const { evmTransactionDetails } = params.route;\n\n if (\n !(\n evmTransactionDetails &&\n lowercasedContractAbiMapping[evmTransactionDetails.contractAddress]\n )\n ) {\n return undefined;\n }\n\n const estimate = await wallet.estimateCall({\n contractAddress: evmTransactionDetails.contractAddress,\n // biome-ignore lint/style/noNonNullAssertion: TS cant infer the type\n abi: lowercasedContractAbiMapping[evmTransactionDetails.contractAddress]!,\n funcName: evmTransactionDetails.contractMethod,\n funcParams: evmTransactionDetails.contractParams,\n });\n\n return AssetValue.fromChainOrSignature(chain, estimate);\n }\n\n default:\n return baseValue;\n }\n }\n\n case Chain.Bitcoin:\n case Chain.BitcoinCash:\n case Chain.Dogecoin:\n case Chain.Dash:\n case Chain.Litecoin: {\n const { estimateMaxSendableAmount, address } = connectedWallets[chain as UTXOChain];\n\n return estimateMaxSendableAmount({\n ...params,\n feeOptionKey,\n from: address,\n recipient: address,\n });\n }\n\n case Chain.THORChain:\n case Chain.Maya:\n case Chain.Kujira:\n case Chain.Cosmos: {\n return cosmosTransactionFee(params);\n }\n\n case Chain.Polkadot: {\n const wallet = connectedWallets[chain as Chain.Polkadot];\n return wallet.estimateTransactionFee({ ...params, recipient: wallet.address });\n }\n\n default:\n return baseValue;\n }\n }\n\n return {\n ...availablePlugins,\n ...connectWalletMethods,\n\n approveAssetValue,\n getAddress,\n getBalance,\n getExplorerAddressUrl: getAddressUrl,\n getExplorerTxUrl: getTxUrl,\n getWallet,\n getAllWallets,\n getWalletWithBalance,\n isAssetValueApproved,\n estimateTransactionFee,\n swap,\n transfer,\n validateAddress,\n disconnectAll,\n disconnectChain,\n };\n}\n",
|
|
7
|
-
"import { Chain, ChainToExplorerUrl, SwapKitError } 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.
|
|
6
|
+
"import { lowercasedContractAbiMapping } from \"@swapkit/contracts\";\nimport {\n type AddChainWalletParams,\n ApproveMode,\n type ApproveReturnType,\n AssetValue,\n Chain,\n type ConnectConfig,\n type EVMChain,\n EVMChains,\n type FeeOption,\n ProviderName as PluginNameEnum,\n SwapKitError,\n type SwapParams,\n type WalletChain,\n isGasAsset,\n} from \"@swapkit/helpers\";\nimport {\n type TransferParams as CosmosTransferParams,\n estimateTransactionFee as cosmosTransactionFee,\n cosmosValidateAddress,\n} from \"@swapkit/toolbox-cosmos\";\nimport { type TransferParams as EVMTransferParams, evmValidateAddress } from \"@swapkit/toolbox-evm\";\nimport { substrateValidateAddress } from \"@swapkit/toolbox-substrate\";\nimport { type UTXOTransferParams, utxoValidateAddress } from \"@swapkit/toolbox-utxo\";\n\nimport {\n getExplorerAddressUrl as getAddressUrl,\n getExplorerTxUrl as getTxUrl,\n} from \"./helpers/explorerUrls.ts\";\nimport type { Apis, SwapKitPluginInterface, SwapKitWallet, Wallet } from \"./types.ts\";\n\nexport function SwapKit<\n Plugins extends { [key in string]: SwapKitPluginInterface<{ [key in string]: Todo }> },\n Wallets extends { [key in string]: SwapKitWallet<NotWorth[]> },\n>({\n apis = {},\n config = {},\n plugins,\n rpcUrls = {},\n stagenet = false,\n wallets,\n}: {\n apis?: Apis;\n config?: ConnectConfig;\n plugins: Plugins;\n rpcUrls?: { [key in Chain]?: string };\n stagenet?: boolean;\n wallets: Wallets;\n}) {\n type PluginName = keyof Plugins;\n\n const connectedWallets = {} as Wallet;\n const availablePlugins = Object.entries(plugins).reduce(\n (acc, [pluginName, { plugin, config: pluginConfig }]) => {\n const methods = plugin({\n wallets: connectedWallets,\n stagenet,\n config: pluginConfig ?? config,\n });\n\n // @ts-expect-error\n acc[pluginName] = methods;\n return acc;\n },\n {} as { [key in PluginName]: ReturnType<Plugins[key][\"plugin\"]> },\n );\n\n const connectWalletMethods = Object.entries(wallets).reduce(\n (acc, [walletName, wallet]) => {\n const connectWallet = wallet({ addChain, config, apis, rpcUrls });\n\n // @ts-expect-error\n acc[walletName] = connectWallet;\n return acc;\n },\n {} as { [key in keyof Wallets]: ReturnType<Wallets[key]> },\n );\n\n function getSwapKitPlugin<T extends PluginName>(pluginName: T) {\n const plugin = availablePlugins[pluginName] || Object.values(availablePlugins)[0];\n\n if (!plugin) {\n throw new SwapKitError(\"core_plugin_not_found\");\n }\n\n return plugin;\n }\n\n function getSwapKitPluginForSKProvider(pluginName: PluginNameEnum): Plugins[keyof Plugins] {\n const plugin = Object.values(availablePlugins).find((plugin) =>\n plugin.supportedSwapkitProviders?.includes(pluginName),\n );\n\n if (!plugin) {\n throw new SwapKitError(\"core_plugin_not_found\");\n }\n\n return plugin;\n }\n\n function addChain<T extends Chain>(connectWallet: AddChainWalletParams<T>) {\n // @ts-expect-error: TODO\n connectedWallets[connectWallet.chain] = connectWallet;\n }\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>\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 | PluginName;\n }) {\n const plugin = availablePlugins[spenderAddress];\n\n if (plugin) {\n if (type === ApproveMode.CheckOnly && \"isAssetValueApproved\" in plugin) {\n return plugin.isAssetValueApproved({ assetValue }) as ApproveReturnType<T>;\n }\n if (type === ApproveMode.Approve && \"approveAssetValue\" in plugin) {\n return plugin.approveAssetValue({ assetValue }) as ApproveReturnType<T>;\n }\n\n throw new SwapKitError({\n errorKey: \"core_approve_asset_target_invalid\",\n info: { message: `Target ${String(spenderAddress)} cannot be used for approve operation` },\n });\n }\n\n const chain = assetValue.chain as EVMChain;\n const isEVMChain = EVMChains.includes(chain);\n const isNativeEVM = isEVMChain && assetValue.isGasAsset;\n\n if (isNativeEVM || !isEVMChain || assetValue.isSynthetic) {\n return Promise.resolve(type === \"checkOnly\" ? true : \"approved\") as ApproveReturnType<T>;\n }\n\n const wallet = getWallet(chain);\n const walletAction = type === \"checkOnly\" ? wallet.isApproved : wallet.approve;\n if (!walletAction) throw new SwapKitError(\"core_wallet_connection_not_found\");\n\n if (!(assetValue.address && wallet.address && typeof spenderAddress === \"string\")) {\n throw new SwapKitError(\"core_approve_asset_address_or_from_not_found\");\n }\n\n return walletAction({\n amount: assetValue.getBaseValue(\"bigint\"),\n assetAddress: assetValue.address,\n from: wallet.address,\n spenderAddress,\n }) as ApproveReturnType<T>;\n }\n\n /**\n * @Public\n */\n function getWallet<T extends Chain>(chain: T) {\n return connectedWallets[chain];\n }\n\n function getAllWallets() {\n return { ...connectedWallets };\n }\n\n function getAddress<T extends Chain>(chain: T) {\n return getWallet(chain)?.address || \"\";\n }\n\n function approveAssetValue(assetValue: AssetValue, contractAddress: string | PluginName) {\n return approve({ assetValue, contractAddress, type: ApproveMode.Approve });\n }\n\n function isAssetValueApproved(assetValue: AssetValue, contractAddress: string | PluginName) {\n return approve({ assetValue, contractAddress, type: ApproveMode.CheckOnly });\n }\n\n function disconnectChain<T extends Chain>(chain: T) {\n const wallet = getWallet(chain);\n wallet?.disconnect?.();\n delete connectedWallets[chain];\n }\n\n function disconnectAll() {\n for (const chain of Object.keys(connectedWallets) as (keyof typeof connectedWallets)[]) {\n disconnectChain(chain);\n }\n }\n\n function getBalance<T extends Chain>(chain: T, refresh?: boolean) {\n return refresh\n ? getWalletWithBalance(chain).then((wallet) => wallet.balance)\n : getWallet(chain)?.balance || [];\n }\n\n function validateAddress({ address, chain }: { address: string; chain: Chain }) {\n switch (chain) {\n case Chain.Arbitrum:\n case Chain.Avalanche:\n case Chain.Optimism:\n case Chain.BinanceSmartChain:\n case Chain.Polygon:\n case Chain.Ethereum:\n return evmValidateAddress({ address });\n\n case Chain.Litecoin:\n case Chain.Dash:\n case Chain.Dogecoin:\n case Chain.BitcoinCash:\n case Chain.Bitcoin:\n return utxoValidateAddress({ address, chain });\n\n case Chain.Cosmos:\n case Chain.Kujira:\n case Chain.Maya:\n case Chain.THORChain:\n return cosmosValidateAddress({ address, chain });\n\n case Chain.Polkadot:\n return substrateValidateAddress({ address, chain });\n\n default:\n return false;\n }\n }\n\n async function getWalletWithBalance<T extends Chain>(chain: T, potentialScamFilter = true) {\n const defaultBalance = [AssetValue.from({ 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 // @ts-expect-error TODO add getBalance to radix\n const balance = await wallet.getBalance(wallet.address, potentialScamFilter);\n wallet.balance = balance?.length ? balance : defaultBalance;\n }\n\n return wallet;\n }\n\n function swap<T extends PluginName>({ route, pluginName, ...rest }: SwapParams<T>) {\n const plugin =\n (pluginName && getSwapKitPlugin(pluginName)) ||\n getSwapKitPluginForSKProvider(route.providers[0] as PluginNameEnum);\n\n if (!plugin) throw new SwapKitError(\"core_swap_route_not_complete\");\n\n if (\"swap\" in plugin) {\n return plugin.swap({ ...rest, route });\n }\n\n throw new SwapKitError(\"core_plugin_swap_not_found\");\n }\n\n function transfer({\n from,\n recipient,\n assetValue,\n feeOptionKey,\n }: UTXOTransferParams | EVMTransferParams | CosmosTransferParams) {\n const chain = assetValue.chain as WalletChain;\n const wallet = getWallet(chain);\n if (!wallet) throw new SwapKitError(\"core_wallet_connection_not_found\");\n\n return wallet.transfer({ from, recipient, assetValue, feeOptionKey });\n }\n\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO clean this up\n async function estimateTransactionFee<T extends PluginName>({\n type,\n feeOptionKey,\n params,\n }: (\n | { type: \"swap\"; params: SwapParams<T> & { assetValue: AssetValue } }\n | {\n type: \"transfer\";\n params: UTXOTransferParams | EVMTransferParams | CosmosTransferParams;\n }\n | {\n type: \"approve\";\n params: {\n assetValue: AssetValue;\n contractAddress: string | PluginName;\n feeOptionKey?: FeeOption;\n };\n }\n ) & {\n feeOptionKey: FeeOption;\n }): Promise<AssetValue | undefined> {\n const { assetValue } = params;\n const { chain } = assetValue;\n\n if (!getWallet(chain)) throw new SwapKitError(\"core_wallet_connection_not_found\");\n\n const baseValue = AssetValue.from({ chain });\n\n switch (chain) {\n case Chain.Arbitrum:\n case Chain.Avalanche:\n case Chain.Ethereum:\n case Chain.BinanceSmartChain:\n case Chain.Polygon: {\n const wallet = getWallet(chain);\n if (type === \"transfer\") {\n const txObject = await wallet.createTransferTx(params);\n return wallet.estimateTransactionFee(txObject, feeOptionKey);\n }\n\n if (type === \"approve\" && !isGasAsset(assetValue)) {\n return wallet.estimateTransactionFee(\n await wallet.createApprovalTx({\n assetAddress: assetValue.address as string,\n spenderAddress: params.contractAddress as string,\n amount: assetValue.getBaseValue(\"bigint\"),\n from: wallet.address,\n }),\n feeOptionKey,\n );\n }\n\n if (type === \"swap\") {\n const plugin = params.route.providers[0] as PluginNameEnum;\n if (plugin === PluginNameEnum.CHAINFLIP) {\n const txObject = await wallet.createTransferTx({\n from: wallet.address,\n recipient: wallet.address,\n assetValue,\n });\n return wallet.estimateTransactionFee(txObject, feeOptionKey);\n }\n\n const { evmTransactionDetails } = params.route;\n if (\n !(\n evmTransactionDetails &&\n lowercasedContractAbiMapping[evmTransactionDetails.contractAddress]\n )\n ) {\n return undefined;\n }\n\n return wallet.estimateTransactionFee(\n await wallet.createContractTxObject({\n contractAddress: evmTransactionDetails.contractAddress,\n // biome-ignore lint/style/noNonNullAssertion: TS cant infer the type\n abi: lowercasedContractAbiMapping[evmTransactionDetails.contractAddress]!,\n funcName: evmTransactionDetails.contractMethod,\n funcParams: evmTransactionDetails.contractParams,\n }),\n feeOptionKey,\n );\n }\n\n return AssetValue.from({ chain });\n }\n\n case Chain.Bitcoin:\n case Chain.BitcoinCash:\n case Chain.Dogecoin:\n case Chain.Dash:\n case Chain.Litecoin: {\n const { estimateMaxSendableAmount, address } = getWallet(chain);\n\n return estimateMaxSendableAmount({\n ...params,\n feeOptionKey,\n from: address,\n recipient: address,\n });\n }\n\n case Chain.THORChain:\n case Chain.Maya:\n case Chain.Kujira:\n case Chain.Cosmos: {\n return cosmosTransactionFee(params);\n }\n\n case Chain.Polkadot: {\n const { address, estimateTransactionFee } = getWallet(chain);\n\n return estimateTransactionFee({ ...params, recipient: address });\n }\n\n default:\n return baseValue;\n }\n }\n\n return {\n ...availablePlugins,\n ...connectWalletMethods,\n\n approveAssetValue,\n getAddress,\n getBalance,\n getExplorerAddressUrl: getAddressUrl,\n getExplorerTxUrl: getTxUrl,\n getWallet,\n getAllWallets,\n getWalletWithBalance,\n isAssetValueApproved,\n estimateTransactionFee,\n swap,\n transfer,\n validateAddress,\n disconnectAll,\n disconnectChain,\n };\n}\n",
|
|
7
|
+
"import { Chain, ChainToExplorerUrl, SwapKitError } 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.Maya:\n case Chain.Kujira:\n case Chain.Cosmos:\n case Chain.THORChain:\n case Chain.Solana:\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 SwapKitError({ errorKey: \"core_explorer_unsupported_chain\", info: { chain } });\n }\n}\n\nexport function getExplorerAddressUrl({ chain, address }: { address: string; chain: Chain }) {\n const baseUrl = ChainToExplorerUrl[chain];\n\n switch (chain) {\n case Chain.Solana:\n return `${baseUrl}/account/${address}`;\n\n default:\n return `${baseUrl}/address/${address}`;\n }\n}\n"
|
|
8
8
|
],
|
|
9
|
-
"mappings": "AAAA,0BACA,8BACA,6BAAS,gCCFT,uCAAS,4BACT,sBAEE,gBAEA,WACA,eAGA,kBAEA,kBACA,
|
|
10
|
-
"debugId": "
|
|
9
|
+
"mappings": "AAAA,0BACA,8BACA,6BAAS,gCCFT,uCAAS,4BACT,sBAEE,gBAEA,WACA,eAGA,kBAEA,kBACA,gBAGA,0BAEF,iCAEE,2BACA,iCAEF,6BAAmD,8BACnD,mCAAS,oCACT,8BAAkC,+BCxBlC,gBAAS,wBAAO,kBAAoB,0BAE7B,SAAS,CAAgB,EAAG,QAAO,UAA4C,CACpF,MAAM,EAAU,EAAmB,GAEnC,OAAQ,QACD,EAAM,UACN,EAAM,YACN,EAAM,YACN,EAAM,eACN,EAAM,OACT,MAAO,GAAG,QAAc,EAAO,WAAW,IAAI,EAAI,EAAO,MAAM,CAAC,EAAI,SAEjE,EAAM,cACN,EAAM,eACN,EAAM,uBACN,EAAM,cACN,EAAM,cACN,EAAM,cACN,EAAM,QACT,MAAO,GAAG,QAAc,EAAO,WAAW,IAAI,EAAI,EAAS,KAAK,WAE7D,EAAM,cACN,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CAAC,CAClC,MAEK,EAAM,aACN,EAAM,iBACN,EAAM,cACN,EAAM,UACN,EAAM,SAAU,CACnB,MAAQ,4BAA2B,WAAY,EAAU,CAAK,EAE9D,OAAO,EAA0B,IAC5B,EACH,eACA,KAAM,EACN,UAAW,CACb,CAAC,CACH,MAEK,EAAM,eACN,EAAM,UACN,EAAM,YACN,EAAM,OACT,OAAO,EAAqB,CAAM,OAG/B,EAAM,SAAU,CACnB,MAAQ,UAAS,0BAA2B,EAAU,CAAK,EAE3D,OAAO,EAAuB,IAAK,EAAQ,UAAW,CAAQ,CAAC,CACjE,SAGE,OAAO,GAIb,MAAO,IACF,KACA,EAEH,oBACA,aACA,aACA,sBAAuB,EACvB,iBAAkB,EAClB,YACA,gBACA,uBACA,uBACA,yBACA,OACA,WACA,kBACA,gBACA,iBACF",
|
|
10
|
+
"debugId": "C19E100412E60E5664756E2164756E21",
|
|
11
11
|
"names": []
|
|
12
12
|
}
|
package/package.json
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@swapkit/api": "
|
|
5
|
-
"@swapkit/contracts": "
|
|
6
|
-
"@swapkit/helpers": "
|
|
7
|
-
"@swapkit/plugin-evm": "1.0.0-rc.
|
|
8
|
-
"@swapkit/toolbox-cosmos": "1.0.0-rc.
|
|
9
|
-
"@swapkit/toolbox-evm": "1.0.0-rc.
|
|
10
|
-
"@swapkit/toolbox-solana": "1.0.0-rc.
|
|
11
|
-
"@swapkit/toolbox-substrate": "1.0.0-rc.
|
|
12
|
-
"@swapkit/toolbox-utxo": "1.0.0-rc.
|
|
13
|
-
},
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
"@swapkit/tokens": "undefined"
|
|
4
|
+
"@swapkit/api": "1.0.0-rc.87",
|
|
5
|
+
"@swapkit/contracts": "1.0.0-rc.4",
|
|
6
|
+
"@swapkit/helpers": "1.0.0-rc.119",
|
|
7
|
+
"@swapkit/plugin-evm": "1.0.0-rc.19",
|
|
8
|
+
"@swapkit/toolbox-cosmos": "1.0.0-rc.146",
|
|
9
|
+
"@swapkit/toolbox-evm": "1.0.0-rc.126",
|
|
10
|
+
"@swapkit/toolbox-solana": "1.0.0-rc.7",
|
|
11
|
+
"@swapkit/toolbox-substrate": "1.0.0-rc.54",
|
|
12
|
+
"@swapkit/toolbox-utxo": "1.0.0-rc.130"
|
|
16
13
|
},
|
|
17
14
|
"description": "SwapKit - Core",
|
|
18
15
|
"files": [
|
|
@@ -38,5 +35,5 @@
|
|
|
38
35
|
},
|
|
39
36
|
"type": "module",
|
|
40
37
|
"types": "./src/index.ts",
|
|
41
|
-
"version": "1.0.0-rc.
|
|
38
|
+
"version": "1.0.0-rc.174"
|
|
42
39
|
}
|
package/src/client.ts
CHANGED
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
ProviderName as PluginNameEnum,
|
|
13
13
|
SwapKitError,
|
|
14
14
|
type SwapParams,
|
|
15
|
-
type UTXOChain,
|
|
16
15
|
type WalletChain,
|
|
17
16
|
isGasAsset,
|
|
18
17
|
} from "@swapkit/helpers";
|
|
@@ -21,11 +20,7 @@ import {
|
|
|
21
20
|
estimateTransactionFee as cosmosTransactionFee,
|
|
22
21
|
cosmosValidateAddress,
|
|
23
22
|
} from "@swapkit/toolbox-cosmos";
|
|
24
|
-
import {
|
|
25
|
-
type BaseEVMWallet,
|
|
26
|
-
type TransferParams as EVMTransferParams,
|
|
27
|
-
evmValidateAddress,
|
|
28
|
-
} from "@swapkit/toolbox-evm";
|
|
23
|
+
import { type TransferParams as EVMTransferParams, evmValidateAddress } from "@swapkit/toolbox-evm";
|
|
29
24
|
import { substrateValidateAddress } from "@swapkit/toolbox-substrate";
|
|
30
25
|
import { type UTXOTransferParams, utxoValidateAddress } from "@swapkit/toolbox-utxo";
|
|
31
26
|
|
|
@@ -55,29 +50,8 @@ export function SwapKit<
|
|
|
55
50
|
}) {
|
|
56
51
|
type PluginName = keyof Plugins;
|
|
57
52
|
|
|
58
|
-
/**
|
|
59
|
-
* @REMOVE (V1)
|
|
60
|
-
* Compatibility layer for plugins and wallets for easier migration and backwards compatibility
|
|
61
|
-
*/
|
|
62
|
-
const compatPlugins: Plugins = Array.isArray(plugins)
|
|
63
|
-
? plugins.reduce((acc, pluginInterface) => {
|
|
64
|
-
// @ts-ignore Ignore until we remove the compatibility layer
|
|
65
|
-
const { name, plugin } = Object.values(pluginInterface)?.[0] || {};
|
|
66
|
-
acc[name] = plugin;
|
|
67
|
-
return acc;
|
|
68
|
-
}, {})
|
|
69
|
-
: plugins;
|
|
70
|
-
const compatWallets: Wallets = Array.isArray(wallets)
|
|
71
|
-
? wallets.reduce((acc, wallet) => {
|
|
72
|
-
// @ts-ignore Ignore until we remove the compatibility layer
|
|
73
|
-
const [walletName, connectWallet] = Object.entries(wallet)?.[0] || {};
|
|
74
|
-
acc[walletName] = connectWallet;
|
|
75
|
-
return acc;
|
|
76
|
-
}, {})
|
|
77
|
-
: wallets;
|
|
78
|
-
|
|
79
53
|
const connectedWallets = {} as Wallet;
|
|
80
|
-
const availablePlugins = Object.entries(
|
|
54
|
+
const availablePlugins = Object.entries(plugins).reduce(
|
|
81
55
|
(acc, [pluginName, { plugin, config: pluginConfig }]) => {
|
|
82
56
|
const methods = plugin({
|
|
83
57
|
wallets: connectedWallets,
|
|
@@ -92,7 +66,7 @@ export function SwapKit<
|
|
|
92
66
|
{} as { [key in PluginName]: ReturnType<Plugins[key]["plugin"]> },
|
|
93
67
|
);
|
|
94
68
|
|
|
95
|
-
const connectWalletMethods = Object.entries(
|
|
69
|
+
const connectWalletMethods = Object.entries(wallets).reduce(
|
|
96
70
|
(acc, [walletName, wallet]) => {
|
|
97
71
|
const connectWallet = wallet({ addChain, config, apis, rpcUrls });
|
|
98
72
|
|
|
@@ -103,29 +77,23 @@ export function SwapKit<
|
|
|
103
77
|
{} as { [key in keyof Wallets]: ReturnType<Wallets[key]> },
|
|
104
78
|
);
|
|
105
79
|
|
|
106
|
-
/**
|
|
107
|
-
* @Private
|
|
108
|
-
*/
|
|
109
80
|
function getSwapKitPlugin<T extends PluginName>(pluginName: T) {
|
|
110
81
|
const plugin = availablePlugins[pluginName] || Object.values(availablePlugins)[0];
|
|
111
82
|
|
|
112
83
|
if (!plugin) {
|
|
113
|
-
throw new SwapKitError("core_plugin_not_found"
|
|
84
|
+
throw new SwapKitError("core_plugin_not_found");
|
|
114
85
|
}
|
|
115
86
|
|
|
116
87
|
return plugin;
|
|
117
88
|
}
|
|
118
89
|
|
|
119
|
-
/**
|
|
120
|
-
* @Private
|
|
121
|
-
*/
|
|
122
90
|
function getSwapKitPluginForSKProvider(pluginName: PluginNameEnum): Plugins[keyof Plugins] {
|
|
123
91
|
const plugin = Object.values(availablePlugins).find((plugin) =>
|
|
124
92
|
plugin.supportedSwapkitProviders?.includes(pluginName),
|
|
125
93
|
);
|
|
126
94
|
|
|
127
95
|
if (!plugin) {
|
|
128
|
-
throw new SwapKitError("core_plugin_not_found"
|
|
96
|
+
throw new SwapKitError("core_plugin_not_found");
|
|
129
97
|
}
|
|
130
98
|
|
|
131
99
|
return plugin;
|
|
@@ -156,33 +124,32 @@ export function SwapKit<
|
|
|
156
124
|
return plugin.approveAssetValue({ assetValue }) as ApproveReturnType<T>;
|
|
157
125
|
}
|
|
158
126
|
|
|
159
|
-
throw new SwapKitError(
|
|
160
|
-
"core_approve_asset_target_invalid",
|
|
161
|
-
`Target ${String(spenderAddress)} cannot be used for approve operation
|
|
162
|
-
);
|
|
127
|
+
throw new SwapKitError({
|
|
128
|
+
errorKey: "core_approve_asset_target_invalid",
|
|
129
|
+
info: { message: `Target ${String(spenderAddress)} cannot be used for approve operation` },
|
|
130
|
+
});
|
|
163
131
|
}
|
|
164
132
|
|
|
165
|
-
const
|
|
166
|
-
const isEVMChain = EVMChains.includes(chain
|
|
167
|
-
const isNativeEVM = isEVMChain && isGasAsset;
|
|
133
|
+
const chain = assetValue.chain as EVMChain;
|
|
134
|
+
const isEVMChain = EVMChains.includes(chain);
|
|
135
|
+
const isNativeEVM = isEVMChain && assetValue.isGasAsset;
|
|
168
136
|
|
|
169
|
-
if (isNativeEVM || !isEVMChain || isSynthetic) {
|
|
137
|
+
if (isNativeEVM || !isEVMChain || assetValue.isSynthetic) {
|
|
170
138
|
return Promise.resolve(type === "checkOnly" ? true : "approved") as ApproveReturnType<T>;
|
|
171
139
|
}
|
|
172
140
|
|
|
173
|
-
const
|
|
174
|
-
const walletAction = type === "checkOnly" ?
|
|
141
|
+
const wallet = getWallet(chain);
|
|
142
|
+
const walletAction = type === "checkOnly" ? wallet.isApproved : wallet.approve;
|
|
175
143
|
if (!walletAction) throw new SwapKitError("core_wallet_connection_not_found");
|
|
176
144
|
|
|
177
|
-
|
|
178
|
-
if (!(address && from && typeof spenderAddress === "string")) {
|
|
145
|
+
if (!(assetValue.address && wallet.address && typeof spenderAddress === "string")) {
|
|
179
146
|
throw new SwapKitError("core_approve_asset_address_or_from_not_found");
|
|
180
147
|
}
|
|
181
148
|
|
|
182
149
|
return walletAction({
|
|
183
150
|
amount: assetValue.getBaseValue("bigint"),
|
|
184
|
-
assetAddress: address,
|
|
185
|
-
from,
|
|
151
|
+
assetAddress: assetValue.address,
|
|
152
|
+
from: wallet.address,
|
|
186
153
|
spenderAddress,
|
|
187
154
|
}) as ApproveReturnType<T>;
|
|
188
155
|
}
|
|
@@ -193,13 +160,41 @@ export function SwapKit<
|
|
|
193
160
|
function getWallet<T extends Chain>(chain: T) {
|
|
194
161
|
return connectedWallets[chain];
|
|
195
162
|
}
|
|
163
|
+
|
|
196
164
|
function getAllWallets() {
|
|
197
165
|
return { ...connectedWallets };
|
|
198
166
|
}
|
|
167
|
+
|
|
199
168
|
function getAddress<T extends Chain>(chain: T) {
|
|
200
169
|
return getWallet(chain)?.address || "";
|
|
201
170
|
}
|
|
202
171
|
|
|
172
|
+
function approveAssetValue(assetValue: AssetValue, contractAddress: string | PluginName) {
|
|
173
|
+
return approve({ assetValue, contractAddress, type: ApproveMode.Approve });
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
function isAssetValueApproved(assetValue: AssetValue, contractAddress: string | PluginName) {
|
|
177
|
+
return approve({ assetValue, contractAddress, type: ApproveMode.CheckOnly });
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function disconnectChain<T extends Chain>(chain: T) {
|
|
181
|
+
const wallet = getWallet(chain);
|
|
182
|
+
wallet?.disconnect?.();
|
|
183
|
+
delete connectedWallets[chain];
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function disconnectAll() {
|
|
187
|
+
for (const chain of Object.keys(connectedWallets) as (keyof typeof connectedWallets)[]) {
|
|
188
|
+
disconnectChain(chain);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function getBalance<T extends Chain>(chain: T, refresh?: boolean) {
|
|
193
|
+
return refresh
|
|
194
|
+
? getWalletWithBalance(chain).then((wallet) => wallet.balance)
|
|
195
|
+
: getWallet(chain)?.balance || [];
|
|
196
|
+
}
|
|
197
|
+
|
|
203
198
|
function validateAddress({ address, chain }: { address: string; chain: Chain }) {
|
|
204
199
|
switch (chain) {
|
|
205
200
|
case Chain.Arbitrum:
|
|
@@ -207,39 +202,32 @@ export function SwapKit<
|
|
|
207
202
|
case Chain.Optimism:
|
|
208
203
|
case Chain.BinanceSmartChain:
|
|
209
204
|
case Chain.Polygon:
|
|
210
|
-
case Chain.Ethereum:
|
|
205
|
+
case Chain.Ethereum:
|
|
211
206
|
return evmValidateAddress({ address });
|
|
212
|
-
|
|
213
|
-
case Chain.Polkadot: {
|
|
214
|
-
return substrateValidateAddress({ address, chain });
|
|
215
|
-
}
|
|
207
|
+
|
|
216
208
|
case Chain.Litecoin:
|
|
217
209
|
case Chain.Dash:
|
|
218
210
|
case Chain.Dogecoin:
|
|
219
211
|
case Chain.BitcoinCash:
|
|
220
|
-
case Chain.Bitcoin:
|
|
212
|
+
case Chain.Bitcoin:
|
|
221
213
|
return utxoValidateAddress({ address, chain });
|
|
222
|
-
|
|
214
|
+
|
|
223
215
|
case Chain.Cosmos:
|
|
224
216
|
case Chain.Kujira:
|
|
225
217
|
case Chain.Maya:
|
|
226
|
-
case Chain.THORChain:
|
|
218
|
+
case Chain.THORChain:
|
|
227
219
|
return cosmosValidateAddress({ address, chain });
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
220
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
return getWalletWithBalance(chain).then((wallet) => wallet.balance);
|
|
236
|
-
}
|
|
221
|
+
case Chain.Polkadot:
|
|
222
|
+
return substrateValidateAddress({ address, chain });
|
|
237
223
|
|
|
238
|
-
|
|
224
|
+
default:
|
|
225
|
+
return false;
|
|
226
|
+
}
|
|
239
227
|
}
|
|
240
228
|
|
|
241
229
|
async function getWalletWithBalance<T extends Chain>(chain: T, potentialScamFilter = true) {
|
|
242
|
-
const defaultBalance = [AssetValue.
|
|
230
|
+
const defaultBalance = [AssetValue.from({ chain })];
|
|
243
231
|
const wallet = getWallet(chain);
|
|
244
232
|
|
|
245
233
|
if (!wallet) {
|
|
@@ -255,18 +243,11 @@ export function SwapKit<
|
|
|
255
243
|
return wallet;
|
|
256
244
|
}
|
|
257
245
|
|
|
258
|
-
function approveAssetValue(assetValue: AssetValue, contractAddress: string | PluginName) {
|
|
259
|
-
return approve({ assetValue, contractAddress, type: ApproveMode.Approve });
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
function isAssetValueApproved(assetValue: AssetValue, contractAddress: string | PluginName) {
|
|
263
|
-
return approve({ assetValue, contractAddress, type: ApproveMode.CheckOnly });
|
|
264
|
-
}
|
|
265
|
-
|
|
266
246
|
function swap<T extends PluginName>({ route, pluginName, ...rest }: SwapParams<T>) {
|
|
267
247
|
const plugin =
|
|
268
248
|
(pluginName && getSwapKitPlugin(pluginName)) ||
|
|
269
249
|
getSwapKitPluginForSKProvider(route.providers[0] as PluginNameEnum);
|
|
250
|
+
|
|
270
251
|
if (!plugin) throw new SwapKitError("core_swap_route_not_complete");
|
|
271
252
|
|
|
272
253
|
if ("swap" in plugin) {
|
|
@@ -283,33 +264,12 @@ export function SwapKit<
|
|
|
283
264
|
feeOptionKey,
|
|
284
265
|
}: UTXOTransferParams | EVMTransferParams | CosmosTransferParams) {
|
|
285
266
|
const chain = assetValue.chain as WalletChain;
|
|
286
|
-
const wallet =
|
|
267
|
+
const wallet = getWallet(chain);
|
|
287
268
|
if (!wallet) throw new SwapKitError("core_wallet_connection_not_found");
|
|
288
269
|
|
|
289
270
|
return wallet.transfer({ from, recipient, assetValue, feeOptionKey });
|
|
290
271
|
}
|
|
291
272
|
|
|
292
|
-
function disconnectAll() {
|
|
293
|
-
for (const chain of Object.keys(connectedWallets)) {
|
|
294
|
-
// @ts-expect-error: TODO
|
|
295
|
-
const wallet = connectedWallets[chain];
|
|
296
|
-
if ("disconnect" in wallet) {
|
|
297
|
-
wallet.disconnect();
|
|
298
|
-
}
|
|
299
|
-
// @ts-expect-error: TODO
|
|
300
|
-
delete connectedWallets[chain];
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
function disconnectChain(chain: Chain) {
|
|
305
|
-
const wallet = connectedWallets[chain];
|
|
306
|
-
const disconnect = wallet?.disconnect;
|
|
307
|
-
if (disconnect) {
|
|
308
|
-
disconnect();
|
|
309
|
-
}
|
|
310
|
-
delete connectedWallets[chain];
|
|
311
|
-
}
|
|
312
|
-
|
|
313
273
|
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO clean this up
|
|
314
274
|
async function estimateTransactionFee<T extends PluginName>({
|
|
315
275
|
type,
|
|
@@ -333,10 +293,11 @@ export function SwapKit<
|
|
|
333
293
|
feeOptionKey: FeeOption;
|
|
334
294
|
}): Promise<AssetValue | undefined> {
|
|
335
295
|
const { assetValue } = params;
|
|
336
|
-
const chain =
|
|
337
|
-
if (!connectedWallets[chain]) throw new SwapKitError("core_wallet_connection_not_found");
|
|
296
|
+
const { chain } = assetValue;
|
|
338
297
|
|
|
339
|
-
|
|
298
|
+
if (!getWallet(chain)) throw new SwapKitError("core_wallet_connection_not_found");
|
|
299
|
+
|
|
300
|
+
const baseValue = AssetValue.from({ chain });
|
|
340
301
|
|
|
341
302
|
switch (chain) {
|
|
342
303
|
case Chain.Arbitrum:
|
|
@@ -344,62 +305,58 @@ export function SwapKit<
|
|
|
344
305
|
case Chain.Ethereum:
|
|
345
306
|
case Chain.BinanceSmartChain:
|
|
346
307
|
case Chain.Polygon: {
|
|
347
|
-
const wallet =
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
308
|
+
const wallet = getWallet(chain);
|
|
309
|
+
if (type === "transfer") {
|
|
310
|
+
const txObject = await wallet.createTransferTx(params);
|
|
311
|
+
return wallet.estimateTransactionFee(txObject, feeOptionKey);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
if (type === "approve" && !isGasAsset(assetValue)) {
|
|
315
|
+
return wallet.estimateTransactionFee(
|
|
316
|
+
await wallet.createApprovalTx({
|
|
317
|
+
assetAddress: assetValue.address as string,
|
|
318
|
+
spenderAddress: params.contractAddress as string,
|
|
319
|
+
amount: assetValue.getBaseValue("bigint"),
|
|
320
|
+
from: wallet.address,
|
|
321
|
+
}),
|
|
322
|
+
feeOptionKey,
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (type === "swap") {
|
|
327
|
+
const plugin = params.route.providers[0] as PluginNameEnum;
|
|
328
|
+
if (plugin === PluginNameEnum.CHAINFLIP) {
|
|
329
|
+
const txObject = await wallet.createTransferTx({
|
|
330
|
+
from: wallet.address,
|
|
331
|
+
recipient: wallet.address,
|
|
332
|
+
assetValue,
|
|
333
|
+
});
|
|
351
334
|
return wallet.estimateTransactionFee(txObject, feeOptionKey);
|
|
352
335
|
}
|
|
353
336
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
from: wallet.address,
|
|
363
|
-
}),
|
|
364
|
-
feeOptionKey,
|
|
365
|
-
);
|
|
337
|
+
const { evmTransactionDetails } = params.route;
|
|
338
|
+
if (
|
|
339
|
+
!(
|
|
340
|
+
evmTransactionDetails &&
|
|
341
|
+
lowercasedContractAbiMapping[evmTransactionDetails.contractAddress]
|
|
342
|
+
)
|
|
343
|
+
) {
|
|
344
|
+
return undefined;
|
|
366
345
|
}
|
|
367
346
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
if (plugin === PluginNameEnum.CHAINFLIP) {
|
|
371
|
-
const txObject = await wallet.createTransferTx({
|
|
372
|
-
from: wallet.address,
|
|
373
|
-
recipient: wallet.address,
|
|
374
|
-
assetValue,
|
|
375
|
-
});
|
|
376
|
-
return wallet.estimateTransactionFee(txObject, feeOptionKey);
|
|
377
|
-
}
|
|
378
|
-
const { evmTransactionDetails } = params.route;
|
|
379
|
-
|
|
380
|
-
if (
|
|
381
|
-
!(
|
|
382
|
-
evmTransactionDetails &&
|
|
383
|
-
lowercasedContractAbiMapping[evmTransactionDetails.contractAddress]
|
|
384
|
-
)
|
|
385
|
-
) {
|
|
386
|
-
return undefined;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
const estimate = await wallet.estimateCall({
|
|
347
|
+
return wallet.estimateTransactionFee(
|
|
348
|
+
await wallet.createContractTxObject({
|
|
390
349
|
contractAddress: evmTransactionDetails.contractAddress,
|
|
391
350
|
// biome-ignore lint/style/noNonNullAssertion: TS cant infer the type
|
|
392
351
|
abi: lowercasedContractAbiMapping[evmTransactionDetails.contractAddress]!,
|
|
393
352
|
funcName: evmTransactionDetails.contractMethod,
|
|
394
353
|
funcParams: evmTransactionDetails.contractParams,
|
|
395
|
-
})
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
default:
|
|
401
|
-
return baseValue;
|
|
354
|
+
}),
|
|
355
|
+
feeOptionKey,
|
|
356
|
+
);
|
|
402
357
|
}
|
|
358
|
+
|
|
359
|
+
return AssetValue.from({ chain });
|
|
403
360
|
}
|
|
404
361
|
|
|
405
362
|
case Chain.Bitcoin:
|
|
@@ -407,7 +364,7 @@ export function SwapKit<
|
|
|
407
364
|
case Chain.Dogecoin:
|
|
408
365
|
case Chain.Dash:
|
|
409
366
|
case Chain.Litecoin: {
|
|
410
|
-
const { estimateMaxSendableAmount, address } =
|
|
367
|
+
const { estimateMaxSendableAmount, address } = getWallet(chain);
|
|
411
368
|
|
|
412
369
|
return estimateMaxSendableAmount({
|
|
413
370
|
...params,
|
|
@@ -425,8 +382,9 @@ export function SwapKit<
|
|
|
425
382
|
}
|
|
426
383
|
|
|
427
384
|
case Chain.Polkadot: {
|
|
428
|
-
const
|
|
429
|
-
|
|
385
|
+
const { address, estimateTransactionFee } = getWallet(chain);
|
|
386
|
+
|
|
387
|
+
return estimateTransactionFee({ ...params, recipient: address });
|
|
430
388
|
}
|
|
431
389
|
|
|
432
390
|
default:
|