@parifi/sdk
Version:
Parifi SDK with common utility functions
1 lines • 25.1 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/subgraph/accounts/index.ts","../../../src/subgraph/accounts/subgraphQueries.ts","../../../src/common/constants.ts","../../../src/common/helpers.ts"],"sourcesContent":["import Decimal from 'decimal.js';\nimport { request } from 'graphql-request';\nimport {\n checkExistingUser,\n depositedCollateralForSnxAccountsQuery,\n fetchAccountByWalletAddress,\n fetchIntegratorFees,\n fetchLeaderboardUserData,\n fetchRealizedPnlData,\n} from './subgraphQueries';\nimport { convertWeiToEther, DECIMAL_ZERO } from '../../common';\nimport { CollateralDeposit, LeaderboardUserData } from '../../interfaces/sdkTypes';\n\nexport interface depositedCollateralAccountIdResponse {\n owner: {\n id: string;\n };\n accountId: string;\n collateralDeposits: CollateralDeposit[];\n}\n\n/// Returns the Realized PNL for positions and vaults for a user address\nexport const getRealizedPnlForUser = async (\n subgraphEndpoint: string,\n userAddress: string,\n): Promise<{\n totalRealizedPnlPositions: Decimal;\n totalRealizedPnlVaults: Decimal;\n}> => {\n try {\n // Interface to map fetched data\n interface RealizedPnlSubgraphResponse {\n account: {\n id: string;\n totalRealizedPnlPositions: string;\n totalRealizedPnlVaults: string;\n };\n }\n\n const query = fetchRealizedPnlData(userAddress);\n const subgraphResponse = await request(subgraphEndpoint, query);\n const realizedPnlResponse: RealizedPnlSubgraphResponse = subgraphResponse as unknown as RealizedPnlSubgraphResponse;\n\n if (realizedPnlResponse === null || realizedPnlResponse.account === null) {\n console.log('Users Realized Pnl data not found');\n return { totalRealizedPnlPositions: DECIMAL_ZERO, totalRealizedPnlVaults: DECIMAL_ZERO };\n }\n const totalRealizedPnlPositions = new Decimal(realizedPnlResponse.account.totalRealizedPnlPositions);\n const totalRealizedPnlVaults = new Decimal(realizedPnlResponse.account.totalRealizedPnlVaults);\n return { totalRealizedPnlPositions, totalRealizedPnlVaults };\n } catch (error) {\n throw error;\n }\n};\n\n// Returns the leaderboard page details for a user address\nexport const getLeaderboardUserData = async (\n subgraphEndpoint: string,\n userAddresses: string[],\n): Promise<LeaderboardUserData[]> => {\n const subgraphResponse: {\n accounts: LeaderboardUserData[];\n } = await request(subgraphEndpoint, fetchLeaderboardUserData(userAddresses));\n\n const leaderboardUserData: LeaderboardUserData[] = subgraphResponse.accounts as LeaderboardUserData[];\n return leaderboardUserData;\n};\n\nexport const getAccountByAddress = async (subgraphEndpoint: string, userAddresses: string) => {\n const subgraphResponse: any = await request(subgraphEndpoint, fetchAccountByWalletAddress(userAddresses));\n if (!subgraphResponse) throw new Error('Error while fetching account data');\n return subgraphResponse?.wallet;\n};\n\nexport const getFeesByAddress = async (\n subgraphEndpoint: string,\n userAddresses: string[],\n): Promise<Map<string, number>> => {\n // Temp interface to map subgraph response\n interface SNXAccountResponse {\n id: string;\n accountId: string;\n owner: { id: string };\n integratorFeesGenerated: string;\n }\n\n const feesByAddress = new Map<string, number>();\n\n const subgraphResponse: any = await request(subgraphEndpoint, fetchIntegratorFees(userAddresses));\n if (!subgraphResponse) throw new Error('Error while fetching account data');\n\n const snxAccounts: SNXAccountResponse[] = subgraphResponse?.snxAccounts;\n snxAccounts.forEach((account) => {\n const userFees = feesByAddress.get(account.owner.id);\n if (userFees) {\n // Multiple SNX accounts exist for the wallet address, add fees to previous values\n const totalFees = userFees + convertWeiToEther(account.integratorFeesGenerated);\n feesByAddress.set(account.owner.id, totalFees);\n } else {\n feesByAddress.set(account.owner.id, convertWeiToEther(account.integratorFeesGenerated));\n }\n });\n return feesByAddress;\n};\n\nexport const checkIfExistingUser = async (subgraphEndpoint: string, userAddress: string) => {\n interface SNXAccountResponse {\n id: string;\n accountId: string;\n totalOrdersCount: string;\n }\n\n const subgraphResponse: any = await request(subgraphEndpoint, checkExistingUser(userAddress));\n if (!subgraphResponse) throw new Error('Error while fetching account data');\n\n // A wallet can have multiple SNX accounts\n // The function returns true if it has any one snxAccount with past orders\n const snxAccounts: SNXAccountResponse[] = subgraphResponse?.snxAccounts;\n let isExisting = false;\n for (let index = 0; index < snxAccounts.length; index++) {\n if (Number(snxAccounts[index].totalOrdersCount) > 0) {\n isExisting = true;\n break;\n }\n }\n\n return isExisting;\n};\n\nexport const depositedCollateralForSnxAccounts = async (subgraphEndpoint: string, accountIds: string[]) => {\n const subgraphResponse: any = await request(subgraphEndpoint, depositedCollateralForSnxAccountsQuery(accountIds));\n if (!subgraphResponse) throw new Error('Error while fetching account data');\n const snxAccounts: depositedCollateralAccountIdResponse[] = subgraphResponse?.snxAccounts;\n return snxAccounts;\n};\n","import { gql } from 'graphql-request';\n\n// The `fetchRealizedPnlData` query fetches the realized PnL for a user address\n// for vaults and positions\nexport const fetchRealizedPnlData = (userAddress: string) => gql`\n {\n account(id: \"${userAddress.toLowerCase()}\") {\n id\n totalRealizedPnlPositions\n totalRealizedPnlVaults\n }\n }\n`;\n\n/// Fetch Portfolio total for a set of addresses\n/// Portfolio total consists of\n/// 1. Realized PNL from positions and vaults - user.totalRealizedPnlPositions, user.totalRealizedPnlVaults\n/// 2. Unrealized PNL from positions - positions.netUnrealizedPnlInUsd\n/// 3. Deposited liquidity in vaults -\n/// 4. Deposited collateral of all open positions - positions.positionCollateral\nexport const fetchPortfolioData = (userAddresses: string[]) => gql`\n{\n accounts(where: {id_in: [${userAddresses.map((id) => `\"${id.toLowerCase()}\"`).join(', ')}]}) {\n id\n totalRealizedPnlPositions\n totalRealizedPnlVaults\n }\n positions(\n first: 1000\n orderBy: positionCollateral\n orderDirection: desc\n where: {\n user_in: [${userAddresses.map((id) => `\"${id.toLowerCase()}\"`).join(', ')}], \n status: OPEN\n }\n ) {\n id\n user {\n id\n }\n netUnrealizedPnlInUsd\n positionCollateral\n market {\n depositToken {\n decimals\n pyth {\n id\n price\n }\n }\n }\n }\n vaultPositions(\n first: 1000\n orderBy: sharesBalance\n orderDirection: desc\n where: {user_in: [${userAddresses.map((id) => `\"${id.toLowerCase()}\"`).join(', ')}]}\n ) {\n user {\n id\n }\n vault {\n id\n assetsPerShare\n sharesPerAsset\n depositToken {\n decimals\n pyth {\n id\n price\n }\n }\n }\n sharesBalance\n }\n}\n`;\n\nexport const fetchAccountByWalletAddress = (walletAddress: string) =>\n gql`\n {\n wallet(id: \"${walletAddress}\") {\n id\n }\n }\n`;\n\n// Fetch account specific data for a user address for Leaderboard view\nexport const fetchLeaderboardUserData = (userAddresses: string[]) => gql`\n{\n accounts(\n where: {id_in: [${userAddresses.map((id) => `\"${id}\"`).join(', ')}]}\n ) {\n id\n totalOrdersCount\n totalPositionsCount\n countProfitablePositions\n countLossPositions\n countLiquidatedPositions\n totalVolumeInUsd\n totalVolumeInUsdLongs\n totalVolumeInUsdShorts\n totalRealizedPnlPositions\n totalAccruedBorrowingFeesInUsd \n }\n}`;\n\nexport const fetchIntegratorFees = (userAddresses: string[]) => gql`\n {\n snxAccounts(where:\n {\n owner_in: [${userAddresses.map((id) => `\"${id}\"`).join(', ')}],\n type: PERP\n }) {\n id\n accountId\n owner {\n id\n }\n integratorFeesGenerated\n }\n }\n`;\n\nexport const checkExistingUser = (userAddress: string) => gql`\n {\n snxAccounts(\n where: {\n owner: \"${userAddress}\",\n type: PERP,\n }\n ) {\n id\n accountId\n\t\ttotalOrdersCount\n }\n}\n`;\n\nexport const depositedCollateralForSnxAccountsQuery = (accountIds: string[]) => gql`\n{\n snxAccounts\n (where :{\n accountId_in : [${accountIds.map((id) => `\"${id}\"`).join(', ')}]\n })\n {\n owner{\n id\n }\n accountId\n collateralDeposits {\n totalAmountDeposited\n totalAmountWithdrawn\n totalAmountLiquidated\n currentDepositedAmount\n collateralName\n collateralSymbol\n collateralDecimals\n }\n }\n}\n`;\n","import { Decimal } from 'decimal.js';\nimport { Address } from 'viem';\n\nexport const PRECISION_MULTIPLIER = new Decimal('10000');\nexport const DEVIATION_PRECISION_MULTIPLIER = new Decimal(10).pow(12);\nexport const SECONDS_IN_A_YEAR = new Decimal(365 * 24 * 60 * 60);\nexport const MAX_FEE = new Decimal(10000000); // 1% = 100_000\nexport const WAD = new Decimal(10).pow(18); // 10^18\nexport const EMPTY_BYTES32 = '0x0000000000000000000000000000000000000000000000000000000000000000';\n// export const PRICE_FEED_DECIMALS = 18;\n// export const PRICE_FEED_PRECISION = new Decimal(10).pow(PRICE_FEED_DECIMALS);\nexport const DECIMAL_10 = new Decimal(10);\nexport const DECIMAL_ZERO = new Decimal(0);\nexport const DEFAULT_BATCH_COUNT = 10;\nexport const BIGINT_ZERO = BigInt(0);\n\nexport const GAS_LIMIT_SETTLEMENT = 10000000; // 10M gas\nexport const GAS_LIMIT_LIQUIDATION = 15000000; // 15M gas\n\nexport const ONE_GWEI = 1000000000; // 10^9\nexport const DEFAULT_GAS_PRICE = 2 * ONE_GWEI; // 1 gwei\n\n// Constants for Pyth price ids of collaterals\nexport const PYTH_ETH_USD_PRICE_ID_BETA = '0xca80ba6dc32e08d06f1aa886011eed1d77c77be9eb761cc10d72b7d0a2fd57a6';\nexport const PYTH_ETH_USD_PRICE_ID_STABLE = '0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace';\n\nexport const PYTH_USDC_USD_PRICE_ID_BETA = '0x41f3625971ca2ed2263e78573fe5ce23e13d2558ed3f2e47ab0f84fb9e7ae722';\nexport const PYTH_USDC_USD_PRICE_ID_STABLE = '0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a';\n\n// Constants for Pimlico relayer\nexport const FACTORY_ADDRESS_SIMPLE_ACCOUNT = '0x91E60e0613810449d098b0b5Ec8b51A0FE8c8985';\n\n// Temporary constants\nexport const SUBGRAPH_HELPER_ADDRESS = '0xf012d32505df6853187170F00C7b789A8ecC41c2';\n\nexport const SYMBOL_TO_PYTH_FEED = new Map<string, string>([\n // market\n ['BTC', '0xc9d8b075a5c69303365ae23633d4e085199bf5c520a3b90fed1322a0342ffc33'],\n ['SOL', '0xef0d8b6fda2ceba41da15d4095d1da392a0d2f8ed0c6c7bc0f4cfac8c280b56d'],\n ['WIF', '0x4ca4beeca86f0d164160323817a4e42b10010a724c2217c6ee41b54cd4cc61fc'],\n ['ETH', '0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace'],\n ['AAVE', '0x2b9ab1e972a281585084148ba1389800799bd4be63b957507db1349314e47445'],\n ['ADA', '0x2a01deaec9e51a579277b34b122399984d0bbf57e2458a7e42fecd2829867a0d'],\n ['ARB', '0x3fa4252848f9f0a1480be62745a4629d9eb1322aebab8a791e344b3b9c1adcf5'],\n ['AVAX', '0x93da3352f9f1d105fdfe4971cfa80e9dd777bfc5d0f683ebb6e1294b92137bb7'],\n ['BCH', '0x3dd2b63686a450ec7290df3a1e0b583c0481f651351edfa7636f39aed55cf8a3'],\n ['BNB', '0x2f95862b045670cd22bee3114c39763a4a08beeb663b145d283c31d7d1101c4f'],\n ['CRV', '0xa19d04ac696c7a6616d291c7e5d1377cc8be437c327b75adb5dc1bad745fcae8'],\n ['DOGE', '0xdcef50dd0a4cd2dcc17e45df1676dcb336a11a61c69df7a0299b0150c672d25c'],\n ['DYDX', '0x6489800bb8974169adfe35937bf6736507097d13c190d760c557108c7e93a81b'],\n ['GMX', '0xb962539d0fcb272a494d65ea56f94851c2bcf8823935da05bd628916e2e9edbf'],\n ['LINK', '0x8ac0c70fff57e9aefdf5edf44b51d62c2d433653cbb2cf5cc06bb115af04d221'],\n ['LTC', '0x6e3f3fa8253588df9326580180233eb791e03b443a3ba7a1d892e73874e19a54'],\n ['MKR', '0x9375299e31c0deb9c6bc378e6329aab44cb48ec655552a70d4b9050346a30378'],\n ['NEAR', '0xc415de8d2eba7db216527dff4b60e8f3a5311c740dadb233e13e12547e226750'],\n ['OP', '0x385f64d993f7b77d8182ed5003d97c60aa3361f3cecfe711544d2d59165e9bdf'],\n ['ORDI', '0x193c739db502aadcef37c2589738b1e37bdb257d58cf1ab3c7ebc8e6df4e3ec0'],\n ['PEPE', '0xd69731a2e74ac1ce884fc3890f7ee324b6deb66147055249568869ed700882e4'],\n ['POL', '0xffd11c5a1cfd42f80afb2df4d9f264c15f956d68153335374ec10722edd70472'],\n ['PYTH', '0x0bbf28e9a841a1cc788f6a361b17ca072d0ea3098a1e5df1c3922d06719579ff'],\n ['RUNE', '0x5fcf71143bb70d41af4fa9aa1287e2efd3c5911cee59f909f915c9f61baacb1e'],\n ['SHIB', '0xf0d57deca57b3da2fe63a493f4c25925fdfd8edf834b20f93e1f84dbd1504d4a'],\n ['STX', '0xec7a775f46379b5e943c3526b1c8d54cd49749176b0b98e02dde68d1bd335c17'],\n ['TIA', '0x09f7c1d7dfbb7df2b8fe3d3d87ee94a2259d212da4f30c1f0540d066dfa44723'],\n ['UNI', '0x78d185a741d07edb3412b09008b7c5cfb9bbbd7d568bf00ba737b456ba171501'],\n ['XLM', '0xb7a8eba68a997cd0210c2e1e4ee811ad2d174b3611c22d9ebf16f4cb7e9ba850'],\n ['XRP', '0xec5d399846a9209f3fe5881d70aae9268c94339ff9817e8d18ff19fa05eea1c8'],\n // collateral\n ['USDC', '0xeaa020c61cc479712813461ce153894a96a6c00b21ed0cfc2798d1f9a9e9c94a'],\n ['USDE', '0x6ec879b1e9963de5ee97e9c8710b742d6228252a5e2ca12d4ae81d7fe5ee8c5d'],\n ['DAI', '0xb0948a5e5313200c632b51bb5ca32f6de0d36e9950a942d19751e833f70dabfd'],\n]);\n\nexport const collateralMappingWithRegularSymbol = new Map<string, string>([\n ['seth', 'eth'],\n ['wbtc', 'btc'],\n ['fbtc', 'btc'],\n ['wsteth', 'eth'],\n ['fdai', 'dai'],\n ['susdc', 'usdc'],\n ['susde', 'usde'],\n ['steth', 'eth'],\n ['fsol', 'sol'],\n ['fusdc', 'usdc'],\n ['fusdt', 'usdt'],\n ['ssol', 'sol'],\n ['sdai', 'dai'],\n ['usdx', 'usdc'],\n ['stbtc', 'btc'],\n]);\n// === TOKEN DISTRIBUTION ===\n\nexport enum SUPPORTED_CHAINS {\n BASE = 8453,\n}\n\nexport const REWARD_DISTRIBUTOR_ADDRESSES: Record<number, Record<string, Address>> = {\n [SUPPORTED_CHAINS.BASE]: {\n esprf: '0x6511718804180CC57833fEA036389A24604Dfc69',\n prf: '0x0000000000000000000000000000000000000000',\n rt: '0x648d6D711860699A11aBa192E9daBAfb6408af18',\n },\n};\n\nexport const REWARD_DISTRIBUTOR_ABI = [\n {\n inputs: [{ internalType: 'contract IERC20', name: '_rewardToken', type: 'address' }],\n stateMutability: 'nonpayable',\n type: 'constructor',\n },\n { inputs: [], name: 'AccessControlBadConfirmation', type: 'error' },\n {\n inputs: [\n { internalType: 'address', name: 'account', type: 'address' },\n { internalType: 'bytes32', name: 'neededRole', type: 'bytes32' },\n ],\n name: 'AccessControlUnauthorizedAccount',\n type: 'error',\n },\n {\n anonymous: false,\n inputs: [\n { indexed: true, internalType: 'address', name: 'user', type: 'address' },\n { indexed: false, internalType: 'uint256', name: 'amount', type: 'uint256' },\n ],\n name: 'RewardClaimed',\n type: 'event',\n },\n {\n anonymous: false,\n inputs: [\n { indexed: true, internalType: 'bytes32', name: 'role', type: 'bytes32' },\n { indexed: true, internalType: 'bytes32', name: 'previousAdminRole', type: 'bytes32' },\n { indexed: true, internalType: 'bytes32', name: 'newAdminRole', type: 'bytes32' },\n ],\n name: 'RoleAdminChanged',\n type: 'event',\n },\n {\n anonymous: false,\n inputs: [\n { indexed: true, internalType: 'bytes32', name: 'role', type: 'bytes32' },\n { indexed: true, internalType: 'address', name: 'account', type: 'address' },\n { indexed: true, internalType: 'address', name: 'sender', type: 'address' },\n ],\n name: 'RoleGranted',\n type: 'event',\n },\n {\n anonymous: false,\n inputs: [\n { indexed: true, internalType: 'bytes32', name: 'role', type: 'bytes32' },\n { indexed: true, internalType: 'address', name: 'account', type: 'address' },\n { indexed: true, internalType: 'address', name: 'sender', type: 'address' },\n ],\n name: 'RoleRevoked',\n type: 'event',\n },\n {\n inputs: [],\n name: 'DEFAULT_ADMIN_ROLE',\n outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [],\n name: 'actualRound',\n outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n { internalType: 'uint256', name: '_round', type: 'uint256' },\n { internalType: 'uint256', name: 'amount', type: 'uint256' },\n { internalType: 'bytes32[]', name: 'proof', type: 'bytes32[]' },\n ],\n name: 'claimReward',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n { internalType: 'uint256[]', name: '_rounds', type: 'uint256[]' },\n { internalType: 'uint256[]', name: 'amounts', type: 'uint256[]' },\n { internalType: 'bytes32[][]', name: 'proofs', type: 'bytes32[][]' },\n ],\n name: 'claimRewards',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n { internalType: 'uint256', name: '', type: 'uint256' },\n { internalType: 'address', name: '', type: 'address' },\n ],\n name: 'claimed',\n outputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [{ internalType: 'bytes32', name: 'role', type: 'bytes32' }],\n name: 'getRoleAdmin',\n outputs: [{ internalType: 'bytes32', name: '', type: 'bytes32' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n { internalType: 'bytes32', name: 'role', type: 'bytes32' },\n { internalType: 'address', name: 'account', type: 'address' },\n ],\n name: 'grantRole',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n { internalType: 'bytes32', name: 'role', type: 'bytes32' },\n { internalType: 'address', name: 'account', type: 'address' },\n ],\n name: 'hasRole',\n outputs: [{ internalType: 'bool', name: '', type: 'bool' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [\n { internalType: 'bytes32', name: 'role', type: 'bytes32' },\n { internalType: 'address', name: 'callerConfirmation', type: 'address' },\n ],\n name: 'renounceRole',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n { internalType: 'bytes32', name: 'role', type: 'bytes32' },\n { internalType: 'address', name: 'account', type: 'address' },\n ],\n name: 'revokeRole',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [],\n name: 'rewardToken',\n outputs: [{ internalType: 'contract IERC20', name: '', type: 'address' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [{ internalType: 'uint256', name: '_round', type: 'uint256' }],\n name: 'setActualRound',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [\n { internalType: 'uint256', name: '_round', type: 'uint256' },\n { internalType: 'bytes32', name: '_root', type: 'bytes32' },\n ],\n name: 'setRootPerRound',\n outputs: [],\n stateMutability: 'nonpayable',\n type: 'function',\n },\n {\n inputs: [{ internalType: 'bytes4', name: 'interfaceId', type: 'bytes4' }],\n name: 'supportsInterface',\n outputs: [{ internalType: 'bool', name: '', type: 'bool' }],\n stateMutability: 'view',\n type: 'function',\n },\n {\n inputs: [{ internalType: 'uint256', name: '', type: 'uint256' }],\n name: 'verifiersPerRound',\n outputs: [{ internalType: 'contract Verifier', name: '', type: 'address' }],\n stateMutability: 'view',\n type: 'function',\n },\n];\n","import { Decimal } from 'decimal.js';\nimport { formatEther, parseEther } from 'viem';\n\nexport const getDiff = (a: Decimal, b: Decimal): Decimal => {\n return a.gt(b) ? a.minus(b) : b.minus(a);\n};\n\nexport const addDelay = async (ms: number): Promise<void> => {\n return new Promise((resolve) => setTimeout(resolve, ms));\n};\n\nexport const getCurrentTimestampInSeconds = (): number => {\n return Math.floor(Date.now() / 1000);\n};\n\nexport const getUniqueValuesFromArray = (originalArray: string[]): string[] => {\n const uniqueArray: string[] = [];\n const seenValues = new Set<string>();\n\n originalArray.forEach((item) => {\n // Check if the value is not already seen\n if (!seenValues.has(item)) {\n // Add the value to the uniqueArray\n uniqueArray.push(item);\n // Mark the value as seen in the set\n seenValues.add(item);\n }\n });\n return uniqueArray;\n};\n\nexport function convertWeiToEther(amountInWei: string | bigint | undefined): number {\n if (amountInWei == undefined) {\n throw new Error('Invalid amount received during conversion: undefined');\n }\n if (typeof amountInWei == 'bigint') {\n return Number(formatEther(amountInWei));\n } else if (typeof amountInWei == 'string') {\n return Number(formatEther(BigInt(amountInWei)));\n } else {\n throw new Error('Expected string or bigint for conversion');\n }\n}\n\nexport function convertEtherToWei(amount: string | number | undefined): bigint {\n if (amount == undefined) {\n throw new Error('Invalid amount received during conversion: undefined');\n }\n if (typeof amount == 'number') {\n return parseEther(amount.toString());\n } else if (typeof amount == 'string') {\n return parseEther(amount);\n } else {\n throw new Error('Expected string or bigint for conversion');\n }\n}\n"],"mappings":";AAAA,OAAOA,cAAa;AACpB,SAAS,eAAe;;;ACDxB,SAAS,WAAW;AAIb,IAAM,uBAAuB,CAAC,gBAAwB;AAAA;AAAA,mBAE1C,YAAY,YAAY,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwErC,IAAM,8BAA8B,CAAC,kBAC1C;AAAA;AAAA,kBAEgB,aAAa;AAAA;AAAA;AAAA;AAAA;AAOxB,IAAM,2BAA2B,CAAC,kBAA4B;AAAA;AAAA;AAAA,sBAG/C,cAAc,IAAI,CAAC,OAAO,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgB9D,IAAM,sBAAsB,CAAC,kBAA4B;AAAA;AAAA;AAAA;AAAA,mBAI7C,cAAc,IAAI,CAAC,OAAO,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAa3D,IAAM,oBAAoB,CAAC,gBAAwB;AAAA;AAAA;AAAA;AAAA,gBAI1C,WAAW;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWpB,IAAM,yCAAyC,CAAC,eAAyB;AAAA;AAAA;AAAA;AAAA,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