@swapkit/toolboxes 1.0.0-beta.0

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.
Files changed (89) hide show
  1. package/dist/chunk-fazw0jvt.js +3 -0
  2. package/dist/chunk-fazw0jvt.js.map +9 -0
  3. package/dist/chunk-tvrdndbw.js +4 -0
  4. package/dist/chunk-tvrdndbw.js.map +9 -0
  5. package/dist/cosmos/index.cjs +3 -0
  6. package/dist/cosmos/index.cjs.map +19 -0
  7. package/dist/cosmos/index.js +3 -0
  8. package/dist/cosmos/index.js.map +19 -0
  9. package/dist/evm/index.cjs +3 -0
  10. package/dist/evm/index.cjs.map +24 -0
  11. package/dist/evm/index.js +3 -0
  12. package/dist/evm/index.js.map +24 -0
  13. package/dist/index.cjs +3 -0
  14. package/dist/index.cjs.map +9 -0
  15. package/dist/index.js +3 -0
  16. package/dist/index.js.map +9 -0
  17. package/dist/radix/index.cjs +3 -0
  18. package/dist/radix/index.cjs.map +10 -0
  19. package/dist/radix/index.js +3 -0
  20. package/dist/radix/index.js.map +10 -0
  21. package/dist/solana/index.cjs +3 -0
  22. package/dist/solana/index.cjs.map +10 -0
  23. package/dist/solana/index.js +3 -0
  24. package/dist/solana/index.js.map +10 -0
  25. package/dist/substrate/index.cjs +3 -0
  26. package/dist/substrate/index.cjs.map +12 -0
  27. package/dist/substrate/index.js +3 -0
  28. package/dist/substrate/index.js.map +12 -0
  29. package/dist/utxo/index.cjs +3 -0
  30. package/dist/utxo/index.cjs.map +18 -0
  31. package/dist/utxo/index.js +3 -0
  32. package/dist/utxo/index.js.map +18 -0
  33. package/package.json +105 -0
  34. package/src/cosmos/index.ts +11 -0
  35. package/src/cosmos/thorchainUtils/addressFormat.ts +24 -0
  36. package/src/cosmos/thorchainUtils/index.ts +4 -0
  37. package/src/cosmos/thorchainUtils/messages.ts +244 -0
  38. package/src/cosmos/thorchainUtils/registry.ts +47 -0
  39. package/src/cosmos/thorchainUtils/types/client-types.ts +80 -0
  40. package/src/cosmos/thorchainUtils/types/index.ts +1 -0
  41. package/src/cosmos/thorchainUtils/types/proto/MsgCompiled.js +2806 -0
  42. package/src/cosmos/thorchainUtils/types/proto/MsgCompiled.ts +2802 -0
  43. package/src/cosmos/thorchainUtils/util.ts +46 -0
  44. package/src/cosmos/toolbox/BaseCosmosToolbox.ts +254 -0
  45. package/src/cosmos/toolbox/gaia.ts +39 -0
  46. package/src/cosmos/toolbox/getToolboxByChain.ts +29 -0
  47. package/src/cosmos/toolbox/kujira.ts +61 -0
  48. package/src/cosmos/toolbox/thorchain.ts +321 -0
  49. package/src/cosmos/types.ts +31 -0
  50. package/src/cosmos/util.ts +230 -0
  51. package/src/evm/__tests__/ethereum.test.ts +147 -0
  52. package/src/evm/api.ts +157 -0
  53. package/src/evm/contracts/eth/multicall.ts +165 -0
  54. package/src/evm/contracts/op/gasOracle.ts +151 -0
  55. package/src/evm/helpers.ts +145 -0
  56. package/src/evm/index.ts +20 -0
  57. package/src/evm/provider.ts +6 -0
  58. package/src/evm/toolbox/EVMToolbox.ts +662 -0
  59. package/src/evm/toolbox/arb.ts +61 -0
  60. package/src/evm/toolbox/avax.ts +36 -0
  61. package/src/evm/toolbox/base.ts +42 -0
  62. package/src/evm/toolbox/bsc.ts +34 -0
  63. package/src/evm/toolbox/eth.ts +44 -0
  64. package/src/evm/toolbox/getToolboxByChain.ts +42 -0
  65. package/src/evm/toolbox/matic.ts +42 -0
  66. package/src/evm/toolbox/op.ts +163 -0
  67. package/src/evm/types.ts +118 -0
  68. package/src/index.ts +0 -0
  69. package/src/radix/index.ts +151 -0
  70. package/src/radix/toolbox.ts +693 -0
  71. package/src/solana/index.ts +49 -0
  72. package/src/solana/toolbox.ts +272 -0
  73. package/src/substrate/index.ts +3 -0
  74. package/src/substrate/toolbox/baseSubstrateToolbox.ts +286 -0
  75. package/src/substrate/toolbox/index.ts +40 -0
  76. package/src/substrate/types/index.ts +2 -0
  77. package/src/substrate/types/network.ts +42 -0
  78. package/src/substrate/types/wallet.ts +78 -0
  79. package/src/utxo/helpers/api.ts +431 -0
  80. package/src/utxo/helpers/bchaddrjs.ts +177 -0
  81. package/src/utxo/helpers/coinselect.ts +96 -0
  82. package/src/utxo/helpers/index.ts +5 -0
  83. package/src/utxo/helpers/txSize.ts +104 -0
  84. package/src/utxo/helpers/utils.ts +45 -0
  85. package/src/utxo/index.ts +9 -0
  86. package/src/utxo/toolbox/bitcoinCash.ts +281 -0
  87. package/src/utxo/toolbox/index.ts +37 -0
  88. package/src/utxo/toolbox/utxo.ts +360 -0
  89. package/src/utxo/types.ts +70 -0
@@ -0,0 +1,24 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/evm/api.ts", "../src/evm/helpers.ts", "../src/evm/provider.ts", "../src/evm/toolbox/EVMToolbox.ts", "../src/evm/types.ts", "../src/evm/toolbox/arb.ts", "../src/evm/toolbox/avax.ts", "../src/evm/toolbox/bsc.ts", "../src/evm/toolbox/eth.ts", "../src/evm/contracts/eth/multicall.ts", "../src/evm/toolbox/getToolboxByChain.ts", "../src/evm/toolbox/base.ts", "../src/evm/toolbox/matic.ts", "../src/evm/toolbox/op.ts", "../src/evm/contracts/op/gasOracle.ts"],
4
+ "sourcesContent": [
5
+ "import {\n Chain,\n ChainToChainId,\n type EVMChain,\n RequestClient,\n SKConfig,\n formatBigIntToSafeValue,\n warnOnce,\n} from \"@swapkit/helpers\";\n\nasync function getEthplorerBalance({ address }: { address: string }) {\n const apiKey = SKConfig.get(\"apiKeys\").ethplorer || \"freekey\";\n\n const { tokens = [] } = await RequestClient.get<AddressInfo>(\n `https://api.ethplorer.io/getAddressInfo/${address}`,\n { searchParams: { apiKey } },\n );\n\n return tokens\n .filter(({ tokenInfo: { symbol }, rawBalance }) => symbol && rawBalance !== \"0\")\n .map(({ tokenInfo: { symbol, decimals, address: tokenAddress }, rawBalance }) => ({\n chain: Chain.Ethereum,\n decimal: Number.parseInt(decimals),\n symbol: tokenAddress ? `${symbol}-${tokenAddress}` : symbol,\n value: formatBigIntToSafeValue({\n value: BigInt(rawBalance),\n decimal: Number.parseInt(decimals),\n bigIntDecimal: Number.parseInt(decimals),\n }),\n }));\n}\n\nasync function getCovalentBalance({ chain, address }: { chain: Chain; address: string }) {\n const apiKey = SKConfig.get(\"apiKeys\").covalent;\n\n if (!apiKey) {\n warnOnce(true, \"No covalent api key found. Use SKConfig.setApiKey('your-api-key')\");\n return [];\n }\n\n const { data } = await RequestClient.get<{ data: CovalentBalanceResponse }>(\n `https://api.covalenthq.com/v1/${ChainToChainId[chain]}/address/${address}/balances_v2/`,\n { searchParams: { key: apiKey } },\n );\n\n return (data?.items || [])\n .filter(({ is_spam }) => !is_spam)\n .map(\n ({ balance, contract_decimals, contract_ticker_symbol, contract_address, native_token }) => ({\n value: formatBigIntToSafeValue({\n value: BigInt(balance),\n decimal: contract_decimals,\n bigIntDecimal: contract_decimals,\n }),\n decimal: contract_decimals,\n chain,\n symbol: `${contract_ticker_symbol || \"Unknown\"}${native_token ? \"\" : `-${contract_address}`}`,\n }),\n );\n}\n\nexport function getEvmApi(chain: EVMChain) {\n const getBalance = chain === Chain.Ethereum ? getEthplorerBalance : getCovalentBalance;\n return { getBalance: (address: string) => getBalance({ address, chain }) };\n}\n\nexport function createCustomEvmApi(methods: ReturnType<typeof getEvmApi>) {\n return methods;\n}\n\ntype CovalentBalanceResponse = {\n address: string;\n updated_at: string;\n next_updated_at: string;\n quote_currency: string;\n items: {\n is_spam: boolean;\n contract_decimals: number;\n contract_name: string;\n contract_ticker_symbol: string;\n contract_address: string;\n logo_url: string;\n last_transferred_at: string;\n native_token: boolean;\n type: string;\n balance: number;\n balance_24h: number;\n quote_rate: number;\n quote_rate_24h: number;\n quote: number;\n quote_24h: number;\n }[];\n};\n\ntype PriceInfo = {\n rate: number;\n diff: number;\n diff7d?: number;\n ts: number;\n marketCapUsd?: number;\n availableSupply?: number;\n volume24h?: number;\n diff30d?: number;\n volDiff1?: number;\n volDiff7?: number;\n volDiff30?: number;\n currency?: string;\n};\n\ntype TokenInfo = {\n address: string;\n decimals: string;\n name: string;\n owner: string;\n symbol: string;\n totalSupply: string;\n lastUpdated: number;\n issuancesCount: number;\n holdersCount: number;\n image?: string;\n description?: string;\n website?: string;\n twitter?: string;\n facebook?: string;\n coingecko?: string;\n ethTransfersCount: number;\n price: boolean | PriceInfo | unknown;\n publicTags?: string[];\n txsCount?: number;\n transfersCount?: number;\n};\n\ntype TokenBalance = {\n tokenInfo: TokenInfo;\n balance: number;\n rawBalance: string;\n totalIn?: number;\n totalOut?: number;\n};\n\nexport type AddressInfo = {\n address: string;\n ETH: {\n balance: number;\n totalIn?: number;\n totalOut?: number;\n price: PriceInfo;\n };\n contractInfo?: {\n creatorAddress: string;\n transactionHash: string;\n timestamp: string;\n };\n tokenInfo?: TokenInfo;\n tokens?: TokenBalance[];\n countTxs: number;\n};\n",
6
+ "import {\n AssetValue,\n BaseDecimal,\n type EVMChain,\n FeeOption,\n SwapKitNumber,\n filterAssets,\n formatBigIntToSafeValue,\n isGasAsset,\n} from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Provider } from \"ethers\";\n\nimport { getEvmApi } from \"./api\";\nimport { type EIP1559TxParams, type EVMMaxSendableAmountsParams, estimateGasPrices } from \"./index\";\n\nexport const estimateMaxSendableAmount = async ({\n toolbox,\n from,\n memo = \"\",\n feeOptionKey = FeeOption.Fastest,\n assetValue,\n abi,\n funcName,\n funcParams,\n contractAddress,\n txOverrides,\n}: EVMMaxSendableAmountsParams): Promise<AssetValue> => {\n const balance = (await toolbox.getBalance(from)).find(({ symbol, chain }) =>\n assetValue ? symbol === assetValue.symbol : symbol === AssetValue.from({ chain })?.symbol,\n );\n\n const gasRate = (await toolbox.estimateGasPrices())[feeOptionKey];\n\n if (!balance) return AssetValue.from({ chain: assetValue.chain });\n\n if (assetValue && (balance.chain !== assetValue.chain || balance.symbol !== assetValue?.symbol)) {\n return balance;\n }\n\n const gasLimit =\n abi && funcName && funcParams && contractAddress\n ? await toolbox.estimateCall({\n contractAddress,\n abi,\n funcName,\n funcParams,\n txOverrides,\n })\n : await toolbox.estimateGasLimit({\n from,\n recipient: from,\n memo,\n assetValue,\n });\n\n const isFeeEIP1559Compatible = \"maxFeePerGas\" in gasRate;\n const isFeeEVMLegacyCompatible = \"gasPrice\" in gasRate;\n\n if (!(isFeeEVMLegacyCompatible || isFeeEIP1559Compatible)) {\n throw new Error(\"Could not fetch fee data\");\n }\n\n const fee =\n gasLimit *\n (isFeeEIP1559Compatible\n ? (gasRate.maxFeePerGas || 1n) + (gasRate.maxPriorityFeePerGas || 1n)\n : gasRate.gasPrice);\n const maxSendableAmount = SwapKitNumber.fromBigInt(balance.getBaseValue(\"bigint\")).sub(\n fee.toString(),\n );\n\n return AssetValue.from({ chain: balance.chain, value: maxSendableAmount.getValue(\"string\") });\n};\n\nexport const toHexString = (value: bigint) => (value > 0n ? `0x${value.toString(16)}` : \"0x0\");\n\nexport const getBalance = async ({\n provider,\n address,\n chain,\n potentialScamFilter,\n}: {\n provider: JsonRpcProvider | BrowserProvider;\n address: string;\n chain: EVMChain;\n potentialScamFilter?: boolean;\n}) => {\n const tokenBalances = await getEvmApi(chain).getBalance(address);\n const evmGasTokenBalance = await provider.getBalance(address);\n\n const balances = [\n {\n chain,\n symbol: AssetValue.from({ chain }).symbol,\n value: formatBigIntToSafeValue({\n value: BigInt(evmGasTokenBalance),\n decimal: 18,\n bigIntDecimal: 18,\n }),\n decimal: BaseDecimal[chain],\n },\n ...tokenBalances.filter((token) => !isGasAsset(token)),\n ];\n\n const filteredBalances = potentialScamFilter ? filterAssets(balances) : balances;\n\n return filteredBalances.map(\n ({ symbol, value, decimal }) =>\n new AssetValue({\n decimal: decimal || BaseDecimal[chain],\n value,\n identifier: `${chain}.${symbol}`,\n }),\n );\n};\n\nexport const estimateTransactionFee = async (\n txObject: EIP1559TxParams,\n // biome-ignore lint/style/useDefaultParameterLast: Should only be used through wrapped toolboxes\n feeOption: FeeOption = FeeOption.Fast,\n chain: EVMChain,\n provider: Provider | BrowserProvider,\n isEIP1559Compatible = true,\n) => {\n const gasPrices = (await estimateGasPrices(provider, isEIP1559Compatible))[feeOption];\n const gasLimit = await provider.estimateGas(txObject);\n const assetValue = AssetValue.from({ chain });\n\n if (!isEIP1559Compatible && gasPrices.gasPrice) {\n return assetValue.set(\n SwapKitNumber.fromBigInt(gasPrices.gasPrice * gasLimit, assetValue.decimal),\n );\n }\n\n if (gasPrices.maxFeePerGas && gasPrices.maxPriorityFeePerGas) {\n return assetValue.set(\n SwapKitNumber.fromBigInt(\n (gasPrices.maxFeePerGas + gasPrices.maxPriorityFeePerGas) * gasLimit,\n assetValue.decimal,\n ),\n );\n }\n\n throw new Error(\"No gas price found\");\n};\n",
7
+ "import { type EVMChain, SKConfig } from \"@swapkit/helpers\";\nimport { JsonRpcProvider } from \"ethers\";\n\nexport const getProvider = (chain: EVMChain, customUrl?: string) => {\n return new JsonRpcProvider(customUrl || SKConfig.get(\"rpcUrls\")[chain]);\n};\n",
8
+ "import {\n type Asset,\n type AssetValue,\n Chain,\n ContractAddress,\n type EVMChain,\n FeeOption,\n SwapKitError,\n SwapKitNumber,\n type WalletTxParams,\n isGasAsset,\n} from \"@swapkit/helpers\";\nimport { erc20ABI } from \"@swapkit/helpers/contracts\";\nimport {\n BrowserProvider,\n Contract,\n type ContractTransaction,\n type Fragment,\n type HDNodeWallet,\n Interface,\n type JsonFragment,\n type JsonRpcSigner,\n MaxInt256,\n type Provider,\n type Signer,\n getAddress,\n hexlify,\n toUtf8Bytes,\n} from \"ethers\";\n\nimport {\n type ARBToolbox,\n type AVAXToolbox,\n type BASEToolbox,\n type BSCToolbox,\n type ETHToolbox,\n type MATICToolbox,\n type OPToolbox,\n toHexString,\n} from \"../index\";\nimport type {\n ApproveParams,\n ApprovedParams,\n CallParams,\n EIP1559TxParams,\n EVMTxParams,\n EstimateCallParams,\n IsApprovedParams,\n LegacyEVMTxParams,\n TransferParams,\n} from \"../types\";\n\nexport const MAX_APPROVAL = MaxInt256;\n\nconst baseAssetAddress: Record<EVMChain, string> = {\n [Chain.Arbitrum]: ContractAddress.ARB,\n [Chain.Avalanche]: ContractAddress.AVAX,\n [Chain.Base]: ContractAddress.BASE,\n [Chain.BinanceSmartChain]: ContractAddress.BSC,\n [Chain.Ethereum]: ContractAddress.ETH,\n [Chain.Optimism]: ContractAddress.OP,\n [Chain.Polygon]: ContractAddress.MATIC,\n};\n\nconst stateMutable = [\"payable\", \"nonpayable\"];\n// const nonStateMutable = ['view', 'pure'];\n\nconst isEIP1559Transaction = (tx: EVMTxParams) =>\n (tx as EIP1559TxParams).type === 2 ||\n !!(tx as EIP1559TxParams).maxFeePerGas ||\n !!(tx as EIP1559TxParams).maxPriorityFeePerGas;\n\nexport const isBrowserProvider = (provider: any) => provider instanceof BrowserProvider;\nexport const createContract = (\n address: string,\n abi: readonly (JsonFragment | Fragment)[],\n provider: Provider,\n) => {\n return new Contract(address, Interface.from(abi), provider);\n};\n\nconst validateAddress = (address: string) => {\n try {\n getAddress(address);\n return true;\n } catch (_error) {\n return false;\n }\n};\n\nexport const isStateChangingCall = (abi: readonly JsonFragment[], functionName: string) => {\n const abiFragment = abi.find((fragment: any) => fragment.name === functionName) as any;\n if (!abiFragment) throw new SwapKitError(\"toolbox_evm_no_abi_fragment\", { functionName });\n return abiFragment.stateMutability && stateMutable.includes(abiFragment.stateMutability);\n};\n\nexport type WithSigner<T> = T & { signer?: Signer };\n\n/**\n * @info call contract function\n * When using this method to make a non state changing call to the blockchain, like a isApproved call,\n * the signer needs to be set to undefined\n */\nconst call = async <T>(\n provider: Provider,\n isEIP1559Compatible: boolean,\n {\n callProvider,\n signer,\n contractAddress,\n abi,\n funcName,\n funcParams = [],\n txOverrides = {},\n feeOption = FeeOption.Fast,\n }: WithSigner<CallParams>,\n): Promise<T> => {\n const contractProvider = callProvider || provider;\n if (!contractAddress) throw new Error(\"contractAddress must be provided\");\n\n const isStateChanging = isStateChangingCall(abi, funcName);\n const overridesParams = {\n ...txOverrides,\n from: txOverrides?.from || (await signer?.getAddress()),\n };\n\n if (isStateChanging && isBrowserProvider(contractProvider) && signer) {\n const txObject = await createContractTxObject(contractProvider, {\n contractAddress,\n abi,\n funcName,\n funcParams,\n txOverrides: overridesParams,\n });\n\n return EIP1193SendTransaction(contractProvider, txObject) as Promise<T>;\n }\n const contract = createContract(contractAddress, abi, contractProvider);\n\n // only use signer if the contract function is state changing\n if (isStateChanging) {\n if (!signer) throw new SwapKitError(\"toolbox_evm_no_signer\");\n\n const address = txOverrides?.from || (await signer.getAddress());\n\n if (!address) throw new SwapKitError(\"toolbox_evm_no_signer_address\");\n\n const connectedContract = contract.connect(signer);\n const { maxFeePerGas, maxPriorityFeePerGas, gasPrice } = (\n await estimateGasPrices(provider, isEIP1559Compatible)\n )[feeOption];\n\n const gasLimit = await contract.getFunction(funcName).estimateGas(...funcParams, txOverrides);\n\n // @ts-expect-error\n const result = await connectedContract[funcName](...funcParams, {\n ...txOverrides,\n gasLimit,\n maxFeePerGas,\n maxPriorityFeePerGas,\n gasPrice,\n /**\n * nonce must be set due to a possible bug with ethers.js,\n * expecting a synchronous nonce while the JsonRpcProvider delivers Promise\n */\n nonce: txOverrides?.nonce || (await contractProvider.getTransactionCount(address)),\n });\n\n return typeof result?.hash === \"string\" ? result?.hash : result;\n }\n\n const result = await contract[funcName]?.(...funcParams);\n\n return typeof result?.hash === \"string\" ? result?.hash : result;\n};\n\nexport const createContractTxObject = async (\n provider: Provider,\n { contractAddress, abi, funcName, funcParams = [], txOverrides }: CallParams,\n) =>\n createContract(contractAddress, abi, provider)\n .getFunction(funcName)\n .populateTransaction(...funcParams.concat(txOverrides).filter((p) => typeof p !== \"undefined\"));\n\nconst approvedAmount = async (\n provider: Provider,\n { assetAddress, spenderAddress, from }: IsApprovedParams,\n) =>\n await call<bigint>(provider, true, {\n contractAddress: assetAddress,\n abi: erc20ABI as any,\n funcName: \"allowance\",\n funcParams: [from, spenderAddress],\n });\n\nconst isApproved = async (\n provider: Provider,\n { assetAddress, spenderAddress, from, amount = MAX_APPROVAL }: IsApprovedParams,\n) => {\n return SwapKitNumber.fromBigInt(\n await approvedAmount(provider, { assetAddress, spenderAddress, from }),\n ).gte(SwapKitNumber.fromBigInt(BigInt(amount)));\n};\n\nconst approve = async (\n provider: Provider,\n {\n assetAddress,\n spenderAddress,\n feeOptionKey = FeeOption.Fast,\n amount,\n gasLimitFallback,\n from,\n nonce,\n }: ApproveParams,\n signer?: Signer,\n isEIP1559Compatible = true,\n) => {\n const funcParams = [spenderAddress, BigInt(amount || MAX_APPROVAL)];\n const txOverrides = { from };\n\n const functionCallParams = {\n contractAddress: assetAddress,\n abi: erc20ABI,\n funcName: \"approve\",\n funcParams,\n signer,\n txOverrides,\n };\n\n if (isBrowserProvider(provider)) {\n return EIP1193SendTransaction(\n provider,\n await createContractTxObject(provider, functionCallParams),\n );\n }\n\n return call<string>(provider, isEIP1559Compatible, {\n ...functionCallParams,\n funcParams,\n txOverrides: {\n from,\n nonce,\n gasLimit: gasLimitFallback ? BigInt(gasLimitFallback.toString()) : undefined,\n },\n feeOption: feeOptionKey,\n });\n};\n\nconst transfer = async (\n provider: Provider | BrowserProvider,\n {\n assetValue,\n memo,\n recipient,\n feeOptionKey = FeeOption.Fast,\n data,\n from: fromOverride,\n maxFeePerGas,\n maxPriorityFeePerGas,\n gasPrice,\n ...tx\n }: TransferParams,\n signer?: Signer,\n isEIP1559Compatible = true,\n) => {\n const txAmount = assetValue.getBaseValue(\"bigint\");\n const chain = assetValue.chain as EVMChain;\n\n const from = fromOverride || (await signer?.getAddress());\n\n if (!from) throw new SwapKitError(\"toolbox_evm_no_from_address\");\n\n if (!assetValue.isGasAsset) {\n const contractAddress = getTokenAddress(assetValue, chain);\n if (!contractAddress) throw new SwapKitError(\"toolbox_evm_no_contract_address\");\n\n // Transfer ERC20\n return call<string>(provider, isEIP1559Compatible, {\n signer,\n contractAddress,\n abi: erc20ABI,\n funcName: \"transfer\",\n funcParams: [recipient, txAmount],\n txOverrides: { from, maxFeePerGas, maxPriorityFeePerGas, gasPrice },\n feeOption: feeOptionKey,\n });\n }\n // Transfer ETH\n const txObject = {\n ...tx,\n from,\n to: recipient,\n value: txAmount,\n data: data || hexlify(toUtf8Bytes(memo || \"\")),\n };\n\n return sendTransaction(provider, txObject, feeOptionKey, signer, isEIP1559Compatible);\n};\n\nexport const estimateGasPrices = async (provider: Provider, isEIP1559Compatible = true) => {\n try {\n const { maxFeePerGas, maxPriorityFeePerGas, gasPrice } = await provider.getFeeData();\n\n if (isEIP1559Compatible) {\n if (maxFeePerGas === null || maxPriorityFeePerGas === null)\n throw new SwapKitError(\"toolbox_evm_no_fee_data\");\n\n return {\n [FeeOption.Average]: { maxFeePerGas, maxPriorityFeePerGas },\n [FeeOption.Fast]: {\n maxFeePerGas: (maxFeePerGas * 15n) / 10n,\n maxPriorityFeePerGas: (maxPriorityFeePerGas * 15n) / 10n,\n },\n [FeeOption.Fastest]: {\n maxFeePerGas: maxFeePerGas * 2n,\n maxPriorityFeePerGas: maxPriorityFeePerGas * 2n,\n },\n };\n }\n if (!gasPrice) throw new SwapKitError(\"toolbox_evm_no_gas_price\");\n\n return {\n [FeeOption.Average]: { gasPrice },\n [FeeOption.Fast]: { gasPrice: (gasPrice * 15n) / 10n },\n [FeeOption.Fastest]: { gasPrice: gasPrice * 2n },\n };\n } catch (error) {\n throw new Error(\n `Failed to estimate gas price: ${(error as any).msg ?? (error as any).toString()}`,\n );\n }\n};\n\nconst estimateCall = (\n provider: Provider,\n {\n signer,\n contractAddress,\n abi,\n funcName,\n funcParams = [],\n txOverrides,\n }: WithSigner<EstimateCallParams>,\n) => {\n if (!contractAddress) throw new SwapKitError(\"toolbox_evm_no_contract_address\");\n\n const contract = createContract(contractAddress, abi, provider);\n return signer\n ? contract\n .connect(signer)\n .getFunction(funcName)\n .estimateGas(...funcParams, txOverrides)\n : contract.getFunction(funcName).estimateGas(...funcParams, txOverrides);\n};\n\nconst estimateGasLimit = (\n provider: Provider,\n {\n assetValue,\n recipient,\n memo,\n from,\n funcName,\n funcParams,\n txOverrides,\n signer,\n }: WalletTxParams & {\n assetValue: AssetValue;\n funcName?: string;\n funcParams?: unknown[];\n signer?: Signer;\n txOverrides?: EVMTxParams;\n },\n) => {\n // const value = assetValue.getBaseValue(\"bigint\");\n const value = assetValue.bigIntValue;\n\n const assetAddress = assetValue.isGasAsset\n ? null\n : getTokenAddress(assetValue, assetValue.chain as EVMChain);\n\n if (assetAddress && funcName) {\n // ERC20 gas estimate\n return estimateCall(provider, {\n contractAddress: assetAddress,\n abi: erc20ABI,\n funcName,\n funcParams,\n txOverrides,\n signer,\n });\n }\n\n return provider.estimateGas({\n from,\n to: recipient,\n value,\n data: memo ? hexlify(toUtf8Bytes(memo)) : undefined,\n });\n};\n\nconst sendTransaction = async (\n provider: Provider | BrowserProvider,\n tx: EVMTxParams,\n feeOptionKey: FeeOption = FeeOption.Fast,\n signer?: Signer,\n isEIP1559Compatible = true,\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: refactor\n) => {\n if (!signer) throw new SwapKitError(\"toolbox_evm_no_signer\");\n const { from, to, data, value, ...transaction } = tx;\n if (!to) throw new SwapKitError(\"toolbox_evm_no_to_address\");\n\n const parsedTxObject = {\n ...transaction,\n data: data || \"0x\",\n to,\n from,\n value: BigInt(value || 0),\n };\n\n // early return to skip gas estimation if provider is EIP-1193\n if (isBrowserProvider(provider)) {\n return EIP1193SendTransaction(provider, parsedTxObject);\n }\n\n const address = from || (await signer.getAddress());\n const nonce = tx.nonce || (await provider.getTransactionCount(address));\n const chainId = (await provider.getNetwork()).chainId;\n\n const isEIP1559 = isEIP1559Transaction(parsedTxObject) || isEIP1559Compatible;\n\n const feeData =\n (isEIP1559 &&\n !(\n (parsedTxObject as EIP1559TxParams).maxFeePerGas &&\n (parsedTxObject as EIP1559TxParams).maxPriorityFeePerGas\n )) ||\n !(parsedTxObject as LegacyEVMTxParams).gasPrice\n ? Object.entries(\n (await estimateGasPrices(provider, isEIP1559Compatible))[feeOptionKey],\n ).reduce(\n // biome-ignore lint/performance/noAccumulatingSpread: this is a small object\n (acc, [k, v]) => ({ ...acc, [k]: toHexString(BigInt(v)) }),\n {} as {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n gasPrice?: string;\n },\n )\n : {};\n let gasLimit: string;\n try {\n gasLimit = toHexString(\n parsedTxObject.gasLimit || ((await provider.estimateGas(parsedTxObject)) * 11n) / 10n,\n );\n } catch (error) {\n throw new SwapKitError(\"toolbox_evm_error_estimating_gas_limit\", { error });\n }\n\n try {\n const txObject = {\n ...parsedTxObject,\n chainId,\n type: isEIP1559 ? 2 : 0,\n gasLimit,\n nonce,\n ...feeData,\n };\n\n try {\n const response = await signer.sendTransaction(txObject);\n return response.hash;\n } catch (_error) {\n const txHex = await signer.signTransaction({\n ...txObject,\n from: address,\n });\n const response = await provider.broadcastTransaction(txHex);\n return response.hash;\n }\n } catch (error) {\n throw new SwapKitError(\"toolbox_evm_error_sending_transaction\", { error });\n }\n};\n\n/**\n * Exported helper functions\n */\nexport const toChecksumAddress = (address: string) => getAddress(address);\n\nexport const EIP1193SendTransaction = (\n provider: Provider | BrowserProvider,\n { from, to, data, value }: EVMTxParams | ContractTransaction,\n): Promise<string> => {\n if (!isBrowserProvider(provider))\n throw new SwapKitError(\"toolbox_evm_provider_not_eip1193_compatible\");\n return (provider as BrowserProvider).send(\"eth_sendTransaction\", [\n { value: toHexString(BigInt(value || 0)), from, to, data } as any,\n ]);\n};\n\nexport const getChecksumAddressFromAsset = (asset: Asset, chain: EVMChain) => {\n const assetAddress = getTokenAddress(asset, chain);\n\n if (assetAddress) {\n return getAddress(assetAddress.toLowerCase());\n }\n\n throw new SwapKitError(\"toolbox_evm_invalid_gas_asset_address\");\n};\n\nexport const getTokenAddress = ({ chain, symbol, ticker }: Asset, baseAssetChain: EVMChain) => {\n try {\n const isBSCBNB = chain === Chain.BinanceSmartChain && symbol === \"BNB\" && ticker === \"BNB\";\n const isBaseAsset =\n chain === baseAssetChain && symbol === baseAssetChain && ticker === baseAssetChain;\n const isEVMAsset =\n [Chain.Arbitrum, Chain.Base].includes(chain) && symbol === \"ETH\" && ticker === \"ETH\";\n\n if (isBaseAsset || isBSCBNB || isEVMAsset) {\n return baseAssetAddress[baseAssetChain];\n }\n\n // strip 0X only - 0x is still valid\n return getAddress(symbol.slice(ticker.length + 1).replace(/^0X/, \"\"));\n } catch (_error) {\n return null;\n }\n};\n\nconst createTransferTx = async (\n provider: Provider | BrowserProvider,\n {\n assetValue,\n memo,\n recipient,\n feeOptionKey = FeeOption.Fast,\n data,\n from: fromOverride,\n maxFeePerGas,\n maxPriorityFeePerGas,\n gasPrice,\n ...tx\n }: TransferParams,\n signer?: Signer,\n) => {\n const txAmount = assetValue.getBaseValue(\"bigint\");\n const chain = assetValue.chain as EVMChain;\n\n const from = fromOverride || (await signer?.getAddress());\n\n if (!from) throw new SwapKitError(\"toolbox_evm_no_from_address\");\n\n if (!isGasAsset(assetValue)) {\n const contractAddress = getTokenAddress(assetValue, chain);\n if (!contractAddress) throw new SwapKitError(\"toolbox_evm_no_contract_address\");\n\n // Transfer ERC20\n return createContractTxObject(provider, {\n contractAddress,\n abi: erc20ABI,\n funcName: \"transfer\",\n funcParams: [recipient, txAmount],\n txOverrides: { from, maxFeePerGas, maxPriorityFeePerGas, gasPrice },\n });\n }\n // Transfer ETH\n const txObject = {\n ...tx,\n from,\n to: recipient,\n value: txAmount,\n data: data || hexlify(toUtf8Bytes(memo || \"\")),\n };\n\n return txObject;\n};\n\nconst createApprovalTx = async (\n provider: Provider,\n { assetAddress, spenderAddress, amount, from }: ApproveParams,\n signer?: Signer,\n) => {\n const funcParams = [spenderAddress, BigInt(amount || MAX_APPROVAL)];\n const txOverrides = { from };\n\n const functionCallParams = {\n contractAddress: assetAddress,\n abi: erc20ABI,\n funcName: \"approve\",\n funcParams,\n signer,\n txOverrides,\n };\n\n const txObject = await createContractTxObject(provider, functionCallParams);\n\n return txObject;\n};\n\nfunction signMessage(signer?: Signer | JsonRpcSigner | HDNodeWallet) {\n if (!signer) throw new SwapKitError(\"toolbox_evm_no_signer\");\n\n return signer.signMessage;\n}\n\nexport const EVMToolbox = ({\n provider,\n signer,\n isEIP1559Compatible = true,\n}: {\n signer?: Signer | JsonRpcSigner | HDNodeWallet;\n provider: Provider | BrowserProvider;\n isEIP1559Compatible?: boolean;\n}) => ({\n approve: (params: ApproveParams) => approve(provider, params, signer, isEIP1559Compatible),\n approvedAmount: (params: ApprovedParams) => approvedAmount(provider, params),\n broadcastTransaction: provider.broadcastTransaction,\n call: <T>(params: CallParams) => call<T>(provider, isEIP1559Compatible, { ...params, signer }),\n createContract: (\n address: string,\n abi: (JsonFragment | Fragment)[],\n contractProvider?: Provider,\n ) => createContract(address, abi, contractProvider || provider),\n createContractTxObject: (params: CallParams) => createContractTxObject(provider, params),\n EIP1193SendTransaction: (tx: EIP1559TxParams) => EIP1193SendTransaction(provider, tx),\n estimateCall: (params: EstimateCallParams) => estimateCall(provider, { ...params, signer }),\n estimateGasLimit: ({\n assetValue,\n recipient,\n memo,\n }: WalletTxParams & { assetValue: AssetValue }) =>\n estimateGasLimit(provider, { assetValue, recipient, memo, signer }),\n estimateGasPrices: () => estimateGasPrices(provider, isEIP1559Compatible),\n isApproved: (params: IsApprovedParams) => isApproved(provider, params),\n sendTransaction: (params: EIP1559TxParams, feeOption?: FeeOption) =>\n sendTransaction(provider, params, feeOption, signer, isEIP1559Compatible),\n transfer: (params: TransferParams) => transfer(provider, params, signer, isEIP1559Compatible),\n validateAddress,\n createTransferTx: (params: TransferParams) => createTransferTx(provider, params, signer),\n createApprovalTx: (params: ApproveParams) => createApprovalTx(provider, params, signer),\n signMessage: signMessage(signer),\n});\n\nexport const evmValidateAddress = ({ address }: { address: string }) => validateAddress(address);\n\nexport type EVMWallet = ReturnType<typeof EVMToolbox>;\nexport type EVMWalletType = {\n [Chain.Arbitrum]: ReturnType<typeof ARBToolbox>;\n [Chain.Avalanche]: ReturnType<typeof AVAXToolbox>;\n [Chain.Base]: ReturnType<typeof BASEToolbox>;\n [Chain.BinanceSmartChain]: ReturnType<typeof BSCToolbox>;\n [Chain.Ethereum]: ReturnType<typeof ETHToolbox>;\n [Chain.Optimism]: ReturnType<typeof OPToolbox>;\n [Chain.Polygon]: ReturnType<typeof MATICToolbox>;\n};\n\nexport type EVMWallets = {\n [chain in EVMChain]: EVMWallet & EVMWalletType[chain];\n};\n",
9
+ "import type { AssetValue, FeeOption, WalletTxParams } from \"@swapkit/helpers\";\nimport type { BigNumberish, JsonFragment, Transaction } from \"ethers\";\n\nimport type {\n ARBToolbox,\n AVAXToolbox,\n BASEToolbox,\n BSCToolbox,\n ETHToolbox,\n MATICToolbox,\n OPToolbox,\n} from \"./index\";\nimport type { getProvider } from \"./provider\";\n\nexport enum EthNetwork {\n Test = \"goerli\",\n Main = \"homestead\",\n}\n\nexport type ApproveParams = {\n assetAddress: string;\n spenderAddress: string;\n feeOptionKey?: FeeOption;\n amount?: BigNumberish;\n from: string;\n // Optional fallback in case estimation for gas limit fails\n gasLimitFallback?: BigNumberish;\n nonce?: number;\n};\n\nexport type ApprovedParams = {\n assetAddress: string;\n spenderAddress: string;\n from: string;\n};\n\nexport type IsApprovedParams = ApprovedParams & {\n amount?: BigNumberish;\n};\n\nexport type CallParams = {\n callProvider?: ReturnType<typeof getProvider>;\n contractAddress: string;\n abi: readonly JsonFragment[];\n funcName: string;\n funcParams?: unknown[];\n txOverrides?: Partial<Transaction>;\n feeOption?: FeeOption;\n};\n\nexport type EstimateCallParams = Pick<\n CallParams,\n \"contractAddress\" | \"abi\" | \"funcName\" | \"funcParams\" | \"txOverrides\"\n>;\n\nexport type TransferParams = WalletTxParams & {\n gasLimit?: bigint;\n gasPrice?: bigint;\n maxFeePerGas?: bigint;\n maxPriorityFeePerGas?: bigint;\n data?: string;\n from: string;\n nonce?: number;\n assetValue: AssetValue;\n};\n\nexport type EVMToolboxType = ReturnType<\n | typeof ARBToolbox\n | typeof AVAXToolbox\n | typeof BASEToolbox\n | typeof BSCToolbox\n | typeof ETHToolbox\n | typeof MATICToolbox\n | typeof OPToolbox\n>;\n\nexport type EVMMaxSendableAmountsParams = {\n from: string;\n toolbox: EVMToolboxType;\n assetValue: AssetValue;\n feeOptionKey?: FeeOption;\n memo?: string;\n abi?: readonly JsonFragment[];\n funcName?: string;\n contractAddress?: string;\n funcParams?: unknown[];\n txOverrides?: Partial<Transaction>;\n};\n\nexport type EVMTxBaseParams<T = bigint> = {\n to?: string;\n from?: string;\n nonce?: number;\n gasLimit?: T;\n data?: string;\n value?: T;\n chainId?: T;\n};\n\nexport type EIP1559TxParams<T = bigint> = EVMTxBaseParams<T> & {\n type?: number;\n maxFeePerGas?: T;\n maxPriorityFeePerGas?: T;\n};\n\nexport type LegacyEVMTxParams<T = bigint> = EVMTxBaseParams<T> & {\n gasPrice?: T;\n};\n\nexport type EVMTxParams = EIP1559TxParams | LegacyEVMTxParams;\n\nexport type NonETHToolbox =\n | ReturnType<typeof ARBToolbox>\n | ReturnType<typeof AVAXToolbox>\n | ReturnType<typeof BSCToolbox>\n | ReturnType<typeof MATICToolbox>\n | ReturnType<typeof OPToolbox>\n | ReturnType<typeof BASEToolbox>;\n",
10
+ "import {\n BaseDecimal,\n Chain,\n ChainId,\n ChainToExplorerUrl,\n FeeOption,\n SKConfig,\n} from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Provider, Signer } from \"ethers\";\n\nimport { type EVMTxBaseParams, estimateTransactionFee, getBalance } from \"../index\";\n\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nconst getNetworkParams = () => ({\n chainId: ChainId.ArbitrumHex,\n chainName: \"Arbitrum One\",\n nativeCurrency: { name: \"Ethereum\", symbol: Chain.Ethereum, decimals: BaseDecimal.ETH },\n rpcUrls: [SKConfig.get(\"rpcUrls\")[Chain.Arbitrum]],\n blockExplorerUrls: [ChainToExplorerUrl[Chain.Arbitrum]],\n});\n\nconst estimateGasPrices = async (provider: Provider) => {\n try {\n const { gasPrice } = await provider.getFeeData();\n\n if (!gasPrice) throw new Error(\"No fee data available\");\n\n return {\n [FeeOption.Average]: { gasPrice },\n [FeeOption.Fast]: { gasPrice },\n [FeeOption.Fastest]: { gasPrice },\n };\n } catch (error) {\n throw new Error(\n `Failed to estimate gas price: ${(error as any).msg ?? (error as any).toString()}`,\n );\n }\n};\n\nexport const ARBToolbox = ({\n provider,\n signer,\n}: { signer?: Signer; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer, isEIP1559Compatible: false });\n const chain = Chain.Arbitrum;\n\n return {\n ...evmToolbox,\n getNetworkParams,\n estimateGasPrices: () => estimateGasPrices(provider),\n estimateTransactionFee: (txObject: EVMTxBaseParams) =>\n estimateTransactionFee(txObject, FeeOption.Average, chain, provider, false),\n getBalance: (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({ provider: overwriteProvider || provider, address, chain, potentialScamFilter }),\n };\n};\n",
11
+ "import { BaseDecimal, Chain, ChainId, ChainToExplorerUrl, type FeeOption } from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Signer } from \"ethers\";\n\nimport { type EVMTxBaseParams, estimateTransactionFee, getBalance } from \"../index\";\n\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nconst getNetworkParams = () => ({\n chainId: ChainId.AvalancheHex,\n chainName: \"Avalanche Network\",\n nativeCurrency: { name: \"Avalanche\", symbol: Chain.Avalanche, decimals: BaseDecimal.AVAX },\n // Use external rpc URL so wallets don't throw warning to user\n rpcUrls: [\"https://api.avax.network/ext/bc/C/rpc\"],\n blockExplorerUrls: [ChainToExplorerUrl[Chain.Avalanche]],\n});\n\nexport const AVAXToolbox = ({\n provider,\n signer,\n}: { signer?: Signer; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer });\n const chain = Chain.Avalanche;\n\n return {\n ...evmToolbox,\n getNetworkParams,\n estimateTransactionFee: (txObject: EVMTxBaseParams, feeOptionKey: FeeOption) =>\n estimateTransactionFee(txObject, feeOptionKey, chain, provider),\n getBalance: (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({ provider: overwriteProvider || provider, address, chain, potentialScamFilter }),\n };\n};\n",
12
+ "import { BaseDecimal, Chain, ChainId, ChainToExplorerUrl, type FeeOption } from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Signer } from \"ethers\";\n\nimport { type EVMTxBaseParams, estimateTransactionFee, getBalance } from \"../index\";\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nconst getNetworkParams = () => ({\n chainId: ChainId.BinanceSmartChainHex,\n chainName: \"BNB Chain\",\n nativeCurrency: { name: \"Binance Coin\", symbol: \"BNB\", decimals: BaseDecimal.BSC },\n rpcUrls: [\"https://bsc-dataseed.binance.org\"],\n blockExplorerUrls: [ChainToExplorerUrl[Chain.BinanceSmartChain]],\n});\n\nexport const BSCToolbox = ({\n provider,\n signer,\n}: { signer?: Signer; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer, isEIP1559Compatible: false });\n const chain = Chain.BinanceSmartChain;\n\n return {\n ...evmToolbox,\n getNetworkParams,\n estimateTransactionFee: (txObject: EVMTxBaseParams, feeOptionKey: FeeOption) =>\n estimateTransactionFee(txObject, feeOptionKey, chain, provider, false),\n getBalance: (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({ provider: overwriteProvider || provider, address, chain, potentialScamFilter }),\n };\n};\n",
13
+ "import { Chain, FeeOption } from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, JsonRpcSigner, Signer } from \"ethers\";\n\nimport { type EVMTxBaseParams, estimateTransactionFee, getBalance } from \"../index\";\n\nimport { multicallAbi } from \"../contracts/eth/multicall\";\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nexport const ETHToolbox = ({\n signer,\n provider,\n}: { signer?: Signer | JsonRpcSigner; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer });\n const chain = Chain.Ethereum;\n\n async function multicall(\n callTuples: { address: string; data: string }[],\n multicallAddress = \"0x5ba1e12693dc8f9c48aad8770482f4739beed696\",\n funcName = \"aggregate\",\n feeOptionKey: FeeOption = FeeOption.Fast,\n ) {\n const txObject = await evmToolbox.createContractTxObject({\n contractAddress: multicallAddress,\n abi: multicallAbi,\n funcName,\n funcParams: [callTuples],\n });\n\n return evmToolbox.sendTransaction(txObject, feeOptionKey);\n }\n\n return {\n ...evmToolbox,\n multicall,\n estimateTransactionFee: (txObject: EVMTxBaseParams, feeOptionKey?: FeeOption) =>\n estimateTransactionFee(txObject, feeOptionKey, chain, provider),\n getBalance: (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({ provider: overwriteProvider || provider, address, chain, potentialScamFilter }),\n };\n};\n",
14
+ "export const multicallAbi = [\n {\n inputs: [\n {\n components: [\n { internalType: \"address\", name: \"target\", type: \"address\" },\n { internalType: \"bytes\", name: \"callData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Call[]\",\n name: \"calls\",\n type: \"tuple[]\",\n },\n ],\n name: \"aggregate\",\n outputs: [\n { internalType: \"uint256\", name: \"blockNumber\", type: \"uint256\" },\n { internalType: \"bytes[]\", name: \"returnData\", type: \"bytes[]\" },\n ],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [\n {\n components: [\n { internalType: \"address\", name: \"target\", type: \"address\" },\n { internalType: \"bytes\", name: \"callData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Call[]\",\n name: \"calls\",\n type: \"tuple[]\",\n },\n ],\n name: \"blockAndAggregate\",\n outputs: [\n { internalType: \"uint256\", name: \"blockNumber\", type: \"uint256\" },\n { internalType: \"bytes32\", name: \"blockHash\", type: \"bytes32\" },\n {\n components: [\n { internalType: \"bool\", name: \"success\", type: \"bool\" },\n { internalType: \"bytes\", name: \"returnData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Result[]\",\n name: \"returnData\",\n type: \"tuple[]\",\n },\n ],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"blockNumber\", type: \"uint256\" }],\n name: \"getBlockHash\",\n outputs: [{ internalType: \"bytes32\", name: \"blockHash\", type: \"bytes32\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"getBlockNumber\",\n outputs: [{ internalType: \"uint256\", name: \"blockNumber\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"getCurrentBlockCoinbase\",\n outputs: [{ internalType: \"address\", name: \"coinbase\", type: \"address\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"getCurrentBlockDifficulty\",\n outputs: [{ internalType: \"uint256\", name: \"difficulty\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"getCurrentBlockGasLimit\",\n outputs: [{ internalType: \"uint256\", name: \"gaslimit\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"getCurrentBlockTimestamp\",\n outputs: [{ internalType: \"uint256\", name: \"timestamp\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"address\", name: \"addr\", type: \"address\" }],\n name: \"getEthBalance\",\n outputs: [{ internalType: \"uint256\", name: \"balance\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"getLastBlockHash\",\n outputs: [{ internalType: \"bytes32\", name: \"blockHash\", type: \"bytes32\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [\n { internalType: \"bool\", name: \"requireSuccess\", type: \"bool\" },\n {\n components: [\n { internalType: \"address\", name: \"target\", type: \"address\" },\n { internalType: \"bytes\", name: \"callData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Call[]\",\n name: \"calls\",\n type: \"tuple[]\",\n },\n ],\n name: \"tryAggregate\",\n outputs: [\n {\n components: [\n { internalType: \"bool\", name: \"success\", type: \"bool\" },\n { internalType: \"bytes\", name: \"returnData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Result[]\",\n name: \"returnData\",\n type: \"tuple[]\",\n },\n ],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [\n { internalType: \"bool\", name: \"requireSuccess\", type: \"bool\" },\n {\n components: [\n { internalType: \"address\", name: \"target\", type: \"address\" },\n { internalType: \"bytes\", name: \"callData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Call[]\",\n name: \"calls\",\n type: \"tuple[]\",\n },\n ],\n name: \"tryBlockAndAggregate\",\n outputs: [\n { internalType: \"uint256\", name: \"blockNumber\", type: \"uint256\" },\n { internalType: \"bytes32\", name: \"blockHash\", type: \"bytes32\" },\n {\n components: [\n { internalType: \"bool\", name: \"success\", type: \"bool\" },\n { internalType: \"bytes\", name: \"returnData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Result[]\",\n name: \"returnData\",\n type: \"tuple[]\",\n },\n ],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n];\n",
15
+ "import { Chain } from \"@swapkit/helpers\";\n\nimport { ARBToolbox } from \"./arb\";\nimport { AVAXToolbox } from \"./avax\";\nimport { BASEToolbox } from \"./base\";\nimport { BSCToolbox } from \"./bsc\";\nimport { ETHToolbox } from \"./eth\";\nimport { MATICToolbox } from \"./matic\";\nimport { OPToolbox } from \"./op\";\n\ntype ToolboxType = {\n ARB: typeof ARBToolbox;\n AVAX: typeof AVAXToolbox;\n BASE: typeof BASEToolbox;\n BSC: typeof BSCToolbox;\n ETH: typeof ETHToolbox;\n MATIC: typeof MATICToolbox;\n OP: typeof OPToolbox;\n};\n\nexport const getToolboxByChain = <T extends keyof ToolboxType>(chain: T): ToolboxType[T] => {\n switch (chain) {\n case Chain.Avalanche:\n return AVAXToolbox as ToolboxType[T];\n case Chain.Arbitrum:\n return ARBToolbox as ToolboxType[T];\n case Chain.Base:\n return BASEToolbox as ToolboxType[T];\n case Chain.Optimism:\n return OPToolbox as ToolboxType[T];\n case Chain.Polygon:\n return MATICToolbox as ToolboxType[T];\n case Chain.BinanceSmartChain:\n return BSCToolbox as ToolboxType[T];\n case Chain.Ethereum:\n return ETHToolbox as ToolboxType[T];\n default:\n throw new Error(`Chain ${chain} is not supported`);\n }\n};\n\nexport { evmValidateAddress } from \"./EVMToolbox\";\n",
16
+ "import {\n BaseDecimal,\n Chain,\n ChainId,\n ChainToExplorerUrl,\n type FeeOption,\n SKConfig,\n} from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Signer } from \"ethers\";\n\nimport { type EVMTxBaseParams, estimateTransactionFee, getBalance } from \"../index\";\n\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nconst getNetworkParams = () => ({\n chainId: ChainId.BaseHex,\n chainName: \"Base Mainnet\",\n nativeCurrency: { name: \"Ethereum\", symbol: Chain.Ethereum, decimals: BaseDecimal.ETH },\n rpcUrls: [SKConfig.get(\"rpcUrls\")[Chain.Base]],\n blockExplorerUrls: [ChainToExplorerUrl[Chain.Base]],\n});\n\nexport const BASEToolbox = ({\n provider,\n signer,\n}: { signer?: Signer; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer });\n const chain = Chain.Base;\n\n return {\n ...evmToolbox,\n getNetworkParams,\n estimateTransactionFee: (txObject: EVMTxBaseParams, feeOptionKey: FeeOption) =>\n estimateTransactionFee(txObject, feeOptionKey, chain, provider),\n getBalance: async (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({ provider: overwriteProvider || provider, address, chain, potentialScamFilter }),\n };\n};\n",
17
+ "import {\n BaseDecimal,\n Chain,\n ChainId,\n ChainToExplorerUrl,\n type FeeOption,\n SKConfig,\n} from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Signer } from \"ethers\";\n\nimport { type EVMTxBaseParams, estimateTransactionFee, getBalance } from \"../index\";\n\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nconst getNetworkParams = () => ({\n chainId: ChainId.PolygonHex,\n chainName: \"Polygon Mainnet\",\n nativeCurrency: { name: \"Polygon\", symbol: Chain.Polygon, decimals: BaseDecimal.MATIC },\n rpcUrls: [SKConfig.get(\"rpcUrls\")[Chain.Polygon]],\n blockExplorerUrls: [ChainToExplorerUrl[Chain.Polygon]],\n});\n\nexport const MATICToolbox = ({\n provider,\n signer,\n}: { signer?: Signer; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer });\n const chain = Chain.Polygon;\n\n return {\n ...evmToolbox,\n getNetworkParams,\n estimateTransactionFee: (txObject: EVMTxBaseParams, feeOptionKey: FeeOption) =>\n estimateTransactionFee(txObject, feeOptionKey, chain, provider),\n getBalance: (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({ provider: overwriteProvider || provider, address, chain, potentialScamFilter }),\n };\n};\n",
18
+ "import {\n BaseDecimal,\n Chain,\n ChainId,\n ChainToExplorerUrl,\n FeeOption,\n SKConfig,\n} from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Signer, TransactionRequest } from \"ethers\";\nimport { Contract, Transaction } from \"ethers\";\n\nimport { gasOracleAbi } from \"../contracts/op/gasOracle\";\nimport { getBalance } from \"../index\";\n\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nconst GAS_PRICE_ORACLE_ADDRESS = \"0x420000000000000000000000000000000000000f\";\n\nexport const connectGasPriceOracle = (provider: JsonRpcProvider | BrowserProvider) => {\n return new Contract(GAS_PRICE_ORACLE_ADDRESS, gasOracleAbi, provider);\n};\n\nexport const getL1GasPrice = (provider: JsonRpcProvider | BrowserProvider) => {\n const gasPriceOracle = connectGasPriceOracle(provider);\n\n if (gasPriceOracle && \"l1BaseFee\" in gasPriceOracle) {\n return gasPriceOracle?.l1BaseFee() as unknown as bigint;\n }\n\n return undefined;\n};\n\nconst _serializeTx = async (\n provider: JsonRpcProvider | BrowserProvider,\n { data, from, to, gasPrice, type, gasLimit, nonce }: TransactionRequest,\n) => {\n if (!to) throw new Error(\"Missing to address\");\n\n return Transaction.from({\n data,\n to: to as string,\n gasPrice,\n type,\n gasLimit,\n nonce: nonce ? nonce : from ? await provider.getTransactionCount(from) : 0,\n }).serialized;\n};\n\nexport const estimateL1GasCost = async (\n provider: JsonRpcProvider | BrowserProvider,\n tx: TransactionRequest,\n) => {\n const gasPriceOracle = await connectGasPriceOracle(provider);\n const serializedTx = await _serializeTx(provider, tx);\n\n if (gasPriceOracle && \"getL1Fee\" in gasPriceOracle) {\n return gasPriceOracle.getL1Fee(serializedTx);\n }\n};\n\nexport const estimateL2GasCost = async (\n provider: JsonRpcProvider | BrowserProvider,\n tx: TransactionRequest,\n) => {\n const l2GasPrice = await provider.send(\"eth_gasPrice\", []);\n const l2GasCost = await provider.estimateGas(tx);\n return l2GasPrice.mul(l2GasCost);\n};\n\nexport const estimateTotalGasCost = async (\n provider: JsonRpcProvider | BrowserProvider,\n tx: TransactionRequest,\n) => {\n const l1GasCost = await estimateL1GasCost(provider, tx);\n const l2GasCost = await estimateL2GasCost(provider, tx);\n return l1GasCost.add(l2GasCost);\n};\n\nexport const estimateL1Gas = async (\n provider: JsonRpcProvider | BrowserProvider,\n tx: TransactionRequest,\n) => {\n const gasPriceOracle = connectGasPriceOracle(provider);\n const serializedTx = await _serializeTx(provider, tx);\n\n if (gasPriceOracle && \"getL1GasUsed\" in gasPriceOracle) {\n return gasPriceOracle.getL1GasUsed(serializedTx);\n }\n};\n\nconst getNetworkParams = () => ({\n chainId: ChainId.OptimismHex,\n chainName: \"Optimism\",\n nativeCurrency: { name: \"Ethereum\", symbol: Chain.Ethereum, decimals: BaseDecimal.ETH },\n rpcUrls: [SKConfig.get(\"rpcUrls\")[Chain.Optimism]],\n blockExplorerUrls: [ChainToExplorerUrl[Chain.Optimism]],\n});\n\nconst estimateGasPrices = async (provider: JsonRpcProvider | BrowserProvider) => {\n try {\n const { maxFeePerGas, maxPriorityFeePerGas, gasPrice } = await provider.getFeeData();\n const l1GasPrice = await getL1GasPrice(provider);\n const price = gasPrice as bigint;\n\n if (!(maxFeePerGas && maxPriorityFeePerGas)) {\n throw new Error(\"No fee data available\");\n }\n\n return {\n [FeeOption.Average]: {\n l1GasPrice,\n gasPrice,\n maxFeePerGas,\n maxPriorityFeePerGas,\n },\n [FeeOption.Fast]: {\n l1GasPrice: ((l1GasPrice || 0n) * 15n) / 10n,\n gasPrice: (price * 15n) / 10n,\n maxFeePerGas,\n maxPriorityFeePerGas: (maxPriorityFeePerGas * 15n) / 10n,\n },\n [FeeOption.Fastest]: {\n l1GasPrice: (l1GasPrice || 0n) * 2n,\n gasPrice: price * 2n,\n maxFeePerGas,\n maxPriorityFeePerGas: maxPriorityFeePerGas * 2n,\n },\n };\n } catch (error) {\n throw new Error(\n `Failed to estimate gas price: ${(error as any).msg ?? (error as any).toString()}`,\n );\n }\n};\n\nexport const OPToolbox = ({\n provider,\n signer,\n}: { signer?: Signer; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer });\n\n return {\n ...evmToolbox,\n estimateTotalGasCost: (tx: TransactionRequest) => estimateTotalGasCost(provider, tx),\n estimateL1GasCost: (tx: TransactionRequest) => estimateL1GasCost(provider, tx),\n estimateL2GasCost: (tx: TransactionRequest) => estimateL2GasCost(provider, tx),\n getL1GasPrice: () => getL1GasPrice(provider),\n estimateL1Gas: (tx: TransactionRequest) => estimateL1Gas(provider, tx),\n getNetworkParams,\n estimateGasPrices: () => estimateGasPrices(provider),\n getBalance: (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({\n provider: overwriteProvider || provider,\n address,\n chain: Chain.Optimism,\n potentialScamFilter,\n }),\n };\n};\n",
19
+ "export const gasOracleAbi = [\n {\n inputs: [{ internalType: \"address\", name: \"_owner\", type: \"address\" }],\n stateMutability: \"nonpayable\",\n type: \"constructor\",\n },\n {\n anonymous: false,\n inputs: [{ indexed: false, internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n name: \"DecimalsUpdated\",\n type: \"event\",\n },\n {\n anonymous: false,\n inputs: [{ indexed: false, internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n name: \"GasPriceUpdated\",\n type: \"event\",\n },\n {\n anonymous: false,\n inputs: [{ indexed: false, internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n name: \"L1BaseFeeUpdated\",\n type: \"event\",\n },\n {\n anonymous: false,\n inputs: [{ indexed: false, internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n name: \"OverheadUpdated\",\n type: \"event\",\n },\n {\n anonymous: false,\n inputs: [\n { indexed: true, internalType: \"address\", name: \"previousOwner\", type: \"address\" },\n { indexed: true, internalType: \"address\", name: \"newOwner\", type: \"address\" },\n ],\n name: \"OwnershipTransferred\",\n type: \"event\",\n },\n {\n anonymous: false,\n inputs: [{ indexed: false, internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n name: \"ScalarUpdated\",\n type: \"event\",\n },\n {\n inputs: [],\n name: \"decimals\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"gasPrice\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"bytes\", name: \"_data\", type: \"bytes\" }],\n name: \"getL1Fee\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"bytes\", name: \"_data\", type: \"bytes\" }],\n name: \"getL1GasUsed\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"l1BaseFee\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"overhead\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"owner\",\n outputs: [{ internalType: \"address\", name: \"\", type: \"address\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"renounceOwnership\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"scalar\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"_decimals\", type: \"uint256\" }],\n name: \"setDecimals\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"_gasPrice\", type: \"uint256\" }],\n name: \"setGasPrice\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"_baseFee\", type: \"uint256\" }],\n name: \"setL1BaseFee\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"_overhead\", type: \"uint256\" }],\n name: \"setOverhead\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"_scalar\", type: \"uint256\" }],\n name: \"setScalar\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"address\", name: \"newOwner\", type: \"address\" }],\n name: \"transferOwnership\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n];\n"
20
+ ],
21
+ "mappings": "4yBAQO,IARP,8BAUA,eAAe,EAAmB,EAAG,WAAgC,CACnE,IAAM,EAAS,WAAS,IAAI,SAAS,EAAE,WAAa,WAE5C,SAAS,CAAC,GAAM,MAAM,gBAAc,IAC1C,2CAA2C,IAC3C,CAAE,aAAc,CAAE,QAAO,CAAE,CAC7B,EAEA,OAAO,EACJ,OAAO,EAAG,WAAa,UAAU,gBAAiB,GAAU,IAAe,GAAG,EAC9E,IAAI,EAAG,WAAa,SAAQ,WAAU,QAAS,GAAgB,iBAAkB,CAChF,MAAO,QAAM,SACb,QAAS,OAAO,SAAS,CAAQ,EACjC,OAAQ,EAAe,GAAG,KAAU,IAAiB,EACrD,MAAO,0BAAwB,CAC7B,MAAO,OAAO,CAAU,EACxB,QAAS,OAAO,SAAS,CAAQ,EACjC,cAAe,OAAO,SAAS,CAAQ,CACzC,CAAC,CACH,EAAE,EAGN,eAAe,EAAkB,EAAG,QAAO,WAA8C,CACvF,IAAM,EAAS,WAAS,IAAI,SAAS,EAAE,SAEvC,IAAK,EAEH,OADA,WAAS,GAAM,mEAAmE,EAC3E,CAAC,EAGV,IAAQ,QAAS,MAAM,gBAAc,IACnC,iCAAiC,iBAAe,cAAkB,iBAClE,CAAE,aAAc,CAAE,IAAK,CAAO,CAAE,CAClC,EAEA,OAAQ,GAAM,OAAS,CAAC,GACrB,OAAO,EAAG,cAAe,CAAO,EAChC,IACC,EAAG,UAAS,oBAAmB,yBAAwB,mBAAkB,mBAAoB,CAC3F,MAAO,0BAAwB,CAC7B,MAAO,OAAO,CAAO,EACrB,QAAS,EACT,cAAe,CACjB,CAAC,EACD,QAAS,EACT,QACA,OAAQ,GAAG,GAA0B,YAAY,EAAe,GAAK,IA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AU,CACnB,aACA,WACA,eACA,sBACF,GACC,YAAU,MAAO,CAChB,YAAc,GAAc,IAAM,IAAO,IACzC,SAAW,EAAQ,IAAO,IAC1B,eACA,qBAAuB,EAAuB,IAAO,GACvD,GACC,YAAU,SAAU,CACnB,YAAa,GAAc,IAAM,GACjC,SAAU,EAAQ,GAClB,eACA,qBAAsB,EAAuB,EAC/C,CACF,QACO,EAAP,CACA,MAAM,IAAI,MACR,iCAAkC,EAAc,KAAQ,EAAc,SAAS,GACjF,IAIS,GAAY,EACvB,WACA,YACsE,CAGtE,MAAO,IAFY,EAAW,CAAE,WAAU,QAAO,CAAC,EAIhD,qBAAsB,CAAC,IAA2B,GAAqB,EAAU,CAAE,EACnF,kBAAmB,CAAC,IAA2B,GAAkB,EAAU,CAAE,EAC7E,kBAAmB,CAAC,IAA2B,GAAkB,EAAU,CAAE,EAC7E,cAAe,IAAM,GAAc,CAAQ,EAC3C,cAAe,CAAC,IAA2B,GAAc,EAAU,CAAE,EACrE,oBACA,kBAAmB,IAAM,GAAkB,CAAQ,EACnD,WAAY,CACV,EACA,EAAsB,GACtB,IAEA,EAAW,CACT,SAAU,GAAqB,EAC/B,UACA,MAAO,QAAM,SACb,qBACF,CAAC,CACL,GH7IK,IAAM,GAAoB,CAA8B,IAA6B,CAC1F,OAAQ,QACD,QAAM,UACT,OAAO,OACJ,QAAM,SACT,OAAO,OACJ,QAAM,KACT,OAAO,OACJ,QAAM,SACT,OAAO,QACJ,QAAM,QACT,OAAO,QACJ,QAAM,kBACT,OAAO,OACJ,QAAM,SACT,OAAO,UAEP,MAAM,IAAI,MAAM,SAAS,oBAAwB",
22
+ "debugId": "544EFBA69A459C0464756E2164756E21",
23
+ "names": []
24
+ }
@@ -0,0 +1,3 @@
1
+ import"../chunk-tvrdndbw.js";import{Chain as d,ChainToChainId as Dt,RequestClient as tt,SKConfig as nt,formatBigIntToSafeValue as et,warnOnce as kt}from"@swapkit/helpers";async function qt({address:t}){let e=nt.get("apiKeys").ethplorer||"freekey",{tokens:o=[]}=await tt.get(`https://api.ethplorer.io/getAddressInfo/${t}`,{searchParams:{apiKey:e}});return o.filter(({tokenInfo:{symbol:n},rawBalance:y})=>n&&y!=="0").map(({tokenInfo:{symbol:n,decimals:y,address:u},rawBalance:l})=>({chain:d.Ethereum,decimal:Number.parseInt(y),symbol:u?`${n}-${u}`:n,value:et({value:BigInt(l),decimal:Number.parseInt(y),bigIntDecimal:Number.parseInt(y)})}))}async function Ht({chain:t,address:e}){let o=nt.get("apiKeys").covalent;if(!o)return kt(!0,"No covalent api key found. Use SKConfig.setApiKey('your-api-key')"),[];let{data:n}=await tt.get(`https://api.covalenthq.com/v1/${Dt[t]}/address/${e}/balances_v2/`,{searchParams:{key:o}});return(n?.items||[]).filter(({is_spam:y})=>!y).map(({balance:y,contract_decimals:u,contract_ticker_symbol:l,contract_address:a,native_token:i})=>({value:et({value:BigInt(y),decimal:u,bigIntDecimal:u}),decimal:u,chain:t,symbol:`${l||"Unknown"}${i?"":`-${a}`}`}))}function ot(t){let e=t===d.Ethereum?qt:Ht;return{getBalance:(o)=>e({address:o,chain:t})}}function Qn(t){return t}import{AssetValue as q,BaseDecimal as yt,FeeOption as ut,SwapKitNumber as P,filterAssets as xt,formatBigIntToSafeValue as $t,isGasAsset as Ct}from"@swapkit/helpers";var Fn=async({toolbox:t,from:e,memo:o="",feeOptionKey:n=ut.Fastest,assetValue:y,abi:u,funcName:l,funcParams:a,contractAddress:i,txOverrides:T})=>{let p=(await t.getBalance(e)).find(({symbol:b,chain:U})=>y?b===y.symbol:b===q.from({chain:U})?.symbol),m=(await t.estimateGasPrices())[n];if(!p)return q.from({chain:y.chain});if(y&&(p.chain!==y.chain||p.symbol!==y?.symbol))return p;let B=u&&l&&a&&i?await t.estimateCall({contractAddress:i,abi:u,funcName:l,funcParams:a,txOverrides:T}):await t.estimateGasLimit({from:e,recipient:e,memo:o,assetValue:y}),g="maxFeePerGas"in m;if(!(("gasPrice"in m)||g))throw new Error("Could not fetch fee data");let w=B*(g?(m.maxFeePerGas||1n)+(m.maxPriorityFeePerGas||1n):m.gasPrice),R=P.fromBigInt(p.getBaseValue("bigint")).sub(w.toString());return q.from({chain:p.chain,value:R.getValue("string")})},G=(t)=>t>0n?`0x${t.toString(16)}`:"0x0",r=async({provider:t,address:e,chain:o,potentialScamFilter:n})=>{let y=await ot(o).getBalance(e),u=await t.getBalance(e),l=[{chain:o,symbol:q.from({chain:o}).symbol,value:$t({value:BigInt(u),decimal:18,bigIntDecimal:18}),decimal:yt[o]},...y.filter((i)=>!Ct(i))];return(n?xt(l):l).map(({symbol:i,value:T,decimal:p})=>new q({decimal:p||yt[o],value:T,identifier:`${o}.${i}`}))},f=async(t,e=ut.Fast,o,n,y=!0)=>{let u=(await $(n,y))[e],l=await n.estimateGas(t),a=q.from({chain:o});if(!y&&u.gasPrice)return a.set(P.fromBigInt(u.gasPrice*l,a.decimal));if(u.maxFeePerGas&&u.maxPriorityFeePerGas)return a.set(P.fromBigInt((u.maxFeePerGas+u.maxPriorityFeePerGas)*l,a.decimal));throw new Error("No gas price found")};import{SKConfig as Gt}from"@swapkit/helpers";import{JsonRpcProvider as St}from"ethers";var Nn=(t,e)=>{return new St(e||Gt.get("rpcUrls")[t])};import{Chain as J,ContractAddress as D,FeeOption as h,SwapKitError as c,SwapKitNumber as lt,isGasAsset as zt}from"@swapkit/helpers";import{erc20ABI as H}from"@swapkit/helpers/contracts";import{BrowserProvider as Et,Contract as Lt,Interface as Qt,MaxInt256 as Wt,getAddress as S,hexlify as N,toUtf8Bytes as j}from"ethers";var K=Wt,Yt={[J.Arbitrum]:D.ARB,[J.Avalanche]:D.AVAX,[J.Base]:D.BASE,[J.BinanceSmartChain]:D.BSC,[J.Ethereum]:D.ETH,[J.Optimism]:D.OP,[J.Polygon]:D.MATIC},Zt=["payable","nonpayable"],Xt=(t)=>t.type===2||!!t.maxFeePerGas||!!t.maxPriorityFeePerGas,z=(t)=>t instanceof Et,E=(t,e,o)=>{return new Lt(t,Qt.from(e),o)},at=(t)=>{try{return S(t),!0}catch(e){return!1}},Ft=(t,e)=>{let o=t.find((n)=>n.name===e);if(!o)throw new c("toolbox_evm_no_abi_fragment",{functionName:e});return o.stateMutability&&Zt.includes(o.stateMutability)},L=async(t,e,{callProvider:o,signer:n,contractAddress:y,abi:u,funcName:l,funcParams:a=[],txOverrides:i={},feeOption:T=h.Fast})=>{let p=o||t;if(!y)throw new Error("contractAddress must be provided");let m=Ft(u,l),B={...i,from:i?.from||await n?.getAddress()};if(m&&z(p)&&n){let w=await C(p,{contractAddress:y,abi:u,funcName:l,funcParams:a,txOverrides:B});return Q(p,w)}let g=E(y,u,p);if(m){if(!n)throw new c("toolbox_evm_no_signer");let w=i?.from||await n.getAddress();if(!w)throw new c("toolbox_evm_no_signer_address");let R=g.connect(n),{maxFeePerGas:b,maxPriorityFeePerGas:U,gasPrice:x}=(await $(t,e))[T],v=await g.getFunction(l).estimateGas(...a,i),_=await R[l](...a,{...i,gasLimit:v,maxFeePerGas:b,maxPriorityFeePerGas:U,gasPrice:x,nonce:i?.nonce||await p.getTransactionCount(w)});return typeof _?.hash==="string"?_?.hash:_}let M=await g[l]?.(...a);return typeof M?.hash==="string"?M?.hash:M},C=async(t,{contractAddress:e,abi:o,funcName:n,funcParams:y=[],txOverrides:u})=>E(e,o,t).getFunction(n).populateTransaction(...y.concat(u).filter((l)=>typeof l!=="undefined")),pt=async(t,{assetAddress:e,spenderAddress:o,from:n})=>await L(t,!0,{contractAddress:e,abi:H,funcName:"allowance",funcParams:[n,o]}),It=async(t,{assetAddress:e,spenderAddress:o,from:n,amount:y=K})=>{return lt.fromBigInt(await pt(t,{assetAddress:e,spenderAddress:o,from:n})).gte(lt.fromBigInt(BigInt(y)))},_t=async(t,{assetAddress:e,spenderAddress:o,feeOptionKey:n=h.Fast,amount:y,gasLimitFallback:u,from:l,nonce:a},i,T=!0)=>{let p=[o,BigInt(y||K)],B={contractAddress:e,abi:H,funcName:"approve",funcParams:p,signer:i,txOverrides:{from:l}};if(z(t))return Q(t,await C(t,B));return L(t,T,{...B,funcParams:p,txOverrides:{from:l,nonce:a,gasLimit:u?BigInt(u.toString()):void 0},feeOption:n})},Pt=async(t,{assetValue:e,memo:o,recipient:n,feeOptionKey:y=h.Fast,data:u,from:l,maxFeePerGas:a,maxPriorityFeePerGas:i,gasPrice:T,...p},m,B=!0)=>{let g=e.getBaseValue("bigint"),M=e.chain,w=l||await m?.getAddress();if(!w)throw new c("toolbox_evm_no_from_address");if(!e.isGasAsset){let b=W(e,M);if(!b)throw new c("toolbox_evm_no_contract_address");return L(t,B,{signer:m,contractAddress:b,abi:H,funcName:"transfer",funcParams:[n,g],txOverrides:{from:w,maxFeePerGas:a,maxPriorityFeePerGas:i,gasPrice:T},feeOption:y})}let R={...p,from:w,to:n,value:g,data:u||N(j(o||""))};return Tt(t,R,y,m,B)},$=async(t,e=!0)=>{try{let{maxFeePerGas:o,maxPriorityFeePerGas:n,gasPrice:y}=await t.getFeeData();if(e){if(o===null||n===null)throw new c("toolbox_evm_no_fee_data");return{[h.Average]:{maxFeePerGas:o,maxPriorityFeePerGas:n},[h.Fast]:{maxFeePerGas:o*15n/10n,maxPriorityFeePerGas:n*15n/10n},[h.Fastest]:{maxFeePerGas:o*2n,maxPriorityFeePerGas:n*2n}}}if(!y)throw new c("toolbox_evm_no_gas_price");return{[h.Average]:{gasPrice:y},[h.Fast]:{gasPrice:y*15n/10n},[h.Fastest]:{gasPrice:y*2n}}}catch(o){throw new Error(`Failed to estimate gas price: ${o.msg??o.toString()}`)}},it=(t,{signer:e,contractAddress:o,abi:n,funcName:y,funcParams:u=[],txOverrides:l})=>{if(!o)throw new c("toolbox_evm_no_contract_address");let a=E(o,n,t);return e?a.connect(e).getFunction(y).estimateGas(...u,l):a.getFunction(y).estimateGas(...u,l)},Nt=(t,{assetValue:e,recipient:o,memo:n,from:y,funcName:u,funcParams:l,txOverrides:a,signer:i})=>{let T=e.bigIntValue,p=e.isGasAsset?null:W(e,e.chain);if(p&&u)return it(t,{contractAddress:p,abi:H,funcName:u,funcParams:l,txOverrides:a,signer:i});return t.estimateGas({from:y,to:o,value:T,data:n?N(j(n)):void 0})},Tt=async(t,e,o=h.Fast,n,y=!0)=>{if(!n)throw new c("toolbox_evm_no_signer");let{from:u,to:l,data:a,value:i,...T}=e;if(!l)throw new c("toolbox_evm_no_to_address");let p={...T,data:a||"0x",to:l,from:u,value:BigInt(i||0)};if(z(t))return Q(t,p);let m=u||await n.getAddress(),B=e.nonce||await t.getTransactionCount(m),g=(await t.getNetwork()).chainId,M=Xt(p)||y,w=M&&!(p.maxFeePerGas&&p.maxPriorityFeePerGas)||!p.gasPrice?Object.entries((await $(t,y))[o]).reduce((b,[U,x])=>({...b,[U]:G(BigInt(x))}),{}):{},R;try{R=G(p.gasLimit||await t.estimateGas(p)*11n/10n)}catch(b){throw new c("toolbox_evm_error_estimating_gas_limit",{error:b})}try{let b={...p,chainId:g,type:M?2:0,gasLimit:R,nonce:B,...w};try{return(await n.sendTransaction(b)).hash}catch(U){let x=await n.signTransaction({...b,from:m});return(await t.broadcastTransaction(x)).hash}}catch(b){throw new c("toolbox_evm_error_sending_transaction",{error:b})}},vn=(t)=>S(t),Q=(t,{from:e,to:o,data:n,value:y})=>{if(!z(t))throw new c("toolbox_evm_provider_not_eip1193_compatible");return t.send("eth_sendTransaction",[{value:G(BigInt(y||0)),from:e,to:o,data:n}])},dn=(t,e)=>{let o=W(t,e);if(o)return S(o.toLowerCase());throw new c("toolbox_evm_invalid_gas_asset_address")},W=({chain:t,symbol:e,ticker:o},n)=>{try{let y=t===J.BinanceSmartChain&&e==="BNB"&&o==="BNB",u=t===n&&e===n&&o===n,l=[J.Arbitrum,J.Base].includes(t)&&e==="ETH"&&o==="ETH";if(u||y||l)return Yt[n];return S(e.slice(o.length+1).replace(/^0X/,""))}catch(y){return null}},jt=async(t,{assetValue:e,memo:o,recipient:n,feeOptionKey:y=h.Fast,data:u,from:l,maxFeePerGas:a,maxPriorityFeePerGas:i,gasPrice:T,...p},m)=>{let B=e.getBaseValue("bigint"),g=e.chain,M=l||await m?.getAddress();if(!M)throw new c("toolbox_evm_no_from_address");if(!zt(e)){let R=W(e,g);if(!R)throw new c("toolbox_evm_no_contract_address");return C(t,{contractAddress:R,abi:H,funcName:"transfer",funcParams:[n,B],txOverrides:{from:M,maxFeePerGas:a,maxPriorityFeePerGas:i,gasPrice:T}})}return{...p,from:M,to:n,value:B,data:u||N(j(o||""))}},Kt=async(t,{assetAddress:e,spenderAddress:o,amount:n,from:y},u)=>{let l=[o,BigInt(n||K)];return await C(t,{contractAddress:e,abi:H,funcName:"approve",funcParams:l,signer:u,txOverrides:{from:y}})};function Vt(t){if(!t)throw new c("toolbox_evm_no_signer");return t.signMessage}var s=({provider:t,signer:e,isEIP1559Compatible:o=!0})=>({approve:(n)=>_t(t,n,e,o),approvedAmount:(n)=>pt(t,n),broadcastTransaction:t.broadcastTransaction,call:(n)=>L(t,o,{...n,signer:e}),createContract:(n,y,u)=>E(n,y,u||t),createContractTxObject:(n)=>C(t,n),EIP1193SendTransaction:(n)=>Q(t,n),estimateCall:(n)=>it(t,{...n,signer:e}),estimateGasLimit:({assetValue:n,recipient:y,memo:u})=>Nt(t,{assetValue:n,recipient:y,memo:u,signer:e}),estimateGasPrices:()=>$(t,o),isApproved:(n)=>It(t,n),sendTransaction:(n,y)=>Tt(t,n,y,e,o),transfer:(n)=>Pt(t,n,e,o),validateAddress:at,createTransferTx:(n)=>jt(t,n,e),createApprovalTx:(n)=>Kt(t,n,e),signMessage:Vt(e)}),Ot=({address:t})=>at(t);var At;((o)=>{o.Test="goerli";o.Main="homestead"})(At||={});import{BaseDecimal as vt,Chain as Y,ChainId as dt,ChainToExplorerUrl as tn,FeeOption as Z,SKConfig as nn}from"@swapkit/helpers";var en=()=>({chainId:dt.ArbitrumHex,chainName:"Arbitrum One",nativeCurrency:{name:"Ethereum",symbol:Y.Ethereum,decimals:vt.ETH},rpcUrls:[nn.get("rpcUrls")[Y.Arbitrum]],blockExplorerUrls:[tn[Y.Arbitrum]]}),on=async(t)=>{try{let{gasPrice:e}=await t.getFeeData();if(!e)throw new Error("No fee data available");return{[Z.Average]:{gasPrice:e},[Z.Fast]:{gasPrice:e},[Z.Fastest]:{gasPrice:e}}}catch(e){throw new Error(`Failed to estimate gas price: ${e.msg??e.toString()}`)}},mt=({provider:t,signer:e})=>{let o=s({provider:t,signer:e,isEIP1559Compatible:!1}),n=Y.Arbitrum;return{...o,getNetworkParams:en,estimateGasPrices:()=>on(t),estimateTransactionFee:(y)=>f(y,Z.Average,n,t,!1),getBalance:(y,u=!0,l)=>r({provider:l||t,address:y,chain:n,potentialScamFilter:u})}};import{BaseDecimal as yn,Chain as V,ChainId as un,ChainToExplorerUrl as ln}from"@swapkit/helpers";var an=()=>({chainId:un.AvalancheHex,chainName:"Avalanche Network",nativeCurrency:{name:"Avalanche",symbol:V.Avalanche,decimals:yn.AVAX},rpcUrls:["https://api.avax.network/ext/bc/C/rpc"],blockExplorerUrls:[ln[V.Avalanche]]}),ct=({provider:t,signer:e})=>{let o=s({provider:t,signer:e}),n=V.Avalanche;return{...o,getNetworkParams:an,estimateTransactionFee:(y,u)=>f(y,u,n,t),getBalance:(y,u=!0,l)=>r({provider:l||t,address:y,chain:n,potentialScamFilter:u})}};import{BaseDecimal as pn,Chain as bt,ChainId as Tn,ChainToExplorerUrl as mn}from"@swapkit/helpers";var cn=()=>({chainId:Tn.BinanceSmartChainHex,chainName:"BNB Chain",nativeCurrency:{name:"Binance Coin",symbol:"BNB",decimals:pn.BSC},rpcUrls:["https://bsc-dataseed.binance.org"],blockExplorerUrls:[mn[bt.BinanceSmartChain]]}),Bt=({provider:t,signer:e})=>{let o=s({provider:t,signer:e,isEIP1559Compatible:!1}),n=bt.BinanceSmartChain;return{...o,getNetworkParams:cn,estimateTransactionFee:(y,u)=>f(y,u,n,t,!1),getBalance:(y,u=!0,l)=>r({provider:l||t,address:y,chain:n,potentialScamFilter:u})}};import{Chain as bn,FeeOption as Bn}from"@swapkit/helpers";var rt=[{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"aggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes[]",name:"returnData",type:"bytes[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"blockAndAggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes32",name:"blockHash",type:"bytes32"},{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall2.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"}],name:"getBlockHash",outputs:[{internalType:"bytes32",name:"blockHash",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[],name:"getBlockNumber",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockCoinbase",outputs:[{internalType:"address",name:"coinbase",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockDifficulty",outputs:[{internalType:"uint256",name:"difficulty",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockGasLimit",outputs:[{internalType:"uint256",name:"gaslimit",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getCurrentBlockTimestamp",outputs:[{internalType:"uint256",name:"timestamp",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"addr",type:"address"}],name:"getEthBalance",outputs:[{internalType:"uint256",name:"balance",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"getLastBlockHash",outputs:[{internalType:"bytes32",name:"blockHash",type:"bytes32"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bool",name:"requireSuccess",type:"bool"},{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"tryAggregate",outputs:[{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall2.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"bool",name:"requireSuccess",type:"bool"},{components:[{internalType:"address",name:"target",type:"address"},{internalType:"bytes",name:"callData",type:"bytes"}],internalType:"struct Multicall2.Call[]",name:"calls",type:"tuple[]"}],name:"tryBlockAndAggregate",outputs:[{internalType:"uint256",name:"blockNumber",type:"uint256"},{internalType:"bytes32",name:"blockHash",type:"bytes32"},{components:[{internalType:"bool",name:"success",type:"bool"},{internalType:"bytes",name:"returnData",type:"bytes"}],internalType:"struct Multicall2.Result[]",name:"returnData",type:"tuple[]"}],stateMutability:"nonpayable",type:"function"}];var st=({signer:t,provider:e})=>{let o=s({provider:e,signer:t}),n=bn.Ethereum;async function y(u,l="0x5ba1e12693dc8f9c48aad8770482f4739beed696",a="aggregate",i=Bn.Fast){let T=await o.createContractTxObject({contractAddress:l,abi:rt,funcName:a,funcParams:[u]});return o.sendTransaction(T,i)}return{...o,multicall:y,estimateTransactionFee:(u,l)=>f(u,l,n,e),getBalance:(u,l=!0,a)=>r({provider:a||e,address:u,chain:n,potentialScamFilter:l})}};import{Chain as k}from"@swapkit/helpers";import{BaseDecimal as rn,Chain as X,ChainId as sn,ChainToExplorerUrl as gn,SKConfig as Mn}from"@swapkit/helpers";var wn=()=>({chainId:sn.BaseHex,chainName:"Base Mainnet",nativeCurrency:{name:"Ethereum",symbol:X.Ethereum,decimals:rn.ETH},rpcUrls:[Mn.get("rpcUrls")[X.Base]],blockExplorerUrls:[gn[X.Base]]}),gt=({provider:t,signer:e})=>{let o=s({provider:t,signer:e}),n=X.Base;return{...o,getNetworkParams:wn,estimateTransactionFee:(y,u)=>f(y,u,n,t),getBalance:async(y,u=!0,l)=>r({provider:l||t,address:y,chain:n,potentialScamFilter:u})}};import{BaseDecimal as fn,Chain as F,ChainId as Rn,ChainToExplorerUrl as hn,SKConfig as Jn}from"@swapkit/helpers";var Un=()=>({chainId:Rn.PolygonHex,chainName:"Polygon Mainnet",nativeCurrency:{name:"Polygon",symbol:F.Polygon,decimals:fn.MATIC},rpcUrls:[Jn.get("rpcUrls")[F.Polygon]],blockExplorerUrls:[hn[F.Polygon]]}),Mt=({provider:t,signer:e})=>{let o=s({provider:t,signer:e}),n=F.Polygon;return{...o,getNetworkParams:Un,estimateTransactionFee:(y,u)=>f(y,u,n,t),getBalance:(y,u=!0,l)=>r({provider:l||t,address:y,chain:n,potentialScamFilter:u})}};import{BaseDecimal as Dn,Chain as I,ChainId as kn,ChainToExplorerUrl as qn,FeeOption as O,SKConfig as Hn}from"@swapkit/helpers";import{Contract as xn,Transaction as $n}from"ethers";var wt=[{inputs:[{internalType:"address",name:"_owner",type:"address"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"",type:"uint256"}],name:"DecimalsUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"",type:"uint256"}],name:"GasPriceUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"",type:"uint256"}],name:"L1BaseFeeUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"",type:"uint256"}],name:"OverheadUpdated",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"previousOwner",type:"address"},{indexed:!0,internalType:"address",name:"newOwner",type:"address"}],name:"OwnershipTransferred",type:"event"},{anonymous:!1,inputs:[{indexed:!1,internalType:"uint256",name:"",type:"uint256"}],name:"ScalarUpdated",type:"event"},{inputs:[],name:"decimals",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"gasPrice",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"_data",type:"bytes"}],name:"getL1Fee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"bytes",name:"_data",type:"bytes"}],name:"getL1GasUsed",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"l1BaseFee",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"overhead",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[],name:"owner",outputs:[{internalType:"address",name:"",type:"address"}],stateMutability:"view",type:"function"},{inputs:[],name:"renounceOwnership",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"scalar",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"uint256",name:"_decimals",type:"uint256"}],name:"setDecimals",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"_gasPrice",type:"uint256"}],name:"setGasPrice",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"_baseFee",type:"uint256"}],name:"setL1BaseFee",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"_overhead",type:"uint256"}],name:"setOverhead",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"uint256",name:"_scalar",type:"uint256"}],name:"setScalar",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"newOwner",type:"address"}],name:"transferOwnership",outputs:[],stateMutability:"nonpayable",type:"function"}];var Cn="0x420000000000000000000000000000000000000f",A=(t)=>{return new xn(Cn,wt,t)},ft=(t)=>{let e=A(t);if(e&&"l1BaseFee"in e)return e?.l1BaseFee();return},Rt=async(t,{data:e,from:o,to:n,gasPrice:y,type:u,gasLimit:l,nonce:a})=>{if(!n)throw new Error("Missing to address");return $n.from({data:e,to:n,gasPrice:y,type:u,gasLimit:l,nonce:a?a:o?await t.getTransactionCount(o):0}).serialized},ht=async(t,e)=>{let o=await A(t),n=await Rt(t,e);if(o&&"getL1Fee"in o)return o.getL1Fee(n)},Jt=async(t,e)=>{let o=await t.send("eth_gasPrice",[]),n=await t.estimateGas(e);return o.mul(n)},Gn=async(t,e)=>{let o=await ht(t,e),n=await Jt(t,e);return o.add(n)},Sn=async(t,e)=>{let o=A(t),n=await Rt(t,e);if(o&&"getL1GasUsed"in o)return o.getL1GasUsed(n)},zn=()=>({chainId:kn.OptimismHex,chainName:"Optimism",nativeCurrency:{name:"Ethereum",symbol:I.Ethereum,decimals:Dn.ETH},rpcUrls:[Hn.get("rpcUrls")[I.Optimism]],blockExplorerUrls:[qn[I.Optimism]]}),En=async(t)=>{try{let{maxFeePerGas:e,maxPriorityFeePerGas:o,gasPrice:n}=await t.getFeeData(),y=await ft(t),u=n;if(!(e&&o))throw new Error("No fee data available");return{[O.Average]:{l1GasPrice:y,gasPrice:n,maxFeePerGas:e,maxPriorityFeePerGas:o},[O.Fast]:{l1GasPrice:(y||0n)*15n/10n,gasPrice:u*15n/10n,maxFeePerGas:e,maxPriorityFeePerGas:o*15n/10n},[O.Fastest]:{l1GasPrice:(y||0n)*2n,gasPrice:u*2n,maxFeePerGas:e,maxPriorityFeePerGas:o*2n}}}catch(e){throw new Error(`Failed to estimate gas price: ${e.msg??e.toString()}`)}},Ut=({provider:t,signer:e})=>{return{...s({provider:t,signer:e}),estimateTotalGasCost:(n)=>Gn(t,n),estimateL1GasCost:(n)=>ht(t,n),estimateL2GasCost:(n)=>Jt(t,n),getL1GasPrice:()=>ft(t),estimateL1Gas:(n)=>Sn(t,n),getNetworkParams:zn,estimateGasPrices:()=>En(t),getBalance:(n,y=!0,u)=>r({provider:u||t,address:n,chain:I.Optimism,potentialScamFilter:y})}};var Ie=(t)=>{switch(t){case k.Avalanche:return ct;case k.Arbitrum:return mt;case k.Base:return gt;case k.Optimism:return Ut;case k.Polygon:return Mt;case k.BinanceSmartChain:return Bt;case k.Ethereum:return st;default:throw new Error(`Chain ${t} is not supported`)}};export{G as toHexString,vn as toChecksumAddress,Ft as isStateChangingCall,z as isBrowserProvider,Ie as getToolboxByChain,W as getTokenAddress,Nn as getProvider,ft as getL1GasPrice,ot as getEvmApi,dn as getChecksumAddressFromAsset,r as getBalance,Ot as evmValidateAddress,f as estimateTransactionFee,Gn as estimateTotalGasCost,Fn as estimateMaxSendableAmount,Jt as estimateL2GasCost,ht as estimateL1GasCost,Sn as estimateL1Gas,$ as estimateGasPrices,Qn as createCustomEvmApi,C as createContractTxObject,E as createContract,A as connectGasPriceOracle,Ut as OPToolbox,K as MAX_APPROVAL,Mt as MATICToolbox,At as EthNetwork,s as EVMToolbox,st as ETHToolbox,Q as EIP1193SendTransaction,Bt as BSCToolbox,gt as BASEToolbox,ct as AVAXToolbox,mt as ARBToolbox};
2
+
3
+ //# debugId=83CFF03F654942D264756E2164756E21
@@ -0,0 +1,24 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/evm/api.ts", "../src/evm/helpers.ts", "../src/evm/provider.ts", "../src/evm/toolbox/EVMToolbox.ts", "../src/evm/types.ts", "../src/evm/toolbox/arb.ts", "../src/evm/toolbox/avax.ts", "../src/evm/toolbox/bsc.ts", "../src/evm/toolbox/eth.ts", "../src/evm/contracts/eth/multicall.ts", "../src/evm/toolbox/getToolboxByChain.ts", "../src/evm/toolbox/base.ts", "../src/evm/toolbox/matic.ts", "../src/evm/toolbox/op.ts", "../src/evm/contracts/op/gasOracle.ts"],
4
+ "sourcesContent": [
5
+ "import {\n Chain,\n ChainToChainId,\n type EVMChain,\n RequestClient,\n SKConfig,\n formatBigIntToSafeValue,\n warnOnce,\n} from \"@swapkit/helpers\";\n\nasync function getEthplorerBalance({ address }: { address: string }) {\n const apiKey = SKConfig.get(\"apiKeys\").ethplorer || \"freekey\";\n\n const { tokens = [] } = await RequestClient.get<AddressInfo>(\n `https://api.ethplorer.io/getAddressInfo/${address}`,\n { searchParams: { apiKey } },\n );\n\n return tokens\n .filter(({ tokenInfo: { symbol }, rawBalance }) => symbol && rawBalance !== \"0\")\n .map(({ tokenInfo: { symbol, decimals, address: tokenAddress }, rawBalance }) => ({\n chain: Chain.Ethereum,\n decimal: Number.parseInt(decimals),\n symbol: tokenAddress ? `${symbol}-${tokenAddress}` : symbol,\n value: formatBigIntToSafeValue({\n value: BigInt(rawBalance),\n decimal: Number.parseInt(decimals),\n bigIntDecimal: Number.parseInt(decimals),\n }),\n }));\n}\n\nasync function getCovalentBalance({ chain, address }: { chain: Chain; address: string }) {\n const apiKey = SKConfig.get(\"apiKeys\").covalent;\n\n if (!apiKey) {\n warnOnce(true, \"No covalent api key found. Use SKConfig.setApiKey('your-api-key')\");\n return [];\n }\n\n const { data } = await RequestClient.get<{ data: CovalentBalanceResponse }>(\n `https://api.covalenthq.com/v1/${ChainToChainId[chain]}/address/${address}/balances_v2/`,\n { searchParams: { key: apiKey } },\n );\n\n return (data?.items || [])\n .filter(({ is_spam }) => !is_spam)\n .map(\n ({ balance, contract_decimals, contract_ticker_symbol, contract_address, native_token }) => ({\n value: formatBigIntToSafeValue({\n value: BigInt(balance),\n decimal: contract_decimals,\n bigIntDecimal: contract_decimals,\n }),\n decimal: contract_decimals,\n chain,\n symbol: `${contract_ticker_symbol || \"Unknown\"}${native_token ? \"\" : `-${contract_address}`}`,\n }),\n );\n}\n\nexport function getEvmApi(chain: EVMChain) {\n const getBalance = chain === Chain.Ethereum ? getEthplorerBalance : getCovalentBalance;\n return { getBalance: (address: string) => getBalance({ address, chain }) };\n}\n\nexport function createCustomEvmApi(methods: ReturnType<typeof getEvmApi>) {\n return methods;\n}\n\ntype CovalentBalanceResponse = {\n address: string;\n updated_at: string;\n next_updated_at: string;\n quote_currency: string;\n items: {\n is_spam: boolean;\n contract_decimals: number;\n contract_name: string;\n contract_ticker_symbol: string;\n contract_address: string;\n logo_url: string;\n last_transferred_at: string;\n native_token: boolean;\n type: string;\n balance: number;\n balance_24h: number;\n quote_rate: number;\n quote_rate_24h: number;\n quote: number;\n quote_24h: number;\n }[];\n};\n\ntype PriceInfo = {\n rate: number;\n diff: number;\n diff7d?: number;\n ts: number;\n marketCapUsd?: number;\n availableSupply?: number;\n volume24h?: number;\n diff30d?: number;\n volDiff1?: number;\n volDiff7?: number;\n volDiff30?: number;\n currency?: string;\n};\n\ntype TokenInfo = {\n address: string;\n decimals: string;\n name: string;\n owner: string;\n symbol: string;\n totalSupply: string;\n lastUpdated: number;\n issuancesCount: number;\n holdersCount: number;\n image?: string;\n description?: string;\n website?: string;\n twitter?: string;\n facebook?: string;\n coingecko?: string;\n ethTransfersCount: number;\n price: boolean | PriceInfo | unknown;\n publicTags?: string[];\n txsCount?: number;\n transfersCount?: number;\n};\n\ntype TokenBalance = {\n tokenInfo: TokenInfo;\n balance: number;\n rawBalance: string;\n totalIn?: number;\n totalOut?: number;\n};\n\nexport type AddressInfo = {\n address: string;\n ETH: {\n balance: number;\n totalIn?: number;\n totalOut?: number;\n price: PriceInfo;\n };\n contractInfo?: {\n creatorAddress: string;\n transactionHash: string;\n timestamp: string;\n };\n tokenInfo?: TokenInfo;\n tokens?: TokenBalance[];\n countTxs: number;\n};\n",
6
+ "import {\n AssetValue,\n BaseDecimal,\n type EVMChain,\n FeeOption,\n SwapKitNumber,\n filterAssets,\n formatBigIntToSafeValue,\n isGasAsset,\n} from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Provider } from \"ethers\";\n\nimport { getEvmApi } from \"./api\";\nimport { type EIP1559TxParams, type EVMMaxSendableAmountsParams, estimateGasPrices } from \"./index\";\n\nexport const estimateMaxSendableAmount = async ({\n toolbox,\n from,\n memo = \"\",\n feeOptionKey = FeeOption.Fastest,\n assetValue,\n abi,\n funcName,\n funcParams,\n contractAddress,\n txOverrides,\n}: EVMMaxSendableAmountsParams): Promise<AssetValue> => {\n const balance = (await toolbox.getBalance(from)).find(({ symbol, chain }) =>\n assetValue ? symbol === assetValue.symbol : symbol === AssetValue.from({ chain })?.symbol,\n );\n\n const gasRate = (await toolbox.estimateGasPrices())[feeOptionKey];\n\n if (!balance) return AssetValue.from({ chain: assetValue.chain });\n\n if (assetValue && (balance.chain !== assetValue.chain || balance.symbol !== assetValue?.symbol)) {\n return balance;\n }\n\n const gasLimit =\n abi && funcName && funcParams && contractAddress\n ? await toolbox.estimateCall({\n contractAddress,\n abi,\n funcName,\n funcParams,\n txOverrides,\n })\n : await toolbox.estimateGasLimit({\n from,\n recipient: from,\n memo,\n assetValue,\n });\n\n const isFeeEIP1559Compatible = \"maxFeePerGas\" in gasRate;\n const isFeeEVMLegacyCompatible = \"gasPrice\" in gasRate;\n\n if (!(isFeeEVMLegacyCompatible || isFeeEIP1559Compatible)) {\n throw new Error(\"Could not fetch fee data\");\n }\n\n const fee =\n gasLimit *\n (isFeeEIP1559Compatible\n ? (gasRate.maxFeePerGas || 1n) + (gasRate.maxPriorityFeePerGas || 1n)\n : gasRate.gasPrice);\n const maxSendableAmount = SwapKitNumber.fromBigInt(balance.getBaseValue(\"bigint\")).sub(\n fee.toString(),\n );\n\n return AssetValue.from({ chain: balance.chain, value: maxSendableAmount.getValue(\"string\") });\n};\n\nexport const toHexString = (value: bigint) => (value > 0n ? `0x${value.toString(16)}` : \"0x0\");\n\nexport const getBalance = async ({\n provider,\n address,\n chain,\n potentialScamFilter,\n}: {\n provider: JsonRpcProvider | BrowserProvider;\n address: string;\n chain: EVMChain;\n potentialScamFilter?: boolean;\n}) => {\n const tokenBalances = await getEvmApi(chain).getBalance(address);\n const evmGasTokenBalance = await provider.getBalance(address);\n\n const balances = [\n {\n chain,\n symbol: AssetValue.from({ chain }).symbol,\n value: formatBigIntToSafeValue({\n value: BigInt(evmGasTokenBalance),\n decimal: 18,\n bigIntDecimal: 18,\n }),\n decimal: BaseDecimal[chain],\n },\n ...tokenBalances.filter((token) => !isGasAsset(token)),\n ];\n\n const filteredBalances = potentialScamFilter ? filterAssets(balances) : balances;\n\n return filteredBalances.map(\n ({ symbol, value, decimal }) =>\n new AssetValue({\n decimal: decimal || BaseDecimal[chain],\n value,\n identifier: `${chain}.${symbol}`,\n }),\n );\n};\n\nexport const estimateTransactionFee = async (\n txObject: EIP1559TxParams,\n // biome-ignore lint/style/useDefaultParameterLast: Should only be used through wrapped toolboxes\n feeOption: FeeOption = FeeOption.Fast,\n chain: EVMChain,\n provider: Provider | BrowserProvider,\n isEIP1559Compatible = true,\n) => {\n const gasPrices = (await estimateGasPrices(provider, isEIP1559Compatible))[feeOption];\n const gasLimit = await provider.estimateGas(txObject);\n const assetValue = AssetValue.from({ chain });\n\n if (!isEIP1559Compatible && gasPrices.gasPrice) {\n return assetValue.set(\n SwapKitNumber.fromBigInt(gasPrices.gasPrice * gasLimit, assetValue.decimal),\n );\n }\n\n if (gasPrices.maxFeePerGas && gasPrices.maxPriorityFeePerGas) {\n return assetValue.set(\n SwapKitNumber.fromBigInt(\n (gasPrices.maxFeePerGas + gasPrices.maxPriorityFeePerGas) * gasLimit,\n assetValue.decimal,\n ),\n );\n }\n\n throw new Error(\"No gas price found\");\n};\n",
7
+ "import { type EVMChain, SKConfig } from \"@swapkit/helpers\";\nimport { JsonRpcProvider } from \"ethers\";\n\nexport const getProvider = (chain: EVMChain, customUrl?: string) => {\n return new JsonRpcProvider(customUrl || SKConfig.get(\"rpcUrls\")[chain]);\n};\n",
8
+ "import {\n type Asset,\n type AssetValue,\n Chain,\n ContractAddress,\n type EVMChain,\n FeeOption,\n SwapKitError,\n SwapKitNumber,\n type WalletTxParams,\n isGasAsset,\n} from \"@swapkit/helpers\";\nimport { erc20ABI } from \"@swapkit/helpers/contracts\";\nimport {\n BrowserProvider,\n Contract,\n type ContractTransaction,\n type Fragment,\n type HDNodeWallet,\n Interface,\n type JsonFragment,\n type JsonRpcSigner,\n MaxInt256,\n type Provider,\n type Signer,\n getAddress,\n hexlify,\n toUtf8Bytes,\n} from \"ethers\";\n\nimport {\n type ARBToolbox,\n type AVAXToolbox,\n type BASEToolbox,\n type BSCToolbox,\n type ETHToolbox,\n type MATICToolbox,\n type OPToolbox,\n toHexString,\n} from \"../index\";\nimport type {\n ApproveParams,\n ApprovedParams,\n CallParams,\n EIP1559TxParams,\n EVMTxParams,\n EstimateCallParams,\n IsApprovedParams,\n LegacyEVMTxParams,\n TransferParams,\n} from \"../types\";\n\nexport const MAX_APPROVAL = MaxInt256;\n\nconst baseAssetAddress: Record<EVMChain, string> = {\n [Chain.Arbitrum]: ContractAddress.ARB,\n [Chain.Avalanche]: ContractAddress.AVAX,\n [Chain.Base]: ContractAddress.BASE,\n [Chain.BinanceSmartChain]: ContractAddress.BSC,\n [Chain.Ethereum]: ContractAddress.ETH,\n [Chain.Optimism]: ContractAddress.OP,\n [Chain.Polygon]: ContractAddress.MATIC,\n};\n\nconst stateMutable = [\"payable\", \"nonpayable\"];\n// const nonStateMutable = ['view', 'pure'];\n\nconst isEIP1559Transaction = (tx: EVMTxParams) =>\n (tx as EIP1559TxParams).type === 2 ||\n !!(tx as EIP1559TxParams).maxFeePerGas ||\n !!(tx as EIP1559TxParams).maxPriorityFeePerGas;\n\nexport const isBrowserProvider = (provider: any) => provider instanceof BrowserProvider;\nexport const createContract = (\n address: string,\n abi: readonly (JsonFragment | Fragment)[],\n provider: Provider,\n) => {\n return new Contract(address, Interface.from(abi), provider);\n};\n\nconst validateAddress = (address: string) => {\n try {\n getAddress(address);\n return true;\n } catch (_error) {\n return false;\n }\n};\n\nexport const isStateChangingCall = (abi: readonly JsonFragment[], functionName: string) => {\n const abiFragment = abi.find((fragment: any) => fragment.name === functionName) as any;\n if (!abiFragment) throw new SwapKitError(\"toolbox_evm_no_abi_fragment\", { functionName });\n return abiFragment.stateMutability && stateMutable.includes(abiFragment.stateMutability);\n};\n\nexport type WithSigner<T> = T & { signer?: Signer };\n\n/**\n * @info call contract function\n * When using this method to make a non state changing call to the blockchain, like a isApproved call,\n * the signer needs to be set to undefined\n */\nconst call = async <T>(\n provider: Provider,\n isEIP1559Compatible: boolean,\n {\n callProvider,\n signer,\n contractAddress,\n abi,\n funcName,\n funcParams = [],\n txOverrides = {},\n feeOption = FeeOption.Fast,\n }: WithSigner<CallParams>,\n): Promise<T> => {\n const contractProvider = callProvider || provider;\n if (!contractAddress) throw new Error(\"contractAddress must be provided\");\n\n const isStateChanging = isStateChangingCall(abi, funcName);\n const overridesParams = {\n ...txOverrides,\n from: txOverrides?.from || (await signer?.getAddress()),\n };\n\n if (isStateChanging && isBrowserProvider(contractProvider) && signer) {\n const txObject = await createContractTxObject(contractProvider, {\n contractAddress,\n abi,\n funcName,\n funcParams,\n txOverrides: overridesParams,\n });\n\n return EIP1193SendTransaction(contractProvider, txObject) as Promise<T>;\n }\n const contract = createContract(contractAddress, abi, contractProvider);\n\n // only use signer if the contract function is state changing\n if (isStateChanging) {\n if (!signer) throw new SwapKitError(\"toolbox_evm_no_signer\");\n\n const address = txOverrides?.from || (await signer.getAddress());\n\n if (!address) throw new SwapKitError(\"toolbox_evm_no_signer_address\");\n\n const connectedContract = contract.connect(signer);\n const { maxFeePerGas, maxPriorityFeePerGas, gasPrice } = (\n await estimateGasPrices(provider, isEIP1559Compatible)\n )[feeOption];\n\n const gasLimit = await contract.getFunction(funcName).estimateGas(...funcParams, txOverrides);\n\n // @ts-expect-error\n const result = await connectedContract[funcName](...funcParams, {\n ...txOverrides,\n gasLimit,\n maxFeePerGas,\n maxPriorityFeePerGas,\n gasPrice,\n /**\n * nonce must be set due to a possible bug with ethers.js,\n * expecting a synchronous nonce while the JsonRpcProvider delivers Promise\n */\n nonce: txOverrides?.nonce || (await contractProvider.getTransactionCount(address)),\n });\n\n return typeof result?.hash === \"string\" ? result?.hash : result;\n }\n\n const result = await contract[funcName]?.(...funcParams);\n\n return typeof result?.hash === \"string\" ? result?.hash : result;\n};\n\nexport const createContractTxObject = async (\n provider: Provider,\n { contractAddress, abi, funcName, funcParams = [], txOverrides }: CallParams,\n) =>\n createContract(contractAddress, abi, provider)\n .getFunction(funcName)\n .populateTransaction(...funcParams.concat(txOverrides).filter((p) => typeof p !== \"undefined\"));\n\nconst approvedAmount = async (\n provider: Provider,\n { assetAddress, spenderAddress, from }: IsApprovedParams,\n) =>\n await call<bigint>(provider, true, {\n contractAddress: assetAddress,\n abi: erc20ABI as any,\n funcName: \"allowance\",\n funcParams: [from, spenderAddress],\n });\n\nconst isApproved = async (\n provider: Provider,\n { assetAddress, spenderAddress, from, amount = MAX_APPROVAL }: IsApprovedParams,\n) => {\n return SwapKitNumber.fromBigInt(\n await approvedAmount(provider, { assetAddress, spenderAddress, from }),\n ).gte(SwapKitNumber.fromBigInt(BigInt(amount)));\n};\n\nconst approve = async (\n provider: Provider,\n {\n assetAddress,\n spenderAddress,\n feeOptionKey = FeeOption.Fast,\n amount,\n gasLimitFallback,\n from,\n nonce,\n }: ApproveParams,\n signer?: Signer,\n isEIP1559Compatible = true,\n) => {\n const funcParams = [spenderAddress, BigInt(amount || MAX_APPROVAL)];\n const txOverrides = { from };\n\n const functionCallParams = {\n contractAddress: assetAddress,\n abi: erc20ABI,\n funcName: \"approve\",\n funcParams,\n signer,\n txOverrides,\n };\n\n if (isBrowserProvider(provider)) {\n return EIP1193SendTransaction(\n provider,\n await createContractTxObject(provider, functionCallParams),\n );\n }\n\n return call<string>(provider, isEIP1559Compatible, {\n ...functionCallParams,\n funcParams,\n txOverrides: {\n from,\n nonce,\n gasLimit: gasLimitFallback ? BigInt(gasLimitFallback.toString()) : undefined,\n },\n feeOption: feeOptionKey,\n });\n};\n\nconst transfer = async (\n provider: Provider | BrowserProvider,\n {\n assetValue,\n memo,\n recipient,\n feeOptionKey = FeeOption.Fast,\n data,\n from: fromOverride,\n maxFeePerGas,\n maxPriorityFeePerGas,\n gasPrice,\n ...tx\n }: TransferParams,\n signer?: Signer,\n isEIP1559Compatible = true,\n) => {\n const txAmount = assetValue.getBaseValue(\"bigint\");\n const chain = assetValue.chain as EVMChain;\n\n const from = fromOverride || (await signer?.getAddress());\n\n if (!from) throw new SwapKitError(\"toolbox_evm_no_from_address\");\n\n if (!assetValue.isGasAsset) {\n const contractAddress = getTokenAddress(assetValue, chain);\n if (!contractAddress) throw new SwapKitError(\"toolbox_evm_no_contract_address\");\n\n // Transfer ERC20\n return call<string>(provider, isEIP1559Compatible, {\n signer,\n contractAddress,\n abi: erc20ABI,\n funcName: \"transfer\",\n funcParams: [recipient, txAmount],\n txOverrides: { from, maxFeePerGas, maxPriorityFeePerGas, gasPrice },\n feeOption: feeOptionKey,\n });\n }\n // Transfer ETH\n const txObject = {\n ...tx,\n from,\n to: recipient,\n value: txAmount,\n data: data || hexlify(toUtf8Bytes(memo || \"\")),\n };\n\n return sendTransaction(provider, txObject, feeOptionKey, signer, isEIP1559Compatible);\n};\n\nexport const estimateGasPrices = async (provider: Provider, isEIP1559Compatible = true) => {\n try {\n const { maxFeePerGas, maxPriorityFeePerGas, gasPrice } = await provider.getFeeData();\n\n if (isEIP1559Compatible) {\n if (maxFeePerGas === null || maxPriorityFeePerGas === null)\n throw new SwapKitError(\"toolbox_evm_no_fee_data\");\n\n return {\n [FeeOption.Average]: { maxFeePerGas, maxPriorityFeePerGas },\n [FeeOption.Fast]: {\n maxFeePerGas: (maxFeePerGas * 15n) / 10n,\n maxPriorityFeePerGas: (maxPriorityFeePerGas * 15n) / 10n,\n },\n [FeeOption.Fastest]: {\n maxFeePerGas: maxFeePerGas * 2n,\n maxPriorityFeePerGas: maxPriorityFeePerGas * 2n,\n },\n };\n }\n if (!gasPrice) throw new SwapKitError(\"toolbox_evm_no_gas_price\");\n\n return {\n [FeeOption.Average]: { gasPrice },\n [FeeOption.Fast]: { gasPrice: (gasPrice * 15n) / 10n },\n [FeeOption.Fastest]: { gasPrice: gasPrice * 2n },\n };\n } catch (error) {\n throw new Error(\n `Failed to estimate gas price: ${(error as any).msg ?? (error as any).toString()}`,\n );\n }\n};\n\nconst estimateCall = (\n provider: Provider,\n {\n signer,\n contractAddress,\n abi,\n funcName,\n funcParams = [],\n txOverrides,\n }: WithSigner<EstimateCallParams>,\n) => {\n if (!contractAddress) throw new SwapKitError(\"toolbox_evm_no_contract_address\");\n\n const contract = createContract(contractAddress, abi, provider);\n return signer\n ? contract\n .connect(signer)\n .getFunction(funcName)\n .estimateGas(...funcParams, txOverrides)\n : contract.getFunction(funcName).estimateGas(...funcParams, txOverrides);\n};\n\nconst estimateGasLimit = (\n provider: Provider,\n {\n assetValue,\n recipient,\n memo,\n from,\n funcName,\n funcParams,\n txOverrides,\n signer,\n }: WalletTxParams & {\n assetValue: AssetValue;\n funcName?: string;\n funcParams?: unknown[];\n signer?: Signer;\n txOverrides?: EVMTxParams;\n },\n) => {\n // const value = assetValue.getBaseValue(\"bigint\");\n const value = assetValue.bigIntValue;\n\n const assetAddress = assetValue.isGasAsset\n ? null\n : getTokenAddress(assetValue, assetValue.chain as EVMChain);\n\n if (assetAddress && funcName) {\n // ERC20 gas estimate\n return estimateCall(provider, {\n contractAddress: assetAddress,\n abi: erc20ABI,\n funcName,\n funcParams,\n txOverrides,\n signer,\n });\n }\n\n return provider.estimateGas({\n from,\n to: recipient,\n value,\n data: memo ? hexlify(toUtf8Bytes(memo)) : undefined,\n });\n};\n\nconst sendTransaction = async (\n provider: Provider | BrowserProvider,\n tx: EVMTxParams,\n feeOptionKey: FeeOption = FeeOption.Fast,\n signer?: Signer,\n isEIP1559Compatible = true,\n // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: refactor\n) => {\n if (!signer) throw new SwapKitError(\"toolbox_evm_no_signer\");\n const { from, to, data, value, ...transaction } = tx;\n if (!to) throw new SwapKitError(\"toolbox_evm_no_to_address\");\n\n const parsedTxObject = {\n ...transaction,\n data: data || \"0x\",\n to,\n from,\n value: BigInt(value || 0),\n };\n\n // early return to skip gas estimation if provider is EIP-1193\n if (isBrowserProvider(provider)) {\n return EIP1193SendTransaction(provider, parsedTxObject);\n }\n\n const address = from || (await signer.getAddress());\n const nonce = tx.nonce || (await provider.getTransactionCount(address));\n const chainId = (await provider.getNetwork()).chainId;\n\n const isEIP1559 = isEIP1559Transaction(parsedTxObject) || isEIP1559Compatible;\n\n const feeData =\n (isEIP1559 &&\n !(\n (parsedTxObject as EIP1559TxParams).maxFeePerGas &&\n (parsedTxObject as EIP1559TxParams).maxPriorityFeePerGas\n )) ||\n !(parsedTxObject as LegacyEVMTxParams).gasPrice\n ? Object.entries(\n (await estimateGasPrices(provider, isEIP1559Compatible))[feeOptionKey],\n ).reduce(\n // biome-ignore lint/performance/noAccumulatingSpread: this is a small object\n (acc, [k, v]) => ({ ...acc, [k]: toHexString(BigInt(v)) }),\n {} as {\n maxFeePerGas?: string;\n maxPriorityFeePerGas?: string;\n gasPrice?: string;\n },\n )\n : {};\n let gasLimit: string;\n try {\n gasLimit = toHexString(\n parsedTxObject.gasLimit || ((await provider.estimateGas(parsedTxObject)) * 11n) / 10n,\n );\n } catch (error) {\n throw new SwapKitError(\"toolbox_evm_error_estimating_gas_limit\", { error });\n }\n\n try {\n const txObject = {\n ...parsedTxObject,\n chainId,\n type: isEIP1559 ? 2 : 0,\n gasLimit,\n nonce,\n ...feeData,\n };\n\n try {\n const response = await signer.sendTransaction(txObject);\n return response.hash;\n } catch (_error) {\n const txHex = await signer.signTransaction({\n ...txObject,\n from: address,\n });\n const response = await provider.broadcastTransaction(txHex);\n return response.hash;\n }\n } catch (error) {\n throw new SwapKitError(\"toolbox_evm_error_sending_transaction\", { error });\n }\n};\n\n/**\n * Exported helper functions\n */\nexport const toChecksumAddress = (address: string) => getAddress(address);\n\nexport const EIP1193SendTransaction = (\n provider: Provider | BrowserProvider,\n { from, to, data, value }: EVMTxParams | ContractTransaction,\n): Promise<string> => {\n if (!isBrowserProvider(provider))\n throw new SwapKitError(\"toolbox_evm_provider_not_eip1193_compatible\");\n return (provider as BrowserProvider).send(\"eth_sendTransaction\", [\n { value: toHexString(BigInt(value || 0)), from, to, data } as any,\n ]);\n};\n\nexport const getChecksumAddressFromAsset = (asset: Asset, chain: EVMChain) => {\n const assetAddress = getTokenAddress(asset, chain);\n\n if (assetAddress) {\n return getAddress(assetAddress.toLowerCase());\n }\n\n throw new SwapKitError(\"toolbox_evm_invalid_gas_asset_address\");\n};\n\nexport const getTokenAddress = ({ chain, symbol, ticker }: Asset, baseAssetChain: EVMChain) => {\n try {\n const isBSCBNB = chain === Chain.BinanceSmartChain && symbol === \"BNB\" && ticker === \"BNB\";\n const isBaseAsset =\n chain === baseAssetChain && symbol === baseAssetChain && ticker === baseAssetChain;\n const isEVMAsset =\n [Chain.Arbitrum, Chain.Base].includes(chain) && symbol === \"ETH\" && ticker === \"ETH\";\n\n if (isBaseAsset || isBSCBNB || isEVMAsset) {\n return baseAssetAddress[baseAssetChain];\n }\n\n // strip 0X only - 0x is still valid\n return getAddress(symbol.slice(ticker.length + 1).replace(/^0X/, \"\"));\n } catch (_error) {\n return null;\n }\n};\n\nconst createTransferTx = async (\n provider: Provider | BrowserProvider,\n {\n assetValue,\n memo,\n recipient,\n feeOptionKey = FeeOption.Fast,\n data,\n from: fromOverride,\n maxFeePerGas,\n maxPriorityFeePerGas,\n gasPrice,\n ...tx\n }: TransferParams,\n signer?: Signer,\n) => {\n const txAmount = assetValue.getBaseValue(\"bigint\");\n const chain = assetValue.chain as EVMChain;\n\n const from = fromOverride || (await signer?.getAddress());\n\n if (!from) throw new SwapKitError(\"toolbox_evm_no_from_address\");\n\n if (!isGasAsset(assetValue)) {\n const contractAddress = getTokenAddress(assetValue, chain);\n if (!contractAddress) throw new SwapKitError(\"toolbox_evm_no_contract_address\");\n\n // Transfer ERC20\n return createContractTxObject(provider, {\n contractAddress,\n abi: erc20ABI,\n funcName: \"transfer\",\n funcParams: [recipient, txAmount],\n txOverrides: { from, maxFeePerGas, maxPriorityFeePerGas, gasPrice },\n });\n }\n // Transfer ETH\n const txObject = {\n ...tx,\n from,\n to: recipient,\n value: txAmount,\n data: data || hexlify(toUtf8Bytes(memo || \"\")),\n };\n\n return txObject;\n};\n\nconst createApprovalTx = async (\n provider: Provider,\n { assetAddress, spenderAddress, amount, from }: ApproveParams,\n signer?: Signer,\n) => {\n const funcParams = [spenderAddress, BigInt(amount || MAX_APPROVAL)];\n const txOverrides = { from };\n\n const functionCallParams = {\n contractAddress: assetAddress,\n abi: erc20ABI,\n funcName: \"approve\",\n funcParams,\n signer,\n txOverrides,\n };\n\n const txObject = await createContractTxObject(provider, functionCallParams);\n\n return txObject;\n};\n\nfunction signMessage(signer?: Signer | JsonRpcSigner | HDNodeWallet) {\n if (!signer) throw new SwapKitError(\"toolbox_evm_no_signer\");\n\n return signer.signMessage;\n}\n\nexport const EVMToolbox = ({\n provider,\n signer,\n isEIP1559Compatible = true,\n}: {\n signer?: Signer | JsonRpcSigner | HDNodeWallet;\n provider: Provider | BrowserProvider;\n isEIP1559Compatible?: boolean;\n}) => ({\n approve: (params: ApproveParams) => approve(provider, params, signer, isEIP1559Compatible),\n approvedAmount: (params: ApprovedParams) => approvedAmount(provider, params),\n broadcastTransaction: provider.broadcastTransaction,\n call: <T>(params: CallParams) => call<T>(provider, isEIP1559Compatible, { ...params, signer }),\n createContract: (\n address: string,\n abi: (JsonFragment | Fragment)[],\n contractProvider?: Provider,\n ) => createContract(address, abi, contractProvider || provider),\n createContractTxObject: (params: CallParams) => createContractTxObject(provider, params),\n EIP1193SendTransaction: (tx: EIP1559TxParams) => EIP1193SendTransaction(provider, tx),\n estimateCall: (params: EstimateCallParams) => estimateCall(provider, { ...params, signer }),\n estimateGasLimit: ({\n assetValue,\n recipient,\n memo,\n }: WalletTxParams & { assetValue: AssetValue }) =>\n estimateGasLimit(provider, { assetValue, recipient, memo, signer }),\n estimateGasPrices: () => estimateGasPrices(provider, isEIP1559Compatible),\n isApproved: (params: IsApprovedParams) => isApproved(provider, params),\n sendTransaction: (params: EIP1559TxParams, feeOption?: FeeOption) =>\n sendTransaction(provider, params, feeOption, signer, isEIP1559Compatible),\n transfer: (params: TransferParams) => transfer(provider, params, signer, isEIP1559Compatible),\n validateAddress,\n createTransferTx: (params: TransferParams) => createTransferTx(provider, params, signer),\n createApprovalTx: (params: ApproveParams) => createApprovalTx(provider, params, signer),\n signMessage: signMessage(signer),\n});\n\nexport const evmValidateAddress = ({ address }: { address: string }) => validateAddress(address);\n\nexport type EVMWallet = ReturnType<typeof EVMToolbox>;\nexport type EVMWalletType = {\n [Chain.Arbitrum]: ReturnType<typeof ARBToolbox>;\n [Chain.Avalanche]: ReturnType<typeof AVAXToolbox>;\n [Chain.Base]: ReturnType<typeof BASEToolbox>;\n [Chain.BinanceSmartChain]: ReturnType<typeof BSCToolbox>;\n [Chain.Ethereum]: ReturnType<typeof ETHToolbox>;\n [Chain.Optimism]: ReturnType<typeof OPToolbox>;\n [Chain.Polygon]: ReturnType<typeof MATICToolbox>;\n};\n\nexport type EVMWallets = {\n [chain in EVMChain]: EVMWallet & EVMWalletType[chain];\n};\n",
9
+ "import type { AssetValue, FeeOption, WalletTxParams } from \"@swapkit/helpers\";\nimport type { BigNumberish, JsonFragment, Transaction } from \"ethers\";\n\nimport type {\n ARBToolbox,\n AVAXToolbox,\n BASEToolbox,\n BSCToolbox,\n ETHToolbox,\n MATICToolbox,\n OPToolbox,\n} from \"./index\";\nimport type { getProvider } from \"./provider\";\n\nexport enum EthNetwork {\n Test = \"goerli\",\n Main = \"homestead\",\n}\n\nexport type ApproveParams = {\n assetAddress: string;\n spenderAddress: string;\n feeOptionKey?: FeeOption;\n amount?: BigNumberish;\n from: string;\n // Optional fallback in case estimation for gas limit fails\n gasLimitFallback?: BigNumberish;\n nonce?: number;\n};\n\nexport type ApprovedParams = {\n assetAddress: string;\n spenderAddress: string;\n from: string;\n};\n\nexport type IsApprovedParams = ApprovedParams & {\n amount?: BigNumberish;\n};\n\nexport type CallParams = {\n callProvider?: ReturnType<typeof getProvider>;\n contractAddress: string;\n abi: readonly JsonFragment[];\n funcName: string;\n funcParams?: unknown[];\n txOverrides?: Partial<Transaction>;\n feeOption?: FeeOption;\n};\n\nexport type EstimateCallParams = Pick<\n CallParams,\n \"contractAddress\" | \"abi\" | \"funcName\" | \"funcParams\" | \"txOverrides\"\n>;\n\nexport type TransferParams = WalletTxParams & {\n gasLimit?: bigint;\n gasPrice?: bigint;\n maxFeePerGas?: bigint;\n maxPriorityFeePerGas?: bigint;\n data?: string;\n from: string;\n nonce?: number;\n assetValue: AssetValue;\n};\n\nexport type EVMToolboxType = ReturnType<\n | typeof ARBToolbox\n | typeof AVAXToolbox\n | typeof BASEToolbox\n | typeof BSCToolbox\n | typeof ETHToolbox\n | typeof MATICToolbox\n | typeof OPToolbox\n>;\n\nexport type EVMMaxSendableAmountsParams = {\n from: string;\n toolbox: EVMToolboxType;\n assetValue: AssetValue;\n feeOptionKey?: FeeOption;\n memo?: string;\n abi?: readonly JsonFragment[];\n funcName?: string;\n contractAddress?: string;\n funcParams?: unknown[];\n txOverrides?: Partial<Transaction>;\n};\n\nexport type EVMTxBaseParams<T = bigint> = {\n to?: string;\n from?: string;\n nonce?: number;\n gasLimit?: T;\n data?: string;\n value?: T;\n chainId?: T;\n};\n\nexport type EIP1559TxParams<T = bigint> = EVMTxBaseParams<T> & {\n type?: number;\n maxFeePerGas?: T;\n maxPriorityFeePerGas?: T;\n};\n\nexport type LegacyEVMTxParams<T = bigint> = EVMTxBaseParams<T> & {\n gasPrice?: T;\n};\n\nexport type EVMTxParams = EIP1559TxParams | LegacyEVMTxParams;\n\nexport type NonETHToolbox =\n | ReturnType<typeof ARBToolbox>\n | ReturnType<typeof AVAXToolbox>\n | ReturnType<typeof BSCToolbox>\n | ReturnType<typeof MATICToolbox>\n | ReturnType<typeof OPToolbox>\n | ReturnType<typeof BASEToolbox>;\n",
10
+ "import {\n BaseDecimal,\n Chain,\n ChainId,\n ChainToExplorerUrl,\n FeeOption,\n SKConfig,\n} from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Provider, Signer } from \"ethers\";\n\nimport { type EVMTxBaseParams, estimateTransactionFee, getBalance } from \"../index\";\n\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nconst getNetworkParams = () => ({\n chainId: ChainId.ArbitrumHex,\n chainName: \"Arbitrum One\",\n nativeCurrency: { name: \"Ethereum\", symbol: Chain.Ethereum, decimals: BaseDecimal.ETH },\n rpcUrls: [SKConfig.get(\"rpcUrls\")[Chain.Arbitrum]],\n blockExplorerUrls: [ChainToExplorerUrl[Chain.Arbitrum]],\n});\n\nconst estimateGasPrices = async (provider: Provider) => {\n try {\n const { gasPrice } = await provider.getFeeData();\n\n if (!gasPrice) throw new Error(\"No fee data available\");\n\n return {\n [FeeOption.Average]: { gasPrice },\n [FeeOption.Fast]: { gasPrice },\n [FeeOption.Fastest]: { gasPrice },\n };\n } catch (error) {\n throw new Error(\n `Failed to estimate gas price: ${(error as any).msg ?? (error as any).toString()}`,\n );\n }\n};\n\nexport const ARBToolbox = ({\n provider,\n signer,\n}: { signer?: Signer; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer, isEIP1559Compatible: false });\n const chain = Chain.Arbitrum;\n\n return {\n ...evmToolbox,\n getNetworkParams,\n estimateGasPrices: () => estimateGasPrices(provider),\n estimateTransactionFee: (txObject: EVMTxBaseParams) =>\n estimateTransactionFee(txObject, FeeOption.Average, chain, provider, false),\n getBalance: (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({ provider: overwriteProvider || provider, address, chain, potentialScamFilter }),\n };\n};\n",
11
+ "import { BaseDecimal, Chain, ChainId, ChainToExplorerUrl, type FeeOption } from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Signer } from \"ethers\";\n\nimport { type EVMTxBaseParams, estimateTransactionFee, getBalance } from \"../index\";\n\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nconst getNetworkParams = () => ({\n chainId: ChainId.AvalancheHex,\n chainName: \"Avalanche Network\",\n nativeCurrency: { name: \"Avalanche\", symbol: Chain.Avalanche, decimals: BaseDecimal.AVAX },\n // Use external rpc URL so wallets don't throw warning to user\n rpcUrls: [\"https://api.avax.network/ext/bc/C/rpc\"],\n blockExplorerUrls: [ChainToExplorerUrl[Chain.Avalanche]],\n});\n\nexport const AVAXToolbox = ({\n provider,\n signer,\n}: { signer?: Signer; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer });\n const chain = Chain.Avalanche;\n\n return {\n ...evmToolbox,\n getNetworkParams,\n estimateTransactionFee: (txObject: EVMTxBaseParams, feeOptionKey: FeeOption) =>\n estimateTransactionFee(txObject, feeOptionKey, chain, provider),\n getBalance: (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({ provider: overwriteProvider || provider, address, chain, potentialScamFilter }),\n };\n};\n",
12
+ "import { BaseDecimal, Chain, ChainId, ChainToExplorerUrl, type FeeOption } from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Signer } from \"ethers\";\n\nimport { type EVMTxBaseParams, estimateTransactionFee, getBalance } from \"../index\";\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nconst getNetworkParams = () => ({\n chainId: ChainId.BinanceSmartChainHex,\n chainName: \"BNB Chain\",\n nativeCurrency: { name: \"Binance Coin\", symbol: \"BNB\", decimals: BaseDecimal.BSC },\n rpcUrls: [\"https://bsc-dataseed.binance.org\"],\n blockExplorerUrls: [ChainToExplorerUrl[Chain.BinanceSmartChain]],\n});\n\nexport const BSCToolbox = ({\n provider,\n signer,\n}: { signer?: Signer; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer, isEIP1559Compatible: false });\n const chain = Chain.BinanceSmartChain;\n\n return {\n ...evmToolbox,\n getNetworkParams,\n estimateTransactionFee: (txObject: EVMTxBaseParams, feeOptionKey: FeeOption) =>\n estimateTransactionFee(txObject, feeOptionKey, chain, provider, false),\n getBalance: (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({ provider: overwriteProvider || provider, address, chain, potentialScamFilter }),\n };\n};\n",
13
+ "import { Chain, FeeOption } from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, JsonRpcSigner, Signer } from \"ethers\";\n\nimport { type EVMTxBaseParams, estimateTransactionFee, getBalance } from \"../index\";\n\nimport { multicallAbi } from \"../contracts/eth/multicall\";\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nexport const ETHToolbox = ({\n signer,\n provider,\n}: { signer?: Signer | JsonRpcSigner; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer });\n const chain = Chain.Ethereum;\n\n async function multicall(\n callTuples: { address: string; data: string }[],\n multicallAddress = \"0x5ba1e12693dc8f9c48aad8770482f4739beed696\",\n funcName = \"aggregate\",\n feeOptionKey: FeeOption = FeeOption.Fast,\n ) {\n const txObject = await evmToolbox.createContractTxObject({\n contractAddress: multicallAddress,\n abi: multicallAbi,\n funcName,\n funcParams: [callTuples],\n });\n\n return evmToolbox.sendTransaction(txObject, feeOptionKey);\n }\n\n return {\n ...evmToolbox,\n multicall,\n estimateTransactionFee: (txObject: EVMTxBaseParams, feeOptionKey?: FeeOption) =>\n estimateTransactionFee(txObject, feeOptionKey, chain, provider),\n getBalance: (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({ provider: overwriteProvider || provider, address, chain, potentialScamFilter }),\n };\n};\n",
14
+ "export const multicallAbi = [\n {\n inputs: [\n {\n components: [\n { internalType: \"address\", name: \"target\", type: \"address\" },\n { internalType: \"bytes\", name: \"callData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Call[]\",\n name: \"calls\",\n type: \"tuple[]\",\n },\n ],\n name: \"aggregate\",\n outputs: [\n { internalType: \"uint256\", name: \"blockNumber\", type: \"uint256\" },\n { internalType: \"bytes[]\", name: \"returnData\", type: \"bytes[]\" },\n ],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [\n {\n components: [\n { internalType: \"address\", name: \"target\", type: \"address\" },\n { internalType: \"bytes\", name: \"callData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Call[]\",\n name: \"calls\",\n type: \"tuple[]\",\n },\n ],\n name: \"blockAndAggregate\",\n outputs: [\n { internalType: \"uint256\", name: \"blockNumber\", type: \"uint256\" },\n { internalType: \"bytes32\", name: \"blockHash\", type: \"bytes32\" },\n {\n components: [\n { internalType: \"bool\", name: \"success\", type: \"bool\" },\n { internalType: \"bytes\", name: \"returnData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Result[]\",\n name: \"returnData\",\n type: \"tuple[]\",\n },\n ],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"blockNumber\", type: \"uint256\" }],\n name: \"getBlockHash\",\n outputs: [{ internalType: \"bytes32\", name: \"blockHash\", type: \"bytes32\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"getBlockNumber\",\n outputs: [{ internalType: \"uint256\", name: \"blockNumber\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"getCurrentBlockCoinbase\",\n outputs: [{ internalType: \"address\", name: \"coinbase\", type: \"address\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"getCurrentBlockDifficulty\",\n outputs: [{ internalType: \"uint256\", name: \"difficulty\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"getCurrentBlockGasLimit\",\n outputs: [{ internalType: \"uint256\", name: \"gaslimit\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"getCurrentBlockTimestamp\",\n outputs: [{ internalType: \"uint256\", name: \"timestamp\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"address\", name: \"addr\", type: \"address\" }],\n name: \"getEthBalance\",\n outputs: [{ internalType: \"uint256\", name: \"balance\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"getLastBlockHash\",\n outputs: [{ internalType: \"bytes32\", name: \"blockHash\", type: \"bytes32\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [\n { internalType: \"bool\", name: \"requireSuccess\", type: \"bool\" },\n {\n components: [\n { internalType: \"address\", name: \"target\", type: \"address\" },\n { internalType: \"bytes\", name: \"callData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Call[]\",\n name: \"calls\",\n type: \"tuple[]\",\n },\n ],\n name: \"tryAggregate\",\n outputs: [\n {\n components: [\n { internalType: \"bool\", name: \"success\", type: \"bool\" },\n { internalType: \"bytes\", name: \"returnData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Result[]\",\n name: \"returnData\",\n type: \"tuple[]\",\n },\n ],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [\n { internalType: \"bool\", name: \"requireSuccess\", type: \"bool\" },\n {\n components: [\n { internalType: \"address\", name: \"target\", type: \"address\" },\n { internalType: \"bytes\", name: \"callData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Call[]\",\n name: \"calls\",\n type: \"tuple[]\",\n },\n ],\n name: \"tryBlockAndAggregate\",\n outputs: [\n { internalType: \"uint256\", name: \"blockNumber\", type: \"uint256\" },\n { internalType: \"bytes32\", name: \"blockHash\", type: \"bytes32\" },\n {\n components: [\n { internalType: \"bool\", name: \"success\", type: \"bool\" },\n { internalType: \"bytes\", name: \"returnData\", type: \"bytes\" },\n ],\n internalType: \"struct Multicall2.Result[]\",\n name: \"returnData\",\n type: \"tuple[]\",\n },\n ],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n];\n",
15
+ "import { Chain } from \"@swapkit/helpers\";\n\nimport { ARBToolbox } from \"./arb\";\nimport { AVAXToolbox } from \"./avax\";\nimport { BASEToolbox } from \"./base\";\nimport { BSCToolbox } from \"./bsc\";\nimport { ETHToolbox } from \"./eth\";\nimport { MATICToolbox } from \"./matic\";\nimport { OPToolbox } from \"./op\";\n\ntype ToolboxType = {\n ARB: typeof ARBToolbox;\n AVAX: typeof AVAXToolbox;\n BASE: typeof BASEToolbox;\n BSC: typeof BSCToolbox;\n ETH: typeof ETHToolbox;\n MATIC: typeof MATICToolbox;\n OP: typeof OPToolbox;\n};\n\nexport const getToolboxByChain = <T extends keyof ToolboxType>(chain: T): ToolboxType[T] => {\n switch (chain) {\n case Chain.Avalanche:\n return AVAXToolbox as ToolboxType[T];\n case Chain.Arbitrum:\n return ARBToolbox as ToolboxType[T];\n case Chain.Base:\n return BASEToolbox as ToolboxType[T];\n case Chain.Optimism:\n return OPToolbox as ToolboxType[T];\n case Chain.Polygon:\n return MATICToolbox as ToolboxType[T];\n case Chain.BinanceSmartChain:\n return BSCToolbox as ToolboxType[T];\n case Chain.Ethereum:\n return ETHToolbox as ToolboxType[T];\n default:\n throw new Error(`Chain ${chain} is not supported`);\n }\n};\n\nexport { evmValidateAddress } from \"./EVMToolbox\";\n",
16
+ "import {\n BaseDecimal,\n Chain,\n ChainId,\n ChainToExplorerUrl,\n type FeeOption,\n SKConfig,\n} from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Signer } from \"ethers\";\n\nimport { type EVMTxBaseParams, estimateTransactionFee, getBalance } from \"../index\";\n\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nconst getNetworkParams = () => ({\n chainId: ChainId.BaseHex,\n chainName: \"Base Mainnet\",\n nativeCurrency: { name: \"Ethereum\", symbol: Chain.Ethereum, decimals: BaseDecimal.ETH },\n rpcUrls: [SKConfig.get(\"rpcUrls\")[Chain.Base]],\n blockExplorerUrls: [ChainToExplorerUrl[Chain.Base]],\n});\n\nexport const BASEToolbox = ({\n provider,\n signer,\n}: { signer?: Signer; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer });\n const chain = Chain.Base;\n\n return {\n ...evmToolbox,\n getNetworkParams,\n estimateTransactionFee: (txObject: EVMTxBaseParams, feeOptionKey: FeeOption) =>\n estimateTransactionFee(txObject, feeOptionKey, chain, provider),\n getBalance: async (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({ provider: overwriteProvider || provider, address, chain, potentialScamFilter }),\n };\n};\n",
17
+ "import {\n BaseDecimal,\n Chain,\n ChainId,\n ChainToExplorerUrl,\n type FeeOption,\n SKConfig,\n} from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Signer } from \"ethers\";\n\nimport { type EVMTxBaseParams, estimateTransactionFee, getBalance } from \"../index\";\n\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nconst getNetworkParams = () => ({\n chainId: ChainId.PolygonHex,\n chainName: \"Polygon Mainnet\",\n nativeCurrency: { name: \"Polygon\", symbol: Chain.Polygon, decimals: BaseDecimal.MATIC },\n rpcUrls: [SKConfig.get(\"rpcUrls\")[Chain.Polygon]],\n blockExplorerUrls: [ChainToExplorerUrl[Chain.Polygon]],\n});\n\nexport const MATICToolbox = ({\n provider,\n signer,\n}: { signer?: Signer; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer });\n const chain = Chain.Polygon;\n\n return {\n ...evmToolbox,\n getNetworkParams,\n estimateTransactionFee: (txObject: EVMTxBaseParams, feeOptionKey: FeeOption) =>\n estimateTransactionFee(txObject, feeOptionKey, chain, provider),\n getBalance: (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({ provider: overwriteProvider || provider, address, chain, potentialScamFilter }),\n };\n};\n",
18
+ "import {\n BaseDecimal,\n Chain,\n ChainId,\n ChainToExplorerUrl,\n FeeOption,\n SKConfig,\n} from \"@swapkit/helpers\";\nimport type { BrowserProvider, JsonRpcProvider, Signer, TransactionRequest } from \"ethers\";\nimport { Contract, Transaction } from \"ethers\";\n\nimport { gasOracleAbi } from \"../contracts/op/gasOracle\";\nimport { getBalance } from \"../index\";\n\nimport { EVMToolbox } from \"./EVMToolbox\";\n\nconst GAS_PRICE_ORACLE_ADDRESS = \"0x420000000000000000000000000000000000000f\";\n\nexport const connectGasPriceOracle = (provider: JsonRpcProvider | BrowserProvider) => {\n return new Contract(GAS_PRICE_ORACLE_ADDRESS, gasOracleAbi, provider);\n};\n\nexport const getL1GasPrice = (provider: JsonRpcProvider | BrowserProvider) => {\n const gasPriceOracle = connectGasPriceOracle(provider);\n\n if (gasPriceOracle && \"l1BaseFee\" in gasPriceOracle) {\n return gasPriceOracle?.l1BaseFee() as unknown as bigint;\n }\n\n return undefined;\n};\n\nconst _serializeTx = async (\n provider: JsonRpcProvider | BrowserProvider,\n { data, from, to, gasPrice, type, gasLimit, nonce }: TransactionRequest,\n) => {\n if (!to) throw new Error(\"Missing to address\");\n\n return Transaction.from({\n data,\n to: to as string,\n gasPrice,\n type,\n gasLimit,\n nonce: nonce ? nonce : from ? await provider.getTransactionCount(from) : 0,\n }).serialized;\n};\n\nexport const estimateL1GasCost = async (\n provider: JsonRpcProvider | BrowserProvider,\n tx: TransactionRequest,\n) => {\n const gasPriceOracle = await connectGasPriceOracle(provider);\n const serializedTx = await _serializeTx(provider, tx);\n\n if (gasPriceOracle && \"getL1Fee\" in gasPriceOracle) {\n return gasPriceOracle.getL1Fee(serializedTx);\n }\n};\n\nexport const estimateL2GasCost = async (\n provider: JsonRpcProvider | BrowserProvider,\n tx: TransactionRequest,\n) => {\n const l2GasPrice = await provider.send(\"eth_gasPrice\", []);\n const l2GasCost = await provider.estimateGas(tx);\n return l2GasPrice.mul(l2GasCost);\n};\n\nexport const estimateTotalGasCost = async (\n provider: JsonRpcProvider | BrowserProvider,\n tx: TransactionRequest,\n) => {\n const l1GasCost = await estimateL1GasCost(provider, tx);\n const l2GasCost = await estimateL2GasCost(provider, tx);\n return l1GasCost.add(l2GasCost);\n};\n\nexport const estimateL1Gas = async (\n provider: JsonRpcProvider | BrowserProvider,\n tx: TransactionRequest,\n) => {\n const gasPriceOracle = connectGasPriceOracle(provider);\n const serializedTx = await _serializeTx(provider, tx);\n\n if (gasPriceOracle && \"getL1GasUsed\" in gasPriceOracle) {\n return gasPriceOracle.getL1GasUsed(serializedTx);\n }\n};\n\nconst getNetworkParams = () => ({\n chainId: ChainId.OptimismHex,\n chainName: \"Optimism\",\n nativeCurrency: { name: \"Ethereum\", symbol: Chain.Ethereum, decimals: BaseDecimal.ETH },\n rpcUrls: [SKConfig.get(\"rpcUrls\")[Chain.Optimism]],\n blockExplorerUrls: [ChainToExplorerUrl[Chain.Optimism]],\n});\n\nconst estimateGasPrices = async (provider: JsonRpcProvider | BrowserProvider) => {\n try {\n const { maxFeePerGas, maxPriorityFeePerGas, gasPrice } = await provider.getFeeData();\n const l1GasPrice = await getL1GasPrice(provider);\n const price = gasPrice as bigint;\n\n if (!(maxFeePerGas && maxPriorityFeePerGas)) {\n throw new Error(\"No fee data available\");\n }\n\n return {\n [FeeOption.Average]: {\n l1GasPrice,\n gasPrice,\n maxFeePerGas,\n maxPriorityFeePerGas,\n },\n [FeeOption.Fast]: {\n l1GasPrice: ((l1GasPrice || 0n) * 15n) / 10n,\n gasPrice: (price * 15n) / 10n,\n maxFeePerGas,\n maxPriorityFeePerGas: (maxPriorityFeePerGas * 15n) / 10n,\n },\n [FeeOption.Fastest]: {\n l1GasPrice: (l1GasPrice || 0n) * 2n,\n gasPrice: price * 2n,\n maxFeePerGas,\n maxPriorityFeePerGas: maxPriorityFeePerGas * 2n,\n },\n };\n } catch (error) {\n throw new Error(\n `Failed to estimate gas price: ${(error as any).msg ?? (error as any).toString()}`,\n );\n }\n};\n\nexport const OPToolbox = ({\n provider,\n signer,\n}: { signer?: Signer; provider: JsonRpcProvider | BrowserProvider }) => {\n const evmToolbox = EVMToolbox({ provider, signer });\n\n return {\n ...evmToolbox,\n estimateTotalGasCost: (tx: TransactionRequest) => estimateTotalGasCost(provider, tx),\n estimateL1GasCost: (tx: TransactionRequest) => estimateL1GasCost(provider, tx),\n estimateL2GasCost: (tx: TransactionRequest) => estimateL2GasCost(provider, tx),\n getL1GasPrice: () => getL1GasPrice(provider),\n estimateL1Gas: (tx: TransactionRequest) => estimateL1Gas(provider, tx),\n getNetworkParams,\n estimateGasPrices: () => estimateGasPrices(provider),\n getBalance: (\n address: string,\n potentialScamFilter = true,\n overwriteProvider?: JsonRpcProvider | BrowserProvider,\n ) =>\n getBalance({\n provider: overwriteProvider || provider,\n address,\n chain: Chain.Optimism,\n potentialScamFilter,\n }),\n };\n};\n",
19
+ "export const gasOracleAbi = [\n {\n inputs: [{ internalType: \"address\", name: \"_owner\", type: \"address\" }],\n stateMutability: \"nonpayable\",\n type: \"constructor\",\n },\n {\n anonymous: false,\n inputs: [{ indexed: false, internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n name: \"DecimalsUpdated\",\n type: \"event\",\n },\n {\n anonymous: false,\n inputs: [{ indexed: false, internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n name: \"GasPriceUpdated\",\n type: \"event\",\n },\n {\n anonymous: false,\n inputs: [{ indexed: false, internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n name: \"L1BaseFeeUpdated\",\n type: \"event\",\n },\n {\n anonymous: false,\n inputs: [{ indexed: false, internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n name: \"OverheadUpdated\",\n type: \"event\",\n },\n {\n anonymous: false,\n inputs: [\n { indexed: true, internalType: \"address\", name: \"previousOwner\", type: \"address\" },\n { indexed: true, internalType: \"address\", name: \"newOwner\", type: \"address\" },\n ],\n name: \"OwnershipTransferred\",\n type: \"event\",\n },\n {\n anonymous: false,\n inputs: [{ indexed: false, internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n name: \"ScalarUpdated\",\n type: \"event\",\n },\n {\n inputs: [],\n name: \"decimals\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"gasPrice\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"bytes\", name: \"_data\", type: \"bytes\" }],\n name: \"getL1Fee\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"bytes\", name: \"_data\", type: \"bytes\" }],\n name: \"getL1GasUsed\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"l1BaseFee\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"overhead\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"owner\",\n outputs: [{ internalType: \"address\", name: \"\", type: \"address\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"renounceOwnership\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [],\n name: \"scalar\",\n outputs: [{ internalType: \"uint256\", name: \"\", type: \"uint256\" }],\n stateMutability: \"view\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"_decimals\", type: \"uint256\" }],\n name: \"setDecimals\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"_gasPrice\", type: \"uint256\" }],\n name: \"setGasPrice\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"_baseFee\", type: \"uint256\" }],\n name: \"setL1BaseFee\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"_overhead\", type: \"uint256\" }],\n name: \"setOverhead\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"uint256\", name: \"_scalar\", type: \"uint256\" }],\n name: \"setScalar\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n {\n inputs: [{ internalType: \"address\", name: \"newOwner\", type: \"address\" }],\n name: \"transferOwnership\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n];\n"
20
+ ],
21
+ "mappings": "6BAAA,gBACE,oBACA,oBAEA,eACA,8BACA,eACA,0BAGF,eAAe,EAAmB,EAAG,WAAgC,CACnE,IAAM,EAAS,GAAS,IAAI,SAAS,EAAE,WAAa,WAE5C,SAAS,CAAC,GAAM,MAAM,GAAc,IAC1C,2CAA2C,IAC3C,CAAE,aAAc,CAAE,QAAO,CAAE,CAC7B,EAEA,OAAO,EACJ,OAAO,EAAG,WAAa,UAAU,gBAAiB,GAAU,IAAe,GAAG,EAC9E,IAAI,EAAG,WAAa,SAAQ,WAAU,QAAS,GAAgB,iBAAkB,CAChF,MAAO,EAAM,SACb,QAAS,OAAO,SAAS,CAAQ,EACjC,OAAQ,EAAe,GAAG,KAAU,IAAiB,EACrD,MAAO,GAAwB,CAC7B,MAAO,OAAO,CAAU,EACxB,QAAS,OAAO,SAAS,CAAQ,EACjC,cAAe,OAAO,SAAS,CAAQ,CACzC,CAAC,CACH,EAAE,EAGN,eAAe,EAAkB,EAAG,QAAO,WAA8C,CACvF,IAAM,EAAS,GAAS,IAAI,SAAS,EAAE,SAEvC,IAAK,EAEH,OADA,GAAS,GAAM,mEAAmE,EAC3E,CAA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GAAc,EAAU,CAAE,EACrE,oBACA,kBAAmB,IAAM,GAAkB,CAAQ,EACnD,WAAY,CACV,EACA,EAAsB,GACtB,IAEA,EAAW,CACT,SAAU,GAAqB,EAC/B,UACA,MAAO,EAAM,SACb,qBACF,CAAC,CACL,GH7IK,IAAM,GAAoB,CAA8B,IAA6B,CAC1F,OAAQ,QACD,EAAM,UACT,OAAO,QACJ,EAAM,SACT,OAAO,QACJ,EAAM,KACT,OAAO,QACJ,EAAM,SACT,OAAO,QACJ,EAAM,QACT,OAAO,QACJ,EAAM,kBACT,OAAO,QACJ,EAAM,SACT,OAAO,WAEP,MAAM,IAAI,MAAM,SAAS,oBAAwB",
22
+ "debugId": "83CFF03F654942D264756E2164756E21",
23
+ "names": []
24
+ }
package/dist/index.cjs ADDED
@@ -0,0 +1,3 @@
1
+ module.exports=void 0;
2
+
3
+ //# debugId=1B76E02F7058E81E64756E2164756E21
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "1B76E02F7058E81E64756E2164756E21",
8
+ "names": []
9
+ }
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ import"./chunk-tvrdndbw.js";var c=void 0;export{c as default};
2
+
3
+ //# debugId=6A33823FB1BB3FA564756E2164756E21
@@ -0,0 +1,9 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [
5
+ ],
6
+ "mappings": "",
7
+ "debugId": "6A33823FB1BB3FA564756E2164756E21",
8
+ "names": []
9
+ }
@@ -0,0 +1,3 @@
1
+ var D={};$(D,{validateAddress:()=>Y,RadixToolbox:()=>B});module.exports=_(D);var W=require("@radixdlt/babylon-gateway-api-sdk"),X=require("@radixdlt/radix-dapp-toolkit"),O=require("@swapkit/helpers");function Y(j){return j.startsWith("account_rdx1")&&j.length===66}function q({networkApi:j}){return async function H(G){let L=await x({address:G,networkApi:j});return T({resources:L,networkApi:j})}}async function x({address:j,networkApi:H}){let G=!0,L,K=[],J=await v(H);while(G){let Q={address:j,limit_per_page:100,cursor:L,at_ledger_state:{state_version:J}},M=await H.state.innerClient.entityFungiblesPage({stateEntityFungiblesPageRequest:Q});if(K=K.concat(M.items),M.next_cursor)L=M.next_cursor;else G=!1}return K}async function T({resources:j,networkApi:H}){let G=[],L=50,K=[];for(let J=0;J<j.length;J+=50)K.push(j.slice(J,J+50));for(let J of K){let Q=J.map((z)=>z.resource_address),M=await H.state.getEntityDetailsVaultAggregated(Q),V=new Map;for(let z of M)if(z.details!==void 0){let N=z.metadata?.items.find((Z)=>Z.key==="symbol"),U=N?.value.typed.type==="String"?N.value.typed.value:"?";if(z.details.type==="FungibleResource")V.set(z.address,{decimals:z.details.divisibility,symbol:U})}for(let z of J)if(z.aggregation_level==="Global"){let N=V.get(z.resource_address)||{decimals:0,symbol:"?"},U=O.AssetValue.from({asset:N.symbol!==O.Chain.Radix?`${O.Chain.Radix}.${N.symbol}-${z.resource_address}`:"XRD.XRD",value:z.amount});G.push(U)}}return G}async function v(j){return j.status.getCurrent().then((H)=>H.ledger_state.state_version)}var B=async({dappConfig:j})=>{let H=X.RadixDappToolkit({...j,networkId:j.network?.networkId||1}),G=W.GatewayApiClient.initialize(H.gatewayApi.clientConfig);return{networkApi:G,getBalance:q({networkApi:G}),getAddress:()=>{return""},validateAddress:Y,signAndBroadcast:()=>{throw new Error("Not implemented")}}};
2
+
3
+ //# debugId=65EA723391DF799E64756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/radix/index.ts"],
4
+ "sourcesContent": [
5
+ "import {\n type FungibleResourcesCollectionItem,\n GatewayApiClient,\n type StateEntityDetailsVaultResponseItem,\n type StateEntityFungiblesPageRequest,\n type StateEntityFungiblesPageResponse,\n} from \"@radixdlt/babylon-gateway-api-sdk\";\nimport { RadixDappToolkit } from \"@radixdlt/radix-dapp-toolkit\";\nimport { AssetValue, Chain, type SKConfigIntegrations } from \"@swapkit/helpers\";\n\nexport type RadixWallets = {\n [Chain.Radix]: Awaited<ReturnType<typeof RadixToolbox>>;\n};\n\ntype RadixGetBalanceParams = {\n address: string;\n networkApi: GatewayApiClient;\n};\n// Could not find anything sync in SDK, ask Radix team\nexport function validateAddress(address: string) {\n return address.startsWith(\"account_rdx1\") && address.length === 66;\n}\n\nfunction getBalance({ networkApi }: { networkApi: GatewayApiClient }) {\n return async function getBalance(address: string) {\n const fungibleResources = await fetchFungibleResources({ address, networkApi });\n const fungibleBalances = convertResourcesToBalances({\n resources: fungibleResources,\n networkApi,\n });\n return fungibleBalances;\n };\n}\n\nasync function fetchFungibleResources({\n address,\n networkApi,\n}: RadixGetBalanceParams): Promise<FungibleResourcesCollectionItem[]> {\n let hasNextPage = true;\n let nextCursor: string | undefined;\n let fungibleResources: FungibleResourcesCollectionItem[] = [];\n const stateVersion = await currentStateVersion(networkApi);\n while (hasNextPage) {\n const stateEntityFungiblesPageRequest: StateEntityFungiblesPageRequest = {\n address: address,\n limit_per_page: 100,\n cursor: nextCursor,\n at_ledger_state: {\n state_version: stateVersion,\n },\n };\n\n const stateEntityFungiblesPageResponse: StateEntityFungiblesPageResponse =\n await networkApi.state.innerClient.entityFungiblesPage({\n stateEntityFungiblesPageRequest: stateEntityFungiblesPageRequest,\n });\n\n fungibleResources = fungibleResources.concat(stateEntityFungiblesPageResponse.items);\n if (stateEntityFungiblesPageResponse.next_cursor) {\n nextCursor = stateEntityFungiblesPageResponse.next_cursor;\n } else {\n hasNextPage = false;\n }\n }\n return fungibleResources;\n}\n\n// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>\nasync function convertResourcesToBalances({\n resources,\n networkApi,\n}: {\n resources: FungibleResourcesCollectionItem[]; //| NonFungibleResourcesCollectionItem[];\n networkApi: GatewayApiClient;\n}): Promise<AssetValue[]> {\n const balances: AssetValue[] = [];\n const BATCH_SIZE = 50;\n\n // Split resources into batches of up to 50 items\n const resourceBatches: FungibleResourcesCollectionItem[][] = [];\n for (let i = 0; i < resources.length; i += BATCH_SIZE) {\n resourceBatches.push(resources.slice(i, i + BATCH_SIZE));\n }\n\n for (const batch of resourceBatches) {\n const addresses = batch.map((item) => item.resource_address);\n const response: StateEntityDetailsVaultResponseItem[] =\n await networkApi.state.getEntityDetailsVaultAggregated(addresses);\n\n const divisibilities = new Map<string, { decimals: number; symbol: string }>();\n\n for (const result of response) {\n if (result.details !== undefined) {\n const metaDataSymbol = result.metadata?.items.find((item) => item.key === \"symbol\");\n const symbol =\n metaDataSymbol?.value.typed.type === \"String\" ? metaDataSymbol.value.typed.value : \"?\";\n\n if (result.details.type === \"FungibleResource\") {\n divisibilities.set(result.address, {\n decimals: result.details.divisibility,\n symbol,\n });\n }\n }\n }\n\n for (const item of batch) {\n if (item.aggregation_level === \"Global\") {\n const assetInfo = divisibilities.get(item.resource_address) || { decimals: 0, symbol: \"?\" };\n\n const balance = AssetValue.from({\n asset:\n assetInfo.symbol !== Chain.Radix\n ? `${Chain.Radix}.${assetInfo.symbol}-${item.resource_address}`\n : \"XRD.XRD\",\n value: item.amount,\n });\n balances.push(balance);\n }\n }\n }\n\n return balances;\n}\n\nasync function currentStateVersion(networkApi: GatewayApiClient) {\n return networkApi.status.getCurrent().then((status) => status.ledger_state.state_version);\n}\n\nexport const RadixToolbox = async ({\n dappConfig,\n}: { dappConfig: SKConfigIntegrations[\"radix\"] }) => {\n const radixToolkit = RadixDappToolkit({\n ...dappConfig,\n networkId: dappConfig.network?.networkId || 1,\n });\n\n const networkApi = GatewayApiClient.initialize(radixToolkit.gatewayApi.clientConfig);\n\n return {\n networkApi,\n getBalance: getBalance({ networkApi }),\n getAddress: () => {\n return \"\";\n },\n validateAddress,\n signAndBroadcast: (() => {\n throw new Error(\"Not implemented\");\n }) as (params: any) => Promise<string>,\n };\n};\n"
6
+ ],
7
+ "mappings": "6EAMO,IANP,+CAOA,0CACA,8BAWO,SAAS,CAAe,CAAC,EAAiB,CAC/C,OAAO,EAAQ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QAAQ,aACzB,QACF,CAAC,EAKP,QAAW,KAAQ,EACjB,GAAI,EAAK,oBAAsB,SAAU,CACvC,IAAM,EAAY,EAAe,IAAI,EAAK,gBAAgB,GAAK,CAAE,SAAU,EAAG,OAAQ,GAAI,EAEpF,EAAU,aAAW,KAAK,CAC9B,MACE,EAAU,SAAW,QAAM,MACvB,GAAG,QAAM,SAAS,EAAU,UAAU,EAAK,mBAC3C,UACN,MAAO,EAAK,MACd,CAAC,EACD,EAAS,KAAK,CAAO,GAK3B,OAAO,EAGT,eAAe,CAAmB,CAAC,EAA8B,CAC/D,OAAO,EAAW,OAAO,WAAW,EAAE,KAAK,CAAC,IAAW,EAAO,aAAa,aAAa,EAGnF,IAAM,EAAe,OAC1B,gBACmD,CACnD,IAAM,EAAe,mBAAiB,IACjC,EACH,UAAW,EAAW,SAAS,WAAa,CAC9C,CAAC,EAEK,EAAa,mBAAiB,WAAW,EAAa,WAAW,YAAY,EAEnF,MAAO,CACL,aACA,WAAY,EAAW,CAAE,YAAW,CAAC,EACrC,WAAY,IAAM,CAChB,MAAO,IAET,kBACA,iBAAmB,IAAM,CACvB,MAAM,IAAI,MAAM,iBAAiB,EAErC",
8
+ "debugId": "65EA723391DF799E64756E2164756E21",
9
+ "names": []
10
+ }
@@ -0,0 +1,3 @@
1
+ import"../chunk-tvrdndbw.js";import{GatewayApiClient as X}from"@radixdlt/babylon-gateway-api-sdk";import{RadixDappToolkit as Y}from"@radixdlt/radix-dapp-toolkit";import{AssetValue as Z,Chain as V}from"@swapkit/helpers";function _(j){return j.startsWith("account_rdx1")&&j.length===66}function $({networkApi:j}){return async function H(G){let L=await q({address:G,networkApi:j});return x({resources:L,networkApi:j})}}async function q({address:j,networkApi:H}){let G=!0,L,K=[],J=await T(H);while(G){let O={address:j,limit_per_page:100,cursor:L,at_ledger_state:{state_version:J}},M=await H.state.innerClient.entityFungiblesPage({stateEntityFungiblesPageRequest:O});if(K=K.concat(M.items),M.next_cursor)L=M.next_cursor;else G=!1}return K}async function x({resources:j,networkApi:H}){let G=[],L=50,K=[];for(let J=0;J<j.length;J+=50)K.push(j.slice(J,J+50));for(let J of K){let O=J.map((z)=>z.resource_address),M=await H.state.getEntityDetailsVaultAggregated(O),U=new Map;for(let z of M)if(z.details!==void 0){let N=z.metadata?.items.find((W)=>W.key==="symbol"),Q=N?.value.typed.type==="String"?N.value.typed.value:"?";if(z.details.type==="FungibleResource")U.set(z.address,{decimals:z.details.divisibility,symbol:Q})}for(let z of J)if(z.aggregation_level==="Global"){let N=U.get(z.resource_address)||{decimals:0,symbol:"?"},Q=Z.from({asset:N.symbol!==V.Radix?`${V.Radix}.${N.symbol}-${z.resource_address}`:"XRD.XRD",value:z.amount});G.push(Q)}}return G}async function T(j){return j.status.getCurrent().then((H)=>H.ledger_state.state_version)}var I=async({dappConfig:j})=>{let H=Y({...j,networkId:j.network?.networkId||1}),G=X.initialize(H.gatewayApi.clientConfig);return{networkApi:G,getBalance:$({networkApi:G}),getAddress:()=>{return""},validateAddress:_,signAndBroadcast:()=>{throw new Error("Not implemented")}}};export{_ as validateAddress,I as RadixToolbox};
2
+
3
+ //# debugId=1EC1285B373EA15064756E2164756E21