@velora-dex/widget 0.7.0 → 0.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ui/tooltip.js +1 -1
- package/dist/components/ui/tooltip.js.map +1 -1
- package/dist/components/widget/AppHeader/AppHeader.d.ts.map +1 -1
- package/dist/components/widget/AppHeader/AppHeader.js +45 -41
- package/dist/components/widget/AppHeader/AppHeader.js.map +1 -1
- package/dist/components/widget/AppHeader/TradeModeSwitcher.d.ts +3 -1
- package/dist/components/widget/AppHeader/TradeModeSwitcher.d.ts.map +1 -1
- package/dist/components/widget/AppHeader/TradeModeSwitcher.js +69 -34
- package/dist/components/widget/AppHeader/TradeModeSwitcher.js.map +1 -1
- package/dist/components/widget/SwapRate/SwapRate.d.ts +2 -1
- package/dist/components/widget/SwapRate/SwapRate.d.ts.map +1 -1
- package/dist/components/widget/SwapRate/SwapRate.js +25 -37
- package/dist/components/widget/SwapRate/SwapRate.js.map +1 -1
- package/dist/components/widget/SwapRate/SwapRateWithTooltip.d.ts +3 -0
- package/dist/components/widget/SwapRate/SwapRateWithTooltip.d.ts.map +1 -0
- package/dist/components/widget/SwapRate/SwapRateWithTooltip.js +42 -0
- package/dist/components/widget/SwapRate/SwapRateWithTooltip.js.map +1 -0
- package/dist/components/widget/SwapRate/utils.d.ts +3 -0
- package/dist/components/widget/SwapRate/utils.d.ts.map +1 -0
- package/dist/components/widget/SwapRate/utils.js +26 -0
- package/dist/components/widget/SwapRate/utils.js.map +1 -0
- package/dist/components/widget/SwapRateWithPriceImpactRow/SwapRateWithPriceImpactRow.d.ts.map +1 -1
- package/dist/components/widget/SwapRateWithPriceImpactRow/SwapRateWithPriceImpactRow.js +20 -27
- package/dist/components/widget/SwapRateWithPriceImpactRow/SwapRateWithPriceImpactRow.js.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +134 -131
- package/dist/core/index.js.map +1 -1
- package/dist/core/logger.d.ts +2 -2
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +8 -2
- package/dist/core/logger.js.map +1 -1
- package/dist/core/screen/hooks/useRunOnMount.d.ts +10 -0
- package/dist/core/screen/hooks/useRunOnMount.d.ts.map +1 -1
- package/dist/core/screen/hooks/useRunOnMount.js +6 -1
- package/dist/core/screen/hooks/useRunOnMount.js.map +1 -1
- package/dist/core/state/configActionsAtom.d.ts.map +1 -1
- package/dist/core/state/configActionsAtom.js +8 -8
- package/dist/core/state/configActionsAtom.js.map +1 -1
- package/dist/core/state/configAtom.d.ts +4 -2
- package/dist/core/state/configAtom.d.ts.map +1 -1
- package/dist/core/state/configAtom.js +7 -4
- package/dist/core/state/configAtom.js.map +1 -1
- package/dist/core/state/validatedReferrerConfigAtom.d.ts +3 -0
- package/dist/core/state/validatedReferrerConfigAtom.d.ts.map +1 -0
- package/dist/core/state/validatedReferrerConfigAtom.js +12 -0
- package/dist/core/state/validatedReferrerConfigAtom.js.map +1 -0
- package/dist/core/types.d.ts +6 -0
- package/dist/core/types.d.ts.map +1 -1
- package/dist/hooks/swap/tradeFlow/useDeltaFlow.d.ts.map +1 -1
- package/dist/hooks/swap/tradeFlow/useDeltaFlow.js +203 -201
- package/dist/hooks/swap/tradeFlow/useDeltaFlow.js.map +1 -1
- package/dist/hooks/swap/tradeFlow/useLimitOrderFlow.d.ts.map +1 -1
- package/dist/hooks/swap/tradeFlow/useLimitOrderFlow.js +85 -82
- package/dist/hooks/swap/tradeFlow/useLimitOrderFlow.js.map +1 -1
- package/dist/hooks/swap/tradeFlow/useMarketFlow.d.ts.map +1 -1
- package/dist/hooks/swap/tradeFlow/useMarketFlow.js +156 -154
- package/dist/hooks/swap/tradeFlow/useMarketFlow.js.map +1 -1
- package/dist/hooks/swap/tradeFlow/useTwapFlow.d.ts.map +1 -1
- package/dist/hooks/swap/tradeFlow/useTwapFlow.js +230 -228
- package/dist/hooks/swap/tradeFlow/useTwapFlow.js.map +1 -1
- package/dist/hooks/useReferrer.d.ts +2 -0
- package/dist/hooks/useReferrer.d.ts.map +1 -0
- package/dist/hooks/useReferrer.js +8 -0
- package/dist/hooks/useReferrer.js.map +1 -0
- package/dist/lib/utils/logger.d.ts +7 -4
- package/dist/lib/utils/logger.d.ts.map +1 -1
- package/dist/lib/utils/logger.js +70 -33
- package/dist/lib/utils/logger.js.map +1 -1
- package/dist/lib/web3/privy/config.js +1 -1
- package/dist/lib/web3/privy/config.js.map +1 -1
- package/dist/lib/web3/wagmi/config.js +1 -1
- package/dist/lib/web3/wagmi/config.js.map +1 -1
- package/dist/lib/web3/wagmi/isInsideSafeIframe.js +11 -11
- package/dist/lib/web3/wagmi/isInsideSafeIframe.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/tokens/utils/transferAmountsFromReceipt.js +14 -14
- package/dist/tokens/utils/transferAmountsFromReceipt.js.map +1 -1
- package/dist/transactions/queries/ensureTxReceipt.js +8 -8
- package/dist/transactions/queries/ensureTxReceipt.js.map +1 -1
- package/package.json +7 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transferAmountsFromReceipt.js","names":["Address","TransactionReceipt","Client","decodeEventLog","erc20Abi","Hex","Hash","getBalance","getGasPrice","getTransaction","getTransactionReceipt","Token","ETH_ADDRESS_LOWERCASE","gatherObjectsByProp","useQuery","UseQueryResult","useClient","SupportedChainId","useCallback","assert","MarkOptional","isETH","createLogger","isFilledArray","MinRequiredReceiptLog","address","topics","data","ERC20TransferAmountsFromReceiptInput","receipt","logs","tokens","Pick","senderAddress","receiverAddress","TransferAmountsFromReceiptInput","TokenTransfers","token","sentAmount","receivedAmount","TransferAmountsFromReceiptResult","Record","TRANSFER_EVENT_SIGNATURE","getERC20TransferAmountsFromReceipt","result","toLowerCase","tokensSet","Set","map","fromAddressLowercase","toAddressLowercase","log","logAddressLowercase","has","decoded","abi","eventName","from","fromAddress","to","toAddress","value","args","tokenTransfer","_error","NativeTokenTransferInput","client","REASONABLE_GAS_PRICE","getNativeTokenTransfer","Promise","beforeBlockNumber","blockNumber","afterBlockNumber","senderPromises","const","senderIsReceiver","receiverPromises","senderBalanceBefore","senderBalanceAfter","receiverBalanceBefore","receiverBalanceAfter","all","gasPrice","effectiveGasPrice","minTxData","getMinTxDataFromHash","hash","transactionHash","account","gasCost","gasUsed","TokenTransfersFromReceiptInput","getTokenTransfersFromReceipt","tokensWithoutNative","filter","tokenTransfers","length","nativeTokenTransfer","TokenTransfersFromReceiptWithLimitsInput","detectedTokenTransfers","expectedTokenTransfers","validateAmount","calculatedAmount","expectedAmount","tolerancePercent","tolerance","BigInt","minExpected","maxExpected","logger1","logger2","getTokenTransfersFromReceiptWithLimits","validatedTokenTransfers","once","tokenAddress","calculatedTransfer","Object","entries","expectedTransfer","validatedTransfer","UseTokenTransfersFromReceiptInput","chainId","useTokenTransfersFromReceipt","t0","$","_c","t1","t2","select","t3","t4","t5","t6","t7","t8","t9","t10","queryKey","queryFn","enabled","MinTxData","GetMinTxDataFromHashInput","undefined","tx"],"sources":["../../../src/tokens/utils/transferAmountsFromReceipt.ts"],"sourcesContent":["import {\n type Address,\n type TransactionReceipt,\n type Client,\n decodeEventLog,\n erc20Abi,\n type Hex,\n type Hash,\n} from \"viem\";\nimport {\n getBalance,\n getGasPrice,\n getTransaction,\n getTransactionReceipt,\n} from \"viem/actions\";\nimport type { Token } from \"../state/types\";\nimport { ETH_ADDRESS_LOWERCASE } from \"../constants\";\nimport { gatherObjectsByProp } from \"@/lib/utils\";\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { useClient } from \"wagmi\";\nimport type { SupportedChainId } from \"@/lib/web3/wagmi/types\";\nimport { useCallback } from \"react\";\nimport { assert, type MarkOptional } from \"ts-essentials\";\nimport { isETH } from \"./eth\";\nimport { createLogger } from \"@/lib/utils/logger\";\nimport { isFilledArray } from \"@/lib/utils/tuple\";\n\ntype MinRequiredReceiptLog = {\n address: Address;\n topics: Hex[];\n data: Hex;\n};\n\ntype ERC20TransferAmountsFromReceiptInput = {\n receipt: {\n logs: MinRequiredReceiptLog[];\n };\n tokens: Pick<Token, \"address\">[];\n senderAddress: Address;\n receiverAddress: Address;\n};\n\ntype TransferAmountsFromReceiptInput = ERC20TransferAmountsFromReceiptInput & {\n receipt: MarkOptional<\n Pick<\n TransactionReceipt,\n | \"blockNumber\"\n | \"gasUsed\"\n | \"effectiveGasPrice\"\n | \"from\"\n | \"transactionHash\"\n >,\n \"effectiveGasPrice\" | \"from\"\n >;\n};\n\nexport type TokenTransfers = {\n token: Address;\n sentAmount: bigint;\n receivedAmount: bigint;\n};\n\ntype TransferAmountsFromReceiptResult = Record<Address, TokenTransfers>;\n\n// ERC20 Transfer event signature: Transfer(address,address,uint256)\nconst TRANSFER_EVENT_SIGNATURE =\n \"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\";\n\n// give TransactionReceipt and tokens finds all transfers of Tokens to receiverAddress and returns amounts\nexport function getERC20TransferAmountsFromReceipt({\n receipt,\n tokens,\n senderAddress,\n receiverAddress,\n}: ERC20TransferAmountsFromReceiptInput): TransferAmountsFromReceiptResult {\n // Initialize result mapping with one entry per token\n const result: Record<Address, TokenTransfers> = gatherObjectsByProp(\n tokens,\n (token) => token.address.toLowerCase(),\n (token) => ({\n token: token.address as Address,\n sentAmount: 0n,\n receivedAmount: 0n,\n })\n );\n\n // Create a map for quick token lookup\n const tokensSet = new Set(tokens.map((token) => token.address.toLowerCase()));\n\n const fromAddressLowercase = senderAddress.toLowerCase();\n const toAddressLowercase = receiverAddress.toLowerCase();\n\n // Parse all logs in the transaction receipt\n for (const log of receipt.logs) {\n const logAddressLowercase = log.address.toLowerCase() as Address;\n // Check if this is a Transfer event from one of our tokens\n if (\n isFilledArray(log.topics) &&\n log.topics[0] === TRANSFER_EVENT_SIGNATURE &&\n tokensSet.has(logAddressLowercase)\n ) {\n try {\n // Parse the Transfer event parameters\n // topics[0] = event signature\n // topics[1] = from address (padded to 32 bytes)\n // topics[2] = to address (padded to 32 bytes)\n // data = value (uint256)\n\n const decoded = decodeEventLog({\n abi: erc20Abi,\n data: log.data,\n topics: log.topics,\n eventName: \"Transfer\",\n });\n\n const { from: fromAddress, to: toAddress, value } = decoded.args;\n\n const tokenTransfer = result[logAddressLowercase];\n if (!tokenTransfer) {\n continue;\n }\n\n // Check if the transfer is from sender to someone else\n if (fromAddress.toLowerCase() === fromAddressLowercase) {\n tokenTransfer.sentAmount += value;\n }\n // Check if the transfer is to receiver from someone else\n if (toAddress.toLowerCase() === toAddressLowercase) {\n tokenTransfer.receivedAmount += value;\n }\n } catch (_error) {\n // If parsing fails, skip this log\n continue;\n }\n }\n }\n\n return result;\n}\n\ntype NativeTokenTransferInput = {\n receipt: MarkOptional<\n Pick<\n TransactionReceipt,\n | \"blockNumber\"\n | \"gasUsed\"\n | \"effectiveGasPrice\"\n | \"from\"\n | \"transactionHash\"\n >,\n \"effectiveGasPrice\" | \"from\"\n >;\n senderAddress: Address;\n receiverAddress: Address;\n client: Client;\n};\n\n// when no gasPrice was fetched across several methods\nconst REASONABLE_GAS_PRICE = 2700000000n;\n\nexport async function getNativeTokenTransfer({\n receipt,\n senderAddress,\n receiverAddress,\n client,\n}: NativeTokenTransferInput): Promise<TokenTransfers> {\n const beforeBlockNumber = receipt.blockNumber - 1n;\n const afterBlockNumber = receipt.blockNumber;\n\n /*\n if the transaction was the only one transaction involving the sender and receiver\n in the block it was mined, and if the transaction was a SwapTransaction only,\n not some bulk transaction or a flashbot transaction, then we can consider\n that the ETH balances difference matches the ETH Swap amount.\n */\n\n const senderPromises = [\n // Get balances before the transaction\n getBalance(client, {\n address: senderAddress,\n blockNumber: beforeBlockNumber,\n }),\n // Get balances after the transaction\n getBalance(client, {\n address: senderAddress,\n blockNumber: afterBlockNumber,\n }),\n ] as const;\n\n const senderIsReceiver =\n senderAddress.toLowerCase() === receiverAddress.toLowerCase();\n\n const receiverPromises = senderIsReceiver\n ? // reuse sender promises if sender is receiver\n senderPromises\n : ([\n // Get balances before the transaction\n getBalance(client, {\n address: receiverAddress,\n blockNumber: beforeBlockNumber,\n }),\n // Get balances after the transaction\n getBalance(client, {\n address: receiverAddress,\n blockNumber: afterBlockNumber,\n }),\n ] as const);\n\n const [\n senderBalanceBefore,\n senderBalanceAfter,\n receiverBalanceBefore,\n receiverBalanceAfter,\n ] = await Promise.all([...senderPromises, ...receiverPromises]);\n\n // Calculate the differences\n let sentAmount = senderBalanceBefore - senderBalanceAfter; // difference in balances = sent ETH + paid gas\n let receivedAmount = receiverBalanceAfter - receiverBalanceBefore;\n\n let gasPrice = receipt.effectiveGasPrice;\n let from = receipt.from;\n if (!gasPrice) {\n // SendCalls receipt does not include some fields,\n // try to fetch them from the transaction hash\n const minTxData = await getMinTxDataFromHash({\n hash: receipt.transactionHash,\n client,\n });\n gasPrice = minTxData.gasPrice;\n from = minTxData.from;\n }\n\n if (!gasPrice) {\n gasPrice = REASONABLE_GAS_PRICE;\n }\n\n if (!from) {\n from = client.account?.address || senderAddress;\n }\n\n const gasCost = receipt.gasUsed * gasPrice;\n\n // if sender is the transaction sender (it may not be if a Relayer was involved)\n if (senderAddress.toLowerCase() === from.toLowerCase()) {\n // Adjust sentAmount for gas:\n // Subtract gas cost from sentAmount to get actual ETH sent (excluding gas fees)\n sentAmount -= gasCost;\n }\n\n // if sender is receiver, then need to adjust receivedAmount for gas\n if (senderAddress.toLowerCase() === receiverAddress.toLowerCase()) {\n receivedAmount += gasCost; // gas was paid out of the receivedAmount, so make this the amount before gas paid\n }\n\n return {\n token: ETH_ADDRESS_LOWERCASE, // Native token address\n sentAmount: sentAmount > 0n ? sentAmount : 0n,\n receivedAmount: receivedAmount > 0n ? receivedAmount : 0n,\n };\n}\n\ntype TokenTransfersFromReceiptInput = TransferAmountsFromReceiptInput & {\n client: Client;\n};\n\nexport async function getTokenTransfersFromReceipt({\n receipt,\n tokens,\n senderAddress,\n receiverAddress,\n client,\n}: TokenTransfersFromReceiptInput): Promise<TransferAmountsFromReceiptResult> {\n const tokensWithoutNative = tokens.filter((token) => !isETH(token));\n\n const tokenTransfers = getERC20TransferAmountsFromReceipt({\n receipt,\n tokens: tokensWithoutNative,\n senderAddress,\n receiverAddress,\n });\n\n // there was a native Token in the list\n if (tokensWithoutNative.length < tokens.length) {\n const nativeTokenTransfer = await getNativeTokenTransfer({\n receipt,\n senderAddress,\n receiverAddress,\n client,\n });\n\n tokenTransfers[ETH_ADDRESS_LOWERCASE] = nativeTokenTransfer;\n }\n\n return tokenTransfers;\n}\n\ntype TokenTransfersFromReceiptWithLimitsInput = {\n detectedTokenTransfers: Record<Address, TokenTransfers>;\n expectedTokenTransfers: Record<Address, TokenTransfers>;\n};\n\n// Helper function to validate an amount against expected value with tolerance\nfunction validateAmount({\n calculatedAmount,\n expectedAmount,\n tolerancePercent = 15, // max slippage %\n}: {\n calculatedAmount: bigint;\n expectedAmount: bigint;\n tolerancePercent?: number;\n}): bigint {\n if (expectedAmount === 0n) {\n // If expected is 0, use expected\n return expectedAmount;\n }\n\n // Check if calculated is within tolerance of expected\n const tolerance = (expectedAmount * BigInt(tolerancePercent)) / 100n;\n const minExpected = expectedAmount - tolerance;\n const maxExpected = expectedAmount + tolerance;\n\n if (calculatedAmount >= minExpected && calculatedAmount <= maxExpected) {\n return calculatedAmount;\n } else {\n return expectedAmount;\n }\n}\n\nconst logger1 = createLogger(\"Swap:amounts:Expected\");\nconst logger2 = createLogger(\"Swap:amounts:Detected\");\n\nexport function getTokenTransfersFromReceiptWithLimits({\n detectedTokenTransfers,\n expectedTokenTransfers,\n}: TokenTransfersFromReceiptWithLimitsInput): TransferAmountsFromReceiptResult {\n // Validate and adjust amounts based on expected values\n const validatedTokenTransfers: Record<Address, TokenTransfers> = {};\n\n logger1.once.log(\"Expected token transfers\", expectedTokenTransfers);\n logger2.once.log(\"Detected token transfers\", detectedTokenTransfers);\n\n for (const [tokenAddress, calculatedTransfer] of Object.entries(\n detectedTokenTransfers\n )) {\n const expectedTransfer = expectedTokenTransfers[tokenAddress as Address];\n\n if (!expectedTransfer) {\n // No expected value, use calculated\n validatedTokenTransfers[tokenAddress as Address] = calculatedTransfer;\n continue;\n }\n\n const validatedTransfer: TokenTransfers = {\n token: calculatedTransfer.token,\n sentAmount: validateAmount({\n calculatedAmount: calculatedTransfer.sentAmount,\n expectedAmount: expectedTransfer.sentAmount,\n }),\n receivedAmount: validateAmount({\n calculatedAmount: calculatedTransfer.receivedAmount,\n expectedAmount: expectedTransfer.receivedAmount,\n }),\n };\n\n validatedTokenTransfers[tokenAddress as Address] = validatedTransfer;\n }\n\n return validatedTokenTransfers;\n}\n\ntype UseTokenTransfersFromReceiptInput = TransferAmountsFromReceiptInput & {\n receipt: Pick<TransactionReceipt, \"transactionHash\">;\n chainId: SupportedChainId;\n expectedTokenTransfers: Record<Address, TokenTransfers>;\n};\n\n/**\n * @param expectedTokenTransfers - expected token transfers, if provided, will be used to validate the detected token transfers\n * @param chainId - chain id\n * @param receipt - transaction receipt\n * @param tokens - tokens\n * @param senderAddress - sender address\n * @param receiverAddress - receiver address\n * @returns - token transfers from receipt validated against expected token transfers\n * @note - ETH transfers are a best guess, and may not be accurate (falls back to expected token transfers)\n */\nexport function useTokenTransfersFromReceipt({\n receipt,\n tokens,\n senderAddress,\n receiverAddress,\n expectedTokenTransfers,\n chainId,\n}: MarkOptional<\n UseTokenTransfersFromReceiptInput,\n \"receipt\" | \"senderAddress\" | \"receiverAddress\" | \"expectedTokenTransfers\"\n>): UseQueryResult<TransferAmountsFromReceiptResult, Error> {\n const client = useClient({ chainId });\n\n const select = useCallback(\n (data: TransferAmountsFromReceiptResult) => {\n if (!expectedTokenTransfers) {\n return data;\n }\n\n return getTokenTransfersFromReceiptWithLimits({\n detectedTokenTransfers: data,\n expectedTokenTransfers,\n });\n },\n [expectedTokenTransfers]\n );\n\n return useQuery({\n queryKey: [\n \"token-transfers-from-receipt\",\n receipt?.transactionHash,\n receipt?.logs.length,\n senderAddress?.toLowerCase(),\n receiverAddress?.toLowerCase(),\n ],\n queryFn: async () => {\n assert(receipt, \"Receipt is required\");\n assert(senderAddress, \"Sender address is required\");\n assert(receiverAddress, \"Receiver address is required\");\n\n return getTokenTransfersFromReceipt({\n receipt,\n tokens,\n senderAddress,\n receiverAddress,\n client,\n });\n },\n select,\n enabled:\n !!receipt &&\n receipt.logs.length > 0 &&\n tokens.length > 0 &&\n !!senderAddress &&\n !!receiverAddress,\n });\n}\n\ntype MinTxData = {\n from?: Address;\n gasPrice?: bigint;\n};\n\ntype GetMinTxDataFromHashInput = {\n hash: Hash;\n client: Client;\n};\n\nasync function getMinTxDataFromHash({\n hash,\n client,\n}: GetMinTxDataFromHashInput): Promise<MinTxData> {\n let gasPrice: bigint | undefined = undefined;\n let from: Address | undefined;\n try {\n // likely this will return the correct receipt for the hash,\n // but in case of different RPC providers between the Wallet (which performed sendCalls),\n // and the RPC of the Client, the receipt may not be found\n const receipt = await getTransactionReceipt(client, {\n hash,\n });\n from = receipt.from;\n gasPrice = receipt.effectiveGasPrice;\n } catch {\n // can be TransactionReceiptNotFoundError\n }\n\n if (!gasPrice) {\n try {\n // very unlikely that even the transaction will not be found, but still possible\n const tx = await getTransaction(client, {\n hash,\n });\n from = tx.from;\n gasPrice = tx.gasPrice;\n } catch {\n // can be TransactionNotFoundError\n }\n }\n\n if (!gasPrice) {\n try {\n // just in case this may error\n gasPrice = await getGasPrice(client);\n } catch {\n // can be RequestError\n }\n }\n\n if (!from) {\n from = client.account?.address;\n }\n\n return {\n from,\n gasPrice,\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAiEA,IAAM0C,IACJ;AAGF,SAAgBC,EAAmC,EACjDd,YACAE,WACAE,kBACAC,sBACyE;CAEzE,IAAMU,IAA0C/B,EAC9CkB,IACCM,MAAUA,EAAMZ,QAAQoB,aAAa,GACrCR,OAAW;EACVA,OAAOA,EAAMZ;EACba,YAAY;EACZC,gBAAgB;EACjB,EACF,EAGKO,IAAY,IAAIC,IAAIhB,EAAOiB,KAAKX,MAAUA,EAAMZ,QAAQoB,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AAS,GAAAT,EAAA,MAAAU,GAAAV,EAAA,MAAAW,GAAAX,EAAA,MAAAY,KAAAA,IAAAZ,EAAA,KA5BM9G,EAAS0H,EA4Bd;;AAaJ,eAAenD,EAAqB,EAClCC,SACApB,aACgD;CAChD,IAAIgB,GACAzB;AACJ,KAAI;EAIF,IAAM5B,IAAU,MAAMnB,EAAsBwD,GAAQ,EAClDoB,SACD,CAAC;AAEFJ,EADAzB,IAAO5B,EAAQ4B,MACfyB,IAAWrD,EAAQsD;SACb;AAIR,KAAI,CAACD,EACH,KAAI;EAEF,IAAM6D,IAAK,MAAMtI,EAAeyD,GAAQ,EACtCoB,SACD,CAAC;AAEFJ,EADAzB,IAAOsF,EAAGtF,MACVyB,IAAW6D,EAAG7D;SACR;AAKV,KAAI,CAACA,EACH,KAAI;AAEFA,MAAW,MAAM1E,EAAY0D,EAAO;SAC9B;AASV,QAJA,AACET,MAAOS,EAAOsB,SAAS/D,SAGlB;EACLgC;EACAyB;EACD"}
|
|
1
|
+
{"version":3,"file":"transferAmountsFromReceipt.js","names":["Address","TransactionReceipt","Client","decodeEventLog","erc20Abi","Hex","Hash","getBalance","getGasPrice","getTransaction","getTransactionReceipt","Token","ETH_ADDRESS_LOWERCASE","gatherObjectsByProp","useQuery","UseQueryResult","useClient","SupportedChainId","useCallback","assert","MarkOptional","isETH","getLogger","isFilledArray","MinRequiredReceiptLog","address","topics","data","ERC20TransferAmountsFromReceiptInput","receipt","logs","tokens","Pick","senderAddress","receiverAddress","TransferAmountsFromReceiptInput","TokenTransfers","token","sentAmount","receivedAmount","TransferAmountsFromReceiptResult","Record","TRANSFER_EVENT_SIGNATURE","getERC20TransferAmountsFromReceipt","result","toLowerCase","tokensSet","Set","map","fromAddressLowercase","toAddressLowercase","log","logAddressLowercase","has","decoded","abi","eventName","from","fromAddress","to","toAddress","value","args","tokenTransfer","_error","NativeTokenTransferInput","client","REASONABLE_GAS_PRICE","getNativeTokenTransfer","Promise","beforeBlockNumber","blockNumber","afterBlockNumber","senderPromises","const","senderIsReceiver","receiverPromises","senderBalanceBefore","senderBalanceAfter","receiverBalanceBefore","receiverBalanceAfter","all","gasPrice","effectiveGasPrice","minTxData","getMinTxDataFromHash","hash","transactionHash","account","gasCost","gasUsed","TokenTransfersFromReceiptInput","getTokenTransfersFromReceipt","tokensWithoutNative","filter","tokenTransfers","length","nativeTokenTransfer","TokenTransfersFromReceiptWithLimitsInput","detectedTokenTransfers","expectedTokenTransfers","validateAmount","calculatedAmount","expectedAmount","tolerancePercent","tolerance","BigInt","minExpected","maxExpected","logger1","logger2","getTokenTransfersFromReceiptWithLimits","validatedTokenTransfers","once","tokenAddress","calculatedTransfer","Object","entries","expectedTransfer","validatedTransfer","UseTokenTransfersFromReceiptInput","chainId","useTokenTransfersFromReceipt","t0","$","_c","t1","t2","select","t3","t4","t5","t6","t7","t8","t9","t10","queryKey","queryFn","enabled","MinTxData","GetMinTxDataFromHashInput","undefined","tx"],"sources":["../../../src/tokens/utils/transferAmountsFromReceipt.ts"],"sourcesContent":["import {\n type Address,\n type TransactionReceipt,\n type Client,\n decodeEventLog,\n erc20Abi,\n type Hex,\n type Hash,\n} from \"viem\";\nimport {\n getBalance,\n getGasPrice,\n getTransaction,\n getTransactionReceipt,\n} from \"viem/actions\";\nimport type { Token } from \"../state/types\";\nimport { ETH_ADDRESS_LOWERCASE } from \"../constants\";\nimport { gatherObjectsByProp } from \"@/lib/utils\";\nimport { useQuery, type UseQueryResult } from \"@tanstack/react-query\";\nimport { useClient } from \"wagmi\";\nimport type { SupportedChainId } from \"@/lib/web3/wagmi/types\";\nimport { useCallback } from \"react\";\nimport { assert, type MarkOptional } from \"ts-essentials\";\nimport { isETH } from \"./eth\";\nimport { getLogger } from \"@/core/logger\";\nimport { isFilledArray } from \"@/lib/utils/tuple\";\n\ntype MinRequiredReceiptLog = {\n address: Address;\n topics: Hex[];\n data: Hex;\n};\n\ntype ERC20TransferAmountsFromReceiptInput = {\n receipt: {\n logs: MinRequiredReceiptLog[];\n };\n tokens: Pick<Token, \"address\">[];\n senderAddress: Address;\n receiverAddress: Address;\n};\n\ntype TransferAmountsFromReceiptInput = ERC20TransferAmountsFromReceiptInput & {\n receipt: MarkOptional<\n Pick<\n TransactionReceipt,\n | \"blockNumber\"\n | \"gasUsed\"\n | \"effectiveGasPrice\"\n | \"from\"\n | \"transactionHash\"\n >,\n \"effectiveGasPrice\" | \"from\"\n >;\n};\n\nexport type TokenTransfers = {\n token: Address;\n sentAmount: bigint;\n receivedAmount: bigint;\n};\n\ntype TransferAmountsFromReceiptResult = Record<Address, TokenTransfers>;\n\n// ERC20 Transfer event signature: Transfer(address,address,uint256)\nconst TRANSFER_EVENT_SIGNATURE =\n \"0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef\";\n\n// give TransactionReceipt and tokens finds all transfers of Tokens to receiverAddress and returns amounts\nexport function getERC20TransferAmountsFromReceipt({\n receipt,\n tokens,\n senderAddress,\n receiverAddress,\n}: ERC20TransferAmountsFromReceiptInput): TransferAmountsFromReceiptResult {\n // Initialize result mapping with one entry per token\n const result: Record<Address, TokenTransfers> = gatherObjectsByProp(\n tokens,\n (token) => token.address.toLowerCase(),\n (token) => ({\n token: token.address as Address,\n sentAmount: 0n,\n receivedAmount: 0n,\n })\n );\n\n // Create a map for quick token lookup\n const tokensSet = new Set(tokens.map((token) => token.address.toLowerCase()));\n\n const fromAddressLowercase = senderAddress.toLowerCase();\n const toAddressLowercase = receiverAddress.toLowerCase();\n\n // Parse all logs in the transaction receipt\n for (const log of receipt.logs) {\n const logAddressLowercase = log.address.toLowerCase() as Address;\n // Check if this is a Transfer event from one of our tokens\n if (\n isFilledArray(log.topics) &&\n log.topics[0] === TRANSFER_EVENT_SIGNATURE &&\n tokensSet.has(logAddressLowercase)\n ) {\n try {\n // Parse the Transfer event parameters\n // topics[0] = event signature\n // topics[1] = from address (padded to 32 bytes)\n // topics[2] = to address (padded to 32 bytes)\n // data = value (uint256)\n\n const decoded = decodeEventLog({\n abi: erc20Abi,\n data: log.data,\n topics: log.topics,\n eventName: \"Transfer\",\n });\n\n const { from: fromAddress, to: toAddress, value } = decoded.args;\n\n const tokenTransfer = result[logAddressLowercase];\n if (!tokenTransfer) {\n continue;\n }\n\n // Check if the transfer is from sender to someone else\n if (fromAddress.toLowerCase() === fromAddressLowercase) {\n tokenTransfer.sentAmount += value;\n }\n // Check if the transfer is to receiver from someone else\n if (toAddress.toLowerCase() === toAddressLowercase) {\n tokenTransfer.receivedAmount += value;\n }\n } catch (_error) {\n // If parsing fails, skip this log\n continue;\n }\n }\n }\n\n return result;\n}\n\ntype NativeTokenTransferInput = {\n receipt: MarkOptional<\n Pick<\n TransactionReceipt,\n | \"blockNumber\"\n | \"gasUsed\"\n | \"effectiveGasPrice\"\n | \"from\"\n | \"transactionHash\"\n >,\n \"effectiveGasPrice\" | \"from\"\n >;\n senderAddress: Address;\n receiverAddress: Address;\n client: Client;\n};\n\n// when no gasPrice was fetched across several methods\nconst REASONABLE_GAS_PRICE = 2700000000n;\n\nexport async function getNativeTokenTransfer({\n receipt,\n senderAddress,\n receiverAddress,\n client,\n}: NativeTokenTransferInput): Promise<TokenTransfers> {\n const beforeBlockNumber = receipt.blockNumber - 1n;\n const afterBlockNumber = receipt.blockNumber;\n\n /*\n if the transaction was the only one transaction involving the sender and receiver\n in the block it was mined, and if the transaction was a SwapTransaction only,\n not some bulk transaction or a flashbot transaction, then we can consider\n that the ETH balances difference matches the ETH Swap amount.\n */\n\n const senderPromises = [\n // Get balances before the transaction\n getBalance(client, {\n address: senderAddress,\n blockNumber: beforeBlockNumber,\n }),\n // Get balances after the transaction\n getBalance(client, {\n address: senderAddress,\n blockNumber: afterBlockNumber,\n }),\n ] as const;\n\n const senderIsReceiver =\n senderAddress.toLowerCase() === receiverAddress.toLowerCase();\n\n const receiverPromises = senderIsReceiver\n ? // reuse sender promises if sender is receiver\n senderPromises\n : ([\n // Get balances before the transaction\n getBalance(client, {\n address: receiverAddress,\n blockNumber: beforeBlockNumber,\n }),\n // Get balances after the transaction\n getBalance(client, {\n address: receiverAddress,\n blockNumber: afterBlockNumber,\n }),\n ] as const);\n\n const [\n senderBalanceBefore,\n senderBalanceAfter,\n receiverBalanceBefore,\n receiverBalanceAfter,\n ] = await Promise.all([...senderPromises, ...receiverPromises]);\n\n // Calculate the differences\n let sentAmount = senderBalanceBefore - senderBalanceAfter; // difference in balances = sent ETH + paid gas\n let receivedAmount = receiverBalanceAfter - receiverBalanceBefore;\n\n let gasPrice = receipt.effectiveGasPrice;\n let from = receipt.from;\n if (!gasPrice) {\n // SendCalls receipt does not include some fields,\n // try to fetch them from the transaction hash\n const minTxData = await getMinTxDataFromHash({\n hash: receipt.transactionHash,\n client,\n });\n gasPrice = minTxData.gasPrice;\n from = minTxData.from;\n }\n\n if (!gasPrice) {\n gasPrice = REASONABLE_GAS_PRICE;\n }\n\n if (!from) {\n from = client.account?.address || senderAddress;\n }\n\n const gasCost = receipt.gasUsed * gasPrice;\n\n // if sender is the transaction sender (it may not be if a Relayer was involved)\n if (senderAddress.toLowerCase() === from.toLowerCase()) {\n // Adjust sentAmount for gas:\n // Subtract gas cost from sentAmount to get actual ETH sent (excluding gas fees)\n sentAmount -= gasCost;\n }\n\n // if sender is receiver, then need to adjust receivedAmount for gas\n if (senderAddress.toLowerCase() === receiverAddress.toLowerCase()) {\n receivedAmount += gasCost; // gas was paid out of the receivedAmount, so make this the amount before gas paid\n }\n\n return {\n token: ETH_ADDRESS_LOWERCASE, // Native token address\n sentAmount: sentAmount > 0n ? sentAmount : 0n,\n receivedAmount: receivedAmount > 0n ? receivedAmount : 0n,\n };\n}\n\ntype TokenTransfersFromReceiptInput = TransferAmountsFromReceiptInput & {\n client: Client;\n};\n\nexport async function getTokenTransfersFromReceipt({\n receipt,\n tokens,\n senderAddress,\n receiverAddress,\n client,\n}: TokenTransfersFromReceiptInput): Promise<TransferAmountsFromReceiptResult> {\n const tokensWithoutNative = tokens.filter((token) => !isETH(token));\n\n const tokenTransfers = getERC20TransferAmountsFromReceipt({\n receipt,\n tokens: tokensWithoutNative,\n senderAddress,\n receiverAddress,\n });\n\n // there was a native Token in the list\n if (tokensWithoutNative.length < tokens.length) {\n const nativeTokenTransfer = await getNativeTokenTransfer({\n receipt,\n senderAddress,\n receiverAddress,\n client,\n });\n\n tokenTransfers[ETH_ADDRESS_LOWERCASE] = nativeTokenTransfer;\n }\n\n return tokenTransfers;\n}\n\ntype TokenTransfersFromReceiptWithLimitsInput = {\n detectedTokenTransfers: Record<Address, TokenTransfers>;\n expectedTokenTransfers: Record<Address, TokenTransfers>;\n};\n\n// Helper function to validate an amount against expected value with tolerance\nfunction validateAmount({\n calculatedAmount,\n expectedAmount,\n tolerancePercent = 15, // max slippage %\n}: {\n calculatedAmount: bigint;\n expectedAmount: bigint;\n tolerancePercent?: number;\n}): bigint {\n if (expectedAmount === 0n) {\n // If expected is 0, use expected\n return expectedAmount;\n }\n\n // Check if calculated is within tolerance of expected\n const tolerance = (expectedAmount * BigInt(tolerancePercent)) / 100n;\n const minExpected = expectedAmount - tolerance;\n const maxExpected = expectedAmount + tolerance;\n\n if (calculatedAmount >= minExpected && calculatedAmount <= maxExpected) {\n return calculatedAmount;\n } else {\n return expectedAmount;\n }\n}\n\nconst logger1 = getLogger(\"Swap:amounts:Expected\");\nconst logger2 = getLogger(\"Swap:amounts:Detected\");\n\nexport function getTokenTransfersFromReceiptWithLimits({\n detectedTokenTransfers,\n expectedTokenTransfers,\n}: TokenTransfersFromReceiptWithLimitsInput): TransferAmountsFromReceiptResult {\n // Validate and adjust amounts based on expected values\n const validatedTokenTransfers: Record<Address, TokenTransfers> = {};\n\n logger1.once.log(\"Expected token transfers\", expectedTokenTransfers);\n logger2.once.log(\"Detected token transfers\", detectedTokenTransfers);\n\n for (const [tokenAddress, calculatedTransfer] of Object.entries(\n detectedTokenTransfers\n )) {\n const expectedTransfer = expectedTokenTransfers[tokenAddress as Address];\n\n if (!expectedTransfer) {\n // No expected value, use calculated\n validatedTokenTransfers[tokenAddress as Address] = calculatedTransfer;\n continue;\n }\n\n const validatedTransfer: TokenTransfers = {\n token: calculatedTransfer.token,\n sentAmount: validateAmount({\n calculatedAmount: calculatedTransfer.sentAmount,\n expectedAmount: expectedTransfer.sentAmount,\n }),\n receivedAmount: validateAmount({\n calculatedAmount: calculatedTransfer.receivedAmount,\n expectedAmount: expectedTransfer.receivedAmount,\n }),\n };\n\n validatedTokenTransfers[tokenAddress as Address] = validatedTransfer;\n }\n\n return validatedTokenTransfers;\n}\n\ntype UseTokenTransfersFromReceiptInput = TransferAmountsFromReceiptInput & {\n receipt: Pick<TransactionReceipt, \"transactionHash\">;\n chainId: SupportedChainId;\n expectedTokenTransfers: Record<Address, TokenTransfers>;\n};\n\n/**\n * @param expectedTokenTransfers - expected token transfers, if provided, will be used to validate the detected token transfers\n * @param chainId - chain id\n * @param receipt - transaction receipt\n * @param tokens - tokens\n * @param senderAddress - sender address\n * @param receiverAddress - receiver address\n * @returns - token transfers from receipt validated against expected token transfers\n * @note - ETH transfers are a best guess, and may not be accurate (falls back to expected token transfers)\n */\nexport function useTokenTransfersFromReceipt({\n receipt,\n tokens,\n senderAddress,\n receiverAddress,\n expectedTokenTransfers,\n chainId,\n}: MarkOptional<\n UseTokenTransfersFromReceiptInput,\n \"receipt\" | \"senderAddress\" | \"receiverAddress\" | \"expectedTokenTransfers\"\n>): UseQueryResult<TransferAmountsFromReceiptResult, Error> {\n const client = useClient({ chainId });\n\n const select = useCallback(\n (data: TransferAmountsFromReceiptResult) => {\n if (!expectedTokenTransfers) {\n return data;\n }\n\n return getTokenTransfersFromReceiptWithLimits({\n detectedTokenTransfers: data,\n expectedTokenTransfers,\n });\n },\n [expectedTokenTransfers]\n );\n\n return useQuery({\n queryKey: [\n \"token-transfers-from-receipt\",\n receipt?.transactionHash,\n receipt?.logs.length,\n senderAddress?.toLowerCase(),\n receiverAddress?.toLowerCase(),\n ],\n queryFn: async () => {\n assert(receipt, \"Receipt is required\");\n assert(senderAddress, \"Sender address is required\");\n assert(receiverAddress, \"Receiver address is required\");\n\n return getTokenTransfersFromReceipt({\n receipt,\n tokens,\n senderAddress,\n receiverAddress,\n client,\n });\n },\n select,\n enabled:\n !!receipt &&\n receipt.logs.length > 0 &&\n tokens.length > 0 &&\n !!senderAddress &&\n !!receiverAddress,\n });\n}\n\ntype MinTxData = {\n from?: Address;\n gasPrice?: bigint;\n};\n\ntype GetMinTxDataFromHashInput = {\n hash: Hash;\n client: Client;\n};\n\nasync function getMinTxDataFromHash({\n hash,\n client,\n}: GetMinTxDataFromHashInput): Promise<MinTxData> {\n let gasPrice: bigint | undefined = undefined;\n let from: Address | undefined;\n try {\n // likely this will return the correct receipt for the hash,\n // but in case of different RPC providers between the Wallet (which performed sendCalls),\n // and the RPC of the Client, the receipt may not be found\n const receipt = await getTransactionReceipt(client, {\n hash,\n });\n from = receipt.from;\n gasPrice = receipt.effectiveGasPrice;\n } catch {\n // can be TransactionReceiptNotFoundError\n }\n\n if (!gasPrice) {\n try {\n // very unlikely that even the transaction will not be found, but still possible\n const tx = await getTransaction(client, {\n hash,\n });\n from = tx.from;\n gasPrice = tx.gasPrice;\n } catch {\n // can be TransactionNotFoundError\n }\n }\n\n if (!gasPrice) {\n try {\n // just in case this may error\n gasPrice = await getGasPrice(client);\n } catch {\n // can be RequestError\n }\n }\n\n if (!from) {\n from = client.account?.address;\n }\n\n return {\n from,\n gasPrice,\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAiEA,IAAM0C,IACJ;AAGF,SAAgBC,EAAmC,EACjDd,YACAE,WACAE,kBACAC,sBACyE;CAEzE,IAAMU,IAA0C/B,EAC9CkB,IACCM,MAAUA,EAAMZ,QAAQoB,aAAa,GACrCR,OAAW;EACVA,OAAOA,EAAMZ;EACba,YAAY;EACZC,gBAAgB;EACjB,EACF,EAGKO,IAAY,IAAIC,IAAIhB,EAAOiB,KAAKX,MAAUA,EAAMZ,QAAQoB,aAAa,CAAC,CAAC,EAEvEI,IAAuBhB,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A,MAAAW,GAAAX,EAAA,MAAAY,KAAAA,IAAAZ,EAAA,KA5BM9G,EAAS0H,EA4Bd;;AAaJ,eAAenD,EAAqB,EAClCC,SACApB,aACgD;CAChD,IAAIgB,GACAzB;AACJ,KAAI;EAIF,IAAM5B,IAAU,MAAMnB,EAAsBwD,GAAQ,EAClDoB,SACD,CAAC;AAEFJ,EADAzB,IAAO5B,EAAQ4B,MACfyB,IAAWrD,EAAQsD;SACb;AAIR,KAAI,CAACD,EACH,KAAI;EAEF,IAAM6D,IAAK,MAAMtI,EAAeyD,GAAQ,EACtCoB,SACD,CAAC;AAEFJ,EADAzB,IAAOsF,EAAGtF,MACVyB,IAAW6D,EAAG7D;SACR;AAKV,KAAI,CAACA,EACH,KAAI;AAEFA,MAAW,MAAM1E,EAAY0D,EAAO;SAC9B;AASV,QAJA,AACET,MAAOS,EAAOsB,SAAS/D,SAGlB;EACLgC;EACAyB;EACD"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { SAFE_CALLS_WAIT_TIMEOUT as e } from "../../lib/constants/index.js";
|
|
2
|
+
import { getLogger as t } from "../../core/logger.js";
|
|
3
3
|
import { wagmiConfig as n } from "../../lib/web3/wagmi/config.js";
|
|
4
4
|
import { queryClient as r } from "../../lib/queryClient.js";
|
|
5
5
|
import { isConnectorWithSafeIframeProvider as i, isExternalConnectorSafeWalletConnect as a } from "../../components/web3/ConnectExternalProvider/utils.js";
|
|
@@ -11,10 +11,10 @@ import "viem";
|
|
|
11
11
|
import { getAccount as l, getConnectorClient as u } from "@wagmi/core";
|
|
12
12
|
import { waitForTransactionReceiptQueryOptions as d } from "wagmi/query";
|
|
13
13
|
//#region src/transactions/queries/ensureTxReceipt.ts
|
|
14
|
-
var f =
|
|
15
|
-
let { queryClient: _ = r, wagmiConfig: v = n, isSafe: y } =
|
|
14
|
+
var f = t("Transactions:EnsureTxReceipt"), p = (t = {}) => async ({ hash: p, chainId: m, confirmations: h, onReplaced: g }) => {
|
|
15
|
+
let { queryClient: _ = r, wagmiConfig: v = n, isSafe: y } = t, { connector: b } = l(v), x = !1, S = !1;
|
|
16
16
|
b && (x = a(b), S = i(b), !x && !S && (x = await o(b)));
|
|
17
|
-
let C = y || x || S ?
|
|
17
|
+
let C = y || x || S ? e : e / 2, w = v, T = p;
|
|
18
18
|
if (S) {
|
|
19
19
|
let e = await u(v, {
|
|
20
20
|
chainId: m,
|
|
@@ -25,12 +25,12 @@ var f = e("Transactions:EnsureTxReceipt"), p = (e = {}) => async ({ hash: p, cha
|
|
|
25
25
|
getClient: (t) => (c(!t || t.chainId === m, "chainId mismatch"), e)
|
|
26
26
|
};
|
|
27
27
|
} else if (x) {
|
|
28
|
-
let
|
|
29
|
-
...
|
|
28
|
+
let e = s({
|
|
29
|
+
...t,
|
|
30
30
|
isSafe: !0
|
|
31
31
|
});
|
|
32
32
|
try {
|
|
33
|
-
let
|
|
33
|
+
let t = await e({ id: p }), n = t.receipts?.[t.receipts.length - 1];
|
|
34
34
|
c(n, `Transaction receipt not found for Safe tx through WalletConnect ${p}, on chain ${m}`), T = n.transactionHash;
|
|
35
35
|
} catch (e) {
|
|
36
36
|
f.error("Error getting calls status for Safe tx through WalletConnect", { error: e });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ensureTxReceipt.js","names":["UseAwaitTxParameters","queryClient","_queryClient","wagmiConfig","_wagmiConfig","QueryClient","assert","MarkRequired","ReplacementReturnType","TransactionReceipt","waitForTransactionReceiptQueryOptions","SAFE_CALLS_WAIT_TIMEOUT","Chain","getAccount","getConnectorClient","isConnectorWithSafeIframeProvider","isExternalConnectorSafeWalletConnect","isWalletConnectConnectorWithSafe","ensureCallsStatusFactory","
|
|
1
|
+
{"version":3,"file":"ensureTxReceipt.js","names":["UseAwaitTxParameters","queryClient","_queryClient","wagmiConfig","_wagmiConfig","QueryClient","assert","MarkRequired","ReplacementReturnType","TransactionReceipt","waitForTransactionReceiptQueryOptions","SAFE_CALLS_WAIT_TIMEOUT","Chain","getAccount","getConnectorClient","isConnectorWithSafeIframeProvider","isExternalConnectorSafeWalletConnect","isWalletConnectConnectorWithSafe","ensureCallsStatusFactory","getLogger","OnReplacedCb","data","EnsureTxReceiptFn","options","Pick","onReplaced","Promise","EnsureTxReceiptFactory","params","isSafe","logger","ensureTxReceiptFactory","hash","chainId","confirmations","_isSafe","connector","isWConnectConnectorWithSafe","isConnectedToSafeIframe","isConnectedToSafe","timeout","config","realtxHash","safeClient","getClient","ensureCallsStatus","callsStatusResult","id","classReceipt","receipts","length","transactionHash","error","queryOptions","receipt","ensureQueryData"],"sources":["../../../src/transactions/queries/ensureTxReceipt.ts"],"sourcesContent":["import type { UseAwaitTxParameters } from \"@/hooks/txs/queries/useAwaitTx\";\nimport { queryClient as _queryClient } from \"@/lib/queryClient\";\nimport { wagmiConfig as _wagmiConfig } from \"@/lib/web3/wagmi/config\";\nimport type { QueryClient } from \"@tanstack/react-query\";\n\nimport { assert, type MarkRequired } from \"ts-essentials\";\nimport { type ReplacementReturnType, type TransactionReceipt } from \"viem\";\n\nimport { waitForTransactionReceiptQueryOptions } from \"wagmi/query\";\nimport { SAFE_CALLS_WAIT_TIMEOUT } from \"@/lib/constants\";\nimport { type Chain } from \"wagmi/chains\";\nimport { getAccount, getConnectorClient } from \"@wagmi/core\";\nimport {\n isConnectorWithSafeIframeProvider,\n isExternalConnectorSafeWalletConnect,\n} from \"@/components/web3/ConnectExternalProvider/utils\";\nimport { isWalletConnectConnectorWithSafe } from \"@/hooks/connectors/useIsSafeThroughWalletConnect\";\nimport { ensureCallsStatusFactory } from \"./ensureCallsStatus\";\nimport { getLogger } from \"@/core/logger\";\n\ntype OnReplacedCb = (data: ReplacementReturnType<Chain>) => void;\n\nexport type EnsureTxReceiptFn = (\n options: MarkRequired<\n Pick<UseAwaitTxParameters, \"hash\" | \"chainId\" | \"confirmations\">,\n \"hash\" | \"chainId\"\n > & {\n onReplaced?: OnReplacedCb;\n }\n) => Promise<TransactionReceipt>;\n\ntype EnsureTxReceiptFactory = (params?: {\n queryClient?: QueryClient;\n wagmiConfig?: typeof _wagmiConfig;\n isSafe?: boolean;\n}) => EnsureTxReceiptFn;\n\nconst logger = getLogger(\"Transactions:EnsureTxReceipt\");\n\nexport const ensureTxReceiptFactory: EnsureTxReceiptFactory =\n (options = {}) =>\n async ({ hash, chainId, confirmations, onReplaced }) => {\n const {\n queryClient = _queryClient,\n wagmiConfig = _wagmiConfig,\n isSafe: _isSafe,\n } = options;\n const { connector } = getAccount(wagmiConfig);\n let isWConnectConnectorWithSafe = false;\n let isConnectedToSafeIframe = false;\n if (connector) {\n isWConnectConnectorWithSafe =\n // can determine sync from connector.type and connector.id in case of external provider\n isExternalConnectorSafeWalletConnect(connector);\n // can determine sync from connector.type and connector.id in case of Safe Iframe provider,\n // whether as external provider or in safe connector\n isConnectedToSafeIframe = isConnectorWithSafeIframeProvider(connector);\n if (!isWConnectConnectorWithSafe && !isConnectedToSafeIframe) {\n // neither External Safe WalletConnect connector nor Safe Iframe connector,\n // so we check if it's a WalletConnect connector with Safe\n isWConnectConnectorWithSafe =\n await isWalletConnectConnectorWithSafe(connector);\n }\n }\n const isConnectedToSafe =\n isWConnectConnectorWithSafe || isConnectedToSafeIframe;\n\n const isSafe = _isSafe || isConnectedToSafe;\n\n const timeout = isSafe\n ? SAFE_CALLS_WAIT_TIMEOUT\n : SAFE_CALLS_WAIT_TIMEOUT / 2; // by default timeout is set to 0 inside waitForTransactionReceipt,\n // which makes the receipt query never resolve if the tx is dropped\n\n let config = wagmiConfig;\n let realtxHash = hash;\n\n // always use connector client if connected through native safe connector.\n // safe provider returns a safeTxHash that is different from a real tx hash.\n if (isConnectedToSafeIframe) {\n const safeClient = await getConnectorClient(wagmiConfig, {\n chainId,\n connector,\n });\n\n // force waitForTransactionReceiptQueryOptions to use SafeClient internally\n config = {\n ...wagmiConfig,\n // doesn't work with Safe through WalletConnect connector\n getClient: (options) => {\n assert(!options || options.chainId === chainId, \"chainId mismatch\");\n return safeClient;\n },\n } as typeof wagmiConfig;\n } else if (isWConnectConnectorWithSafe) {\n /**\n * When Safe is connected through WalletConnect\n * (whether as external provider or in WalletConnect connector),\n * the resulting provider only ever returns safeTxHash in response to eth_sendTransaction.\n * And the provider never returns any kind of result in response to eth_getTransactionReceipt\n * or eth_getTransactionByHash for that safeTxHash.\n * Safe iframe provider does return real txHash's receipt in response to eth_getTransactionReceipt for safeTxHash.\n * But Safe through WalletConnect never does that.\n * Options:\n * 1. Use deprecated Safe API v1 to get the real tx hash and await its receipt\n * 2. Use Safe API v2 (optionally through safe-api-kit) but there an API key is required\n * 3. Safe SDK isn't an option as it communicates with Safe only from inside an iframe\n * 4. Surprisingly, wallet_getCallsStatus works with safeTxHash (at least with multiple signers)\n *\n * Here we go with option 4:\n * sendCallsId=safeTxHash -> getCallsStatus -> realTxHash=callsReceipt.txHash -> await receipt of realTxHash\n *\n * refs:\n * https://github.com/safe-global/safe-react-apps/issues/712\n * https://github.com/safe-global/safe-react-apps/issues/62\n */\n const ensureCallsStatus = ensureCallsStatusFactory({\n ...options,\n isSafe: true,\n });\n try {\n const callsStatusResult = await ensureCallsStatus({ id: hash });\n const classReceipt =\n callsStatusResult.receipts?.[callsStatusResult.receipts.length - 1];\n\n assert(\n classReceipt,\n `Transaction receipt not found for Safe tx through WalletConnect ${hash}, on chain ${chainId}`\n );\n\n realtxHash = classReceipt.transactionHash;\n } catch (error) {\n // it is possible Safe through WalletConnect could be connected but called with a past non-Safe tx from localStorage,\n // in that case we should try to get the tx receipt normally\n logger.error(\n \"Error getting calls status for Safe tx through WalletConnect\",\n { error }\n );\n }\n }\n\n // wagmi/core waitForTransactionReceipt throws on receipt.status==\"reverted\",\n // unlike viem waitForTransactionReceipt which returns the receipt as is\n const queryOptions = waitForTransactionReceiptQueryOptions(config, {\n hash: realtxHash,\n chainId,\n confirmations,\n timeout,\n onReplaced,\n });\n\n const receipt = await queryClient.ensureQueryData(queryOptions);\n\n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+1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@velora-dex/widget",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -41,17 +41,17 @@
|
|
|
41
41
|
"@tanstack/react-query-devtools": "^5.91.1",
|
|
42
42
|
"@types/big.js": "^6.2.2",
|
|
43
43
|
"@types/node": "^20.19.9",
|
|
44
|
-
"@types/react": "^19.
|
|
45
|
-
"@types/react-dom": "^19.
|
|
44
|
+
"@types/react": "^19.2.14",
|
|
45
|
+
"@types/react-dom": "^19.2.3",
|
|
46
46
|
"@vitejs/plugin-react": "^6.0.1",
|
|
47
47
|
"babel-plugin-react-compiler": "1.0.0",
|
|
48
48
|
"eslint": "^9.32.0",
|
|
49
49
|
"eslint-plugin-react-hooks": "7.0.1",
|
|
50
|
-
"eslint-plugin-react-refresh": "^0.4.
|
|
50
|
+
"eslint-plugin-react-refresh": "^0.4.26",
|
|
51
51
|
"globals": "^16.3.0",
|
|
52
52
|
"madge": "^8.0.0",
|
|
53
|
-
"react": "^19.
|
|
54
|
-
"react-dom": "^19.
|
|
53
|
+
"react": "^19.2.5",
|
|
54
|
+
"react-dom": "^19.2.5",
|
|
55
55
|
"tailwindcss": "^4.2.2",
|
|
56
56
|
"tw-animate-css": "^1.3.6",
|
|
57
57
|
"typescript": "~5.9.2",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"@tanstack/react-pacer": "^0.14.0",
|
|
79
79
|
"@tanstack/react-virtual": "^3.13.12",
|
|
80
80
|
"@uniswap/token-lists": "1.0.0-beta.34",
|
|
81
|
-
"@velora-dex/sdk": "9.5.
|
|
81
|
+
"@velora-dex/sdk": "9.5.1",
|
|
82
82
|
"@wagmi/core": "^2.18.1",
|
|
83
83
|
"axios": "^1.11.0",
|
|
84
84
|
"big.js": "^7.0.1",
|