feat: add temporary logging to swap_signed (#7472)

This commit is contained in:
eddie 2023-10-19 13:49:13 -07:00 committed by GitHub
parent b02352e8bf
commit 36242d14b0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

@ -1,11 +1,12 @@
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
import * as Sentry from '@sentry/react' import * as Sentry from '@sentry/react'
import { SwapEventName } from '@uniswap/analytics-events' import { CustomUserProperties, SwapEventName } from '@uniswap/analytics-events'
import { Percent } from '@uniswap/sdk-core' import { Percent } from '@uniswap/sdk-core'
import { DutchOrder, DutchOrderBuilder } from '@uniswap/uniswapx-sdk' import { DutchOrder, DutchOrderBuilder } from '@uniswap/uniswapx-sdk'
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import { sendAnalyticsEvent, useTrace } from 'analytics' import { sendAnalyticsEvent, useTrace } from 'analytics'
import { useCachedPortfolioBalancesQuery } from 'components/PrefetchBalancesWrapper/PrefetchBalancesWrapper' import { useCachedPortfolioBalancesQuery } from 'components/PrefetchBalancesWrapper/PrefetchBalancesWrapper'
import { getConnection } from 'connection'
import { formatSwapSignedAnalyticsEventProperties } from 'lib/utils/analytics' import { formatSwapSignedAnalyticsEventProperties } from 'lib/utils/analytics'
import { useCallback } from 'react' import { useCallback } from 'react'
import { DutchOrderTrade, TradeFillType } from 'state/routing/types' import { DutchOrderTrade, TradeFillType } from 'state/routing/types'
@ -13,6 +14,7 @@ import { trace } from 'tracing/trace'
import { SignatureExpiredError, UserRejectedRequestError } from 'utils/errors' import { SignatureExpiredError, UserRejectedRequestError } from 'utils/errors'
import { signTypedData } from 'utils/signing' import { signTypedData } from 'utils/signing'
import { didUserReject, swapErrorToUserReadableMessage } from 'utils/swapErrorToUserReadableMessage' import { didUserReject, swapErrorToUserReadableMessage } from 'utils/swapErrorToUserReadableMessage'
import { getWalletMeta } from 'utils/walletMeta'
type DutchAuctionOrderError = { errorCode?: number; detail?: string } type DutchAuctionOrderError = { errorCode?: number; detail?: string }
type DutchAuctionOrderSuccess = { hash: string } type DutchAuctionOrderSuccess = { hash: string }
@ -54,7 +56,7 @@ export function useUniswapXSwapCallback({
fiatValues: { amountIn?: number; amountOut?: number; feeUsd?: number } fiatValues: { amountIn?: number; amountOut?: number; feeUsd?: number }
allowedSlippage: Percent allowedSlippage: Percent
}) { }) {
const { account, provider } = useWeb3React() const { account, provider, connector } = useWeb3React()
const analyticsContext = useTrace() const analyticsContext = useTrace()
const { data } = useCachedPortfolioBalancesQuery({ account }) const { data } = useCachedPortfolioBalancesQuery({ account })
@ -122,6 +124,10 @@ export function useUniswapXSwapCallback({
portfolioBalanceUsd, portfolioBalanceUsd,
}), }),
...analyticsContext, ...analyticsContext,
// TODO (WEB-2993): remove these after debugging missing user properties.
[CustomUserProperties.WALLET_ADDRESS]: account,
[CustomUserProperties.WALLET_TYPE]: getConnection(connector).getName(),
[CustomUserProperties.PEER_WALLET_AGENT]: provider ? getWalletMeta(provider)?.agent : undefined,
}) })
const res = await fetch(`${UNISWAP_API_URL}/order`, { const res = await fetch(`${UNISWAP_API_URL}/order`, {
@ -160,6 +166,6 @@ export function useUniswapXSwapCallback({
response: { orderHash: body.hash, deadline: updatedOrder.info.deadline }, response: { orderHash: body.hash, deadline: updatedOrder.info.deadline },
} }
}), }),
[account, provider, trade, allowedSlippage, fiatValues, analyticsContext, portfolioBalanceUsd] [account, provider, trade, allowedSlippage, fiatValues, portfolioBalanceUsd, analyticsContext, connector]
) )
} }

@ -1,12 +1,13 @@
import { BigNumber } from '@ethersproject/bignumber' import { BigNumber } from '@ethersproject/bignumber'
import { t } from '@lingui/macro' import { t } from '@lingui/macro'
import { SwapEventName } from '@uniswap/analytics-events' import { CustomUserProperties, SwapEventName } from '@uniswap/analytics-events'
import { Percent } from '@uniswap/sdk-core' import { Percent } from '@uniswap/sdk-core'
import { FlatFeeOptions, SwapRouter, UNIVERSAL_ROUTER_ADDRESS } from '@uniswap/universal-router-sdk' import { FlatFeeOptions, SwapRouter, UNIVERSAL_ROUTER_ADDRESS } from '@uniswap/universal-router-sdk'
import { FeeOptions, toHex } from '@uniswap/v3-sdk' import { FeeOptions, toHex } from '@uniswap/v3-sdk'
import { useWeb3React } from '@web3-react/core' import { useWeb3React } from '@web3-react/core'
import { sendAnalyticsEvent, useTrace } from 'analytics' import { sendAnalyticsEvent, useTrace } from 'analytics'
import { useCachedPortfolioBalancesQuery } from 'components/PrefetchBalancesWrapper/PrefetchBalancesWrapper' import { useCachedPortfolioBalancesQuery } from 'components/PrefetchBalancesWrapper/PrefetchBalancesWrapper'
import { getConnection } from 'connection'
import useBlockNumber from 'lib/hooks/useBlockNumber' import useBlockNumber from 'lib/hooks/useBlockNumber'
import { formatCommonPropertiesForTrade, formatSwapSignedAnalyticsEventProperties } from 'lib/utils/analytics' import { formatCommonPropertiesForTrade, formatSwapSignedAnalyticsEventProperties } from 'lib/utils/analytics'
import { useCallback } from 'react' import { useCallback } from 'react'
@ -17,6 +18,7 @@ import { calculateGasMargin } from 'utils/calculateGasMargin'
import { UserRejectedRequestError, WrongChainError } from 'utils/errors' import { UserRejectedRequestError, WrongChainError } from 'utils/errors'
import isZero from 'utils/isZero' import isZero from 'utils/isZero'
import { didUserReject, swapErrorToUserReadableMessage } from 'utils/swapErrorToUserReadableMessage' import { didUserReject, swapErrorToUserReadableMessage } from 'utils/swapErrorToUserReadableMessage'
import { getWalletMeta } from 'utils/walletMeta'
import { PermitSignature } from './usePermitAllowance' import { PermitSignature } from './usePermitAllowance'
@ -52,7 +54,7 @@ export function useUniversalRouterSwapCallback(
fiatValues: { amountIn?: number; amountOut?: number; feeUsd?: number }, fiatValues: { amountIn?: number; amountOut?: number; feeUsd?: number },
options: SwapOptions options: SwapOptions
) { ) {
const { account, chainId, provider } = useWeb3React() const { account, chainId, provider, connector } = useWeb3React()
const analyticsContext = useTrace() const analyticsContext = useTrace()
const blockNumber = useBlockNumber() const blockNumber = useBlockNumber()
const isAutoSlippage = useUserSlippageTolerance()[0] === 'auto' const isAutoSlippage = useUserSlippageTolerance()[0] === 'auto'
@ -125,6 +127,10 @@ export function useUniversalRouterSwapCallback(
portfolioBalanceUsd, portfolioBalanceUsd,
}), }),
...analyticsContext, ...analyticsContext,
// TODO (WEB-2993): remove these after debugging missing user properties.
[CustomUserProperties.WALLET_ADDRESS]: account,
[CustomUserProperties.WALLET_TYPE]: getConnection(connector).getName(),
[CustomUserProperties.PEER_WALLET_AGENT]: provider ? getWalletMeta(provider)?.agent : undefined,
}) })
if (tx.data !== response.data) { if (tx.data !== response.data) {
sendAnalyticsEvent(SwapEventName.SWAP_MODIFIED_IN_WALLET, { sendAnalyticsEvent(SwapEventName.SWAP_MODIFIED_IN_WALLET, {
@ -163,11 +169,16 @@ export function useUniversalRouterSwapCallback(
chainId, chainId,
provider, provider,
trade, trade,
options, options.slippageTolerance,
options.deadline,
options.permit,
options.feeOptions,
options.flatFeeOptions,
analyticsContext, analyticsContext,
blockNumber, blockNumber,
isAutoSlippage, isAutoSlippage,
fiatValues, fiatValues,
portfolioBalanceUsd, portfolioBalanceUsd,
connector,
]) ])
} }